ReportService.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.core.base.Constants;
  3. import cn.cslg.pas.common.model.dto.report.*;
  4. import cn.cslg.pas.common.model.vo.ReportVO;
  5. import cn.cslg.pas.common.utils.*;
  6. import cn.cslg.pas.domain.*;
  7. import cn.cslg.pas.mapper.ReportMapper;
  8. import cn.hutool.core.util.IdUtil;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import com.deepoove.poi.XWPFTemplate;
  12. import com.deepoove.poi.config.Configure;
  13. import com.deepoove.poi.data.PictureRenderData;
  14. import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
  15. import lombok.RequiredArgsConstructor;
  16. import org.springframework.context.annotation.Lazy;
  17. import org.springframework.scheduling.annotation.Async;
  18. import org.springframework.stereotype.Service;
  19. import java.io.FileOutputStream;
  20. import java.util.*;
  21. import java.util.stream.Collectors;
  22. /**
  23. * <p>
  24. * 报告表 服务实现类
  25. * </p>
  26. *
  27. * @author 王岩
  28. * @since 2021-12-27
  29. */
  30. @Service
  31. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  32. public class ReportService extends ServiceImpl<ReportMapper, Report> {
  33. private final PatentService patentService;
  34. private final ReportTemplateService reportTemplateService;
  35. private final ReportTemplateLabelService reportTemplateLabelService;
  36. private final ProjectService projectService;
  37. private final PatentAffairService patentAffairService;
  38. private final PatentApplicantService patentApplicantService;
  39. private final PatentApplicantLinkService patentApplicantLinkService;
  40. private final PatentInventorService patentInventorService;
  41. private final PatentInventorLinkService patentInventorLinkService;
  42. private final PatentLicensorService patentLicensorService;
  43. private final SystemDictService systemDictService;
  44. private final PatentAgencyService patentAgencyService;
  45. private final PatentAgentService patentAgentService;
  46. private final FileUtils fileUtils;
  47. private final ProjectFolderPatentLinkService projectFolderPatentLinkService;
  48. private final ProjectFieldPatentLinkService projectFieldPatentLinkService;
  49. private final PatentLabelService patentLabelService;
  50. private final PatentClassNumberLinkService patentClassNumberLinkService;
  51. private final PatentInstructionTextService patentInstructionTextService;
  52. private final PatentRightService patentRightService;
  53. private final PatentSimpleFamilyLinkService patentSimpleFamilyLinkService;
  54. public List<Report> getReportList(ReportVO params) {
  55. LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>();
  56. if (StringUtils.isNotEmpty(params.getPatentKey())) {
  57. queryWrapper.eq(Report::getPatentKey, params.getPatentKey());
  58. }
  59. queryWrapper.orderByDesc(Report::getCreateTime);
  60. List<Report> dataList = this.list(queryWrapper);
  61. dataList.forEach(item -> item.setCfg(null));
  62. return dataList;
  63. }
  64. public Report getReportById(Integer id) {
  65. Report report = this.getById(id);
  66. report.setCfg(null);
  67. return report;
  68. }
  69. public List<Report> getReportByIds(List<Integer> ids) {
  70. if (ids == null || ids.size() == 0) {
  71. return new ArrayList<>();
  72. }
  73. LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>();
  74. queryWrapper.in(Report::getId, ids);
  75. return this.list(queryWrapper);
  76. }
  77. public List<Integer> getReportIdsLikeName(String name) {
  78. LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>();
  79. queryWrapper.like(Report::getName, name);
  80. List<Integer> ids = this.list(queryWrapper).stream().map(Report::getId).collect(Collectors.toList());
  81. if (ids.size() == 0) {
  82. ids.add(0);
  83. }
  84. return ids;
  85. }
  86. @Async
  87. public void add(Report report) {
  88. try {
  89. LoopRowTableRenderPolicy hackLoopSameLineTableRenderPolicy = new LoopRowTableRenderPolicy(true);
  90. Configure config = Configure.builder()
  91. .bind("content", hackLoopSameLineTableRenderPolicy)//权利要求行循环
  92. .bind("selfcontent", hackLoopSameLineTableRenderPolicy)//独权合并行
  93. .bind("patents", hackLoopSameLineTableRenderPolicy)
  94. .useSpringEL()//使用spring表达式
  95. .setValidErrorHandler(new Configure.AbortHandler())
  96. .build();
  97. //获取模板
  98. ReportTemplate reportTemplate = reportTemplateService.getTemplateById(report.getTemplateId());
  99. XWPFTemplate template = XWPFTemplate.compile(fileUtils.getPath(reportTemplate.getPath()), config);
  100. //数据整合
  101. Map<String, Object> map = this.assemData(report);
  102. //渲染数据
  103. template.render(map);
  104. //导出
  105. String fileName = IdUtil.simpleUUID() + ".docx";
  106. String directoryName = fileUtils.createDirectory();
  107. String savePath = fileUtils.getSavePath(directoryName);
  108. template.writeAndClose(new FileOutputStream(savePath + fileName));
  109. String url = fileUtils.getDirectory2(directoryName) + fileName;
  110. //保存文件地址到报表表
  111. report.setPath(url);
  112. report.setStatus(1);
  113. report.updateById();
  114. this.getReturnData(String.valueOf(report.getCreateBy()));
  115. } catch (Exception e) {
  116. e.printStackTrace();
  117. report.setStatus(2);
  118. report.updateById();
  119. this.getReturnData(String.valueOf(report.getCreateBy()));
  120. }
  121. }
  122. private void getReturnData(String userId) {
  123. Map<String, Object> map = new HashMap<>();
  124. map.put("success", true);
  125. WebSocketServer.sendInfo(Response.success(map), userId);
  126. }
  127. //组建数据
  128. private Map<String, Object> assemData(Report report) {
  129. //数据整合
  130. Map<String, Object> map = new HashMap<>();
  131. //1.系统数据
  132. String date = DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
  133. String[] ds = date.split("-");
  134. map.put("sys", new SystemMO(ds[0], ds[1], ds[2], "", report.getName()));
  135. //2专题库信息
  136. ThematicMO thematicMO = this.formatThematic(report);
  137. map.put("thematic", thematicMO);
  138. //3 分类,专利数据
  139. List<ClassifyMO> classifyMOS = this.formatClassify(report);
  140. if (classifyMOS.size() > 0) {
  141. for (ClassifyMO m : classifyMOS) {
  142. map.put(m.getKey(), m);
  143. }
  144. }
  145. //4.所有专利
  146. List<PatentMO> patentList = new ArrayList<>();
  147. List<Patent> patents = patentService.getPatentListByIds(report.getPatentIds());
  148. ParameModel parameModel = getParame(report.getPatentIds());
  149. if (patents != null && patents.size() > 0) {
  150. for (Patent p : patents) {
  151. patentList.add(this.formatPatentMO(p, parameModel.getAllApplicant(), parameModel.getAllAffair(), parameModel.getAllInventor(), parameModel.getAllInventorRelation(), parameModel.getAllLicensorRelation()));
  152. }
  153. }
  154. map.put("patents", patentList);
  155. return map;
  156. }
  157. private List<ClassifyMO> formatClassify(Report report) {
  158. List<ClassifyMO> list = new ArrayList<>();
  159. //获取分类
  160. List<ReportTemplateLabel> reportTemplateLabelList = reportTemplateLabelService.getTemplateLabelByTemplateIds(Collections.singletonList(report.getTemplateId()));
  161. List<ReportPatentLabelDTO> reportLabelCfg = JsonUtils.jsonToList(report.getCfg(), ReportPatentLabelDTO.class);
  162. ClassifyMO classifyMO;
  163. for (ReportTemplateLabel label : reportTemplateLabelList) {
  164. classifyMO = new ClassifyMO();
  165. classifyMO.setKey(label.getLabel().replace("-", ""));
  166. classifyMO.setClassify_name(label.getName());
  167. //此分类的配置的专利
  168. ReportPatentLabelDTO lscfg = null;
  169. if (reportLabelCfg != null) {
  170. lscfg = reportLabelCfg.stream().filter(m -> m.getLabel().equals(label.getId())).findFirst().orElse(null);
  171. }
  172. if (lscfg == null || lscfg.getId() == null || lscfg.getId().size() == 0) {
  173. continue;
  174. }
  175. List<Integer> patentIDS = lscfg.getId();
  176. List<Patent> patentList = patentService.getPatentListByIds(patentIDS);
  177. if (patentList == null || patentList.size() == 0) {
  178. continue;
  179. }
  180. ParameModel parameModel = this.getParame(patentIDS);
  181. List<PatentMO> arrys = new ArrayList<>();
  182. for (Patent p : patentList) {
  183. arrys.add(this.formatPatentMO(p, parameModel.getAllApplicant(), parameModel.getAllAffair(), parameModel.getAllInventor(), parameModel.getAllInventorRelation(), parameModel.getAllLicensorRelation()));
  184. }
  185. classifyMO.setArrys(arrys);
  186. list.add(classifyMO);
  187. }
  188. //补齐其他标记
  189. if (reportTemplateLabelList.size() != list.size()) {
  190. for (ReportTemplateLabel lb : reportTemplateLabelList) {
  191. String lkey = lb.getLabel().replace("-", "");
  192. long count = list.stream().filter(m -> m.getKey().equalsIgnoreCase(lkey)).count();
  193. if (count == 0) {
  194. classifyMO = new ClassifyMO();
  195. classifyMO.setKey(lkey);
  196. classifyMO.setClassify_name(lb.getName());
  197. classifyMO.setArrys(new ArrayList<>());
  198. list.add(classifyMO);
  199. }
  200. }
  201. }
  202. return list;
  203. }
  204. private ParameModel getParame(List<Integer> ids) {
  205. List<PatentApplicantLink> attrList = patentApplicantLinkService.getApplicantAttributesListByPatentIds(ids);
  206. List<PatentAffair> affList = patentAffairService.getPatentAffairListByPatentIds(ids);
  207. List<PatentInventor> inventorList = patentInventorService.getPatentInventorByPatentIds(ids);
  208. List<PatentInventorLink> inventorRelationList = patentInventorLinkService.getPatentInventorLinkByPatentIds(ids);
  209. List<PatentLicensor> licensorList = patentLicensorService.getPatentLicensorByPatentIds(ids);
  210. ParameModel m = new ParameModel();
  211. m.setAllAffair(affList);
  212. m.setAllApplicant(attrList);
  213. m.setAllInventor(inventorList);
  214. m.setAllInventorRelation(inventorRelationList);
  215. m.setAllLicensorRelation(licensorList);
  216. return m;
  217. }
  218. private ThematicMO formatThematic(Report report) {
  219. Project project = projectService.getProjectById(report.getProjectId());
  220. ThematicMO thematicMO = new ThematicMO();
  221. thematicMO.setTname(FormatUtil.toString(project.getName()));//专题库名称
  222. thematicMO.setTechnical_theme(FormatUtil.toString(project.getTechnicalTheme()));//技术主题
  223. thematicMO.setInnerfile(FormatUtil.toString(project.getInnerFile()));//内部案卷
  224. thematicMO.setUpdate_cycle(project.getUpdate().equals(1) ? "是" : "否");//是否更新
  225. thematicMO.setTreat_status(FormatUtil.toString(project.getStatus()));//处理状态
  226. thematicMO.setContract_no(FormatUtil.toString(project.getContractNo()));//合同号
  227. thematicMO.setCase_data(FormatUtil.toString(project.getCaseDate()));//委案日
  228. thematicMO.setTupdate_time(FormatUtil.toString(project.getUpdateTime()));//更新周期
  229. thematicMO.setTremark(FormatUtil.toString(project.getRemark()));//备注
  230. thematicMO.setTcreate_time(DateUtils.formatDate(project.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));//TODO:创建时间
  231. thematicMO.setSurvey_type(FormatUtil.toString(project.getTypeName()));//调查类型
  232. thematicMO.setScenario(FormatUtil.toString(project.getScenarioName()));//委托场景
  233. thematicMO.setClient(FormatUtil.toString(project.getClientName()));//委托方
  234. return thematicMO;
  235. }
  236. public PatentMO formatPatentMO(Patent p,
  237. List<PatentApplicantLink> allApplicant,
  238. List<PatentAffair> allAffair,
  239. List<PatentInventor> allInventor,
  240. List<PatentInventorLink> allInventorRelation,
  241. List<PatentLicensor> allLicensorRelation
  242. ) {
  243. PatentMO patentMO = new PatentMO();
  244. patentMO.setPname(FormatUtil.toString(p.getName()));//专利名称(标题)
  245. patentMO.setTranslate_name(FormatUtil.toString(p.getNameOut()));//专利名称(标题)(译)
  246. patentMO.setPatentno(FormatUtil.toString(p.getPatentNo()));//专利号
  247. patentMO.setAbstracts(FormatUtil.toString(p.getAbstractStr()));//摘要
  248. patentMO.setAbstractout(FormatUtil.toString(p.getAbstractOut()));//摘要(译)
  249. patentMO.setApplicationno(FormatUtil.toString(p.getApplicationNo()));//申请号
  250. patentMO.setAppdate(DateUtils.formatDate(p.getApplicationDate(), DateUtils.YYYY_MM_DD));//申请日
  251. patentMO.setPublicno(FormatUtil.toString(p.getPublicNo()));//公开号
  252. patentMO.setPublicdate(DateUtils.formatDate(p.getPublicDate(), DateUtils.YYYY_MM_DD));//:公开日
  253. patentMO.setFpublicdate(DateUtils.formatDate(p.getFirstPublicDate(), DateUtils.YYYY_MM_DD));//:首次公开日
  254. patentMO.setPublictono(FormatUtil.toString(p.getPublicAccreditNo()));//公开授权号
  255. patentMO.setPublictodate(DateUtils.formatDate(p.getPublicAccreditDate(), DateUtils.YYYY_MM_DD));//:公开授权日
  256. patentMO.setBureau(FormatUtil.toString(p.getBureau()));//受理局
  257. List<PatentClassNumberLink> patentClassNumberLinkList = patentClassNumberLinkService.getPatentClassNumberLinkByPatentIds(Collections.singletonList(p.getId()));
  258. patentMO.setIntclassno(FormatUtil.toString(StringUtils.join(patentClassNumberLinkList.stream().filter(item -> item.getType().equals(Constants.PATENT_CLASS_NUMBER_IPC)).map(PatentClassNumberLink::getCode).collect(Collectors.toList()), "\n")));//IPC分类号
  259. patentMO.setIntclasscpcno(FormatUtil.toString(StringUtils.join(patentClassNumberLinkList.stream().filter(item -> item.getType().equals(Constants.PATENT_CLASS_NUMBER_CPC)).map(PatentClassNumberLink::getCode).collect(Collectors.toList()), "\n")));//CPC分类号
  260. patentMO.setIntclassupcno(FormatUtil.toString(StringUtils.join(patentClassNumberLinkList.stream().filter(item -> item.getType().equals(Constants.PATENT_CLASS_NUMBER_UPC)).map(PatentClassNumberLink::getCode).collect(Collectors.toList()), "\n")));//UPC分类号
  261. patentMO.setIntclasslocno(FormatUtil.toString(StringUtils.join(patentClassNumberLinkList.stream().filter(item -> item.getType().equals(Constants.PATENT_CLASS_NUMBER_LOC)).map(PatentClassNumberLink::getCode).collect(Collectors.toList()), "\n")));//LOC分类号
  262. patentMO.setPstatus(systemDictService.getSystemDictLabelByTypeAndValue(Constants.PATENT_SIMPLE_STATUS, p.getSimpleStatus()));//状态
  263. patentMO.setPtype(systemDictService.getSystemDictLabelByTypeAndValue(Constants.PATENT_TYPE, p.getType()));//类型
  264. patentMO.setCode(FormatUtil.toString(p.getCode()));//文献代码
  265. PatentInstructionText patentInstructionText = patentInstructionTextService.getPatentInstructionTextByPatentId(p.getId());
  266. if (patentInstructionText != null) {
  267. patentMO.setManual(FormatUtil.toString(patentInstructionText.getManual()));//说明书
  268. patentMO.setManualout(FormatUtil.toString(patentInstructionText.getManualOut()));//说明书(译)
  269. }
  270. patentMO.setPage(FormatUtil.toString(p.getDocPage()));//文献页数
  271. patentMO.setInventornum(FormatUtil.toString(p.getInventorNum()));//发明人数量
  272. patentMO.setNum2(FormatUtil.toString(p.getSelfRightContentNum()));//权利要求数量
  273. patentMO.setNum3(FormatUtil.toString(p.getSelfRightNum()));//独立权利要求数量 这个字段是没有数据的
  274. List<PatentRight> patentRightList = patentRightService.getPatentRightByPatentId(p.getId());
  275. List<PatentMO.ContentMO2> cs = formatContent(patentRightList.stream().filter(item -> item.getType().equals(1)).collect(Collectors.toList()));
  276. patentMO.setSelfcontent(cs);//独立权利要求
  277. patentMO.setPriorityno(FormatUtil.toString(p.getPriorityNo()));//优先权号
  278. patentMO.setPrioritycountry(FormatUtil.toString(p.getPriorityCountry()));//优先权国家
  279. patentMO.setPrioritydate(DateUtils.formatDate(p.getPriorityDate(), DateUtils.YYYY_MM_DD));
  280. patentMO.setSimplefamilynum(FormatUtil.toString(p.getSimpleFamilyNum()));//:简单同族数量
  281. patentMO.setInpadocfamilynum(FormatUtil.toString(p.getInpadocFamilyNum()));//:Inpadoc同族数量
  282. patentMO.setQuoteno(FormatUtil.toString(p.getQuoteNum()));//:引用专利数量
  283. patentMO.setQuotedno(FormatUtil.toString(p.getQuotedNum()));//:被引用数量
  284. patentMO.setQuotedno3(FormatUtil.toString(p.getQuotedNum3()));//:三年内被引用数量
  285. patentMO.setQuotedno5(FormatUtil.toString(p.getQuotedNum5()));//:五年内被引用数量
  286. List<PatentSimpleFamilyLink> patentSimpleFamilyLinkList = patentSimpleFamilyLinkService.getPatentSimpleFamilyLinkByFamilyIds(Arrays.asList(p.getSimpleFamily(), p.getInpadocFamily()));
  287. patentMO.setSfamily(FormatUtil.toString(StringUtils.join(patentSimpleFamilyLinkList.stream().filter(item -> item.getFamilyId().equals(p.getSimpleFamily())).map(PatentSimpleFamilyLink::getPatentNo).collect(Collectors.toList()), " | ")));//简单同族
  288. patentMO.setIfamily(FormatUtil.toString(StringUtils.join(patentSimpleFamilyLinkList.stream().filter(item -> item.getFamilyId().equals(p.getInpadocFamily())).map(PatentSimpleFamilyLink::getPatentNo).collect(Collectors.toList()), " | ")));//i同族
  289. if (StringUtils.isNotEmpty(p.getAgencyId())) {
  290. PatentAgency a = patentAgencyService.getById(p.getAgencyId());
  291. if (a != null) {
  292. patentMO.setAgency(a.getName());//:代理机构
  293. }
  294. }
  295. List<PatentAgent> b = patentAgentService.getPatentAgentByPatentId(p.getId());
  296. if (b != null && b.size() != 0) {
  297. patentMO.setAgent(StringUtils.join(b.stream().map(PatentAgent::getName).collect(Collectors.toList()), ","));
  298. }
  299. patentMO.setWonational(FormatUtil.toString(p.getWo()));//WO国家阶段
  300. patentMO.setExaminer(p.getExaminer());//审查员
  301. patentMO.setAssexaminer(p.getAidExaminer());//助理审查员
  302. patentMO.setQuote(FormatUtil.toString(p.getQuote()));//引用专利
  303. patentMO.setQuoted(FormatUtil.toString(p.getQuoted()));//被引用专利
  304. patentMO.setNonpatentquote(FormatUtil.toString(p.getNotPatentQuote()));//非专利引用文献
  305. if (StringUtils.isNotEmpty(p.getAbstractPath())) {
  306. PictureRenderData pic = new PictureRenderData(100, 100, fileUtils.getPath(p.getAbstractPath()));
  307. patentMO.setAbstract_path(pic);//摘要附图
  308. }
  309. patentMO.setEpcountry(FormatUtil.toString(p.getEpStatus()));//指定国状态
  310. //1是权利人 2是申请人
  311. List<PatentApplicantLink> applyList = allApplicant.stream().filter(m -> m.getPatentId().equals(p.getId()) && m.getType().equals(2)).collect(Collectors.toList());
  312. if (applyList.size() > 0) {
  313. //申请人 当前
  314. List<Integer> currAppIDS = applyList.stream().map(PatentApplicantLink::getApplicantId).collect(Collectors.toList());
  315. List<PatentApplicant> alist = patentApplicantService.getPatentApplicantByIds(currAppIDS);
  316. List<String> names = alist.stream().map(PatentApplicant::getName).collect(Collectors.toList());
  317. patentMO.setApplicant_names_current(FormatUtil.toString(StringUtils.join(names, ",")));
  318. List<PatentApplyMO> aplist = new ArrayList<>();
  319. PatentApplyMO mo;
  320. for (PatentApplicant a : alist) {
  321. mo = new PatentApplyMO();
  322. mo.setName(a.getName());
  323. mo.setBname(a.getShortName());
  324. mo.setRemark(a.getRemark());
  325. aplist.add(mo);
  326. }
  327. PatentApplicantLink firstApplicantLink = applyList.stream().filter(item -> item.getOrder().equals(0)).findFirst().orElse(null);
  328. if (firstApplicantLink != null) {
  329. PatentApplicant firstApplicant = alist.stream().filter(item -> item.getId().equals(firstApplicantLink.getApplicantId())).findFirst().orElse(null);
  330. if (firstApplicant != null) {
  331. if (firstApplicant.getName() == null || firstApplicant.getName().equals("")) {
  332. patentMO.setFirstapplicant("无");
  333. } else {
  334. patentMO.setFirstapplicant(FormatUtil.toString(firstApplicant.getName()));
  335. }
  336. }
  337. }
  338. patentMO.setApplicant_list_current(aplist);
  339. //申请人 标准
  340. List<String> names2 = alist.stream().map(PatentApplicant::getShortName).collect(Collectors.toList());
  341. patentMO.setApplicant_names_standard(FormatUtil.toString(StringUtils.join(names2, ",")));//赋值
  342. List<PatentApplyMO> aplist2 = new ArrayList<>();
  343. PatentApplyMO mo2;
  344. for (PatentApplicant a : alist) {
  345. mo2 = new PatentApplyMO();
  346. mo2.setName(a.getName());
  347. mo2.setBname(a.getShortName());
  348. mo2.setRemark(a.getRemark());
  349. aplist2.add(mo2);
  350. }
  351. patentMO.setApplicant_list_standard(aplist2);
  352. }
  353. //权利人
  354. List<PatentApplicantLink> obligeeList = allApplicant.stream().filter(m -> m.getPatentId().equals(p.getId()) && m.getType().equals(1)).collect(Collectors.toList());
  355. if (obligeeList.size() > 0) {
  356. //权利人 当前
  357. List<Integer> currAppIDS = obligeeList.stream().map(PatentApplicantLink::getApplicantId).collect(Collectors.toList());
  358. List<PatentApplicant> alist = patentApplicantService.getPatentApplicantByIds(currAppIDS);
  359. List<String> names = alist.stream().map(PatentApplicant::getName).collect(Collectors.toList());
  360. patentMO.setObligee_names_current(FormatUtil.toString(StringUtils.join(names, ",")));//赋值
  361. List<PatentApplyMO> aplist = new ArrayList<>();
  362. PatentApplyMO mo;
  363. for (PatentApplicant a : alist) {
  364. mo = new PatentApplyMO();
  365. mo.setName(a.getName());
  366. mo.setBname(a.getShortName());
  367. mo.setRemark(a.getRemark());
  368. aplist.add(mo);
  369. }
  370. patentMO.setObligee_list_current(aplist);
  371. //权利人 标准
  372. List<String> names2 = alist.stream().map(PatentApplicant::getName).collect(Collectors.toList());
  373. patentMO.setObligee_names_standard(FormatUtil.toString(StringUtils.join(names2, ",")));//赋值
  374. List<PatentApplyMO> aplist2 = new ArrayList<>();
  375. PatentApplyMO mo2;
  376. for (PatentApplicant a : alist) {
  377. mo2 = new PatentApplyMO();
  378. mo2.setName(a.getName());
  379. mo2.setBname(a.getShortName());
  380. mo2.setRemark(a.getRemark());
  381. aplist2.add(mo2);
  382. }
  383. patentMO.setObligee_list_standard(aplist2);
  384. }
  385. //法律事务
  386. List<PatentLawMO> affairMoList = new ArrayList<>();
  387. List<PatentAffair> affairList = allAffair.stream().filter(m -> m.getPatentId().equals(p.getId())).collect(Collectors.toList());
  388. if (affairList.size() > 0) {
  389. PatentLawMO m;
  390. for (PatentAffair a : affairList) {
  391. m = new PatentLawMO();
  392. m.setLaw_content(a.getContent());
  393. m.setLaw_datetime(DateUtils.formatDate(a.getDateTime(), DateUtils.YYYY_MM_DD));
  394. m.setLaw_remark(a.getRemark());
  395. m.setLaw_simplestatus(systemDictService.getSystemDictLabelByTypeAndValue(Constants.PATENT_SIMPLE_STATUS, a.getSimpleStatus()));
  396. m.setLaw_status(systemDictService.getSystemDictLabelByTypeAndValue(Constants.PATENT_STATUS, a.getStatus()));
  397. affairMoList.add(m);
  398. }
  399. }
  400. patentMO.setLawArrys(affairMoList);//法律事务
  401. //发明人
  402. List<InventorMO> inventorMoList = new ArrayList<>();
  403. List<PatentInventorLink> inventorReloationList = allInventorRelation.stream().filter(m -> m.getPatentId().equals(p.getId())).collect(Collectors.toList());
  404. if (inventorReloationList.size() > 0) {
  405. List<Integer> ids = inventorReloationList.stream().map(PatentInventorLink::getInventorId).collect(Collectors.toList());
  406. List<PatentInventor> inventorList = allInventor.stream().filter(m -> ids.contains(m.getId())).collect(Collectors.toList());
  407. List<String> inventorNames = inventorList.stream().map(PatentInventor::getName).collect(Collectors.toList());
  408. patentMO.setInventor_names(FormatUtil.toString(StringUtils.join(inventorNames, ",")));//赋值
  409. InventorMO m;
  410. for (PatentInventor a : inventorList) {
  411. m = new InventorMO();
  412. m.setName(a.getName());
  413. inventorMoList.add(m);
  414. }
  415. }
  416. patentMO.setInventor_list(inventorMoList);//发明人
  417. List<PermitMO> permitMoList = new ArrayList<>(); //许可人
  418. List<PermitMO> licentorMoList = new ArrayList<>();//被许可
  419. List<PatentLicensor> permitRelation = allLicensorRelation.stream().filter(m -> m.getPatentId().equals(p.getId())).collect(Collectors.toList());
  420. permitRelation.forEach(item -> {
  421. PermitMO m1 = new PermitMO();
  422. m1.setName(item.getLicensor());
  423. PermitMO m2 = new PermitMO();
  424. m2.setName(item.getLicensee());
  425. m1.setPermittype(item.getType());
  426. m2.setPermittype(item.getType());
  427. permitMoList.add(m1);
  428. licentorMoList.add(m2);
  429. });
  430. patentMO.setPermit_list(permitMoList);//许可
  431. patentMO.setLicensed_list(licentorMoList);//被许可
  432. return patentMO;
  433. }
  434. //独立权利要求格式化
  435. private List<PatentMO.ContentMO2> formatContent(List<PatentRight> content) {
  436. if (content == null || content.size() == 0) {
  437. return new ArrayList<>();
  438. }
  439. List<PatentMO.ContentMO> list = new ArrayList<>();
  440. for (int i = 0; i < content.size(); i++) {
  441. PatentMO.ContentMO m = new PatentMO.ContentMO();
  442. m.setTitle("独权" + (i + 1));
  443. m.setItem(Collections.singletonList(content.get(i).getContent()));
  444. m.setOut(Collections.singletonList(content.get(i).getContentOut()));
  445. list.add(m);
  446. }
  447. List<PatentMO.ContentMO2> rlist = new ArrayList<>();
  448. if (list.size() > 0) {
  449. for (PatentMO.ContentMO cm : list) {
  450. StringBuilder sb = new StringBuilder();
  451. StringBuilder sbb = new StringBuilder();
  452. for (String s : cm.getItem()) {
  453. sb.append(s);
  454. }
  455. for (String s : cm.getOut()) {
  456. sbb.append(s);
  457. }
  458. String dcode = sb.toString().replace("\n", "").replace(";", ";");
  459. String code;
  460. if (sbb.toString().contains("。")) {
  461. code = sbb.toString().replace("\n", "").replace("。", ";");
  462. } else {
  463. code = sbb.toString().replace("\n", "").replace(";", ";");
  464. }
  465. List<String> sarry = Arrays.asList(dcode.split(";"));
  466. List<String> out = Arrays.asList(code.split(";"));
  467. for (int i = 0, sarrySize = sarry.size(); i < sarrySize; i++) {
  468. String s = sarry.get(i);
  469. if (sarrySize - 1 == i) {
  470. if (out.size() > i) {
  471. rlist.add(new PatentMO.ContentMO2(cm.getTitle(), s + ".", out.get(i)));
  472. } else {
  473. rlist.add(new PatentMO.ContentMO2(cm.getTitle(), s + ".", ""));
  474. }
  475. } else {
  476. if (out.size() > i) {
  477. rlist.add(new PatentMO.ContentMO2(cm.getTitle(), s + ";", out.get(i)));
  478. } else {
  479. rlist.add(new PatentMO.ContentMO2(cm.getTitle(), s + ";", ""));
  480. }
  481. }
  482. }
  483. }
  484. }
  485. return rlist;
  486. }
  487. public List<ReportPatentDTO> getPatentList(List<Integer> patentIds, Integer projectId) {
  488. List<ReportPatentDTO> dataList = new ArrayList<>();
  489. List<Patent> patentList = patentService.getPatentListByIds(patentIds);
  490. List<PatentApplicant> patentApplicantList = patentApplicantService.getPatentApplicantByPatentIds(patentIds);
  491. List<ProjectFolderPatentLink> projectFolderPatentLinkList = projectFolderPatentLinkService.getProjectFolderLinkListByProjectIdAndPatentIds(projectId, patentIds);
  492. List<ProjectFieldPatentLink> projectFieldPatentLinkList = projectFieldPatentLinkService.getProjectPatentLinkByPatentIdsAndProjectId(patentIds, projectId);
  493. List<PatentLabel> patentLabelList = patentLabelService.getPatentLabelByPatentIdsAndProjectId(patentIds, projectId);
  494. patentList.forEach(item -> {
  495. List<PatentApplicant> patentApplicants = patentApplicantList.stream().filter(patentApplicant -> patentApplicant.getPatentId().equals(item.getId())).collect(Collectors.toList());
  496. List<ProjectFieldPatentLink> projectFieldPatentLinks = projectFieldPatentLinkList.stream().filter(projectFieldPatentLink -> projectFieldPatentLink.getPatentId().equals(item.getId())).collect(Collectors.toList());
  497. ReportPatentDTO patentDTO = new ReportPatentDTO();
  498. List<ReportPatentDTO.Field> fieldList = new ArrayList<>();
  499. patentDTO.setName(item.getName());
  500. patentDTO.setPatentno(item.getPatentNo());
  501. patentDTO.setApplicationno(item.getApplicationNo());
  502. patentDTO.setPublicno(item.getPublicNo());
  503. patentDTO.setId(item.getId());
  504. patentDTO.setType(item.getType());
  505. patentDTO.setStatus(item.getSimpleStatus());
  506. patentDTO.setFolder(projectFolderPatentLinkList.stream().filter(projectFolderPatentLink -> projectFolderPatentLink.getPatentId().equals(item.getId())).map(ProjectFolderPatentLink::getFolderId).distinct().collect(Collectors.toList()));
  507. patentDTO.setApplicant(patentApplicants.stream().filter(patentApplicant -> patentApplicant.getDataType().equals(2)).map(PatentApplicant::getName).collect(Collectors.toList()));
  508. patentDTO.setObligee(patentApplicants.stream().filter(patentApplicant -> patentApplicant.getDataType().equals(1)).map(PatentApplicant::getName).collect(Collectors.toList()));
  509. List<Integer> fieldIds = projectFieldPatentLinks.stream().map(ProjectFieldPatentLink::getFieldId).distinct().collect(Collectors.toList());
  510. fieldIds.forEach(fieldId -> {
  511. ReportPatentDTO.Field field = new ReportPatentDTO.Field();
  512. field.setId(fieldId);
  513. field.setValue(projectFieldPatentLinks.stream().filter(projectFieldPatentLink -> projectFieldPatentLink.getFieldId().equals(fieldId)).map(ProjectFieldPatentLink::getOptionId).distinct().collect(Collectors.toList()));
  514. fieldList.add(field);
  515. });
  516. patentDTO.setLabel(patentLabelList.stream().filter(patentLabel -> patentLabel.getPatentId().equals(item.getId())).map(PatentLabel::getName).collect(Collectors.toList()));
  517. patentDTO.setField(fieldList);
  518. dataList.add(patentDTO);
  519. });
  520. return dataList;
  521. }
  522. //根据Id删除报告
  523. public String deleteById(List<Integer> ids) {
  524. this.deleteById(ids);
  525. return Response.success();
  526. }
  527. }