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 c148b86..b602dc5 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 @@ -18,7 +18,8 @@ public interface WorkTicketConstants { /**第二种安措**/ TWO("2","matterLibraryListTwo"), /**第三种安措**/ - THREE("3","matterLibraryListThree") + THREE("3","matterLibraryListThree"), + FOUR("4","matterLibraryListFour") ; @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 ab112ed..82f0992 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 @@ -3,6 +3,7 @@ package com.hnac.hzims.ticket.workTicket.entity; import java.time.LocalDateTime; import java.io.Serializable; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -191,6 +192,11 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { private Long signer; + @TableField(exist = false) + @ApiModelProperty(value = "签发人名称") + private String signerName; + + /** * 签发人签发时间 */ @@ -229,6 +235,14 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { @JsonSerialize(nullsUsing = NullSerializer.class) private Long licensor; + + + @TableField(exist = false) + @ApiModelProperty(value = "许可人名称") + @JsonSerialize(nullsUsing = NullSerializer.class) + private String licensorName; + + /** * 许可时间 */ @@ -282,51 +296,21 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { /** - * 批准工作结束时间 + * 值班负责人名称 */ - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @ApiModelProperty("批准工作结束时间") - private LocalDateTime watchPrincipalEndTime; + @TableField(exist = false) + @ApiModelProperty("值班负责人名称") + private String watchPrincipalName; /** - * 开工时间 - */ - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @ApiModelProperty("开工时间") - private LocalDateTime startDateTime; - - - /** - * 收工时间 + * 批准工作结束时间 */ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @ApiModelProperty("收工时间") - private LocalDateTime endDateTime; - - - /** - * 工作票结束时间 - */ - @ApiModelProperty("工作票结束时间") - private LocalDateTime workTicketEndTime; - - - /** - * 备注 - */ - @ApiModelProperty("备注") - private String content; - + @ApiModelProperty("批准工作结束时间") + private LocalDateTime watchPrincipalEndTime; - /** - * 交底内容 - */ - @ApiModelProperty("交底内容") - private String tellContent; /** @@ -361,11 +345,11 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { * 编号(原站点ID) */ @ApiModelProperty("编号(原站点ID)") - private String signageCode; + private String signageCode; /** - * 开票时间 + * 开票时间 */ @ApiModelProperty("开票时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @@ -383,7 +367,7 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { */ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private LocalDateTime confirmDateTime; + private LocalDateTime confirmDateTime; /** @@ -398,24 +382,21 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { * 签发人签发是否通过 */ @ApiModelProperty("签发人签发是否通过") - private Boolean signFlag; - + private Boolean signFlag; /** * 运行人员是否通过 */ @ApiModelProperty("运行人员是否通过") - private Boolean recieveFlag; - - + private Boolean recieveFlag; /** * 工作确认是否通过 (input= 延期 input=转移 input 通过 ) */ @ApiModelProperty("input= 延期 input=转移 input 通过") - private String input; + private String input; /** @@ -439,8 +420,6 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { private String flowTaskName; - - /** * 当前任务名 */ @@ -448,5 +427,4 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable { private String flowTaskId; - } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketPrincipalChangeEntity.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketPrincipalChangeEntity.java index 2373dff..cf4f7c7 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketPrincipalChangeEntity.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketPrincipalChangeEntity.java @@ -3,6 +3,7 @@ package com.hnac.hzims.ticket.workTicket.entity; import java.time.LocalDateTime; import java.io.Serializable; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -43,9 +44,25 @@ public class WorkTicketPrincipalChangeEntity extends TenantEntity implements Ser @QueryField(condition = SqlCondition.EQUAL) private Long initialPrincipal; + + @TableField(exist = false) + @ApiModelProperty("原负责人名称") + private String initialPrincipalName; + @ApiModelProperty("变更负责人") @JsonSerialize(nullsUsing = NullSerializer.class) @QueryField(condition = SqlCondition.EQUAL) private Long changePrincipal; + + @TableField(exist = false) + @ApiModelProperty("变更负责人名称") + private String changePrincipalName; + + + + @ApiModelProperty("变动时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime principalChangeTime; } diff --git a/hzims-service/hzims-middle/src/main/resources/application.yml b/hzims-service/hzims-middle/src/main/resources/application.yml index f3bb7f5..180d5d3 100644 --- a/hzims-service/hzims-middle/src/main/resources/application.yml +++ b/hzims-service/hzims-middle/src/main/resources/application.yml @@ -2,6 +2,7 @@ server: port: 8400 + #数据源配置 spring: main: diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java index 71ba8b5..aaf8cc5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java @@ -10,7 +10,9 @@ import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; import com.hnac.hzims.operational.alert.mapper.HistoryAbnormalAlarmMapper; import com.hnac.hzims.operational.alert.service.AlarmHandleService; import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; -import com.hnac.hzims.operational.alert.vo.*; +import com.hnac.hzims.operational.alert.vo.AlarmDataVo; +import com.hnac.hzims.operational.alert.vo.AlarmParamVo; +import com.hnac.hzims.operational.alert.vo.AlarmReustVo; import com.hnac.hzims.operational.config.vo.AlarmDataPageVo; import com.hnac.hzims.operational.config.vo.AlarmVo; import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/properties/TicketProperties.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/properties/TicketProperties.java index 83ce875..ea0a088 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/properties/TicketProperties.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/properties/TicketProperties.java @@ -1,5 +1,6 @@ package com.hnac.hzims.ticket.processflow.properties; + import lombok.Data; import lombok.experimental.Accessors; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -18,7 +19,6 @@ import java.util.List; @Data @Accessors(chain = true) @Component -//@NacosPropertySource(dataId = "hzims-ticket-dev.yaml", autoRefreshed = true) @ConfigurationProperties(prefix = "ticket") @RefreshScope public class TicketProperties { 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 c929ed2..b84c076 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 @@ -58,8 +58,9 @@ public class TicketProcessController { @GetMapping("/preview") @ApiOperation(value = "预览") @ApiOperationSupport(order = 11) - public void preview(@RequestParam @ApiParam("票据类型") String ticketType, @RequestParam @ApiParam("票据ID") Long ticketId) { - ticketProcessService.preview(ticketType,ticketId); + public R preview(@RequestParam @ApiParam("票据类型") String ticketType, @RequestParam @ApiParam("票据ID") Long ticketId) { + String preview = ticketProcessService.preview(ticketType, ticketId); + return R.data(preview); } 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 c7554d3..23920a2 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,5 +30,5 @@ public interface TicketProcessService { * @param ticketType * @param ticketId */ - void preview(String ticketType, Long ticketId); + String preview(String ticketType, Long ticketId); } 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 c97b63a..af14806 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 @@ -1,8 +1,7 @@ package com.hnac.hzims.ticket.twoTicket.service.impl; -import cn.afterturn.easypoi.excel.ExcelExportUtil; -import cn.afterturn.easypoi.excel.entity.TemplateExportParams; +import cn.afterturn.easypoi.word.WordExportUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -36,7 +35,7 @@ import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.math.NumberUtils; -import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; @@ -123,11 +122,9 @@ public class TicketProcessServiceImpl implements TicketProcessService { private final IWorkTicketInfoService ticketInfoService; - @Value("${hzims.ticket.path.pdf.savePath}") - private String pdfSavePath; + @Value("${hzims.ticket.path.word.templatePath}") + private String templatePath; - @Value("${hzims.ticket.path.xlsx.savePath}") - private String xlsSavePath; /** * 启动开票流程 @@ -348,17 +345,13 @@ public class TicketProcessServiceImpl implements TicketProcessService { User user = UserCache.getUser(workTicket.getStepOperator()); if (StringUtils.isNotEmpty(nextStepOperator)) { - Long taskUser = NumberUtils.createLong(nextStepOperator.startsWith("taskUser_") ? - nextStepOperator.substring(9) : null); + 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("待审批"); + 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(user.getName()); } //如果taskId为空 或 flowStatus = 99 if (StringUtils.isEmpty(taskId) || 99 == flowStatus) { @@ -609,39 +602,32 @@ public class TicketProcessServiceImpl implements TicketProcessService { */ @SneakyThrows @Override - public void preview(String ticketType, Long ticketId) { + public String preview(String ticketType, Long ticketId) { WorkTicketVo workTicketVo = ticketInfoService.selectDetailsById(ticketId); //将查询的数据转换为map Map workTicketInfoMap = this.convertMap(workTicketVo); - workTicketInfoMap.put("name", 22); String fileName = TicketConstants.WordFileNameEnum.getFileNameByType(ticketType) + PdfUtils.XLSX_SUFFIX; log.info("工作票模板为:{}", fileName); - TemplateExportParams templateExportParams = new TemplateExportParams("template/新电气第一种工作票模板.xlsx", true); - Workbook workbook = null; - try { - workbook = ExcelExportUtil.exportExcel(templateExportParams, workTicketInfoMap); - } catch (Exception e) { - e.printStackTrace(); + XWPFDocument doc = WordExportUtil.exportWord07("template/电气第一种工作票模版.docx", workTicketInfoMap); + FileOutputStream fos = null; + String name = null; + String os = System.getProperty("os.name"); + //Windows操作系统 + if (os != null && os.toLowerCase().startsWith("windows")) { + log.info("当前系统版本是:{}", os); + name = "D:/导出excel/电气第一种工作票模版.docx"; + fos = new FileOutputStream(name); + } else { + //其它操作系统 + log.info("当前系统版本是:{}", os); + String prefix = IdWorker.get32UUID(); + name = templatePath + prefix + ".docx"; + fos = new FileOutputStream(name); } - FileOutputStream fos = new FileOutputStream("F:\\idea项目\\flowable\\demo\\src\\main\\resources\\新电气第一种工作票模板5" + - ".xlsx"); - workbook.write(fos); - // //上传xlsx至服务器 - // try { - // ExcelUtil.upload(workbook, xlsSavePath, workTicketVo.getWorkTicket().getWorkContent() + PdfUtils.XLSX_SUFFIX); - // } catch (Exception e) { - // e.printStackTrace(); - // } - // //将xlsx文件转换为pdf并保存 - // String pdfFileName = workTicketVo.getWorkTicket().getWorkContent() + PdfUtils.PDF_SUFFIX; - // String xlsFileName = workTicketVo.getWorkTicket().getWorkContent() + PdfUtils.XLSX_SUFFIX; - // PdfUtils.convertPdf(xlsSavePath, xlsFileName, pdfSavePath, pdfFileName); - // String savePath = pdfSavePath + pdfFileName; - // // 设置response参数,可以打开下载页面 - // ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - // HttpServletResponse response = servletRequestAttributes.getResponse(); - // PdfUtils.readPdf(response, savePath); + doc.write(fos); + fos.close(); + return name; } @@ -650,7 +636,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { Map result = new HashMap<>(); WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); //1. 工作对象 - Map workTicketInfoMap = PdfUtils.objectToMap(workTicket); + Map workTicketInfoMap = PdfUtils.objectToMap(workTicket, true); //2. 安全措施 List safetyMeasuresList = workTicketVo.getSafetyMeasuresList(); @@ -658,13 +644,25 @@ public class TicketProcessServiceImpl implements TicketProcessService { 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 = measureMap.get(measureEnum.getType()).stream().map(measureVO -> { - Map map = PdfUtils.objectToMap(measureVO); + + 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++; + } + 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()) ? TicketConstants.SafetyMeasureStatusEnum.FINISH.getDescribe() : " "; + String status = TicketConstants.SafetyMeasureStatusEnum.FINISH.getStatus().equals(measureVO.getStatus()) ? "√" : "×"; map.put("status", status); - return map; - }).collect(Collectors.toList()); + mapList.add(map); + index++; + } + workTicketInfoMap.put(measureEnum.getConvertAttributes(), mapList); } else { workTicketInfoMap.put(measureEnum.getConvertAttributes(), new ArrayList>(1)); @@ -681,21 +679,26 @@ public class TicketProcessServiceImpl implements TicketProcessService { //4. 工作票延期 WorkTicketDelayEntity workTicketDelay = workTicketVo.getWorkTicketDelay(); if (ObjectUtils.isNotEmpty(workTicketDelay)) { - result.putAll(PdfUtils.objectToMap(workTicketDelay)); + result.putAll(PdfUtils.objectToMap(workTicketDelay, true)); + } else { + result.putAll(PdfUtils.objectToMap(new WorkTicketDelayEntity(), true)); } //5. 工作结束 WorkTicketFinish workTicketFinish = workTicketVo.getWorkTicketFinish(); if (ObjectUtils.isNotEmpty(workTicketFinish)) { - result.putAll(PdfUtils.objectToMap(workTicketFinish)); + result.putAll(PdfUtils.objectToMap(workTicketFinish, true)); + } else { + result.putAll(PdfUtils.objectToMap(new WorkTicketFinish(), true)); } //5. 工作票负责人变更 WorkTicketPrincipalChangeEntity workTicketPrincipalChange = workTicketVo.getWorkTicketPrincipalChange(); if (ObjectUtils.isNotEmpty(workTicketPrincipalChange)) { - result.putAll(PdfUtils.objectToMap(workTicketPrincipalChange)); + result.putAll(PdfUtils.objectToMap(workTicketPrincipalChange, true)); + } else { + result.putAll(PdfUtils.objectToMap(new WorkTicketPrincipalChangeEntity(), true)); } - 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 33475ee..ef57581 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 @@ -32,187 +32,243 @@ import java.util.stream.Collectors; @Slf4j public class PdfUtils { - /**文件后缀名**/ - public static String DOC_SUFFIX = ".doc"; - public static String DOCX_SUFFIX = ".docx"; - public static String XLS_SUFFIX = ".xls"; - public static String XLSX_SUFFIX = ".xlsx"; - public static String PDF_SUFFIX = ".pdf"; - - /*** - * 各文件转换为pdf - * @param templatePath 待转换的文件路径 - * @param templateFileName 待转换的文件名 - * @param savePath 转换为pdf后的文件路径 - * @param saveFileName 转换为pdf后的文件名称 - * @return - */ - public static void convertPdf (String templatePath, String templateFileName, String savePath, String saveFileName) { - String templateFilePath = templatePath + templateFileName; - String saveFilePath = savePath + saveFileName; - log.info("转换前的文件为:{};转换后的路径为:{}",templateFilePath,saveFilePath); - File templateFile = new File(templateFilePath); - File saveFile = new File(saveFilePath); - //获取文件类型 - String fileType = templateFileName.substring(templateFileName.lastIndexOf("."),templateFileName.length()); - InputStream inputStream = null; - OutputStream outputStream = null; - try { - try { - inputStream = new FileInputStream(templateFile); - outputStream = new FileOutputStream(saveFile); - //document4j 转换 pdf linux环境下不支持 - if(DOCX_SUFFIX.equals(fileType)) { - IConverter converter = LocalConverter.builder().build(); - converter.convert(inputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute(); - converter.shutDown(); - }else if(DOC_SUFFIX.equals(fileType)){ - IConverter converter = LocalConverter.builder().build(); - converter.convert(inputStream).as(DocumentType.DOC).to(outputStream).as(DocumentType.PDF).execute(); - converter.shutDown(); - }else if(XLS_SUFFIX.equals(fileType)){ - IConverter converter = LocalConverter.builder().build(); - converter.convert(inputStream).as(DocumentType.XLS).to(outputStream).as(DocumentType.PDF).execute(); - converter.shutDown(); - }else if(XLSX_SUFFIX.equals(fileType)){ - //此方式行不通 - //converter.convert(inputStream).as(DocumentType.XLSX).to(outputStream).as(DocumentType.PDF).execute(); - Workbook wb = new Workbook(); - wb.loadFromFile(templateFilePath); - wb.saveToFile(saveFilePath,FileFormat.PDF); - } - } - catch (Exception e) { - log.error("转换失败,错误信息为:{}",e.getMessage()); - throw new ServiceException(e.getMessage()); - } - finally { - inputStream.close(); - outputStream.close(); - } - } - catch(IOException e) { - e.printStackTrace(); - } - } - - /** - * 对象转化为Map 并设置默认值 - * @param obj - * @return - * @throws Exception - */ - public static Map objectToMap(Object obj) { - Map result = new HashMap<>(); - if(ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { - Class clazz = obj.getClass(); - List fieldList = new ArrayList<>(); - while(clazz != null) { - fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); - clazz = clazz.getSuperclass(); - } - fieldList.forEach(field -> { - field.setAccessible(true); - DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); - Object value; - try { - value = field.get(obj); - } catch (IllegalAccessException e) { - throw new ServiceException("获取属性性出错"); - } - //若为list则不处理 - if(value instanceof List){ - return ; - } - //若为时间格式则进行格式化 - if(value instanceof LocalDateTime){ - value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); - } - if(value instanceof Date){ - value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); - } - - if ((ObjectUtils.isEmpty(value) || value == "") && StringUtil.isNoneBlank(field.getName())){ - return; - } - - //属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值 - if(ObjectUtil.isNotEmpty(defaultValue)){ - result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), - ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); - } - else { - result.put(field.getName(), Optional.ofNullable(value).orElse("")); - } - }); - } - return result; - } - - /** - * 读取本地pdf,这里设置的是预览 - */ - public static void readPdf(HttpServletResponse response, String filePath) { - response.reset(); - response.setContentType("application/pdf"); - FileInputStream fileInputStream = null; - OutputStream outputStream = null; - try { - File file = new File(filePath); - fileInputStream = new FileInputStream(file); - outputStream = response.getOutputStream(); - IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); - response.setHeader("Content-Disposition", - "inline; filename= " + URLEncoder.encode( file.getName() , "UTF-8")); - outputStream.flush(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - finally { - try{ - fileInputStream.close(); - outputStream.close(); - - } - catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * 读取本地pdf,这里设置的是导出 - */ - public static void exportPdf(HttpServletResponse response, String filePath) { - response.reset(); - response.setContentType("application/pdf"); - FileInputStream fileInputStream = null; - OutputStream outputStream = null; - try { - File file = new File(filePath); - fileInputStream = new FileInputStream(file); - outputStream = response.getOutputStream(); - IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); - response.setHeader("Content-Disposition", "inline; filename= " + URLEncoder.encode( file.getName() , "UTF-8")); - outputStream.flush(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - finally { - try{ - fileInputStream.close(); - outputStream.close(); - - } - catch (IOException e) { - e.printStackTrace(); - } - } - } + /** 文件后缀名 **/ + public static String DOC_SUFFIX = ".doc"; + public static String DOCX_SUFFIX = ".docx"; + public static String XLS_SUFFIX = ".xls"; + public static String XLSX_SUFFIX = ".xlsx"; + public static String PDF_SUFFIX = ".pdf"; + + /*** + * 各文件转换为pdf + * @param templatePath 待转换的文件路径 + * @param templateFileName 待转换的文件名 + * @param savePath 转换为pdf后的文件路径 + * @param saveFileName 转换为pdf后的文件名称 + * @return + */ + public static void convertPdf(String templatePath, String templateFileName, String savePath, String saveFileName) { + String templateFilePath = templatePath + templateFileName; + String saveFilePath = savePath + saveFileName; + log.info("转换前的文件为:{};转换后的路径为:{}", templateFilePath, saveFilePath); + File templateFile = new File(templateFilePath); + File saveFile = new File(saveFilePath); + //获取文件类型 + String fileType = templateFileName.substring(templateFileName.lastIndexOf("."), templateFileName.length()); + InputStream inputStream = null; + OutputStream outputStream = null; + try { + try { + inputStream = new FileInputStream(templateFile); + outputStream = new FileOutputStream(saveFile); + //document4j 转换 pdf linux环境下不支持 + if (DOCX_SUFFIX.equals(fileType)) { + IConverter converter = LocalConverter.builder().build(); + converter.convert(inputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute(); + converter.shutDown(); + } else if (DOC_SUFFIX.equals(fileType)) { + IConverter converter = LocalConverter.builder().build(); + converter.convert(inputStream).as(DocumentType.DOC).to(outputStream).as(DocumentType.PDF).execute(); + converter.shutDown(); + } else if (XLS_SUFFIX.equals(fileType)) { + IConverter converter = LocalConverter.builder().build(); + converter.convert(inputStream).as(DocumentType.XLS).to(outputStream).as(DocumentType.PDF).execute(); + converter.shutDown(); + } else if (XLSX_SUFFIX.equals(fileType)) { + //此方式行不通 + //converter.convert(inputStream).as(DocumentType.XLSX).to(outputStream).as(DocumentType.PDF).execute(); + Workbook wb = new Workbook(); + wb.loadFromFile(templateFilePath); + wb.saveToFile(saveFilePath, FileFormat.PDF); + } + } catch (Exception e) { + log.error("转换失败,错误信息为:{}", e.getMessage()); + throw new ServiceException(e.getMessage()); + } finally { + inputStream.close(); + outputStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + + /** + * 对象转化为Map 并设置默认值 + * + * @param obj + * @return + * @throws Exception + */ + public static Map objectToMap(Object obj) { + Map result = new HashMap<>(); + if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { + Class clazz = obj.getClass(); + List fieldList = new ArrayList<>(); + while (clazz != null) { + fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); + clazz = clazz.getSuperclass(); + } + fieldList.forEach(field -> { + field.setAccessible(true); + DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); + Object value; + try { + value = field.get(obj); + } catch (IllegalAccessException e) { + throw new ServiceException("获取属性性出错"); + } + //若为list则不处理 + if (value instanceof List) { + return; + } + //若为时间格式则进行格式化 + if (value instanceof LocalDateTime) { + value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); + } + if (value instanceof Date) { + value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); + } + + //如果value为空直接跳出 + // if ((ObjectUtils.isEmpty(value) || value == "") && StringUtil.isNoneBlank(field.getName())){ + // return; + // } + + //属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值 + if (ObjectUtil.isNotEmpty(defaultValue)) { + result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), + ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); + } else { + result.put(field.getName(), Optional.ofNullable(value).orElse(" ")); + + } + }); + } + return result; + } + + + /** + * 对象转化为Map 并设置默认值 + * + * @param obj + * @return + * @throws Exception + */ + public static Map objectToMap(Object obj, boolean isWordFlag) { + Map result = new HashMap<>(); + if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { + Class clazz = obj.getClass(); + List fieldList = new ArrayList<>(); + while (clazz != null) { + fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); + clazz = clazz.getSuperclass(); + } + fieldList.forEach(field -> { + field.setAccessible(true); + DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); + Object value; + try { + value = field.get(obj); + } catch (IllegalAccessException e) { + throw new ServiceException("获取属性性出错"); + } + //若为list则不处理 + if (value instanceof List) { + return; + } + //若为时间格式则进行格式化 + if (value instanceof LocalDateTime) { + value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); + } + if (value instanceof Date) { + value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); + } + + //如果value为空直接跳出 + // if ((ObjectUtils.isEmpty(value) || value == "") && StringUtil.isNoneBlank(field.getName())){ + // return; + // } + + //属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值 + if (ObjectUtil.isNotEmpty(defaultValue)) { + result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), + ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); + } else { + if (isWordFlag) { + //如果导出word为null会出现{{ ,value设置"\u00A0" + result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0")); + } else { + result.put(field.getName(), Optional.ofNullable(value).orElse(" ")); + } + } + }); + } + return result; + } + + /** + * 读取本地pdf,这里设置的是预览 + */ + public static void readPdf(HttpServletResponse response, String filePath) { + response.reset(); + response.setContentType("application/pdf"); + FileInputStream fileInputStream = null; + OutputStream outputStream = null; + try { + File file = new File(filePath); + fileInputStream = new FileInputStream(file); + outputStream = response.getOutputStream(); + IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); + response.setHeader("Content-Disposition", + "inline; filename= " + URLEncoder.encode(file.getName(), "UTF-8")); + outputStream.flush(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + fileInputStream.close(); + outputStream.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 读取本地pdf,这里设置的是导出 + */ + public static void exportPdf(HttpServletResponse response, String filePath) { + response.reset(); + response.setContentType("application/pdf"); + FileInputStream fileInputStream = null; + OutputStream outputStream = null; + try { + File file = new File(filePath); + fileInputStream = new FileInputStream(file); + outputStream = response.getOutputStream(); + IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); + response.setHeader("Content-Disposition", "inline; filename= " + URLEncoder.encode(file.getName(), "UTF-8")); + outputStream.flush(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + fileInputStream.close(); + outputStream.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + } // public static void main(String[] args) { // Runnable runnable = new Runnable() { 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 726e683..31607c8 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 @@ -55,6 +55,7 @@ import org.springblade.core.tool.utils.*; import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.vo.ComleteTask; +import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.BeanUtils; @@ -937,6 +938,22 @@ public class WorkTicketInfoServiceImpl extends BaseServiceImpl