diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/annotation/DateTimeToMap.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/annotation/DateTimeToMap.java similarity index 100% rename from hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/annotation/DateTimeToMap.java rename to hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/annotation/DateTimeToMap.java diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/TicketConstants.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/TicketConstants.java index 320d3e0..71b73bb 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/TicketConstants.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/TicketConstants.java @@ -10,7 +10,7 @@ import java.util.Optional; * @author hx */ public interface TicketConstants { - String APP_NAME = "hzims-ticket"; + String APP_NAME = "hzims-ticket-hx"; String TICKET_DATE_PATTERN = "yyyy年MM月dd日 HH时mm分"; String TICKET_TYPE = "ticketType"; diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/WorkTicketConstants.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/WorkTicketConstants.java index 16e662d..737d4c6 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/WorkTicketConstants.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/WorkTicketConstants.java @@ -36,6 +36,11 @@ public interface WorkTicketConstants { private String type; @Getter private String convertAttributes; + + public static String getKeyByMeasureType(String type) { + Optional measureEnum = Arrays.stream(WorkTicketMeasureTypeEnum.class.getEnumConstants()).filter(e -> type.equals(e.getType())).findAny(); + return measureEnum.map(WorkTicketMeasureTypeEnum::getConvertAttributes).orElse(null); + } } @AllArgsConstructor @@ -87,21 +92,28 @@ public interface WorkTicketConstants { @AllArgsConstructor enum TicketSignageEnum { /**第一种工作票**/ - FIRST("6","D1"), + FIRST("6","D1","电气第一种工作票模版.docx"), /**第二种工作票**/ - SECOND("7","D2"), + SECOND("7","D2","电气第二种工作票模版.docx"), /**机械工作票**/ - MACHINE("8","JX"), + MACHINE("8","JX","水力机械工作票模版.docx"), ; @Getter private String ticketType; @Getter private String signage; + @Getter + private String fileName; public static String getTicketSignageByType(String ticketType) { Optional exist = Arrays.stream(TicketSignageEnum.class.getEnumConstants()) .filter(e -> ticketType.equals(e.getTicketType())).findFirst(); return exist.map(TicketSignageEnum::getSignage).orElse(null); } + public static String getTempFileNameByType(String ticketType) { + Optional exist = Arrays.stream(TicketSignageEnum.class.getEnumConstants()) + .filter(e -> ticketType.equals(e.getTicketType())).findFirst(); + return exist.map(TicketSignageEnum::getFileName).orElse(null); + } } } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java index e669474..e25a44d 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import com.hnac.hzims.ticket.annotation.DateTimeToMap; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import io.swagger.models.auth.In; @@ -174,6 +175,7 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "计划开始时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeToMap(prefix = "ps") private LocalDateTime planStartTime; /** @@ -182,6 +184,7 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "计划结束时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeToMap(prefix = "pe") private LocalDateTime planEndTime; @@ -204,6 +207,7 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "签发人签发时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeToMap(prefix = "s") private LocalDateTime signerDateTime; @@ -250,6 +254,7 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "许可时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeToMap(prefix = "l") private LocalDateTime licenseTime; @@ -456,6 +461,7 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { @ApiModelProperty("工作接收人时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeToMap(prefix = "r") private LocalDateTime jobReceiverTime; diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/StockAlertServiceImpl.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/StockAlertServiceImpl.java index bb7773d..ae165f1 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/StockAlertServiceImpl.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/StockAlertServiceImpl.java @@ -1,7 +1,5 @@ package com.hnac.hzims.spare.service.impl; -import com.hnac.hzims.message.fegin.IMessageClient; -import com.hnac.hzims.message.fegin.IMessagePushClient; import com.hnac.hzims.message.fegin.IPushMsgClient; import com.hnac.hzims.spare.service.IStockAlertService; import com.hnac.hzims.spare.service.IWtSpTotalService; diff --git a/hzims-service/message/pom.xml b/hzims-service/message/pom.xml index b3856f8..2dcf390 100644 --- a/hzims-service/message/pom.xml +++ b/hzims-service/message/pom.xml @@ -118,10 +118,6 @@ org.springframework.boot spring-boot-starter-mail - - com.hnac.hzims - hzims-operational-api - diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/impl/TicketMatterGroupServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/impl/TicketMatterGroupServiceImpl.java index 73dfbc8..8290179 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/impl/TicketMatterGroupServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/library/service/impl/TicketMatterGroupServiceImpl.java @@ -671,19 +671,19 @@ public class TicketMatterGroupServiceImpl extends BaseServiceImpl params = new HashMap(){{ - put("projectName","海南三亚一级站"); - put("code","GY-D2-2311--004"); - put("principalName","杨汪洋"); - put("classGroupName","白班"); - put("classGroupMembersName","吴先强,唐钰,彭晨洋,黄兴,肖璐"); - put("totalPerson","5"); - put("addressEquName","#1变压器出线-三洪奇"); - put("workContent","#29电池舱第四簇高压箱"); - put("ps_year","2023"); - put("ps_month","11"); - put("ps_day","11"); - put("ps_hour","16"); - put("ps_minuter","45"); - put("pe_year","2023"); - put("pe_month","11"); - put("pe_day","12"); - put("pe_hour","11"); - put("pe_minuter","13"); - put("matterLibraryListOne", Lists.newArrayList(measure,measure,measure,measure,measure,measure,measure,measure)); - put("signerName","杨汪洋"); - put("s_year","2023"); - put("s_month","11"); - put("s_day","12"); - put("s_hour","11"); - put("s_minuter","13"); - put("jobReceiver","杨汪洋"); - put("r_year","2023"); - put("r_month","11"); - put("r_day","12"); - put("r_hour","11"); - put("r_minuter","13"); - put("l_year","2023"); - put("l_month","11"); - put("l_day","12"); - put("l_hour","11"); - put("l_minuter","13"); - put("licensorName","杨汪洋"); - put("principalName1","杨汪洋"); - put("groundNum","11"); - put("dismantleNum","12"); - put("retainNum","8"); - put("brakeNumber","A7758258"); - put("licensorName2","A7758258"); - put("isSafety ","☑"); - put("isHazard","☑"); - put("isRailway","☑"); - put("isLimited","☑"); - }}; + WorkTicketInfoEntity workTicketInfoEntity = this.getById(ticketId); + Map params = this.getTicketParamById(ticketId,workTicketInfoEntity); + String tempFileName = WorkTicketConstants.TicketSignageEnum.getTempFileNameByType(workTicketInfoEntity.getType()); + Assert.isTrue(StringUtil.isNotBlank(tempFileName),() -> { + throw new ServiceException("未找到模板文件,预览失败!"); + }); + String wordPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".docx"; + this.exportTicketWord("template/"+tempFileName, wordPath, params); + String pdfPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".pdf"; + AsposeUtil.wordToPdf(wordPath,pdfPath); + PdfUtils.readPdf(response,pdfPath); + } + + private String getFileSavePath() { + String os = System.getProperty("os.name").toLowerCase(); + if("linux".equals(os)) { + return pdfSavePath; + } + else { + return "E://template/"; + } + } + + private Map getTicketParamById(Long ticketId,WorkTicketInfoEntity workTicketInfoEntity) { + Map params = ObjectUtils.obj2Map(workTicketInfoEntity); + params.put("signerName",Optional.ofNullable(workTicketInfoEntity.getSigner()).map(UserCache::getUser).map(User::getName).orElse(null)); + // 获取两票安措 + List measures = workTicketSafetyMeasureService.selectByTicketId(ticketId); + if(CollectionUtil.isNotEmpty(measures)) { + Map> measureMap = measures.stream().map(ObjectUtils::obj2Map).peek(m -> m.put("status", TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus().equals(m.get("status")) ? "√" : null)).collect(Collectors.groupingBy(m -> (String) m.get("type"))); + Arrays.stream(WorkTicketConstants.WorkTicketMeasureTypeEnum.class.getEnumConstants()).forEach(e -> { + if(ObjectUtil.isNotEmpty(measureMap.get(e.getType()))) { + List list = measureMap.get(e.getType()); + List> measureList = IntStream.iterate(0, index -> index + 1).limit(list.size()> 4 ? list.size() : 4).mapToObj(index -> { + if(list.size() != 0 && list.size() >= index + 1) { + HashMap map = new HashMap() {{ + putAll(list.get(index)); + put("index", index + 1); + }}; + return map; + } + return new HashMap(); + }).collect(Collectors.toList()); + params.put(e.getConvertAttributes(),measureList); + } + else { + params.put(e.getConvertAttributes(),IntStream.iterate(0, index -> index + 1).limit(4).mapToObj(index -> new HashMap()).collect(Collectors.toList())); + } + }); + List addressList = measureMap.get(WorkTicketConstants.WorkTicketMeasureTypeEnum.Five.getType()); + List fillList = measureMap.get(WorkTicketConstants.WorkTicketMeasureTypeEnum.Flow.getType()); + List> measureList = IntStream.iterate(0, index -> index + 1).limit(4).mapToObj(index -> { + Map result = new HashMap(); + if(CollectionUtil.isNotEmpty(addressList) && addressList.size() >= index + 1) { + result.put("safetyMeasure",addressList.get(index).get("measure")); + } + if(CollectionUtil.isNotEmpty(fillList) && fillList.size() >= index + 1) { + result.put("safetyMeasure1",fillList.get(index).get("measure")); + } + return result; + }).collect(Collectors.toList()); + params.put("matterLibraryList",measureList); + } + params.put("isSafety",workTicketInfoEntity.getIsSafety() ? "☑" : "□"); + params.put("isHazard",workTicketInfoEntity.getIsHazard() ? "☑" : "□"); + params.put("isRailway",workTicketInfoEntity.getIsRailway() ? "☑" : "□"); + params.put("isLimited",workTicketInfoEntity.getIsLimited() ? "☑" : "□"); + params.put("isStart",workTicketInfoEntity.getIsStart() ? "☑" : "□"); + // 许可人许可环节 + if(ObjectUtil.isNotEmpty(workTicketInfoEntity.getLicenseTime())) { + params.put("licensorName",Optional.ofNullable(workTicketInfoEntity.getLicensor()).map(UserCache::getUser).map(User::getName).orElse(null)); + params.put("principalName1",params.get("principalName")); + } + WorkTicketFinish finish = workTicketFinishService.selectByTicketId(ticketId); + if(ObjectUtil.isNotEmpty(finish)) { + if(Func.isNotEmpty(finish.getWorkEndTime())) { + params.put("principalName3",params.get("principalName")); + params.put("licensorName1",params.get("licensorName")); + params.putAll(ObjectUtils.LocalDateConvertMap(finish.getWorkEndTime(),"f","_")); + } + if(Func.isNotEmpty(finish.getLicensorEndTime())) { + params.put("licensorName2",params.get("licensorName")); + params.put("groundNum",finish.getGroundNum()); + params.put("dismantleNum",finish.getDismantleNum()); + params.put("retainNum",finish.getRetainNum()); + params.put("brakeNumber",finish.getBrakeNumber()); + params.put("tellContent",finish.getTellContent()); + params.putAll(ObjectUtils.LocalDateConvertMap(finish.getLicensorEndTime(),"e","_")); + } + } + return params; + } + /** + * word模板填充内容并将结果导出 + * @param templatePath 模板路径 + * @param savePath 结果导出路径 + * @param params 填充对象 + */ + private void exportTicketWord(String templatePath, String savePath, Map params) { XWPFDocument xwpfDocument = null; try { - xwpfDocument = WordExportUtil.exportWord07("template/电气第一种工作票模版新.docx", params); + xwpfDocument = WordExportUtil.exportWord07(templatePath, params); } catch (Exception e) { - throw new RuntimeException(e); + e.printStackTrace(); } - String wordPath = "E://template/" + params.get("code") + "_" + params.get("addressEquName") +".docx"; - String pdfPath = "E://template/" + params.get("code") + "_" + params.get("addressEquName") +".pdf"; - // String pdfPath = pdfSavePath + "/" + params.get("code") + "_" + params.get("addressEquName") +".pdf"; FileOutputStream outputStream = null; try { - outputStream = new FileOutputStream(wordPath); + outputStream = new FileOutputStream(savePath); } catch (FileNotFoundException e) { throw new RuntimeException(e); } @@ -358,8 +403,6 @@ public class FirstWorkTicketServiceImpl extends BaseServiceImpldocFileList = new ArrayList<>(); - // docFileList.add(new File("F:\\idea项目\\flowable\\demo\\src\\main\\resources\\电气第一种工作票模版.docx")); + // docFileList.add(new File("F:\\idea项目\\flowable\\demo\\src\\main\\resources\\电气第一种工作票模版_bak.docx")); // docFileList.add(new File("F:\\idea项目\\flowable\\demo\\src\\main\\resources\\动火工作票.docx")); // // //合并之后doc存储路径 此处读的配置文件的存储路径 D:/pdfData/ diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/ObjectUtils.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/ObjectUtils.java index ac273f5..4ca8a4c 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/ObjectUtils.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/ObjectUtils.java @@ -6,6 +6,7 @@ import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; import java.lang.reflect.Field; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -40,12 +41,7 @@ public class ObjectUtils { result.put(field.getName(),time.format(DateUtil.TIME_FORMATTER)); } else { - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"year",time.getYear()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"month",time.getMonth()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"day",time.getDayOfMonth()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"hour",time.getHour()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"minute",time.getMinute()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"second",time.getSecond()); + result.putAll(LocalDateConvertMap(time,dateTimeToMap.prefix(),dateTimeToMap.split())); } } else if(value instanceof Date) { @@ -59,14 +55,36 @@ public class ObjectUtils { result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"month",time.getMonth()); result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"day",time.getDay()); result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"hour",time.getHours()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"minute",time.getMinutes()); + result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"minuter",time.getMinutes()); result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"second",time.getSeconds()); } } + else { + result.put(field.getName(),value); + } }); return result; } return null; } + /** + * 将时间按格式转化为map对象 + * @param dateTime 待转换时间 + * @param prefix 转换格式Key前缀 + * @param split 转换格式Key分隔符 + * @return map对象 + */ + public static Map LocalDateConvertMap(LocalDateTime dateTime,String prefix,String split) { + HashMap result = new HashMap() {{ + put(prefix + split + "year", dateTime.getYear()); + put(prefix + split + "month", dateTime.getMonthValue()); + put(prefix + split + "day", dateTime.getDayOfMonth()); + put(prefix + split + "hour", dateTime.getHour()); + put(prefix + split + "minuter", dateTime.getMinute()); + put(prefix + split + "second", dateTime.getSecond()); + }}; + return result; + } + } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/PdfUtils.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/PdfUtils.java index d9f32cc..61267e1 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/PdfUtils.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/PdfUtils.java @@ -326,36 +326,4 @@ public class PdfUtils { } } } - -// public static void main(String[] args) { -// Runnable runnable = new Runnable() { -// @Override -// public void run() { -// try { -// Thread.sleep(3000); -// log.info("---调用结束---"); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// } -// }; -// new Thread(runnable).start(); -// log.info("---返回结果---"); -// Callable callable = new Callable() { -// @Override -// public Object call() throws Exception { -// try { -// log.info("进入包装方法"); -// Thread.sleep(4000); -// log.info("包装方法执行完成"); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// return null; -// } -// }; -// FutureTask ft1 = new FutureTask(callable); -// new Thread(ft1).start(); -// log.info("---返回结果---"); -// } } diff --git a/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx b/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx index 0ebee99..d8dbb9d 100644 Binary files a/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx and b/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/水力机械工作票模版_bak.docx b/hzims-service/ticket/src/main/resources/template/水力机械工作票模版_bak.docx new file mode 100644 index 0000000..0ebee99 Binary files /dev/null and b/hzims-service/ticket/src/main/resources/template/水力机械工作票模版_bak.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版.docx b/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版.docx index 3e60ea9..6c836e1 100644 Binary files a/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版.docx and b/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版_bak.docx b/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版_bak.docx new file mode 100644 index 0000000..079aa5a Binary files /dev/null and b/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版_bak.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版新.docx b/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版新.docx deleted file mode 100644 index 0f33d89..0000000 Binary files a/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版新.docx and /dev/null differ diff --git a/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx b/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx index 068eca3..3ea1e4d 100644 Binary files a/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx and b/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版_bak.docx b/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版_bak.docx new file mode 100644 index 0000000..068eca3 Binary files /dev/null and b/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版_bak.docx differ