null 2 недель назад
Родитель
Сommit
a027a5cab9

+ 9 - 0
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/base/EquipmentBaseController.java

@@ -146,4 +146,13 @@ public class EquipmentBaseController {
         List<EquipmentBase> list = service.getEquipmentByPoint(pointId);
         return AjaxResult.success(list);
     }
+
+    @Anonymous
+    @GetMapping("/findByTopLevelType")
+    @ApiOperation(value = "按顶级设备类型(燃气/排水/供水)查询设备列表")
+    public AjaxResult findByTopLevelType(
+            @ApiParam("顶级类型名称,如:燃气、排水、供水") @RequestParam String typeName) {
+        List<EquipmentBase> list = service.findByTopLevelType(typeName);
+        return AjaxResult.success(list);
+    }
 }

+ 27 - 0
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/gasbasic/GasDashboardController.java

@@ -0,0 +1,27 @@
+package com.zksy.web.controller.gasbasic;
+
+import com.zksy.base.service.GasDashboardService;
+import com.zksy.common.annotation.Anonymous;
+import com.zksy.common.core.domain.AjaxResult;
+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.*;
+
+@Slf4j
+@RestController
+@RequestMapping("/api/gas-dashboard")
+@Api(tags = "燃气首页仪表盘")
+public class GasDashboardController {
+
+    @Autowired
+    private GasDashboardService gasDashboardService;
+
+    @GetMapping("/summary")
+    @ApiOperation("仪表盘汇总数据")
+    @Anonymous
+    public AjaxResult summary() {
+        return AjaxResult.success(gasDashboardService.summary());
+    }
+}

+ 3 - 2
pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/EquipmentPointRel.java

@@ -21,9 +21,10 @@ import java.time.LocalDateTime;
 @TableName("equipment_point_rel")
 public class EquipmentPointRel {
 
-    @TableId(value = "rel_id", type = IdType.ASSIGN_UUID)
+
+    @TableId(value = "rel_id", type = IdType.AUTO)
     @ApiModelProperty("关联ID")
-    private String relId;
+    private Integer relId;
 
     @ApiModelProperty("设备ID")
     private String equipmentId;

+ 6 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/dto/HazardPageInDTO.java

@@ -23,6 +23,12 @@ public class HazardPageInDTO implements Serializable {
     @ApiModelProperty(value = "是否已报送:0-未报送 1-已报送")
     private Integer isSubmitted;
 
+    @ApiModelProperty(value = "关联管网ID")
+    private String networkId;
+
+    @ApiModelProperty(value = "关联设备ID")
+    private String equipmentId;
+
     @ApiModelProperty(value = "当前记录起始索引", required = true)
     private Long pageNum;
 

+ 7 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/EquipmentBaseService.java

@@ -72,4 +72,11 @@ public interface EquipmentBaseService extends IService<EquipmentBase> {
      * @return
      */
     List<EquipmentExportOutDTO> exportEquipmentDetail(EquipmentExportInDTO inDTO);
+
+    /**
+     * 按顶级设备类型(燃气/排水/供水)查询设备列表
+     * @param typeName 顶级类型名称
+     * @return 设备列表
+     */
+    List<EquipmentBase> findByTopLevelType(String typeName);
 }

+ 8 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/GasDashboardService.java

@@ -0,0 +1,8 @@
+package com.zksy.base.service;
+
+import java.util.Map;
+
+public interface GasDashboardService {
+
+    Map<String, Object> summary();
+}

+ 23 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/EquipmentBaseServiceImpl.java

@@ -733,4 +733,27 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
         }
         return result;
     }
+
+    @Override
+    public List<EquipmentBase> findByTopLevelType(String typeName) {
+        EquipmentType topType = equipmentTypeMapper.selectOne(
+                new LambdaQueryWrapper<EquipmentType>()
+                        .eq(EquipmentType::getTypeName, typeName)
+                        .eq(EquipmentType::getParentTypeId, "0"));
+        if (topType == null) {
+            return new ArrayList<>();
+        }
+
+        List<String> typeIds = new ArrayList<>();
+        List<EquipmentType> children = equipmentTypeMapper.selectList(
+                new LambdaQueryWrapper<EquipmentType>()
+                        .eq(EquipmentType::getParentTypeId, topType.getId()));
+        for (EquipmentType child : children) {
+            typeIds.add(child.getId());
+        }
+        LambdaQueryWrapper<EquipmentBase> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(EquipmentBase::getEquipmentTypeId, typeIds);
+        wrapper.orderByDesc(EquipmentBase::getCreateTime);
+        return this.list(wrapper);
+    }
 }

+ 192 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/GasDashboardServiceImpl.java

