Преглед изворни кода

Merge remote-tracking branch 'origin/master'

Kazerin пре 2 месеци
родитељ
комит
bddddd26b5
14 измењених фајлова са 192 додато и 290 уклоњено
  1. 0 4
      pipe-network-service/sql/iot_equipment_management.sql
  2. 67 101
      pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/base/MonitorPointController.java
  3. 4 0
      pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/gasbasic/GasEquipmentController.java
  4. 0 65
      pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/gasbasic/GasMonitorPointController.java
  5. 0 4
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/EquipmentPointRel.java
  6. 5 18
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/domain/MonitorPoint.java
  7. 0 25
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/dto/MonitorPointPageInDTO.java
  8. 1 2
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/mapper/EquipmentPointRelMapper.java
  9. 5 7
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/MonitorPointService.java
  10. 13 3
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/EquipmentBaseServiceImpl.java
  11. 80 58
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/MonitorPointServiceImpl.java
  12. 0 2
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/PressureMonitorServiceImpl.java
  13. 16 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/drainage/service/impl/DrainageEquipmentPointRelServiceImpl.java
  14. 1 1
      pipe-network-service/zksy-system/src/test/java/com/zksy/base/service/impl/EquipmentBaseServiceImplTest.java

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

@@ -71,13 +71,9 @@ CREATE TABLE `monitor_point` (
   `point_id` VARCHAR(64) NOT NULL COMMENT '监测点ID(主键)',
   `point_id` VARCHAR(64) NOT NULL COMMENT '监测点ID(主键)',
   `point_code` VARCHAR(64) NOT NULL COMMENT '监测点编码',
   `point_code` VARCHAR(64) NOT NULL COMMENT '监测点编码',
   `point_name` VARCHAR(256) NOT NULL COMMENT '监测点名称',
   `point_name` VARCHAR(256) NOT NULL COMMENT '监测点名称',
-  `network_id` VARCHAR(64) COMMENT '关联管网设施ID',
-  `point_type` VARCHAR(64) COMMENT '监测点类型(水位、流量、压力、温度等)',
   `location` VARCHAR(512) COMMENT '位置描述',
   `location` VARCHAR(512) COMMENT '位置描述',
   `longitude` DECIMAL(15, 10) COMMENT '经度',
   `longitude` DECIMAL(15, 10) COMMENT '经度',
   `latitude` DECIMAL(15, 10) COMMENT '纬度',
   `latitude` DECIMAL(15, 10) COMMENT '纬度',
-  `installation_date` DATE COMMENT '安装日期',
-  `status` VARCHAR(32) DEFAULT 'NORMAL' COMMENT '状态(NORMAL-正常 ABNORMAL-异常 OFFLINE-离线)',
   `remark` TEXT COMMENT '备注',
   `remark` TEXT COMMENT '备注',
   `create_by` VARCHAR(128) COMMENT '创建人',
   `create_by` VARCHAR(128) COMMENT '创建人',
   `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',

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

@@ -1,6 +1,5 @@
 package com.zksy.web.controller.base;
 package com.zksy.web.controller.base;
 
 
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zksy.base.domain.MonitorPoint;
 import com.zksy.base.domain.MonitorPoint;
 import com.zksy.base.service.MonitorPointService;
 import com.zksy.base.service.MonitorPointService;
@@ -10,139 +9,106 @@ import com.zksy.common.core.domain.AjaxResult;
 import com.zksy.common.enums.BusinessType;
 import com.zksy.common.enums.BusinessType;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
+import lombok.RequiredArgsConstructor;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import java.util.List;
 import java.util.List;
-import java.util.Map;
 
 
-@Slf4j
+/** 关键监测点位资源。 */
 @RestController
 @RestController
-@RequestMapping("/MonitorPoint")
-@Api(tags = "关键监测点管理")
+@RequiredArgsConstructor
+@RequestMapping("/monitor-points")
+@Api(tags = "关键监测点位")
 public class MonitorPointController {
 public class MonitorPointController {
 
 
-    @Autowired
-    private MonitorPointService service;
+    private final MonitorPointService monitorPointService;
 
 
-    @GetMapping("/getById/{id}")
-    @ApiOperation(value = "获取监测点详情")
+    @GetMapping
     @Anonymous
     @Anonymous
-    public AjaxResult getById(@PathVariable String id) {
-        MonitorPoint entity = service.getById(id);
-        if (entity == null) {
-            return AjaxResult.error("该监测点信息不存在");
-        }
-        return AjaxResult.success(entity);
+    @ApiOperation("分页查询监测点位")
+    public Page<MonitorPoint> page(@RequestParam(defaultValue = "1") long pageNum,
+                                   @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);
     }
     }
 
 
+    @GetMapping("/all")
     @Anonymous
     @Anonymous
-    @GetMapping("/findByPage")
-    @ApiOperation(value = "监测点分页查询")
-    public Page findByPage(
-            @ApiParam("页码") @RequestParam(defaultValue = "1") long pageNum,
-            @ApiParam("每页数量") @RequestParam(defaultValue = "10") long pageSize,
-            @ApiParam("监测点编码") @RequestParam(required = false) String pointCode,
-            @ApiParam("监测点名称") @RequestParam(required = false) String pointName,
-            @ApiParam("监测点类型") @RequestParam(required = false) String pointType,
-            @ApiParam("状态") @RequestParam(required = false) String status) {
-        return service.findByPage(pageNum, pageSize, pointCode, pointName, pointType, status);
+    @ApiOperation("查询全部监测点位")
+    public AjaxResult all() {
+        return AjaxResult.success(monitorPointService.list());
     }
     }
 
 
+    @GetMapping("/statistics")
     @Anonymous
     @Anonymous
-    @GetMapping("/getList")
-    @ApiOperation(value = "查询所有监测点")
-    public AjaxResult getList() {
-        return AjaxResult.success(service.list());
+    @ApiOperation("查询监测点位统计")
+    public AjaxResult statistics() {
+        return AjaxResult.success(monitorPointService.statistics());
     }
     }
 
 
+    @GetMapping("/{pointId}")
     @Anonymous
     @Anonymous
-    @GetMapping("/byNetwork/{networkId}")
-    @ApiOperation(value = "根据管网设施查询监测点")
-    public AjaxResult getPointsByNetwork(@PathVariable String networkId) {
-        List<MonitorPoint> list = service.getPointsByNetwork(networkId);
-        return AjaxResult.success(list);
+    @ApiOperation("查询监测点位")
+    public AjaxResult get(@PathVariable String pointId) {
+        MonitorPoint point = monitorPointService.getById(pointId);
+        return point == null ? AjaxResult.error("监测点位不存在") : AjaxResult.success(point);
     }
     }
 
 
-    @PostMapping("/save")
-    @ApiOperation(value = "新增监测点")
-    @Log(title = "新增监测点", businessType = BusinessType.INSERT)
-    public AjaxResult save(@RequestBody MonitorPoint entity) {
-        boolean saved = service.saveWithCheck(entity);
-        return saved ? AjaxResult.success("新增成功", saved)
-                : AjaxResult.error("新增失败", saved);
-    }
-
-    @PostMapping("/saveBatch")
-    @ApiOperation(value = "监测点批量新增")
-    @Log(title = "批量新增监测点", businessType = BusinessType.INSERT)
-    public AjaxResult saveBatch(@RequestBody List<MonitorPoint> entityList) {
-        if (CollectionUtils.isEmpty(entityList)) {
-            return AjaxResult.error("批量新增失败:列表不能为空");
-        }
-        boolean saved = service.saveBatchWithCheck(entityList);
-        return saved ? AjaxResult.success("新增成功", saved)
-                : AjaxResult.error("新增失败", saved);
+    @GetMapping("/{pointId}/detail")
+    @Anonymous
+    @ApiOperation("查询监测点位详情")
+    public AjaxResult detail(@PathVariable String pointId) {
+        return AjaxResult.success(monitorPointService.getPointDetail(pointId));
     }
     }
 
 
-    @PutMapping("/updateById")
-    @ApiOperation(value = "监测点修改")
-    @Log(title = "修改监测点", businessType = BusinessType.UPDATE)
-    public AjaxResult updateById(@RequestBody MonitorPoint entity) {
-        boolean updated = service.updateWithCheck(entity);
-        return updated ? AjaxResult.success("修改成功", updated)
-                : AjaxResult.error("修改失败", updated);
+    @GetMapping("/{pointId}/available-devices")
+    @Anonymous
+    @ApiOperation("查询监测点位可关联设备")
+    public AjaxResult availableDevices(@PathVariable String pointId) {
+        return AjaxResult.success(monitorPointService.listEquipmentForAssociation(pointId));
     }
     }
 
 
-    @DeleteMapping("/deleteById")
-    @ApiOperation(value = "监测点删除")
-    @Log(title = "删除监测点", businessType = BusinessType.DELETE)
-    public AjaxResult deleteById(String id) {
-        boolean deleted = service.removeWithCheck(id);
-        return deleted ? AjaxResult.success("删除成功", deleted)
-                : AjaxResult.error("删除失败", deleted);
+    @PostMapping
+    @Log(title = "新增监测点位", businessType = BusinessType.INSERT)
+    @ApiOperation("新增监测点位")
+    public AjaxResult create(@RequestBody MonitorPoint point) {
+        return monitorPointService.saveWithCheck(point) ? AjaxResult.success("新增成功", point) : AjaxResult.error("新增失败");
     }
     }
 
 
-    @DeleteMapping("/deleteBatchById")
-    @ApiOperation(value = "监测点批量删除")
-    @Log(title = "监测点批量删除", businessType = BusinessType.DELETE)
-    public AjaxResult deleteBatchById(@RequestParam List<String> ids) {
-        boolean deleted = service.removeBatchWithCheck(ids);
-        return deleted ? AjaxResult.success("删除成功", deleted)
-                : AjaxResult.error("删除失败", deleted);
+    @PutMapping("/{pointId}")
+    @Log(title = "修改监测点位", businessType = BusinessType.UPDATE)
+    @ApiOperation("修改监测点位")
+    public AjaxResult update(@PathVariable String pointId, @RequestBody MonitorPoint point) {
+        point.setPointId(pointId);
+        return monitorPointService.updateWithCheck(point) ? AjaxResult.success("修改成功", point) : AjaxResult.error("修改失败");
     }
     }
 
 
-    @PostMapping("/bindEquipment")
-    @ApiOperation(value = "监测点关联设备")
-    @Log(title = "监测点关联设备", businessType = BusinessType.UPDATE)
-    @Anonymous
-    public AjaxResult bindEquipment(
-            @ApiParam("监测点ID") @RequestParam String pointId,
-            @ApiParam("设备ID列表") @RequestParam List<String> equipmentIds) {
-        boolean bound = service.bindEquipment(pointId, equipmentIds);
-        return bound ? AjaxResult.success("关联成功")
-                : AjaxResult.error("关联失败");
+    @DeleteMapping("/{pointId}")
+    @Transactional
+    @Log(title = "删除监测点位", businessType = BusinessType.DELETE)
+    @ApiOperation("删除监测点位")
+    public AjaxResult delete(@PathVariable String pointId) {
+        return monitorPointService.removeWithCheck(pointId) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
     }
     }
 
 
-    @PostMapping("/unbindEquipment")
-    @ApiOperation(value = "监测点取消关联设备")
-    @Log(title = "监测点取消关联设备", businessType = BusinessType.UPDATE)
+    @PostMapping("/{pointId}/devices")
     @Anonymous
     @Anonymous
-    public AjaxResult unbindEquipment(
-            @ApiParam("监测点ID") @RequestParam String pointId,
-            @ApiParam("设备ID列表") @RequestParam List<String> equipmentIds) {
-        boolean unbound = service.unbindEquipment(pointId, equipmentIds);
-        return unbound ? AjaxResult.success("取消关联成功")
-                : AjaxResult.error("取消关联失败");
+    @Transactional
+    @Log(title = "关联监测设备", businessType = BusinessType.UPDATE)
+    @ApiOperation("关联监测设备")
+    public AjaxResult bindDevices(@PathVariable String pointId, @RequestBody List<String> equipmentIds) {
+        return monitorPointService.bindEquipment(pointId, equipmentIds) ? AjaxResult.success("关联成功") : AjaxResult.error("关联失败");
     }
     }
 
 
-    @GetMapping("/pointDetail/{pointId}")
-    @ApiOperation(value = "监测点详情(含关联设备和管网)")
+    @DeleteMapping("/{pointId}/devices")
     @Anonymous
     @Anonymous
-    public AjaxResult getPointDetail(@PathVariable String pointId) {
-        Map<String, Object> detail = service.getPointDetail(pointId);
-        return AjaxResult.success(detail);
+    @Transactional
+    @Log(title = "解除监测设备关联", businessType = BusinessType.UPDATE)
+    @ApiOperation("解除监测设备关联")
+    public AjaxResult unbindDevices(@PathVariable String pointId, @RequestBody List<String> equipmentIds) {
+        return monitorPointService.unbindEquipment(pointId, equipmentIds) ? AjaxResult.success("解绑成功") : AjaxResult.error("解绑失败");
     }
     }
 }
 }

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

@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.List;
 
 
 /**
 /**
@@ -70,6 +71,7 @@ public class GasEquipmentController {
     @ApiOperation("新增设备测点关联")
     @ApiOperation("新增设备测点关联")
     @Anonymous
     @Anonymous
     public AjaxResult savePointRel(@RequestBody EquipmentPointRel rel) {
     public AjaxResult savePointRel(@RequestBody EquipmentPointRel rel) {
+        rel.setCreateTime(LocalDateTime.now());
         boolean saved = equipmentPointRelMapper.insert(rel) > 0;
         boolean saved = equipmentPointRelMapper.insert(rel) > 0;
         return saved ? AjaxResult.success("关联成功") : AjaxResult.error("关联失败");
         return saved ? AjaxResult.success("关联成功") : AjaxResult.error("关联失败");
     }
     }
@@ -99,7 +101,9 @@ public class GasEquipmentController {
         if (relList == null || relList.isEmpty()) {
         if (relList == null || relList.isEmpty()) {
             return AjaxResult.error("关联列表不能为空");
             return AjaxResult.error("关联列表不能为空");
         }
         }
+        LocalDateTime now = LocalDateTime.now();
         for (EquipmentPointRel rel : relList) {
         for (EquipmentPointRel rel : relList) {
+            rel.setCreateTime(now);
             equipmentPointRelMapper.insert(rel);
             equipmentPointRelMapper.insert(rel);
         }
         }
         return AjaxResult.success("批量关联成功");
         return AjaxResult.success("批量关联成功");

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

@@ -1,65 +0,0 @@
-package com.zksy.web.controller.gasbasic;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.zksy.base.domain.MonitorPoint;
-import com.zksy.base.dto.MonitorPointPageInDTO;
-import com.zksy.base.service.MonitorPointService;
-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.*;
-
-@Slf4j
-@RestController
-@RequestMapping("/api/monitor-point")
-@Api(tags = "监测点管理")
-public class GasMonitorPointController {
-
-    @Autowired
-    private MonitorPointService service;
-
-    @GetMapping("/findByPage")
-    @ApiOperation("监测点分页查询")
-    @Anonymous
-    public AjaxResult findByPage(MonitorPointPageInDTO dto) {
-        Page<MonitorPoint> page = service.queryByPage(dto);
-        return AjaxResult.success(page);
-    }
-
-    @GetMapping("/getById/{id}")
-    @ApiOperation("根据ID查询监测点")
-    @Anonymous
-    public AjaxResult getById(@PathVariable String id) {
-        MonitorPoint entity = service.getById(id);
-        return entity != null ? AjaxResult.success(entity) : AjaxResult.error("监测点信息不存在");
-    }
-
-    @PostMapping("/save")
-    @ApiOperation("新增监测点")
-    @Log(title = "新增监测点", businessType = BusinessType.INSERT)
-    public AjaxResult save(@RequestBody MonitorPoint entity) {
-        boolean saved = service.saveWithCheck(entity);
-        return saved ? AjaxResult.success("新增成功", saved) : AjaxResult.error("新增失败");
-    }
-
-    @PutMapping("/updateById")
-    @ApiOperation("修改监测点")
-    @Log(title = "修改监测点", businessType = BusinessType.UPDATE)
-    public AjaxResult updateById(@RequestBody MonitorPoint entity) {
-        boolean updated = service.updateWithCheck(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.removeWithCheck(id);
-        return deleted ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
-    }
-}

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

@@ -1,7 +1,6 @@
 package com.zksy.base.domain;
 package com.zksy.base.domain;
 
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -36,7 +35,4 @@ public class EquipmentPointRel {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private LocalDateTime createTime;
     private LocalDateTime createTime;
 
 
-    @TableField(exist = false)
-    @ApiModelProperty("删除标志(当前 schema 未提供)")
-    private String delFlag;
 }
 }

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

@@ -1,8 +1,8 @@
 package com.zksy.base.domain;
 package com.zksy.base.domain;
 
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -34,14 +34,6 @@ public class MonitorPoint {
     @ApiModelProperty("监测点名称")
     @ApiModelProperty("监测点名称")
     private String pointName;
     private String pointName;
 
 
-    @TableField(exist = false)
-    @ApiModelProperty("关联管网设施ID(当前 schema 未提供)")
-    private String networkId;
-
-    @TableField(exist = false)
-    @ApiModelProperty("监测点类型(当前 schema 未提供)")
-    private String pointType;
-
     @ApiModelProperty("位置描述")
     @ApiModelProperty("位置描述")
     private String location;
     private String location;
 
 
@@ -51,15 +43,6 @@ public class MonitorPoint {
     @ApiModelProperty("纬度")
     @ApiModelProperty("纬度")
     private BigDecimal latitude;
     private BigDecimal latitude;
 
 
-    @TableField(exist = false)
-    @ApiModelProperty("安装日期(当前 schema 未提供)")
-    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
-    private Date installationDate;
-
-    @TableField(exist = false)
-    @ApiModelProperty("状态(当前 schema 未提供)")
-    private String status;
-
     @ApiModelProperty("备注")
     @ApiModelProperty("备注")
     private String remark;
     private String remark;
 
 
@@ -80,4 +63,8 @@ public class MonitorPoint {
     @TableLogic(value = "0", delval = "2")
     @TableLogic(value = "0", delval = "2")
     @ApiModelProperty("删除标志(0=正常 2=删除)")
     @ApiModelProperty("删除标志(0=正常 2=删除)")
     private String delFlag;
     private String delFlag;
+
+    /** 当前关联设备数量,仅用于列表返回,不落库。 */
+    @TableField(exist = false)
+    private Long equipmentCount;
 }
 }

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

@@ -1,25 +0,0 @@
-package com.zksy.base.dto;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-
-import java.io.Serializable;
-
-@Data
-@ApiModel(value = "监测点分页查询入参", description = "监测点分页查询入参")
-public class MonitorPointPageInDTO implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    @ApiModelProperty(value = "监测点名称")
-    private String pointName;
-
-    @ApiModelProperty(value = "监测点类型")
-    private String pointType;
-
-    @ApiModelProperty(value = "当前记录起始索引", required = true)
-    private Long pageNum;
-
-    @ApiModelProperty(value = "每页显示记录数", required = true)
-    private Long pageSize;
-}

+ 1 - 2
pipe-network-service/zksy-system/src/main/java/com/zksy/base/mapper/EquipmentPointRelMapper.java

@@ -16,8 +16,7 @@ public interface EquipmentPointRelMapper extends BaseMapper<EquipmentPointRel> {
     /**
     /**
      * 物理删除指定设备的监测点关联。
      * 物理删除指定设备的监测点关联。
      *
      *
-     * <p>同 {@code equipment_status}:实体标注了 {@code @TableLogic},逻辑删除后行仍存在,
-     * 设备删除必须显式物理删除从属数据(#52)。</p>
+     * <p>保留显式删除方法,供设备删除流程清理关联记录。</p>
      */
      */
     @Delete("DELETE FROM app_user.equipment_point_rel WHERE equipment_id = #{equipmentId}")
     @Delete("DELETE FROM app_user.equipment_point_rel WHERE equipment_id = #{equipmentId}")
     int deletePhysicallyByEquipmentId(@Param("equipmentId") String equipmentId);
     int deletePhysicallyByEquipmentId(@Param("equipmentId") String equipmentId);

+ 5 - 7
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/MonitorPointService.java

@@ -3,17 +3,13 @@ package com.zksy.base.service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zksy.base.domain.MonitorPoint;
 import com.zksy.base.domain.MonitorPoint;
-import com.zksy.base.dto.MonitorPointPageInDTO;
 
 
-import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.List;
 
 
 public interface MonitorPointService extends IService<MonitorPoint> {
 public interface MonitorPointService extends IService<MonitorPoint> {
 
 
-    Page<MonitorPoint> queryByPage(MonitorPointPageInDTO dto);
-    Page<MonitorPoint> findByPage(long pageNum, long pageSize,
-                                    String pointCode, String pointName,
-                                    String pointType, String status);
+    Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName, String associationStatus);
 
 
     boolean saveWithCheck(MonitorPoint entity);
     boolean saveWithCheck(MonitorPoint entity);
 
 
@@ -31,5 +27,7 @@ public interface MonitorPointService extends IService<MonitorPoint> {
 
 
     Map<String, Object> getPointDetail(String pointId);
     Map<String, Object> getPointDetail(String pointId);
 
 
-    List<MonitorPoint> getPointsByNetwork(String networkId);
+    Map<String, Object> statistics();
+
+    List<Map<String, Object>> listEquipmentForAssociation(String pointId);
 }
 }

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

@@ -324,8 +324,8 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
         equipmentMaintainMapper.delete(maintainWrapper);
         equipmentMaintainMapper.delete(maintainWrapper);
         log.info("已删除设备[{}]的维护记录", equipmentId);
         log.info("已删除设备[{}]的维护记录", equipmentId);
 
 
-        // equipment_status / equipment_point_rel 带外键且标注了 @TableLogic,
-        // 逻辑删除只改 del_flag、行仍存在,会挡住 equipment_base 的物理删除,必须走物理删除语句(#52)
+        // equipment_status 带外键且标注了 @TableLogic,逻辑删除只改 del_flag、行仍存在,
+        // 会挡住 equipment_base 的物理删除,必须先物理清理从属数据(#52)。
         equipmentStatusMapper.deletePhysicallyByEquipmentId(equipmentId);
         equipmentStatusMapper.deletePhysicallyByEquipmentId(equipmentId);
         log.info("已删除设备[{}]的状态记录", equipmentId);
         log.info("已删除设备[{}]的状态记录", equipmentId);
 
 
@@ -1125,7 +1125,17 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
                 .map(EquipmentPointRel::getEquipmentId)
                 .map(EquipmentPointRel::getEquipmentId)
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
 
 
-        return this.listByIds(equipmentIds);
+        List<EquipmentBase> equipmentList = this.listByIds(equipmentIds);
+        Set<Integer> typeIds = equipmentList.stream()
+                .map(EquipmentBase::getEquipmentTypeId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        if (!typeIds.isEmpty()) {
+            Map<Integer, String> typeNameMap = equipmentTypeMapper.selectBatchIds(typeIds).stream()
+                    .collect(Collectors.toMap(EquipmentType::getId, EquipmentType::getTypeName, (left, right) -> left));
+            equipmentList.forEach(device -> device.setEquipmentTypeName(typeNameMap.get(device.getEquipmentTypeId())));
+        }
+        return equipmentList;
     }
     }
 
 
     /**
     /**

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

@@ -7,12 +7,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zksy.base.domain.EquipmentBase;
 import com.zksy.base.domain.EquipmentBase;
 import com.zksy.base.domain.EquipmentPointRel;
 import com.zksy.base.domain.EquipmentPointRel;
 import com.zksy.base.domain.MonitorPoint;
 import com.zksy.base.domain.MonitorPoint;
-import com.zksy.base.domain.PipeNetworkBase;
-import com.zksy.base.dto.MonitorPointPageInDTO;
 import com.zksy.base.mapper.EquipmentBaseMapper;
 import com.zksy.base.mapper.EquipmentBaseMapper;
 import com.zksy.base.mapper.EquipmentPointRelMapper;
 import com.zksy.base.mapper.EquipmentPointRelMapper;
+import com.zksy.base.mapper.EquipmentTypeMapper;
 import com.zksy.base.mapper.MonitorPointMapper;
 import com.zksy.base.mapper.MonitorPointMapper;
-import com.zksy.base.mapper.PipeNetworkBaseMapper;
 import com.zksy.base.service.MonitorPointService;
 import com.zksy.base.service.MonitorPointService;
 import com.zksy.common.exception.ServiceException;
 import com.zksy.common.exception.ServiceException;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
@@ -20,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
@@ -35,22 +34,10 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
     private EquipmentBaseMapper equipmentBaseMapper;
     private EquipmentBaseMapper equipmentBaseMapper;
 
 
     @Autowired
     @Autowired
-    private PipeNetworkBaseMapper pipeNetworkBaseMapper;
+    private EquipmentTypeMapper equipmentTypeMapper;
 
 
     @Override
     @Override
-    public Page<MonitorPoint> queryByPage(MonitorPointPageInDTO dto) {
-        Page<MonitorPoint> page = new Page<>(dto.getPageNum(), dto.getPageSize());
-        LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
-        wrapper.like(dto.getPointName() != null && !dto.getPointName().isEmpty(), MonitorPoint::getPointName, dto.getPointName());
-        wrapper.eq(dto.getPointType() != null && !dto.getPointType().isEmpty(), MonitorPoint::getPointType, dto.getPointType());
-        wrapper.orderByDesc(MonitorPoint::getCreateTime);
-        return this.page(page, wrapper);
-    }
-
-    @Override
-    public Page<MonitorPoint> findByPage(long pageNum, long pageSize,
-                                          String pointCode, String pointName,
-                                          String pointType, String status) {
+    public Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName, String associationStatus) {
         Page<MonitorPoint> page = new Page<>(pageNum, pageSize);
         Page<MonitorPoint> page = new Page<>(pageNum, pageSize);
         LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
         if (pointCode != null && !pointCode.isEmpty()) {
         if (pointCode != null && !pointCode.isEmpty()) {
@@ -59,24 +46,24 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
         if (pointName != null && !pointName.isEmpty()) {
         if (pointName != null && !pointName.isEmpty()) {
             queryWrapper.like(MonitorPoint::getPointName, pointName);
             queryWrapper.like(MonitorPoint::getPointName, pointName);
         }
         }
-        if (pointType != null && !pointType.isEmpty()) {
-            queryWrapper.eq(MonitorPoint::getPointType, pointType);
-        }
-        if (status != null && !status.isEmpty()) {
-            queryWrapper.eq(MonitorPoint::getStatus, status);
+        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());
+            if ("linked".equalsIgnoreCase(associationStatus)) {
+                queryWrapper.in(!linkedPointIds.isEmpty(), MonitorPoint::getPointId, linkedPointIds);
+                if (linkedPointIds.isEmpty()) queryWrapper.eq(MonitorPoint::getPointId, "__none__");
+            } else if (!linkedPointIds.isEmpty()) {
+                queryWrapper.notIn(MonitorPoint::getPointId, linkedPointIds);
+            }
         }
         }
         queryWrapper.orderByDesc(MonitorPoint::getCreateTime);
         queryWrapper.orderByDesc(MonitorPoint::getCreateTime);
-        return this.page(page, queryWrapper);
+        Page<MonitorPoint> result = this.page(page, queryWrapper);
+        result.getRecords().forEach(point -> point.setEquipmentCount(equipmentCount(point.getPointId())));
+        return result;
     }
     }
 
 
     @Override
     @Override
     public boolean saveWithCheck(MonitorPoint entity) {
     public boolean saveWithCheck(MonitorPoint entity) {
-        if (entity.getNetworkId() != null) {
-            PipeNetworkBase network = pipeNetworkBaseMapper.selectById(entity.getNetworkId());
-            if (network == null) {
-                throw new ServiceException("关联管网设施不存在:" + entity.getNetworkId());
-            }
-        }
         LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(MonitorPoint::getPointCode, entity.getPointCode());
         queryWrapper.eq(MonitorPoint::getPointCode, entity.getPointCode());
         long count = this.count(queryWrapper);
         long count = this.count(queryWrapper);
@@ -98,11 +85,6 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
         }
         }
 
 
         for (MonitorPoint entity : entityList) {
         for (MonitorPoint entity : entityList) {
-            if (entity.getNetworkId() != null) {
-                if (pipeNetworkBaseMapper.selectById(entity.getNetworkId()) == null) {
-                    throw new ServiceException("关联管网设施不存在:" + entity.getNetworkId());
-                }
-            }
             LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
             LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
             wrapper.eq(MonitorPoint::getPointCode, entity.getPointCode());
             wrapper.eq(MonitorPoint::getPointCode, entity.getPointCode());
             if (this.count(wrapper) > 0) {
             if (this.count(wrapper) > 0) {
@@ -120,12 +102,6 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
             throw new ServiceException("监测点不存在,无法修改:" + pointId);
             throw new ServiceException("监测点不存在,无法修改:" + pointId);
         }
         }
 
 
-        if (entity.getNetworkId() != null) {
-            if (pipeNetworkBaseMapper.selectById(entity.getNetworkId()) == null) {
-                throw new ServiceException("关联管网设施不存在:" + entity.getNetworkId());
-            }
-        }
-
         String newCode = entity.getPointCode();
         String newCode = entity.getPointCode();
         if (newCode != null) {
         if (newCode != null) {
             LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
             LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
@@ -148,8 +124,9 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
 
 
         LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
         relWrapper.eq(EquipmentPointRel::getPointId, pointId);
         relWrapper.eq(EquipmentPointRel::getPointId, pointId);
-        equipmentPointRelMapper.delete(relWrapper);
-        log.info("已删除监测点[{}]的设备关联关系", pointId);
+        if (equipmentPointRelMapper.selectCount(relWrapper) > 0) {
+            throw new ServiceException("监测点仍有关联设备,请先解除关联");
+        }
 
 
         return this.removeById(pointId);
         return this.removeById(pointId);
     }
     }
@@ -179,8 +156,9 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
 
 
         LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
         relWrapper.in(EquipmentPointRel::getPointId, existIds);
         relWrapper.in(EquipmentPointRel::getPointId, existIds);
-        equipmentPointRelMapper.delete(relWrapper);
-        log.info("已批量删除{}条监测点的设备关联关系", existIds.size());
+        if (equipmentPointRelMapper.selectCount(relWrapper) > 0) {
+            throw new ServiceException("选中的监测点仍有关联设备,请先解除关联");
+        }
 
 
         return this.removeByIds(existIds);
         return this.removeByIds(existIds);
     }
     }
@@ -192,6 +170,10 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
         if (point == null) {
         if (point == null) {
             throw new ServiceException("监测点不存在:" + pointId);
             throw new ServiceException("监测点不存在:" + pointId);
         }
         }
+        if (CollectionUtils.isEmpty(equipmentIds)) {
+            throw new ServiceException("设备ID列表不能为空");
+        }
+        equipmentIds = new ArrayList<>(new LinkedHashSet<>(equipmentIds));
 
 
         for (String equipmentId : equipmentIds) {
         for (String equipmentId : equipmentIds) {
             EquipmentBase equipment = equipmentBaseMapper.selectById(equipmentId);
             EquipmentBase equipment = equipmentBaseMapper.selectById(equipmentId);
@@ -199,18 +181,21 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
                 throw new ServiceException("设备不存在:" + equipmentId);
                 throw new ServiceException("设备不存在:" + equipmentId);
             }
             }
             LambdaQueryWrapper<EquipmentPointRel> checkWrapper = new LambdaQueryWrapper<>();
             LambdaQueryWrapper<EquipmentPointRel> checkWrapper = new LambdaQueryWrapper<>();
-            checkWrapper.eq(EquipmentPointRel::getPointId, pointId)
-                    .eq(EquipmentPointRel::getEquipmentId, equipmentId);
-            if (equipmentPointRelMapper.selectCount(checkWrapper) > 0) {
-                throw new ServiceException("设备已绑定此监测点:" + equipmentId);
+            checkWrapper.eq(EquipmentPointRel::getEquipmentId, equipmentId);
+            List<EquipmentPointRel> existing = equipmentPointRelMapper.selectList(checkWrapper);
+            if (!existing.isEmpty() && existing.stream().noneMatch(rel -> pointId.equals(rel.getPointId()))) {
+                throw new ServiceException("设备已归属其他监测点:" + equipmentId);
             }
             }
+            if (!existing.isEmpty()) throw new ServiceException("设备已绑定此监测点:" + equipmentId);
         }
         }
 
 
         List<EquipmentPointRel> relList = new ArrayList<>();
         List<EquipmentPointRel> relList = new ArrayList<>();
+        LocalDateTime now = LocalDateTime.now();
         for (String equipmentId : equipmentIds) {
         for (String equipmentId : equipmentIds) {
             EquipmentPointRel rel = new EquipmentPointRel();
             EquipmentPointRel rel = new EquipmentPointRel();
             rel.setPointId(pointId);
             rel.setPointId(pointId);
             rel.setEquipmentId(equipmentId);
             rel.setEquipmentId(equipmentId);
+            rel.setCreateTime(now);
             relList.add(rel);
             relList.add(rel);
         }
         }
 
 
@@ -241,11 +226,6 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
         Map<String, Object> result = new HashMap<>();
         Map<String, Object> result = new HashMap<>();
         result.put("pointInfo", point);
         result.put("pointInfo", point);
 
 
-        if (point.getNetworkId() != null) {
-            PipeNetworkBase network = pipeNetworkBaseMapper.selectById(point.getNetworkId());
-            result.put("networkInfo", network);
-        }
-
         LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
         relWrapper.eq(EquipmentPointRel::getPointId, pointId);
         relWrapper.eq(EquipmentPointRel::getPointId, pointId);
         List<EquipmentPointRel> relList = equipmentPointRelMapper.selectList(relWrapper);
         List<EquipmentPointRel> relList = equipmentPointRelMapper.selectList(relWrapper);
@@ -254,17 +234,59 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
                     .map(EquipmentPointRel::getEquipmentId)
                     .map(EquipmentPointRel::getEquipmentId)
                     .collect(Collectors.toList());
                     .collect(Collectors.toList());
             List<EquipmentBase> equipmentList = equipmentBaseMapper.selectBatchIds(equipmentIds);
             List<EquipmentBase> equipmentList = equipmentBaseMapper.selectBatchIds(equipmentIds);
+            fillEquipmentTypeNames(equipmentList);
             result.put("equipmentList", equipmentList);
             result.put("equipmentList", equipmentList);
         }
         }
 
 
+        result.put("equipmentList", result.getOrDefault("equipmentList", Collections.emptyList()));
+        return result;
+    }
+
+    @Override
+    public Map<String, Object> statistics() {
+        List<EquipmentPointRel> relations = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>());
+        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("linkedPoints", linkedPointIds.size());
+        result.put("pendingPoints", Math.max(0, this.count() - linkedPointIds.size()));
+        result.put("totalDevices", relations.stream().map(EquipmentPointRel::getEquipmentId).filter(Objects::nonNull).distinct().count());
         return result;
         return result;
     }
     }
 
 
     @Override
     @Override
-    public List<MonitorPoint> getPointsByNetwork(String networkId) {
-        LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(MonitorPoint::getNetworkId, networkId);
-        wrapper.orderByDesc(MonitorPoint::getCreateTime);
-        return this.list(wrapper);
+    public List<Map<String, Object>> listEquipmentForAssociation(String pointId) {
+        Map<String, String> ownerByEquipment = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>()).stream()
+                .filter(rel -> rel.getEquipmentId() != null)
+                .collect(Collectors.toMap(EquipmentPointRel::getEquipmentId, EquipmentPointRel::getPointId, (left, right) -> left));
+        List<EquipmentBase> devices = equipmentBaseMapper.selectList(null);
+        fillEquipmentTypeNames(devices);
+        return devices.stream().map(device -> {
+            Map<String, Object> row = new LinkedHashMap<>();
+            row.put("equipmentId", device.getEquipmentId());
+            row.put("equipmentCode", device.getEquipmentCode());
+            row.put("equipmentName", device.getEquipmentName());
+            row.put("equipmentTypeName", device.getEquipmentTypeName());
+            row.put("equipmentLocation", device.getEquipmentLocation());
+            String owner = ownerByEquipment.get(device.getEquipmentId());
+            if (owner != null && !owner.equals(pointId)) row.put("boundPointId", owner);
+            return row;
+        }).collect(Collectors.toList());
+    }
+
+    private void fillEquipmentTypeNames(List<EquipmentBase> devices) {
+        if (devices == null || devices.isEmpty()) return;
+        Set<Integer> typeIds = devices.stream()
+                .map(EquipmentBase::getEquipmentTypeId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        if (typeIds.isEmpty()) return;
+        equipmentTypeMapper.selectBatchIds(typeIds).forEach(type -> devices.stream()
+                .filter(device -> Objects.equals(device.getEquipmentTypeId(), type.getId()))
+                .forEach(device -> device.setEquipmentTypeName(type.getTypeName())));
+    }
+
+    private long equipmentCount(String pointId) {
+        return equipmentPointRelMapper.selectCount(new LambdaQueryWrapper<EquipmentPointRel>().eq(EquipmentPointRel::getPointId, pointId));
     }
     }
 }
 }

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

@@ -49,7 +49,6 @@ public class PressureMonitorServiceImpl implements PressureMonitorService {
     public List<Map<String, Object>> getPoints() {
     public List<Map<String, Object>> getPoints() {
         List<MonitorPoint> points = monitorPointMapper.selectList(
         List<MonitorPoint> points = monitorPointMapper.selectList(
                 new LambdaQueryWrapper<MonitorPoint>()
                 new LambdaQueryWrapper<MonitorPoint>()
-                        .eq(MonitorPoint::getPointType, "GAS")
                         .eq(MonitorPoint::getDelFlag, "0")
                         .eq(MonitorPoint::getDelFlag, "0")
         );
         );
 
 
@@ -194,7 +193,6 @@ public class PressureMonitorServiceImpl implements PressureMonitorService {
         List<EquipmentPointRel> rels = equipmentPointRelMapper.selectList(
         List<EquipmentPointRel> rels = equipmentPointRelMapper.selectList(
                 new LambdaQueryWrapper<EquipmentPointRel>()
                 new LambdaQueryWrapper<EquipmentPointRel>()
                         .eq(EquipmentPointRel::getPointId, pointId)
                         .eq(EquipmentPointRel::getPointId, pointId)
-                        .eq(EquipmentPointRel::getDelFlag, "0")
         );
         );
         if (rels.isEmpty()) return null;
         if (rels.isEmpty()) return null;
         List<EquipmentBase> eqs = equipmentBaseMapper.selectBatchIds(
         List<EquipmentBase> eqs = equipmentBaseMapper.selectBatchIds(

+ 16 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/drainage/service/impl/DrainageEquipmentPointRelServiceImpl.java

@@ -72,6 +72,12 @@ public class DrainageEquipmentPointRelServiceImpl extends ServiceImpl<EquipmentP
         if (this.count(wrapper) > 0) {
         if (this.count(wrapper) > 0) {
             throw new ServiceException("该设备与监测点的关联关系已存在");
             throw new ServiceException("该设备与监测点的关联关系已存在");
         }
         }
+        LambdaQueryWrapper<EquipmentPointRel> ownerWrapper = new LambdaQueryWrapper<>();
+        ownerWrapper.eq(EquipmentPointRel::getEquipmentId, equipmentId)
+                .ne(EquipmentPointRel::getPointId, pointId);
+        if (this.count(ownerWrapper) > 0) {
+            throw new ServiceException("该设备已归属其他监测点,不能重复关联");
+        }
         entity.setCreateTime(LocalDateTime.now());
         entity.setCreateTime(LocalDateTime.now());
         return this.save(entity);
         return this.save(entity);
     }
     }
@@ -82,6 +88,9 @@ public class DrainageEquipmentPointRelServiceImpl extends ServiceImpl<EquipmentP
         Set<String> equipmentIds = entityList.stream()
         Set<String> equipmentIds = entityList.stream()
                 .map(EquipmentPointRel::getEquipmentId)
                 .map(EquipmentPointRel::getEquipmentId)
                 .collect(Collectors.toSet());
                 .collect(Collectors.toSet());
+        if (equipmentIds.size() != entityList.size()) {
+            throw new ServiceException("批量关联中存在重复设备,一个设备只能关联一个监测点");
+        }
         List<String> existEqIds = equipmentBaseMapper.selectBatchIds(equipmentIds).stream()
         List<String> existEqIds = equipmentBaseMapper.selectBatchIds(equipmentIds).stream()
                 .map(EquipmentBase::getEquipmentId)
                 .map(EquipmentBase::getEquipmentId)
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
@@ -103,6 +112,13 @@ public class DrainageEquipmentPointRelServiceImpl extends ServiceImpl<EquipmentP
         if (!invalidPointIds.isEmpty()) {
         if (!invalidPointIds.isEmpty()) {
             throw new ServiceException("存在无效的监测点ID:" + invalidPointIds);
             throw new ServiceException("存在无效的监测点ID:" + invalidPointIds);
         }
         }
+        Set<String> duplicateEquipmentIds = equipmentIds.stream()
+                .filter(equipmentId -> this.count(new LambdaQueryWrapper<EquipmentPointRel>()
+                        .eq(EquipmentPointRel::getEquipmentId, equipmentId)) > 0)
+                .collect(Collectors.toSet());
+        if (!duplicateEquipmentIds.isEmpty()) {
+            throw new ServiceException("以下设备已归属监测点,不能重复关联:" + duplicateEquipmentIds);
+        }
         LocalDateTime now = LocalDateTime.now();
         LocalDateTime now = LocalDateTime.now();
         entityList.forEach(e -> e.setCreateTime(now));
         entityList.forEach(e -> e.setCreateTime(now));
         return this.saveBatch(entityList);
         return this.saveBatch(entityList);

+ 1 - 1
pipe-network-service/zksy-system/src/test/java/com/zksy/base/service/impl/EquipmentBaseServiceImplTest.java

@@ -37,7 +37,7 @@ import static org.mockito.Mockito.when;
 /**
 /**
  * Gogs #52:设备删除必须真正清掉从属数据。
  * Gogs #52:设备删除必须真正清掉从属数据。
  *
  *
- * <p>根因:{@code equipment_status} / {@code equipment_point_rel} 标注了 {@code @TableLogic},
+ * <p>根因:{@code equipment_status} 标注了 {@code @TableLogic},
  * MyBatis-Plus 的 {@code delete(wrapper)} 只把 del_flag 改成 '2',行仍物理存在,
  * MyBatis-Plus 的 {@code delete(wrapper)} 只把 del_flag 改成 '2',行仍物理存在,
  * 于是 KingbaseES 的外键 {@code fk_equipment_status} 继续阻止 {@code equipment_base} 的物理删除。
  * 于是 KingbaseES 的外键 {@code fk_equipment_status} 继续阻止 {@code equipment_base} 的物理删除。
  * 因此删除设备时必须走物理删除语句。</p>
  * 因此删除设备时必须走物理删除语句。</p>