ContractApiController.java 8.2 KB

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