123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- package cn.cslg.pas.service;
- import cn.cslg.pas.common.dto.PatentDetailDTO;
- import cn.cslg.pas.common.dto.es.EsCustomFieldDTO;
- import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
- 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.common.utils.FormatUtil;
- import cn.cslg.pas.common.utils.PatentRightUtils;
- import cn.cslg.pas.common.vo.AvoidFeaturesVO;
- import cn.cslg.pas.common.vo.FieldValueVO;
- import cn.cslg.pas.common.vo.PatentRightParams;
- import cn.cslg.pas.common.vo.RePatentClaim;
- import cn.cslg.pas.common.vo.business.AllCustomFieldVO;
- import cn.cslg.pas.common.vo.business.PatentNoVO;
- import cn.cslg.pas.domain.business.*;
- import cn.cslg.pas.domain.es.Text;
- import cn.cslg.pas.exception.XiaoShiException;
- import cn.cslg.pas.mapper.AvoidDesignMapper;
- import cn.cslg.pas.service.business.CustomFieldService;
- import cn.cslg.pas.service.business.ReportProjectService;
- import cn.cslg.pas.service.business.TemplateConfigService;
- import cn.cslg.pas.service.business.TempleService;
- import cn.cslg.pas.service.business.es.EsPatentService;
- import cn.cslg.pas.service.business.es.EsService;
- 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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.deepoove.poi.XWPFTemplate;
- import com.deepoove.poi.config.Configure;
- import com.deepoove.poi.data.PictureRenderData;
- import com.deepoove.poi.data.PictureType;
- import com.deepoove.poi.data.Pictures;
- import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.poi.ss.usermodel.PictureData;
- import org.ddr.poi.html.HtmlRenderPolicy;
- import org.joda.time.format.FormatUtils;
- 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.*;
- import java.util.stream.Collectors;
- @Slf4j
- @Service
- public class ReportExportService {
- @Autowired
- private TempleService templeService;
- @Autowired
- private FileUtils fileUtils;
- @Autowired
- private ReportProjectService reportProjectService;
- @Autowired
- private FileManagerService fileManagerService;
- @Autowired
- private EsPatentService esPatentService;
- @Autowired
- private AvoidDesignMapper avoidDesignMapper;
- @Autowired
- private TemplateConfigService templateConfigService;
- @Autowired
- private CustomFieldService customFieldService;
- @Autowired
- private EsService esService;
- /**
- * @param projectId
- * @param templeId
- * @return
- * @throws IOException
- * @function: 导出报告
- */
- public String exportReport(Integer projectId, Integer templeId) throws IOException {
- //根据模板ID获得模板
- ReportTemple reportTemplate = templeService.getById(templeId);
- //获得模板路径
- String templateFilePath = fileUtils.getPath(reportTemplate.getTemplatePath());
- //读取模板后保存生成word的地址
- String fileName = IdUtil.simpleUUID() + ".docx";
- String directoryName = fileUtils.createDirectory();
- String outPath = fileUtils.getSavePath(directoryName) + fileName;
- //根据ProjectId 获得报告
- LambdaQueryWrapper<ReportProject> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ReportProject::getProjectId, projectId);
- ReportProject report = reportProjectService.getOne(queryWrapper, false);
- if (report == null) {
- throw new XiaoShiException("报告不存在");
- }
- XWPFTemplate template = null;
- template = this.avoidDesignTemplate(projectId);
- 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 projectId) throws IOException {
- String filePath = fileUtils.getPath("/11.docx");
- log.info("开始处理导出规避设计报告,参数为:{}, {}", projectId, filePath);
- LambdaQueryWrapper<ReportProject> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ReportProject::getProjectId, projectId);
- ReportProject report = reportProjectService.getOne(queryWrapper, false);
- String signPatentNo = report.getSignPatentNo();
- //装载标的专利信息
- Map<String, Object> signPatent = this.signPatentMess(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("patentNo", 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 = avoidDesignMapper.selectAvoidDesign(projectId);
- // 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();
- XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
- return template;
- }
- public Map<String, Object> signPatentMess(String patentNo) throws IOException {
- // PatentNoVO patentVO = new PatentNoVO();
- // patentVO.setPatentNo(patentNo);
- // //根据专利号查询专利详细信息
- // PatentDetailDTO patentDetailDTO = esPatentService.selectPatentDetail(patentVO);
- // //装载单个专利的信息
- Map<String, Object> patentMap = new HashMap<>();
- // StringBuilder applicants = new StringBuilder();
- // StringBuilder rightPerson = new StringBuilder();
- //
- // //申请日
- // patentMap.put("applicationDate", patentDetailDTO.getAppDate());
- //
- // //公开日
- // patentMap.put("publicDate", patentDetailDTO.getPublicDate());
- // //公开号
- // patentMap.put("publicNo", patentDetailDTO.getPublicNo());
- // //专利号
- // patentMap.put("patentNo", patentDetailDTO.getPatentNo());
- // //专利权人
- // patentMap.put("rightPerson", rightPerson);
- // //图示
- // String guid = FormatUtil.getPictureFormat(patentDetailDTO.getAppNo());
- // PictureRenderData pictureData = this.guidToStream(guid);
- // if (pictureData != null) {
- // patentMap.put("abstractPath", pictureData);
- // }
- // //获得标题
- // if (patentDetailDTO.getTitle() != null && patentDetailDTO.getTitle().size() > 0) {
- // Text title = patentDetailDTO.getTitle().stream()
- // .filter(item -> item.getIfOrigin().equals(true)).findFirst().orElse(null);
- // if (title != null) {
- // patentMap.put("name", title.getTextContent());
- // }
- // }
- //
- // //获得权要
- // List<Map<String, Object>> rights= this.getClaimMaps(patentDetailDTO.getClaim(),patentDetailDTO.getPatentNo());
- //
- // patentMap.put("rights", rights);
- return patentMap;
- }
- private PictureRenderData guidToStream(String guid) {
- PictureRenderData pictureRenderData = null;
- byte[] bytes = null;
- if (bytes != null) {
- try {
- bytes = fileManagerService.downloadSystemFileFromFMS(guid);
- } catch (Exception e) {
- }
- }
- FileInputStream fileInputStream = FileUtils.byteToFile(bytes);
- pictureRenderData = Pictures.ofStream(fileInputStream, PictureType.PNG)
- .create();
- return pictureRenderData;
- }
- private List<Map<String, Object>> getClaimMaps(List<Text> claims, String patentNo) {
- List<Map<String, Object>> rights = new ArrayList<>();
- if (claims == null || claims.size() == 0) {
- return rights;
- }
- Text claim = claims.stream().filter(item -> item.getIfOrigin().equals(true)).findFirst().orElse(null);
- if (claim == null) {
- return rights;
- }
- PatentRightParams params = new PatentRightParams();
- params.setContent(claim.getTextContent());
- params.setPatentNo(patentNo);
- List<RePatentClaim> patentRights = PatentRightUtils.formatPatentRight(params);
- //给权要进行格式更改
- patentRights.forEach(item -> {
- Map<String, Object> temMap = new HashMap<>();
- temMap.put("rightName", "权" + (item.getSort() + 1));
- temMap.put("content", item.getContent());
- temMap.put("rightNameLong", "权利要求" + (item.getSort() + 1));
- temMap.put("parentSort", item.getParentSort());
- temMap.put("sort", item.getSort());
- rights.add(temMap);
- });
- return rights;
- }
- /**
- * @param projectId
- * @param filePath
- * @return
- * @description 装载FTO模板
- */
- private XWPFTemplate FTOTemplate(Integer projectId, String filePath, Integer templateId) throws IOException {
- //根据报告ID获得自定义字段值的信息
- //获得模板的配置信息
- LambdaQueryWrapper<TemplateConfig> templateConfigWrapper = new LambdaQueryWrapper<TemplateConfig>();
- templateConfigWrapper.eq(TemplateConfig::getTemplateId, templateId);
- List<TemplateConfig> templateConfigs = templateConfigService.list(templateConfigWrapper);
- for (TemplateConfig templateConfig : templateConfigs) {
- String value = templateConfig.getValueName();
- //根据value 查询专利
- List<EsCustomFieldDTO> esCustomFieldDTOS = customFieldService.getCustomFieldByValueName(value,projectId);
- if(esCustomFieldDTOS.size()!=0){
- }
- }
- //
- List<Map<String, Object>> classifyMaps = new ArrayList<>();
- //装载信息
- // for (TemplateConfig templateConfig : templateConfigs) {
- // Map<String, Object> classifyMap = new HashMap<>();
- // classifyMap.put("classify", map.get("CName"));
- // //根据自定义字段ID和值Id查询专利号
- // List<String> patentNos = reportFieldPatentLinkService.getPatentNos(Integer.parseInt(map.get("FId").toString()), Integer.parseInt(map.get("CId").toString()));
- // PatentVO patentVO = new PatentVO();
- // patentVO.setPatentNos(patentNos);
- // //根据专利号查询专利详细信息
- // String resBody = outInterfaceService.getPatentDTOListForRMS(patentVO);
- // JSONObject jsonObject = JSONObject.parseObject(resBody);
- // List<JSONObject> patentDTOS = JSON.parseArray(jsonObject.get("data").toString(), JSONObject.class);
- // //根据专利号和报告Id获得对比记录
- // //存放公告专利
- // List<Map<String, Object>> announcePatents = new ArrayList<>();
- // //存放公开专利
- // List<Map<String, Object>> publicPatents = new ArrayList<>();
- // //存放失效专利信息
- // List<Map<String, Object>> lapsePatents = new ArrayList<>();
- // for (JSONObject patent : patentDTOS) {
- // 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");
- // }
- //
- // );
- // //装载单个专利的信息
- // Map<String, Object> patentMap = new HashMap<>();
- // //同族专利
- // 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("priorityDate", patent.get("priorityDate"));
- // //图示
- // patentMap.put("abstractPath", "http://139.224.24.90:8081" + patent.get("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"));
- // Integer status = Integer.parseInt(patent.get("simpleStatusInt").toString());
- // if (status == 1 || status == 5 || status == 6) {
- // announcePatents.add(patentMap);
- // } else if (status == 2) {
- // lapsePatents.add(patentMap);
- // } else if (status == 3) {
- // publicPatents.add(patentMap);
- // }
- // classifyMap.put("publicPatents", publicPatents);
- // classifyMap.put("lapsePatents", lapsePatents);
- // classifyMap.put("announcePatents", announcePatents);
- // }
- // classifyMaps.add(classifyMap);
- // }
- // 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("classifys", classifyMaps);
- // // 为表格的显示绑定行循环
- // 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;
- return null;
- }
- }
|