Browse Source

合同管理客户端--CRUD

Antiloveg 8 years ago
parent
commit
e7736f8bfb

+ 0 - 2
src/main/java/com/goafanti/common/mapper/UserAbilityMapper.xml

@@ -30,8 +30,6 @@
     #{intellectRight,jdbcType=VARCHAR}, #{scienceAchievement,jdbcType=VARCHAR}, 
     #{researchInnovation,jdbcType=VARCHAR}, #{personnel,jdbcType=VARCHAR}
       )
-       ON DUPLICATE KEY UPDATE
-       uid = values(uid)
   </insert>
   <insert id="insertSelective" parameterType="com.goafanti.common.model.UserAbility" >
     insert into user_ability

+ 104 - 10
src/main/java/com/goafanti/contract/controller/ContractApiController.java

@@ -1,5 +1,8 @@
 package com.goafanti.contract.controller;
 
+import java.util.Arrays;
+import java.util.List;
+
 import javax.annotation.Resource;
 import javax.validation.Valid;
 
@@ -7,6 +10,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.validation.BindingResult;
 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.cognizance.service.OrgCognizanceService;
@@ -14,25 +18,113 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.enums.ContractFields;
+import com.goafanti.common.enums.ContractStatus;
 import com.goafanti.common.model.Contract;
+import com.goafanti.common.model.ContractLog;
 import com.goafanti.common.model.User;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.contract.bo.InputSaveContract;
+import com.goafanti.contract.service.ContractLogService;
 import com.goafanti.contract.service.ContractService;
 import com.goafanti.core.shiro.token.TokenManager;
+
 @RestController
 @RequestMapping(value = "/api/user/contract")
-public class ContractApiController extends CertifyApiController{
+public class ContractApiController extends CertifyApiController {
 	@Resource
-	private ContractService contractService;
+	private ContractService			contractService;
 	@Resource
-	private OrgCognizanceService orgCognizanceService;
-	
+	private OrgCognizanceService	orgCognizanceService;
+	@Resource
+	private ContractLogService		contractLogService;
+
+	/**
+	 * 合同流转日志
+	 */
+	@RequestMapping(value = "/log", method = RequestMethod.GET)
+	public Result log(String cid) {
+		Result res = new Result();
+		if (StringUtils.isBlank(cid)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
+			return res;
+		}
+		List<ContractLog> list = contractLogService.selectContractLogByCid(cid);
+		for (ContractLog c : list) {
+			if (ContractStatus.getStatus(c.getStatus()) == ContractStatus.CIRCULATION) {
+				list.remove(c);
+			}
+		}
+		res.setData(list);
+		return res;
+	}
+
+	/**
+	 * 合同详情
+	 */
+	@RequestMapping(value = "/detail", method = RequestMethod.GET)
+	public Result detail(String id) {
+		Result res = new Result();
+		if (StringUtils.isBlank(id)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
+			return res;
+		}
+		res.setData(contractService.selectContractDetail(id));
+		return res;
+	}
+
+	/**
+	 * 批量删除合同
+	 */
+	@RequestMapping(value = "/delete", method = RequestMethod.POST)
+	public Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
+		Result res = new Result();
+		if (ids == null || ids.length < 1) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
+		} else {
+			res.setData(contractService.deleteByPrimaryKey(Arrays.asList(ids)));
+		}
+		return res;
+	}
+
+	/**
+	 * 修改合同
+	 */
+	@RequestMapping(value = "/update", method = RequestMethod.POST)
+	public Result update(@Valid InputSaveContract contract, BindingResult bindingResult) {
+		Result res = new Result();
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					ContractFields.getFieldDesc(bindingResult.getFieldError().getField())));
+			return res;
+		}
+		User curUser = TokenManager.getUserToken();
+		if (!checkCertify(res, curUser)) {
+			return res;
+		}
+
+		if (StringUtils.isBlank(contract.getId())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
+			return res;
+		}
+
+		if (null != contract.getCognizanceYear() && !contract.getCognizanceYear().equals(0)) {
+			if (!disposeCog(contract.getCognizanceYear(), contract.getUid(), res).getError().isEmpty()) {
+				return res;
+			}
+		}
+
+		Contract c = new Contract();
+		BeanUtils.copyProperties(contract, c);
+
+		res.setData(contractService.updateByPrimaryKeySelective(c));
+		return res;
+	}
+
 	/**
 	 * 提交申请新合同
 	 */
 	@RequestMapping(value = "/apply", method = RequestMethod.POST)
