PatentInfoServiceImpl.java 14 KB

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