AdminContractApiController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. package com.goafanti.admin.controller;
  2. import java.util.Map;
  3. import java.util.TreeMap;
  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.admin.service.AdminService;
  13. import com.goafanti.cognizance.service.OrgCognizanceService;
  14. import com.goafanti.common.bo.Result;
  15. import com.goafanti.common.constant.AFTConstants;
  16. import com.goafanti.common.constant.ErrorConstants;
  17. import com.goafanti.common.controller.CertifyApiController;
  18. import com.goafanti.common.enums.ContractBusinessStatus;
  19. import com.goafanti.common.enums.ContractFields;
  20. import com.goafanti.common.enums.ContractLogFields;
  21. import com.goafanti.common.enums.ContractStatus;
  22. import com.goafanti.common.model.Contract;
  23. import com.goafanti.common.model.User;
  24. import com.goafanti.common.utils.StringUtils;
  25. import com.goafanti.contract.bo.InputContactLog;
  26. import com.goafanti.contract.bo.InputContract;
  27. import com.goafanti.contract.bo.InputSaveContract;
  28. import com.goafanti.contract.service.ContractLogService;
  29. import com.goafanti.contract.service.ContractService;
  30. import com.goafanti.copyright.service.CopyrightInfoService;
  31. import com.goafanti.core.shiro.token.TokenManager;
  32. import com.goafanti.patent.service.PatentInfoService;
  33. import com.goafanti.techproject.service.TechProjectService;
  34. import com.goafanti.user.service.UserService;
  35. @RestController
  36. @RequestMapping(value = "/api/admin/contract")
  37. public class AdminContractApiController extends CertifyApiController {
  38. @Resource
  39. private ContractService contractService;
  40. @Resource
  41. private ContractLogService contractLogService;
  42. @Resource
  43. private UserService userService;
  44. @Resource
  45. private OrgCognizanceService orgCognizanceService;
  46. @Resource
  47. private AdminService adminService;
  48. @Resource
  49. private PatentInfoService patentInfoService;
  50. @Resource
  51. private CopyrightInfoService copyrightInfoService;
  52. @Resource
  53. private TechProjectService techProjectService;
  54. /**
  55. * 合同编号下拉
  56. */
  57. @RequestMapping(value= "/serialNumber", method = RequestMethod.GET)
  58. public Result contractSerialNumber(){
  59. Result res = new Result();
  60. res.setData(contractService.selectContractSerialNumber());
  61. return res;
  62. }
  63. /**
  64. * 合同管理--创建高企认定申请
  65. */
  66. @RequestMapping(value = "/createCognizance", method = RequestMethod.POST)
  67. public Result createCognizance(String id) {
  68. Result res = new Result();
  69. if (StringUtils.isBlank(id)) {
  70. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  71. return res;
  72. }
  73. Contract c = contractService.selectByPrimaryKey(id);
  74. if (null == c) {
  75. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "合同ID"));
  76. return res;
  77. }
  78. if (!c.getCognizanceStatus().equals(ContractBusinessStatus.UNCREATE.getCode())) {
  79. res.getError().add(buildError(ErrorConstants.CONTRACT_COGNIZANCE_CREATED, "", "当前合同高企认定申请已创建,无法重复创建!"));
  80. return res;
  81. }
  82. if (null == c.getCognizanceYear() || c.getCognizanceYear().equals(0)) {
  83. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到高企认定申请年份", "高企认定申请年份"));
  84. return res;
  85. }
  86. if (null != c.getCognizanceYear() && !c.getCognizanceYear().equals(0)) {
  87. if (!disposeCog(c.getCognizanceYear(), c.getUid(), res).getError().isEmpty()) {
  88. return res;
  89. }
  90. }
  91. orgCognizanceService.insertContractRecord(c);
  92. return res;
  93. }
  94. /**
  95. * 合同管理--批量创建科技项目
  96. */
  97. @RequestMapping(value = "/createTechProject", method = RequestMethod.POST)
  98. public Result createTechProject(String id) {
  99. Result res = new Result();
  100. if (StringUtils.isBlank(id)) {
  101. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  102. return res;
  103. }
  104. Contract c = contractService.selectByPrimaryKey(id);
  105. if (null == c) {
  106. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "合同ID"));
  107. return res;
  108. }
  109. if (!c.getTechProjectStatus().equals(ContractBusinessStatus.UNCREATE.getCode())) {
  110. res.getError().add(buildError(ErrorConstants.CONTRACT_TECHPROJECT_CREATED, "", "当前合同科技项目申请已创建,无法重复创建!"));
  111. return res;
  112. }
  113. if (c.getTechProjectNum() >= 1 && c.getTechProjectNum() <= 30) {
  114. techProjectService.batchInsertContractRecord(c);
  115. } else {
  116. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "软著数量"));
  117. }
  118. return res;
  119. }
  120. /**
  121. * 合同管理--批量创建软著
  122. */
  123. @RequestMapping(value = "/createCopyright", method = RequestMethod.POST)
  124. public Result createCopyright(String id) {
  125. Result res = new Result();
  126. if (StringUtils.isBlank(id)) {
  127. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  128. return res;
  129. }
  130. Contract c = contractService.selectByPrimaryKey(id);
  131. if (null == c) {
  132. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "合同ID"));
  133. return res;
  134. }
  135. if (!c.getCopyrightStatus().equals(ContractBusinessStatus.UNCREATE.getCode())) {
  136. res.getError().add(buildError(ErrorConstants.CONTRACT_COPYRIGHT_CREATED, "", "当前合同软著申请已创建,无法重复创建!"));
  137. return res;
  138. }
  139. if (c.getCopyrightNum() >= 1 && c.getCopyrightNum() <= 30) {
  140. copyrightInfoService.batchInsertContractRecord(c);
  141. } else {
  142. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "软著数量"));
  143. }
  144. return res;
  145. }
  146. /**
  147. * 合同管理--创建专利
  148. */
  149. @RequestMapping(value = "/createPatent", method = RequestMethod.POST)
  150. public Result createPatent(String id) {
  151. Result res = new Result();
  152. if (StringUtils.isBlank(id)) {
  153. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  154. return res;
  155. }
  156. Contract c = contractService.selectByPrimaryKey(id);
  157. if (null == c) {
  158. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "合同ID"));
  159. return res;
  160. }
  161. if (!c.getPatentStatus().equals(ContractBusinessStatus.UNCREATE.getCode())) {
  162. res.getError().add(buildError(ErrorConstants.CONTRACT_PATENT_CREATED, "", "当前合同专利申请已创建,无法重复创建!"));
  163. return res;
  164. }
  165. if (c.getPatentNum() >= 1 && c.getPatentNum() <= 30) {
  166. patentInfoService.batchInsertContractRecord(c);
  167. } else {
  168. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "专利数量"));
  169. }
  170. return res;
  171. }
  172. /**
  173. * 合同详情-科技项目列表
  174. */
  175. @RequestMapping(value = "/techProject", method = RequestMethod.GET)
  176. public Result listTechProject(String contractId) {
  177. Result res = new Result();
  178. if (StringUtils.isBlank(contractId)) {
  179. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  180. return res;
  181. }
  182. res.setData(techProjectService.listContractTechProjectByContractId(contractId));
  183. return res;
  184. }
  185. /**
  186. * 合同详情-高企记录
  187. */
  188. @RequestMapping(value = "/cognizance", method = RequestMethod.GET)
  189. public Result cognizance(String contractId) {
  190. Result res = new Result();
  191. if (StringUtils.isBlank(contractId)) {
  192. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  193. return res;
  194. }
  195. res.setData(orgCognizanceService.selectContractCognizanceByContractId(contractId));
  196. return res;
  197. }
  198. /**
  199. * 合同详情-软著列表
  200. */
  201. @RequestMapping(value = "/copyright", method = RequestMethod.GET)
  202. public Result listCopyright(String contractId) {
  203. Result res = new Result();
  204. if (StringUtils.isBlank(contractId)) {
  205. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  206. return res;
  207. }
  208. res.setData(copyrightInfoService.listContractCopyrightByContractId(contractId));
  209. return res;
  210. }
  211. /**
  212. * 合同详情-专利列表
  213. */
  214. @RequestMapping(value = "/patent", method = RequestMethod.GET)
  215. public Result listPatent(String contractId) {
  216. Result res = new Result();
  217. if (StringUtils.isBlank(contractId)) {
  218. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  219. return res;
  220. }
  221. res.setData(patentInfoService.listContractPatentByContractId(contractId));
  222. return res;
  223. }
  224. /**
  225. * 合同分发流转人员下拉
  226. */
  227. @RequestMapping(value = "/principal", method = RequestMethod.GET)
  228. public Result getPrincipal() {
  229. Result res = new Result();
  230. res.setData(adminService.selectContractManager());
  231. return res;
  232. }
  233. /**
  234. * 合同列表
  235. */
  236. @RequestMapping(value = "/list", method = RequestMethod.GET)
  237. public Result listContract(String contractId, Integer serialNumber, Integer type, Integer status, String startDateFormattedDate,
  238. String endDateFormattedDate, String province, String unitName, String uid, String pageNo, String pageSize) {
  239. Result res = new Result();
  240. Integer pNo = 1;
  241. Integer pSize = 10;
  242. if (StringUtils.isNumeric(pageSize)) {
  243. pSize = Integer.parseInt(pageSize);
  244. }
  245. if (StringUtils.isNumeric(pageNo)) {
  246. pNo = Integer.parseInt(pageNo);
  247. }
  248. res.setData(contractService.getManageList(contractId, serialNumber, type, status, startDateFormattedDate,
  249. endDateFormattedDate, province, unitName, uid, pNo, pSize));
  250. return res;
  251. }
  252. /**
  253. * 新增合同(保存)
  254. */
  255. @RequestMapping(value = "/apply", method = RequestMethod.POST)
  256. public Result applyContract(@Valid InputSaveContract contract, BindingResult bindingResult) {
  257. Result res = new Result();
  258. if (bindingResult.hasErrors()) {
  259. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  260. ContractFields.getFieldDesc(bindingResult.getFieldError().getField())));
  261. return res;
  262. }
  263. if (StringUtils.isBlank(contract.getUid())) {
  264. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  265. return res;
  266. }
  267. User curUser = userService.selectByPrimaryKey(contract.getUid());
  268. if (!checkCertify(res, curUser)) {
  269. return res;
  270. }
  271. if (null != contract.getCognizanceYear() && !contract.getCognizanceYear().equals(0)) {
  272. if (!disposeCog(contract.getCognizanceYear(), contract.getUid(), res).getError().isEmpty()) {
  273. return res;
  274. }
  275. }
  276. Contract c = new Contract();
  277. BeanUtils.copyProperties(contract, c);
  278. if (StringUtils.isBlank(contract.getId())) {
  279. res.setData(contractService.saveManageContract(c));
  280. } else {
  281. res.setData(contractService.updateByPrimaryKeySelective(c));
  282. }
  283. return res;
  284. }
  285. /**
  286. * 新增--提交合同
  287. */
  288. @RequestMapping(value = "/submit", method = RequestMethod.POST)
  289. public Result submitContract(@Valid InputContract ic, BindingResult bindingResult, String signDateFormattedDate,
  290. @RequestParam(name = "principals[]", required = false) String[] principals) {
  291. Result res = new Result();
  292. if (principals.length < 1 || null == principals) {
  293. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到流转分发用户", "流转分发用户"));
  294. return res;
  295. }
  296. if (StringUtils.isBlank(signDateFormattedDate)) {
  297. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同签订时间", "合同签订时间"));
  298. return res;
  299. }
  300. if (StringUtils.isBlank(ic.getUid())) {
  301. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  302. return res;
  303. }
  304. User curUser = userService.selectByPrimaryKey(ic.getUid());
  305. if (!checkCertify(res, curUser)) {
  306. return res;
  307. }
  308. if (null != ic.getCognizanceYear() && !ic.getCognizanceYear().equals(0)) {
  309. if (!disposeCog(ic.getCognizanceYear(), ic.getUid(), res).getError().isEmpty()) {
  310. return res;
  311. }
  312. }
  313. Contract c = new Contract();
  314. BeanUtils.copyProperties(ic, c);
  315. if (StringUtils.isBlank(ic.getId())) {
  316. contractService.insertManageSubmit(c, principals, signDateFormattedDate);
  317. } else {
  318. contractService.updateSubmit(c, principals, signDateFormattedDate);
  319. }
  320. return res;
  321. }
  322. /**
  323. * 合同详情
  324. */
  325. @RequestMapping(value = "/detail", method = RequestMethod.GET)
  326. public Result detail(String id) {
  327. Result res = new Result();
  328. if (StringUtils.isBlank(id)) {
  329. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  330. return res;
  331. }
  332. res.setData(contractService.selectContractDetail(id));
  333. return res;
  334. }
  335. /**
  336. * 合同流转日志
  337. */
  338. @RequestMapping(value = "/log", method = RequestMethod.GET)
  339. public Result log(String cid) {
  340. Result res = new Result();
  341. if (StringUtils.isBlank(cid)) {
  342. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  343. return res;
  344. }
  345. res.setData(contractLogService.selectContractLogByCid(cid));
  346. return res;
  347. }
  348. /**
  349. * 合同流转状态下拉
  350. */
  351. @RequestMapping(value = "/status", method = RequestMethod.GET)
  352. public Result status() {
  353. Result res = new Result();
  354. res.setData(disposeStatus());
  355. return res;
  356. }
  357. /**
  358. * 流转分发
  359. */
  360. @RequestMapping(value = "/circulation", method = RequestMethod.POST)
  361. public Result circulation(@Valid InputContactLog icl, BindingResult bindingResult, String recordTimeFormattedDate,
  362. @RequestParam(name = "principals[]", required = false) String[] principals) {
  363. Result res = new Result();
  364. if (bindingResult.hasErrors()) {
  365. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  366. ContractLogFields.getFieldDesc(bindingResult.getFieldError().getField())));
  367. return res;
  368. }
  369. if (StringUtils.isBlank(recordTimeFormattedDate)) {
  370. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到流转分发时间", "流转分发时间"));
  371. return res;
  372. }
  373. if (principals.length < 1 || null == principals) {
  374. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到流转分发用户", "流转分发用户"));
  375. return res;
  376. }
  377. if (StringUtils.isBlank(icl.getCid())) {
  378. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
  379. return res;
  380. }
  381. if (null == icl.getStatus()) {
  382. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同流转分发状态", "合同流转分发状态"));
  383. return res;
  384. }
  385. contractLogService.insertCirculation(icl, principals, recordTimeFormattedDate);
  386. return res;
  387. }
  388. private Result disposeCog(Integer year, String uid, Result res) {
  389. Integer latelyYear = orgCognizanceService.selectLatelyRecordYear(uid);
  390. if (null != latelyYear && year - latelyYear < 4) {
  391. res.getError()
  392. .add(buildError(ErrorConstants.STATUS_ERROR, "高企认定申请中或认定未到期!无法提交新申请!", "高企认定申请中或认定未到期!无法提交新申请!"));
  393. return res;
  394. }
  395. return res;
  396. }
  397. private Object disposeStatus() {
  398. Map<String, String> status = new TreeMap<String, String>();
  399. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  400. for (ContractStatus p : ContractStatus.values()) {
  401. status.put(p.getCode().toString(), p.getDesc());
  402. status.remove(ContractStatus.OTHER.getCode().toString());
  403. }
  404. } else {
  405. if (TokenManager.hasPermission("ContractStatus" + ContractStatus.CREATE.getCode())) {
  406. status.put(ContractStatus.CREATE.getCode().toString(), ContractStatus.CREATE.getDesc());
  407. }
  408. if (TokenManager.hasPermission("ContractStatus" + ContractStatus.SIGN.getCode())) {
  409. status.put(ContractStatus.SIGN.getCode().toString(), ContractStatus.SIGN.getDesc());
  410. }
  411. if (TokenManager.hasPermission("ContractStatus" + ContractStatus.CIRCULATION.getCode())) {
  412. status.put(ContractStatus.CIRCULATION.getCode().toString(), ContractStatus.CIRCULATION.getDesc());
  413. }
  414. if (TokenManager.hasPermission("ContractStatus" + ContractStatus.COMPLETE.getCode())) {
  415. status.put(ContractStatus.COMPLETE.getCode().toString(), ContractStatus.COMPLETE.getDesc());
  416. }
  417. }
  418. return status;
  419. }
  420. }