-	public Result apply(@Valid InputSaveContract contract, BindingResult bindingResult){
+	public Result apply(@Valid InputSaveContract contract, BindingResult bindingResult) {
 		Result res = new Result();
 		if (bindingResult.hasErrors()) {
 			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
@@ -48,18 +140,20 @@ public class ContractApiController extends CertifyApiController{
 				return res;
 			}
 		}
-		
+
 		Contract c = new Contract();
 		BeanUtils.copyProperties(contract, c);
+
+		contractService.saveContract(c);
 		return res;
 	}
-	
+
 	/**
 	 * 合同列表
 	 */
 	@RequestMapping(value = "/list", method = RequestMethod.GET)
-	public Result listContract(String contractId, Integer serialNumber, Integer type, Integer status, String startDateFormattedDate,
-			String endDateFormattedDate, String pageNo, String pageSize){
+	public Result listContract(String contractId, Integer serialNumber, Integer type, Integer status,
+			String startDateFormattedDate, String endDateFormattedDate, String pageNo, String pageSize) {
 		Result res = new Result();
 		Integer pNo = 1;
 		Integer pSize = 10;
@@ -73,7 +167,7 @@ public class ContractApiController extends CertifyApiController{
 				endDateFormattedDate, pNo, pSize));
 		return res;
 	}
-	
+
 	private Result disposeCog(Integer year, String uid, Result res) {
 		Integer latelyYear = orgCognizanceService.selectLatelyRecordYear(uid);
 		if (null != latelyYear && year - latelyYear < 4) {

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

@@ -35,4 +35,6 @@ public interface ContractService {
 	Pagination<ContractClientListBo> getClientList(String contractId, Integer serialNumber, Integer type, Integer status,
 			String startDateFormattedDate, String endDateFormattedDate, Integer pNo, Integer pSize);
 
+	Contract saveContract(Contract c);
+
 }

+ 61 - 39
src/main/java/com/goafanti/contract/service/impl/ContractServiceImpl.java

@@ -25,6 +25,7 @@ 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.Admin;
 import com.goafanti.common.model.Contract;
 import com.goafanti.common.model.ContractLog;
 import com.goafanti.common.model.Notice;
@@ -53,15 +54,15 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 	@Autowired
 	private PatentInfoMapper	patentInfoMapper;
 	@Autowired
-	private CopyrightInfoMapper copyrightInfoMapper;
+	private CopyrightInfoMapper	copyrightInfoMapper;
 	@Autowired
-	private OrgCognizanceMapper orgCognizanceMapper;
+	private OrgCognizanceMapper	orgCognizanceMapper;
 
 	@SuppressWarnings("unchecked")
 	@Override
-	public Pagination<ContractManageListBo> getManageList(String contractId, Integer serialNumber, Integer type, Integer status,
-			String startDateFormattedDate, String endDateFormattedDate, String province, String unitName, String uid,
-			Integer pNo, Integer pSize) {
+	public Pagination<ContractManageListBo> getManageList(String contractId, Integer serialNumber, Integer type,
+			Integer status, String startDateFormattedDate, String endDateFormattedDate, String province,
+			String unitName, String uid, Integer pNo, Integer pSize) {
 		Date cStart = null;
 		Date cEnd = null;
 
@@ -131,7 +132,7 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 		return (Pagination<ContractManageListBo>) findPage("findManageContractListByPage", "findManageContractCount",
 				params, pNo, pSize);
 	}
-	
+
 	@SuppressWarnings("unchecked")
 	@Override
 	public Pagination<ContractClientListBo> getClientList(String contractId, Integer serialNumber, Integer type,
@@ -141,8 +142,8 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 
 		Map<String, Object> params = new HashMap<>();
 
-        params.put("uid", TokenManager.getUserId());
-        
+		params.put("uid", TokenManager.getUserId());
+
 		if (null != serialNumber) {
 			params.put("serialNumber", serialNumber);
 		}
@@ -239,35 +240,6 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 
 	}
 
-	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.setPatentStatus(ContractBusinessStatus.UNCREATE.getCode());
-		c.setCopyrightStatus(ContractBusinessStatus.UNCREATE.getCode());
-		c.setTechProjectStatus(ContractBusinessStatus.UNCREATE.getCode());
-		c.setCognizanceStatus(ContractBusinessStatus.UNCREATE.getCode());
-		c.setDeletedSign(DeleteStatus.UNDELETE.getCode());
-		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());
-		Calendar now = Calendar.getInstance();
-		now.set(Calendar.MILLISECOND, 0);
-		cl.setRecordTime(now.getTime());
-		cl.setStatus(c.getStatus());
-		cl.setCid(c.getId());
-		return cl;
-	}
-
 	@Override
 	public ContractDetail selectContractDetail(String id) {
 		return contractMapper.selectContractDetail(id);
@@ -286,13 +258,19 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 	@Override
 	public void updateSubmit(Contract c, String[] principals, String signDateFormattedDate) {
 		Date signDate = null;
+		Boolean flag = false;
 		if (!StringUtils.isBlank(signDateFormattedDate)) {
 			try {
 				signDate = DateUtils.parseDate(signDateFormattedDate, AFTConstants.YYYYMMDDHHMMSS);
 			} catch (ParseException e) {
 			}
 		}
-		c.setStatus(ContractStatus.CIRCULATION.getCode());
+		
+		if (null != c.getStatus() && c.getStatus().equals(ContractStatus.CIRCULATION.getCode())) {
+			c.setStatus(ContractStatus.SIGN.getCode());
+			flag = true;
+		}
+		
 		c.setSignDate(signDate);
 		contractMapper.updateByPrimaryKeySelective(c);
 
@@ -301,6 +279,9 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 
 		for (int i = 0; i < principals.length; i++) {
 			ContractLog log = disposeContractLog(c);
+			if (flag){
+				log.setStatus(ContractStatus.CIRCULATION.getCode());
+			}
 			log.setPrincipal(principals[i]);
 			log.setOperator(TokenManager.getAdminId());
 			logs.add(log);
@@ -328,8 +309,31 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 	}
 
 	
-
+	@Override
+	public Contract saveContract(Contract c) {
+		c.setStatus(ContractStatus.CREATE.getCode());
+		c.setUid(TokenManager.getUserId());
+		c = disposeContract(c);
+		contractMapper.insert(c);
+		contractLogMapper.insert(disposeContractLog(c));
+		return c;
+	}
 	
+	private ContractLog disposeContractLog(Contract c) {
+		ContractLog cl = new ContractLog();
+		cl.setId(UUID.randomUUID().toString());
+		cl.setComment(c.getComment());
+		if (TokenManager.getToken() instanceof Admin) {
+			cl.setOperator(c.getFounder());
+			cl.setPrincipal(c.getFounder());
+		}
+		Calendar now = Calendar.getInstance();
+		now.set(Calendar.MILLISECOND, 0);
+		cl.setRecordTime(now.getTime());
+		cl.setStatus(c.getStatus());
+		cl.setCid(c.getId());
+		return cl;
+	}
 	
 	private Notice createNotice(Contract c, ContractLog l) {
 		Contract info = contractMapper.selectByPrimaryKey(c.getId());
@@ -355,4 +359,22 @@ public class ContractServiceImpl extends BaseMybatisDao<ContractMapper> implemen
 		n.setYear(info.getCognizanceYear());
 		return n;
 	}
+	
+	private Contract disposeContract(Contract c) {
+		c.setId(UUID.randomUUID().toString());
+		Calendar now = Calendar.getInstance();
+		now.set(Calendar.MILLISECOND, 0);
+		c.setCreateTime(now.getTime());
+		if (TokenManager.getToken() instanceof Admin) {
+			c.setFounder(TokenManager.getAdminId());
+		}
+
+		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());
+		return c;
+	}
+
 }

+ 0 - 3
src/main/java/com/goafanti/copyright/controller/CopyrightApiController.java

@@ -45,9 +45,6 @@ public class CopyrightApiController extends CertifyApiController {
 		if (handleBindingError(res, bindingResult)) {
 			return res;
 		}
-		if (!checkUserLogin(res)) {
-			return res;
-		}
 		User curUser = TokenManager.getUserToken();
 		if (!checkCertify(res, curUser)) {
 			return res;