Commit f3b978d1f8535d361e95cf3bf75cdc1c1d3f65e5
1 parent
f7518567
抢险任务提交update
Showing
3 changed files
with
45 additions
and
9 deletions
urbanops-framework/urbanops-spring-boot-starter-excel/src/main/java/com/zteits/urbanops/framework/excel/core/convert/ListToStringConverter.java
0 → 100644
| 1 | +package com.zteits.urbanops.framework.excel.core.convert; | |
| 2 | +import cn.idev.excel.converters.Converter; | |
| 3 | +import cn.hutool.core.collection.CollectionUtil; | |
| 4 | +import cn.idev.excel.enums.CellDataTypeEnum; | |
| 5 | +import cn.idev.excel.metadata.GlobalConfiguration; | |
| 6 | +import cn.idev.excel.metadata.data.WriteCellData; | |
| 7 | +import cn.idev.excel.metadata.property.ExcelContentProperty; | |
| 8 | + | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * List 转 Excel 字符串转换器(将List用逗号拼接成字符串) | |
| 13 | + */ | |
| 14 | +public class ListToStringConverter implements Converter<List<?>> { | |
| 15 | + | |
| 16 | + @Override | |
| 17 | + public Class<?> supportJavaTypeKey() { | |
| 18 | + // 声明支持的Java类型:List | |
| 19 | + return List.class; | |
| 20 | + } | |
| 21 | + | |
| 22 | + @Override | |
| 23 | + public CellDataTypeEnum supportExcelTypeKey() { | |
| 24 | + // Excel单元格类型:字符串 | |
| 25 | + return CellDataTypeEnum.STRING; | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public WriteCellData<?> convertToExcelData(List<?> value, ExcelContentProperty contentProperty, | |
| 30 | + GlobalConfiguration globalConfiguration) { | |
| 31 | + // 核心转换逻辑:List为空返回空字符串,否则用逗号拼接 | |
| 32 | + if (CollectionUtil.isEmpty(value)) { | |
| 33 | + return new WriteCellData<>(""); | |
| 34 | + } | |
| 35 | + String joinStr = String.join(",", value.stream() | |
| 36 | + .map(Object::toString) | |
| 37 | + .toArray(String[]::new)); | |
| 38 | + return new WriteCellData<>(joinStr); | |
| 39 | + } | |
| 40 | +} | |
| 0 | 41 | \ No newline at end of file | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/emergencytask/EmergencyTaskController.java
| ... | ... | @@ -98,7 +98,7 @@ public class EmergencyTaskController { |
| 98 | 98 | |
| 99 | 99 | @GetMapping("/export-excel") |
| 100 | 100 | @Operation(summary = "导出抢险任务主 Excel") |
| 101 | - @PreAuthorize("@ss.hasPermission('garden:emergency-task:export')") | |
| 101 | + //@PreAuthorize("@ss.hasPermission('garden:emergency-task:export')") | |
| 102 | 102 | @ApiAccessLog(operateType = EXPORT) |
| 103 | 103 | public void exportEmergencyTaskExcel(@Valid EmergencyTaskPageReqVO pageReqVO, |
| 104 | 104 | HttpServletResponse response) throws IOException { | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/emergencytask/vo/EmergencyTaskRespVO.java
| 1 | 1 | package com.zteits.urbanops.module.garden.controller.admin.emergencytask.vo; |
| 2 | 2 | |
| 3 | -import com.baomidou.mybatisplus.annotation.TableField; | |
| 4 | -import com.zteits.urbanops.framework.mybatis.core.type.StringArrayToListTypeHandler; | |
| 5 | -import com.zteits.urbanops.framework.mybatis.core.type.StringListTypeHandler; | |
| 3 | +import com.zteits.urbanops.framework.excel.core.convert.ListToStringConverter; | |
| 6 | 4 | import com.zteits.urbanops.module.garden.dal.dataobject.emergencytask.EmergencyMachineryDO; |
| 7 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 8 | 6 | import lombok.*; |
| 9 | 7 | import java.util.*; |
| 10 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 11 | 8 | import java.time.LocalDateTime; |
| 12 | 9 | import cn.idev.excel.annotation.*; |
| 13 | 10 | |
| ... | ... | @@ -57,8 +54,7 @@ public class EmergencyTaskRespVO { |
| 57 | 54 | private LocalDateTime rescueStartTime; |
| 58 | 55 | |
| 59 | 56 | @Schema(description = "抢险中照片", requiredMode = Schema.RequiredMode.REQUIRED) |
| 60 | - @ExcelProperty("抢险中照片") | |
| 61 | - @TableField(typeHandler = StringArrayToListTypeHandler.class) | |
| 57 | + @ExcelProperty(value="抢险中照片", converter = ListToStringConverter.class) | |
| 62 | 58 | private List<String> emergencyImg; |
| 63 | 59 | |
| 64 | 60 | @Schema(description = "树种(如:国槐)") |
| ... | ... | @@ -78,8 +74,7 @@ public class EmergencyTaskRespVO { |
| 78 | 74 | private Integer personnelCount; |
| 79 | 75 | |
| 80 | 76 | @Schema(description = "抢险结束照片", requiredMode = Schema.RequiredMode.REQUIRED) |
| 81 | - @ExcelProperty("抢险结束照片") | |
| 82 | - @TableField(typeHandler = StringArrayToListTypeHandler.class) | |
| 77 | + @ExcelProperty(value="抢险结束照片", converter = ListToStringConverter.class) | |
| 83 | 78 | private List<String> emergencyEndImg; |
| 84 | 79 | |
| 85 | 80 | @Schema(description = "备注") |
| ... | ... | @@ -130,6 +125,7 @@ public class EmergencyTaskRespVO { |
| 130 | 125 | @ExcelProperty("更新者") |
| 131 | 126 | private String updaterName; |
| 132 | 127 | |
| 128 | + @ExcelProperty(value="机械信息", converter = ListToStringConverter.class) | |
| 133 | 129 | private List<EmergencyMachineryDO> emergencyMachineryList; |
| 134 | 130 | |
| 135 | 131 | @Schema(description = "归属(一级部门id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "20800") | ... | ... |