UploadPatentBatchService.java 35 KB

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