ReportExportService.java 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.dto.PatentColumnDTO;
  3. import cn.cslg.pas.common.dto.PatentDTO;
  4. import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
  5. import cn.cslg.pas.common.model.SystemMO;
  6. import cn.cslg.pas.common.model.cronModel.PersonnelVO;
  7. import cn.cslg.pas.common.model.request.StringRequest;
  8. import cn.cslg.pas.common.utils.*;
  9. import cn.cslg.pas.common.vo.*;
  10. import cn.cslg.pas.domain.ReportDocument;
  11. import cn.cslg.pas.domain.business.*;
  12. import cn.cslg.pas.domain.es.Patent;
  13. import cn.cslg.pas.domain.es.Text;
  14. import cn.cslg.pas.exception.XiaoShiException;
  15. import cn.cslg.pas.mapper.AvoidDesignMapper;
  16. import cn.cslg.pas.service.business.*;
  17. import cn.cslg.pas.service.business.es.*;
  18. import cn.cslg.pas.service.common.FileManagerService;
  19. import cn.hutool.core.util.IdUtil;
  20. import com.alibaba.fastjson.JSON;
  21. import com.alibaba.fastjson.JSONObject;
  22. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  23. import com.deepoove.poi.XWPFTemplate;
  24. import com.deepoove.poi.config.Configure;
  25. import com.deepoove.poi.data.PictureRenderData;
  26. import com.deepoove.poi.data.PictureType;
  27. import com.deepoove.poi.data.Pictures;
  28. import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
  29. import lombok.extern.slf4j.Slf4j;
  30. import org.apache.commons.lang3.StringUtils;
  31. import org.ddr.poi.html.HtmlRenderPolicy;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.stereotype.Service;
  34. import java.io.File;
  35. import java.io.FileInputStream;
  36. import java.io.IOException;
  37. import java.text.SimpleDateFormat;
  38. import java.time.format.DateTimeFormatter;
  39. import java.util.*;
  40. import java.util.stream.Collectors;
  41. @Slf4j
  42. @Service
  43. public class ReportExportService {
  44. @Autowired
  45. private ReportTempleService templeService;
  46. @Autowired
  47. private FileUtils fileUtils;
  48. @Autowired
  49. private ReportProjectService reportProjectService;
  50. @Autowired
  51. private FileManagerService fileManagerService;
  52. @Autowired
  53. private EsPatentService esPatentService;
  54. @Autowired
  55. private AvoidDesignMapper avoidDesignMapper;
  56. @Autowired
  57. private TemplateConfigService templateConfigService;
  58. @Autowired
  59. private CustomFieldService customFieldService;
  60. @Autowired
  61. private EsService esService;
  62. @Autowired
  63. private FTOCompareRecordService ftoCompareRecordService;
  64. @Autowired
  65. private EsQuotePatentService esQuotePatentService;
  66. @Autowired
  67. private EsFamilyService esFamilyService;
  68. @Autowired
  69. private LoginUtils loginUtils;
  70. @Autowired
  71. private CacheUtils cacheUtils;
  72. @Autowired
  73. private EsLegalEventService esLegalEventService;
  74. /**
  75. * @param projectId
  76. * @param templeId
  77. * @return
  78. * @throws IOException
  79. * @function: 导出报告
  80. */
  81. public String exportReport(Integer projectId, Integer templeId) throws IOException {
  82. //根据模板ID获得模板
  83. ReportTemple reportTemplate = templeService.getById(templeId);
  84. //获得模板路径
  85. String templateFilePath = fileUtils.getPath(reportTemplate.getTemplatePath());
  86. //读取模板后保存生成word的地址
  87. String fileName = IdUtil.simpleUUID() + ".docx";
  88. String directoryName = fileUtils.createDirectory();
  89. String outPath = fileUtils.getSavePath(directoryName) + fileName;
  90. //根据ProjectId 获得报告
  91. LambdaQueryWrapper<ReportProject> queryWrapper = new LambdaQueryWrapper<>();
  92. queryWrapper.eq(ReportProject::getProjectId, projectId);
  93. ReportProject report = reportProjectService.getOne(queryWrapper, false);
  94. if (report == null) {
  95. throw new XiaoShiException("报告不存在");
  96. }
  97. XWPFTemplate template = null;
  98. if (report.getReportType() == 0 || report.getReportType() == 2) {
  99. // template = this.getstabilityTemplate(projectId, templateFilePath);
  100. } else if (report.getReportType() == 3) {
  101. template = this.FTOTemplate(projectId, templateFilePath, templeId);
  102. } else if (report.getReportType() == 4) {
  103. template = this.Torttemplate(projectId, templateFilePath);
  104. } else if (report.getReportType() == 5) {
  105. template = this.avoidDesignTemplate(projectId, templateFilePath);
  106. } else if (report.getReportType() == 1) {
  107. // template = this.getThirdTemplate(report, filePath);
  108. }
  109. // 读取模板、数据并渲染
  110. // 文件是否已存在,则删除
  111. File file = new File(outPath);
  112. // 生成word保存在指定目录
  113. template.writeToFile(outPath);
  114. template.close();
  115. //导出成功后,导出报告记录入库
  116. List<String> ids = fileManagerService.uploadFileGetGuid2(Arrays.asList(file));
  117. if (ids == null || ids.size() == 0) {
  118. throw new XiaoShiException("保存记录失败");
  119. }
  120. // PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  121. PersonnelVO personnelVO = new PersonnelVO();
  122. personnelVO.setId("1");
  123. ReportDocument reportDocument = new ReportDocument();
  124. reportDocument.setProjectId(projectId);
  125. reportDocument.setFileName(fileName);
  126. reportDocument.setFileGuid(ids.get(0));
  127. reportDocument.setCreateId(personnelVO.getId());
  128. reportDocument.setTemplateId(reportTemplate.getId());
  129. reportDocument.setTemplateName(reportTemplate.getTemplateName());
  130. reportDocument.insert();
  131. if (file.exists()) {
  132. file.delete();
  133. }
  134. return ids.get(0);
  135. }
  136. private XWPFTemplate Torttemplate(Integer reportId, String filePath) throws IOException {
  137. //根据报告Id查询标的专利号
  138. LambdaQueryWrapper<ReportProject> projectLambdaQueryWrapper = new LambdaQueryWrapper<>();
  139. projectLambdaQueryWrapper.eq(ReportProject::getProjectId, reportId);
  140. ReportProject report = reportProjectService.getOne(projectLambdaQueryWrapper, false);
  141. String patentNo = report.getSignPatentNo();
  142. // PatentVO patentVO = new PatentVO();
  143. // patentVO.setPatentNos(Arrays.asList(patentNo));
  144. // //根据专利号查询专利详细信息
  145. // String resBody = outInterfaceService.getPatentDTOListForRMS(patentVO);
  146. // JSONObject jsonObject = JSONObject.parseObject(resBody);
  147. // List<JSONObject> patentDTOS = JSON.parseArray(jsonObject.get("data").toString(), JSONObject.class);
  148. // //装载单个专利的信息
  149. Map<String, Object> patentMap = new HashMap<>();
  150. // JSONObject patent = patentDTOS.get(0);
  151. // List<JSONObject> applicantJSONs = JSON.parseArray(patent.get("applicant").toString(), JSONObject.class);
  152. // StringBuilder applicants = new StringBuilder();
  153. // StringBuilder rightPerson = new StringBuilder();
  154. // applicantJSONs.forEach(tem -> {
  155. // if (Integer.parseInt(tem.get("dataType").toString()) == 1) {
  156. // applicants.append(tem.get("name") + "\r");
  157. // } else {
  158. // rightPerson.append(tem.get("name") + "\r");
  159. // }
  160. // });
  161. // //装载同族信息
  162. // JSONObject familys = JSONObject.parseObject(patent.get("family").toString());
  163. // List<String> patSnaps = JSON.parseArray(familys.get("patSnap").toString(), String.class);
  164. // List<String> simples = JSON.parseArray(familys.get("simple").toString(), String.class);
  165. // List<String> inpadocs = JSON.parseArray(familys.get("inpadoc").toString(), String.class);
  166. // patSnaps.addAll(simples);
  167. // patSnaps.addAll(inpadocs);
  168. // String familyStr = StringUtils.join(patSnaps, ",");
  169. // //装载法律状态
  170. // StringBuilder affair = new StringBuilder();
  171. // List<JSONObject> affaires = JSON.parseArray(patent.get("affair").toString(), JSONObject.class);
  172. // affaires.forEach(item -> {
  173. // affair.append(item.get("status") + "\r");
  174. // }
  175. // );
  176. // //同族专利
  177. // patentMap.put("simpleFamilys", familyStr);
  178. // //引用专利
  179. // patentMap.put("quotePatents", patent.get("quote"));
  180. // //申请日
  181. // patentMap.put("applicationDate", patent.get("applicationDate"));
  182. // //公开日
  183. // patentMap.put("publicDate", patent.get("publicDate"));
  184. // //专利号
  185. // patentMap.put("publicNo", patent.get("publicNo"));
  186. // patentMap.put("firstPublicDate", patent.get("firstPublicDate"));
  187. // patentMap.put("applicant", applicants);
  188. // patentMap.put("rightPerson", rightPerson);
  189. // patentMap.put("affair", affair);
  190. // patentMap.put("name", patent.get("name"));
  191. //图示
  192. patentMap.put("abstractPath", "");
  193. //获得专利对比记录的信息
  194. // Map<String, Object> temMap = compareMessageService.queryforTemplate(patent.get("patentNo").toString(), reportId);
  195. // List<CompareMessageVO> compareMessageVOS = (List<CompareMessageVO>) temMap.get("compareMessageVOs");
  196. //装载对比记录的信息
  197. // patentMap.put("cM", compareMessageVOS);
  198. // patentMap.put("rightNum", temMap.get("right"));
  199. // patentMap.put("mainRightNum", temMap.get("mainRight"));
  200. Map<String, Object> map = new HashMap<>();
  201. String date = DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
  202. String[] ds = date.split("-");
  203. map.put("sys", new SystemMO(ds[0], ds[1], ds[2], "", "reportName"));
  204. map.put("patentMap", patentMap);
  205. map.put("", patentNo);
  206. // 为表格的显示绑定行循环
  207. LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
  208. HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
  209. // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
  210. Configure configure = Configure.builder().bind("cM", policy).bind("targetDescription", htmlRenderPolicy).build();
  211. XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
  212. return template;
  213. }
  214. private XWPFTemplate avoidDesignTemplate(Integer projectId, String path) throws IOException {
  215. String filePath = fileUtils.getPath(path);
  216. log.info("开始处理导出规避设计报告,参数为:{}, {}", projectId, filePath);
  217. LambdaQueryWrapper<ReportProject> queryWrapper = new LambdaQueryWrapper<>();
  218. queryWrapper.eq(ReportProject::getProjectId, projectId);
  219. ReportProject report = reportProjectService.getOne(queryWrapper, false);
  220. String signPatentNo = report.getSignPatentNo();
  221. //装载标的专利信息
  222. ;
  223. //装载年月日
  224. String date = DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
  225. String[] dates = date.split("-");
  226. SystemMO systemMO = new SystemMO()
  227. .setYear(dates[0])
  228. .setMonth(dates[1])
  229. .setDay(dates[2]);
  230. //
  231. //装载特征、解释、回避设计方向、回避设计总体方向
  232. List<AvoidFeaturesVO> features = avoidDesignMapper.selectAvoidDesign(projectId);
  233. // String wholeDirection = avoidDesignWholeDirectionMapper.selectWholeDirectionByReportId(reportId);
  234. // map.put("wholeDirection", wholeDirection);
  235. //
  236. //绑定政策(绑定集合和元素循环遍历)
  237. LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
  238. //把指定元素内容识别传输成html格式
  239. HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
  240. Configure configure = Configure.builder()
  241. .bind("signPatent.rights", policy)
  242. .bind("features", policy)
  243. .bind("explainText", htmlRenderPolicy)
  244. .bind("littleDirection", htmlRenderPolicy)
  245. .bind("wholeDirection", htmlRenderPolicy)
  246. .build();
  247. XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(new HashMap<>());
  248. return template;
  249. }
  250. private PictureRenderData guidToStream(String guid) {
  251. PictureRenderData pictureRenderData = null;
  252. byte[] bytes = null;
  253. try {
  254. bytes = fileManagerService.downloadSystemFileFromFMS(guid);
  255. } catch (Exception e) {
  256. }
  257. FileInputStream fileInputStream = FileUtils.byteToFile(bytes);
  258. pictureRenderData = Pictures.ofStream(fileInputStream, PictureType.PNG)
  259. .create();
  260. return pictureRenderData;
  261. }
  262. private List<Map<String, Object>> getClaimMaps(List<Text> claims, String patentNo) {
  263. List<Map<String, Object>> rights = new ArrayList<>();
  264. if (claims == null || claims.size() == 0) {
  265. return rights;
  266. }
  267. Text claim = claims.stream().filter(item -> item.getIfOrigin().equals(true)).findFirst().orElse(null);
  268. if (claim == null) {
  269. return rights;
  270. }
  271. PatentRightParams params = new PatentRightParams();
  272. params.setContent(claim.getTextContent());
  273. params.setPatentNo(patentNo);
  274. List<RePatentClaim> patentRights = PatentRightUtils.formatPatentRight(params);
  275. //给权要进行格式更改
  276. patentRights.forEach(item -> {
  277. Map<String, Object> temMap = new HashMap<>();
  278. temMap.put("rightName", "权" + (item.getSort() + 1));
  279. temMap.put("content", item.getContent());
  280. temMap.put("rightNameLong", "权利要求" + (item.getSort() + 1));
  281. temMap.put("parentSort", item.getParentSort());
  282. temMap.put("sort", item.getSort());
  283. rights.add(temMap);
  284. });
  285. return rights;
  286. }
  287. /**
  288. * @param projectId
  289. * @param filePath
  290. * @return
  291. * @description 装载FTO模板
  292. */
  293. private XWPFTemplate FTOTemplate(Integer projectId, String filePath, Integer templateId) throws IOException {
  294. //获得模板的配置信息
  295. LambdaQueryWrapper<TemplateConfig> templateConfigWrapper = new LambdaQueryWrapper<TemplateConfig>();
  296. templateConfigWrapper.eq(TemplateConfig::getTemplateId, templateId);
  297. List<TemplateConfig> templateConfigs = templateConfigService.list(templateConfigWrapper);
  298. List<Map<String, Object>> classifyMaps = new ArrayList<>();
  299. for (TemplateConfig templateConfig : templateConfigs) {
  300. Map<String, Object> classifyMap = new HashMap<>();
  301. String value = templateConfig.getValueName();
  302. //根据value 查询专利
  303. List<EsCustomFieldValueDTO> esCustomFieldDTOS = customFieldService.getCustomFieldByValueName(value, projectId);
  304. if (esCustomFieldDTOS.size() != 0) {
  305. classifyMap.put("classify", templateConfig.getMapName());
  306. StringRequest stringRequest = new StringRequest();
  307. stringRequest.setCustomFields(esCustomFieldDTOS);
  308. stringRequest.setProjectId(projectId);
  309. stringRequest.setCurrent(1L);
  310. stringRequest.setSize(999L);
  311. List<PatentColumnDTO> patentColumnDTOS = new ArrayList<>();
  312. try {
  313. PatentDTO patentDTO = esService.esSearch(stringRequest);
  314. patentColumnDTOS = patentDTO.getPatents();
  315. } catch (Exception e) {
  316. return null;
  317. }
  318. //存放公告专利
  319. List<Map<String, Object>> announcePatents = new ArrayList<>();
  320. //存放公开专利
  321. List<Map<String, Object>> publicPatents = new ArrayList<>();
  322. //存放失效专利信息
  323. List<Map<String, Object>> lapsePatents = new ArrayList<>();
  324. for (PatentColumnDTO patent : patentColumnDTOS) {
  325. String applicants = "";
  326. String rightPerson = "";
  327. if (patent.getApplicant() != null && patent.getApplicant().size() != 0) {
  328. applicants = StringUtils.join(patent.getApplicant(), "\n");
  329. }
  330. if (patent.getRightHolder() != null && patent.getRightHolder().size() != 0) {
  331. rightPerson = StringUtils.join(patent.getRightHolder(), "\n");
  332. }
  333. List<String> affairs = esLegalEventService.getStrLegalEvent(patent.getAppNo());
  334. String affairStrs = "";
  335. if (affairs != null && affairs.size() != 0) {
  336. affairStrs = StringUtils.join(affairs, "\n");
  337. }
  338. //装载单个专利的信息
  339. Map<String, Object> patentMap = new HashMap<>();
  340. //同族专利
  341. try {
  342. //装载同族信息
  343. List<Map<String, Object>> familyMaps = esFamilyService.getPatentFamilyByNos(Arrays.asList(patent.getPatentNo()), "inpadoc");
  344. if (familyMaps != null && familyMaps.size() > 0) {
  345. Map<String, Object> familyMap = familyMaps.get(0);
  346. if (familyMap.get("nos") != null) {
  347. List<String> nos = (List<String>) familyMap.get("nos");
  348. if (nos != null && nos.size() > 0) {
  349. String nosStr = StringUtils.join(nos, "\n");
  350. patentMap.put("simpleFamilys", nosStr);
  351. }
  352. }
  353. }
  354. } catch (Exception e) {
  355. }
  356. //引用专利
  357. try {
  358. Map<String, Object> map = esQuotePatentService.getEsQutePatentByNos(patent.getPatentNo());
  359. if (map.get("nos") != null) {
  360. List<String> nos = (List<String>) map.get("nos");
  361. if (nos != null && nos.size() > 0) {
  362. String nosStr = StringUtils.join(nos, "\n");
  363. patentMap.put("quotePatents", nosStr);
  364. }
  365. }
  366. } catch (Exception e) {
  367. }
  368. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  369. //申请日
  370. if (patent.getAppDate() != null) {
  371. patentMap.put("appDate", dateFormat.format(patent.getAppDate()));
  372. }
  373. //公开日
  374. if (patent.getPublicDate() != null) {
  375. patentMap.put("publicDate", dateFormat.format(patent.getPublicDate()));
  376. }
  377. //专利号
  378. patentMap.put("publicNo", patent.getPatentNo());
  379. patentMap.put("firstPublicDate", patent.getPublicDate());
  380. patentMap.put("applicant", applicants);
  381. patentMap.put("rightPerson", rightPerson);
  382. patentMap.put("affair", affairStrs);
  383. if (patent.getTitle() != null && patent.getTitle().size() > 0) {
  384. patentMap.put("nameOut", patent.getTitle().get(0).getTextContent());
  385. }
  386. //优先权日
  387. if (patent.getPriorities() != null && patent.getPriorities().size() != 0) {
  388. patentMap.put("priorityDate", patent.getPriorities().get(0).getPriorityDate());
  389. }
  390. //图示
  391. String guid = FormatUtil.getPictureFormat(patent.getAppNo());
  392. PictureRenderData pictureData = this.guidToStream(guid);
  393. if (pictureData != null) {
  394. patentMap.put("abstractPath", pictureData);
  395. }
  396. //获得专利对比记录的信息
  397. Map<String, Object> temMap = ftoCompareRecordService.LoadCompareMessageForExport(projectId, patent.getPatentNo());
  398. List<CompareMessageVO> compareMessageVOS = (List<CompareMessageVO>) temMap.get("compareMessageVOs");
  399. //装载对比记录的信息
  400. patentMap.put("cM", compareMessageVOS);
  401. patentMap.put("rightNum", temMap.get("rightNum"));
  402. patentMap.put("mainNum", temMap.get("mainRightNum"));
  403. Integer status = Integer.parseInt(patent.getSimpleStatus());
  404. if (status == 1 || status == 5 || status == 6) {
  405. announcePatents.add(patentMap);
  406. } else if (status == 2) {
  407. lapsePatents.add(patentMap);
  408. } else if (status == 3) {
  409. publicPatents.add(patentMap);
  410. }
  411. classifyMap.put("publicPatents", publicPatents);
  412. classifyMap.put("lapsePatents", lapsePatents);
  413. classifyMap.put("announcePatents", announcePatents);
  414. }
  415. classifyMaps.add(classifyMap);
  416. }
  417. }
  418. Map<String, Object> map = new HashMap<>();
  419. String date = DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
  420. String[] ds = date.split("-");
  421. map.put("sys", new SystemMO(ds[0], ds[1], ds[2], "", "reportName"));
  422. map.put("classifys", classifyMaps);
  423. // 为表格的显示绑定行循环
  424. LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
  425. HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
  426. // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
  427. Configure configure = Configure.builder().bind("cM", policy).bind("targetDescription", htmlRenderPolicy).build();
  428. XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
  429. return template;
  430. }
  431. // private XWPFTemplate getstabilityTemplate(Integer projectId, String filePath) throws IOException {
  432. // List<PatentRight> patentRights = new ArrayList<>();
  433. //
  434. // //装载标的专利信息
  435. // LambdaQueryWrapper<ReportProject> queryWrapper = new LambdaQueryWrapper<>();
  436. // queryWrapper.eq(ReportProject::getProjectId, projectId);
  437. // ReportProject report = reportProjectService.getOne(queryWrapper, false);
  438. // String signPatentNo = report.getSignPatentNo();
  439. // Map<String, Object> signPatent = this.signPantentMess(signPatentNo);
  440. // //根据报告Id获得报告信息
  441. // // 根据拆分人(报告的创建人)Id和报告ID获得所有特征
  442. // LambdaQueryWrapper<Features> allFeaturesWrapper = new LambdaQueryWrapper<>();
  443. // allFeaturesWrapper.eq(Features::getReportId, report.getId());
  444. // allFeaturesWrapper.and(wrapper -> wrapper.eq(Features::getPartnerId, report.getPersonId()).or().eq(Features::getPartnerId, report.getCreatePersonId()));
  445. //
  446. // List<Features> allFeatures = featureService.list(allFeaturesWrapper);
  447. // //根据报告Id 查询出报告下所有的方案
  448. // LambdaQueryWrapper<CompareScenarios> queryWrapper = new LambdaQueryWrapper<>();
  449. // queryWrapper.eq(CompareScenarios::getReportId, report.getId());
  450. // List<CompareScenarios> compareScenarios = compareScenariosService.list(queryWrapper);
  451. // List<Integer> scenarioIds = compareScenarios.stream().map(CompareScenarios::getId).collect(Collectors.toList());
  452. // //根据对比方案Id 查询所有对比方案和(对比记录-特征)关联信息
  453. // List<AssoScenarIOS> scenariosRecords = new ArrayList<>();
  454. // if (scenarioIds != null && scenarioIds.size() != 0) {
  455. // LambdaQueryWrapper<AssoScenarIOS> queryRecordsByIDs = new LambdaQueryWrapper<>();
  456. // queryRecordsByIDs.in(AssoScenarIOS::getScenariosID, scenarioIds);
  457. // scenariosRecords = scenariosRecordsService.list(queryRecordsByIDs);
  458. // }
  459. // //获得对比记录-特征关联ID
  460. // List<Integer> recordfeatureRecordIds = scenariosRecords.stream().map(AssoScenarIOS::getFeatureRecordID).collect(Collectors.toList());
  461. // //从关联表里获得是公识的特征Id
  462. // List<Integer> knowedIds = scenariosRecords.stream().map(AssoScenarIOS::getFeaturesID).collect(Collectors.toList());
  463. // //根据对比记录-特征关联ID查出对比记录-特征关联信息
  464. // List<AssoRecordsFeature> assoRecordsFeatures = new ArrayList<>();
  465. // if (recordfeatureRecordIds != null && recordfeatureRecordIds.size() != 0) {
  466. // LambdaQueryWrapper<AssoRecordsFeature> wrapper = new LambdaQueryWrapper<>();
  467. // wrapper.in(AssoRecordsFeature::getId, recordfeatureRecordIds);
  468. // assoRecordsFeatures = assoRecordsFeatureService.list(wrapper);
  469. // }
  470. // List<AssoRecordsFeature> finalAsso = assoRecordsFeatures;
  471. // //从对比记录-特征关联信息里剔出对比记录Id
  472. // List<Integer> recordIds = assoRecordsFeatures.stream().map(AssoRecordsFeature::getRecordsId).collect(Collectors.toList());
  473. // //从对比记录-特征关联信息里剔出特征Id
  474. // List<Integer> sFeatureIds = assoRecordsFeatures.stream().map(AssoRecordsFeature::getFeatureId).collect(Collectors.toList());
  475. // sFeatureIds.addAll(knowedIds);
  476. // //根据特征ID查询出报告所有方案的特征
  477. // List<Features> sFeatures = new ArrayList<>();
  478. // LambdaQueryWrapper<Features> sFeaturesWrapper = new LambdaQueryWrapper<>();
  479. // sFeaturesWrapper.eq(Features::getId, sFeatureIds);
  480. // if (sFeatures != null && sFeatures.size() != 0) {
  481. // sFeatures = featureService.list(sFeaturesWrapper);
  482. // }
  483. // //根据对比记录ID查询出报告所有方案的对比记录
  484. // List<CompareRecords> compareRecords = new ArrayList<>();
  485. // if (recordIds != null && recordIds.size() != 0) {
  486. // LambdaQueryWrapper<CompareRecords> queryPatentByIDs = new LambdaQueryWrapper<>();
  487. // queryPatentByIDs.in(CompareRecords::getId, recordIds);
  488. // compareRecords = compareRecordsService.list(queryPatentByIDs);
  489. // }
  490. // //根据对比记录ID获得专利号
  491. // List<String> PatentNos = compareRecords.stream().map(CompareRecords::getPatentNo).collect(Collectors.toList());
  492. // PatentVO patentVO = new PatentVO();
  493. // patentVO.setPatentNos(PatentNos);
  494. // //根据专利号查询专利的排序
  495. // LambdaQueryWrapper<CompareFiles> comWrapper = new LambdaQueryWrapper<>();
  496. // comWrapper
  497. // .eq(CompareFiles::getReportId, report.getId())
  498. // .last("ORDER BY IF(isnull(SYS_ORDER),1,0), SYS_ORDER ASC");
  499. // ;
  500. // List<CompareFiles> compareFiles = compareFilesService.list(comWrapper);
  501. // //专利号别名的map
  502. // Map<String, Object> OtherName = new HashMap<>();
  503. // int flag = 1;
  504. // for (CompareFiles item : compareFiles) {
  505. // Integer order = item.getSysOrder() == null ? flag : item.getSysOrder();
  506. // OtherName.put(item.getPatentNo(), order);
  507. // flag++;
  508. // }
  509. //
  510. // //根据专利号查询专利详细信息
  511. // String resBody = outInterfaceService.getPatentDTOListForRMS(patentVO);
  512. // JSONObject jsonObject = JSONObject.parseObject(resBody);
  513. // List<JSONObject> patentDTOS = JSON.parseArray(jsonObject.get("data").toString(), JSONObject.class);
  514. // //存放专利信息的map集合
  515. // List<Map<String, Object>> patentListMaps = new ArrayList<>();
  516. // //填充专利数据到patentListMap
  517. // for (int i = 0; i < patentDTOS.size(); i++) {
  518. // JSONObject item = patentDTOS.get(i);
  519. // Map<String, Object> patentListMap = new HashMap<>();
  520. // List<JSONObject> applicantJSONs = JSON.parseArray(item.get("applicant").toString(), JSONObject.class);
  521. // ;
  522. // StringBuilder applicants = new StringBuilder();
  523. // applicantJSONs.forEach(tem -> {
  524. // applicants.append(tem.get("name") + "\r");
  525. // });
  526. // //填充相关揭露(对比记录文字和特征组合)
  527. // StringBuffer disclosures = new StringBuffer("");
  528. // //根据专利号获得对比记录
  529. // List<CompareRecords> pantentRecords = compareRecords.stream().filter(tem -> tem.getPatentNo().equals(item.get("publicNo"))).collect(Collectors.toList());
  530. // //遍历对比记录根据对比记录获得对比记录-特征关联信息并获得特征ID
  531. // for (CompareRecords tem : pantentRecords) {
  532. // //填充对比记录文字
  533. // disclosures.append(tem.getContent());
  534. // disclosures.append("\r");
  535. // disclosures.append("(");
  536. // disclosures.append(tem.getFields());
  537. // disclosures.append("[" + (tem.getPosition()) + "]");
  538. // disclosures.append(")");
  539. // List<Integer> featuresIds = assoRecordsFeatures.stream().filter(te -> te.getRecordsId().equals(tem.getId())).map(AssoRecordsFeature::getFeatureId).collect(Collectors.toList());
  540. // //根据特征Id获得特征内容
  541. // List<String> feaListContent = sFeatures.stream().filter(te -> featuresIds.contains(te.getId())).map(Features::getContent).collect(Collectors.toList());
  542. // feaListContent.forEach(te -> disclosures.append("(" + te + ")"));
  543. // disclosures.append("\n");
  544. // }
  545. // int order = Integer.parseInt(OtherName.get(item.get("patentNo")).toString());
  546. //
  547. // patentListMap.put("name", item.get("name"));
  548. // patentListMap.put("fileName", "D" + order);
  549. // patentListMap.put("publicDate", item.get("publicDate"));
  550. // patentListMap.put("publicNo", item.get("publicNo"));
  551. // patentListMap.put("SSIM", "");
  552. // patentListMap.put("applicant", applicants);
  553. // patentListMap.put("patentNo", item.get("patentNo"));
  554. // patentListMap.put("abstractStr", item.get("abstractStr"));
  555. // patentListMap.put("compareFileName", "对比文件" + (order));
  556. // patentListMap.put("applicationDate", item.get("applicationDate"));
  557. // patentListMap.put("abstractPath", pasFile + item.get("abstractPath"));
  558. // patentListMap.put("disclosures", disclosures);
  559. // patentListMap.put("order", order);
  560. // patentListMaps.add(patentListMap);
  561. //
  562. // }
  563. // //存放对比方案信息的map集合
  564. // List<Map<String, Object>> scenariosMaps = new ArrayList<>(compareFiles.size());
  565. // //存放所有对比方案所有不重复的rightId
  566. // List<Integer> rightIds = new ArrayList<>();
  567. // for (int i = 0; i < compareScenarios.size(); i++) {
  568. // CompareScenarios item1 = compareScenarios.get(i);
  569. // //获得单个对比方案的
  570. // List<AssoScenarIOS> partScenariosRecords = scenariosRecords.stream().filter(item -> item.getScenariosID().equals(item1.getId())).collect(Collectors.toList());
  571. // List<Integer> featureRecordsIds = partScenariosRecords.stream().map(AssoScenarIOS::getFeatureRecordID).collect(Collectors.toList());
  572. // List<AssoRecordsFeature> assoRecordsFeatures1 = assoRecordsFeatures.stream().filter(item -> featureRecordsIds.contains(item.getId())).collect(Collectors.toList());
  573. // List<Integer> partRecordIds = assoRecordsFeatures1.stream().map(AssoRecordsFeature::getRecordsId).collect(Collectors.toList());
  574. // List<Integer> partFetIds = assoRecordsFeatures1.stream().map(AssoRecordsFeature::getFeatureId).collect(Collectors.toList());
  575. // //获得公识特征的ID
  576. // List<Integer> comFetIds = partScenariosRecords.stream().map(AssoScenarIOS::getFeaturesID).collect(Collectors.toList());
  577. // partFetIds.addAll(comFetIds);
  578. // //获得单个对比方案的权要的所有特征
  579. // List<Features> partFeatures = allFeatures.stream().filter(item -> partFetIds.contains(item.getId())).collect(Collectors.toList());
  580. // List<CompareRecords> records = compareRecords.stream().filter(item -> partRecordIds.contains(item.getId())).collect(Collectors.toList());
  581. // //获得单条权要所有的特征
  582. // List<Features> allRightFeatures = allFeatures.stream().filter(item -> item.getRightId().equals(item1.getRightId())).collect(Collectors.toList());
  583. // //存放单条对比结果的map
  584. // Map<String, Object> temMap = new HashMap<>();
  585. // String a = partFeatures.get(0).getRightName().replace("\r", "");
  586. // if (partFeatures.size() != 0 && partFeatures.get(0).getRightType().equals(1)) {
  587. // temMap.put("rightName", "独立" + a);
  588. // } else {
  589. // temMap.put("rightName", "附属" + a);
  590. // }
  591. // temMap.put("rightId", item1.getRightId());
  592. // if (report.getType() == 1) {
  593. // String rightContent = patentRights.stream().filter(t -> t.getSort().equals(item1.getRightId())).map(PatentRight::getContent).findFirst().orElse("");
  594. // temMap.put("rightContent", rightContent);
  595. // }
  596. // temMap.put("remark", item1.getContrastResult());
  597. // // 从关联数据里获得特征id
  598. // if (!rightIds.contains(item1.getRightId())) {
  599. // rightIds.add(item1.getRightId());
  600. // }
  601. // //存放对比方案每一个特征记录
  602. // List<Map<String, Object>> maps = new ArrayList<>();
  603. // allRightFeatures.forEach(tem -> {
  604. //
  605. // List<AssoRecordsFeature> assoRecordsFeatures2 = assoRecordsFeatures1.stream().filter(item -> item.getFeatureId().equals(tem.getId())).collect(Collectors.toList());
  606. // if (comFetIds.contains(tem.getId())) {
  607. // Map<String, Object> map = new LinkedHashMap<>();
  608. // map.put("featureContent", tem.getContent());
  609. // map.put("compareResult", "公识");
  610. // map.put("compareContent", "");
  611. // maps.add(map);
  612. // } else if (assoRecordsFeatures2.size() != 0) {
  613. // Map<String, Object> map = new LinkedHashMap<>();
  614. // map.put("featureContent", tem.getContent());
  615. // List<Map<String, Object>> temMap1 = new ArrayList<>();
  616. // AssoRecordsFeature assoRecordsFeature = assoRecordsFeatures2.get(0);
  617. // CompareRecords record = records.stream().filter(item -> item.getId().equals(assoRecordsFeature.getRecordsId())).findFirst().orElse(new CompareRecords());
  618. // String compareContent = "";
  619. // //获取对比内容
  620. // String content = record.getContent() != null ? record.getContent() : "";
  621. // //获得对比专利号
  622. // String patentNo = record.getPatentNo() != null ? record.getPatentNo() : "";
  623. // if (OtherName.containsKey(patentNo)) {
  624. // patentNo = "D" + OtherName.get(patentNo).toString() + ":";
  625. // } else if (!patentNo.equals("")) {
  626. // patentNo += ":";
  627. // }
  628. // //获得解析过程
  629. // String paresingProcess = record.getParesingProcess() != null ? "(" + record.getParesingProcess() + ")" : "";
  630. // compareContent = patentNo + content + paresingProcess;
  631. // //获取对比专利号
  632. // if (maps.size() > 0) {
  633. // Map<String, Object> lastMap = maps.get(maps.size() - 1);
  634. // if (lastMap.get("compareContent").toString().equals(compareContent)) {
  635. // lastMap.put("featureContent", lastMap.get("featureContent") + tem.getContent());
  636. // } else {
  637. // map.put("compareResult", assoRecordsFeature.getComResult() != null ? assoRecordsFeature.getComResult() : "不公开");
  638. // map.put("compareContent", compareContent);
  639. // map.put("figure", fileUtils.getSystemPath() + record.getFilePath());
  640. // if (record.getFields() == null && record.getPosition() == null) {
  641. // map.put("position", "");
  642. // } else {
  643. // map.put("position", "\r" + "(" + record.getFields() + "[" + record.getPosition() + "]" + ")");
  644. // }
  645. // maps.add(map);
  646. // }
  647. // } else {
  648. // map.put("compareResult", assoRecordsFeature.getComResult() != null ? assoRecordsFeature.getComResult() : "不公开");
  649. // map.put("compareContent", compareContent);
  650. // map.put("figure", fileUtils.getSystemPath() + record.getFilePath());
  651. // if (record.getFields() == null && record.getPosition() == null) {
  652. // map.put("position", "");
  653. // } else {
  654. // map.put("position", "\r" + "(" + record.getFields() + "[" + record.getPosition() + "]" + ")");
  655. // }
  656. // maps.add(map);
  657. // }
  658. //
  659. // } else {
  660. // Map<String, Object> map = new LinkedHashMap<>();
  661. // map.put("featureContent", tem.getContent());
  662. // map.put("compareResult", "未公开");
  663. // map.put("compareContent", "");
  664. // maps.add(map);
  665. // }
  666. //
  667. // });
  668. // //方案内容
  669. // temMap.put("fileDetails", maps);
  670. // //新颖性模块
  671. // //获得本方案所有的专利号
  672. // List<String> patentNOs = new ArrayList<>();
  673. // records.forEach(item -> {
  674. // if (!patentNOs.contains(item.getPatentNo())) {
  675. // patentNOs.add(item.getPatentNo());
  676. // }
  677. // });
  678. // //比较所有专利号和权要所有权要的大小,如果相等则将该专利加入到新颖性列表中
  679. // List<String> noveltyFiles = new ArrayList<>();
  680. // patentNOs.forEach(
  681. // item -> {
  682. // List<Integer> temRecordIds = records.stream().filter(tm -> tm.getPatentNo().equals(item)).map(CompareRecords::getId).collect(Collectors.toList());
  683. // List<Integer> temFIds = finalAsso.stream().filter(tm -> temRecordIds.contains(tm.getRecordsId())).map(AssoRecordsFeature::getFeatureId).collect(Collectors.toList());
  684. // String tmName = item;
  685. // if (OtherName.containsKey(item)) {
  686. // tmName = "D" + OtherName.get(item).toString();
  687. // }
  688. // if (temFIds.size() == allRightFeatures.size()) {
  689. // noveltyFiles.add(tmName);
  690. // }
  691. // }
  692. // );
  693. // //创造性列表
  694. // List<String> creativeFiles = new ArrayList<>();
  695. // //当前方案所有的特征Id
  696. // records.forEach(
  697. // item -> {
  698. // String tmName = item.getPatentNo();
  699. // if (OtherName.containsKey(tmName)) {
  700. // tmName = "D" + OtherName.get(tmName).toString();
  701. // }
  702. // if (!creativeFiles.contains(tmName)) {
  703. // creativeFiles.add(tmName);
  704. // }
  705. // }
  706. // );
  707. // List<AssoScenarIOS> andRecords = partScenariosRecords.stream().filter(tm -> tm.getScenariosID().equals(item1.getId()) && tm.getFeaturesID() != 0).collect(Collectors.toList());
  708. // if (andRecords.size() != 0) {
  709. // creativeFiles.add("C");
  710. // }
  711. // String creative = creativeFiles.size() == 0 ? "" : StringUtils.join(creativeFiles, "+");
  712. // String novelty = noveltyFiles.size() == 0 ? "" : StringUtils.join(noveltyFiles, "-");
  713. // //新颖性
  714. // temMap.put("novelty", novelty);
  715. // //创造性
  716. // temMap.put("creative", creative);
  717. // scenariosMaps.add(temMap);
  718. // }
  719. // List<Map<String, Object>> allRightScenarios = new ArrayList<>();
  720. // List<Map<String, Object>> resultMaps = new ArrayList<>();
  721. // // 存放创造性和新颖性的权要
  722. //
  723. // rightIds.forEach(tem -> {
  724. // Map<String, Object> map = new HashMap<>();
  725. // Map<String, Object> resultMap = new HashMap<>();
  726. // List<Map<String, Object>> rightScenarios = new ArrayList<>();
  727. // //存放新颖性信息
  728. // List<String> noveList = new ArrayList<>();
  729. // List<String> creaList = new ArrayList<>();
  730. // //存放创造性信息
  731. // for (int t = 0; t < scenariosMaps.size(); t++) {
  732. // Map<String, Object> item = scenariosMaps.get(t);
  733. // if (item.get("rightId").equals(tem)) {
  734. // item.put("scenariosName", "对比组合" + (t + 1));
  735. // rightScenarios.add(item);
  736. // if (item.get("novelty").toString() != "") {
  737. // if (!noveList.contains(item.get("novelty").toString())) {
  738. // noveList.add(item.get("novelty").toString());
  739. // }
  740. // }
  741. // if (item.get("creative").toString() != "") {
  742. // if (!creaList.contains(item.get("creative").toString())) {
  743. // creaList.add(item.get("creative").toString());
  744. // }
  745. // }
  746. // }
  747. // }
  748. // map.put("rightScenrios", rightScenarios);
  749. // map.put("rightName", rightScenarios.get(0).get("rightName"));
  750. // String creative = creaList.size() == 0 ? "" : StringUtils.join(creaList, "、");
  751. // String novelty = noveList.size() == 0 ? "" : StringUtils.join(noveList, "-");
  752. // resultMap.put("rightName", rightScenarios.get(0).get("rightName"));
  753. // resultMap.put("rightNovelty", novelty);
  754. // resultMap.put("rightCreative", creative);
  755. // allRightScenarios.add(map);
  756. // resultMaps.add(resultMap);
  757. // });
  758. // //1.系统数据
  759. // //存放单条对比结果的map
  760. // Map<String, Object> map = new HashMap<>();
  761. // String date = DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
  762. // String[] ds = date.split("-");
  763. // map.put("sys", new SystemMO(ds[0], ds[1], ds[2], "", "reportName"));
  764. // if (patentListMaps.size() > 1) {
  765. // patentListMaps = this.sortMap(patentListMaps);
  766. // }
  767. // map.put("patentList", patentListMaps);
  768. // map.put("combinations", allRightScenarios);
  769. // map.put("allResults", resultMaps);
  770. // map.put("signPatent", signPatent);
  771. // map.put("pantentNo", report.getSignPatentNo());
  772. // map.put("rights", signPatent.get("rights"));
  773. // // 为表格的显示绑定行循环
  774. // LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
  775. // HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
  776. // // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
  777. // Configure configure = Configure.builder()
  778. // .bind("patentList", policy)
  779. // .bind("fileDetails", policy)
  780. // .bind("allResults", policy)
  781. // .bind("signPatent.rights", policy)
  782. // .bind("remark", htmlRenderPolicy)
  783. // .build();
  784. // // 读取模板、数据并渲染
  785. // XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
  786. // return template;
  787. // }
  788. //
  789. // public Map<String, Object> signPantentMess(String patentNo) throws IOException {
  790. //
  791. // Patent patent = new Patent();
  792. // try {
  793. // List<Patent> patentList = esPatentService.getPatentsByNo(Arrays.asList(patentNo), true, null, null);
  794. // if(patentList.size()>0){
  795. // patent=patentList.get(0);
  796. // }
  797. // } catch (Exception e) {
  798. // throw new IOException();
  799. // }
  800. //
  801. // //装载单个专利的信息
  802. // Map<String, Object> patentMap = new HashMap<>();
  803. // List<JSONObject> applicantJSONs = JSON.parseArray(patent.get("applicant").toString(), JSONObject.class);
  804. // StringBuilder applicants = new StringBuilder();
  805. // StringBuilder rightPerson = new StringBuilder();
  806. // applicantJSONs.forEach(tem -> {
  807. // if (Integer.parseInt(tem.get("dataType").toString()) == 1) {
  808. // applicants.append(tem.get("name") + "\r");
  809. // } else {
  810. // rightPerson.append(tem.get("name") + "\r");
  811. // }
  812. // });
  813. // //申请日
  814. // patentMap.put("applicationDate", patent.getAppDate());
  815. //
  816. // //公开日
  817. // patentMap.put("publicDate", patent.getPublicDate());
  818. // //公开号
  819. // patentMap.put("publicNo", patent.getPublicNo());
  820. // //专利号
  821. // patentMap.put("patentNo", patent.getPatentNo());
  822. // //专利权人
  823. // patentMap.put("rightPerson", rightPerson);
  824. // //图示
  825. // patentMap.put("abstractPath", pasFile + patent.get("abstractPath"));
  826. // patentMap.put("name", patent.getTitle());
  827. // //查询专利权要
  828. // String resBody2 = outInterfaceService.getPatentRightFromPAS(patentNo);
  829. // JSONObject jsonObject2 = JSONObject.parseObject(resBody2);
  830. // //解析jason获得标的专利的权要
  831. // List<PatentRight> patentRightsOrgin = JSON.parseArray(jsonObject2.getString("data"), PatentRight.class);
  832. // List<Map<String, Object>> rights = new ArrayList<>();
  833. // //给权要进行格式更改
  834. // List<PatentRight> patentRights = featureService.FormatPatentRights(patentRightsOrgin, patentNo);
  835. // patentRights.forEach(item -> {
  836. // Map<String, Object> temMap = new HashMap<>();
  837. // temMap.put("rightName", "权" + (item.getSort() + 1));
  838. // temMap.put("content", item.getContent());
  839. // temMap.put("rightNameLong", "权利要求" + (item.getSort() + 1));
  840. // temMap.put("parentSort", item.getParentSort());
  841. // temMap.put("sort", item.getSort());
  842. // rights.add(temMap);
  843. // });
  844. // patentMap.put("rights", rights);
  845. // return patentMap;
  846. // }
  847. }