样地+样木查询

This commit is contained in:
2025-11-28 18:33:47 +08:00
parent 984c1c5ef3
commit e755e9d98e
9 changed files with 248 additions and 82 deletions

View File

@@ -2,7 +2,7 @@ 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.PlotService;
import com.whu.edu.LyStatistic.MapLyStatistic.Service.AttrService;
import com.whu.edu.LyStatistic.MapLyStatistic.Service.DateService;
import com.whu.edu.LyStatistic.Util.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,17 +24,48 @@ public class StatisticsController {
@Autowired
private StatisticsService statisticsService;
@Autowired
private PlotService plotService;
private AttrService attrService;
@Autowired
private DateService dateService;
/**
* 小班属性
* 入参内业小班号NYXBH+乡XIANG
* 出参:小班的所有属性+媒体数据
*/
@GetMapping("/plot/attr")
public ApiResponse<PlotAttrDTO> getPlotAttr(@RequestParam String nyxbh, @RequestParam String xiang) {
try {
PlotAttrDTO data = plotService.getPlotAttributes(nyxbh, xiang);
PlotAttrDTO data = attrService.getPlotAttributes(nyxbh, xiang);
return ApiResponse.success(data);
} catch (Exception e) {
return ApiResponse.error("查询小班属性失败:" + e.getMessage());
}
}
/**
* t1sub1样地属性
* 入参database_name+ID
* 出参t1sub1内所有值、t1sub1_media中的媒体数据
*/
@GetMapping("/t1sub1")
public ApiResponse<T1sub1DTO> getT1sub1(@RequestParam String database, @RequestParam String id) {
try {
T1sub1DTO data = attrService.getT1sub1(database, id);
return ApiResponse.success(data);
} catch (Exception e) {
return ApiResponse.error("查询小班属性失败:" + e.getMessage());
}
}
/**
* t1sub2样木属性
* 入参database_name+ID
* 出参t1sub2内所有值
*/
@GetMapping("/t1sub2")
public ApiResponse<T1sub2DTO> getT1sub2(@RequestParam String database, @RequestParam String id) {
try {
T1sub2DTO data = attrService.getT1sub2(database, id);
return ApiResponse.success(data);
} catch (Exception e) {
return ApiResponse.error("查询小班属性失败:" + e.getMessage());
@@ -42,9 +73,13 @@ public class StatisticsController {
}
/**
* 小班属性
* 入参:内业小班号NYXBH+乡XIANG
* 按日期返回已完成的小班数和样地数
* 入参:date yyyy-MM-dd
* 出参:"district": "区名",
* "plotcount": 小班数,
* "sampleplotcount": 样地数
*/
@GetMapping("/date")
public ApiResponse<List<DatePlotDTO>> getPlotAttr(
@@ -78,6 +113,7 @@ public class StatisticsController {
/**
* 小班计数
* 入参rootiddatabasename
* 出参:样木数等
*/
@GetMapping("/plot/count")
public ApiResponse<PlotCountDTO> getPlotCount(@RequestParam String rootId, @RequestParam String databaseName) {
@@ -92,6 +128,9 @@ public class StatisticsController {
/**
* 区级统计
* 出参:"completionStatus": 完成状态
* "plotArea"小班面积
* "plotCount"小班数量
*/
@GetMapping("/district")
public ApiResponse<DistrictStatsDTO> getDistrictStats() {

View File

@@ -0,0 +1,56 @@
package com.whu.edu.LyStatistic.MapLyStatistic.Dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class T1sub1DTO {
private String databaseName;
private String id;
private String bz;
private String mgqxj;
// 对应 MGQZS
private String mgqzs;
// 对应 PJ_XJ
private String pjXj;
// 对应 TYPE
private String type;
// 对应 YDZXJ
private String ydzxj;
// 对应 ZS
private String zs;
// 对应 angle
private String angle;
// 对应 area
private String area;
// 对应 length
private String length;
// 对应 parentID (建议转为 parentId)
private String parentId;
// 对应 shape
private String shape;
// 对应 version
private String version;
// 对应 width
private String width;
private List<String> mediaPathList;
// 这里需要生成getter和setter方法
// 可以使用IDE自动生成或Lombok注解
}

View File

@@ -0,0 +1,25 @@
package com.whu.edu.LyStatistic.MapLyStatistic.Dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class T1sub2DTO {
private String databaseName;
private String grandparentid;
private String cjl;
private String id;
private String sz;
private String type;
private String type2;
private String xj;
private String ymh;
private String parentId;
private String photo;
private String version;
}

View File

@@ -0,0 +1,20 @@
package com.whu.edu.LyStatistic.MapLyStatistic.Mapper;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotAttrDTO;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.T1sub1DTO;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.T1sub2DTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Mapper
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<String> findMediaPaths(@Param("id") String id,
@Param("databaseName") String databaseName,
@Param("table") String table);
}

View File

@@ -1,15 +0,0 @@
package com.whu.edu.LyStatistic.MapLyStatistic.Mapper;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotAttrDTO;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.UnitInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface PlotMapper {
PlotAttrDTO findPlotAttributes(@Param("nyxbh") String nyxbh,@Param("xiang") String xiang);
List<String> findMediaPaths(@Param("id") String id,
@Param("databaseName") String databaseName);
}

View File

@@ -0,0 +1,62 @@
package com.whu.edu.LyStatistic.MapLyStatistic.Service;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotAttrDTO;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.T1sub1DTO;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.T1sub2DTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.whu.edu.LyStatistic.MapLyStatistic.Mapper.AttrMapper;
import java.util.List;
@Service
public class AttrService {
@Autowired
private AttrMapper attrMapper; // 查询 unit_info 表
/**
* 查询小班属性
* 条件NYXBH + XIANG
*/
public PlotAttrDTO getPlotAttributes(String nyxbh, String xiang){
// ① 通过 NYXBH + XIANG
PlotAttrDTO schema = attrMapper.findPlotAttributes(nyxbh, xiang);
if (schema == null) {
throw new RuntimeException("未找到对应的小班所在任务 schema");
}
// 第二次查 media_path 列表
List<String> mediaPaths = attrMapper.findMediaPaths(schema.getId(), schema.getDatabaseName(),"merged.roottable1_media_merged");
// 设置到 DTO 中
schema.setMediaPathList(mediaPaths);
return schema;
}
/**
* t1sub1样地属性
* 入参database_name+ID
* 出参t1sub1内所有值、t1sub1_media中的媒体数据
*/
public T1sub1DTO getT1sub1(String database, String id){
T1sub1DTO schema = attrMapper.findT1sub1(database, id);
if (schema == null) {
throw new RuntimeException("未找到对应的样地所在任务 schema");
}
// 第二次查 media_path 列表
List<String> mediaPaths = attrMapper.findMediaPaths(schema.getId(), schema.getDatabaseName(),"merged.t1sub1_media_merged");
// 设置到 DTO 中
schema.setMediaPathList(mediaPaths);
return schema;
}
public T1sub2DTO getT1sub2(String database, String id){
T1sub2DTO schema = attrMapper.findT1sub2(database, id);
if (schema == null) {
throw new RuntimeException("未找到对应的样木所在任务 schema");
}
return schema;
}
}

View File

@@ -1,33 +0,0 @@
package com.whu.edu.LyStatistic.MapLyStatistic.Service;
import com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotAttrDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.whu.edu.LyStatistic.MapLyStatistic.Mapper.PlotMapper;
import java.util.List;
@Service
public class PlotService {
@Autowired
private PlotMapper plotMapper; // 查询 unit_info 表
/**
* 查询小班属性
* 条件NYXBH + XIANG
*/
public PlotAttrDTO getPlotAttributes(String nyxbh, String xiang){
// ① 通过 NYXBH + XIANG
PlotAttrDTO schema = plotMapper.findPlotAttributes(nyxbh, xiang);
if (schema == null) {
throw new RuntimeException("未找到对应的小班所在任务 schema");
}
// 第二次查 media_path 列表
List<String> mediaPaths = plotMapper.findMediaPaths(schema.getId(), schema.getDatabaseName());
// 设置到 DTO 中
schema.setMediaPathList(mediaPaths);
return schema;
}
}

View File

@@ -145,30 +145,30 @@ public class StatisticsService {
//
// return totalBoundaries;
// }
// ✅ 防止 null 值累加
private int safeInt(Integer value) {
return (value != null) ? value : 0;
}
private double safeDouble(Double value) {
return (value != null) ? value : 0.0;
}
/**
* 合并两个 PlotStatsDTO
*/
private void merge(PlotStatsDTO total, PlotStatsDTO add) {
if (add == null) return;
total.setPlotCount(total.getPlotCount() + add.getPlotCount());
total.setTotalArea(total.getTotalArea() + add.getTotalArea());
// total.setUnPassedCount(total.getUnPassedCount() + add.getUnPassedCount());
// total.setAssignedCount(total.getAssignedCount() + add.getAssignedCount());
total.setCollectedCount(total.getCollectedCount() + add.getCollectedCount());
total.setPublishedUncollectedCount(total.getPublishedUncollectedCount() + add.getPublishedUncollectedCount());
}
//
//
// // ✅ 防止 null 值累加
// private int safeInt(Integer value) {
// return (value != null) ? value : 0;
// }
//
// private double safeDouble(Double value) {
// return (value != null) ? value : 0.0;
// }
//
//
// /**
// * 合并两个 PlotStatsDTO
// */
// private void merge(PlotStatsDTO total, PlotStatsDTO add) {
// if (add == null) return;
//
// total.setPlotCount(total.getPlotCount() + add.getPlotCount());
// total.setTotalArea(total.getTotalArea() + add.getTotalArea());
//
//// total.setUnPassedCount(total.getUnPassedCount() + add.getUnPassedCount());
//// total.setAssignedCount(total.getAssignedCount() + add.getAssignedCount());
// total.setCollectedCount(total.getCollectedCount() + add.getCollectedCount());
// total.setPublishedUncollectedCount(total.getPublishedUncollectedCount() + add.getPublishedUncollectedCount());
// }
}

View File

@@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.whu.edu.LyStatistic.MapLyStatistic.Mapper.PlotMapper">
<mapper namespace="com.whu.edu.LyStatistic.MapLyStatistic.Mapper.AttrMapper">
<select id="findPlotAttributes" resultType="com.whu.edu.LyStatistic.MapLyStatistic.Dto.PlotAttrDTO">
SELECT *
FROM merged.roottable1_merged
@@ -11,14 +11,26 @@
LIMIT 1
</select>
<select id="findT1sub1" resultType="com.whu.edu.LyStatistic.MapLyStatistic.Dto.T1sub1DTO">
SELECT *
FROM merged.t1sub1_merged
WHERE database_name = #{database} AND "parentID" = #{id}
LIMIT 1
</select>
<select id="findMediaPaths" resultType="string">
SELECT media_path
FROM merged.roottable1_media_merged
FROM ${table}
WHERE "id" = #{id}
AND "database_name" = #{databaseName}
ORDER BY media_path
</select>
<select id="findT1sub2" resultType="com.whu.edu.LyStatistic.MapLyStatistic.Dto.T1sub2DTO">
SELECT *
FROM merged.t1sub2_merged
WHERE database_name = #{database} AND "parentID" = #{id}
LIMIT 1
</select>
</mapper>