PatentInfoServiceImpl.java 16 KB

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