From c11ca291a56d8affe36bb76ced0e77e5809a54a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Wed, 24 May 2023 18:17:54 +0800 Subject: [PATCH] =?UTF-8?q?poi=20=E5=AF=BC=E5=87=BAword=E5=90=88=E5=B9=B6?= =?UTF-8?q?=20,=E6=96=B0=E5=A2=9E=E5=B7=A5=E4=BD=9C=E7=A5=A8=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/ticket/constants/TicketConstants.java | 1 + .../workTicket/entity/WorkTicketInfoEntity.java | 50 ++++- .../ticket/response/ProcessWorkFlowResponse.java | 5 + .../controller/TicketProcessController.java | 18 +- .../ticket/twoTicket/entity/WorkTicketFinish.java | 32 ++- .../twoTicket/service/TicketProcessService.java | 10 + .../service/impl/TicketProcessServiceImpl.java | 226 +++++++++++++++++++-- .../ticket/twoTicket/vo/process/WorkTicketVo.java | 5 + .../com/hnac/hzims/ticket/utils/MergeDocUtils.java | 172 ++++++++++++++++ .../ticket/workTicket/dto/WorkTicketInfoDto.java | 4 + .../service/impl/WorkTicketInfoServiceImpl.java | 62 +++++- 11 files changed, 546 insertions(+), 39 deletions(-) create mode 100644 hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/MergeDocUtils.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 928605a..de3b0bd 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 @@ -102,6 +102,7 @@ public interface TicketConstants { MECHANICAL_WORK("8","大隆水电站水力机械工作票模板"), EMERGENCY_REPAIR("9","大隆水电站事故应急抢修单模板"), NEW_FIRST_WORK("10","新电气第一种工作票模板"), + NEW_FIRST_WORK1("11","第一种工作票"), ; @Getter private String type; 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 82f0992..b0f4153 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 @@ -403,14 +403,14 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { * 下一个审批人 */ @ApiModelProperty("下一个审批人") - private Long nextStepOperator; + private String nextStepOperator; /** * 当前审批人 */ @ApiModelProperty("当前审批人") - private Long stepOperator; + private String stepOperator; /** @@ -427,4 +427,50 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { private String flowTaskId; + /** + * 项目名称 + */ + @ApiModelProperty("项目名称") + private String projectName; + + + /** + * 工作接收人 + */ + @ApiModelProperty("工作接收人") + private String jobReceiver; + + + + /** + * 工作接收人时间 + */ + @ApiModelProperty("工作接收人时间") + private String jobReceiverDateTime; + + + /** + * 安全隔离措施附页 (true,展示附件,false,不展示附件) + */ + @ApiModelProperty("安全隔离措施附页 (true,展示附件,false,不展示附件)") + private Boolean isSafety; + + /** + * 危险点分析与预控措施票 (true,展示附件,false,不展示附件) + */ + @ApiModelProperty("危险点分析与预控措施票 (true,展示附件,false,不展示附件)") + private Boolean isHazard; + + /** + * 动火工作票 (true,展示附件,false,不展示附件) + */ + @ApiModelProperty("动火工作票 (true,展示附件,false,不展示附件)") + private Boolean isRailway; + /** + *有限空间监测记录单(true,展示附件,false,不展示附件) + */ + @ApiModelProperty("有限空间监测记录单 (true,展示附件,false,不展示附件)") + private Boolean isLimited; + + } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/response/ProcessWorkFlowResponse.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/response/ProcessWorkFlowResponse.java index be96d3c..2071db4 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/response/ProcessWorkFlowResponse.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/response/ProcessWorkFlowResponse.java @@ -50,4 +50,9 @@ public class ProcessWorkFlowResponse implements Serializable { /**票据表单**/ private Object variables; + /** + * 根据handleType区分是用户还是候选组角色 标识 0是用户 1是角色 + */ + private String handleType; + } 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 b84c076..719404b 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 @@ -16,12 +16,15 @@ import org.springblade.flow.core.vo.ComleteTask; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 工作票 + * * @Author WL * @Version v1.0 * @Serial 1.0 @@ -35,11 +38,12 @@ import java.util.Map; public class TicketProcessController { - private final TicketProcessService ticketProcessService; + private final TicketProcessService ticketProcessService; /** * 启动流程 + * * @return */ @ApiOperation("启动流程") @@ -52,6 +56,7 @@ public class TicketProcessController { /** * 预览 + * * @param ticketType * @param ticketId */ @@ -64,4 +69,15 @@ public class TicketProcessController { } + /** + * 预览 + */ + @GetMapping("/newPreview") + @ApiOperation(value = "新预览") + @ApiOperationSupport(order = 11) + public void preview(@RequestParam(value = "ticketId", required = true) Long ticketId, + HttpServletResponse response) { + ticketProcessService.newPreview(ticketId, response); + } + } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/entity/WorkTicketFinish.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/entity/WorkTicketFinish.java index 46c86ed..145b692 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/entity/WorkTicketFinish.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/entity/WorkTicketFinish.java @@ -26,7 +26,7 @@ import java.time.LocalDateTime; @TableName("hzims_work_ticket_finish") public class WorkTicketFinish implements Serializable { - private static final long serialVersionUID=1L; + private static final long serialVersionUID = 1L; /** * 编号 @@ -99,7 +99,6 @@ public class WorkTicketFinish implements Serializable { private Long principal; - /** * 许可人 */ @@ -108,7 +107,6 @@ public class WorkTicketFinish implements Serializable { private Long licensor; - /** * 负责人工作结束时间 */ @@ -126,8 +124,7 @@ public class WorkTicketFinish implements Serializable { /** * 结束时间 */ - private LocalDateTime workEndTime; - + private LocalDateTime workEndTime; /** @@ -140,7 +137,30 @@ public class WorkTicketFinish implements Serializable { * 交底内容 */ @ApiModelProperty("交底内容") - private String tellContent; + private String tellContent; + + + /** + * 刀闸编号 + */ + private String brakeNumber; + + + /** + * 监护人 + */ + private Long guardian; + + /** + * 监护人地点 + */ + private String guardianPlace; + + + /** + * 其他事项 + */ + private String otherItems; } 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 23920a2..6429eda 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 @@ -3,6 +3,8 @@ package com.hnac.hzims.ticket.twoTicket.service; import com.hnac.hzims.ticket.response.ProcessWorkFlowResponse; import com.hnac.hzims.ticket.twoTicket.vo.process.WorkTicketVo; +import javax.servlet.http.HttpServletResponse; + /** * 开票处理流程接口 * @Author dfy @@ -31,4 +33,12 @@ public interface TicketProcessService { * @param ticketId */ String preview(String ticketType, Long ticketId); + + + /** + * 新预览 + * @param response + * @return + */ + void newPreview(Long ticketId, 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 af14806..f34a2f0 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 @@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient; @@ -26,16 +28,20 @@ import com.hnac.hzims.ticket.twoTicket.service.IWorkTicketFinishService; import com.hnac.hzims.ticket.twoTicket.service.TicketProcessService; 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; import com.hnac.hzims.ticket.utils.PdfUtils; import com.hnac.hzims.ticket.workTicket.entity.*; import com.hnac.hzims.ticket.workTicket.service.*; import com.hnac.hzims.ticket.workTicket.service.impl.WorkTicketDelayServiceImpl; import com.hnac.hzims.ticket.workTicket.service.impl.WorkTicketOperateTimeServiceImpl; +import io.swagger.annotations.ApiModelProperty; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; @@ -51,6 +57,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.time.LocalDateTime; import java.util.*; @@ -100,7 +110,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { private final IAccessTaskClient accessTaskClient; - private String newFirstWorkTicketFlowKey = "workTicket"; + private String newFirstWorkTicketFlowKey = "workTicketFlow"; private final IStationClient stationClient; @@ -193,6 +203,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { log.info("获取taskId: {}", response.getTaskId()); log.info("获取下一个审批人是: {}", response.getNextStepOperator()); log.info("获取当前任务名称是: {}", response.getTaskName()); + log.info("获取根据handleType区分是用户还是候选组角色: {}", response.getHandleType()); //json转换表单 String formData = JSON.toJSONString(response.getVariables()); log.info("获取表单的数据:{}", formData); @@ -342,16 +353,20 @@ public class TicketProcessServiceImpl implements TicketProcessService { String description = getWorkTicketDescription(flowStatus); String flowDescription = ""; //当前审批人 - User user = UserCache.getUser(workTicket.getStepOperator()); + String stepOperator = workTicket.getStepOperator(); - if (StringUtils.isNotEmpty(nextStepOperator)) { + if ("0".equals(response.getHandleType())) { Long taskUser = NumberUtils.createLong(nextStepOperator.startsWith("taskUser_") ? nextStepOperator.substring(9) : null); //下一个审批人 User stepUser = UserCache.getUser(taskUser); - flowDescription = "审批中,当前环节是".concat(description).concat(",当前审批人是").concat(user.getName()).concat(",下一个审批人是").concat(stepUser.getName()).concat("待审批"); - workTicket.setNextStepOperator(taskUser); - } else { - flowDescription = "审批中,当前环节是".concat(description).concat(",审批人是").concat(user.getName()); + flowDescription = + "审批中,当前环节是".concat(description).concat(",待").concat(stepUser.getName()).concat("审批"); + workTicket.setNextStepOperator(stepUser.getName()); + } + + if ("1".equals(response.getHandleType())) { + System.out.println("获取角色信息" + response.getNextStepOperator()); + flowDescription = "审批中,当前环节是".concat(description).concat(",当前操作人是").concat(stepOperator); } //如果taskId为空 或 flowStatus = 99 if (StringUtils.isEmpty(taskId) || 99 == flowStatus) { @@ -359,8 +374,8 @@ public class TicketProcessServiceImpl implements TicketProcessService { workTicket.setFlowDescription(flowDescription); workTicket.setFlowTaskId(""); workTicket.setFlowTaskName("结束"); - workTicket.setNextStepOperator(-1L); - workTicket.setStepOperator(-1L); + workTicket.setNextStepOperator(null); + workTicket.setStepOperator(null); } else { workTicket.setFlowDescription(flowDescription); workTicket.setFlowTaskId(taskId); @@ -368,7 +383,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { } //如果下一个审批人【nextStepOperator】是null设为-1 if (StringUtils.isEmpty(nextStepOperator)) { - workTicket.setNextStepOperator(-1L); + workTicket.setNextStepOperator(null); } } @@ -424,7 +439,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { * * @param workTicketVo */ - private void returnTicket(WorkTicketVo workTicketVo) { + public void returnTicket(WorkTicketVo workTicketVo) { WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); if (TicketConstants.TaskTypeEnum.JXRW.getType().equals(workTicket.getTaskType())) { OperAccessTaskEntity taskEntity = new OperAccessTaskEntity(); @@ -451,7 +466,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { * @param newFirstWorkTicketFlowKey * @param workTicketVo */ - private void dealProcess(String newFirstWorkTicketFlowKey, WorkTicketVo workTicketVo) { + public void dealProcess(String newFirstWorkTicketFlowKey, WorkTicketVo workTicketVo) { //若为线下工作票 则无需开启工作流 Integer status = WorkTicketConstants.FirstWorkTicketStatusEnum.SIGN.getStatus(); if (status.intValue() != workTicketVo.getWorkTicket().getFlowStatus().intValue()) { @@ -465,7 +480,6 @@ public class TicketProcessServiceImpl implements TicketProcessService { if (!listR.isSuccess() || CollectionUtil.isEmpty(listR.getData())) { throw new ServiceException("工作票签发人角色下未查询到相关人员"); } - log.info("获取签发人角色下的人员: {}", listR.getData()); Map params = new HashMap<>(4); params.put("workTicketVo", workTicketVo); @@ -473,7 +487,10 @@ public class TicketProcessServiceImpl implements TicketProcessService { workTicketVo.setIsState(true); log.info("获取表单的数据: {}", workTicketVo); R processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(newFirstWorkTicketFlowKey, String.valueOf(workTicketVo.getWorkTicket().getId()), workTicketVo.getWorkTicket().getWorkContent(), params); - if (!processInstanceContainNameByKey.isSuccess() && processInstanceContainNameByKey.getData() == null) { + log.info("processInstanceContainNameByKey.isSuccess() : {}", processInstanceContainNameByKey.isSuccess()); + log.info("processInstanceContainNameByKey.getData() : {}", processInstanceContainNameByKey.getData()); + log.info("BladeFlow processInstanceContainNameByKey:{}", processInstanceContainNameByKey); + if (!processInstanceContainNameByKey.isSuccess() && processInstanceContainNameByKey.getCode() == 500) { throw new ServiceException("启动流程失败..."); } } @@ -485,7 +502,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { * @param workTicketContentDtoList * @param workTicketInfoEntity */ - private void saveWorkTicketContentDto(List workTicketContentDtoList, WorkTicketInfoEntity workTicketInfoEntity) { + public void saveWorkTicketContentDto(List workTicketContentDtoList, WorkTicketInfoEntity workTicketInfoEntity) { if (CollectionUtils.isEmpty(workTicketContentDtoList)) { return; } @@ -508,7 +525,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { * @param safetyMeasuresList * @param workTicketInfoEntity */ - private void saveSafetyMeasures(List safetyMeasuresList, WorkTicketInfoEntity workTicketInfoEntity) { + public void saveSafetyMeasures(List safetyMeasuresList, WorkTicketInfoEntity workTicketInfoEntity) { if (CollectionUtil.isEmpty(safetyMeasuresList)) { return; } @@ -533,7 +550,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { * @param workTicket * @return */ - private WorkTicketInfoEntity saveWorkTicketInfo(WorkTicketInfoEntity workTicket) { + public WorkTicketInfoEntity saveWorkTicketInfo(WorkTicketInfoEntity workTicket) { workTicket.setStatus(Func.isEmpty(workTicket.getPrincipal()) || Func.isEmpty(workTicket.getClassGroupMembers()) ? WorkTicketConstants.FirstWorkTicketStatusEnum.OFFLINE_OPERATE.getStatus() : WorkTicketConstants.FirstWorkTicketStatusEnum.SIGN.getStatus()); //班组成员名称 String byclassGroupMembers = getByClassGroupMembers(workTicket); @@ -542,7 +559,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { String principalName = getByPrincipal(workTicket); workTicket.setPrincipalName(principalName); workTicket.setFlowStatus(1); - workTicket.setStepOperator(AuthUtil.getUserId()); + workTicket.setStepOperator(UserCache.getUser(AuthUtil.getUserId()).getName()); //唯一 workTicket.setCreateUser(AuthUtil.getUserId()); boolean isSave = firstWorkTicketService.save(workTicket); @@ -631,15 +648,120 @@ public class TicketProcessServiceImpl implements TicketProcessService { } + /** + * 新预览 + * + * @param ticketId + * @param response + * @return + */ + @SneakyThrows + @Override + public void newPreview(Long ticketId, HttpServletResponse response) { + String fileName = IdWorker.get32UUID() + ".docx"; + // response.setContentType("application/octet-stream;charset=ISO8859-1"); + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + response.setContentType("application/vnd.ms-excel;charset=utf-8"); + // response.addHeader("Pargam", "no-cache"); + // response.addHeader("Cache-Control", "no-cache"); + WorkTicketVo workTicketVo = ticketInfoService.selectDetailsById(ticketId); + log.info("新工作票 {}", workTicketVo); + //将查询的数据转换为map + Map workTicketInfoMap = this.convertMap(workTicketVo); + //创建新的map + Map objectObjectHashMap = new HashMap<>(); + for (Map.Entry stringObjectEntry : workTicketInfoMap.entrySet()) { + System.out.println("获取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); + return; + } + + //如果4个多为false 或为空 附件不展示附件 + if (!workTicket.getIsSafety() && !workTicket.getIsHazard() && !workTicket.getIsLimited() && !workTicket.getIsRailway()) { + extractedWithWord(response, workTicketInfoMap); + return; + } + List docFileList = new ArrayList<>(); + docFileList.add(new File("template/电气第一种工作票模版.docx")); + //安全隔离措施附页 (true,展示附件,false,不展示附件) + if (workTicket.getIsSafety()) { + setWorkTicketPrincipalChange(docFileList); + } + //危险点分析与预控措施票 (true,展示附件,false,不展示附件) + if (workTicket.getIsSafety()) { + setWorkTicketHazardPointChange(docFileList); + } + //动火工作票 (true,展示附件,false,不展示附件) + if (workTicket.getIsRailway()) { + setWorkTicketRailwayChange(docFileList); + } + //有限空间监测记录单(true,展示附件,false,不展示附件) + if (workTicket.getIsLimited()) { + setWorkTicketLimitedChange(docFileList); + } + MergeDocUtils.mergeDoc(docFileList, response); + } + + + /** + * 预览 + * + * @param response + * @param workTicketInfoMap + * @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"); + //Windows操作系统 + if (os != null && os.toLowerCase().startsWith("windows")) { + log.info("当前系统版本是:{}", os); + String name = "D:/导出excel/电气第一种工作票模版.docx"; + FileOutputStream fos = new FileOutputStream(name); + doc.write(fos); + } else { + //其它操作系统 + log.info("当前系统版本是:{}", os); + ServletOutputStream outputStream = response.getOutputStream(); + doc.write(outputStream); + } + } + //封装map 转换 excel导出 private Map convertMap(WorkTicketVo workTicketVo) { Map result = new HashMap<>(); WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); + + Map map1 = JSONObject.parseObject(JSONObject.toJSONString(workTicket), Map.class); + for (Map.Entry stringObjectEntry : map1.entrySet()) { + System.out.println("stringObjectEntry : " + stringObjectEntry.getKey() + "=====>" + stringObjectEntry.getValue()); + } + + //1. 工作对象 + // log.info("工作对象: {}", workTicket); + Map workTicketInfoMap = PdfUtils.objectToMap(workTicket, true); + //安全隔离措施附页 (true,展示附件,false,不展示附件 + getDataConversion(workTicketInfoMap, "isSafety", workTicketInfoMap.get("isSafety")); + //危险点分析与预控措施票 (true,展示附件,false,不展示附件) + getDataConversion(workTicketInfoMap, "isHazard", workTicketInfoMap.get("isHazard")); + //危险点分析与预控措施票 (true,展示附件,false,不展示附件) + getDataConversion(workTicketInfoMap, "isRailway", workTicketInfoMap.get("isRailway")); + //有限空间监测记录单(true,展示附件,false,不展示附件) + getDataConversion(workTicketInfoMap, "isLimited", workTicketInfoMap.get("isLimited")); + + + result.putAll(workTicketInfoMap); //2. 安全措施 List safetyMeasuresList = workTicketVo.getSafetyMeasuresList(); + log.info("安全措施: {}", safetyMeasuresList); if (CollectionUtils.isNotEmpty(safetyMeasuresList)) { Map> measureMap = safetyMeasuresList.stream().collect(Collectors.groupingBy(WorkTicketSafetyMeasureEntity::getType)); Arrays.stream(WorkTicketConstants.WorkTicketMeasureTypeEnum.class.getEnumConstants()).forEach(measureEnum -> { @@ -654,10 +776,11 @@ public class TicketProcessServiceImpl implements TicketProcessService { 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()) ? "√" : "×"; + String status = TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus().equals(measureVO.getStatus()) ? "√" : ""; map.put("status", status); mapList.add(map); index++; @@ -668,8 +791,14 @@ public class TicketProcessServiceImpl implements TicketProcessService { workTicketInfoMap.put(measureEnum.getConvertAttributes(), new ArrayList>(1)); } }); + result.putAll(workTicketInfoMap); + } else { + result.put("matterLibraryListOne", new ArrayList<>()); + result.put("matterLibraryListTwo", new ArrayList<>()); + result.put("matterLibraryListThree", new ArrayList<>()); + result.put("matterLibraryListFour", new ArrayList<>()); } - result.putAll(workTicketInfoMap); + //3. 工作票工作任务组 List workTicketContentDtoList = workTicketVo.getWorkTicketContentDtoList(); if (CollectionUtils.isNotEmpty(workTicketContentDtoList)) { @@ -678,6 +807,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { //4. 工作票延期 WorkTicketDelayEntity workTicketDelay = workTicketVo.getWorkTicketDelay(); + log.info("工作票延期: {}", workTicketDelay); if (ObjectUtils.isNotEmpty(workTicketDelay)) { result.putAll(PdfUtils.objectToMap(workTicketDelay, true)); } else { @@ -686,6 +816,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { //5. 工作结束 WorkTicketFinish workTicketFinish = workTicketVo.getWorkTicketFinish(); + log.info("工作结束: {}", workTicketFinish); if (ObjectUtils.isNotEmpty(workTicketFinish)) { result.putAll(PdfUtils.objectToMap(workTicketFinish, true)); } else { @@ -710,6 +841,61 @@ public class TicketProcessServiceImpl implements TicketProcessService { return JSONObject.parseObject(JSONObject.toJSONString(target), Map.class); } + + /** + * 安全隔离措施附页 + */ + @SneakyThrows + public void setWorkTicketPrincipalChange(List docFileList) { + docFileList.add(new File("template/secondary/工作票安全措施附页.docx")); + } + + + /** + * 危险点分析与预控措施票 + */ + @SneakyThrows + public void setWorkTicketHazardPointChange(List docFileList) { + docFileList.add(new File("template/secondary/工作票危险点分析及控制措施票.docx")); + } + + + /** + * 动火工作票 + */ + @SneakyThrows + public void setWorkTicketRailwayChange(List docFileList) { + File file = new File("template/secondary/动火工作票.docx"); + docFileList.add(file); + + } + + + /** + * 有限空间监测记录单(true,展示附件,false,不展示附件) + */ + @SneakyThrows + public void setWorkTicketLimitedChange(List docFileList) { + File file = new File("template/secondary/有限空间监测记录单.docx"); + docFileList.add(file); + } + + + /** + * value true转 ☑ 或 false转 □ + * + * @param dataConversion + * @param key + * @param value + */ + public void getDataConversion(Map dataConversion, String key, Object value) { + String newValue = value == null ? (String) value : value.toString(); + if (StringUtils.isNoneBlank(newValue)) { + dataConversion.put(key, BooleanUtils.toBoolean(newValue) ? "☑" : "□"); + } + } + + } 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 378d8ad..45daa09 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 @@ -74,4 +74,9 @@ public class WorkTicketVo { private Boolean isState = true; + + + private String ticketType; + + } 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 new file mode 100644 index 0000000..209f4fb --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/MergeDocUtils.java @@ -0,0 +1,172 @@ +package com.hnac.hzims.ticket.utils; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/5/23 16:42 + */ +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.xwpf.usermodel.BreakType; +import org.apache.poi.xwpf.usermodel.Document; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFPictureData; +import org.apache.xmlbeans.XmlOptions; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody; + +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.time.LocalDate; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +/** + * 参数1:需要合并的word的文件对象list + * 参数2:合并之后word存储的全路径file对象 + */ +public class MergeDocUtils { + + + /** + * word文档合并 + * @param fileList 合并文档的路径 + * @param response 新的word + * @throws Exception + */ + public static void mergeDoc(List fileList, HttpServletResponse response)throws Exception { + + OutputStream dest = response.getOutputStream(); + ArrayList documentList = new ArrayList(); + XWPFDocument doc = null; + for (int i = 0; i < fileList.size(); i++) { + FileInputStream in = new FileInputStream(fileList.get(i).getPath()); + OPCPackage open = OPCPackage.open(in); + XWPFDocument document = new XWPFDocument(open); + documentList.add(document); + } + + + + for (int i = 0; i < documentList.size(); i++) { + doc = documentList.get(0); + if (i != 0) { + //documentList.get(i).createParagraph().setPageBreak(true);//实现了分页效果。//但是会出现在首行为空的情况 + documentList.get(i).createParagraph().createRun().addBreak(BreakType.PAGE);//现了分页效果。使用这种方式不会出现留白的情况 + appendBody(doc, documentList.get(i)); + } + } + doc.write(dest);//输出合并之后的文件 + } + + + /** + * 图片文件追加 + * @param src + * @param append + * @throws Exception + */ + public static void appendBody(XWPFDocument src, XWPFDocument append) throws Exception { + CTBody src1Body = src.getDocument().getBody(); + CTBody src2Body = append.getDocument().getBody(); + + List allPictures = append.getAllPictures(); + // 记录图片合并前及合并后的ID + Map map = new HashMap(); + for (XWPFPictureData picture : allPictures) { + String before = append.getRelationId(picture); + //将原文档中的图片加入到目标文档中 + String after = src.addPictureData(picture.getData(), Document.PICTURE_TYPE_PNG); + map.put(before, after); + } + + appendBody(src1Body, src2Body, map); + + } + + private static void appendBody(CTBody src, CTBody append, Map map) throws Exception { + XmlOptions optionsOuter = new XmlOptions(); + optionsOuter.setSaveOuter(); + String appendString = append.xmlText(optionsOuter); + + //去掉追加word内容中的 w:sectPr 标签,确保合成的word中只有一个 w:sectPr 标签对 + //避免合成的word文档打开之后会提示有些内容读不出来,导致文件损坏 + String rgex = "<[\\s]*?w:sectPr[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?w:sectPr[\\s]*?>"; + appendString = appendString.replaceAll(rgex, ""); + + String srcString = src.xmlText(); + String regex = regex(srcString, "w:sectPr"); + // System.out.println(regex); + + String prefix = srcString.substring(0, srcString.indexOf(">") + 1); + String mainPart = srcString.substring(srcString.indexOf(">") + 1, srcString.lastIndexOf("<")); + String sufix = srcString.substring(srcString.lastIndexOf("<")); + String addPart = appendString.substring(appendString.indexOf(">") + 1, appendString.lastIndexOf("<")); + + if (map != null && !map.isEmpty()) { + //对xml字符串中图片ID进行替换 + for (Map.Entry set : map.entrySet()) { + addPart = addPart.replace(set.getKey(), set.getValue()); + } + } + //将两个文档的xml内容进行拼接 + CTBody makeBody = CTBody.Factory.parse(prefix + mainPart + addPart + sufix); + + src.set(makeBody); + } + + /** + * 获取指定标签中的内容 + * + * @param xml + * @param label + * @return + */ + public static String regex(String xml, String label) { + String context = ""; + // 正则表达式 + String rgex = "<" + label + "[^>]*>((?:(?!<\\/" + label + ">)[\\s\\S])*)<\\/" + label + ">"; + Pattern pattern = Pattern.compile(rgex);// 匹配的模式 + Matcher m = pattern.matcher(xml); + // 匹配的有多个 + List list = new ArrayList(); + while (m.find()) { + int i = 1; + list.add(m.group(i)); + i++; + } + if (list.size() > 0) { + // 输出内容自己定义 + context = String.valueOf(list.size()); + } + return context; + } + + + // public static void main(String[] args) throws Exception { + // //new一个list 模拟要合并的word对象集合 + // ListdocFileList = 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\\动火工作票.docx")); + // + // //合并之后doc存储路径 此处读的配置文件的存储路径 D:/pdfData/ + // String docPath = "D:\\导出excel\\"; + // //当前日期+UUID作为文件名防止重复 + // String fileName = LocalDate.now() + "-" + UUID.randomUUID().toString().replaceAll("-", ""); + // //合并之后doc存储路径 + // String mergeDocUrl = docPath+fileName+".docx"; + // //转成file对象 + // File mergeDocFile = new File(mergeDocUrl); + // + // //合并doc + // MergeDocUtils.mergeDoc(docFileList,mergeDocFile); + // + // System.out.println("合并word成功"); + // + // } +} + diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/dto/WorkTicketInfoDto.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/dto/WorkTicketInfoDto.java index cb7f418..cefe915 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/dto/WorkTicketInfoDto.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/dto/WorkTicketInfoDto.java @@ -60,4 +60,8 @@ public class WorkTicketInfoDto extends WorkTicketInfoEntity implements Serializa @ApiModelProperty("机构编号集合") private List deptIds; + + @ApiModelProperty("创建人") + private String createUserName; + } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java index 31607c8..c0e3ad5 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java @@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.collect.Lists; +import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.operational.access.constants.AccessConstants; import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient; @@ -237,14 +238,24 @@ public class WorkTicketInfoServiceImpl extends BaseServiceImpl> queryList(WorkTicketInfoDto req, Query query) { LambdaQueryWrapper lqw = this.getQueryWrapper(req); - if(ObjectUtil.isNotEmpty(req.getCreateDept())) { - lqw.eq(WorkTicketInfoEntity::getCreateDept,req.getCreateDept()); + if (ObjectUtil.isNotEmpty(req.getCreateDept())) { + lqw.eq(WorkTicketInfoEntity::getCreateDept, req.getCreateDept()); } lqw.orderByDesc(WorkTicketInfoEntity::getCreateTime).orderByDesc(WorkTicketInfoEntity::getUpdateTime); - IPage pages = super.page(Condition.getPage(query), lqw); - pages.setRecords(WorkTicketInfoWrapper.build().listVO(pages.getRecords())); - return R.data(pages); + IPage pages = this.page(Condition.getPage(query), lqw); + //数据转换 + IPage workTicketInfoVOIPage = new Page<>(pages.getCurrent(),pages.getSize()); + workTicketInfoVOIPage.setRecords(WorkTicketInfoWrapper.build().listVO(pages.getRecords())); + workTicketInfoVOIPage.setPages(pages.getPages()); + workTicketInfoVOIPage.setTotal(pages.getTotal()); + //获取创建人 + workTicketInfoVOIPage.getRecords().forEach(item -> { + item.setCreateUserName(UserCache.getUser(item.getCreateUser()).getName()); + }); + + + return R.data(workTicketInfoVOIPage); } @Override @@ -940,20 +951,51 @@ public class WorkTicketInfoServiceImpl extends BaseServiceImpl " + classGroupMembers); + String[] split = classGroupMembers.split(","); + StringBuilder sb = new StringBuilder(); + for (String classGroupMember : split) { + System.out.println(classGroupMember); + if (StringUtils.isNoneBlank(classGroupMember)) { + boolean matches = classGroupMember.matches("[0-9]+"); + if (matches) { + String name = UserCache.getUser(Long.valueOf(classGroupMember)).getName(); + // System.out.println("获取用户信息 ==> " + name); + sb.append(name).append(","); + } + } + } + + //成员信息 + if (workTicketInfo.getClassGroupMembersName() == null) { + workTicketInfo.setClassGroupMembersName(sb.toString().endsWith(",") ? + sb.toString().substring(0,sb.length() - 1) : sb.toString()); + } + //统计人数 + if (workTicketInfo.getTotalPerson() == null) { + workTicketInfo.setTotalPerson(split.length); + } + //负责人名称 + if (workTicketInfo.getPrincipalName() == null && workTicketInfo.getPrincipal() != null) { + workTicketInfo.setPrincipalName(UserCache.getUser(workTicketInfo.getPrincipal()).getName()); + } + + workTicketVo.setWorkTicket(workTicketInfo); //2. 安全措施数组 @@ -995,13 +1037,13 @@ public class WorkTicketInfoServiceImpl extends BaseServiceImpl