|
|
@@ -1,210 +0,0 @@
|
|
|
-package com.zksy.web.controller.gasbasic;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.zksy.base.domain.PipeNetworkBase;
|
|
|
-import com.zksy.base.domain.PipeRepairRecord;
|
|
|
-import com.zksy.base.dto.RepairRecordPageInDTO;
|
|
|
-import com.zksy.base.service.PipeRepairRecordService;
|
|
|
-import com.zksy.common.annotation.Anonymous;
|
|
|
-import com.zksy.common.annotation.Log;
|
|
|
-import com.zksy.common.core.domain.AjaxResult;
|
|
|
-import com.zksy.common.enums.BusinessType;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-@Slf4j
|
|
|
-@RestController
|
|
|
-@RequestMapping("/api/repair-record")
|
|
|
-@Api(tags = "燃气管网维修记录")
|
|
|
-public class GasRepairRecordController {
|
|
|
-
|
|
|
- /**
|
|
|
- * 健康等级分界:累计维修达到该次数即计入重点管段
|
|
|
- */
|
|
|
- private static final int HEALTH_HIGH_RISK_TIMES = 4;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PipeRepairRecordService service;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private com.zksy.base.mapper.PipeNetworkBaseMapper pipeNetworkBaseMapper;
|
|
|
-
|
|
|
- @GetMapping("/stats")
|
|
|
- @ApiOperation("维修统计+趋势")
|
|
|
- @Anonymous
|
|
|
- public AjaxResult stats() {
|
|
|
- java.util.List<com.zksy.base.domain.PipeRepairRecord> all = service.list();
|
|
|
- java.util.Map<String, Object> result = new java.util.LinkedHashMap<>();
|
|
|
-
|
|
|
- // 维修统计 (按类型)
|
|
|
- String[] typeNames = {"抢修","计划维修","防腐层修复","管件更换","焊缝修补","阀门维修"};
|
|
|
- String[] colors = {"#e63946","#457b9d","#f77f00","#2a9d8f","#6c757d","#b08968"};
|
|
|
- java.util.List<java.util.Map<String, Object>> typeStats = new java.util.ArrayList<>();
|
|
|
- for (int i = 0; i < typeNames.length; i++) {
|
|
|
- int idx = i + 1;
|
|
|
- long cnt = all.stream().filter(r -> r.getRepairType() != null && String.valueOf(idx).equals(r.getRepairType())).count();
|
|
|
- java.util.Map<String, Object> m = new java.util.LinkedHashMap<>();
|
|
|
- m.put("name", typeNames[i]); m.put("value", cnt); m.put("color", colors[i]);
|
|
|
- typeStats.add(m);
|
|
|
- }
|
|
|
- result.put("typeStats", typeStats);
|
|
|
-
|
|
|
- // 维修趋势 (近6月, 按压力等级)
|
|
|
- java.time.LocalDate today = java.time.LocalDate.now();
|
|
|
- String[] months = new String[6];
|
|
|
- int[] highData = new int[6], mediumData = new int[6], lowData = new int[6];
|
|
|
- for (int i = 0; i < 6; i++) {
|
|
|
- java.time.LocalDate m = today.minusMonths(5 - i);
|
|
|
- months[i] = m.getMonthValue() + "月";
|
|
|
- }
|
|
|
- java.util.Map<String, String> levelMap = new java.util.LinkedHashMap<>();
|
|
|
- // 燃气模块:仅查询 network_type=0 的燃气设施
|
|
|
- pipeNetworkBaseMapper.selectList(new LambdaQueryWrapper<PipeNetworkBase>()
|
|
|
- .eq(PipeNetworkBase::getNetworkType, PipeNetworkBase.NETWORK_TYPE_GAS))
|
|
|
- .forEach(n -> levelMap.put(n.getNetworkId(), n.getNetworkLevel()));
|
|
|
- for (com.zksy.base.domain.PipeRepairRecord r : all) {
|
|
|
- if (r.getRepairDate() == null) continue;
|
|
|
- int mDiff = (today.getYear() - r.getRepairDate().getYear()) * 12 + today.getMonthValue() - r.getRepairDate().getMonthValue();
|
|
|
- int idx = 5 - mDiff;
|
|
|
- if (idx < 0 || idx >= 6) continue;
|
|
|
- // network_level 存的是字典 pipe_network_level 的编码:0-高压、1-次高压、2-中压、3-低压
|
|
|
- // 图表只画三档,次高压并入中压;兼容历史数据里直接存 high/low 的写法
|
|
|
- String lv = levelMap.get(r.getNetworkId());
|
|
|
- if ("0".equals(lv) || "high".equals(lv)) {
|
|
|
- highData[idx]++;
|
|
|
- } else if ("3".equals(lv) || "low".equals(lv)) {
|
|
|
- lowData[idx]++;
|
|
|
- } else {
|
|
|
- mediumData[idx]++;
|
|
|
- }
|
|
|
- }
|
|
|
- java.util.Map<String, Object> trend = new java.util.LinkedHashMap<>();
|
|
|
- trend.put("months", months); trend.put("high", highData);
|
|
|
- trend.put("medium", mediumData); trend.put("low", lowData);
|
|
|
- result.put("trend", trend);
|
|
|
-
|
|
|
- // 按管网聚合,供维修记录拓扑图做健康状态分级
|
|
|
- result.put("networkSummary", buildNetworkSummary(all));
|
|
|
-
|
|
|
- return AjaxResult.success(result);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 按管网聚合维修情况
|
|
|
- *
|
|
|
- * 返回累计维修次数、最近维修日期与最近维修类型,以及重点管段与近 30 天维修的汇总值。
|
|
|
- */
|
|
|
- private Map<String, Object> buildNetworkSummary(List<PipeRepairRecord> all) {
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- LocalDate thirtyDaysAgo = today.minusDays(30);
|
|
|
-
|
|
|
- Map<String, Integer> countMap = new HashMap<>();
|
|
|
- Map<String, LocalDate> lastDateMap = new HashMap<>();
|
|
|
- Map<String, String> lastTypeMap = new HashMap<>();
|
|
|
- int last30Days = 0;
|
|
|
-
|
|
|
- for (PipeRepairRecord record : all) {
|
|
|
- String networkId = record.getNetworkId();
|
|
|
- if (networkId == null || networkId.isEmpty()) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- countMap.merge(networkId, 1, Integer::sum);
|
|
|
- LocalDate repairDate = record.getRepairDate();
|
|
|
- if (repairDate == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- LocalDate lastDate = lastDateMap.get(networkId);
|
|
|
- if (lastDate == null || repairDate.isAfter(lastDate)) {
|
|
|
- lastDateMap.put(networkId, repairDate);
|
|
|
- lastTypeMap.put(networkId, record.getRepairType());
|
|
|
- }
|
|
|
- if (!repairDate.isBefore(thirtyDaysAgo)) {
|
|
|
- last30Days++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- int highRiskNetworks = 0;
|
|
|
- List<Map<String, Object>> items = new ArrayList<>(countMap.size());
|
|
|
- for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
|
|
|
- int repairCount = entry.getValue();
|
|
|
- if (repairCount >= HEALTH_HIGH_RISK_TIMES) {
|
|
|
- highRiskNetworks++;
|
|
|
- }
|
|
|
- Map<String, Object> item = new LinkedHashMap<>();
|
|
|
- item.put("networkId", entry.getKey());
|
|
|
- item.put("repairCount", repairCount);
|
|
|
- LocalDate lastDate = lastDateMap.get(entry.getKey());
|
|
|
- item.put("lastRepairDate", lastDate == null ? null : lastDate.toString());
|
|
|
- item.put("lastRepairType", lastTypeMap.get(entry.getKey()));
|
|
|
- items.add(item);
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> result = new LinkedHashMap<>();
|
|
|
- result.put("totalRepairs", all.size());
|
|
|
- result.put("repairedNetworks", countMap.size());
|
|
|
- result.put("highRiskNetworks", highRiskNetworks);
|
|
|
- result.put("last30DaysRepairs", last30Days);
|
|
|
- result.put("items", items);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/findByPage")
|
|
|
- @ApiOperation("维修记录分页查询")
|
|
|
- @Anonymous
|
|
|
- public AjaxResult findByPage(RepairRecordPageInDTO dto) {
|
|
|
- Page<PipeRepairRecord> page = service.findByPage(dto);
|
|
|
- return AjaxResult.success(page);
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/getById/{id}")
|
|
|
- @ApiOperation("根据ID查询维修记录")
|
|
|
- @Anonymous
|
|
|
- public AjaxResult getById(@PathVariable String id) {
|
|
|
- PipeRepairRecord entity = service.getById(id);
|
|
|
- return entity != null ? AjaxResult.success(entity) : AjaxResult.error("维修记录不存在");
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/list-by-network/{networkId}")
|
|
|
- @ApiOperation("按管网ID查询历史维修记录")
|
|
|
- @Anonymous
|
|
|
- public AjaxResult listByNetworkId(@PathVariable String networkId) {
|
|
|
- return AjaxResult.success(service.listByNetworkId(networkId));
|
|
|
- }
|
|
|
-
|
|
|
- @PostMapping("/save")
|
|
|
- @ApiOperation("新增维修记录")
|
|
|
- @Log(title = "新增维修记录", businessType = BusinessType.INSERT)
|
|
|
- public AjaxResult save(@RequestBody PipeRepairRecord entity) {
|
|
|
- entity.setCreateTime(LocalDateTime.now());
|
|
|
- boolean saved = service.save(entity);
|
|
|
- return saved ? AjaxResult.success("新增成功", saved) : AjaxResult.error("新增失败");
|
|
|
- }
|
|
|
-
|
|
|
- @PutMapping("/updateById")
|
|
|
- @ApiOperation("修改维修记录")
|
|
|
- @Log(title = "修改维修记录", businessType = BusinessType.UPDATE)
|
|
|
- public AjaxResult updateById(@RequestBody PipeRepairRecord entity) {
|
|
|
- boolean updated = service.updateById(entity);
|
|
|
- return updated ? AjaxResult.success("修改成功", updated) : AjaxResult.error("修改失败");
|
|
|
- }
|
|
|
-
|
|
|
- @DeleteMapping("/deleteById")
|
|
|
- @ApiOperation("删除维修记录")
|
|
|
- @Log(title = "删除维修记录", businessType = BusinessType.DELETE)
|
|
|
- public AjaxResult deleteById(@RequestParam String id) {
|
|
|
- boolean deleted = service.removeById(id);
|
|
|
- return deleted ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
|
|
|
- }
|
|
|
-}
|