Browse Source

合同管理--新增合同时直接提交接口

Antiloveg 8 years ago
parent
commit
bece5e1462

+ 63 - 30
src/main/java/com/goafanti/admin/controller/AdminContractApiController.java

@@ -80,49 +80,82 @@ public class AdminContractApiController extends CertifyApiController {
 		}
 
 		if (null != contract.getCognizanceYear()) {
-			LatelyCogRecord lcr = orgCognizanceService.selectLatelyRecord(contract.getUid());
-			if (null != lcr && null != lcr.getState() && OrgCognizanceStatus.FOSTER.getCode() == lcr.getState()) {
-				res.getError().add(buildError(ErrorConstants.STATUS_ERROR, "高企培育中!无法提交新申请!", "高企培育中!无法提交新申请!"));
+			if (!disposeCog(contract.getUid(), res).getError().isEmpty()) {
 				return res;
 			}
-
-			if (null != lcr && null != lcr.getState() && OrgCognizanceStatus.SETTLEMENT.getCode() != lcr.getState()
-					&& OrgCognizanceStatus.CALLBACK.getCode() != lcr.getState()) {
-				res.getError().add(buildError(ErrorConstants.STATUS_ERROR, "高企申请中!无法提交新申请!", "高企申请中!无法提交新申请!"));
-				return res;
-			}
-
-			if (null != lcr && null != lcr.getState() && OrgCognizanceStatus.SETTLEMENT.getCode() == lcr.getState()) {
-				if (null == lcr.getIssuingDate()) {
-					res.getError().add(buildError(ErrorConstants.STATUS_ERROR, "高企认定未过期!无法提交新申请!", "高企认定未过期!无法提交新申请!"));
-					return res;
-				}
-				try {
-					if (Boolean.FALSE == TimeUtils.checkCogExpire(lcr.getIssuingDate())) {
-						res.getError()
-								.add(buildError(ErrorConstants.STATUS_ERROR, "高企认定未过期,无法提交新申请!", "高企认定未过期,无法提交新申请!"));
-						return res;
-					}
-				} catch (ParseException e) {
-				}
-			}
 		}
-		
+
 		Contract c = new Contract();
 		BeanUtils.copyProperties(contract, c);
-		if (StringUtils.isBlank(contract.getId())) {
-			res.setData(contractService.saveManageContract(c));
-		}
+		res.setData(contractService.saveManageContract(c));
 		return res;
 	}
 
 	/**
-	 * 新增提交合同
+	 * 新增--提交合同
 	 */
 	@RequestMapping(value = "/submit", method = RequestMethod.POST)
-	public Result submitContract(@Valid InputContract ic, BindingResult bindingResult,
+	public Result submitContract(@Valid InputContract ic, BindingResult bindingResult, String recordTimeFormattedDate,
 			@RequestParam(name = "principals[]", required = false) String[] principals) {
 		Result res = new Result();
+		if (principals.length < 1 || null == principals) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到流转分发用户", "流转分发用户"));
+			return res;
+		}
+
+		if (StringUtils.isBlank(recordTimeFormattedDate)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同签订时间", "合同签订时间"));
+			return res;
+		}
+
+		if (StringUtils.isBlank(ic.getUid())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
+			return res;
+		}
+
+		User curUser = userService.selectByPrimaryKey(ic.getUid());
+		if (!checkCertify(res, curUser)) {
+			return res;
+		}
+
+		if (null != ic.getCognizanceYear()) {
+			if (!disposeCog(ic.getUid(), res).getError().isEmpty()) {
+				return res;
+			}
+		}
+
+		Contract c = new Contract();
+		BeanUtils.copyProperties(ic, c);
+		contractService.insertManageSubmit(c, principals);
+		return res;
+	}
+
+	private Result disposeCog(String uid, Result res) {
+		LatelyCogRecord lcr = orgCognizanceService.selectLatelyRecord(uid);
+		if (null != lcr && null != lcr.getState() && OrgCognizanceStatus.FOSTER.getCode() == lcr.getState()) {
+			res.getError().add(buildError(ErrorConstants.STATUS_ERROR, "高企培育中!无法提交新申请!", "高企培育中!无法提交新申请!"));
+			return res;
+		}
+
+		if (null != lcr && null != lcr.getState() && OrgCognizanceStatus.SETTLEMENT.getCode() != lcr.getState()
+				&& OrgCognizanceStatus.CALLBACK.getCode() != lcr.getState()) {
+			res.getError().add(buildError(ErrorConstants.STATUS_ERROR, "高企申请中!无法提交新申请!", "高企申请中!无法提交新申请!"));
+			return res;
+		}
+
+		if (null != lcr && null != lcr.getState() && OrgCognizanceStatus.SETTLEMENT.getCode() == lcr.getState()) {
+			if (null == lcr.getIssuingDate()) {
+				res.getError().add(buildError(ErrorConstants.STATUS_ERROR, "高企认定未过期!无法提交新申请!", "高企认定未过期!无法提交新申请!"));
+				return res;
+			}
+			try {
+				if (Boolean.FALSE == TimeUtils.checkCogExpire(lcr.getIssuingDate())) {
+					res.getError().add(buildError(ErrorConstants.STATUS_ERROR, "高企认定未过期,无法提交新申请!", "高企认定未过期,无法提交新申请!"));
+					return res;
+				}
+			} catch (ParseException e) {
+			}
+		}
 		return res;
 	}
 

+ 2 - 0
src/main/java/com/goafanti/contract/service/ContractService.java

