管道统计数据

This commit is contained in:
Timer
2026-03-08 19:57:26 +08:00
parent 513741bbfa
commit 2c1a99269f
8 changed files with 84 additions and 6 deletions

View File

@ -161,6 +161,8 @@ public class PipelineDataController {
* - totalCount: 污水管网总数量
* - materialLengthRatio: 污水管网【材质-长度】比例
* - materialCountRatio: 污水管网【材质-数量】比例
* - diameterLengthRatio: 污水管网【管径-长度】分布
* - diameterCountRatio: 污水管网【管径-数量】分布
*/
@RequestMapping("/getStatistics.do")
public ModelAndView getStatistics(HttpServletRequest request, Model model) {
@ -239,6 +241,57 @@ public class PipelineDataController {
result.put("materialLengthRatio", materialLengthRatio);
result.put("materialCountRatio", materialCountRatio);
// 获取按管径分组的统计数据
List<Map<String, Object>> diameterStats = pipelineDataService.selectDiameterStats();
// 管径-长度分布
JSONArray diameterLengthRatio = new JSONArray();
// 管径-数量分布
JSONArray diameterCountRatio = new JSONArray();
if (diameterStats != null && !diameterStats.isEmpty()) {
for (Map<String, Object> stat : diameterStats) {
String diameter = (String) stat.get("diameter");
if (diameter == null || diameter.isEmpty()) {
diameter = "未知";
}
Object countObj = stat.get("count");
Object lengthObj = stat.get("totalLength");
int count = 0;
double length = 0.0;
if (countObj != null) {
count = ((Number) countObj).intValue();
}
if (lengthObj != null) {
length = ((Number) lengthObj).doubleValue();
}
// 计算比例
double lengthRatio = totalLength > 0 ? Math.round(length / totalLength * 10000) / 100.0 : 0;
double countRatio = totalCount > 0 ? Math.round(count * 1.0 / totalCount * 10000) / 100.0 : 0;
// 管径-长度分布
JSONObject lengthItem = new JSONObject();
lengthItem.put("diameter", diameter);
lengthItem.put("length", Math.round(length * 100) / 100.0);
lengthItem.put("ratio", lengthRatio); // 百分比
diameterLengthRatio.add(lengthItem);
// 管径-数量分布
JSONObject countItem = new JSONObject();
countItem.put("diameter", diameter);
countItem.put("count", count);
countItem.put("ratio", countRatio); // 百分比
diameterCountRatio.add(countItem);
}
}
result.put("diameterLengthRatio", diameterLengthRatio);
result.put("diameterCountRatio", diameterCountRatio);
result.put("success", true);
} catch (Exception e) {

View File

@ -27,4 +27,11 @@ public class PipelineDataDao extends CommDaoImpl<PipelineData> {
public Map<String, Object> selectTotalStats() {
return this.getSqlSession().selectOne(this.getMappernamespace() + ".selectTotalStats");
}
/**
* 获取按管径分组的统计数据
*/
public List<Map<String, Object>> selectDiameterStats() {
return this.getSqlSession().selectList(this.getMappernamespace() + ".selectDiameterStats");
}
}

View File

@ -200,4 +200,15 @@
SUM(COALESCE(length_m, 0)) as totalLength
FROM tb_pipeline_data
</select>
<!-- 获取管道统计信息:按管径分组 -->
<select id="selectDiameterStats" resultType="java.util.Map">
SELECT
COALESCE(CAST(diameter_mm AS VARCHAR(50)), '未知') as diameter,
COUNT(*) as count,
SUM(COALESCE(length_m, 0)) as totalLength
FROM tb_pipeline_data
GROUP BY diameter_mm
ORDER BY count DESC
</select>
</mapper>

View File

@ -77,4 +77,11 @@ public class PipelineDataService implements CommService<PipelineData> {
public Map<String, Object> selectTotalStats() {
return pipelineDataDao.selectTotalStats();
}
/**
* 获取按管径分组的统计数据
*/
public List<Map<String, Object>> selectDiameterStats() {
return pipelineDataDao.selectDiameterStats();
}
}