diff --git a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Controller/StatisticsController.java b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Controller/StatisticsController.java index d09735d..c7b2a87 100644 --- a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Controller/StatisticsController.java +++ b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Controller/StatisticsController.java @@ -1,9 +1,10 @@ package com.whu.edu.LyStatistic.MapLyStatistic.Controller; import com.whu.edu.LyStatistic.MapLyStatistic.Dto.*; -import com.whu.edu.LyStatistic.MapLyStatistic.Service.StatisticsService; +import com.whu.edu.LyStatistic.MapLyStatistic.Service.StatisticService; import com.whu.edu.LyStatistic.MapLyStatistic.Service.AttrService; import com.whu.edu.LyStatistic.MapLyStatistic.Service.DateService; +import com.whu.edu.LyStatistic.MapLyStatistic.Service.CountService; import com.whu.edu.LyStatistic.Util.ApiResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; @@ -22,11 +23,13 @@ import java.util.List; public class StatisticsController { @Autowired - private StatisticsService statisticsService; + private StatisticService statisticService; @Autowired private AttrService attrService; @Autowired private DateService dateService; + @Autowired + private CountService countService; /** * 小班属性 * 入参:内业小班号NYXBH+乡XIANG @@ -48,9 +51,9 @@ public class StatisticsController { * 出参:t1sub1内所有值、t1sub1_media中的媒体数据 */ @GetMapping("/t1sub1") - public ApiResponse getT1sub1(@RequestParam String database, @RequestParam String id) { + public ApiResponse> getT1sub1(@RequestParam String database, @RequestParam String id) { try { - T1sub1DTO data = attrService.getT1sub1(database, id); + List data = attrService.getT1sub1(database, id); return ApiResponse.success(data); } catch (Exception e) { return ApiResponse.error("查询小班属性失败:" + e.getMessage()); @@ -63,9 +66,9 @@ public class StatisticsController { * 出参:t1sub2内所有值 */ @GetMapping("/t1sub2") - public ApiResponse getT1sub2(@RequestParam String database, @RequestParam String id) { + public ApiResponse> getT1sub2(@RequestParam String database, @RequestParam String id) { try { - T1sub2DTO data = attrService.getT1sub2(database, id); + List data = attrService.getT1sub2(database, id); return ApiResponse.success(data); } catch (Exception e) { return ApiResponse.error("查询小班属性失败:" + e.getMessage()); @@ -103,7 +106,7 @@ public class StatisticsController { @GetMapping("/district/count") public ApiResponse getDistrictCount(@RequestParam String district) { try { - DistrictCountDTO data = statisticsService.getDistrictCount(district); + DistrictCountDTO data = countService.getDistrictCount(district); return ApiResponse.success(data); } catch (Exception e) { return ApiResponse.error("查询区计数失败:" + e.getMessage()); @@ -118,7 +121,7 @@ public class StatisticsController { @GetMapping("/plot/count") public ApiResponse getPlotCount(@RequestParam String rootId, @RequestParam String databaseName) { try { - PlotCountDTO data = statisticsService.getPlotCount(rootId,databaseName); + PlotCountDTO data = countService.getPlotCount(rootId,databaseName); return ApiResponse.success(data); } catch (Exception e) { return ApiResponse.error("查询小班计数失败:" + e.getMessage()); @@ -136,7 +139,7 @@ public class StatisticsController { public ApiResponse getDistrictStats() { try { // 1️⃣ 获取各区统计 List - List statsList = statisticsService.getAllDistrictStats(); + List statsList = statisticService.getAllDistrictStats(); // 2️⃣ 构建 DTO 需要的 Map Map completionStatus = new LinkedHashMap<>(); diff --git a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/AttrMapper.java b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/AttrMapper.java index 9772b75..f4647ef 100644 --- a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/AttrMapper.java +++ b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/AttrMapper.java @@ -12,8 +12,8 @@ import java.util.List; public interface AttrMapper { PlotAttrDTO findPlotAttributes(@Param("nyxbh") String nyxbh,@Param("xiang") String xiang); - T1sub1DTO findT1sub1(@Param("database") String database, @Param("id") String id); - T1sub2DTO findT1sub2(@Param("database") String database, @Param("id") String id); + List findT1sub1(@Param("database") String database, @Param("id") String id); + List findT1sub2(@Param("database") String database, @Param("id") String id); List findMediaPaths(@Param("id") String id, @Param("databaseName") String databaseName, @Param("table") String table); diff --git a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/CountMapper.java b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/CountMapper.java new file mode 100644 index 0000000..f80d97e --- /dev/null +++ b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/CountMapper.java @@ -0,0 +1,26 @@ +package com.whu.edu.LyStatistic.MapLyStatistic.Mapper; + +import com.whu.edu.LyStatistic.MapLyStatistic.Dto.DistrictCountDTO; +import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotCountDTO; +import org.apache.ibatis.annotations.Mapper; + +/** + * TaskCommonMapper.xml + * 区、小班的计数 + */ +@Mapper +public interface CountMapper { + + /** + * 按照区统计数量(内业外业样地数量) + * @return 统计结果 DTO + */ + DistrictCountDTO loadDistrictCount(String district); + + /** + * 按照小班统计数量(样地数量) + * @return 统计结果 DTO + */ + PlotCountDTO loadPlotCount(String rootId, String databaseName); + +} diff --git a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/StatisticMapper.java b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/StatisticMapper.java new file mode 100644 index 0000000..80b01df --- /dev/null +++ b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/StatisticMapper.java @@ -0,0 +1,23 @@ +package com.whu.edu.LyStatistic.MapLyStatistic.Mapper; +import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotStatsDTO; +import org.apache.ibatis.annotations.Mapper; + + +import java.util.List; + +/** + * TaskCommonMapper.xml + * 通用 Mapper,用于不同 schema 下的 roottable1 表 + */ +@Mapper +public interface StatisticMapper { + + + /** + * 按照区统计图斑信息(数量、面积、各状态) + * @return 统计结果 DTO + */ + List selectPlotStatsByDistrict(); + + +} diff --git a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/TaskCommonMapper.java b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/TaskCommonMapper.java index 8e7ac5b..bbde803 100644 --- a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/TaskCommonMapper.java +++ b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Mapper/TaskCommonMapper.java @@ -1,12 +1,8 @@ package com.whu.edu.LyStatistic.MapLyStatistic.Mapper; - import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotStatsDTO; -import com.whu.edu.LyStatistic.MapLyStatistic.Dto.DistrictCountDTO; -import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotCountDTO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.util.List; /** * TaskCommonMapper.xml @@ -21,25 +17,6 @@ public interface TaskCommonMapper { * @return 统计结果 DTO */ PlotStatsDTO selectPlotStats(@Param("schema") String schema); - /** - * 按照区统计图斑信息(数量、面积、各状态) - * @return 统计结果 DTO - */ - List selectPlotStatsByDistrict(); - - - - /** - * 按照区统计数量(内业外业样地数量) - * @return 统计结果 DTO - */ - DistrictCountDTO loadDistrictCount(String district); - - /** - * 按照小班统计信息(内业外业样地数量) - * @return 统计结果 DTO - */ - PlotCountDTO loadPlotCount(String rootId, String databaseName); /** * 获取所有小班的ID和边界信息 diff --git a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/AttrService.java b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/AttrService.java index a81d2b2..f08edb6 100644 --- a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/AttrService.java +++ b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/AttrService.java @@ -36,24 +36,30 @@ public class AttrService { * 入参:database_name+ID * 出参:t1sub1内所有值、t1sub1_media中的媒体数据 */ - public T1sub1DTO getT1sub1(String database, String id){ - T1sub1DTO schema = attrMapper.findT1sub1(database, id); - if (schema == null) { + public List getT1sub1(String database, String id){ + + // 查询得到 List + List schema = attrMapper.findT1sub1(database, id); + if (schema == null || schema.isEmpty()) { throw new RuntimeException("未找到对应的样地所在任务 schema"); } - // 第二次查 media_path 列表 - List mediaPaths = attrMapper.findMediaPaths(schema.getId(), schema.getDatabaseName(),"merged.t1sub1_media_merged"); - - // 设置到 DTO 中 - schema.setMediaPathList(mediaPaths); + // 为每条 DTO 设置 mediaPathList + for (T1sub1DTO dto : schema) { + List mediaPaths = attrMapper.findMediaPaths( + dto.getId(), + dto.getDatabaseName(), + "merged.t1sub1_media_merged" + ); + dto.setMediaPathList(mediaPaths); + } return schema; } - public T1sub2DTO getT1sub2(String database, String id){ - T1sub2DTO schema = attrMapper.findT1sub2(database, id); + public List getT1sub2(String database, String id){ + List schema = attrMapper.findT1sub2(database, id); if (schema == null) { throw new RuntimeException("未找到对应的样木所在任务 schema"); } diff --git a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/CountService.java b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/CountService.java new file mode 100644 index 0000000..89e30e3 --- /dev/null +++ b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/CountService.java @@ -0,0 +1,33 @@ +package com.whu.edu.LyStatistic.MapLyStatistic.Service; + +import com.whu.edu.LyStatistic.MapLyStatistic.Dto.DistrictCountDTO; +import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotCountDTO; +import com.whu.edu.LyStatistic.MapLyStatistic.Mapper.CountMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class CountService { + + @Autowired + private CountMapper countMapper; + + /** + * 查询区的计数信息 + */ + public DistrictCountDTO getDistrictCount(String district) { + DistrictCountDTO data = countMapper.loadDistrictCount(district); + + return data; + } + /** + * 查询小班的计数信息 + */ + public PlotCountDTO getPlotCount(String rootId, String databaseName) { + PlotCountDTO data = countMapper.loadPlotCount(rootId,databaseName); + + return data; + } + + +} diff --git a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/StatisticsService.java b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/StatisticService.java similarity index 84% rename from src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/StatisticsService.java rename to src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/StatisticService.java index a93a09b..a94fcea 100644 --- a/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/StatisticsService.java +++ b/src/main/java/com/whu/edu/LyStatistic/MapLyStatistic/Service/StatisticService.java @@ -1,26 +1,30 @@ package com.whu.edu.LyStatistic.MapLyStatistic.Service; import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotStatsDTO; -import com.whu.edu.LyStatistic.MapLyStatistic.Dto.DistrictCountDTO; -import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotCountDTO; -//import com.whu.edu.LyStatistic.MapLyStatistic.Dto.UnitInfo; -//import com.whu.edu.LyStatistic.MapLyStatistic.Mapper.InfoMapper; -import com.whu.edu.LyStatistic.MapLyStatistic.Mapper.TaskCommonMapper; -//import com.whu.edu.LyStatistic.MapLyStatistic.Service.BaseService.BaseTaskQueryService; +import com.whu.edu.LyStatistic.MapLyStatistic.Mapper.StatisticMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; @Service -public class StatisticsService { +public class StatisticService { // @Autowired // private InfoMapper unitInfoMapper; // 查询 unit_info 表 // // @Autowired // private BaseTaskQueryService baseQueryService; // 通用任务查询 Service @Autowired - private TaskCommonMapper taskCommonMapper; + private StatisticMapper statisticMapper; + /** + * 查询所有区的统计信息 + * 返回 Map<区名, PlotStatsDTO> + */ + public List getAllDistrictStats() { + // 直接从数据库一次性查出“按区聚合后的统计数据” + List list = statisticMapper.selectPlotStatsByDistrict(); + return list; + } /** * 查询单个区的统计信息 */ @@ -42,34 +46,6 @@ public class StatisticsService { // return total; // } - /** - * 查询所有区的统计信息 - * 返回 Map<区名, PlotStatsDTO> - */ - public List getAllDistrictStats() { - // 直接从数据库一次性查出“按区聚合后的统计数据” - List list = taskCommonMapper.selectPlotStatsByDistrict(); - - return list; - } - - /** - * 查询区的计数信息 - */ - public DistrictCountDTO getDistrictCount(String district) { - DistrictCountDTO data = taskCommonMapper.loadDistrictCount(district); - - return data; - } - /** - * 查询小班的计数信息 - */ - public PlotCountDTO getPlotCount(String rootId, String databaseName) { - PlotCountDTO data = taskCommonMapper.loadPlotCount(rootId,databaseName); - - return data; - } - /** * 按街道统计(传入区名称) * 返回 Map<街道名, PlotStatsDTO> diff --git a/src/main/java/com/whu/edu/LyStatistic/statistic/mapper/TaskStatisticMapper.java b/src/main/java/com/whu/edu/LyStatistic/statistic/mapper/StatisticDataMapper.java similarity index 98% rename from src/main/java/com/whu/edu/LyStatistic/statistic/mapper/TaskStatisticMapper.java rename to src/main/java/com/whu/edu/LyStatistic/statistic/mapper/StatisticDataMapper.java index 5cfa65f..3831eda 100644 --- a/src/main/java/com/whu/edu/LyStatistic/statistic/mapper/TaskStatisticMapper.java +++ b/src/main/java/com/whu/edu/LyStatistic/statistic/mapper/StatisticDataMapper.java @@ -8,7 +8,7 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Map; -public interface TaskStatisticMapper { +public interface StatisticDataMapper { /** * 查询根表任务(支持时间范围 + 人员过滤) diff --git a/src/main/java/com/whu/edu/LyStatistic/statistic/service/TaskStatisticService.java b/src/main/java/com/whu/edu/LyStatistic/statistic/service/TaskStatisticService.java index 4f5de1f..d75c330 100644 --- a/src/main/java/com/whu/edu/LyStatistic/statistic/service/TaskStatisticService.java +++ b/src/main/java/com/whu/edu/LyStatistic/statistic/service/TaskStatisticService.java @@ -1,7 +1,7 @@ package com.whu.edu.LyStatistic.statistic.service; import com.whu.edu.LyStatistic.statistic.dto.*; -import com.whu.edu.LyStatistic.statistic.mapper.TaskStatisticMapper; +import com.whu.edu.LyStatistic.statistic.mapper.StatisticDataMapper; import com.whu.edu.LyStatistic.statistic.mapper.UserStaffMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,7 +18,7 @@ public class TaskStatisticService { private UserStaffMapper userStaffMapper; @Autowired - private TaskStatisticMapper taskStatisticMapper; + private StatisticDataMapper statisticDataMapper; /** * 按 schema 和时间区间统计任务数据 @@ -42,11 +42,11 @@ public class TaskStatisticService { .collect(Collectors.toList()); } - String districtName = taskStatisticMapper.getDistrictNameBySchema(schema); - String villageName = taskStatisticMapper.getVillageNameBySchema(schema); + String districtName = statisticDataMapper.getDistrictNameBySchema(schema); + String villageName = statisticDataMapper.getVillageNameBySchema(schema); // 2️⃣ 查询根表记录(支持时间区间) - List rootTasks = taskStatisticMapper.findRootTasksByTimeRange(schema, startTime, endTime, userIds); + List rootTasks = statisticDataMapper.findRootTasksByTimeRange(schema, startTime, endTime, userIds); if (rootTasks.isEmpty()) { return new TaskStatisticResult(schema, districtName, villageName, Collections.emptyList(), 0, 0, 0, 0); } @@ -139,7 +139,7 @@ public class TaskStatisticService { // 🧩 安全封装:防止 schema 无表时报错 private Map safeCountByParent(String schema, String table, List rootIds) { try { - return taskStatisticMapper.countGroupByParent(schema, table, "parentID", rootIds) + return statisticDataMapper.countGroupByParent(schema, table, "parentID", rootIds) .stream() .filter(m -> m.get("parentid") != null) .collect(Collectors.toMap( @@ -153,7 +153,7 @@ public class TaskStatisticService { private List> safeFindSubIds(String schema, String table, List rootIds) { try { - return taskStatisticMapper.findSubIdsGroupByParent(schema, table, "parentID", rootIds); + return statisticDataMapper.findSubIdsGroupByParent(schema, table, "parentID", rootIds); } catch (Exception e) { return Collections.emptyList(); } @@ -161,7 +161,7 @@ public class TaskStatisticService { private Integer safeCountByParentId(String schema, String table, Long parentId) { try { - return taskStatisticMapper.countByParentId(schema, table, "parentID", parentId); + return statisticDataMapper.countByParentId(schema, table, "parentID", parentId); } catch (Exception e) { return 0; } diff --git a/src/main/resources/mapper/MapLyStatistic/Attr.xml b/src/main/resources/mapper/MapLyStatistic/Attr.xml index 6460ee0..388dc4f 100644 --- a/src/main/resources/mapper/MapLyStatistic/Attr.xml +++ b/src/main/resources/mapper/MapLyStatistic/Attr.xml @@ -15,7 +15,6 @@ SELECT * FROM merged.t1sub1_merged WHERE database_name = #{database} AND "parentID" = #{id} - LIMIT 1 diff --git a/src/main/resources/mapper/MapLyStatistic/Count.xml b/src/main/resources/mapper/MapLyStatistic/Count.xml new file mode 100644 index 0000000..7ba0c89 --- /dev/null +++ b/src/main/resources/mapper/MapLyStatistic/Count.xml @@ -0,0 +1,23 @@ + + + + + + + + + + diff --git a/src/main/resources/mapper/MapLyStatistic/Statistic.xml b/src/main/resources/mapper/MapLyStatistic/Statistic.xml new file mode 100644 index 0000000..4b84449 --- /dev/null +++ b/src/main/resources/mapper/MapLyStatistic/Statistic.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + diff --git a/src/main/resources/mapper/MapLyStatistic/TaskCommonMapper.xml b/src/main/resources/mapper/MapLyStatistic/TaskCommonMapper.xml index 2240496..b5d2989 100644 --- a/src/main/resources/mapper/MapLyStatistic/TaskCommonMapper.xml +++ b/src/main/resources/mapper/MapLyStatistic/TaskCommonMapper.xml @@ -105,20 +105,5 @@ FROM "${schema}".roottable1 - - - - diff --git a/src/main/resources/mapper/TaskStatisticMapper.xml b/src/main/resources/mapper/TaskStatisticMapper.xml index 92ed06f..d072fdd 100644 --- a/src/main/resources/mapper/TaskStatisticMapper.xml +++ b/src/main/resources/mapper/TaskStatisticMapper.xml @@ -2,7 +2,7 @@ - +