ContractApiController.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. package com.goafanti.contract.controller;
  2. import java.util.Arrays;
  3. import java.util.Iterator;
  4. import java.util.List;
  5. import javax.annotation.Resource;
  6. import javax.validation.Valid;
  7. import org.springframework.beans.BeanUtils;
  8. import org.springframework.validation.BindingResult;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RequestParam;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import com.goafanti.cognizance.service.OrgCognizanceService;
  14. import com.goafanti.common.bo.Result;
  15. import com.goafanti.common.constant.ErrorConstants;
  16. import com.goafanti.common.controller.CertifyApiController;
  17. import com.goafanti.common.enums.ContractFields;
  18. import com.goafanti.common.enums.ContractStatus;
  19. import com.goafanti.common.model.Contract;
  20. import com.goafanti.common.model.ContractLog;
  21. import com.goafanti.common.model.User;
  22. import com.goafanti.common.utils.StringUtils;
  23. import com.goafanti.contract.bo.InputSaveContract;
  24. import com.goafanti.contract.service.ContractLogService;
  25. import com.goafanti.contract.service.ContractService;
  26. import com.goafanti.copyright.service.CopyrightInfoService;
  27. import com.goafanti.core.shiro.token.TokenManager;
  28. import com.goafanti.patent.service.PatentInfoService;
  29. import com.goafanti.techproject.service.TechProjectService;
  30. @RestController
  31. @RequestMapping(value = "/api/user/contract")
  32. public class ContractApiController extends CertifyApiController {
  33. @Resource
  34. private ContractService contractService;
  35. @Resource
  36. private OrgCognizanceService orgCognizanceService;
  37. @Resource
  38. private ContractLogService contractLogService;
  39. @Resource
  40. private CopyrightInfoService copyrightInfoService;
  41. @Resource
  42. private TechProjectService techProjectService;
  43. @Resource
  44. private PatentInfoService patentInfoService;
  45. /**
  46. * 合同详情-科技项目列表
  47. */
  48. @RequestMapping(value = "/techProject", method = RequestMethod.GET)
  49. public Result listTechProject(String contractId) {
  50. Result res = new Result();
  51. if (StringUtils.isBlank(contractId)) {
  52. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  53. return res;
  54. }
  55. res.setData(techProjectService.listContractTechProjectByContractId(contractId));
  56. return res;
  57. }
  58. /**
  59. * 合同详情-高企记录
  60. */
  61. @RequestMapping(value = "/cognizance", method = RequestMethod.GET)
  62. public Result cognizance(String contractId) {
  63. Result res = new Result();
  64. if (StringUtils.isBlank(contractId)) {
  65. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  66. return res;
  67. }
  68. res.setData(orgCognizanceService.selectContractCognizanceByContractId(contractId));
  69. return res;
  70. }
  71. /**
  72. * 合同详情-软著列表
  73. */
  74. @RequestMapping(value = "/copyright", method = RequestMethod.GET)
  75. public Result listCopyright(String contractId) {
  76. Result res = new Result();
  77. if (StringUtils.isBlank(contractId)) {
  78. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  79. return res;
  80. }
  81. res.setData(copyrightInfoService.listContractCopyrightByContractId(contractId));
  82. return res;
  83. }
  84. /**
  85. * 合同详情-专利列表
  86. */
  87. @RequestMapping(value = "/patent", method = RequestMethod.GET)
  88. public Result listPatent(String contractId) {
  89. Result res = new Result();
  90. if (StringUtils.isBlank(contractId)) {
  91. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  92. return res;
  93. }
  94. res.setData(patentInfoService.listContractPatentByContractId(contractId));
  95. return res;
  96. }
  97. /**
  98. * 合同流转日志
  99. */
  100. @RequestMapping(value = "/log", method = RequestMethod.GET)
  101. public Result log(String cid) {
  102. Result res = new Result();
  103. if (StringUtils.isBlank(cid)) {
  104. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  105. return res;
  106. }
  107. List<ContractLog> list = contractLogService.selectContractLogByCid(cid);
  108. for (Iterator<ContractLog> log = list.iterator(); log.hasNext();) {
  109. Integer status = log.next().getStatus();
  110. if (ContractStatus.getStatus(status) == ContractStatus.CIRCULATION) {
  111. log.remove();
  112. }
  113. }
  114. res.setData(list);
  115. return res;
  116. }
  117. /**
  118. * 合同详情
  119. */
  120. @RequestMapping(value = "/detail", method = RequestMethod.GET)
  121. public Result detail(String id) {
  122. Result res = new Result();
  123. if (StringUtils.isBlank(id)) {
  124. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  125. return res;
  126. }
  127. res.setData(contractService.selectContractDetail(id));
  128. return res;
  129. }
  130. /**
  131. * 批量删除合同
  132. */
  133. @RequestMapping(value = "/delete", method = RequestMethod.POST)
  134. public Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
  135. Result res = new Result();
  136. if (ids == null || ids.length < 1) {
  137. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
  138. } else {
  139. res.setData(contractService.deleteByPrimaryKey(Arrays.asList(ids)));
  140. }
  141. return res;
  142. }
  143. /**
  144. * 修改合同
  145. */
  146. @RequestMapping(value = "/update", method = RequestMethod.POST)
  147. public Result update(@Valid InputSaveContract contract, BindingResult bindingResult) {
  148. Result res = new Result();
  149. if (bindingResult.hasErrors()) {
  150. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  151. ContractFields.getFieldDesc(bindingResult.getFieldError().getField())));
  152. return res;
  153. }
  154. User curUser = TokenManager.getUserToken();
  155. if (!checkCertify(res, curUser)) {
  156. return res;
  157. }
  158. if (StringUtils.isBlank(contract.getId())) {
  159. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  160. return res;
  161. }
  162. if (null != contract.getCognizanceYear() && !contract.getCognizanceYear().equals(0)) {
  163. if (!disposeCog(contract.getCognizanceYear(), contract.getUid(), res).getError().isEmpty()) {
  164. return res;
  165. }
  166. }
  167. Contract c = new Contract();
  168. BeanUtils.copyProperties(contract, c);
  169. Contract ct = contractService.selectByPrimaryKey(c.getId());
  170. if (null != ct && !ContractStatus.COMPLETE.getCode().equals(ct.getStatus())) {
  171. res.setData(contractService.updateByPrimaryKeySelective(c));
  172. } else {
  173. res.getError().add(buildError("", "当前合同已完成(结款),无法操作!"));
  174. }
  175. return res;
  176. }
  177. /**
  178. * 提交申请新合同
  179. */
  180. @RequestMapping(value = "/apply", method = RequestMethod.POST)
  181. public Result apply(@Valid InputSaveContract contract, BindingResult bindingResult) {
  182. Result res = new Result();
  183. if (bindingResult.hasErrors()) {
  184. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  185. ContractFields.getFieldDesc(bindingResult.getFieldError().getField())));
  186. return res;
  187. }
  188. User curUser = TokenManager.getUserToken();
  189. if (!checkCertify(res, curUser)) {
  190. return res;
  191. }
  192. if (null != contract.getCognizanceYear() && !contract.getCognizanceYear().equals(0)) {
  193. if (!disposeCog(contract.getCognizanceYear(), contract.getUid(), res).getError().isEmpty()) {
  194. return res;
  195. }
  196. }
  197. Contract c = new Contract();
  198. BeanUtils.copyProperties(contract, c);
  199. contractService.saveContract(c);
  200. return res;
  201. }
  202. /**
  203. * 合同列表
  204. */
  205. @RequestMapping(value = "/list", method = RequestMethod.GET)
  206. public Result listContract(String contractId, Integer serialNumber, Integer type, Integer status,
  207. String startDateFormattedDate, String endDateFormattedDate, String completeStartDate,
  208. String completeEndDate, String pageNo, String pageSize) {
  209. Result res = new Result();
  210. Integer pNo = 1;
  211. Integer pSize = 10;
  212. if (StringUtils.isNumeric(pageSize)) {
  213. pSize = Integer.parseInt(pageSize);
  214. }
  215. if (StringUtils.isNumeric(pageNo)) {
  216. pNo = Integer.parseInt(pageNo);
  217. }
  218. res.setData(contractService.getClientList(contractId, serialNumber, type, status, startDateFormattedDate,
  219. endDateFormattedDate, completeStartDate, completeEndDate, pNo, pSize));
  220. return res;
  221. }
  222. private Result disposeCog(Integer year, String uid, Result res) {
  223. Integer latelyYear = orgCognizanceService.selectLatelyRecordYear(uid);
  224. if (null != latelyYear && year - latelyYear < 4) {
  225. res.getError()
  226. .add(buildError(ErrorConstants.STATUS_ERROR, "高企认定申请中或认定未到期!无法提交新申请!", "高企认定申请中或认定未到期!无法提交新申请!"));
  227. return res;
  228. }
  229. Contract c = contractService.findByUidAndYear(uid, year);
  230. if (null != c) {
  231. res.getError().add(buildError("", "当前年份已有合同申请,无法提交新申请!"));
  232. }
  233. return res;
  234. }
  235. }