Browse Source

完善监测点管理

zengy 3 weeks ago
parent
commit
47a6b017e3

+ 1 - 0
pipe-network-service/sql/iot_equipment_management.sql

@@ -71,6 +71,7 @@ CREATE TABLE `monitor_point` (
   `point_id` VARCHAR(64) NOT NULL COMMENT '监测点ID(主键)',
   `point_code` VARCHAR(64) NOT NULL COMMENT '监测点编码',
   `point_name` VARCHAR(256) NOT NULL COMMENT '监测点名称',
+  `point_type` INT COMMENT '监测点类型(1-供水监测点 2-排水监测点 3-燃气监测点)',
   `location` VARCHAR(512) COMMENT '位置描述',
   `longitude` DECIMAL(15, 10) COMMENT '经度',
   `latitude` DECIMAL(15, 10) COMMENT '纬度',

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

@@ -31,22 +31,25 @@ public class MonitorPointController {
                                    @RequestParam(defaultValue = "10") long pageSize,
                                    @RequestParam(required = false) String pointCode,
                                    @RequestParam(required = false) String pointName,
-                                   @RequestParam(required = false) String associationStatus) {
-        return monitorPointService.findByPage(pageNum, pageSize, pointCode, pointName, associationStatus);
+                                   @RequestParam(required = false) String associationStatus,
+                                   @RequestParam(required = false) Integer rootTypeId) {
+        return monitorPointService.findByPage(pageNum, pageSize, pointCode, pointName, associationStatus, rootTypeId);
     }
 
     @GetMapping("/all")
     @Anonymous
     @ApiOperation("查询全部监测点位")
-    public AjaxResult all() {
-        return AjaxResult.success(monitorPointService.list());
+    public AjaxResult all(@RequestParam(required = false) Integer rootTypeId) {
+        return AjaxResult.success(monitorPointService.lambdaQuery()
+                .eq(rootTypeId != null, MonitorPoint::getPointType, rootTypeId)
+                .list());
     }
 
     @GetMapping("/statistics")
     @Anonymous
     @ApiOperation("查询监测点位统计")
-    public AjaxResult statistics() {
-        return AjaxResult.success(monitorPointService.statistics());
+    public AjaxResult statistics(@RequestParam(required = false) Integer rootTypeId) {
+        return AjaxResult.success(monitorPointService.statistics(rootTypeId));
     }
 
     @GetMapping("/{pointId}")

+ 2 - 60
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/gasbasic/GasEquipmentController.java

@@ -1,10 +1,8 @@
 package com.zksy.web.controller.gasbasic;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.zksy.base.domain.EquipmentPointRel;
 import com.zksy.base.domain.EquipmentStatus;
 import com.zksy.base.domain.GasPipePointDeviceRel;
-import com.zksy.base.mapper.EquipmentPointRelMapper;
 import com.zksy.base.mapper.EquipmentStatusMapper;
 import com.zksy.base.mapper.GasPipePointDeviceRelMapper;
 import com.zksy.common.annotation.Anonymous;
@@ -15,17 +13,16 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.time.LocalDateTime;
 import java.util.List;
 
 /**
- * 燃气监测设备-测点关联与运行状态查询。
+ * 燃气监测设备运行状态与管点关联查询。
  * 设备台账的新增/修改/删除已统一收口至 EquipmentBaseController(/equipment-base)。
  */
 @Slf4j
 @RestController
 @RequestMapping("/api/equipment")
-@Api(tags = "监测设备管理-测点关联")
+@Api(tags = "燃气监测设备管理")
 public class GasEquipmentController {
 
     @Autowired
@@ -34,9 +31,6 @@ public class GasEquipmentController {
     @Autowired
     private EquipmentStatusMapper equipmentStatusMapper;
 
-    @Autowired
-    private EquipmentPointRelMapper equipmentPointRelMapper;
-
     @GetMapping("/status/{equipmentId}")
     @ApiOperation("获取设备实时运行状态")
     @Anonymous
@@ -57,58 +51,6 @@ public class GasEquipmentController {
         return AjaxResult.success(list);
     }
 
-    @GetMapping("/point-rel/{equipmentId}")
-    @ApiOperation("获取设备关联的测点")
-    @Anonymous
-    public AjaxResult getPointRelByEquipment(@PathVariable String equipmentId) {
-        LambdaQueryWrapper<EquipmentPointRel> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(EquipmentPointRel::getEquipmentId, equipmentId);
-        List<EquipmentPointRel> list = equipmentPointRelMapper.selectList(wrapper);
-        return AjaxResult.success(list);
-    }
-
-    @PostMapping("/point-rel/save")
-    @ApiOperation("新增设备测点关联")
-    @Anonymous
-    public AjaxResult savePointRel(@RequestBody EquipmentPointRel rel) {
-        rel.setCreateTime(LocalDateTime.now());
-        boolean saved = equipmentPointRelMapper.insert(rel) > 0;
-        return saved ? AjaxResult.success("关联成功") : AjaxResult.error("关联失败");
-    }
-
-    @DeleteMapping("/point-rel/delete")
-    @ApiOperation("删除设备测点关联")
-    @Anonymous
-    public AjaxResult deletePointRel(@RequestParam String relId) {
-        boolean deleted = equipmentPointRelMapper.deleteById(relId) > 0;
-        return deleted ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
-    }
-
-    @GetMapping("/point-rel/by-point/{pointId}")
-    @ApiOperation("获取管点关联的设备")
-    @Anonymous
-    public AjaxResult getPointRelByPoint(@PathVariable String pointId) {
-        LambdaQueryWrapper<EquipmentPointRel> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(EquipmentPointRel::getPointId, pointId);
-        List<EquipmentPointRel> list = equipmentPointRelMapper.selectList(wrapper);
-        return AjaxResult.success(list);
-    }
-
-    @PostMapping("/point-rel/save-batch")
-    @ApiOperation("批量关联设备到管点")
-    @Anonymous
-    public AjaxResult savePointRelBatch(@RequestBody List<EquipmentPointRel> relList) {
-        if (relList == null || relList.isEmpty()) {
-            return AjaxResult.error("关联列表不能为空");
-        }
-        LocalDateTime now = LocalDateTime.now();
-        for (EquipmentPointRel rel : relList) {
-            rel.setCreateTime(now);
-            equipmentPointRelMapper.insert(rel);
-        }
-        return AjaxResult.success("批量关联成功");
-    }
-
     @PostMapping("/device-rel/save")
     @ApiOperation("更新设备管点关联(删旧插新)")
     @Anonymous

+ 5 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/MonitorPoint.java

@@ -1,6 +1,7 @@
 package com.zksy.base.domain;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableLogic;
@@ -34,6 +35,10 @@ public class MonitorPoint {
     @ApiModelProperty("监测点名称")
     private String pointName;
 
+    @ApiModelProperty("监测点类型(1-供水监测点 2-排水监测点 3-燃气监测点)")
+    @TableField(updateStrategy = FieldStrategy.ALWAYS)
+    private Integer pointType;
+
     @ApiModelProperty("位置描述")
     private String location;
 

+ 30 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/enums/MonitorPointTypeEnum.java

@@ -0,0 +1,30 @@
+package com.zksy.base.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Objects;
+
+/** 监测点所属子系统类型。 */
+@Getter
+@AllArgsConstructor
+public enum MonitorPointTypeEnum {
+    WATER_SUPPLY(1, "供水监测点"),
+    DRAINAGE(2, "排水监测点"),
+    GAS(3, "燃气监测点");
+
+    private final Integer code;
+    private final String description;
+
+    public static MonitorPointTypeEnum getByCode(Integer code) {
+        if (code == null) return null;
+        for (MonitorPointTypeEnum type : values()) {
+            if (Objects.equals(type.code, code)) return type;
+        }
+        return null;
+    }
+
+    public static boolean isValid(Integer code) {
+        return code == null || getByCode(code) != null;
+    }
+}

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

@@ -9,7 +9,8 @@ import java.util.List;
 
 public interface MonitorPointService extends IService<MonitorPoint> {
 
-    Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName, String associationStatus);
+    Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName,
+                                  String associationStatus, Integer pointType);
 
     boolean saveWithCheck(MonitorPoint entity);
 
@@ -27,7 +28,7 @@ public interface MonitorPointService extends IService<MonitorPoint> {
 
     Map<String, Object> getPointDetail(String pointId);
 
-    Map<String, Object> statistics();
+    Map<String, Object> statistics(Integer pointType);
 
     List<Map<String, Object>> listEquipmentForAssociation(String pointId);
 }

+ 26 - 5
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/MonitorPointServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zksy.base.domain.EquipmentBase;
 import com.zksy.base.domain.EquipmentPointRel;
 import com.zksy.base.domain.MonitorPoint;
+import com.zksy.base.enums.MonitorPointTypeEnum;
 import com.zksy.base.mapper.EquipmentBaseMapper;
 import com.zksy.base.mapper.EquipmentPointRelMapper;
 import com.zksy.base.mapper.EquipmentTypeMapper;
@@ -37,7 +38,8 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
     private EquipmentTypeMapper equipmentTypeMapper;
 
     @Override
-    public Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName, String associationStatus) {
+    public Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName,
+                                         String associationStatus, Integer pointType) {
         Page<MonitorPoint> page = new Page<>(pageNum, pageSize);
         LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
         if (pointCode != null && !pointCode.isEmpty()) {
@@ -46,6 +48,9 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
         if (pointName != null && !pointName.isEmpty()) {
             queryWrapper.like(MonitorPoint::getPointName, pointName);
         }
+        if (pointType != null) {
+            queryWrapper.eq(MonitorPoint::getPointType, pointType);
+        }
         if ("linked".equalsIgnoreCase(associationStatus) || "pending".equalsIgnoreCase(associationStatus)) {
             List<String> linkedPointIds = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>()).stream()
                     .map(EquipmentPointRel::getPointId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
@@ -64,6 +69,7 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
 
     @Override
     public boolean saveWithCheck(MonitorPoint entity) {
+        validatePointType(entity.getPointType());
         LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(MonitorPoint::getPointCode, entity.getPointCode());
         long count = this.count(queryWrapper);
@@ -77,6 +83,7 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
     public boolean saveBatchWithCheck(List<MonitorPoint> entityList) {
         Set<String> codeSet = new HashSet<>();
         for (MonitorPoint entity : entityList) {
+            validatePointType(entity.getPointType());
             String code = entity.getPointCode();
             if (codeSet.contains(code)) {
                 throw new ServiceException("列表中存在重复编码:" + code);
@@ -101,6 +108,7 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
         if (this.getById(pointId) == null) {
             throw new ServiceException("监测点不存在,无法修改:" + pointId);
         }
+        validatePointType(entity.getPointType());
 
         String newCode = entity.getPointCode();
         if (newCode != null) {
@@ -243,13 +251,20 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
     }
 
     @Override
-    public Map<String, Object> statistics() {
-        List<EquipmentPointRel> relations = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>());
+    public Map<String, Object> statistics(Integer pointType) {
+        LambdaQueryWrapper<MonitorPoint> pointWrapper = new LambdaQueryWrapper<>();
+        pointWrapper.eq(pointType != null, MonitorPoint::getPointType, pointType);
+        List<MonitorPoint> points = this.list(pointWrapper);
+        Set<String> pointIds = points.stream().map(MonitorPoint::getPointId).collect(Collectors.toSet());
+        List<EquipmentPointRel> relations = pointIds.isEmpty()
+                ? Collections.emptyList()
+                : equipmentPointRelMapper.selectList(new LambdaQueryWrapper<EquipmentPointRel>()
+                        .in(EquipmentPointRel::getPointId, pointIds));
         Set<String> linkedPointIds = relations.stream().map(EquipmentPointRel::getPointId).filter(Objects::nonNull).collect(Collectors.toSet());
         Map<String, Object> result = new LinkedHashMap<>();
-        result.put("totalPoints", this.count());
+        result.put("totalPoints", points.size());
         result.put("linkedPoints", linkedPointIds.size());
-        result.put("pendingPoints", Math.max(0, this.count() - linkedPointIds.size()));
+        result.put("pendingPoints", Math.max(0, points.size() - linkedPointIds.size()));
         result.put("totalDevices", relations.stream().map(EquipmentPointRel::getEquipmentId).filter(Objects::nonNull).distinct().count());
         return result;
     }
@@ -289,4 +304,10 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
     private long equipmentCount(String pointId) {
         return equipmentPointRelMapper.selectCount(new LambdaQueryWrapper<EquipmentPointRel>().eq(EquipmentPointRel::getPointId, pointId));
     }
+
+    private void validatePointType(Integer pointType) {
+        if (!MonitorPointTypeEnum.isValid(pointType)) {
+            throw new ServiceException("监测点类型无效:" + pointType);
+        }
+    }
 }