Browse Source

# 附票合并

zhongwei
haungxing 10 months ago
parent
commit
ff8397f5be
  1. 2
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/constant/TicketConstant.java
  2. 49
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/FirstWorkTicketServiceImpl.java
  3. 11
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/MergeDocUtils.java

2
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操作系统工作票访问路径

49
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<WorkTicketInfoMa
throw new ServiceException("未找到模板文件,预览失败!");
});
String wordPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".docx";
List<XWPFDocument> documents;
List<File> 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<WorkTicketInfoMa
params.putAll(ObjectUtils.LocalDateConvertMap(finish.getLicensorEndTime(),"e","_"));
}
}
//第一种工作票
params.put("one", "6".equals(workTicketInfoEntity.getType()) ? "☑" : "□");
//第二种工作票
params.put("two", "7".equals(workTicketInfoEntity.getType()) ? "☑" : "□");
//水力机器工作票
params.put("three", "8".equals(workTicketInfoEntity.getType()) ? "☑" : "□");
return params;
}
private List<XWPFDocument> getDocuments(WorkTicketInfoEntity workTicketInfo,Map<String,Object> params) {
List<XWPFDocument> result = Lists.newArrayList();
XWPFDocument document = this.fillDocument("template/" + WorkTicketConstants.TicketSignageEnum.getTempFileNameByType(workTicketInfo.getType()), params);
result.add(document);
private List<File> getFiles(WorkTicketInfoEntity workTicketInfo) {
List<File> 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;
}

11
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<String> list = new ArrayList<String>();
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());

Loading…
Cancel
Save