From ff8397f5be1213dbd299cdc37a25261741d8f878 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Tue, 23 Jan 2024 09:32:19 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E9=99=84=E7=A5=A8=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ticket/twoTicket/constant/TicketConstant.java | 2 +- .../service/impl/FirstWorkTicketServiceImpl.java | 49 ++++++++++++++-------- .../com/hnac/hzims/ticket/utils/MergeDocUtils.java | 11 ++--- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/constant/TicketConstant.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/constant/TicketConstant.java index 3985daa..c374b59 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/constant/TicketConstant.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/constant/TicketConstant.java @@ -12,7 +12,7 @@ public class TicketConstant { /** * window操作系统工作票访问路径 */ - public static final String TICKET_WINDOW_PATH = "hzims-service/ticket/src/main/resources/template"; + public static final String TICKET_WINDOW_PATH = "E:/project/HZIMS/hzims-service/ticket/src/main/resources/template/"; /** * Liunx操作系统工作票访问路径 diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java index d58dc5e..a37d029 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java @@ -2,6 +2,7 @@ package com.hnac.hzims.ticket.twoTicket.service.impl; import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.afterturn.easypoi.word.WordExportUtil; +import cn.hutool.core.io.resource.FileResource; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -74,6 +75,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import static org.aspectj.weaver.tools.cache.SimpleCacheFactory.path; +import static org.springframework.transaction.support.TransactionSynchronizationManager.getResource; /** * @author hx @@ -292,15 +294,18 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpl documents; + List templateFiles = this.getFiles(workTicketInfoEntity); try { - documents = this.getDocuments(workTicketInfoEntity, params); + MergeDocUtils.mergeDoc(templateFiles,new File(wordPath)); } catch (Exception e) { + e.printStackTrace(); throw new RuntimeException(e); } try { - this.exportTicketWord(documents,wordPath); - } catch (IOException e) { + XWPFDocument xwpfDocument = WordExportUtil.exportWord07(wordPath, params); + xwpfDocument.write(new FileOutputStream(wordPath)); + } catch (Exception e) { + e.printStackTrace(); throw new RuntimeException(e); } String pdfPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".pdf"; @@ -396,37 +401,45 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpl getDocuments(WorkTicketInfoEntity workTicketInfo,Map params) { - List result = Lists.newArrayList(); - XWPFDocument document = this.fillDocument("template/" + WorkTicketConstants.TicketSignageEnum.getTempFileNameByType(workTicketInfo.getType()), params); - result.add(document); + private List getFiles(WorkTicketInfoEntity workTicketInfo) { + List result = Lists.newArrayList(); + String prefix; + //Windows操作系统 + if (TicketConstant.OS_NAME.toLowerCase().startsWith("windows")) { + prefix = TicketConstant.TICKET_WINDOW_PATH; + } else { + prefix = TicketConstant.TICKET_LIUNX_PATH; + } + String templatePath = prefix + "/" + WorkTicketConstants.TicketSignageEnum.getTempFileNameByType(workTicketInfo.getType()); + result.add(new File(templatePath)); //安全隔离措施附页 (true,展示附件,false,不展示附件) if (workTicketInfo.getIsSafety()) { - XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.SECURE_PAGE, params); - //result.add(xwpfDocument); + result.add(new File(prefix + "/" + TicketConstant.SAFETY_PAGE)); } //危险点分析与预控措施票 (true,展示附件,false,不展示附件) if (workTicketInfo.getIsHazard()) { - XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.SAFETY_PAGE, params); - //result.add(xwpfDocument); + result.add(new File(prefix + "/" + TicketConstant.SAFETY_PAGE)); } //动火工作票 (true,展示附件,false,不展示附件) if (workTicketInfo.getIsRailway()) { - XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.FLIGHT_PAGE, params); - //result.add(xwpfDocument); + result.add(new File(prefix + "/" + TicketConstant.FLIGHT_PAGE)); } //有限空间监测记录单(true,展示附件,false,不展示附件) if (workTicketInfo.getIsLimited()) { - XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.SPACE_PAGE, params); - //result.add(xwpfDocument); + result.add(new File(prefix + "/" + TicketConstant.SPACE_PAGE)); } //每日开工和收工时间附页 if (workTicketInfo.getIsStart()) { - XWPFDocument xwpfDocument = this.fillDocument("template/" + TicketConstant.START_PAGE, params); - //result.add(xwpfDocument); + result.add(new File(prefix + "/" + TicketConstant.START_PAGE)); } return result; } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/MergeDocUtils.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/MergeDocUtils.java index 932e324..55b2c9a 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/MergeDocUtils.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/MergeDocUtils.java @@ -7,6 +7,7 @@ package com.hnac.hzims.ticket.utils; * @Date 2023/5/23 16:42 */ import cn.afterturn.easypoi.word.entity.MyXWPFDocument; +import com.google.common.collect.Lists; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.xwpf.usermodel.BreakType; import org.apache.poi.xwpf.usermodel.Document; @@ -132,11 +133,11 @@ public class MergeDocUtils { Matcher m = pattern.matcher(xml); // 匹配的有多个 List list = new ArrayList(); - while (m.find()) { - int i = 1; - list.add(m.group(i)); - i++; - } +// while (m.find()) { +// int i = 1; +// list.add(m.group(i)); +// i++; +// } if (list.size() > 0) { // 输出内容自己定义 context = String.valueOf(list.size());