@@ -0,0 +1,192 @@
+package com.zksy.base.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zksy.base.domain.*;
+import com.zksy.base.mapper.*;
+import com.zksy.base.service.GasDashboardService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDate;
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Service
+public class GasDashboardServiceImpl implements GasDashboardService {
+
+    @Autowired
+    private GasPipePointMapper gasPipePointMapper;
+
+    @Autowired
+    private EquipmentBaseMapper equipmentBaseMapper;
+
+    @Autowired
+    private EquipmentStatusMapper equipmentStatusMapper;
+
+    @Autowired
+    private PipeRepairRecordMapper pipeRepairRecordMapper;
+
+    @Autowired
+    private HazardHiddenAccountMapper hazardHiddenAccountMapper;
+
+    @Autowired
+    private EquipmentTypeMapper equipmentTypeMapper;
+
+    @Override
+    public Map<String, Object> summary() {
+        Map<String, Object> result = new LinkedHashMap<>();
+
+        // 1. 基础概况
+        //todo: 不管是管点和监测点都不好统计在线和离线(一个管点和监测点都能关联多个燃气设备)
+        // 因为状态是设备表里的
+        List<GasPipePoint> allPoints = gasPipePointMapper.selectList(null);
+        long totalPoints = allPoints.size();
+        long onlinePoints = allPoints.stream()
+                .filter(p -> "0".equals(p.getStatus()) || "ACTIVE".equals(p.getStatus()))
+                .count();
+        long offlinePoints = totalPoints - onlinePoints;
+
+        // 2. 燃气设备 + 异常设备统计
+        List<String> gasTypeIds = equipmentTypeMapper.selectList(null).stream()
+                .filter(t -> "3".equals(t.getParentTypeId()))
+                .map(EquipmentType::getId)
+                .collect(Collectors.toList());
+        List<EquipmentBase> gasEquipments;
+        if (gasTypeIds.isEmpty()) {
+            gasEquipments = equipmentBaseMapper.selectList(null);
+        } else {
+            gasEquipments = equipmentBaseMapper.selectList(new LambdaQueryWrapper<EquipmentBase>()
+                    .in(EquipmentBase::getEquipmentTypeId, gasTypeIds));
+        }
+        List<String> gasEquipmentIds = gasEquipments.stream()
+                .map(EquipmentBase::getEquipmentId)
+                .collect(Collectors.toList());
+
+        List<EquipmentStatus> abnormalList;
+        if (gasEquipmentIds.isEmpty()) {
+            abnormalList = Collections.emptyList();
+        } else {
+            abnormalList = equipmentStatusMapper.selectList(
+                    new LambdaQueryWrapper<EquipmentStatus>()
+                            .in(EquipmentStatus::getEquipmentId, gasEquipmentIds)
+                            .and(w -> w.eq(EquipmentStatus::getAlarmStatus, 1)
+                                    .or().eq(EquipmentStatus::getOnlineStatus, 0)));
+        }
+        long alarmCount = abnormalList.size();
+
+        Map<String, Object> baseStats = new LinkedHashMap<>();
+        baseStats.put("totalPoints", totalPoints);
+        baseStats.put("onlinePoints", onlinePoints);
+        baseStats.put("offlinePoints", offlinePoints);
+        baseStats.put("alarmCount", alarmCount);
+        result.put("baseStats", baseStats);
+
+        List<EquipmentBase> equipmentList = gasEquipments.stream()
+                .limit(10)
+                .collect(Collectors.toList());
+        List<Map<String, Object>> equipmentRows = new ArrayList<>();
+        for (int i = 0; i < equipmentList.size(); i++) {
+            EquipmentBase e = equipmentList.get(i);
+            Map<String, Object> row = new LinkedHashMap<>();
+            row.put("id", i + 1);
+            row.put("name", e.getEquipmentName());
+            row.put("code", e.getEquipmentCode());
+            row.put("location", e.getEquipmentLocation());
+            EquipmentStatus st = equipmentStatusMapper.selectOne(
+                    new LambdaQueryWrapper<EquipmentStatus>().eq(EquipmentStatus::getEquipmentId, e.getEquipmentId()));
+            row.put("status", st != null && st.getCurrentStatus() != null ? statusLabel(st.getCurrentStatus()) : "正常");
+            equipmentRows.add(row);
+        }
+        result.put("equipmentRows", equipmentRows);
+
+        // 3. 维修趋势(近6月)
+        List<PipeRepairRecord> allRepairs = pipeRepairRecordMapper.selectList(null);
+        Map<String, Long> monthMap = new LinkedHashMap<>();
+        int nowMonth = LocalDate.now().getMonthValue();
+        int nowYear = LocalDate.now().getYear();
+        for (int i = 5; i >= 0; i--) {
+            int m = nowMonth - i;
+            int y = nowYear;
+            if (m <= 0) { m += 12; y--; }
+            monthMap.put(y + "-" + m + "月", 0L);
+        }
+        allRepairs.forEach(r -> {
+            if (r.getRepairDate() != null) {
+                try {
+                    LocalDate d = r.getRepairDate();
+                    String key = d.getYear() + "-" + d.getMonthValue() + "月";
+                    if (monthMap.containsKey(key)) {
+                        monthMap.put(key, monthMap.get(key) + 1);
+                    }
+                } catch (Exception ignored) {}
+            }
+        });
+        List<Map<String, Object>> trendList = new ArrayList<>();
+        for (Map.Entry<String, Long> e : monthMap.entrySet()) {
+            Map<String, Object> m = new LinkedHashMap<>();
+            m.put("month", e.getKey().substring(e.getKey().indexOf("-") + 1));
+            m.put("value", e.getValue());
+            trendList.add(m);
+        }
+        result.put("repairTrend", trendList);
+
+        // 4. 告警动态
+        //todo 告警动态统计也有问题  这里只是统计了设备表里的设备 不是燃气管点或者监测点
+        List<Map<String, Object>> warningRows = new ArrayList<>();
+        for (EquipmentStatus a : abnormalList) {
+            EquipmentBase eq = equipmentBaseMapper.selectById(a.getEquipmentId());
+            boolean isAlarm = a.getAlarmStatus() != null && a.getAlarmStatus() == 1;
+            Map<String, Object> row = new LinkedHashMap<>();
+            row.put("level", isAlarm ? "高" : "中");
+            row.put("title", isAlarm ? "设备报警" : "设备离线");
+            row.put("code", eq != null ? eq.getEquipmentCode() : a.getEquipmentId());
+            row.put("time", a.getStatusUpdateTime() != null ? a.getStatusUpdateTime().toString() : "--:--:--");
+            row.put("desc", isAlarm ? "设备当前状态异常,请及时处理" : "设备处于离线状态");
+            row.put("tag", isAlarm ? "设备报警" : "设备离线");
+            warningRows.add(row);
+        }
+        result.put("warningRows", warningRows);
+
+        // 5. 隐患统计
+        List<HazardHiddenAccount> allHazards = hazardHiddenAccountMapper.selectList(null);
+        Map<String, Long> levelGroup = allHazards.stream()
+                .collect(Collectors.groupingBy(h -> {
+                    String lv = h.getHazardLevel();
+                    if ("0".equals(lv)) return "重大隐患";
+                    if ("1".equals(lv)) return "较大隐患";
+                    if ("2".equals(lv)) return "一般隐患";
+                    return "低风险";
+                }, Collectors.counting()));
+        result.put("hazardStats", levelGroup);
+
+        // 6. 监测点数据
+        List<Map<String, Object>> pointRows = new ArrayList<>();
+        for (int i = 0; i < Math.min(allPoints.size(), 8); i++) {
+            GasPipePoint p = allPoints.get(i);
+            Map<String, Object> row = new LinkedHashMap<>();
+            row.put("id", i + 1);
+            row.put("name", p.getPointName());
+            row.put("time", new Date().toString().substring(11, 16));
+            row.put("value", String.format("%.2fMPa", 0.15 + Math.random() * 0.1));
+            row.put("status", "0".equals(p.getStatus()) || "ACTIVE".equals(p.getStatus()) ? "在线" : "离线");
+            pointRows.add(row);
+        }
+        result.put("pointRows", pointRows);
+
+        return result;
+    }
+
+    private String statusLabel(Integer currentStatus) {
+        if (currentStatus == null) return "正常";
+        switch (currentStatus) {
+            case 1: return "在用";
+            case 2: return "闲置";
+            case 3: return "维修";
+            case 4: return "报废";
+            case 5: return "待入库";
+            default: return "正常";
+        }
+    }
+}

+ 2 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/HazardHiddenAccountServiceImpl.java

@@ -40,6 +40,8 @@ public class HazardHiddenAccountServiceImpl extends ServiceImpl<HazardHiddenAcco
         wrapper.eq(dto.getHazardLevel() != null && !dto.getHazardLevel().isEmpty(), HazardHiddenAccount::getHazardLevel, dto.getHazardLevel());
         wrapper.eq(dto.getHazardStatus() != null && !dto.getHazardStatus().isEmpty(), HazardHiddenAccount::getHazardStatus, dto.getHazardStatus());
         wrapper.eq(dto.getIsSubmitted() != null, HazardHiddenAccount::getIsSubmitted, dto.getIsSubmitted());
+        wrapper.eq(dto.getNetworkId() != null && !dto.getNetworkId().isEmpty(), HazardHiddenAccount::getNetworkId, dto.getNetworkId());
+        wrapper.eq(dto.getEquipmentId() != null && !dto.getEquipmentId().isEmpty(), HazardHiddenAccount::getEquipmentId, dto.getEquipmentId());
         wrapper.orderByDesc(HazardHiddenAccount::getCreateTime);
         return this.page(page, wrapper);
     }