PatentInfoServiceImpl.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. package com.goafanti.patent.service.impl;
  2. import java.text.ParseException;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.UUID;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import com.goafanti.common.constant.AFTConstants;
  12. import com.goafanti.common.dao.NoticeMapper;
  13. import com.goafanti.common.dao.OrgIntellectualPropertyMapper;
  14. import com.goafanti.common.dao.PatentCostMapper;
  15. import com.goafanti.common.dao.PatentInfoMapper;
  16. import com.goafanti.common.dao.PatentLogMapper;
  17. import com.goafanti.common.dao.PatentRegistrationMapper;
  18. import com.goafanti.common.dao.UserMapper;
  19. import com.goafanti.common.enums.NoticeStatus;
  20. import com.goafanti.common.enums.PatentInfoStatus;
  21. import com.goafanti.common.enums.TechProjectStatus;
  22. import com.goafanti.common.model.Admin;
  23. import com.goafanti.common.model.Notice;
  24. import com.goafanti.common.model.OrgIntellectualProperty;
  25. import com.goafanti.common.model.PatentCost;
  26. import com.goafanti.common.model.PatentInfo;
  27. import com.goafanti.common.model.PatentLog;
  28. import com.goafanti.common.model.PatentRegistration;
  29. import com.goafanti.common.utils.DateUtils;
  30. import com.goafanti.common.utils.StringUtils;
  31. import com.goafanti.core.mybatis.BaseMybatisDao;
  32. import com.goafanti.core.mybatis.page.Pagination;
  33. import com.goafanti.core.shiro.token.TokenManager;
  34. import com.goafanti.patent.bo.PatentInfoDetailBo;
  35. import com.goafanti.patent.bo.PatentManageListBo;
  36. import com.goafanti.patent.bo.PatentNoticeOfCorrectionBo;
  37. import com.goafanti.patent.bo.PatentPendingBo;
  38. import com.goafanti.patent.service.PatentInfoService;
  39. @Service
  40. public class PatentInfoServiceImpl extends BaseMybatisDao<PatentInfoMapper> implements PatentInfoService {
  41. @Autowired
  42. PatentInfoMapper patentInfoMapper;
  43. @Autowired
  44. UserMapper userMapper;
  45. @Autowired
  46. PatentRegistrationMapper patentRegistrationMapper;
  47. @Autowired
  48. PatentCostMapper patentCostMapper;
  49. @Autowired
  50. PatentLogMapper patentLogMapper;
  51. @Autowired
  52. OrgIntellectualPropertyMapper orgIntellectualPropertyMapper;
  53. @Autowired
  54. NoticeMapper noticeMapper;
  55. @Override
  56. public PatentInfo insert(PatentInfo patentInfo) {
  57. patentInfoMapper.insert(patentInfo);
  58. return patentInfo;
  59. }
  60. @Override
  61. public int updateByPrimaryKeySelective(PatentInfo patentInfo) {
  62. return patentInfoMapper.updateByPrimaryKeySelective(patentInfo);
  63. }
  64. @Override
  65. public PatentInfo selectByPrimaryKey(String id) {
  66. return patentInfoMapper.selectByPrimaryKey(id);
  67. }
  68. @SuppressWarnings("unchecked")
  69. @Override
  70. public Pagination<PatentInfo> getClientApplyList(String uid, String patentNumber, String patentName,
  71. Integer patentCatagory, Integer patentState, Integer pageNo, Integer pageSize) {
  72. Map<String, Object> params = new HashMap<>();
  73. if (uid == null) {
  74. return null;
  75. } else {
  76. params.put("uid", uid);
  77. }
  78. if (patentNumber != null && patentNumber != "") {
  79. params.put("patentNumber", patentNumber);
  80. }
  81. if (patentName != null && patentName != "") {
  82. params.put("patentName", patentName);
  83. }
  84. if (patentCatagory != null) {
  85. params.put("patentCatagory", patentCatagory);
  86. }
  87. if (patentState != null) {
  88. params.put("patentState", patentState);
  89. }
  90. if (pageNo == null || pageNo < 0) {
  91. pageNo = 1;
  92. }
  93. if (pageSize == null || pageSize < 0) {
  94. pageSize = 10;
  95. }
  96. return (Pagination<PatentInfo>) findPage("findClientApplyListByPage", "findClentApplyCount", params, pageNo,
  97. pageSize);
  98. }
  99. @SuppressWarnings("unchecked")
  100. @Override
  101. public Pagination<PatentManageListBo> getManagePatentList(Integer serialNumber, String patentNumber, String office,
  102. String locationProvince, String unitName, Integer patentCatagory, String patentName, Integer patentState,
  103. String[] cDate, String[] pDate, String author, Integer pageNo, Integer pageSize) {
  104. Map<String, Object> params = new HashMap<>();
  105. Date cStart = null;
  106. Date cEnd = null;
  107. Date pStart = null;
  108. Date pEnd = null;
  109. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  110. params.put("principal", TokenManager.getAdminId());
  111. }
  112. if (cDate != null && cDate.length > 0) {
  113. try {
  114. cStart = StringUtils.isBlank(cDate[0]) ? null : DateUtils.parseDate(cDate[0], "yyyy-MM-dd");
  115. cEnd = StringUtils.isBlank(cDate[1]) ? null
  116. : DateUtils.addDays(DateUtils.parseDate(cDate[1], "yyyy-MM-dd"), 1);
  117. } catch (ParseException e) {
  118. }
  119. }
  120. if (pDate != null && pDate.length > 0) {
  121. try {
  122. pStart = StringUtils.isBlank(pDate[0]) ? null : DateUtils.parseDate(pDate[0], "yyyy-MM-dd");
  123. pEnd = StringUtils.isBlank(pDate[1]) ? null
  124. : DateUtils.addDays(DateUtils.parseDate(pDate[1], "yyyy-MM-dd"), 1);
  125. } catch (ParseException e) {
  126. }
  127. }
  128. if (cStart != null) {
  129. params.put("cStart", cStart);
  130. }
  131. if (cEnd != null) {
  132. params.put("cEnd", cEnd);
  133. }
  134. if (pStart != null) {
  135. params.put("pStart", pStart);
  136. }
  137. if (pEnd != null) {
  138. params.put("pEnd", pEnd);
  139. }
  140. if (serialNumber != null) {
  141. params.put("serialNumber", serialNumber);
  142. }
  143. if (patentNumber != null && patentNumber != "") {
  144. params.put("patentNumber", patentNumber);
  145. }
  146. if (office != null && office != "") {
  147. params.put("office", office);
  148. }
  149. if (locationProvince != null && locationProvince != "") {
  150. params.put("locationProvince", locationProvince);
  151. }
  152. if (unitName != null && unitName != "") {
  153. params.put("unitName", unitName);
  154. }
  155. if (patentCatagory != null) {
  156. params.put("patentCatagory", patentCatagory);
  157. }
  158. if (patentName != null && patentName != "") {
  159. params.put("patentName", patentName);
  160. }
  161. if (patentState != null) {
  162. params.put("patentState", patentState);
  163. }
  164. if (author != null && author != "") {
  165. params.put("author", author);
  166. }
  167. if (pageNo == null || pageNo < 0) {
  168. pageNo = 1;
  169. }
  170. if (pageSize == null || pageSize < 0) {
  171. pageSize = 10;
  172. }
  173. return (Pagination<PatentManageListBo>) findPage("findManagePatentListByPage", "findManagePatentCount", params,
  174. pageNo, pageSize);
  175. }
  176. @SuppressWarnings("unchecked")
  177. @Override
  178. public Pagination<PatentPendingBo> getManagePendingPaymentList(String locationProvince, Integer pageNo,
  179. Integer pageSize) {
  180. Map<String, Object> params = new HashMap<>();
  181. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  182. params.put("principal", TokenManager.getAdminId());
  183. }
  184. if (locationProvince != null && locationProvince != "") {
  185. params.put("locationProvince", locationProvince);
  186. }
  187. if (pageNo == null || pageNo < 0) {
  188. pageNo = 1;
  189. }
  190. if (pageSize == null || pageSize < 0) {
  191. pageSize = 10;
  192. }
  193. return (Pagination<PatentPendingBo>) findPage("findManagePendingPaymentListByPage",
  194. "findManagePendingPaymentCount", params, pageNo, pageSize);
  195. }
  196. @SuppressWarnings("unchecked")
  197. @Override
  198. public Pagination<PatentNoticeOfCorrectionBo> getNoticeOfCorrectionList(Date authorizedDate, Integer serialNumber,
  199. String patentNumber, String office, String locationProvince, String unitName, Integer patentCatagory,
  200. String patentName, Integer patentState, String author, Integer pageNo, Integer pageSize) {
  201. Map<String, Object> params = new HashMap<>();
  202. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  203. params.put("principal", TokenManager.getAdminId());
  204. }
  205. if (authorizedDate != null) {
  206. params.put("authorizedDate", authorizedDate);
  207. }
  208. if (serialNumber != null) {
  209. params.put("serialNumber", serialNumber);
  210. }
  211. if (patentNumber != null && patentNumber != "") {
  212. params.put(patentNumber, patentNumber);
  213. }
  214. if (office != null && office != "") {
  215. params.put("office", office);
  216. }
  217. if (locationProvince != null && locationProvince != "") {
  218. params.put("locationProvince", locationProvince);
  219. }
  220. if (unitName != null && unitName != "") {
  221. params.put("unitName", unitName);
  222. }
  223. if (patentCatagory != null) {
  224. params.put("patentCatagory", patentCatagory);
  225. }
  226. if (patentName != null && patentName != "") {
  227. params.put("patentName", patentName);
  228. }
  229. if (patentState != null) {
  230. params.put("patentState", patentState);
  231. }
  232. if (author != null && author != "") {
  233. params.put("author", patentState);
  234. }
  235. if (pageNo == null || pageNo < 0) {
  236. pageNo = 1;
  237. }
  238. if (pageSize == null || pageSize < 0) {
  239. pageSize = 10;
  240. }
  241. return (Pagination<PatentNoticeOfCorrectionBo>) findPage("findNoticeOfCorrectionListByPage",
  242. "findNoticeOfCorrectionCount", params, pageNo, pageSize);
  243. }
  244. @Override
  245. public int batchDeleteByPrimaryKey(List<String> id) {
  246. return patentInfoMapper.batchDeleteByPrimaryKey(id);
  247. }
  248. @Override
  249. public PatentInfo savePatentInfo(PatentInfo patentInfo, String aid) {
  250. patentInfo.setId(UUID.randomUUID().toString());
  251. Calendar now = Calendar.getInstance();
  252. now.set(Calendar.MILLISECOND, 0);
  253. patentInfo.setRecordTime(now.getTime());
  254. patentInfo.setDeletedSign(0);
  255. patentInfo.setConfirmState(0);
  256. patentInfo.setPatentState(PatentInfoStatus.CREATE.getCode());
  257. patentInfo.setPrincipal(aid);
  258. patentInfoMapper.insert(patentInfo);
  259. PatentRegistration patentRegistration = new PatentRegistration();
  260. patentRegistration.setId(UUID.randomUUID().toString());
  261. patentRegistration.setPid(patentInfo.getId());
  262. patentRegistrationMapper.insert(patentRegistration);
  263. PatentCost patentCost = new PatentCost();
  264. patentCost.setId(UUID.randomUUID().toString());
  265. patentCost.setPid(patentInfo.getId());
  266. patentCost.setAnnualFeeState(0);
  267. patentCost.setPaymentState(0);
  268. patentCostMapper.insert(patentCost);
  269. PatentLog log = new PatentLog();
  270. log.setId(UUID.randomUUID().toString());
  271. log.setPid(patentInfo.getId());
  272. log.setRecordTime(patentInfo.getRecordTime());
  273. log.setState(PatentInfoStatus.CREATE.getCode());
  274. log.setPrincipal(StringUtils.isBlank(aid) && TokenManager.getToken() instanceof Admin ? TokenManager.getAdminId() : "");
  275. if (TokenManager.getToken() instanceof Admin) {
  276. log.setOperator(TokenManager.getAdminId());
  277. }
  278. patentLogMapper.insert(log);
  279. createNotice(patentInfo, log);
  280. return patentInfo;
  281. }
  282. @Override
  283. public void updatePatentInfo(PatentInfo p, PatentLog log, Date recordTime) {
  284. if (null != log.getState() && recordTime != null && null != log.getPrincipal()) {
  285. log.setId(UUID.randomUUID().toString());
  286. log.setPid(p.getId());
  287. log.setRecordTime(recordTime);
  288. if (TokenManager.getToken() instanceof Admin) {
  289. log.setOperator(TokenManager.getAdminId());
  290. }
  291. if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.DELIVERD) {
  292. p.setCreateTime(recordTime);
  293. } else if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.ACCEPT) {
  294. p.setPatentApplicationDate(recordTime);
  295. } else if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.AUTHORIZE) {
  296. p.setAuthorizedDate(recordTime);
  297. }
  298. if (TechProjectStatus.getStatus(log.getState()) != TechProjectStatus.CIRCULATION) {
  299. p.setPatentState(log.getState());
  300. }
  301. p.setPrincipal(log.getPrincipal());
  302. patentLogMapper.insert(log);
  303. createNotice(p, log);
  304. }
  305. patentInfoMapper.updateByPrimaryKeySelective(p);
  306. if (PatentInfoStatus.getStatus(p.getPatentState()) == PatentInfoStatus.AUTHORIZE) {
  307. OrgIntellectualProperty o = new OrgIntellectualProperty();
  308. o.setId(UUID.randomUUID().toString());
  309. o.setUid(p.getUid());
  310. o.setPid(p.getId());
  311. o.setDeletedSign(0);
  312. o.setIntellectualPropertyNumber(p.getPatentNumber());
  313. o.setIntellectualPropertyName(p.getPatentName());
  314. o.setCatagory(1);
  315. o.setObtainWay(1);
  316. o.setAuthorizationNumber(p.getPatentNumber());
  317. o.setAuthorizationDate(p.getAuthorizedDate());
  318. o.setEvaluationCategory((3 == p.getPatentCatagory()) ? 0 : 1);
  319. orgIntellectualPropertyMapper.insert(o);
  320. }
  321. if (PatentInfoStatus.getStatus(p.getPatentState()) == PatentInfoStatus.LICENSE) {
  322. OrgIntellectualProperty o = orgIntellectualPropertyMapper.selectOrgIntellectualPropertyByPid(p.getId());
  323. if (null != o) {
  324. Integer i = 0;
  325. switch (p.getPatentCatagory()) {
  326. case 0:
  327. i = 0;
  328. break;
  329. case 1:
  330. i = 2;
  331. break;
  332. case 2:
  333. i = 3;
  334. break;
  335. case 3:
  336. i = 11;
  337. break;
  338. }
  339. o.setCatagory(i);
  340. orgIntellectualPropertyMapper.updateByPrimaryKeySelective(o);
  341. }
  342. }
  343. }
  344. @Override
  345. public void updateNoticeOfCorrection(String pid, Integer patentState) {
  346. PatentInfo patentInfo = new PatentInfo();
  347. patentInfo.setId(pid);
  348. if (patentState == PatentInfoStatus.REVIEWNOTICE.getCode()) {
  349. patentInfo.setPatentState(PatentInfoStatus.REVIEWREPLY.getCode());
  350. } else if (patentState == PatentInfoStatus.CORRECTIONNOTICE.getCode()) {
  351. patentInfo.setPatentState(PatentInfoStatus.CORRECTIONREPLY.getCode());
  352. }
  353. patentInfoMapper.updateByPrimaryKeySelective(patentInfo);
  354. PatentLog patentLog = new PatentLog();
  355. PatentInfo p = patentInfoMapper.selectByPrimaryKey(pid);
  356. patentLog.setId(UUID.randomUUID().toString());
  357. patentLog.setPid(pid);
  358. patentLog.setState(p.getPatentState());
  359. patentLog.setOperator(TokenManager.getAdminId());
  360. patentLog.setPrincipal(p.getPrincipal());
  361. Calendar now = Calendar.getInstance();
  362. now.set(Calendar.MILLISECOND, 0);
  363. patentLog.setRecordTime(now.getTime());
  364. patentLogMapper.insert(patentLog);
  365. }
  366. @Override
  367. public PatentInfoDetailBo selectPatentInfoDetail(String id) {
  368. return patentInfoMapper.selectPatentInfoDetail(id);
  369. }
  370. private void createNotice(PatentInfo p, PatentLog l){
  371. PatentInfo info = patentInfoMapper.selectByPrimaryKey(p.getId());
  372. Notice n = new Notice();
  373. Calendar now = Calendar.getInstance();
  374. now.set(Calendar.MILLISECOND, 0);
  375. n.setId(UUID.randomUUID().toString());
  376. n.setCreateTime(now.getTime());
  377. n.setReaded(0);
  378. n.setAid(l.getPrincipal());
  379. n.setContent("编号" + info.getSerialNumber() + " " + PatentInfoStatus.getStatus(l.getState()).getDesc());
  380. n.setNoticeType(NoticeStatus.PATENTINFO.getCode());
  381. noticeMapper.insert(n);
  382. }
  383. }