diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java index df269e3..f79db79 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java @@ -26,11 +26,9 @@ public class RehearsalExportDTO { private String subject; @ApiModelProperty("演练计划开始时间") - @ExcelProperty(value = "计划开始时间", index = 2) private Date scheduledStartTime; @ApiModelProperty("演练计划结束时间") - @ExcelProperty(value = "计划结束时间", index = 3) private Date scheduledEndTime; @ApiModelProperty("演练地点") @@ -40,4 +38,12 @@ public class RehearsalExportDTO { @ApiModelProperty("演练状态") @ExcelProperty(value = "演练状态", index = 5) private String rehearsalStatus; + + @ApiModelProperty("计划开始时间") + @ExcelProperty(value = "计划开始时间", index = 2) + private String startTime; + + @ApiModelProperty("计划结束时间") + @ExcelProperty(value = "计划结束时间", index = 3) + private String endTime; } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalPlanEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalPlanEntity.java index 4cd4306..45acd49 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalPlanEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalPlanEntity.java @@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.core.mp.base.BaseEntity; +import org.springblade.core.tool.utils.DateUtil; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @@ -33,12 +34,12 @@ public class RehearsalPlanEntity extends BaseEntity { private String subject; @NotNull - @JsonFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = DateUtil.PATTERN_DATE) @ApiModelProperty("演练计划开始时间") private Date scheduledStartTime; @NotNull - @JsonFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = DateUtil.PATTERN_DATE) @ApiModelProperty("演练计划结束时间") private Date scheduledEndTime; diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java index 86afcbe..9b57e9c 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java @@ -1,10 +1,12 @@ package com.hnac.hzims.safeproduct.vo; +import cn.afterturn.easypoi.entity.ImageEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.Date; +import java.util.List; /** * @author liwen @@ -52,4 +54,13 @@ public class RehearsalRecordDetailVO { @ApiModelProperty("演练科目") private String subject; + + @ApiModelProperty("图片列表") + private List images; + + @ApiModelProperty("年份") + private String year; + + @ApiModelProperty("月份") + private String month; } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java index 040e07a..a296345 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java @@ -21,6 +21,7 @@ import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.utils.DateUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -45,8 +46,7 @@ import java.util.stream.Collectors; * @date 2023-12-27 */ @Service -public class RehearsalPlanServiceImpl extends ServiceImpl - implements IRehearsalPlanService { +public class RehearsalPlanServiceImpl extends ServiceImpl implements IRehearsalPlanService { @Autowired IRehearsalRecordService rehearsalRecordService; @@ -190,8 +190,9 @@ public class RehearsalPlanServiceImpl extends ServiceImpl rehearsalList = getRehearsalByUnitAndDate(unit, startTime, endTime); - // 处理演练状态信息 + // 数据处理 rehearsalList.forEach(record -> { + // 演练状态 String status; if (record.getRehearsalStatus().equals(RehearsalStatusEnum.WAITING.getValue())) { status = RehearsalStatusEnum.WAITING.getDesc(); @@ -201,6 +202,9 @@ public class RehearsalPlanServiceImpl extends ServiceImpl list = new ArrayList<>(); + for (String img : imgArr) { + ImageEntity imageEntity = new ImageEntity(BaseUtil.imgToByte(savePath + + BaseUtil.downloadFileByUrl(img, savePath)), 180, 150); + list.add(imageEntity); + } + rehearsalRecordDetailVO.setImages(list); + } + // 表头年月 + String code = rehearsalRecordDetailVO.getCode(); + rehearsalRecordDetailVO.setYear(code.substring(4, 8)); + rehearsalRecordDetailVO.setMonth(code.substring(8, 10)); + // 演练方式 String rehearsalMethod = rehearsalRecordDetailVO.getRehearsalMethod(); if (rehearsalMethod.equals(RehearsalMethodEnum.MIXED.getValue())) { rehearsalRecordDetailVO.setRehearsalMethod(RehearsalMethodEnum.MIXED.getDesc()); diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java index 1cc74f1..3118280 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java @@ -2,7 +2,7 @@ package com.hnac.hzims.safeproduct.utils; import cn.afterturn.easypoi.word.WordExportUtil; import com.hnac.hzims.common.logs.utils.StringUtils; -import com.hnac.hzims.ticket.annotation.DateTimeToMap; +import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.apache.poi.xwpf.usermodel.XWPFDocument; @@ -13,10 +13,12 @@ import org.springblade.core.tool.utils.ObjectUtil; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.lang.reflect.Field; +import java.net.HttpURLConnection; +import java.net.URL; import java.net.URLEncoder; +import java.nio.file.Files; import java.time.LocalDateTime; import java.util.*; -import java.util.stream.Collectors; /** * 公用工具类 @@ -156,8 +158,8 @@ public class BaseUtil { * @return map参数 */ public static Map obj2Map(Object obj) { + Map result = new HashMap<>(); if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { - Map result = new HashMap<>(); List fieldList = new ArrayList<>(); Class clazz = obj.getClass(); while (clazz != null) { @@ -172,59 +174,81 @@ public class BaseUtil { } catch (IllegalAccessException e) { throw new ServiceException("获取属性性出错"); } - if (value instanceof List) { - List> list = ((List) value).stream().map(BaseUtil::obj2Map).collect(Collectors.toList()); - result.put(field.getName(),list); - } - else if (value instanceof LocalDateTime) { - DateTimeToMap dateTimeToMap = field.getAnnotation(DateTimeToMap.class); - LocalDateTime time = (LocalDateTime) value; - if(ObjectUtil.isEmpty(dateTimeToMap)) { - result.put(field.getName(),time.format(DateUtil.TIME_FORMATTER)); - } - else { - result.putAll(LocalDateConvertMap(time,dateTimeToMap.prefix(),dateTimeToMap.split())); - } + if (value instanceof LocalDateTime) { + value = DateUtil.format((LocalDateTime) value, SafeProductConstant.SAFEPRODUCT_EXPORT_DATE); } else if (value instanceof Date) { - DateTimeToMap dateTimeToMap = field.getAnnotation(DateTimeToMap.class); - Date time = (Date) value; - if (ObjectUtil.isEmpty(dateTimeToMap)) { - result.put(field.getName(),DateUtil.format(time,DateUtil.PATTERN_DATETIME)); - } - else { - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"year", time.getYear()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"month", time.getMonth()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"day", time.getDay()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"hour", time.getHours()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"minuter", time.getMinutes()); - result.put(dateTimeToMap.prefix()+dateTimeToMap.split()+"second", time.getSeconds()); - } - } - else { - result.put(field.getName(),value); + value = DateUtil.format((Date) value, SafeProductConstant.SAFEPRODUCT_EXPORT_DATE); } + result.put(field.getName(),value); }); - return result; } - return null; + return result; + } + + /** + * 图片转字节 + * @param tempImgPath 图片路径 + * @return 图片字节 + */ + public static byte[] imgToByte(String tempImgPath) { + File file = new File(tempImgPath); + byte[] buffer = null; + try { + FileInputStream fis = new FileInputStream(file); + ByteArrayOutputStream bos = new ByteArrayOutputStream(1000); + byte[] b = new byte[1000]; + int n; + while ((n = fis.read(b)) != -1) { + bos.write(b, 0, n); + } + fis.close(); + bos.close(); + buffer = bos.toByteArray(); + } catch (IOException e) { + log.error(e.getMessage()); + } + //删除临时文件 + file.delete(); + return buffer; } /** - * 将时间按格式转化为map对象 - * @param dateTime 待转换时间 - * @param prefix 转换格式Key前缀 - * @param split 转换格式Key分隔符 - * @return map对象 + * 下载文件 + * @param fileUrl 文件路径 + * @param downloadFileDir 下载路径 + * @return 下载文件路径 */ - public static Map LocalDateConvertMap(LocalDateTime dateTime,String prefix,String split) { - return new HashMap() {{ - put(prefix + split + "year", dateTime.getYear()); - put(prefix + split + "month", dateTime.getMonthValue()); - put(prefix + split + "day", dateTime.getDayOfMonth()); - put(prefix + split + "hour", dateTime.getHour()); - put(prefix + split + "minuter", dateTime.getMinute()); - put(prefix + split + "second", dateTime.getSecond()); - }}; + public static String downloadFileByUrl(String fileUrl, String downloadFileDir){ + URL url; + String fileName = null; + try { + url = new URL(fileUrl); + HttpURLConnection connection = (HttpURLConnection)url.openConnection(); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.connect(); + int responseCode = connection.getResponseCode(); + if (responseCode == 200) { + InputStream inputStream = connection.getInputStream(); + int lastSlashIndex = fileUrl.lastIndexOf("/"); + if (lastSlashIndex > 0) { + fileName = fileUrl.substring(lastSlashIndex+1); + String filePath = downloadFileDir + fileName; + File file = new File(filePath); + if (file.exists()){ + file.delete(); + } + OutputStream outputStream = Files.newOutputStream(file.toPath()); + // 将文件流拷贝到本地处理 + IOUtils.copy(inputStream, outputStream); + } else { + throw new ServiceException("下载文件路径异常:" + downloadFileDir); + } + } + } catch (Exception e) { + throw new ServiceException("文件图片下载失败!"); + } + return fileName; } } diff --git a/hzims-service/safeproduct/src/main/resources/template/演练记录表.docx b/hzims-service/safeproduct/src/main/resources/template/演练记录表.docx index ce1bbf9..f3c3438 100644 Binary files a/hzims-service/safeproduct/src/main/resources/template/演练记录表.docx and b/hzims-service/safeproduct/src/main/resources/template/演练记录表.docx differ