管道统计数据
This commit is contained in:
@ -7,6 +7,7 @@ import com.sipai.entity.user.User;
|
|||||||
import com.sipai.service.pipeline.PipelineDataService;
|
import com.sipai.service.pipeline.PipelineDataService;
|
||||||
import com.sipai.tools.CommUtil;
|
import com.sipai.tools.CommUtil;
|
||||||
import net.sf.json.JSONArray;
|
import net.sf.json.JSONArray;
|
||||||
|
import net.sf.json.JSONObject;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
@ -16,7 +17,9 @@ import org.springframework.web.servlet.ModelAndView;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/pipeline/pipelineData")
|
@RequestMapping("/pipeline/pipelineData")
|
||||||
@ -150,4 +153,100 @@ public class PipelineDataController {
|
|||||||
model.addAttribute("pipelineData", pipelineData);
|
model.addAttribute("pipelineData", pipelineData);
|
||||||
return "/pipeline/pipelineDataView";
|
return "/pipeline/pipelineDataView";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取管道统计数据
|
||||||
|
* 返回内容:
|
||||||
|
* - totalLength: 污水管线总长度(米)
|
||||||
|
* - totalCount: 污水管网总数量
|
||||||
|
* - materialLengthRatio: 污水管网【材质-长度】比例
|
||||||
|
* - materialCountRatio: 污水管网【材质-数量】比例
|
||||||
|
*/
|
||||||
|
@RequestMapping("/getStatistics.do")
|
||||||
|
public ModelAndView getStatistics(HttpServletRequest request, Model model) {
|
||||||
|
JSONObject result = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取总统计数据
|
||||||
|
Map<String, Object> totalStats = pipelineDataService.selectTotalStats();
|
||||||
|
|
||||||
|
// 总数量
|
||||||
|
long totalCount = 0;
|
||||||
|
double totalLength = 0.0;
|
||||||
|
|
||||||
|
if (totalStats != null) {
|
||||||
|
Object countObj = totalStats.get("totalCount");
|
||||||
|
Object lengthObj = totalStats.get("totalLength");
|
||||||
|
|
||||||
|
if (countObj != null) {
|
||||||
|
totalCount = ((Number) countObj).longValue();
|
||||||
|
}
|
||||||
|
if (lengthObj != null) {
|
||||||
|
totalLength = ((Number) lengthObj).doubleValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.put("totalLength", Math.round(totalLength * 100) / 100.0); // 保留2位小数
|
||||||
|
result.put("totalCount", totalCount);
|
||||||
|
|
||||||
|
// 获取按材质分组的统计数据
|
||||||
|
List<Map<String, Object>> materialStats = pipelineDataService.selectMaterialStats();
|
||||||
|
|
||||||
|
// 材质-长度比例
|
||||||
|
JSONArray materialLengthRatio = new JSONArray();
|
||||||
|
// 材质-数量比例
|
||||||
|
JSONArray materialCountRatio = new JSONArray();
|
||||||
|
|
||||||
|
if (materialStats != null && !materialStats.isEmpty()) {
|
||||||
|
for (Map<String, Object> stat : materialStats) {
|
||||||
|
String material = (String) stat.get("material");
|
||||||
|
if (material == null || material.isEmpty()) {
|
||||||
|
material = "未知";
|
||||||
|
}
|
||||||
|
|
||||||
|
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("material", material);
|
||||||
|
lengthItem.put("length", Math.round(length * 100) / 100.0);
|
||||||
|
lengthItem.put("ratio", lengthRatio); // 百分比
|
||||||
|
materialLengthRatio.add(lengthItem);
|
||||||
|
|
||||||
|
// 材质-数量比例
|
||||||
|
JSONObject countItem = new JSONObject();
|
||||||
|
countItem.put("material", material);
|
||||||
|
countItem.put("count", count);
|
||||||
|
countItem.put("ratio", countRatio); // 百分比
|
||||||
|
materialCountRatio.add(countItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.put("materialLengthRatio", materialLengthRatio);
|
||||||
|
result.put("materialCountRatio", materialCountRatio);
|
||||||
|
result.put("success", true);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "获取统计数据失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
model.addAttribute("result", result.toString());
|
||||||
|
return new ModelAndView("result");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,10 +4,27 @@ import com.sipai.dao.base.CommDaoImpl;
|
|||||||
import com.sipai.entity.pipeline.PipelineData;
|
import com.sipai.entity.pipeline.PipelineData;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class PipelineDataDao extends CommDaoImpl<PipelineData> {
|
public class PipelineDataDao extends CommDaoImpl<PipelineData> {
|
||||||
public PipelineDataDao() {
|
public PipelineDataDao() {
|
||||||
super();
|
super();
|
||||||
this.setMappernamespace("pipeline.PipelineDataMapper");
|
this.setMappernamespace("pipeline.PipelineDataMapper");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取按材质分组的统计数据
|
||||||
|
*/
|
||||||
|
public List<Map<String, Object>> selectMaterialStats() {
|
||||||
|
return this.getSqlSession().selectList(this.getMappernamespace() + ".selectMaterialStats");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取总统计数据
|
||||||
|
*/
|
||||||
|
public Map<String, Object> selectTotalStats() {
|
||||||
|
return this.getSqlSession().selectOne(this.getMappernamespace() + ".selectTotalStats");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,4 +181,23 @@
|
|||||||
tb_pipeline_data
|
tb_pipeline_data
|
||||||
${where}
|
${where}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<!-- 获取管道统计信息:按材质分组 -->
|
||||||
|
<select id="selectMaterialStats" resultType="java.util.Map">
|
||||||
|
SELECT
|
||||||
|
COALESCE(pipe_material, '未知') as material,
|
||||||
|
COUNT(*) as count,
|
||||||
|
SUM(COALESCE(length_m, 0)) as totalLength
|
||||||
|
FROM tb_pipeline_data
|
||||||
|
GROUP BY pipe_material
|
||||||
|
ORDER BY count DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 获取管道总统计 -->
|
||||||
|
<select id="selectTotalStats" resultType="java.util.Map">
|
||||||
|
SELECT
|
||||||
|
COUNT(*) as totalCount,
|
||||||
|
SUM(COALESCE(length_m, 0)) as totalLength
|
||||||
|
FROM tb_pipeline_data
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PipelineDataService implements CommService<PipelineData> {
|
public class PipelineDataService implements CommService<PipelineData> {
|
||||||
@ -62,4 +63,18 @@ public class PipelineDataService implements CommService<PipelineData> {
|
|||||||
pipelineData.setWhere(wherestr);
|
pipelineData.setWhere(wherestr);
|
||||||
return pipelineDataDao.deleteByWhere(pipelineData);
|
return pipelineDataDao.deleteByWhere(pipelineData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取按材质分组的统计数据
|
||||||
|
*/
|
||||||
|
public List<Map<String, Object>> selectMaterialStats() {
|
||||||
|
return pipelineDataDao.selectMaterialStats();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取总统计数据
|
||||||
|
*/
|
||||||
|
public Map<String, Object> selectTotalStats() {
|
||||||
|
return pipelineDataDao.selectTotalStats();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user