@@ -13,4 +13,6 @@ public interface ContractService {
 
 	int updateContractByManage(Contract contract);
 
+	void insertManageSubmit(Contract c, String[] principals);
+
 }

+ 72 - 10
src/main/java/com/goafanti/contract/service/impl/ContractServiceImpl.java

@@ -13,11 +13,17 @@ import org.springframework.stereotype.Service;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.dao.ContractLogMapper;
 import com.goafanti.common.dao.ContractMapper;
+import com.goafanti.common.dao.NoticeMapper;
+import com.goafanti.common.dao.UserMapper;
 import com.goafanti.common.enums.ContractBusinessStatus;
 import com.goafanti.common.enums.ContractStatus;
 import com.goafanti.common.enums.DeleteStatus;
+import com.goafanti.common.enums.NoticeReadStatus;
+import com.goafanti.common.enums.NoticeStatus;
 import com.goafanti.common.model.Contract;
 import com.goafanti.common.model.ContractLog;
+import com.goafanti.common.model.Notice;
+import com.goafanti.common.model.User;
 import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.contract.bo.ContractManageListBo;
@@ -32,6 +38,10 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 	private ContractMapper		contractMapper;
 	@Autowired
 	private ContractLogMapper	contractLogMapper;
+	@Autowired
+	private UserMapper			userMapper;
+	@Autowired
+	private NoticeMapper		noticeMapper;
 
 	@SuppressWarnings("unchecked")
 	@Override
@@ -58,8 +68,8 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 		if (null != status) {
 			params.put("status", status);
 		}
-		
-		if (!StringUtils.isBlank(uid)){
+
+		if (!StringUtils.isBlank(uid)) {
 			params.put("uid", uid);
 		}
 
@@ -106,34 +116,86 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 
 	@Override
 	public Contract saveManageContract(Contract c) {
+		c.setStatus(ContractStatus.CREATE.getCode());
+		c = disposeContract(c);
+		contractMapper.insert(c);
+		contractLogMapper.insert(disposeContractLog(c));
+		return c;
+	}
+
+	@Override
+	public int updateContractByManage(Contract contract) {
+		return contractMapper.updateByPrimaryKeySelective(contract);
+	}
+
+	@Override
+	public void insertManageSubmit(Contract c, String[] principals) {
+		c.setStatus(ContractStatus.CIRCULATION.getCode());
+		c = disposeContract(c);
+		contractMapper.insert(c);
+		ContractLog clog = disposeContractLog(c);
+		clog.setStatus(ContractStatus.SIGN.getCode());
+		contractLogMapper.insert(clog);
+
+		for (int i = 0; i < principals.length; i++) {
+			ContractLog log = disposeContractLog(c);
+			log.setPrincipal(principals[i]);
+			contractLogMapper.insert(log);
+			createNotice(c, log);
+		}
+	}
+
+	private Contract disposeContract(Contract c) {
 		c.setId(UUID.randomUUID().toString());
 		Calendar now = Calendar.getInstance();
 		now.set(Calendar.MILLISECOND, 0);
 		c.setCreateTime(now.getTime());
 		c.setFounder(TokenManager.getAdminId());
-		c.setStatus(ContractStatus.CREATE.getCode());
+
 		c.setPatentStatus(ContractBusinessStatus.UNCREATE.getCode());
 		c.setCopyrightStatus(ContractBusinessStatus.UNCREATE.getCode());
 		c.setTechProjectStatus(ContractBusinessStatus.UNCREATE.getCode());
 		c.setCognizanceStatus(ContractBusinessStatus.UNCREATE.getCode());
 		c.setDeletedSign(DeleteStatus.UNDELETE.getCode());
-		contractMapper.insert(c);
+		return c;
+	}
 
+	private ContractLog disposeContractLog(Contract c) {
 		ContractLog cl = new ContractLog();
 		cl.setId(UUID.randomUUID().toString());
 		cl.setComment(c.getComment());
 		cl.setOperator(c.getFounder());
 		cl.setPrincipal(c.getFounder());
-		cl.setRecordTime(c.getCreateTime());
+		Calendar now = Calendar.getInstance();
+		now.set(Calendar.MILLISECOND, 0);
+		cl.setRecordTime(now.getTime());
 		cl.setStatus(c.getStatus());
 		cl.setCid(c.getId());
-		contractLogMapper.insert(cl);
-		return c;
+		return cl;
 	}
 
-	@Override
-	public int updateContractByManage(Contract contract) {
-		return contractMapper.updateByPrimaryKeySelective(contract);
+	private void createNotice(Contract c, ContractLog l) {
+		Contract info = contractMapper.selectByPrimaryKey(c.getId());
+
+		Notice n = new Notice();
+		Calendar now = Calendar.getInstance();
+		now.set(Calendar.MILLISECOND, 0);
+		n.setId(UUID.randomUUID().toString());
+		n.setCreateTime(now.getTime());
+		n.setReaded(NoticeReadStatus.UNREAD.getCode());
+
+		User u = userMapper.selectByPrimaryKey(c.getUid());
+		if (null != u) {
+			n.setPid(u.getAid());
+		}
+
+		n.setUid(c.getUid());
+		n.setRid(c.getId());
+
+		n.setAid(l.getPrincipal());
+		n.setContent("编号" + info.getSerialNumber() + "  " + ContractStatus.getStatus(c.getStatus()).getDesc());
+		n.setNoticeType(NoticeStatus.TECHPROJECT.getCode());
+		noticeMapper.insert(n);
 	}
 
 }