albertshaw 8 years ago
parent
commit
6a1bc2f2c0

+ 6 - 0
src/main/java/com/goafanti/common/mapper/CopyrightInfoMapper.xml

@@ -269,6 +269,9 @@
 	<if test="unitName != null">
 	    and oi.unit_name like CONCAT('%', #{unitName,jdbcType=VARCHAR}, '%')
 	</if>
+	<if test="unitId != null">
+	    and ci.uid = #{unitId,jdbcType=VARCHAR}
+	</if>
 	<if test="copyrightName != null">
 	    and ci.copyright_name like CONCAT('%', #{copyrightName,jdbcType=VARCHAR}, '%')
 	</if>
@@ -310,6 +313,9 @@
 	<if test="unitName != null">
 	    and oi.unit_name like CONCAT('%', #{unitName,jdbcType=VARCHAR}, '%')
 	</if>
+	<if test="unitId != null">
+	    and ci.uid = #{unitId,jdbcType=VARCHAR}
+	</if>
 	<if test="copyrightName != null">
 	    and ci.copyright_name like CONCAT('%', #{copyrightName,jdbcType=VARCHAR}, '%')
 	</if>

+ 0 - 3
src/main/java/com/goafanti/common/utils/FileUtils.java

@@ -234,7 +234,4 @@ public class FileUtils {
 		return "企业" + s.substring(s.lastIndexOf(UNDERLINE) + 1, s.lastIndexOf("."));
 	}
 
-	public static void main(String[] args) {
-		System.out.println(FileUtils.buildFilePath("/upload", "/private/", "/ss/s/"));
-	}
 }

+ 154 - 11
src/main/java/com/goafanti/copyright/controller/CopyrightApiController.java

@@ -1,26 +1,32 @@
 package com.goafanti.copyright.controller;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.validation.BindingResult;
+import org.springframework.validation.FieldError;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.goafanti.common.bo.Result;
+import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
+import com.goafanti.common.enums.AttachmentType;
 import com.goafanti.common.enums.CopyrightFields;
 import com.goafanti.common.enums.CopyrightStatus;
 import com.goafanti.common.model.CopyrightInfo;
+import com.goafanti.common.model.CopyrightLog;
 import com.goafanti.common.model.User;
-import com.goafanti.core.shiro.token.TokenManager;
+import com.goafanti.copyright.bo.CopyrightInfoDetail;
 import com.goafanti.copyright.bo.InputCopyright;
 import com.goafanti.copyright.service.CopyrightInfoService;
+import com.goafanti.core.shiro.token.TokenManager;
 
 @RestController
 @RequestMapping(value = "/techservice/copyright")
@@ -28,22 +34,16 @@ public class CopyrightApiController extends CertifyApiController {
 	@Resource
 	private CopyrightInfoService	copyrightInfoService;
 
-	@Value(value = "${upload.private.path}")
-	private String					uploadPrivatePath	= null;
-
 	@RequestMapping(value = "/apply", method = RequestMethod.POST)
 	public Result newApply(@Valid InputCopyright inputInfo, BindingResult bindingResult) {
 		Result res = new Result();
-		if (bindingResult.hasErrors()) {
-			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
-					CopyrightFields.getFieldDesc(bindingResult.getFieldError().getField())));
+		if (handleBindingError(res, bindingResult)) {
 			return res;
 		}
-		User curUser = TokenManager.getUserToken();
-		if (curUser == null) {
-			res.getError().add(buildError(ErrorConstants.NON_LOGIN, "找不到用户登录信息"));
+		if (!checkUserLogin(res)) {
 			return res;
 		}
+		User curUser = TokenManager.getUserToken();
 		if (!checkCertify(res, curUser)) {
 			return res;
 		}
@@ -61,4 +61,147 @@ public class CopyrightApiController extends CertifyApiController {
 		return res;
 	}
 
+	@RequestMapping(value = "/modify", method = RequestMethod.POST)
+	public Result modify(String id, @Valid InputCopyright inputInfo, BindingResult bindingResult) {
+		Result res = new Result();
+		if (handleBindingError(res, bindingResult)) {
+			return res;
+		}
+		if (!checkUserLogin(res)) {
+			return res;
+		}
+		User curUser = TokenManager.getUserToken();
+		if (!checkCertify(res, curUser)) {
+			return res;
+		}
+		if (StringUtils.isBlank(id)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到软著", "软著申请id"));
+			return res;
+		}
+		CopyrightInfo oci = copyrightInfoService.selectByPrimaryKey(id);
+		if (oci == null || !oci.getUid().equals(curUser.getId())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "找不到软著", "软著申请"));
+			return res;
+		}
+
+		CopyrightInfo ci = new CopyrightInfo();
+		CopyrightLog cl = new CopyrightLog();
+		BeanUtils.copyProperties(inputInfo, ci);
+		BeanUtils.copyProperties(inputInfo, cl);
+		ci.setId(oci.getId());
+		ci.setUid(oci.getUid());
+		cl.setCid(oci.getId());
+		cl.setOperator(TokenManager.getAdminId());
+		copyrightInfoService.updateByPrimaryKeySelective(ci, cl);
+		res.setData(1);
+		return res;
+	}
+
+	@RequestMapping(value = "/upload", method = RequestMethod.POST)
+	public Result upload(String id, String sign, HttpServletRequest req) {
+		Result res = new Result();
+		if (!checkUserLogin(res)) {
+			return res;
+		}
+		User curUser = TokenManager.getUserToken();
+		if (!checkCertify(res, curUser)) {
+			return res;
+		}
+		if (StringUtils.isEmpty(id)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "软著id"));
+			return res;
+		}
+		CopyrightInfo ci = copyrightInfoService.selectByPrimaryKey(id);
+		if (ci == null || !curUser.getId().equals(ci.getUid())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "软著id"));
+			return res;
+		}
+		AttachmentType attachmentType = AttachmentType.getField(sign);
+		if (attachmentType == AttachmentType.COPYRIGHT_APPLY || attachmentType == AttachmentType.COPYRIGHT_AUTH) {
+			String filePath = handleFile(res, true, req, attachmentType.getCode(), ci.getUid(), ci.getId());
+			if (attachmentType == AttachmentType.COPYRIGHT_APPLY) {
+				ci.setApplicationUrl(filePath);
+			} else if (attachmentType == AttachmentType.COPYRIGHT_AUTH) {
+				ci.setCertificateUrl(filePath);
+			}
+			copyrightInfoService.updateByPrimaryKey(ci);
+			res.setData(filePath);
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+		}
+		return res;
+	}
+
+	@RequestMapping(value = "/list", method = RequestMethod.GET)
+	public Result list(String province, String unitName, String copyrightName, String status, String pageNo,
+			String pageSize, @RequestParam(name = "createTime[]", required = false) String[] createTime,
+			@RequestParam(name = "acceptTime[]", required = false) String[] acceptTime,
+			@RequestParam(name = "authTime[]", required = false) String[] authTime) {
+		Result res = new Result();
+		if (!checkUserLogin(res)) {
+			return res;
+		}
+		res.setData(copyrightInfoService.listMyCopyrightInfo(province, unitName, copyrightName,
+				CopyrightStatus.getStatus(status), createTime, acceptTime, authTime, getPageNo(pageNo),
+				getPageSize(pageSize), TokenManager.getUserId()));
+		return res;
+	}
+
+	@RequestMapping(value = "/detail", method = RequestMethod.GET)
+	public Result detail(String id) {
+		Result res = new Result();
+		if (!checkUserLogin(res)) {
+			return res;
+		}
+		if (StringUtils.isBlank(id)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "公司"));
+		} else {
+			CopyrightInfoDetail cid = copyrightInfoService.findByPrimaryKey(id);
+			if (cid.getUid().equals(TokenManager.getUserId())) {
+				res.setData(cid);
+			} else {
+				res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "公司"));
+			}
+		}
+		return res;
+	}
+
+	@RequestMapping(value = "/logs", method = RequestMethod.GET)
+	public Result logs(String id) {
+		Result res = new Result();
+		if (!checkUserLogin(res)) {
+			return res;
+		}
+		if (StringUtils.isBlank(id)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "软著申请id"));
+			return res;
+		}
+		CopyrightInfo oci = copyrightInfoService.selectByPrimaryKey(id);
+		if (oci == null || !oci.getUid().equals(TokenManager.getUserId())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "软著申请id"));
+			return res;
+		}
+		res.setData(copyrightInfoService.findLogsByPrimaryKey(id));
+		return res;
+	}
+
+	private boolean handleBindingError(Result res, BindingResult bindingResult) {
+		if (bindingResult.hasErrors()) {
+			for (FieldError fe : bindingResult.getFieldErrors()) {
+				Class<?> clazz = bindingResult.getFieldType(fe.getField());
+				if (clazz != null && "java.util.Date".equals(clazz.getName())) {
+					res.getError()
+							.add(buildError(ErrorConstants.PARAM_PATTERN_ERROR, "日期格式错误",
+									CopyrightFields.getFieldDesc(fe.getField()), AFTConstants.YYYYMMDDHHMMSS)
+											.buildField(fe.getField()));
+				} else {
+					res.getError()
+							.add(buildErrorByMsg(fe.getDefaultMessage(), CopyrightFields.getFieldDesc(fe.getField()))
+									.buildField(fe.getField()));
+				}
+			}
+			return true;
+		}
+		return false;
+	}
 }

