Browse Source

工作票预览

zhongwei
段飞宇 2 years ago
parent
commit
7ea6756ea2
  1. 3
      hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/WorkTicketConstants.java
  2. 64
      hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketInfoEntity.java
  3. 17
      hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/workTicket/entity/WorkTicketPrincipalChangeEntity.java
  4. 1
      hzims-service/hzims-middle/src/main/resources/application.yml
  5. 4
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java
  6. 2
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/processflow/properties/TicketProperties.java
  7. 5
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java
  8. 2
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java
  9. 103
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java
  10. 90
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/PdfUtils.java
  11. 30
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java
  12. BIN
      hzims-service/ticket/src/main/resources/template/新电气第一种工作票模板.xlsx
  13. BIN
      hzims-service/ticket/src/main/resources/template/第一种工作票.docx

3
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"), TWO("2","matterLibraryListTwo"),
/**第三种安措**/ /**第三种安措**/
THREE("3","matterLibraryListThree") THREE("3","matterLibraryListThree"),
FOUR("4","matterLibraryListFour")
; ;
@Getter @Getter
private String type; private String type;

64
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.time.LocalDateTime;
import java.io.Serializable; import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -191,6 +192,11 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable {
private Long signer; 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) @JsonSerialize(nullsUsing = NullSerializer.class)
private Long licensor; 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") @TableField(exist = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty("值班负责人名称")
@ApiModelProperty("批准工作结束时间") private String watchPrincipalName;
private LocalDateTime watchPrincipalEndTime;
/** /**
* 开工时间 * 批准工作结束时间
*/
@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") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("收工时间") @ApiModelProperty("批准工作结束时间")
private LocalDateTime endDateTime; private LocalDateTime watchPrincipalEndTime;
/**
* 工作票结束时间
*/
@ApiModelProperty("工作票结束时间")
private LocalDateTime workTicketEndTime;
/**
* 备注
*/
@ApiModelProperty("备注")
private String content;
/**
* 交底内容
*/
@ApiModelProperty("交底内容")
private String tellContent;
/** /**
@ -401,7 +385,6 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable {
private Boolean signFlag; private Boolean signFlag;
/** /**
* 运行人员是否通过 * 运行人员是否通过
*/ */
@ -409,8 +392,6 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable {
private Boolean recieveFlag; private Boolean recieveFlag;
/** /**
* 工作确认是否通过 input= 延期 input=转移 input 通过 * 工作确认是否通过 input= 延期 input=转移 input 通过
*/ */
@ -439,8 +420,6 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable {
private String flowTaskName; private String flowTaskName;
/** /**
* 当前任务名 * 当前任务名
*/ */
@ -448,5 +427,4 @@ public class WorkTicketInfoEntity extends TenantEntity implements Serializable {
private String flowTaskId; private String flowTaskId;
} }

17
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.time.LocalDateTime;
import java.io.Serializable; import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -43,9 +44,25 @@ public class WorkTicketPrincipalChangeEntity extends TenantEntity implements Ser
@QueryField(condition = SqlCondition.EQUAL) @QueryField(condition = SqlCondition.EQUAL)
private Long initialPrincipal; private Long initialPrincipal;
@TableField(exist = false)
@ApiModelProperty("原负责人名称")
private String initialPrincipalName;
@ApiModelProperty("变更负责人") @ApiModelProperty("变更负责人")
@JsonSerialize(nullsUsing = NullSerializer.class) @JsonSerialize(nullsUsing = NullSerializer.class)
@QueryField(condition = SqlCondition.EQUAL) @QueryField(condition = SqlCondition.EQUAL)
private Long changePrincipal; 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;
} }

1
hzims-service/hzims-middle/src/main/resources/application.yml

@ -2,6 +2,7 @@
server: server:
port: 8400 port: 8400
#数据源配置 #数据源配置
spring: spring:
main: main:

