Commit fdd2cde4444884e3aba5d525424b314029814945
1 parent
58121e4c
feat(garden): GIS数据核对导出按道路名称合并十谱绿地数据
同一道路关联多个十谱绿地时,导出Excel按道路名称分组合并: - 十谱绿地名称和面积用顿号拼接展示 - 道路面积求和 - 差异面积 = 十谱绿地面积合计 - 道路面积合计
Showing
2 changed files
with
80 additions
and
13 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/gis/GisRoadController.java
| @@ -17,6 +17,7 @@ import java.io.IOException; | @@ -17,6 +17,7 @@ import java.io.IOException; | ||
| 17 | import java.time.LocalDate; | 17 | import java.time.LocalDate; |
| 18 | import java.time.format.DateTimeFormatter; | 18 | import java.time.format.DateTimeFormatter; |
| 19 | import java.util.*; | 19 | import java.util.*; |
| 20 | +import java.util.stream.Collectors; | ||
| 20 | 21 | ||
| 21 | import com.zteits.urbanops.framework.common.pojo.PageResult; | 22 | import com.zteits.urbanops.framework.common.pojo.PageResult; |
| 22 | import com.zteits.urbanops.framework.common.pojo.CommonResult; | 23 | import com.zteits.urbanops.framework.common.pojo.CommonResult; |
| @@ -70,35 +71,102 @@ public class GisRoadController { | @@ -70,35 +71,102 @@ public class GisRoadController { | ||
| 70 | HttpServletResponse response) throws IOException { | 71 | HttpServletResponse response) throws IOException { |
| 71 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | 72 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 72 | List<GisRoadRespVO> list = gisRoadService.getGisRoadPage(pageReqVO).getList(); | 73 | List<GisRoadRespVO> list = gisRoadService.getGisRoadPage(pageReqVO).getList(); |
| 73 | - List<GisRoadExportVO> exportList = new ArrayList<>(); | 74 | + |
| 75 | + // 按道路名称分组 | ||
| 76 | + Map<String, List<GisRoadRespVO>> groupedByRoad = new LinkedHashMap<>(); | ||
| 77 | + List<GisRoadRespVO> unassociatedList = new ArrayList<>(); | ||
| 74 | for (GisRoadRespVO vo : list) { | 78 | for (GisRoadRespVO vo : list) { |
| 79 | + if (vo.getRoadName() == null || vo.getRoadName().isEmpty()) { | ||
| 80 | + unassociatedList.add(vo); | ||
| 81 | + } else { | ||
| 82 | + groupedByRoad.computeIfAbsent(vo.getRoadName(), k -> new ArrayList<>()).add(vo); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + List<GisRoadExportVO> exportList = new ArrayList<>(); | ||
| 87 | + | ||
| 88 | + // 未关联的记录:保持原样 | ||
| 89 | + for (GisRoadRespVO vo : unassociatedList) { | ||
| 75 | GisRoadExportVO exportVO = new GisRoadExportVO(); | 90 | GisRoadExportVO exportVO = new GisRoadExportVO(); |
| 76 | exportVO.setGisPlotName(vo.getGisPlotName()); | 91 | exportVO.setGisPlotName(vo.getGisPlotName()); |
| 77 | exportVO.setRoadName(vo.getRoadName()); | 92 | exportVO.setRoadName(vo.getRoadName()); |
| 78 | - exportVO.setGisPlotArea(vo.getGisPlotArea()); | 93 | + exportVO.setGisPlotArea(vo.getGisPlotArea() != null ? String.format("%.2f", vo.getGisPlotArea()) : null); |
| 79 | exportVO.setTotalArea(vo.getTotalArea()); | 94 | exportVO.setTotalArea(vo.getTotalArea()); |
| 80 | - exportVO.setGisIsRelatedStr(vo.getGisIsRelated() != null && vo.getGisIsRelated() == 1 ? "已关联" : "未关联"); | 95 | + exportVO.setGisIsRelatedStr("未关联"); |
| 81 | exportVO.setGisDiffArea(vo.getGisDiffArea()); | 96 | exportVO.setGisDiffArea(vo.getGisDiffArea()); |
| 82 | exportVO.setCompanyName(vo.getCompanyName()); | 97 | exportVO.setCompanyName(vo.getCompanyName()); |
| 83 | exportVO.setDeptName(vo.getDeptName()); | 98 | exportVO.setDeptName(vo.getDeptName()); |
| 84 | - // 位置信息:起点描述 ~ 终点描述 | ||
| 85 | - String positionInfo = ""; | ||
| 86 | - if (vo.getStartingRemark() != null) { | ||
| 87 | - positionInfo += vo.getStartingRemark(); | 99 | + String positionInfo = buildPositionInfo(vo); |
| 100 | + exportVO.setPositionInfo(positionInfo.isEmpty() ? null : positionInfo); | ||
| 101 | + exportList.add(exportVO); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + // 已关联的记录:按道路名称合并 | ||
| 105 | + for (Map.Entry<String, List<GisRoadRespVO>> entry : groupedByRoad.entrySet()) { | ||
| 106 | + List<GisRoadRespVO> group = entry.getValue(); | ||
| 107 | + GisRoadRespVO first = group.get(0); | ||
| 108 | + | ||
| 109 | + GisRoadExportVO exportVO = new GisRoadExportVO(); | ||
| 110 | + exportVO.setRoadName(entry.getKey()); | ||
| 111 | + | ||
| 112 | + // 十谱绿地名称:用顿号拼接 | ||
| 113 | + exportVO.setGisPlotName(group.stream() | ||
| 114 | + .map(GisRoadRespVO::getGisPlotName) | ||
| 115 | + .filter(Objects::nonNull) | ||
| 116 | + .collect(Collectors.joining("、"))); | ||
| 117 | + | ||
| 118 | + // 十谱绿地面积:一一对应拼接,不求和 | ||
| 119 | + exportVO.setGisPlotArea(group.stream() | ||
| 120 | + .map(v -> v.getGisPlotArea() != null ? String.format("%.2f", v.getGisPlotArea()) : "0.00") | ||
| 121 | + .collect(Collectors.joining("、"))); | ||
| 122 | + | ||
| 123 | + // 道路面积:求和 | ||
| 124 | + float sumTotalArea = 0; | ||
| 125 | + for (GisRoadRespVO v : group) { | ||
| 126 | + if (v.getTotalArea() != null) { | ||
| 127 | + sumTotalArea += v.getTotalArea(); | ||
| 128 | + } | ||
| 88 | } | 129 | } |
| 89 | - if (vo.getEndRemark() != null) { | ||
| 90 | - if (!positionInfo.isEmpty()) { | ||
| 91 | - positionInfo += " ~ "; | 130 | + exportVO.setTotalArea(sumTotalArea); |
| 131 | + | ||
| 132 | + // 十谱绿地面积求和(用于计算差异面积) | ||
| 133 | + float sumGisPlotArea = 0; | ||
| 134 | + for (GisRoadRespVO v : group) { | ||
| 135 | + if (v.getGisPlotArea() != null) { | ||
| 136 | + sumGisPlotArea += v.getGisPlotArea(); | ||
| 92 | } | 137 | } |
| 93 | - positionInfo += vo.getEndRemark(); | ||
| 94 | } | 138 | } |
| 139 | + | ||
| 140 | + // 差异面积:十谱绿地面积合计 - 道路面积合计 | ||
| 141 | + exportVO.setGisDiffArea(sumGisPlotArea - sumTotalArea); | ||
| 142 | + | ||
| 143 | + exportVO.setGisIsRelatedStr("已关联"); | ||
| 144 | + exportVO.setCompanyName(first.getCompanyName()); | ||
| 145 | + exportVO.setDeptName(first.getDeptName()); | ||
| 146 | + // 位置信息:起点描述 ~ 终点描述 | ||
| 147 | + String positionInfo = buildPositionInfo(first); | ||
| 95 | exportVO.setPositionInfo(positionInfo.isEmpty() ? null : positionInfo); | 148 | exportVO.setPositionInfo(positionInfo.isEmpty() ? null : positionInfo); |
| 96 | exportList.add(exportVO); | 149 | exportList.add(exportVO); |
| 97 | } | 150 | } |
| 151 | + | ||
| 98 | String filename = "十谱绿地核对" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + ".xls"; | 152 | String filename = "十谱绿地核对" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + ".xls"; |
| 99 | ExcelUtils.write(response, filename, "数据", GisRoadExportVO.class, exportList); | 153 | ExcelUtils.write(response, filename, "数据", GisRoadExportVO.class, exportList); |
| 100 | } | 154 | } |
| 101 | 155 | ||
| 156 | + private String buildPositionInfo(GisRoadRespVO vo) { | ||
| 157 | + String positionInfo = ""; | ||
| 158 | + if (vo.getStartingRemark() != null) { | ||
| 159 | + positionInfo += vo.getStartingRemark(); | ||
| 160 | + } | ||
| 161 | + if (vo.getEndRemark() != null) { | ||
| 162 | + if (!positionInfo.isEmpty()) { | ||
| 163 | + positionInfo += " ~ "; | ||
| 164 | + } | ||
| 165 | + positionInfo += vo.getEndRemark(); | ||
| 166 | + } | ||
| 167 | + return positionInfo; | ||
| 168 | + } | ||
| 169 | + | ||
| 102 | @PostMapping("/associate") | 170 | @PostMapping("/associate") |
| 103 | @Operation(summary = "关联道路到 GIS 图斑") | 171 | @Operation(summary = "关联道路到 GIS 图斑") |
| 104 | // @PreAuthorize("@ss.hasPermission('garden:gis-road:query')") | 172 | // @PreAuthorize("@ss.hasPermission('garden:gis-road:query')") |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/gis/vo/GisRoadExportVO.java
| @@ -22,8 +22,7 @@ public class GisRoadExportVO { | @@ -22,8 +22,7 @@ public class GisRoadExportVO { | ||
| 22 | 22 | ||
| 23 | @Schema(description = "十谱绿地面积") | 23 | @Schema(description = "十谱绿地面积") |
| 24 | @ExcelProperty("十谱绿地面积(㎡)") | 24 | @ExcelProperty("十谱绿地面积(㎡)") |
| 25 | - @JsonSerialize(using = TwoDecimalFloatSerializer.class) | ||
| 26 | - private Float gisPlotArea; | 25 | + private String gisPlotArea; |
| 27 | 26 | ||
| 28 | @Schema(description = "道路面积") | 27 | @Schema(description = "道路面积") |
| 29 | @ExcelProperty("道路面积(㎡)") | 28 | @ExcelProperty("道路面积(㎡)") |