Commit 30ada1c3398f68687cf2ce4a5be597b76a24d440
1 parent
e8e13752
1、批量导出模板中,去掉抢险中照片、抢险结束照片,这两个字段,以便用户导出全量数据做数据分析。
2、批量导出模板中,机械信息字段展示数据不正确。
Showing
7 changed files
with
72 additions
and
20 deletions
urbanops-framework/urbanops-spring-boot-starter-excel/src/main/java/com/zteits/urbanops/framework/excel/core/handler/CellVerticalCenterStyleStrategy.java
0 → 100644
| 1 | +package com.zteits.urbanops.framework.excel.core.handler; | |
| 2 | + | |
| 3 | +import cn.idev.excel.write.handler.context.CellWriteHandlerContext; | |
| 4 | +import cn.idev.excel.write.style.AbstractCellStyleStrategy; | |
| 5 | +import org.apache.poi.ss.usermodel.Cell; | |
| 6 | +import org.apache.poi.ss.usermodel.CellStyle; | |
| 7 | +import org.apache.poi.ss.usermodel.VerticalAlignment; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Excel 单元格垂直居中样式策略 | |
| 11 | + * | |
| 12 | + * 所有单元格内容上下居中 | |
| 13 | + * | |
| 14 | + * @author hmb | |
| 15 | + */ | |
| 16 | +public class CellVerticalCenterStyleStrategy extends AbstractCellStyleStrategy { | |
| 17 | + | |
| 18 | + @Override | |
| 19 | + protected void setHeadCellStyle(CellWriteHandlerContext context) { | |
| 20 | + setVerticalCenter(context.getCell()); | |
| 21 | + } | |
| 22 | + | |
| 23 | + @Override | |
| 24 | + protected void setContentCellStyle(CellWriteHandlerContext context) { | |
| 25 | + setVerticalCenter(context.getCell()); | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 设置单元格垂直居中 | |
| 30 | + */ | |
| 31 | + private void setVerticalCenter(Cell cell) { | |
| 32 | + CellStyle cellStyle = cell.getCellStyle(); | |
| 33 | + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |
| 34 | + cell.setCellStyle(cellStyle); | |
| 35 | + } | |
| 36 | +} | ... | ... |
urbanops-framework/urbanops-spring-boot-starter-excel/src/main/java/com/zteits/urbanops/framework/excel/core/util/ExcelUtils.java
| ... | ... | @@ -6,6 +6,7 @@ import cn.idev.excel.FastExcelFactory; |
| 6 | 6 | import cn.idev.excel.converters.longconverter.LongStringConverter; |
| 7 | 7 | import cn.idev.excel.write.builder.ExcelWriterBuilder; |
| 8 | 8 | import com.zteits.urbanops.framework.common.util.http.HttpUtils; |
| 9 | +import com.zteits.urbanops.framework.excel.core.handler.CellVerticalCenterStyleStrategy; | |
| 9 | 10 | import com.zteits.urbanops.framework.excel.core.handler.ColumnWidthMatchStyleStrategy; |
| 10 | 11 | import com.zteits.urbanops.framework.excel.core.handler.HeadMergeHandler; |
| 11 | 12 | import com.zteits.urbanops.framework.excel.core.handler.SelectSheetWriteHandler; |
| ... | ... | @@ -139,6 +140,7 @@ public class ExcelUtils { |
| 139 | 140 | .head(headList) //动态自定义3行表头 |
| 140 | 141 | .autoCloseStream(true) // 自动关闭 |
| 141 | 142 | .registerWriteHandler(new ColumnWidthMatchStyleStrategy()) // 基于 column 长度,自动适配。最大 255 宽度 |
| 143 | + //.registerWriteHandler(new CellVerticalCenterStyleStrategy()) //垂直居中 | |
| 142 | 144 | .registerWriteHandler(new SelectSheetWriteHandler(head)) // 基于固定 sheet 实现下拉框 |
| 143 | 145 | .registerConverter(new LongStringConverter()) // 避免 Long 类型丢失精度 |
| 144 | 146 | .registerWriteHandler(new HeadMergeHandler(mergeList.toArray(new CellRangeAddress[0]))); |
| ... | ... | @@ -146,6 +148,7 @@ public class ExcelUtils { |
| 146 | 148 | writeBuilder = FastExcelFactory.write(fos, head) |
| 147 | 149 | .autoCloseStream(true) // 自动关闭 |
| 148 | 150 | .registerWriteHandler(new ColumnWidthMatchStyleStrategy()) // 基于 column 长度,自动适配。最大 255 宽度 |
| 151 | + //.registerWriteHandler(new CellVerticalCenterStyleStrategy()) //垂直居中 | |
| 149 | 152 | .registerWriteHandler(new SelectSheetWriteHandler(head)) // 基于固定 sheet 实现下拉框 |
| 150 | 153 | .registerConverter(new LongStringConverter()); // 避免 Long 类型丢失精度 |
| 151 | 154 | } | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/emergencytask/vo/EmergencyTaskExcleRespVO.java
| ... | ... | @@ -64,11 +64,11 @@ public class EmergencyTaskExcleRespVO { |
| 64 | 64 | @ExcelProperty("抢险开始时间") |
| 65 | 65 | private LocalDateTime rescueStartTime; |
| 66 | 66 | |
| 67 | - @Schema(description = "抢险中照片", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 67 | + //@Schema(description = "抢险中照片", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 68 | 68 | //@ExcelProperty(value="抢险中照片", converter = ListToStringConverter.class) |
| 69 | - @ExcelProperty(value = "抢险中照片", converter = ImageListConverter.class) | |
| 70 | - @ColumnWidth(70) | |
| 71 | - private List<byte[]> emergencyImg; | |
| 69 | + //@ExcelProperty(value = "抢险中照片", converter = ImageListConverter.class) | |
| 70 | + //@ColumnWidth(70) | |
| 71 | + //private List<byte[]> emergencyImg; | |
| 72 | 72 | |
| 73 | 73 | @Schema(description = "树种(如:国槐)") |
| 74 | 74 | @ExcelProperty("树种") |
| ... | ... | @@ -86,11 +86,11 @@ public class EmergencyTaskExcleRespVO { |
| 86 | 86 | @ExcelProperty("出动人员数量") |
| 87 | 87 | private Integer personnelCount; |
| 88 | 88 | |
| 89 | - @Schema(description = "抢险结束照片", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 89 | + //@Schema(description = "抢险结束照片", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 90 | 90 | //@ExcelProperty(value="抢险结束照片", converter = ListToStringConverter.class) |
| 91 | - @ExcelProperty(value = "抢险结束照片", converter = ImageListConverter.class) | |
| 92 | - @ColumnWidth(70) | |
| 93 | - private List<byte[]> emergencyEndImg; | |
| 91 | + //@ExcelProperty(value = "抢险结束照片", converter = ImageListConverter.class) | |
| 92 | + //@ColumnWidth(70) | |
| 93 | + //private List<byte[]> emergencyEndImg; | |
| 94 | 94 | |
| 95 | 95 | @Schema(description = "备注") |
| 96 | 96 | @ExcelProperty("备注") | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/emergencytask/vo/EmergencyTaskSaveReqVO.java
| ... | ... | @@ -38,6 +38,7 @@ public class EmergencyTaskSaveReqVO { |
| 38 | 38 | private String emergencyLocation; |
| 39 | 39 | |
| 40 | 40 | @Schema(description = "上报人", requiredMode = Schema.RequiredMode.REQUIRED) |
| 41 | + @NotEmpty(message = "上报人不能为空") | |
| 41 | 42 | private String reporter; |
| 42 | 43 | |
| 43 | 44 | @Schema(description = "联系电话", requiredMode = Schema.RequiredMode.REQUIRED) |
| ... | ... | @@ -56,10 +57,12 @@ public class EmergencyTaskSaveReqVO { |
| 56 | 57 | |
| 57 | 58 | @Schema(description = "树种(如:国槐)") |
| 58 | 59 | @Size(max = 100, message = "险情地点长度不能超过 255 个字符") |
| 60 | + @NotEmpty(message = "树种不能为空") | |
| 59 | 61 | private String treeSpecies; |
| 60 | 62 | |
| 61 | 63 | @Schema(description = "树木规格(如:胸径20厘米)") |
| 62 | 64 | @Size(max = 100, message = "树木规格100个字符") |
| 65 | + @NotEmpty(message = "树木规格不能为空") | |
| 63 | 66 | private String treeSpec; |
| 64 | 67 | |
| 65 | 68 | @Schema(description = "抢险完成时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| ... | ... | @@ -71,6 +74,7 @@ public class EmergencyTaskSaveReqVO { |
| 71 | 74 | private Integer personnelCount; |
| 72 | 75 | |
| 73 | 76 | @Schema(description = "抢险结束照片", requiredMode = Schema.RequiredMode.REQUIRED) |
| 77 | + @NotEmpty(message = "抢险后照片不能为空") | |
| 74 | 78 | private List<String> emergencyEndImg; |
| 75 | 79 | |
| 76 | 80 | @Schema(description = "备注") |
| ... | ... | @@ -96,6 +100,7 @@ public class EmergencyTaskSaveReqVO { |
| 96 | 100 | private String approvalUserName; |
| 97 | 101 | |
| 98 | 102 | @Schema(description = "使用机械", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") |
| 103 | + @NotEmpty(message = "抢险后照片不能为空") | |
| 99 | 104 | private List<EmergencyMachinerySaveReqVO> emergencyMachineryList; |
| 100 | 105 | |
| 101 | 106 | @Schema(description = "险情类型数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/emergencytask/EmergencyExportHandler.java
| ... | ... | @@ -19,8 +19,6 @@ import java.util.*; |
| 19 | 19 | import java.util.concurrent.ConcurrentHashMap; |
| 20 | 20 | import java.util.stream.Collectors; |
| 21 | 21 | |
| 22 | -import static com.zteits.urbanops.module.garden.service.filedownload.ExcelExportAsyncService.BATCH_SIZE; | |
| 23 | - | |
| 24 | 22 | /** |
| 25 | 23 | * 应急任务导出处理器 |
| 26 | 24 | * 实现 ExcelExportHandler 接口,替代原抽象类继承 |
| ... | ... | @@ -36,7 +34,7 @@ public class EmergencyExportHandler implements ExcelExportHandler<EmergencyTaskR |
| 36 | 34 | private static final String DICT_HAZARD_TYPE = "hazard_type"; |
| 37 | 35 | private static final String DICT_HAZARD_RISK = "hazard_risk"; |
| 38 | 36 | private static final String DICT_TREE_PERMISSIONS = "tree_permissions"; |
| 39 | - private static final String DICT_MECHANICAL_TYPE = "mechanical_type"; | |
| 37 | + private static final String DICT_MECHANICAL_TYPE = "mechanical_type_name"; | |
| 40 | 38 | private static final String DICT_RESCUE_STATUS = "rescue_status"; |
| 41 | 39 | |
| 42 | 40 | @Resource |
| ... | ... | @@ -56,7 +54,7 @@ public class EmergencyExportHandler implements ExcelExportHandler<EmergencyTaskR |
| 56 | 54 | Map<String, String> mechanicalTypeDict = getDictMap(DICT_MECHANICAL_TYPE); |
| 57 | 55 | Map<String, String> rescueStatusDict = getDictMap(DICT_RESCUE_STATUS); |
| 58 | 56 | // 初始化文件客户端 |
| 59 | - FileClient fileClient = fileConfigService.getMasterFileClient(); | |
| 57 | + //FileClient fileClient = fileConfigService.getMasterFileClient(); | |
| 60 | 58 | |
| 61 | 59 | for (EmergencyTaskRespVO task : batchList) { |
| 62 | 60 | EmergencyTaskExcleRespVO vo = new EmergencyTaskExcleRespVO(); |
| ... | ... | @@ -88,8 +86,8 @@ public class EmergencyExportHandler implements ExcelExportHandler<EmergencyTaskR |
| 88 | 86 | vo.setBusiStatus(getLabel(rescueStatusDict, task.getBusiStatus())); |
| 89 | 87 | |
| 90 | 88 | // 图片下载处理 |
| 91 | - vo.setEmergencyImg(ImgDownUtils.batchDownloadImages(task.getEmergencyImg(), fileClient)); | |
| 92 | - vo.setEmergencyEndImg(ImgDownUtils.batchDownloadImages(task.getEmergencyEndImg(), fileClient)); | |
| 89 | + //vo.setEmergencyImg(ImgDownUtils.batchDownloadImages(task.getEmergencyImg(), fileClient)); | |
| 90 | + //vo.setEmergencyEndImg(ImgDownUtils.batchDownloadImages(task.getEmergencyEndImg(), fileClient)); | |
| 93 | 91 | |
| 94 | 92 | // 机械设备信息拼接 |
| 95 | 93 | List<String> machineryInfoList = new ArrayList<>(); | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/emergencytask/EmergencyExportNewHandler.java
| ... | ... | @@ -15,11 +15,8 @@ import org.springframework.util.CollectionUtils; |
| 15 | 15 | |
| 16 | 16 | import java.util.*; |
| 17 | 17 | import java.util.concurrent.ConcurrentHashMap; |
| 18 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 19 | 18 | import java.util.stream.Collectors; |
| 20 | 19 | |
| 21 | -import static com.zteits.urbanops.module.garden.service.filedownload.ExcelExportAsyncService.BATCH_SIZE; | |
| 22 | - | |
| 23 | 20 | /** |
| 24 | 21 | * 新版应急任务导出处理器 |
| 25 | 22 | * 实现 ExcelExportHandler 接口 | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/filedownload/ExcelExportAsyncService.java
| ... | ... | @@ -15,6 +15,7 @@ import org.springframework.util.CollectionUtils; |
| 15 | 15 | |
| 16 | 16 | import java.io.File; |
| 17 | 17 | import java.io.IOException; |
| 18 | +import java.nio.charset.StandardCharsets; | |
| 18 | 19 | import java.time.LocalDateTime; |
| 19 | 20 | import java.util.ArrayList; |
| 20 | 21 | import java.util.List; |
| ... | ... | @@ -28,8 +29,8 @@ public class ExcelExportAsyncService { |
| 28 | 29 | |
| 29 | 30 | @Value("${file.upload-local.expire-days}") |
| 30 | 31 | private Integer expireDay; |
| 31 | - | |
| 32 | - public static final int BATCH_SIZE = 50; | |
| 32 | + //分页大小 | |
| 33 | + private int BATCH_SIZE = 1000; | |
| 33 | 34 | |
| 34 | 35 | private final FileDownloadMapper fileDownloadMapper; |
| 35 | 36 | |
| ... | ... | @@ -109,6 +110,10 @@ public class ExcelExportAsyncService { |
| 109 | 110 | log.info("导出数据为空,业务编码:{}", downloadDO.getBusiCode()); |
| 110 | 111 | return; |
| 111 | 112 | } |
| 113 | + //存在大量图片,设置较小值防止内存溢出 | |
| 114 | + if ("EmergencyTaskExcleNew".equals(downloadDO.getBusiCode())) { | |
| 115 | + BATCH_SIZE = 50; | |
| 116 | + } | |
| 112 | 117 | WriteSheet writeSheet |
| 113 | 118 | = EasyExcel.writerSheet(sheetName).build(); |
| 114 | 119 | int total = sourceList.size(); |
| ... | ... | @@ -126,7 +131,15 @@ public class ExcelExportAsyncService { |
| 126 | 131 | } |
| 127 | 132 | |
| 128 | 133 | private String buildFilePath(FileDownloadDO downloadDO) { |
| 129 | - return new File(localExcelPath, downloadDO.getFileName()).getAbsolutePath(); | |
| 134 | + //return new File(localExcelPath, downloadDO.getFileName()).getAbsolutePath(); | |
| 135 | + String fileName = downloadDO.getFileName(); | |
| 136 | + // 统一UTF-8转码,解决Linux中文文件名乱码 | |
| 137 | + byte[] nameBytes = fileName.getBytes(StandardCharsets.UTF_8); | |
| 138 | + String safeFileName = new String(nameBytes, StandardCharsets.UTF_8); | |
| 139 | + // 剔除操作系统非法字符 | |
| 140 | + safeFileName = safeFileName.replaceAll("[\\\\/:*?\"<>|]", "_"); | |
| 141 | + File targetFile = new File(localExcelPath, safeFileName); | |
| 142 | + return targetFile.getAbsolutePath(); | |
| 130 | 143 | } |
| 131 | 144 | |
| 132 | 145 | private void updateSuccess(FileDownloadDO downloadDO) { | ... | ... |