4
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.mapper.HistoryAbnormalAlarmMapper;
import com.hnac.hzims.operational.alert.service.AlarmHandleService; import com.hnac.hzims.operational.alert.service.AlarmHandleService;
import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; 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.AlarmDataPageVo;
import com.hnac.hzims.operational.config.vo.AlarmVo; import com.hnac.hzims.operational.config.vo.AlarmVo;
import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo;

2
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; package com.hnac.hzims.ticket.processflow.properties;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ -18,7 +19,6 @@ import java.util.List;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@Component @Component
//@NacosPropertySource(dataId = "hzims-ticket-dev.yaml", autoRefreshed = true)
@ConfigurationProperties(prefix = "ticket") @ConfigurationProperties(prefix = "ticket")
@RefreshScope @RefreshScope
public class TicketProperties { public class TicketProperties {

5
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketProcessController.java

@ -58,8 +58,9 @@ public class TicketProcessController {
@GetMapping("/preview") @GetMapping("/preview")
@ApiOperation(value = "预览") @ApiOperation(value = "预览")
@ApiOperationSupport(order = 11) @ApiOperationSupport(order = 11)
public void preview(@RequestParam @ApiParam("票据类型") String ticketType, @RequestParam @ApiParam("票据ID") Long ticketId) { public R preview(@RequestParam @ApiParam("票据类型") String ticketType, @RequestParam @ApiParam("票据ID") Long ticketId) {
ticketProcessService.preview(ticketType,ticketId); String preview = ticketProcessService.preview(ticketType, ticketId);
return R.data(preview);
} }

2
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketProcessService.java

@ -30,5 +30,5 @@ public interface TicketProcessService {
* @param ticketType * @param ticketType
* @param ticketId * @param ticketId
*/ */
void preview(String ticketType, Long ticketId); String preview(String ticketType, Long ticketId);
} }

103
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; package com.hnac.hzims.ticket.twoTicket.service.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.word.WordExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -36,7 +35,7 @@ import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils; 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.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
@ -123,11 +122,9 @@ public class TicketProcessServiceImpl implements TicketProcessService {
private final IWorkTicketInfoService ticketInfoService; private final IWorkTicketInfoService ticketInfoService;
@Value("${hzims.ticket.path.pdf.savePath}") @Value("${hzims.ticket.path.word.templatePath}")
private String pdfSavePath; 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()); User user = UserCache.getUser(workTicket.getStepOperator());
if (StringUtils.isNotEmpty(nextStepOperator)) { if (StringUtils.isNotEmpty(nextStepOperator)) {
Long taskUser = NumberUtils.createLong(nextStepOperator.startsWith("taskUser_") ? Long taskUser = NumberUtils.createLong(nextStepOperator.startsWith("taskUser_") ? nextStepOperator.substring(9) : null);
nextStepOperator.substring(9) : null);
//下一个审批人 //下一个审批人
User stepUser = UserCache.getUser(taskUser); User stepUser = UserCache.getUser(taskUser);
flowDescription = "审批中,当前环节是".concat(description) flowDescription = "审批中,当前环节是".concat(description).concat(",当前审批人是").concat(user.getName()).concat(",下一个审批人是").concat(stepUser.getName()).concat("待审批");
.concat(",当前审批人是").concat(user.getName())
.concat(",下一个审批人是").concat(stepUser.getName()).concat("待审批");
workTicket.setNextStepOperator(taskUser); workTicket.setNextStepOperator(taskUser);
} else { } else {
flowDescription = "审批中,当前环节是".concat(description) flowDescription = "审批中,当前环节是".concat(description).concat(",审批人是").concat(user.getName());
.concat(",审批人是").concat(user.getName());
} }
//如果taskId为空 或 flowStatus = 99 //如果taskId为空 或 flowStatus = 99
if (StringUtils.isEmpty(taskId) || 99 == flowStatus) { if (StringUtils.isEmpty(taskId) || 99 == flowStatus) {
@ -609,39 +602,32 @@ public class TicketProcessServiceImpl implements TicketProcessService {
*/ */
@SneakyThrows @SneakyThrows
@Override @Override
public void preview(String ticketType, Long ticketId) { public String preview(String ticketType, Long ticketId) {
WorkTicketVo workTicketVo = ticketInfoService.selectDetailsById(ticketId); WorkTicketVo workTicketVo = ticketInfoService.selectDetailsById(ticketId);
//将查询的数据转换为map //将查询的数据转换为map
Map<String, Object> workTicketInfoMap = this.convertMap(workTicketVo); Map<String, Object> workTicketInfoMap = this.convertMap(workTicketVo);
workTicketInfoMap.put("name", 22);
String fileName = TicketConstants.WordFileNameEnum.getFileNameByType(ticketType) + PdfUtils.XLSX_SUFFIX; String fileName = TicketConstants.WordFileNameEnum.getFileNameByType(ticketType) + PdfUtils.XLSX_SUFFIX;
log.info("工作票模板为:{}", fileName); log.info("工作票模板为:{}", fileName);
TemplateExportParams templateExportParams = new TemplateExportParams("template/新电气第一种工作票模板.xlsx", true); XWPFDocument doc = WordExportUtil.exportWord07("template/电气第一种工作票模版.docx", workTicketInfoMap);
Workbook workbook = null; FileOutputStream fos = null;
try { String name = null;
workbook = ExcelExportUtil.exportExcel(templateExportParams, workTicketInfoMap); String os = System.getProperty("os.name");
} catch (Exception e) { //Windows操作系统
e.printStackTrace(); 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" + doc.write(fos);
".xlsx"); fos.close();
workbook.write(fos); return name;
// //上传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);
} }
@ -650,7 +636,7 @@ public class TicketProcessServiceImpl implements TicketProcessService {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket();
//1. 工作对象 //1. 工作对象
Map<String, Object> workTicketInfoMap = PdfUtils.objectToMap(workTicket); Map<String, Object> workTicketInfoMap = PdfUtils.objectToMap(workTicket, true);
//2. 安全措施 //2. 安全措施
List<WorkTicketSafetyMeasureEntity> safetyMeasuresList = workTicketVo.getSafetyMeasuresList(); List<WorkTicketSafetyMeasureEntity> safetyMeasuresList = workTicketVo.getSafetyMeasuresList();
@ -658,13 +644,25 @@ public class TicketProcessServiceImpl implements TicketProcessService {
Map<String, List<WorkTicketSafetyMeasureEntity>> measureMap = safetyMeasuresList.stream().collect(Collectors.groupingBy(WorkTicketSafetyMeasureEntity::getType)); Map<String, List<WorkTicketSafetyMeasureEntity>> measureMap = safetyMeasuresList.stream().collect(Collectors.groupingBy(WorkTicketSafetyMeasureEntity::getType));
Arrays.stream(WorkTicketConstants.WorkTicketMeasureTypeEnum.class.getEnumConstants()).forEach(measureEnum -> { Arrays.stream(WorkTicketConstants.WorkTicketMeasureTypeEnum.class.getEnumConstants()).forEach(measureEnum -> {
if (CollectionUtil.isNotEmpty(measureMap.get(measureEnum.getType()))) { if (CollectionUtil.isNotEmpty(measureMap.get(measureEnum.getType()))) {
List<Map<String, Object>> mapList = measureMap.get(measureEnum.getType()).stream().map(measureVO -> {
Map<String, Object> map = PdfUtils.objectToMap(measureVO); List<Map<String, Object>> mapList = new ArrayList<>();
int tempIndex = 1, index = 1;
List<WorkTicketSafetyMeasureEntity> workTicketSafetyMeasureEntities = measureMap.get(measureEnum.getType());
for (WorkTicketSafetyMeasureEntity measureVO : workTicketSafetyMeasureEntities) {
String type = measureEnum.getType();
if (tempIndex != Integer.valueOf(type)) {
index = 1;
tempIndex++;
}
Map<String, Object> map = PdfUtils.objectToMap(measureVO, true);
map.put("index", index);
map.put("safetyMeasure", ObjectUtil.isNotEmpty(map.get("measure")) ? map.get("measure") : null); 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); map.put("status", status);
return map; mapList.add(map);
}).collect(Collectors.toList()); index++;
}
workTicketInfoMap.put(measureEnum.getConvertAttributes(), mapList); workTicketInfoMap.put(measureEnum.getConvertAttributes(), mapList);
} else { } else {
workTicketInfoMap.put(measureEnum.getConvertAttributes(), new ArrayList<Map<String, String>>(1)); workTicketInfoMap.put(measureEnum.getConvertAttributes(), new ArrayList<Map<String, String>>(1));
@ -681,21 +679,26 @@ public class TicketProcessServiceImpl implements TicketProcessService {
//4. 工作票延期 //4. 工作票延期
WorkTicketDelayEntity workTicketDelay = workTicketVo.getWorkTicketDelay(); WorkTicketDelayEntity workTicketDelay = workTicketVo.getWorkTicketDelay();
if (ObjectUtils.isNotEmpty(workTicketDelay)) { if (ObjectUtils.isNotEmpty(workTicketDelay)) {
result.putAll(PdfUtils.objectToMap(workTicketDelay)); result.putAll(PdfUtils.objectToMap(workTicketDelay, true));
} else {
result.putAll(PdfUtils.objectToMap(new WorkTicketDelayEntity(), true));
} }
//5. 工作结束 //5. 工作结束
WorkTicketFinish workTicketFinish = workTicketVo.getWorkTicketFinish(); WorkTicketFinish workTicketFinish = workTicketVo.getWorkTicketFinish();
if (ObjectUtils.isNotEmpty(workTicketFinish)) { if (ObjectUtils.isNotEmpty(workTicketFinish)) {
result.putAll(PdfUtils.objectToMap(workTicketFinish)); result.putAll(PdfUtils.objectToMap(workTicketFinish, true));
} else {
result.putAll(PdfUtils.objectToMap(new WorkTicketFinish(), true));
} }
//5. 工作票负责人变更 //5. 工作票负责人变更
WorkTicketPrincipalChangeEntity workTicketPrincipalChange = workTicketVo.getWorkTicketPrincipalChange(); WorkTicketPrincipalChangeEntity workTicketPrincipalChange = workTicketVo.getWorkTicketPrincipalChange();
if (ObjectUtils.isNotEmpty(workTicketPrincipalChange)) { 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; return result;
} }

90
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/utils/PdfUtils.java

@ -81,23 +81,22 @@ public class PdfUtils {
wb.loadFromFile(templateFilePath); wb.loadFromFile(templateFilePath);
wb.saveToFile(saveFilePath, FileFormat.PDF); wb.saveToFile(saveFilePath, FileFormat.PDF);
} }
} } catch (Exception e) {
catch (Exception e) {
log.error("转换失败,错误信息为:{}", e.getMessage()); log.error("转换失败,错误信息为:{}", e.getMessage());
throw new ServiceException(e.getMessage()); throw new ServiceException(e.getMessage());
} } finally {
finally {
inputStream.close(); inputStream.close();
outputStream.close(); outputStream.close();
} }
} } catch (IOException e) {
catch(IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
* 对象转化为Map 并设置默认值 * 对象转化为Map 并设置默认值
*
* @param obj * @param obj
* @return * @return
* @throws Exception * @throws Exception
@ -132,18 +131,79 @@ public class PdfUtils {
value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN);
} }
if ((ObjectUtils.isEmpty(value) || value == "") && StringUtil.isNoneBlank(field.getName())){ //如果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<String, Object> objectToMap(Object obj, boolean isWordFlag) {
Map<String, Object> result = new HashMap<>();
if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) {
Class clazz = obj.getClass();
List<Field> 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; 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注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值 //属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值
if (ObjectUtil.isNotEmpty(defaultValue)) { if (ObjectUtil.isNotEmpty(defaultValue)) {
result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(),
ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value);
} } else {
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(" ")); result.put(field.getName(), Optional.ofNullable(value).orElse(" "));
} }
}
}); });
} }
return result; return result;
@ -169,14 +229,12 @@ public class PdfUtils {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} } finally {
finally {
try { try {
fileInputStream.close(); fileInputStream.close();
outputStream.close(); outputStream.close();
} } catch (IOException e) {
catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -201,14 +259,12 @@ public class PdfUtils {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} } finally {
finally {
try { try {
fileInputStream.close(); fileInputStream.close();
outputStream.close(); outputStream.close();
} } catch (IOException e) {
catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

30
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.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.flow.core.vo.ComleteTask; 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.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -937,6 +938,22 @@ public class WorkTicketInfoServiceImpl extends BaseServiceImpl<WorkTicketInfoMap
if (ObjectUtils.isEmpty(workTicketInfo)) { if (ObjectUtils.isEmpty(workTicketInfo)) {
throw new ServiceException("未查询到ticketId对应的信息"); throw new ServiceException("未查询到ticketId对应的信息");
} }
//赋值签发人
if (workTicketInfo.getSigner() != null){
workTicketInfo.setSignerName(UserCache.getUser(workTicketInfo.getSigner()).getName());
}
//赋值许可人名称
if (workTicketInfo.getLicensor() != null){
workTicketInfo.setLicensorName(UserCache.getUser(workTicketInfo.getLicensor()).getName());
}
// 负责值班负责人
if (workTicketInfo.getWatchPrincipal() != null){
workTicketInfo.setWatchPrincipalName(UserCache.getUser(workTicketInfo.getWatchPrincipal()).getName());
}
workTicketVo.setWorkTicket(workTicketInfo); workTicketVo.setWorkTicket(workTicketInfo);
//2. 安全措施数组 //2. 安全措施数组
@ -977,6 +994,19 @@ public class WorkTicketInfoServiceImpl extends BaseServiceImpl<WorkTicketInfoMap
WorkTicketPrincipalChangeEntity workTicketPrincipalChangeEntity = WorkTicketPrincipalChangeEntity workTicketPrincipalChangeEntity =
workTicketPrincipalChangeService.selectByTicketId(ticketId); workTicketPrincipalChangeService.selectByTicketId(ticketId);
if (ObjectUtils.isNotEmpty(workTicketPrincipalChangeEntity)) { if (ObjectUtils.isNotEmpty(workTicketPrincipalChangeEntity)) {
//原负责人
if (workTicketPrincipalChangeEntity.getInitialPrincipal() != null){
workTicketPrincipalChangeEntity.setInitialPrincipalName(
UserCache.getUser(workTicketPrincipalChangeEntity.getInitialPrincipal()).getName()
);
}
//变更负责人
if (workTicketPrincipalChangeEntity.getChangePrincipal() != null){
workTicketPrincipalChangeEntity.setChangePrincipalName(
UserCache.getUser(workTicketPrincipalChangeEntity.getChangePrincipal()).getName()
);
}
workTicketVo.setWorkTicketPrincipalChange(workTicketPrincipalChangeEntity); workTicketVo.setWorkTicketPrincipalChange(workTicketPrincipalChangeEntity);
} }

BIN
hzims-service/ticket/src/main/resources/template/新电气第一种工作票模板.xlsx

Binary file not shown.

BIN
hzims-service/ticket/src/main/resources/template/第一种工作票.docx

Binary file not shown.
Loading…
Cancel
Save