|
@@ -0,0 +1,229 @@
|
|
|
+package cn.cslg.pas.service;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.model.SystemMO;
|
|
|
+import cn.cslg.pas.common.utils.DateUtils;
|
|
|
+import cn.cslg.pas.common.utils.FileUtils;
|
|
|
+import cn.cslg.pas.domain.business.Project;
|
|
|
+import cn.cslg.pas.domain.business.ReportProject;
|
|
|
+import cn.cslg.pas.domain.business.ReportTemple;
|
|
|
+import cn.cslg.pas.service.business.ReportProjectService;
|
|
|
+import cn.cslg.pas.service.business.TempleService;
|
|
|
+import cn.cslg.pas.service.common.FileManagerService;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
+import com.deepoove.poi.config.Configure;
|
|
|
+import com.deepoove.poi.data.PictureType;
|
|
|
+import com.deepoove.poi.data.Pictures;
|
|
|
+import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.ddr.poi.html.HtmlRenderPolicy;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ReportExportService {
|
|
|
+ @Autowired
|
|
|
+ private TempleService templeService;
|
|
|
+ @Autowired
|
|
|
+ private FileUtils fileUtils;
|
|
|
+ @Autowired
|
|
|
+ private ReportProjectService reportProjectService;
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param reportId
|
|
|
+ * @param templeId
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ * @function: 导出报告
|
|
|
+ */
|
|
|
+ public String exportReport(Integer reportId, Integer templeId) throws IOException {
|
|
|
+ //根据模板ID获得模板
|
|
|
+// ReportTemple reportTemplate = templeService.getById(templeId);
|
|
|
+// //获得模板路径
|
|
|
+// String filePath = fileUtils.getPath(reportTemplate.getTemplatePath());
|
|
|
+ //读取模板后保存生成word的地址
|
|
|
+ String fileName = IdUtil.simpleUUID() + ".docx";
|
|
|
+ String directoryName = fileUtils.createDirectory();
|
|
|
+ String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
|
+
|
|
|
+ ReportProject report = reportProjectService.getById(reportId);
|
|
|
+ XWPFTemplate template = null;
|
|
|
+ template = this.avoidDesignTemplate(1);
|
|
|
+// if (report.getReportType() == 0 || report.getReportType() == 2) {
|
|
|
+// template = this.getstabilityTemplate(report, filePath);
|
|
|
+// } else if (report.getReportType() == 3) {
|
|
|
+// template = this.FTOtemplate(reportId, filePath, templeId);
|
|
|
+// } else if (report.getReportType() == 4) {
|
|
|
+// template = this.Torttemplate(reportId, filePath, templeId);
|
|
|
+// } else if (report.getReportType() == 5) {
|
|
|
+// template = this.avoidDesignTemplate(reportId, filePath);
|
|
|
+// } else if (report.getReportType() == 1) {
|
|
|
+// template = this.getThirdTemplate(report, filePath);
|
|
|
+// }
|
|
|
+ // 读取模板、数据并渲染
|
|
|
+// 文件是否已存在,则删除
|
|
|
+ File file = new File(outPath);
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+// 生成word保存在指定目录
|
|
|
+ template.writeToFile(outPath);
|
|
|
+ template.close();
|
|
|
+ //导出成功后,导出报告记录入库
|
|
|
+// String url = fileUtils.getDirectory2(directoryName) + fileName;
|
|
|
+// PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+// ReportDocument reportDocument = new ReportDocument();
|
|
|
+// reportDocument.setReportId(reportId);
|
|
|
+// reportDocument.setFileName(fileName);
|
|
|
+// reportDocument.setFilePath(url);
|
|
|
+// reportDocument.setPersonId(personnelVO.getId());
|
|
|
+// reportDocument.setTemplateId(reportTemplate.getId());
|
|
|
+// reportDocument.setTemplateName(reportTemplate.getTemplateName());
|
|
|
+// reportDocument.setPersonName(personnelVO.getName());
|
|
|
+// reportDocument.insert();
|
|
|
+// return Response.success(url);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// private XWPFTemplate Torttemplate(Integer reportId, String filePath, Integer templateId) throws IOException {
|
|
|
+// //根据报告Id查询标的专利号
|
|
|
+// ReportProject report = reportProjectService.getById(reportId);
|
|
|
+// String patentNo = report.getSignPatentNo();
|
|
|
+//// PatentVO patentVO = new PatentVO();
|
|
|
+//// patentVO.setPatentNos(Arrays.asList(patentNo));
|
|
|
+//// //根据专利号查询专利详细信息
|
|
|
+//// String resBody = outInterfaceService.getPatentDTOListForRMS(patentVO);
|
|
|
+//// JSONObject jsonObject = JSONObject.parseObject(resBody);
|
|
|
+//// List<JSONObject> patentDTOS = JSON.parseArray(jsonObject.get("data").toString(), JSONObject.class);
|
|
|
+//// //装载单个专利的信息
|
|
|
+// Map<String, Object> patentMap = new HashMap<>();
|
|
|
+//// JSONObject patent = patentDTOS.get(0);
|
|
|
+//// List<JSONObject> applicantJSONs = JSON.parseArray(patent.get("applicant").toString(), JSONObject.class);
|
|
|
+//// StringBuilder applicants = new StringBuilder();
|
|
|
+//// StringBuilder rightPerson = new StringBuilder();
|
|
|
+//// applicantJSONs.forEach(tem -> {
|
|
|
+//// if (Integer.parseInt(tem.get("dataType").toString()) == 1) {
|
|
|
+//// applicants.append(tem.get("name") + "\r");
|
|
|
+//// } else {
|
|
|
+//// rightPerson.append(tem.get("name") + "\r");
|
|
|
+//// }
|
|
|
+//// });
|
|
|
+//// //装载同族信息
|
|
|
+//// JSONObject familys = JSONObject.parseObject(patent.get("family").toString());
|
|
|
+//// List<String> patSnaps = JSON.parseArray(familys.get("patSnap").toString(), String.class);
|
|
|
+//// List<String> simples = JSON.parseArray(familys.get("simple").toString(), String.class);
|
|
|
+//// List<String> inpadocs = JSON.parseArray(familys.get("inpadoc").toString(), String.class);
|
|
|
+//// patSnaps.addAll(simples);
|
|
|
+//// patSnaps.addAll(inpadocs);
|
|
|
+//// String familyStr = StringUtils.join(patSnaps, ",");
|
|
|
+//// //装载法律状态
|
|
|
+//// StringBuilder affair = new StringBuilder();
|
|
|
+//// List<JSONObject> affaires = JSON.parseArray(patent.get("affair").toString(), JSONObject.class);
|
|
|
+//// affaires.forEach(item -> {
|
|
|
+//// affair.append(item.get("status") + "\r");
|
|
|
+//// }
|
|
|
+//// );
|
|
|
+//// //同族专利
|
|
|
+//// patentMap.put("simpleFamilys", familyStr);
|
|
|
+//// //引用专利
|
|
|
+//// patentMap.put("quotePatents", patent.get("quote"));
|
|
|
+//// //申请日
|
|
|
+//// patentMap.put("applicationDate", patent.get("applicationDate"));
|
|
|
+//// //公开日
|
|
|
+//// patentMap.put("publicDate", patent.get("publicDate"));
|
|
|
+//// //专利号
|
|
|
+//// patentMap.put("publicNo", patent.get("publicNo"));
|
|
|
+//// patentMap.put("firstPublicDate", patent.get("firstPublicDate"));
|
|
|
+//// patentMap.put("applicant", applicants);
|
|
|
+//// patentMap.put("rightPerson", rightPerson);
|
|
|
+//// patentMap.put("affair", affair);
|
|
|
+//// patentMap.put("name", patent.get("name"));
|
|
|
+// //图示
|
|
|
+// patentMap.put("abstractPath", "");
|
|
|
+// //获得专利对比记录的信息
|
|
|
+//// Map<String, Object> temMap = compareMessageService.queryforTemplate(patent.get("patentNo").toString(), reportId);
|
|
|
+//// List<CompareMessageVO> compareMessageVOS = (List<CompareMessageVO>) temMap.get("compareMessageVOs");
|
|
|
+// //装载对比记录的信息
|
|
|
+//// patentMap.put("cM", compareMessageVOS);
|
|
|
+//// patentMap.put("rightNum", temMap.get("right"));
|
|
|
+//// patentMap.put("mainRightNum", temMap.get("mainRight"));
|
|
|
+// Map<String, Object> map = new HashMap<>();
|
|
|
+// String date = DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
|
|
|
+// String[] ds = date.split("-");
|
|
|
+// map.put("sys", new SystemMO(ds[0], ds[1], ds[2], "", "reportName"));
|
|
|
+// map.put("patentMap", patentMap);
|
|
|
+// map.put("", patentNo);
|
|
|
+// // 为表格的显示绑定行循环
|
|
|
+// LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
|
|
+// HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
|
|
|
+// // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
|
|
|
+// Configure configure = Configure.builder().bind("cM", policy).bind("targetDescription", htmlRenderPolicy).build();
|
|
|
+// XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
|
|
|
+// return template;
|
|
|
+// }
|
|
|
+
|
|
|
+ private XWPFTemplate avoidDesignTemplate(Integer reportId) throws IOException {
|
|
|
+ String filePath = fileUtils.getPath("/11.docx");
|
|
|
+
|
|
|
+// log.info("开始处理导出规避设计报告,参数为:{}, {}", reportId, filePath);
|
|
|
+// Report report = reportService.getById(reportId);
|
|
|
+// String signPatentNo = report.getSignPatentNo();
|
|
|
+//
|
|
|
+// //装载标的专利信息
|
|
|
+// Map<String, Object> signPatent = this.signPantentMess(report.getSignPatentNo());
|
|
|
+// System.out.println(signPatent.get(""));
|
|
|
+// Map<String, Object> map = new HashMap<>();
|
|
|
+// //装载标的专利信息
|
|
|
+// map.put("signPatent", signPatent);
|
|
|
+// map.put("rights", signPatent.get("rights"));
|
|
|
+// //装载公开/公告号
|
|
|
+// map.put("pantentNo", signPatentNo);
|
|
|
+//
|
|
|
+// //装载年月日
|
|
|
+// String date = DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
|
|
|
+// String[] dates = date.split("-");
|
|
|
+// SystemMO systemMO = new SystemMO()
|
|
|
+// .setYear(dates[0])
|
|
|
+// .setMonth(dates[1])
|
|
|
+// .setDay(dates[2]);
|
|
|
+// map.put("sys", systemMO);
|
|
|
+//
|
|
|
+// //装载特征、解释、回避设计方向、回避设计总体方向
|
|
|
+// List<AvoidFeaturesVO> features = avoidDesignLittleDirectionMapper.selectWholeByReportId(reportId);
|
|
|
+// String wholeDirection = avoidDesignWholeDirectionMapper.selectWholeDirectionByReportId(reportId);
|
|
|
+// map.put("features", features);
|
|
|
+// map.put("wholeDirection", wholeDirection);
|
|
|
+//
|
|
|
+ //绑定政策(绑定集合和元素循环遍历)
|
|
|
+ LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
|
|
+ //把指定元素内容识别传输成html格式
|
|
|
+ HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
|
|
|
+ Configure configure = Configure.builder()
|
|
|
+// .bind("signPatent.rights", policy)
|
|
|
+// .bind("features", policy)
|
|
|
+// .bind("explainText", htmlRenderPolicy)
|
|
|
+// .bind("littleDirection", htmlRenderPolicy)
|
|
|
+// .bind("wholeDirection", htmlRenderPolicy)
|
|
|
+ .build();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ byte[] bytes = fileManagerService.downloadSystemFileFromFMS("CN202022791374.3_p");
|
|
|
+
|
|
|
+
|
|
|
+ FileInputStream fileInputStream = FileUtils.byteToFile(bytes, "aa.png");
|
|
|
+ map.put("p", Pictures.ofStream(fileInputStream, PictureType.PNG)
|
|
|
+ .create());
|
|
|
+ map.put("a", "张");
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
|
|
|
+ return template;
|
|
|
+ }
|
|
|
+}
|