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 9fa55b4..68fbb3f 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 @@ -2,77 +2,85 @@ package com.hnac.hzims.ticket.constants; import lombok.AllArgsConstructor; import lombok.Getter; + import java.util.Arrays; import java.util.Optional; /** * 工作票中所需常数定义 + * * @author hx */ public interface WorkTicketConstants { - @AllArgsConstructor - enum WorkTicketMeasureTypeEnum { - /**第一种安措**/ - ONE("1","matterLibraryListOne"), - /**第二种安措**/ - TWO("2","matterLibraryListTwo"), - /**第三种安措**/ - THREE("3","matterLibraryListThree"), - FOUR("4","matterLibraryListFour"), - Five("5","matterLibraryListFive"), - Flow("6","matterLibraryListFlow"), - ; - @Getter - private String type; - @Getter - private String convertAttributes; - } + @AllArgsConstructor + enum WorkTicketMeasureTypeEnum { + /** 第一种安措 **/ + ONE("1", "matterLibraryListOne"), + /** 第二种安措 **/ + TWO("2", "matterLibraryListTwo"), + /** 第三种安措 **/ + THREE("3", "matterLibraryListThree"), + FOUR("4", "matterLibraryListFour"), + Five("5", "matterLibraryListFive"), + Flow("6", "matterLibraryListFlow"), + //第二种工作票 + SEVEN("7", "matterLibraryListSeven"), + //水力机器工作票 + EIGHT("8", "matterLibraryListEight"), + NINE("9", "matterLibraryListNine"), + TEN("10", "matterLibraryListTen"), + + ; + @Getter + private String type; + @Getter + private String convertAttributes; + } - @AllArgsConstructor - enum FirstWorkTicketStatusEnum { - /**签发**/ - SIGN(1,"签发"), - /**收到工作票**/ - RECEIVE(2,"收到工作票"), - /**许可人许可**/ - LICENSE(3,"许可人许可"), - /**确认条件具备**/ - CONFIRM_MEASURE(4,"确认条件具备"), - /**工作负责人确认工作**/ - CONFIRM_WORK(5,"工作负责人确认工作"), - /**许可人确认工作结束**/ - WORK_FINISH(6,"许可人确认工作结束"), - /**工作票终结**/ - TICKET_FINISH(7,"工作票终结"), - /**结束**/ - FINISH(8,"结束"), - /**许可人延期确认**/ - LICENSE_DELAY(9,"许可人延期确认"), - /**负责人延期确认**/ - CONFIRM_DELAY(10,"负责人延期确认"), - /**作废**/ - INVALID(11,"作废"), - /**逾期**/ - OVERDUE(12,"逾期"), - /**线下开票**/ - OFFLINE(13,"线下开票"), - /**线下执行任务**/ - OFFLINE_OPERATE(14,"线下执行任务"), - /**线下许可人许可**/ - OFFLINE_LICENSE(15,"线下许可人许可"), - /**线下结束**/ - OFFLINE_END(16,"线下结束") - ; - @Getter - private Integer status; - @Getter - private String description; + @AllArgsConstructor + enum FirstWorkTicketStatusEnum { + /** 签发 **/ + SIGN(1, "签发"), + /** 收到工作票 **/ + RECEIVE(2, "收到工作票"), + /** 许可人许可 **/ + LICENSE(3, "许可人许可"), + /** 确认条件具备 **/ + CONFIRM_MEASURE(4, "确认条件具备"), + /** 工作负责人确认工作 **/ + CONFIRM_WORK(5, "工作负责人确认工作"), + /** 许可人确认工作结束 **/ + WORK_FINISH(6, "许可人确认工作结束"), + /** 工作票终结 **/ + TICKET_FINISH(7, "工作票终结"), + /** 结束 **/ + FINISH(8, "结束"), + /** 许可人延期确认 **/ + LICENSE_DELAY(9, "许可人延期确认"), + /** 负责人延期确认 **/ + CONFIRM_DELAY(10, "负责人延期确认"), + /** 作废 **/ + INVALID(11, "作废"), + /** 逾期 **/ + OVERDUE(12, "逾期"), + /** 线下开票 **/ + OFFLINE(13, "线下开票"), + /** 线下执行任务 **/ + OFFLINE_OPERATE(14, "线下执行任务"), + /** 线下许可人许可 **/ + OFFLINE_LICENSE(15, "线下许可人许可"), + /** 线下结束 **/ + OFFLINE_END(16, "线下结束"); + @Getter + private Integer status; + @Getter + private String description; - public static FirstWorkTicketStatusEnum getEnumByStatus(Integer status) { - Optional statusOptional = Arrays.stream(FirstWorkTicketStatusEnum.class.getEnumConstants()) - .filter(e-> status.equals(e.getStatus())).findAny(); - return statusOptional.orElse(null); - } - } + public static FirstWorkTicketStatusEnum getEnumByStatus(Integer status) { + Optional statusOptional = Arrays.stream(FirstWorkTicketStatusEnum.class.getEnumConstants()) + .filter(e -> status.equals(e.getStatus())).findAny(); + return statusOptional.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 77e63a0..ff89923 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 @@ -316,8 +316,8 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { /** * 工作条件(false 停电 true 不停电) */ - @ApiModelProperty("工作条件(false 停电 true 不停电)") - private Boolean isPower; + @ApiModelProperty("工作条件(停电或不停电)") + private String power; /** @@ -414,6 +414,13 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { /** + * 用户Id + */ + @ApiModelProperty("用户Id") + private String flowUserId; + + + /** * 当前任务名 */ @ApiModelProperty("当前任务名") 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 new file mode 100644 index 0000000..f74288f --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/constant/TicketConstant.java @@ -0,0 +1,58 @@ +package com.hnac.hzims.ticket.twoTicket.constant; + +/** + * 定义ticket常量 + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/6/2 13:48 + */ +public class TicketConstant { + + /** + * window操作系统工作票访问路径 + */ + public static final String TICKET_WINDOW_PATH = "hzims-service/ticket/src/main/resources/template"; + + /** + * Liunx操作系统工作票访问路径 + */ + public static final String TICKET_LIUNX_PATH = "/data/hzims/ticket/word/template/ticket"; + + + /** + * window操作系统工作票合并输出路径 + */ + public static final String TICKET_WINDOW_MERGE_PATH = "D:\\导出excel\\"; + + /** + * liunx操作系统工作票合并输出路径 + */ + public static final String TICKET_LIUNX_MERGE_PATH = "/data/hzims/ticket/word/template/ticket/ouput/"; + + /** + * os.name + */ + public static final String OS_NAME = System.getProperty("os.name"); + + + /** + * 安全隔离措施附页 + */ + public static final String SECURE_PAGE = "/secondary/工作票安全措施附页.docx"; + + /** + * 危险点分析与预控措施票 + */ + public static final String SAFETY_PAGE = "/secondary/工作票危险点分析及控制措施票.docx"; + /** + * 动火工作票 + */ + public static final String FLIGHT_PAGE = "/secondary/动火工作票.docx"; + + /** + * 有限空间监测记录单 + */ + public static final String SPACE_PAGE = "/secondary/有限空间监测记录单.docx"; + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java index caf10e2..a15519d 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java @@ -61,8 +61,9 @@ public class TicketProcessController { @ApiOperation(value = "新预览") @ApiOperationSupport(order = 11) public void preview(@RequestParam(value = "ticketId", required = true) Long ticketId, + @RequestParam(value = "status", required = true) Integer status, HttpServletResponse response) { - ticketProcessService.newPreview(ticketId, response); + ticketProcessService.newPreview(ticketId, status, response); } } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java index 156e974..c4522ba 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java @@ -30,8 +30,10 @@ public interface TicketProcessService { /** * 新预览 + * + * @param status * @param response * @return */ - void newPreview(Long ticketId, HttpServletResponse response); + void newPreview(Long ticketId, Integer status, HttpServletResponse response); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java index 5931c64..da04670 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java @@ -20,12 +20,15 @@ import com.hnac.hzims.ticket.constants.TicketConstants; import com.hnac.hzims.ticket.constants.WorkTicketConstants; import com.hnac.hzims.ticket.processflow.strategy.core.ProcessIdWorker; import com.hnac.hzims.ticket.response.ProcessWorkFlowResponse; +import com.hnac.hzims.ticket.twoTicket.constant.TicketConstant; import com.hnac.hzims.ticket.twoTicket.entity.TicketInfoDanger; import com.hnac.hzims.ticket.twoTicket.entity.WorkTicketFinish; import com.hnac.hzims.ticket.twoTicket.service.IFirstWorkTicketService; import com.hnac.hzims.ticket.twoTicket.service.IWorkTicketFinishService; import com.hnac.hzims.ticket.twoTicket.service.TicketInfoDangerService; import com.hnac.hzims.ticket.twoTicket.service.TicketProcessService; +import com.hnac.hzims.ticket.twoTicket.utils.WordHelper; +import com.hnac.hzims.ticket.twoTicket.utils.WordMapUtils; import com.hnac.hzims.ticket.twoTicket.vo.process.FristWorkTicketVo; import com.hnac.hzims.ticket.twoTicket.vo.process.WorkTicketVo; import com.hnac.hzims.ticket.utils.MergeDocUtils; @@ -58,7 +61,8 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.File; -import java.io.FileOutputStream; +import java.time.Duration; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; @@ -148,28 +152,28 @@ public class TicketProcessServiceImpl implements TicketProcessService { public void startUp(WorkTicketVo workTicketVo) { log.info("执行 com.hnac.hzims.ticket.twoTicket.service.impl【startUp】 。。。方法"); if (workTicketVo.getWorkTicket().getSignage() == null) { - throw new ServiceException("站点编码不能为空"); + throw new ServiceException("票据抬头未配置,请您到站点管理配置"); } StationEntity stationEntity = new StationEntity(); stationEntity.setCode(workTicketVo.getWorkTicket().getSignageCode()); R stationClientOne = stationClient.getOne(stationEntity); if (!stationClientOne.isSuccess()) { - throw new IllegalArgumentException("站点编码不能为空"); + throw new IllegalArgumentException("票据抬头未配置,请您到站点管理配置?"); } StationEntity station = stationClientOne.getData(); if (station == null) { - throw new ServiceException("站点编码不能为空"); + throw new ServiceException("票据抬头未配置,请您到站点管理配置"); } log.info("前端查的站点编号 :{}", workTicketVo.getWorkTicket().getSignage()); log.info("后端查寻的站点编码 :{}", station.getSignage()); if (!workTicketVo.getWorkTicket().getSignage().equals(station.getSignage())) { - throw new ServiceException("站点编码不能为空"); + throw new ServiceException("站点标识不能为空"); } //获取站点编号 String signage = station.getSignage(); if (StringUtils.isBlank(signage) || signage.length() < 2) { - throw new ServiceException("站点编码不能为空"); + throw new ServiceException("站点标识不能为空"); } signage = signage.length() == 2 ? station.getSignage() : station.getSignage().substring(0, 2); @@ -405,6 +409,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { // log.error("获取用户信息失败"); // workTicket.setNextStepOperator(null); // } + workTicket.setFlowUserId(response.getUserId()); workTicket.setNextStepOperator(response.getNextStepOperator()); } @@ -504,35 +509,36 @@ public class TicketProcessServiceImpl implements TicketProcessService { * @param workTicketVo */ public void dealProcess(String newFirstWorkTicketFlowKey, WorkTicketVo workTicketVo) { + Instant start = Instant.now(); //若为线下工作票 则无需开启工作流 Integer status = WorkTicketConstants.FirstWorkTicketStatusEnum.SIGN.getStatus(); if (status.intValue() != workTicketVo.getWorkTicket().getFlowStatus().intValue()) { return; } - log.info("租户Id:{}", AuthUtil.getTenantId()); - log.info("用户部门Id: {}", AuthUtil.getUser().getDeptId()); - log.info("用户Id: {}", AuthUtil.getUserId()); + //log.info("租户Id:{}", AuthUtil.getTenantId()); + //log.info("用户部门Id: {}", AuthUtil.getUser().getDeptId()); + //log.info("用户Id: {}", AuthUtil.getUserId()); //获取签发人角色下的人员 - R> listR = userClient.relationUserListByRoleAlias(AuthUtil.getTenantId(), Long.parseLong(AuthUtil.getUser().getDeptId()), TicketConstants.SIGNER_ROLE); - if (!listR.isSuccess() || CollectionUtil.isEmpty(listR.getData())) { - throw new ServiceException("工作票签发人角色下未查询到相关人员"); - } - log.info("获取签发人角色下的人员: {}", listR.getData()); + // R> listR = userClient.relationUserListByRoleAlias(AuthUtil.getTenantId(), Long.parseLong(AuthUtil.getUser().getDeptId()), TicketConstants.SIGNER_ROLE); + // if (!listR.isSuccess() || CollectionUtil.isEmpty(listR.getData())) { + // throw new ServiceException("工作票签发人角色下未查询到相关人员"); + // } Map params = new HashMap<>(4); params.put("workTicketVo", workTicketVo); //已开启流程 - workTicketVo.setIsState(true); - log.info("获取表单的数据: {}", workTicketVo); R processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(newFirstWorkTicketFlowKey, String.valueOf(workTicketVo.getWorkTicket().getId()), workTicketVo.getWorkTicket().getWorkContent(), params); log.info("processInstanceContainNameByKey.isSuccess() : {}", processInstanceContainNameByKey.isSuccess()); - log.info("processInstanceContainNameByKey.getData() : {}", processInstanceContainNameByKey.getData()); - log.info("BladeFlow processInstanceContainNameByKey:{}", processInstanceContainNameByKey); if (!processInstanceContainNameByKey.isSuccess() && processInstanceContainNameByKey.getCode() == 500) { log.error("processInstanceContainNameByKey {}", processInstanceContainNameByKey.getMsg()); throw new ServiceException("不好意思,您暂无权限..."); } log.info("获取启动流程数据 : {}", processInstanceContainNameByKey); + Duration between = Duration.between(start, Instant.now()); + System.out.println("================================================================"); + System.err.println("耗时: " + (between.getSeconds()) + "秒"); + System.err.println("耗时: " + (between.toMillis()) + "毫秒"); + System.out.println("================================================================"); } @@ -660,12 +666,13 @@ public class TicketProcessServiceImpl implements TicketProcessService { * 新预览 * * @param ticketId + * @param status * @param response * @return */ @SneakyThrows @Override - public void newPreview(Long ticketId, HttpServletResponse response) { + public void newPreview(Long ticketId, Integer status, HttpServletResponse response) { String fileName = IdWorker.get32UUID() + ".docx"; // response.setContentType("application/octet-stream;charset=ISO8859-1"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); @@ -675,65 +682,67 @@ public class TicketProcessServiceImpl implements TicketProcessService { WorkTicketVo workTicketVo = ticketInfoService.selectDetailsById(ticketId); //将查询的数据转换为map Map workTicketInfoMap = this.convertMap(workTicketVo); + Map resultMap = WordHelper.resultMap(workTicketInfoMap); //创建新的map - for (Map.Entry stringObjectEntry : workTicketInfoMap.entrySet()) { + for (Map.Entry stringObjectEntry : resultMap.entrySet()) { log.info("获取map : " + stringObjectEntry.getKey() + "=====>" + stringObjectEntry.getValue()); } WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); if ((workTicket.getIsSafety() == null && workTicket.getIsHazard() == null && workTicket.getIsLimited() == null && workTicket.getIsRailway() == null) || (workTicket.getIsSafety() == null || workTicket.getIsHazard() == null || workTicket.getIsLimited() == null || workTicket.getIsRailway() == null)) { - extractedWithWord(response, workTicketInfoMap); + extractedWithWord(response, resultMap, status); return; } //如果4个多为false 或为空 附件不展示附件 if (!workTicket.getIsSafety() && !workTicket.getIsHazard() && !workTicket.getIsLimited() && !workTicket.getIsRailway()) { - extractedWithWord(response, workTicketInfoMap); + extractedWithWord(response, resultMap, status); return; } - List docFileList = new ArrayList<>(); + List docFileList = new ArrayList<>(); // /template/secondary/工作票安全措施附页.docx - String os = System.getProperty("os.name"); - + String os = TicketConstant.OS_NAME; String prefix = null; //Windows操作系统 if (os != null && os.toLowerCase().startsWith("windows")) { - prefix = "hzims-service/ticket/src/main/resources/template"; + prefix = TicketConstant.TICKET_WINDOW_PATH; } else { - prefix = "/data/hzims/ticket/word/template/ticket"; + prefix = TicketConstant.TICKET_LIUNX_PATH; } + //获取工作票种类 + String workTicketStatus = WordMapUtils.getWorkTicketStatus(status); - docFileList.add(new File(prefix + "/电气第一种工作票模版.docx")); + docFileList.add(new File(prefix + "/" + workTicketStatus)); //安全隔离措施附页 (true,展示附件,false,不展示附件) if (workTicket.getIsSafety()) { - addFile(prefix, "/secondary/工作票安全措施附页.docx", docFileList); + addFile(prefix, TicketConstant.SECURE_PAGE, docFileList); // setWorkTicketPrincipalChange(docFileList); } //危险点分析与预控措施票 (true,展示附件,false,不展示附件) if (workTicket.getIsSafety()) { - addFile(prefix, "/secondary/工作票危险点分析及控制措施票.docx", docFileList); + addFile(prefix, TicketConstant.SAFETY_PAGE, docFileList); // setWorkTicketHazardPointChange(docFileList); } //动火工作票 (true,展示附件,false,不展示附件) if (workTicket.getIsRailway()) { - addFile(prefix, "/secondary/动火工作票.docx", docFileList); + addFile(prefix, TicketConstant.FLIGHT_PAGE, docFileList); // setWorkTicketRailwayChange(docFileList); } //有限空间监测记录单(true,展示附件,false,不展示附件) if (workTicket.getIsLimited()) { - addFile(prefix, "/secondary/有限空间监测记录单.docx", docFileList); + addFile(prefix, TicketConstant.SPACE_PAGE, docFileList); // setWorkTicketLimitedChange(docFileList); } String name = LocalDate.now() + "-" + UUID.randomUUID().toString().replaceAll("-", ""); String docPath = null; if (os != null && os.toLowerCase().startsWith("windows")) { - docPath = "D:\\导出excel\\"; + docPath = TicketConstant.TICKET_WINDOW_MERGE_PATH; } else { - docPath = "/data/hzims/ticket/word/template/ticket/ouput/"; + docPath = TicketConstant.TICKET_LIUNX_MERGE_PATH; } docPath = docPath + name + ".docx"; @@ -742,7 +751,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { //导入文档 File file = new File(docPath); MergeDocUtils.mergeDoc(docFileList, file); - XWPFDocument xwpfDocument = WordExportUtil.exportWord07(docPath, workTicketInfoMap); + XWPFDocument xwpfDocument = WordExportUtil.exportWord07(docPath, resultMap); xwpfDocument.write(response.getOutputStream()); //删除路径 file.delete(); @@ -754,18 +763,23 @@ public class TicketProcessServiceImpl implements TicketProcessService { * * @param response * @param workTicketInfoMap + * @param status * @throws Exception */ - private static void extractedWithWord(HttpServletResponse response, Map workTicketInfoMap) throws Exception { - XWPFDocument doc = WordExportUtil.exportWord07("template/电气第一种工作票模版.docx", workTicketInfoMap); - String os = System.getProperty("os.name"); + private static void extractedWithWord(HttpServletResponse response, Map workTicketInfoMap, Integer status) throws Exception { + String workTicketStatus = WordMapUtils.getWorkTicketStatus(status); + String os = TicketConstant.OS_NAME; //Windows操作系统 if (os != null && os.toLowerCase().startsWith("windows")) { + String url = "template/" + workTicketStatus; + XWPFDocument doc = WordExportUtil.exportWord07(url, workTicketInfoMap); log.info("当前系统版本是:{}", os); - String name = "D:/导出excel/电气第一种工作票模版.docx"; - FileOutputStream fos = new FileOutputStream(name); - doc.write(fos); + //String name = "D:/导出excel/电气第一种工作票模版.docx"; + //FileOutputStream fos = new FileOutputStream(name); + doc.write(response.getOutputStream()); } else { + String url = TicketConstant.TICKET_LIUNX_PATH + "/" + workTicketStatus; + XWPFDocument doc = WordExportUtil.exportWord07(url, workTicketInfoMap); //其它操作系统 log.info("当前系统版本是:{}", os); ServletOutputStream outputStream = response.getOutputStream(); @@ -793,38 +807,35 @@ public class TicketProcessServiceImpl implements TicketProcessService { log.info("安全措施: {}", safetyMeasuresList); if (CollectionUtils.isNotEmpty(safetyMeasuresList)) { Map workTicketInfoMap1 = new HashMap<>(); - Map> measureMap = safetyMeasuresList.stream(). - collect(Collectors.groupingBy(WorkTicketSafetyMeasureEntity::getType)); - Arrays.stream(WorkTicketConstants.WorkTicketMeasureTypeEnum.class.getEnumConstants()) - .forEach(measureEnum -> { - if (CollectionUtil.isNotEmpty(measureMap.get(measureEnum.getType()))) { - List> mapList = new ArrayList<>(); - int tempIndex = 1, index = 1; - List workTicketSafetyMeasureEntities = measureMap - .get(measureEnum.getType()); - for (WorkTicketSafetyMeasureEntity measureVO : workTicketSafetyMeasureEntities) { - String type = measureEnum.getType(); - if (tempIndex != Integer.valueOf(type)) { - index = 1; - tempIndex++; - } - log.info("获取安全措施的信息: {}", measureVO); - Map map = PdfUtils.objectToMap(measureVO, true); - map.put("index", index); - map.put("safetyMeasure", ObjectUtil.isNotEmpty(map.get("measure")) ? map.get("measure") : null); - String status = TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus() - .equals(measureVO.getStatus()) ? "√" : ""; - map.put("status", status); - mapList.add(map); - index++; - } - workTicketInfoMap1.put(measureEnum.getConvertAttributes(), mapList); - } else { - workTicketInfoMap1.put(measureEnum.getConvertAttributes(), - new ArrayList()); + Map> measureMap = safetyMeasuresList.stream().collect(Collectors.groupingBy(WorkTicketSafetyMeasureEntity::getType)); + Arrays.stream(WorkTicketConstants.WorkTicketMeasureTypeEnum.class.getEnumConstants()).forEach(measureEnum -> { + if (CollectionUtil.isNotEmpty(measureMap.get(measureEnum.getType()))) { + List> mapList = new ArrayList<>(); + int tempIndex = 1, index = 1; + List workTicketSafetyMeasureEntities = measureMap.get(measureEnum.getType()); + for (WorkTicketSafetyMeasureEntity measureVO : workTicketSafetyMeasureEntities) { + String type = measureEnum.getType(); + if (tempIndex != Integer.valueOf(type)) { + index = 1; + tempIndex++; } - }); + log.info("获取安全措施的信息: {}", measureVO); + Map map = PdfUtils.objectToMap(measureVO, true); + map.put("index", index); + map.put("safetyMeasure", ObjectUtil.isNotEmpty(map.get("measure")) ? map.get("measure") : null); + String status = TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus().equals(measureVO.getStatus()) ? "√" : ""; + map.put("status", status); + mapList.add(map); + index++; + } + workTicketInfoMap1.put(measureEnum.getConvertAttributes(), mapList); + } else { + workTicketInfoMap1.put(measureEnum.getConvertAttributes(), new ArrayList()); + } + }); + //验证工作措施是有有数据 + this.isMatterLibraryList(workTicketInfoMap1); // 工作地点保留带电部位或注意事项 this.matterLibraryListWithMap(workTicketInfoMap1); result.putAll(workTicketInfoMap1); @@ -876,31 +887,118 @@ public class TicketProcessServiceImpl implements TicketProcessService { return newItem; }).collect(Collectors.toList()); - map.put("ticketInfoDangers", CollectionUtils.isNotEmpty(collect) ? collect - : new ArrayList>()); + map.put("ticketInfoDangers", CollectionUtils.isNotEmpty(collect) ? collect : new ArrayList>()); result.putAll(map); } + //工作票危险点分析及控制措施票 + WordMapUtils.newMapWithList("ticketInfoDangers", result, true, 4, "maintenance", "dangerousPoint"); //7. 是否包含 - isExists(result); - + this.isExists(result); + //8. 存入新的数据 + this.addMapPut(result); return result; } /** + * 验证是否有数据 + * + * @param workTicketInfoMap + */ + private void isMatterLibraryList(Map workTicketInfoMap) { + //1. 第一种工作票 + //1.1 应断开断路器和隔离开关,包括填写前已断开断路器和隔离开关(注明编号)、应取熔断器(保险) + WordMapUtils.newMapWithList(WorkTicketConstants.WorkTicketMeasureTypeEnum.ONE.getConvertAttributes(), workTicketInfoMap, true, 6, "safetyMeasure", "status"); + //1.2 应装设接地线、隔板、隔罩(注明确切地点),应合上接地刀闸(注明双重名称) + WordMapUtils.newMapWithList(WorkTicketConstants.WorkTicketMeasureTypeEnum.TWO.getConvertAttributes(), workTicketInfoMap, true, 3, "safetyMeasure", "status"); + //1.3 应装设遮拦、应挂标识牌及防止二次回路误碰等措施(注明确实地点、名称) + WordMapUtils.newMapWithList(WorkTicketConstants.WorkTicketMeasureTypeEnum.THREE.getConvertAttributes(), workTicketInfoMap, true, 6, "safetyMeasure", "status"); + + //2. 第二种工作票 + //2.1 应断开断路器和隔离开关,包括填写前已断开断路器和隔离开关(注明编号)、应取熔断器(保险) + WordMapUtils.newMapWithList(WorkTicketConstants.WorkTicketMeasureTypeEnum.SEVEN.getConvertAttributes(), workTicketInfoMap, true, 6, "safetyMeasure", "status"); + + + //3. 水利机器工作票 + //3.1 必须采取的安全措施 + WordMapUtils.newMapWithList(WorkTicketConstants.WorkTicketMeasureTypeEnum.EIGHT.getConvertAttributes(), workTicketInfoMap, true, 8, "safetyMeasure", "status"); + //3.2 检修工作要求检修人员自行执行的安全措施(由工作负责人填写) + WordMapUtils.newMapWithList(WorkTicketConstants.WorkTicketMeasureTypeEnum.NINE.getConvertAttributes(), workTicketInfoMap, true, 5, "safetyMeasure", "status"); + //3.3 检修工作要求检修人员自行执行的安全措施(由工作负责人填写) + WordMapUtils.newMapWithList(WorkTicketConstants.WorkTicketMeasureTypeEnum.TEN.getConvertAttributes(), workTicketInfoMap, true, 5, "safetyMeasure", "status"); + + + } + + + /** + * 存入新的数据 + * + * @param result + */ + private void addMapPut(Map result) { + log.info("存入新的数据"); + //许可人确认安全措施,负责人确认安全措施 + if (WordHelper.isNoneBlank(result, "licenseTime")) { + log.info("许可人确认安全措施,负责人确认安全措施"); + String principalName = WordHelper.toMapAsString(result, "principalName", 10); + result.put("principalName1", principalName); + } else { + WordHelper.putMap(result, "principalName1", 10); + } + + //负责人变更 + if (WordHelper.isNoneBlank(result, "initialPrincipalName")) { + log.info("负责人变更"); + //签发人 + String signerName = WordHelper.toMapAsString(result, "signerName", 10); + result.put("signerName2", signerName); + //许可人 + String licensorName = WordHelper.toMapAsString(result, "licensorName", 10); + result.put("licensorName1", licensorName); + } else { + WordHelper.putMap(result, "signerName2", 10); + WordHelper.putMap(result, "licensorName1", 10); + } + + //延期 + if (WordHelper.isNoneBlank(result, "changeTime")) { + log.info("延期"); + //负责人 + String licensorName = WordHelper.toMapAsString(result, "principalName", 10); + result.put("principalName2", licensorName); + }else { + WordHelper.putMap(result, "principalName2", 10); + } + + //许可人确认工作票终结 + + if (WordHelper.isNoneBlank(result, "workEndTime")) { + log.info("许可人确认工作票终结"); + //负责人 + String principalName = WordHelper.toMapAsString(result, "principalName", 10); + result.put("principalName3", principalName); + //许可人 + String licensorName = WordHelper.toMapAsString(result, "licensorName", 10); + result.put("licensorName2", licensorName); + }else { + WordHelper.putMap(result, "principalName3", 10); + WordHelper.putMap(result, "licensorName2", 10); + } + } + + + /** * 工作地点保留带电部位或注意事项 - * 2 个map集合转成一个map集合 + * 2 个map集合转成一个map集合 + * * @param workTicketInfoMap */ private static void matterLibraryListWithMap(Map workTicketInfoMap) { - List> matterLibraryListFive1 = - workTicketInfoMap.get("matterLibraryListFive") == null ? new ArrayList>() - : (List>) workTicketInfoMap.get("matterLibraryListFive"); - List> matterLibraryListFlow1 = workTicketInfoMap.get("matterLibraryListFlow") == null - ? new ArrayList>() - : (List>) workTicketInfoMap.get("matterLibraryListFlow"); + List> matterLibraryListFive1 = workTicketInfoMap.get("matterLibraryListFive") == null ? new ArrayList>() : (List>) workTicketInfoMap.get("matterLibraryListFive"); + List> matterLibraryListFlow1 = workTicketInfoMap.get("matterLibraryListFlow") == null ? new ArrayList>() : (List>) workTicketInfoMap.get("matterLibraryListFlow"); if (matterLibraryListFive1 != null && matterLibraryListFlow1 != null) { List> matterLibraryListFive = matterLibraryListFive1; @@ -930,23 +1028,27 @@ public class TicketProcessServiceImpl implements TicketProcessService { } workTicketInfoMap.put("matterLibraryList", CollectionUtils.isEmpty(maps) ? new ArrayList<>() : maps); - } + + + WordMapUtils.newMapWithList("matterLibraryList", workTicketInfoMap, true, 3, null); + } /** * 判断是否包含,是否存在 + * * @param result */ private static void isExists(Map result) { if (!result.containsKey("ticketInfoDangers")) { - result.put("ticketInfoDangers",new ArrayList>()); + result.put("ticketInfoDangers", new ArrayList>()); } //项目名称 - if (!result.containsKey("projectName")) { - result.put("projectName","\u00A0 "); + if (!result.containsKey("projectName") || StringUtils.isBlank((CharSequence) result.get("projectName"))) { + result.put("projectName", "\u00A0 "); } } @@ -1004,7 +1106,6 @@ public class TicketProcessServiceImpl implements TicketProcessService { } - /** * 添加文件 * @@ -1018,7 +1119,6 @@ public class TicketProcessServiceImpl implements TicketProcessService { } - /** * value true转 ☑ 或 false转 □ * @@ -1033,6 +1133,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { } } + } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/utils/WordHelper.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/utils/WordHelper.java new file mode 100644 index 0000000..8240377 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/utils/WordHelper.java @@ -0,0 +1,229 @@ +package com.hnac.hzims.ticket.twoTicket.utils; + + +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import lombok.AllArgsConstructor; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; + +import java.util.*; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/6/2 14:27 + */ +public class WordHelper extends StringUtils { + + + /** + * Object转 toString + * + * @param object + * @return + */ + public static String toString(Object object) { + return object == null ? null : object.toString().trim(); + } + + + /** + * Map ===》 string + * + * @param result map + * @param key 值 + * @param count 存在多少空格 + * @return + */ + public static String toMapAsString(Map result, String key, int count) { + String signerName = WordHelper.toString(result.get(key)); + return isNotBlank(signerName) ? signerName : "\u00A0" + printSpace(count); + } + + + /** + * 存入map + * + * @param result map + * @param key 值 + * @param count 存在多少空格 + * @return + */ + public static void putMap(Map result, String key, int count) { + result.put(key, "\u00A0" + printSpace(count)); + } + + + /** + * 判断map是否为空 + */ + public static boolean isBlank(Map result, String key) { + String value = WordHelper.toString(result.get(key)); + if (StringUtils.isBlank(value)) { + return true; + } + return false; + } + + + /** + * 判断map不为为空 + */ + public static boolean isNoneBlank(Map result, String key) { + String value = WordHelper.toString(result.get(key)).trim(); + System.out.println(value.length()); + if (StringUtils.isNoneBlank(value)) { + return true; + } + return false; + } + + + /** + * 打印多少空格 + */ + public static String printSpace(int count) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < count; i++) { + sb.append(" "); + } + return sb.toString(); + } + + /** + * map验证是value否为null + * + * @param params + */ + public static Map resultMap(Map params) { + //创建新的Map + Map result = new HashMap<>(); + isContainsKey(params,result); + //遍历 + Set> entries = params.entrySet(); + for (Map.Entry entry : entries) { + listEntryMap(result, entry.getKey(), entry.getValue()); + } + return result; + } + + + /** + * 包含移除 + * @param params + * @param result + */ + private static void isContainsKey(Map params, Map result) { + + if (params.containsKey("principalName1")) { + result.put("principalName1", params.get("principalName1")); + params.remove("principalName1"); + } + + if (params.containsKey("signerName2")) { + result.put("signerName2", params.get("signerName2")); + params.remove("signerName2"); + } + + if (params.containsKey("licensorName1")) { + result.put("licensorName1", params.get("licensorName1")); + params.remove("licensorName1"); + } + + + if (params.containsKey("principalName2")) { + result.put("principalName2", params.get("principalName2")); + params.remove("principalName2"); + } + + + if (params.containsKey("principalName3")) { + result.put("principalName3", params.get("principalName3")); + params.remove("principalName3"); + } + + + if (params.containsKey("licensorName2")) { + result.put("licensorName2", params.get("licensorName2")); + params.remove("licensorName2"); + } + + } + + /** + * + */ + public static void listEntryMap(Map result, String key, Object value) { + List params = new ArrayList<>(); + paramsList(params); + for (Entry entry : params) { + isEntryMap(result, entry.getFileName(), key, value, entry.getCount()); + } + + } + + + @Data + @AllArgsConstructor + static class Entry { + /** + * key值 + */ + private String fileName; + + /** + * count + */ + private Integer count; + + } + + + /** + * 存储list + * + * @param params + */ + private static void paramsList(List params) { + params.add(new Entry("initialPrincipalName", 10)); + params.add(new Entry("principalChangeTime", 10)); + params.add(new Entry("principalName", 10)); + params.add(new Entry("jobReceiver", 10)); + params.add(new Entry("jobReceiverTime", 10)); + params.add(new Entry("watchPrincipalEndTime", 10)); + params.add(new Entry("licenseTime", 10)); + params.add(new Entry("signerDateTime", 10)); + params.add(new Entry("classGroupName", 10)); + params.add(new Entry("code", 10)); + params.add(new Entry("signerName", 10)); + params.add(new Entry("watchPrincipalName", 10)); + params.add(new Entry("projectName", 10)); + params.add(new Entry("groundNum", 5)); + params.add(new Entry("dismantleNum", 5)); + params.add(new Entry("retainNum", 5)); + } + + + /** + * 验证map是否为空 + * + * @param result + * @param fieldName + * @param key + * @param value + * @param count + */ + public static void isEntryMap(Map result, String fieldName, String key, Object value, int count) { + if (fieldName.equals(key)) { + // Object newValue = Optional.ofNullable(value).orElse("\u00A0" + printSpace(count)); + Object newValue = StringUtils.isNoneBlank(toString(value).trim()) ? value : "\u00A0" + printSpace(count); + result.put(key, newValue); + } else { + Object newValue = StringUtils.isNoneBlank(toString(value).trim()) ? value : "\u00A0"; + result.put(key, newValue); + } + } + + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/utils/WordMapUtils.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/utils/WordMapUtils.java new file mode 100644 index 0000000..cdb46e2 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/utils/WordMapUtils.java @@ -0,0 +1,120 @@ +package com.hnac.hzims.ticket.twoTicket.utils; + +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/6/2 7:39 + */ +public class WordMapUtils { + + + + /** + * word 表格转换 + * + * @param key key值 + * @param result 存入数据 + * @param isIndex 是否需要索引 + * @param size word最多的表格数据 + * @param keys 多个key值 + */ + public static void newMapWithList(String key, Map result + , boolean isIndex, int size, String... keys) { + List> list = (List>) result.get(key); + if (CollectionUtils.isEmpty(list)) { + List> newMatterLibraryListTHREE = new ArrayList<>(); + for (int i = 1; i <= size; i++) { + Map map = new HashMap<>(); + //是否需要索引 + if (isIndex) { + map.put("index", i); + } + // 是否有keys + if (keys != null) { + for (String value : keys) { + map.put(value, ""); + } + } + newMatterLibraryListTHREE.add(map); + } + result.put(key, + newMatterLibraryListTHREE); + } else { + + int tempSize = list.size(); + + List> newList = new ArrayList<>(); + if (size > tempSize) { + int sizeLimit = 1; + int tempIndex = 1; + for (int i = 0; i < size; i++) { + Map map = new HashMap<>(); + if (tempSize >= sizeLimit) { + Map stringObjectMap = list.get(i); + // map.putAll(stringObjectMap); + newList.add(stringObjectMap); + tempIndex++; + sizeLimit++; + }else { + //是否需要索引 + if (isIndex) { + map.put("index", tempIndex); + + } + // 是否有keys + if (keys != null) { + for (String value : keys) { + map.put(value, ""); + } + } + tempIndex++; + newList.add(map); + } + } + } else { + for (int i = 0; i < tempSize; i++) { + Map map = list.get(i); + if (isIndex) { + map.put("index", i + 1); + } + newList.add(map); + } + } + result.put(key, newList); + } + } + + + + + /** + * 通过状态获取是第几种工作票 + */ + public static String getWorkTicketStatus(Integer status) { + String pathName = null; + switch (status) { + case 1: + pathName = "电气第一种工作票模版.docx"; + break; + case 2: + pathName = "电气第二种工作票模版.docx"; + break; + case 3: + pathName = "水力机械工作票模版.docx"; + break; + default: + pathName = "电气第一种工作票模版.docx"; + break; + } + return pathName; + } + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/vo/process/WorkTicketVo.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/vo/process/WorkTicketVo.java index 58da938..2dfa1e7 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/vo/process/WorkTicketVo.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/vo/process/WorkTicketVo.java @@ -69,11 +69,6 @@ public class WorkTicketVo { private WorkTicketPrincipalChangeEntity workTicketPrincipalChange; - /** - * 开启流程 - */ - private Boolean isState = true; - 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 3e7b2d9..45251de 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 @@ -257,33 +257,34 @@ public class PdfUtils { result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); } else { - if ("initialPrincipalName".equals(field.getName()) - || "principalChangeTime".equals(field.getName()) - || "principalName".equals(field.getName()) - || "jobReceiver".equals(field.getName()) - || "jobReceiverTime".equals(field.getName()) - || "watchPrincipalEndTime".equals(field.getName()) - || "licenseTime".equals(field.getName()) - || "licensorName".equals(field.getName()) - || "signerDateTime".equals(field.getName()) - || "classGroupName".equals(field.getName()) - || "code".equals(field.getName()) - || "signerName".equals(field.getName()) - || "watchPrincipalName".equals(field.getName())) - { - result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0 ")); - - } else if ( - "groundNum".equals(field.getName()) || - "dismantleNum".equals(field.getName()) || - "retainNum".equals(field.getName()) - - ) { - result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0 ")); - } else { + // if ("initialPrincipalName".equals(field.getName()) + // || "principalChangeTime".equals(field.getName()) + // || "principalName".equals(field.getName()) + // || "jobReceiver".equals(field.getName()) + // || "jobReceiverTime".equals(field.getName()) + // || "watchPrincipalEndTime".equals(field.getName()) + // || "licenseTime".equals(field.getName()) + // || "licensorName".equals(field.getName()) + // || "signerDateTime".equals(field.getName()) + // || "classGroupName".equals(field.getName()) + // || "code".equals(field.getName()) + // || "signerName".equals(field.getName()) + // || "watchPrincipalName".equals(field.getName()) + // || "projectName".equals(field.getName())) + // { + // result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0 ")); + // + // } else if ( + // "groundNum".equals(field.getName()) || + // "dismantleNum".equals(field.getName()) || + // "retainNum".equals(field.getName()) + // + // ) { + // result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0 ")); + // } else { //如果导出word为null会出现{{ ,value设置"\u00A0" - result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0")); - } + result.put(field.getName(), Optional.ofNullable(value).orElse("")); + //} } diff --git a/hzims-service/ticket/src/main/resources/template/secondary/工作票危险点分析及控制措施票.docx b/hzims-service/ticket/src/main/resources/template/secondary/工作票危险点分析及控制措施票.docx index 46cec0f..591306f 100644 Binary files a/hzims-service/ticket/src/main/resources/template/secondary/工作票危险点分析及控制措施票.docx and b/hzims-service/ticket/src/main/resources/template/secondary/工作票危险点分析及控制措施票.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx b/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx new file mode 100644 index 0000000..e43e2d5 Binary files /dev/null and b/hzims-service/ticket/src/main/resources/template/水力机械工作票模版.docx differ diff --git a/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版.docx b/hzims-service/ticket/src/main/resources/template/电气第一种工作票模版.docx index 76478f2..f2760d0 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/电气第二种工作票模版.docx b/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx new file mode 100644 index 0000000..702f915 Binary files /dev/null and b/hzims-service/ticket/src/main/resources/template/电气第二种工作票模版.docx differ