UploadPatentBatchService.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.core.base.Constants;
  3. import cn.cslg.pas.common.model.PatentCell;
  4. import cn.cslg.pas.common.model.dto.TaskWebSocketDTO;
  5. import cn.cslg.pas.common.model.params.*;
  6. import cn.cslg.pas.common.model.vo.ProjectImportPatentVO;
  7. import cn.cslg.pas.common.model.vo.TaskParams;
  8. import cn.cslg.pas.common.model.vo.UploadParamsVO;
  9. import cn.cslg.pas.common.model.vo.UploadSettingVO;
  10. import cn.cslg.pas.common.utils.*;
  11. import cn.cslg.pas.domain.*;
  12. import cn.cslg.pas.mapper.ImportErrorLogMapper;
  13. import cn.cslg.pas.service.asso.AssoProductPatentService;
  14. import cn.hutool.extra.spring.SpringUtil;
  15. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  16. import lombok.RequiredArgsConstructor;
  17. import org.apache.poi.ss.usermodel.PictureData;
  18. import org.springframework.context.annotation.Lazy;
  19. import org.springframework.scheduling.annotation.Async;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  23. import java.text.SimpleDateFormat;
  24. import java.util.*;
  25. import java.util.stream.Collectors;
  26. @Service
  27. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  28. public class UploadPatentBatchService {
  29. private final FileUtils fileUtils;
  30. private final SystemDictService systemDictService;
  31. private final PatentImageService patentImageService;
  32. private final PatentService patentService;
  33. private final PatentAgencyService patentAgencyService;
  34. private final PatentInstructionTextService patentInstructionTextService;
  35. private final PatentRightService patentRightService;
  36. private final PatentAgentService patentAgentService;
  37. private final PatentPledgeService patentPledgeService;
  38. private final PatentLicensorService patentLicensorService;
  39. private final PatentSimpleFamilyService patentSimpleFamilyService;
  40. private final PatentInventorService patentInventorService;
  41. private final ProjectPatentLinkService projectPatentLinkService;
  42. private final ProjectFieldPatentLinkService projectFieldPatentLinkService;
  43. private final ProjectFolderPatentLinkService projectFolderPatentLinkService;
  44. private final PatentApplicantLinkService patentApplicantLinkService;
  45. private final PatentApplicantService patentApplicantService;
  46. private final PatentLabelService patentLabelService;
  47. private final PatentClassNumberLinkService patentClassNumberLinkService;
  48. private final PatentAffairService patentAffairService;
  49. private final ImportErrorLogMapper importErrorLogMapper;
  50. private final AssoProductPatentService assoProductPatentService;
  51. private static int FLAG = 0;
  52. @Async("singleThreadAsyncTaskExecutor")
  53. public void uploadPatentBatch(TaskParams params, ProjectImportPatentVO projectImportPatentVO) {
  54. Integer total = params.getRowList().size();
  55. try {
  56. //先解析Json文件 获得配置文件的Json串
  57. String getSettingJson = fileUtils.analysisJsonFile();
  58. //查找需求数据源的对应配置
  59. List<UploadSettingVO.Column> jsonData = UploadPatentBatchUtil.parsingConfigurationFiles(projectImportPatentVO, getSettingJson);
  60. Map<String, PictureData> pictureDataMap = ExcelUtils.getDataFromExcel(params.getPath());
  61. //将数据进行装配并进行数据库操作
  62. for (int i = 0; i < params.getRowList().size(); i++) {
  63. //获取每一行的数据
  64. Map<Object, Object> row = params.getRowList().get(i);
  65. //基础数据装配
  66. UploadParamsVO uploadParamsVO = UploadPatentBatchUtil.processData(row, jsonData);
  67. //查询数据是否存在 如果存在 返回该条数据 如果不存在 新增一条数据
  68. getOneOrInsertOne(uploadParamsVO);
  69. //专利信息需要特殊处理部分
  70. //专利信息(摘要附图)数据装配
  71. PictureData pictureData = pictureDataMap.get(String.valueOf(i + 1));
  72. if (uploadParamsVO.getPatent() != null) {
  73. if (uploadParamsVO.getPatent().getId() != null && pictureData != null) {
  74. uploadParamsVO.getPatent().setAbstractPath(patentImageService.updatePatentImage(uploadParamsVO.getPatent().getId(), pictureData));
  75. }
  76. }
  77. //专利信息(代理机构)数据装配
  78. if (uploadParamsVO.getPatent() != null) {
  79. if (uploadParamsVO.getPatent().getAgencyId() != null) {
  80. uploadParamsVO.getPatent().setAgencyId(patentAgencyService.getAgencyStringIdByName(uploadParamsVO.getPatent().getAgencyId()));
  81. }
  82. }
  83. //将装配对象中的数据保存到数据库
  84. dataToDB(params, uploadParamsVO, projectImportPatentVO);
  85. //通过WebSocket 在每一次循环结束后 向前端发送完成进度
  86. WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
  87. .setTaskId(params.getTaskId())
  88. .setProjectId(projectImportPatentVO.getProjectId())
  89. .setComplete(false)
  90. .setIndex(i)
  91. .setTaskType(Constants.TASK_IMPORT_PATENT)
  92. .setPercentage(total == 0 ? 0 : Math.round((total.equals(i) ? (i * 1D) : (i + 1D)) / total * 100D))
  93. .setFileName("")
  94. .setOldName(params.getOldName())
  95. .setUrl("")
  96. .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId());
  97. }
  98. SpringUtil.getBean(ProjectService.class).setImportPatentTaskStatus(2, params.getTaskId());
  99. WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
  100. .setTaskId(params.getTaskId())
  101. .setProjectId(projectImportPatentVO.getProjectId())
  102. .setComplete(true)
  103. .setIndex(total)
  104. .setTaskType(Constants.TASK_IMPORT_PATENT)
  105. .setPercentage(100L)
  106. .setFileName("")
  107. .setOldName(params.getOldName())
  108. .setUrl("")
  109. .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId());
  110. } catch (Exception e) {
  111. e.printStackTrace();
  112. SpringUtil.getBean(ProjectService.class).setImportPatentTaskStatus(3, params.getTaskId());
  113. if (FLAG > 0) {
  114. int successCount = total - FLAG;
  115. WebSocketServer.sendInfo(Response.error("部分数据上传成功" + "\n" + "成功条数:" + successCount + "失败条数:" + FLAG), params.getUserId());
  116. }
  117. FLAG = 0;
  118. }
  119. }
  120. /**
  121. * @return uploadParamsVO 返回一个由processData方法填充完数据的Pojo类
  122. * @date 2022/7/7
  123. * @name 解析配置文件
  124. * @description uploadPatentBatch的兄弟方法
  125. */
  126. // @Async("singleThreadAsyncTaskExecutor")
  127. public String uploadPatentBatchBro(TaskParams params) {
  128. Integer total = params.getTotal();
  129. Integer index = params.getIndex();
  130. try {
  131. //先解析Json文件 获得配置文件的Json串
  132. String getSettingJson = fileUtils.analysisJsonFile();
  133. //查找需求数据源的对应配置
  134. List<UploadSettingVO.Column> jsonData = UploadPatentBatchUtil.parsingConfigurationFilesBro(getSettingJson);
  135. Map<String, PictureData> pictureDataMap = ExcelUtils.getDataFromExcel(params.getPath());
  136. //将数据进行装配并进行数据库操作
  137. //获取每一行的数据
  138. Map<Object, Object> row = params.getRowList().get(0);
  139. //基础数据装配
  140. UploadParamsVO uploadParamsVO = UploadPatentBatchUtil.processData(row, jsonData);
  141. //查询数据是否存在 如果存在 返回该条数据 如果不存在 新增一条数据
  142. getOneOrInsertOne(uploadParamsVO);
  143. //专利信息需要特殊处理部分
  144. //专利信息(摘要附图)数据装配
  145. PictureData pictureData = pictureDataMap.get(String.valueOf(index + 1));
  146. if (uploadParamsVO.getPatent() != null) {
  147. if (uploadParamsVO.getPatent().getId() != null && pictureData != null) {
  148. uploadParamsVO.getPatent().setAbstractPath(patentImageService.updatePatentImage(uploadParamsVO.getPatent().getId(), pictureData));
  149. }
  150. }
  151. //专利信息(代理机构)数据装配
  152. if (uploadParamsVO.getPatent() != null) {
  153. if (uploadParamsVO.getPatent().getAgencyId() != null) {
  154. uploadParamsVO.getPatent().setAgencyId(patentAgencyService.getAgencyStringIdByName(uploadParamsVO.getPatent().getAgencyId()));
  155. }
  156. }
  157. //将装配对象中的数据保存到数据库
  158. dataToDBBro(params, uploadParamsVO);
  159. ImportTaskPatent importTaskPatent = new ImportTaskPatent();
  160. importTaskPatent.setImportTaskId(params.getTaskId());
  161. importTaskPatent.setPatentNo(uploadParamsVO.getPatent().getPatentNo());
  162. importTaskPatent.insert();
  163. //通过WebSocket 在每一次循环结束后 向前端发送完成进度
  164. WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
  165. .setTaskId(params.getTaskId())
  166. .setComplete(false)
  167. .setIndex(0)
  168. .setTaskType(Constants.TASK_IMPORT_PATENT)
  169. .setPercentage(total == 0 ? 0 : Math.round((total.equals(index) ? (index * 1D) : (index + 1D)) / total * 100D))
  170. .setFileName("")
  171. .setOldName(params.getOldName())
  172. .setUrl("")
  173. .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId());
  174. return Response.success();
  175. } catch (Exception e) {
  176. return Response.error();
  177. }
  178. }
  179. /**
  180. * @param uploadParamsVO 全局类
  181. * @date 2022-7-11
  182. * @name 数据库交互
  183. * @description 将装配完毕的VO类向数据库中不同的表进行添加或修改操作
  184. */
  185. @Transactional(rollbackFor = Exception.class)
  186. public void dataToDB(TaskParams params, UploadParamsVO uploadParamsVO, ProjectImportPatentVO projectImportPatentVO) {
  187. try {
  188. //专利信息 OS_PATENT
  189. if (uploadParamsVO.getPatent() != null) {
  190. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.PATENT_SIMPLE_STATUS));
  191. Integer simpleStatus = Integer.parseInt(systemDictList.stream()
  192. .filter(systemDict -> systemDict.getType().equals(Constants.PATENT_SIMPLE_STATUS) && systemDict.getLabel().equals(uploadParamsVO.getPatentSimpleStatus()))
  193. .findFirst()
  194. .orElse(new SystemDict()).getValue());
  195. uploadParamsVO.getPatent().setSimpleStatus(simpleStatus);
  196. uploadParamsVO.getPatent().updateById();
  197. }
  198. //权利要求 OS_PATENT_RIGHT
  199. patentRightBusiness(uploadParamsVO);
  200. //说明书(文本) OS_PATENT_INSTRUCTION_TEXT
  201. if (uploadParamsVO.getPatentInstructionText() != null) {
  202. patentInstructionTextBusiness(uploadParamsVO);
  203. }
  204. //代理人 OS_PATENT_AGENT
  205. if (uploadParamsVO.getPatentAgentList() != null) {
  206. patentAgentBusiness(uploadParamsVO);
  207. }
  208. //质押质权人 OS_PATENT_PLEDGE
  209. if (uploadParamsVO.getPatentPledgeList() != null) {
  210. patentPledgeBusiness(uploadParamsVO);
  211. }
  212. //许可人 OS_PATENT_LICENSOR
  213. if (uploadParamsVO.getPatentLicensorList() != null) {
  214. patentLicensorBusiness(uploadParamsVO);
  215. }
  216. //简单同族 OS_PATENT_SIMPLEFAMILY
  217. patentSimplyFamilyBusiness(uploadParamsVO);
  218. //发明人 OS_PATENT_INVENTOR
  219. patentInventorBusiness(uploadParamsVO);
  220. //申请人(原始)/权利人(当前) OS_PATENT_APPLICATION || OS_APPLICATION_ATTR
  221. patentApplicationBusiness(uploadParamsVO);
  222. //申请人地址 OS_PATENT_APPLICATION
  223. patentApplicationAddressBusiness(uploadParamsVO);
  224. //专题库关联专利信息 OS_THEMATIC_PID
  225. if (uploadParamsVO.getPatent() != null) {
  226. patentThematicPidBusiness(uploadParamsVO, projectImportPatentVO);
  227. }
  228. //标引内容关联专利信息 OS_PATENT_FIELD_PATENT_LINK
  229. if (uploadParamsVO.getPatent() != null) {
  230. patentProjectFieldPatentLinkBusiness(uploadParamsVO, projectImportPatentVO);
  231. }
  232. //文件夹管理 OS_PORTFOLIO_LINK
  233. if (uploadParamsVO.getPatent() != null) {
  234. patentProjectFolderPatentLinkBusiness(uploadParamsVO, projectImportPatentVO);
  235. }
  236. //标签 OS_PATENT_LABEL
  237. if (uploadParamsVO.getPatentLabelList() != null) {
  238. patentLabelBusiness(uploadParamsVO, projectImportPatentVO);
  239. }
  240. //分类号关联 OS_PATENT_TYPENO
  241. patentTypeNoBusiness(uploadParamsVO);
  242. //事务信息 OS_PATENT_AFFAIR
  243. patentAffairBusiness(uploadParamsVO);
  244. //自定义字段
  245. if (uploadParamsVO.getCustomerFieldList() != null) {
  246. patentFieldBusiness(params, uploadParamsVO, projectImportPatentVO);
  247. }
  248. } catch (Exception e) {
  249. e.printStackTrace();
  250. if (uploadParamsVO.getPatent() != null) {
  251. ImportErrorLog importErrorLog = new ImportErrorLog();
  252. importErrorLog.setPatentId(uploadParamsVO.getPatent().getId())
  253. .setPatentNo(uploadParamsVO.getPatent().getPatentNo())
  254. .setCreateTime(new SimpleDateFormat("yyyy-MM-dd 24HI:mm:ss").format(new Date()))
  255. .setCreateUserId(Integer.parseInt(params.getUserId()))
  256. .setMistakeMessage(e.getMessage())
  257. .setProjectId(params.getProjectId());
  258. importErrorLogMapper.insert(importErrorLog);
  259. FLAG += 1;
  260. }
  261. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  262. }
  263. }
  264. /**
  265. * @param uploadParamsVO 全局类
  266. * @date 2022-7-11
  267. * @name 数据库交互
  268. * @description 将装配完毕的VO类向数据库中不同的表进行添加或修改操作(dataToDB兄弟类)
  269. */
  270. @Transactional(rollbackFor = Exception.class)
  271. public void dataToDBBro(TaskParams params, UploadParamsVO uploadParamsVO) {
  272. try {
  273. //专利信息 OS_PATENT
  274. if (uploadParamsVO.getPatent() != null) {
  275. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.PATENT_SIMPLE_STATUS));
  276. Integer simpleStatus = Integer.parseInt(systemDictList.stream()
  277. .filter(systemDict -> systemDict.getType().equals(Constants.PATENT_SIMPLE_STATUS) && systemDict.getLabel().equals(uploadParamsVO.getPatentSimpleStatus()))
  278. .findFirst()
  279. .orElse(new SystemDict()).getValue());
  280. uploadParamsVO.getPatent().setSimpleStatus(simpleStatus);
  281. uploadParamsVO.getPatent().updateById();
  282. }
  283. //权利要求 OS_PATENT_RIGHT
  284. patentRightBusiness(uploadParamsVO);
  285. //说明书(文本) OS_PATENT_INSTRUCTION_TEXT
  286. if (uploadParamsVO.getPatentInstructionText() != null) {
  287. patentInstructionTextBusiness(uploadParamsVO);
  288. }
  289. //代理人 OS_PATENT_AGENT
  290. if (uploadParamsVO.getPatentAgentList() != null) {
  291. patentAgentBusiness(uploadParamsVO);
  292. }
  293. //质押质权人 OS_PATENT_PLEDGE
  294. if (uploadParamsVO.getPatentPledgeList() != null) {
  295. patentPledgeBusiness(uploadParamsVO);
  296. }
  297. //许可人 OS_PATENT_LICENSOR
  298. if (uploadParamsVO.getPatentLicensorList() != null) {
  299. patentLicensorBusiness(uploadParamsVO);
  300. }
  301. //简单同族 OS_PATENT_SIMPLEFAMILY
  302. patentSimplyFamilyBusiness(uploadParamsVO);
  303. //发明人 OS_PATENT_INVENTOR
  304. patentInventorBusiness(uploadParamsVO);
  305. //申请人(原始)/权利人(当前) OS_PATENT_APPLICATION || OS_APPLICATION_ATTR
  306. patentApplicationBusiness(uploadParamsVO);
  307. //申请人地址 OS_PATENT_APPLICATION
  308. patentApplicationAddressBusiness(uploadParamsVO);
  309. //分类号关联 OS_PATENT_TYPENO
  310. patentTypeNoBusiness(uploadParamsVO);
  311. //事务信息 OS_PATENT_AFFAIR
  312. patentAffairBusiness(uploadParamsVO);
  313. } catch (Exception e) {
  314. e.printStackTrace();
  315. if (uploadParamsVO.getPatent() != null) {
  316. ImportErrorLog importErrorLog = new ImportErrorLog();
  317. importErrorLog.setPatentId(uploadParamsVO.getPatent().getId())
  318. .setPatentNo(uploadParamsVO.getPatent().getPatentNo())
  319. .setCreateTime(new SimpleDateFormat("yyyy-MM-dd 24HI:mm:ss").format(new Date()))
  320. .setCreateUserId(Integer.parseInt(params.getUserId()))
  321. .setMistakeMessage(e.getMessage())
  322. .setProjectId(params.getProjectId());
  323. importErrorLogMapper.insert(importErrorLog);
  324. FLAG += 1;
  325. }
  326. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  327. }
  328. }
  329. /**
  330. * @param uploadParamsVO 全局类
  331. * @date 2022-7-11
  332. * @name 工具方法
  333. * @description 查询数据是否存在 如果存在 返回该条数据 如果不存在 新增一条数据
  334. */
  335. private void getOneOrInsertOne(UploadParamsVO uploadParamsVO) {
  336. if (uploadParamsVO.getPatent() != null) {
  337. uploadParamsVO.getPatent().setPatentNo(uploadParamsVO.getPatent().getPatentNo().trim());
  338. //用专利号查询该条数据是否存在
  339. Patent patent = patentService.getByPatentNo(uploadParamsVO.getPatent().getPatentNo());
  340. //如果不存在就新增一条
  341. if (patent == null) {
  342. uploadParamsVO.getPatent().insert();
  343. } else {
  344. uploadParamsVO.getPatent().setId(patent.getId());
  345. }
  346. }
  347. }
  348. private void patentRightBusiness(UploadParamsVO uploadParamsVO) {
  349. PatentRightParams patentRightParams = new PatentRightParams();
  350. patentRightParams.setPatentId(uploadParamsVO.getPatent().getId());
  351. patentRightParams.setPatentNo(uploadParamsVO.getPatent().getPatentNo());
  352. if (uploadParamsVO.getPatentRight() != null) {
  353. patentRightParams.setContent(uploadParamsVO.getPatentRight().getContent());
  354. patentRightParams.setContentOut(uploadParamsVO.getPatentRight().getContentOut());
  355. }
  356. if (uploadParamsVO.getSelfContent() != null) {
  357. patentRightParams.setSelfContent(uploadParamsVO.getSelfContent());
  358. }
  359. patentRightService.updatePatentRight(patentRightParams);
  360. patentRightService.importAuthority(patentRightParams);
  361. }
  362. private void patentInstructionTextBusiness(UploadParamsVO uploadParamsVO) {
  363. PatentInstructionTextParams patentInstructionTextParams = new PatentInstructionTextParams();
  364. patentInstructionTextParams.setPatentId(uploadParamsVO.getPatent().getId());
  365. patentInstructionTextParams.setManual(uploadParamsVO.getPatentInstructionText().getManual());
  366. patentInstructionTextParams.setManualOut(uploadParamsVO.getPatentInstructionText().getManualOut());
  367. patentInstructionTextService.updatePatentInstructionText(patentInstructionTextParams);
  368. }
  369. //代理人
  370. private void patentAgentBusiness(UploadParamsVO uploadParamsVO) {
  371. PatentAgentParams patentAgentParams = new PatentAgentParams();
  372. patentAgentParams.setPatentId(uploadParamsVO.getPatent().getId());
  373. List<String> agentList = uploadParamsVO.getPatentAgentList().stream().map(PatentAgent::getName).collect(Collectors.toList());
  374. patentAgentParams.setAgent(agentList);
  375. patentAgentService.updatePatentAgent(patentAgentParams);
  376. }
  377. //质押质权人 OS_PATENT_PLEDGE
  378. private void patentPledgeBusiness(UploadParamsVO uploadParamsVO) {
  379. PatentPledgeParams patentPledgeParams = new PatentPledgeParams();
  380. patentPledgeParams.setPatentId(uploadParamsVO.getPatent().getId());
  381. List<String> pledgeeList = uploadParamsVO.getPatentPledgeList().stream().map(PatentPledge::getPledgee).collect(Collectors.toList());
  382. List<String> pledgorList = uploadParamsVO.getPatentPledgeList().stream().map(PatentPledge::getPledgor).collect(Collectors.toList());
  383. patentPledgeParams.setPledgee(pledgeeList);
  384. patentPledgeParams.setPledgor(pledgorList);
  385. patentPledgeService.updatePatentPledge(patentPledgeParams);
  386. }
  387. //许可人 OS_PATENT_LICENSOR
  388. private void patentLicensorBusiness(UploadParamsVO uploadParamsVO) {
  389. PatentLicensorParams patentLicensorParams = new PatentLicensorParams();
  390. patentLicensorParams.setPatentId(uploadParamsVO.getPatent().getId());
  391. List<String> licensorList = uploadParamsVO.getPatentLicensorList().stream().map(PatentLicensor::getLicensor).collect(Collectors.toList());
  392. List<String> licenseeList = uploadParamsVO.getPatentLicensorList().stream().map(PatentLicensor::getLicensee).collect(Collectors.toList());
  393. List<String> typeList = uploadParamsVO.getPatentLicensorList().stream().map(PatentLicensor::getType).collect(Collectors.toList());
  394. patentLicensorParams.setLicensor(licensorList);
  395. patentLicensorParams.setLicensee(licenseeList);
  396. patentLicensorParams.setType(typeList);
  397. patentLicensorService.updatePatentLicensor(patentLicensorParams);
  398. }
  399. //简单同族
  400. private void patentSimplyFamilyBusiness(UploadParamsVO uploadParamsVO) {
  401. PatentSimpleFamilyParams patentSimpleFamilyParams = new PatentSimpleFamilyParams();
  402. if (uploadParamsVO.getSimpleFamily() != null) {
  403. patentSimpleFamilyParams.setSimpleFamily(uploadParamsVO.getSimpleFamily());
  404. }
  405. if (uploadParamsVO.getPatSnapFamily() != null) {
  406. patentSimpleFamilyParams.setPatSnapFamily(uploadParamsVO.getPatSnapFamily());
  407. }
  408. if (uploadParamsVO.getInpadocFamily() != null) {
  409. patentSimpleFamilyParams.setInpadocFamily(uploadParamsVO.getInpadocFamily());
  410. }
  411. patentSimpleFamilyParams.setPatentId(uploadParamsVO.getPatent().getId());
  412. patentSimpleFamilyParams.setPatentNo(uploadParamsVO.getPatent().getPatentNo());
  413. patentSimpleFamilyService.updatePatentSimpleFamily(patentSimpleFamilyParams);
  414. }
  415. //发明人 OS_PATENT_INVENTOR
  416. private void patentInventorBusiness(UploadParamsVO uploadParamsVO) {
  417. PatentInventorParams patentInventorParams = new PatentInventorParams();
  418. if (uploadParamsVO.getPatentInventorList() != null) {
  419. List<String> addressList = uploadParamsVO.getPatentInventorList().stream().map(PatentInventor::getAddress).filter(Objects::nonNull).collect(Collectors.toList());
  420. patentInventorParams.setAddressList(addressList);
  421. List<String> nameList = uploadParamsVO.getPatentInventorList().stream().map(PatentInventor::getName).collect(Collectors.toList());
  422. patentInventorParams.setNameList(nameList);
  423. }
  424. if (uploadParamsVO.getFirstName() != null) {
  425. patentInventorParams.setFirstName(uploadParamsVO.getFirstName());
  426. }
  427. if (uploadParamsVO.getFirstAddress() != null) {
  428. patentInventorParams.setFirstAddress(uploadParamsVO.getFirstAddress());
  429. }
  430. patentInventorParams.setPatentId(uploadParamsVO.getPatent().getId());
  431. patentInventorService.updatePatentInventor(patentInventorParams);
  432. }
  433. //申请人(原始)/权利人(当前) OS_PATENT_APPLICATION || OS_APPLICATION_ATTR
  434. private void patentApplicationBusiness(UploadParamsVO uploadParamsVO) {
  435. // 根据本条数据的名字查询所有的申请人信息
  436. List<String> name = new ArrayList<>();
  437. if (uploadParamsVO.getPatentApplicantCurrentName() != null) {
  438. name.addAll(uploadParamsVO.getPatentApplicantCurrentName());
  439. }
  440. if (uploadParamsVO.getPatentApplicantOriginalName() != null) {
  441. name.addAll(uploadParamsVO.getPatentApplicantOriginalName());
  442. }
  443. if (uploadParamsVO.getPatentApplicantStandardCurrentName() != null) {
  444. name.addAll(uploadParamsVO.getPatentApplicantStandardCurrentName());
  445. }
  446. if (uploadParamsVO.getPatentApplicantStandardOriginalName() != null) {
  447. name.addAll(uploadParamsVO.getPatentApplicantStandardOriginalName());
  448. }
  449. if (name.size() != 0) {
  450. List<PatentApplicant> patentApplicantList = patentApplicantService.list(Wrappers.<PatentApplicant>lambdaQuery().in(PatentApplicant::getName, name));
  451. //权利人
  452. if (uploadParamsVO.getPatentApplicantCurrentName() != null || uploadParamsVO.getPatentApplicantStandardCurrentName() != null)
  453. patentApplicantLinkService.updatePatentApplicantLink(uploadParamsVO.getPatentApplicantCurrentName(), uploadParamsVO.getPatentApplicantStandardCurrentName(), 1, uploadParamsVO.getPatent().getId(), patentApplicantList);
  454. //申请人
  455. if (uploadParamsVO.getPatentApplicantOriginalName() != null || uploadParamsVO.getPatentApplicantStandardOriginalName() != null)
  456. patentApplicantLinkService.updatePatentApplicantLink(uploadParamsVO.getPatentApplicantOriginalName(), uploadParamsVO.getPatentApplicantStandardOriginalName(), 2, uploadParamsVO.getPatent().getId(), patentApplicantList);
  457. }
  458. }
  459. private void patentApplicationAddressBusiness(UploadParamsVO uploadParamsVO) {
  460. PatentApplicantAddressParams patentApplicantAddressParams = new PatentApplicantAddressParams();
  461. patentApplicantAddressParams.setPatentId(uploadParamsVO.getPatent().getId());
  462. patentApplicantAddressParams.setCurrentAddress(uploadParamsVO.getPatentApplicantCurrentAddress());
  463. patentApplicantAddressParams.setOriginalAddress(uploadParamsVO.getPatentApplicantOriginalAddress());
  464. patentApplicantAddressParams.setCurrentCountry(uploadParamsVO.getPatentApplicantCurrentCountry());
  465. patentApplicantAddressParams.setOriginalCountry(uploadParamsVO.getPatentApplicantOriginalCountry());
  466. patentApplicantAddressParams.setFirstCurrentAddress(uploadParamsVO.getFirstAddress());
  467. patentApplicantService.updatePatentApplicantAddress(patentApplicantAddressParams);
  468. }
  469. private void patentThematicPidBusiness(UploadParamsVO uploadParamsVO, ProjectImportPatentVO projectImportPatentVO) {
  470. projectPatentLinkService.updateProjectPatent(projectImportPatentVO.getProjectId(), uploadParamsVO.getPatent().getId());
  471. }
  472. private void patentProjectFieldPatentLinkBusiness(UploadParamsVO uploadParamsVO, ProjectImportPatentVO projectImportPatentVO) {
  473. projectFieldPatentLinkService.updateProjectFieldPatentLink(projectImportPatentVO, uploadParamsVO.getPatent().getId());
  474. }
  475. private void patentProjectFolderPatentLinkBusiness(UploadParamsVO uploadParamsVO, ProjectImportPatentVO projectImportPatentVO) {
  476. projectFolderPatentLinkService.updateProjectFolderLink(projectImportPatentVO, uploadParamsVO.getPatent().getId());
  477. }
  478. private void patentLabelBusiness(UploadParamsVO uploadParamsVO, ProjectImportPatentVO projectImportPatentVO) {
  479. PatentLabelParams patentLabelParams = new PatentLabelParams();
  480. patentLabelParams.setPatentId(uploadParamsVO.getPatent().getId());
  481. patentLabelParams.setProjectId(projectImportPatentVO.getProjectId());
  482. List<String> labelList = uploadParamsVO.getPatentLabelList().stream().map(PatentLabel::getName).collect(Collectors.toList());
  483. patentLabelParams.setLabel(labelList);
  484. patentLabelService.updatePatentLabel(patentLabelParams);
  485. }
  486. private void patentTypeNoBusiness(UploadParamsVO uploadParamsVO) {
  487. PatentClassNumberParams patentClassNumberParams = new PatentClassNumberParams();
  488. if (uploadParamsVO.getMainIpc() != null) {
  489. patentClassNumberParams.setMainIpc(uploadParamsVO.getMainIpc());
  490. }
  491. if (uploadParamsVO.getMainUpc() != null) {
  492. patentClassNumberParams.setMainUpc(uploadParamsVO.getMainUpc());
  493. }
  494. if (uploadParamsVO.getCpcList() != null) {
  495. patentClassNumberParams.setCpcList(uploadParamsVO.getCpcList());
  496. }
  497. if (uploadParamsVO.getLocList() != null) {
  498. patentClassNumberParams.setLocList(uploadParamsVO.getLocList());
  499. }
  500. if (uploadParamsVO.getUpcList() != null) {
  501. patentClassNumberParams.setUpcList(uploadParamsVO.getUpcList());
  502. }
  503. if (uploadParamsVO.getIpcList() != null) {
  504. patentClassNumberParams.setIpcList(uploadParamsVO.getIpcList());
  505. }
  506. patentClassNumberParams.setPatentId(uploadParamsVO.getPatent().getId());
  507. patentClassNumberLinkService.updatePatentClassNumberLink(patentClassNumberParams);
  508. }
  509. private void patentAffairBusiness(UploadParamsVO uploadParamsVO) {
  510. PatentAffairParams patentAffairParams = new PatentAffairParams();
  511. if (uploadParamsVO.getPatentAffair() != null) {
  512. patentAffairParams.setContent(uploadParamsVO.getPatentAffair().getContent());
  513. patentAffairParams.setStatusList(uploadParamsVO.getPatentAffair().getStatus());
  514. patentAffairParams.setDateTime(uploadParamsVO.getPatentAffair().getDateTime());
  515. }
  516. if (uploadParamsVO.getSimpleStatus() != null) {
  517. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.PATENT_SIMPLE_STATUS));
  518. Integer simpleStatus = Integer.parseInt(systemDictList.stream()
  519. .filter(systemDict -> systemDict.getType().equals(Constants.PATENT_SIMPLE_STATUS) && systemDict.getLabel().equals(uploadParamsVO.getSimpleStatus()))
  520. .findFirst()
  521. .orElse(new SystemDict()).getValue());
  522. patentAffairParams.setSimpleStatus(simpleStatus);
  523. }
  524. patentAffairParams.setPatentId(uploadParamsVO.getPatent().getId());
  525. patentAffairService.updatePatientAffair(patentAffairParams);
  526. }
  527. private void patentFieldBusiness(TaskParams params, UploadParamsVO uploadParamsVO, ProjectImportPatentVO projectImportPatentVO) {
  528. PatentCustomFieldParams patentCustomFieldParams = new PatentCustomFieldParams();
  529. for (int i = 0; i < uploadParamsVO.getCustomerFieldList().size(); i++) {
  530. patentCustomFieldParams.setPatentId(uploadParamsVO.getPatent().getId());
  531. patentCustomFieldParams.setProjectId(projectImportPatentVO.getProjectId());
  532. patentCustomFieldParams.setUserId(Integer.parseInt(params.getUserId()));
  533. patentCustomFieldParams.put(uploadParamsVO.getCustomerFieldList().get(i).getKey(), uploadParamsVO.getCustomerFieldList().get(i).getFieldList());
  534. }
  535. patentService.updatePatentCustomField(patentCustomFieldParams);
  536. }
  537. @Async("singleThreadAsyncTaskExecutor")
  538. public void uploadPatentForProduct(TaskParams params, Integer productId) {
  539. Integer total = params.getRowList().size();
  540. try {
  541. //先解析Json文件 获得配置文件的Json串
  542. String getSettingJson = fileUtils.analysisJsonFile();
  543. //查找需求数据源的对应配置
  544. List<UploadSettingVO.Column> jsonData = UploadPatentBatchUtil.parsingConfigurationFilesBro(getSettingJson);
  545. Map<String, PictureData> pictureDataMap = ExcelUtils.getDataFromExcel(params.getPath());
  546. //将数据进行装配并进行数据库操作
  547. for (int i = 0; i < params.getRowList().size(); i++) {
  548. //获取每一行的数据
  549. Map<Object, Object> row = params.getRowList().get(i);
  550. //基础数据装配
  551. UploadParamsVO uploadParamsVO = UploadPatentBatchUtil.processData(row, jsonData);
  552. //查询数据是否存在 如果存在 返回该条数据 如果不存在 新增一条数据
  553. getOneOrInsertOne(uploadParamsVO);
  554. //专利信息需要特殊处理部分
  555. //专利信息(摘要附图)数据装配
  556. PictureData pictureData = pictureDataMap.get(String.valueOf(i + 1));
  557. if (uploadParamsVO.getPatent() != null) {
  558. if (uploadParamsVO.getPatent().getId() != null && pictureData != null) {
  559. uploadParamsVO.getPatent().setAbstractPath(patentImageService.updatePatentImage(uploadParamsVO.getPatent().getId(), pictureData));
  560. }
  561. }
  562. //专利信息(代理机构)数据装配
  563. if (uploadParamsVO.getPatent() != null) {
  564. if (uploadParamsVO.getPatent().getAgencyId() != null) {
  565. uploadParamsVO.getPatent().setAgencyId(patentAgencyService.getAgencyStringIdByName(uploadParamsVO.getPatent().getAgencyId()));
  566. }
  567. }
  568. //将装配对象中的数据保存到数据库
  569. dataToDBBro(params, uploadParamsVO);
  570. //添加关联关系
  571. assoProductPatentService.addPatents(Arrays.asList(uploadParamsVO.getPatent().getPatentNo()), productId);
  572. //通过WebSocket 在每一次循环结束后 向前端发送完成进度
  573. WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
  574. .setTaskId(params.getTaskId())
  575. .setComplete(false)
  576. .setIndex(i)
  577. .setTaskType(Constants.TASK_IMPORT_PATENT)
  578. .setPercentage(total == 0 ? 0 : Math.round((total.equals(i) ? (i * 1D) : (i + 1D)) / total * 100D))
  579. .setFileName("")
  580. .setOldName(params.getOldName())
  581. .setUrl("")
  582. .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId());
  583. }
  584. SpringUtil.getBean(ProjectService.class).setImportPatentTaskStatus(2, params.getTaskId());
  585. WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
  586. .setTaskId(params.getTaskId())
  587. .setComplete(true)
  588. .setIndex(total)
  589. .setTaskType(Constants.TASK_IMPORT_PATENT)
  590. .setPercentage(100L)
  591. .setFileName("")
  592. .setOldName(params.getOldName())
  593. .setUrl("")
  594. .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId());
  595. } catch (Exception e) {
  596. e.printStackTrace();
  597. SpringUtil.getBean(ProjectService.class).setImportPatentTaskStatus(3, params.getTaskId());
  598. if (FLAG > 0) {
  599. int successCount = total - FLAG;
  600. WebSocketServer.sendInfo(Response.error("部分数据上传成功" + "\n" + "成功条数:" + successCount + "失败条数:" + FLAG), params.getUserId());
  601. }
  602. FLAG = 0;
  603. }
  604. }
  605. /**
  606. * @date 2022-7-11
  607. * @name 数据库交互
  608. * @description 将装配完毕的VO类向数据库中不同的表进行添加或修改操作(dataToDB兄弟类)
  609. */
  610. @Transactional(rollbackFor = Exception.class)
  611. public String dataToDBCell(PatentCell patentCell) {
  612. UploadParamsVO uploadParamsVO = new UploadParamsVO();
  613. uploadParamsVO.setPatent(new Patent());
  614. uploadParamsVO.getPatent().setPatentNo(patentCell.getPatentNo());
  615. getOneOrInsertOne(uploadParamsVO);
  616. uploadParamsVO.setSimpleStatus(patentCell.getStatue());
  617. try {
  618. //专利信息 OS_PATENT
  619. if (uploadParamsVO.getPatent() != null) {
  620. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.PATENT_SIMPLE_STATUS));
  621. Integer simpleStatus = Integer.parseInt(systemDictList.stream()
  622. .filter(systemDict -> systemDict.getType().equals(Constants.PATENT_SIMPLE_STATUS) && systemDict.getLabel().equals(uploadParamsVO.getPatentSimpleStatus()))
  623. .findFirst()
  624. .orElse(new SystemDict()).getValue());
  625. uploadParamsVO.getPatent().setSimpleStatus(simpleStatus);
  626. uploadParamsVO.getPatent().updateById();
  627. }
  628. uploadParamsVO.setPatentRight(new PatentRight());
  629. uploadParamsVO.getPatentRight().setContent(StringUtils.join(patentCell.getRights(), ""));
  630. uploadParamsVO.setSelfContent(patentCell.getMainRignt());
  631. //权利要求 OS_PATENT_RIGHT
  632. patentRightBusiness(uploadParamsVO);
  633. //说明书(文本) OS_PATENT_INSTRUCTION_TEXT
  634. uploadParamsVO.setPatentInstructionText(new PatentInstructionText());
  635. uploadParamsVO.getPatentInstructionText().setManual(patentCell.getPatentInstructionText());
  636. if (uploadParamsVO.getPatentInstructionText() != null) {
  637. patentInstructionTextBusiness(uploadParamsVO);
  638. }
  639. //简单同族 OS_PATENT_SIMPLEFAMILY
  640. patentSimplyFamilyBusiness(uploadParamsVO);
  641. //发明人 OS_PATENT_INVENTOR
  642. patentInventorBusiness(uploadParamsVO);
  643. //申请人(原始)/权利人(当前) OS_PATENT_APPLICATION || OS_APPLICATION_ATTR
  644. patentApplicationBusiness(uploadParamsVO);
  645. //申请人地址 OS_PATENT_APPLICATION
  646. patentApplicationAddressBusiness(uploadParamsVO);
  647. //分类号关联 OS_PATENT_TYPENO
  648. patentTypeNoBusiness(uploadParamsVO);
  649. //事务信息 OS_PATENT_AFFAIR
  650. patentAffairBusiness(uploadParamsVO);
  651. return Response.success();
  652. } catch (Exception e) {
  653. e.printStackTrace();
  654. if (uploadParamsVO.getPatent() != null) {
  655. ImportErrorLog importErrorLog = new ImportErrorLog();
  656. importErrorLog.setPatentId(uploadParamsVO.getPatent().getId())
  657. .setPatentNo(uploadParamsVO.getPatent().getPatentNo())
  658. .setCreateTime(new SimpleDateFormat("yyyy-MM-dd 24HI:mm:ss").format(new Date()));
  659. // .setCreateUserId(Integer.parseInt(params.getUserId()))
  660. // .setMistakeMessage(e.getMessage())
  661. // .setProjectId(params.getProjectId());
  662. importErrorLogMapper.insert(importErrorLog);
  663. FLAG += 1;
  664. }
  665. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  666. return Response.error();
  667. }
  668. }
  669. }