+ 4 - 0
src/main/java/com/goafanti/copyright/service/CopyrightInfoService.java

@@ -26,6 +26,10 @@ public interface CopyrightInfoService {
 	Pagination<CopyrightInfo> listCopyrightInfo(String province, String unitName, String copyrightName,
 			CopyrightStatus status, String[] createTime, String[] acceptTime, String[] authTime, Integer pageNo,
 			Integer pageSize);
+	
+	Pagination<CopyrightInfo> listMyCopyrightInfo(String province, String unitName, String copyrightName,
+			CopyrightStatus status, String[] createTime, String[] acceptTime, String[] authTime, Integer pageNo,
+			Integer pageSize, String uid);
 
 	List<CopyrightLogBO> findLogsByPrimaryKey(String id);
 

+ 22 - 1
src/main/java/com/goafanti/copyright/service/impl/CopyrightInfoServiceImpl.java

@@ -74,6 +74,24 @@ public class CopyrightInfoServiceImpl extends BaseMybatisDao<CopyrightInfoMapper
 	public Pagination<CopyrightInfo> listCopyrightInfo(String province, String unitName, String copyrightName,
 			CopyrightStatus status, String[] createTime, String[] acceptTime, String[] authTime, Integer pageNo,
 			Integer pageSize) {
+		return (Pagination<CopyrightInfo>) findPage("findListByPage", "findListCount", buildListParams(province,
+				unitName, copyrightName, status, createTime, acceptTime, authTime, pageNo, pageSize, null), pageNo,
+				pageSize);
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Pagination<CopyrightInfo> listMyCopyrightInfo(String province, String unitName, String copyrightName,
+			CopyrightStatus status, String[] createTime, String[] acceptTime, String[] authTime, Integer pageNo,
+			Integer pageSize, String uid) {
+		return (Pagination<CopyrightInfo>) findPage("findListByPage", "findListCount", buildListParams(province,
+				unitName, copyrightName, status, createTime, acceptTime, authTime, pageNo, pageSize, uid), pageNo,
+				pageSize);
+	}
+
+	private Map<String, Object> buildListParams(String province, String unitName, String copyrightName,
+			CopyrightStatus status, String[] createTime, String[] acceptTime, String[] authTime, Integer pageNo,
+			Integer pageSize, String uid) {
 		Map<String, Object> params = new HashMap<>();
 		if (StringUtils.isNotBlank(province)) {
 			params.put("province", province);
@@ -81,6 +99,9 @@ public class CopyrightInfoServiceImpl extends BaseMybatisDao<CopyrightInfoMapper
 		if (StringUtils.isNotBlank(unitName)) {
 			params.put("unitName", unitName);
 		}
+		if (StringUtils.isNotBlank(uid)) {
+			params.put("unitId", uid);
+		}
 		if (StringUtils.isNotBlank(copyrightName)) {
 			params.put("copyrightName", copyrightName);
 		}
@@ -123,7 +144,7 @@ public class CopyrightInfoServiceImpl extends BaseMybatisDao<CopyrightInfoMapper
 			} catch (ParseException e) {
 			}
 		}
-		return (Pagination<CopyrightInfo>) findPage("findListByPage", "findListCount", params, pageNo, pageSize);
+		return params;
 	}
 
 	@Override