UserContractApiController.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 UserContractApiController 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. private static final Integer SECTION_YEAR = 4;
  46. /**
  47. * 合同详情-科技项目列表
  48. */
  49. @RequestMapping(value = "/techProject", method = RequestMethod.GET)
  50. public Result listTechProject(String contractId) {
  51. Result res = new Result();
  52. if (StringUtils.isBlank(contractId)) {
  53. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  54. return res;
  55. }
  56. res.setData(techProjectService.listContractTechProjectByContractId(contractId));
  57. return res;
  58. }
  59. /**
  60. * 合同详情-高企记录
  61. */
  62. @RequestMapping(value = "/cognizance", method = RequestMethod.GET)
  63. public Result cognizance(String contractId) {
  64. Result res = new Result();
  65. if (StringUtils.isBlank(contractId)) {
  66. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  67. return res;
  68. }
  69. res.setData(orgCognizanceService.selectContractCognizanceByContractId(contractId));
  70. return res;
  71. }
  72. /**
  73. * 合同详情-软著列表
  74. */
  75. @RequestMapping(value = "/copyright", method = RequestMethod.GET)
  76. public Result listCopyright(String contractId) {
  77. Result res = new Result();
  78. if (StringUtils.isBlank(contractId)) {
  79. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  80. return res;
  81. }
  82. res.setData(copyrightInfoService.listContractCopyrightByContractId(contractId));
  83. return res;
  84. }
  85. /**
  86. * 合同详情-专利列表
  87. */
  88. @RequestMapping(value = "/patent", method = RequestMethod.GET)
  89. public Result listPatent(String contractId) {
  90. Result res = new Result();
  91. if (StringUtils.isBlank(contractId)) {
  92. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  93. return res;
  94. }
  95. res.setData(patentInfoService.listContractPatentByContractId(contractId));
  96. return res;
  97. }
  98. /**
  99. * 合同流转日志
  100. */
  101. @RequestMapping(value = "/log", method = RequestMethod.GET)
  102. public Result log(String cid) {
  103. Result res = new Result();
  104. if (StringUtils.isBlank(cid)) {
  105. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  106. return res;
  107. }
  108. List<ContractLog> list = contractLogService.selectContractLogByCid(cid);
  109. for (Iterator<ContractLog> log = list.iterator(); log.hasNext();) {
  110. Integer status = log.next().getStatus();
  111. if (ContractStatus.getStatus(status) == ContractStatus.CIRCULATION) {
  112. log.remove();
  113. }
  114. }
  115. res.setData(list);
  116. return res;
  117. }
  118. /**
  119. * 合同详情
  120. */
  121. @RequestMapping(value = "/detail", method = RequestMethod.GET)
  122. public Result detail(String id) {
  123. Result res = new Result();
  124. if (StringUtils.isBlank(id)) {
  125. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  126. return res;
  127. }
  128. res.setData(contractService.selectContractDetail(id));
  129. return res;
  130. }
  131. /**
  132. * 批量删除合同
  133. */
  134. @RequestMapping(value = "/delete", method = RequestMethod.POST)
  135. public Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
  136. Result res = new Result();
  137. if (ids == null || ids.length < 1) {
  138. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
  139. } else {
  140. res.setData(contractService.deleteByPrimaryKey(Arrays.asList(ids)));
  141. }
  142. return res;
  143. }
  144. /**
  145. * 修改合同
  146. */
  147. @RequestMapping(value = "/update", method = RequestMethod.POST)
  148. public Result update(@Valid InputSaveContract contract, BindingResult bindingResult) {
  149. Result res = new Result();
  150. if (bindingResult.hasErrors()) {
  151. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  152. ContractFields.getFieldDesc(bindingResult.getFieldError().getField())));
  153. return res;
  154. }
  155. User curUser = TokenManager.getUserToken();
  156. if (!checkCertify(res, curUser)) {
  157. return res;
  158. }
  159. if (StringUtils.isBlank(contract.getId())) {
  160. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  161. return res;
  162. }
  163. if (null == contract.getType()) {
  164. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "合同类型"));
  165. return res;
  166. }
  167. if (null != contract.getCognizanceYear() && !contract.getCognizanceYear().equals(0)) {
  168. if (!disposeCog(contract.getId(), contract.getCognizanceYear(), contract.getUid(), res).getError()
  169. .isEmpty()) {
  170. return res;
  171. }
  172. }
  173. Contract c = new Contract();
  174. BeanUtils.copyProperties(contract, c);
  175. Contract ct = contractService.selectByPrimaryKey(c.getId());
  176. if (null != ct && ContractStatus.CREATE.getCode().equals(ct.getStatus())) {
  177. res.setData(contractService.updateByPrimaryKeySelective(c));
  178. } else {
  179. res.getError().add(buildError("", "当前合同为非草稿状态,无法操作!"));
  180. }
  181. return res;
  182. }
  183. /**
  184. * 提交申请新合同
  185. */
  186. @RequestMapping(value = "/apply", method = RequestMethod.POST)
  187. public Result apply(@Valid InputSaveContract contract, BindingResult bindingResult) {
  188. Result res = new Result();
  189. if (bindingResult.hasErrors()) {
  190. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  191. ContractFields.getFieldDesc(bindingResult.getFieldError().getField())));
  192. return res;
  193. }
  194. if (null == contract.getType()) {
  195. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "合同类型"));
  196. return res;
  197. }
  198. User curUser = TokenManager.getUserToken();
  199. if (!checkCertify(res, curUser)) {
  200. return res;
  201. }
  202. if (null != contract.getCognizanceYear() && !contract.getCognizanceYear().equals(0)) {
  203. if (!disposeCog(null, contract.getCognizanceYear(), contract.getUid(), res).getError().isEmpty()) {
  204. return res;
  205. }
  206. }
  207. Contract c = new Contract();
  208. BeanUtils.copyProperties(contract, c);
  209. contractService.saveContract(c);
  210. return res;
  211. }
  212. /**
  213. * 合同列表
  214. */
  215. @RequestMapping(value = "/list", method = RequestMethod.GET)
  216. public Result listContract(String contractId, Integer serialNumber, Integer type, Integer status,
  217. String startDateFormattedDate, String endDateFormattedDate, String completeStartDate,
  218. String completeEndDate, String pageNo, String pageSize) {
  219. Result res = new Result();
  220. Integer pNo = 1;
  221. Integer pSize = 10;
  222. if (StringUtils.isNumeric(pageSize)) {
  223. pSize = Integer.parseInt(pageSize);
  224. }
  225. if (StringUtils.isNumeric(pageNo)) {
  226. pNo = Integer.parseInt(pageNo);
  227. }
  228. res.setData(contractService.getClientList(contractId, serialNumber, type, status, startDateFormattedDate,
  229. endDateFormattedDate, completeStartDate, completeEndDate, pNo, pSize));
  230. return res;
  231. }
  232. //to udpate 18
  233. @SuppressWarnings("unused")
  234. private Result disposeCog(String id, Integer year, String uid, Result res) {
  235. Integer latelyYear = orgCognizanceService.selectLatelyRecordYear(uid);
  236. if (null != latelyYear && year - latelyYear < SECTION_YEAR) {
  237. res.getError()
  238. .add(buildError(ErrorConstants.STATUS_ERROR, "高企认定申请中或认定未到期!无法提交新申请!", "高企认定申请中或认定未到期!无法提交新申请!"));
  239. return res;
  240. }
  241. Contract c = contractService.findLatelyRecordByUid(uid);
  242. boolean flag = Boolean.TRUE;
  243. /* if (null != c) {
  244. if (StringUtils.isNotBlank(id)) {
  245. if (null != c.getCognizanceYear() && year - c.getCognizanceYear() < SECTION_YEAR && !id.equals(c.getId())) {
  246. flag = false;
  247. }
  248. } else {
  249. if (null != c.getCognizanceYear() && year - c.getCognizanceYear() < SECTION_YEAR) {
  250. flag = false;
  251. }
  252. }
  253. }*/
  254. if (!flag) {
  255. res.getError().add(buildError(ErrorConstants.CONTRACT_YEAR_SECTION));
  256. }
  257. return res;
  258. }
  259. }