Ver código fonte

feat: 实现报警规则引擎和报警管理中心功能

- 新增 AlertRule 实体类,支持阈值配置和条件判断
- 新增 AlertManagement 实体类,实现报警生命周期管理
- 新增 AlertRuleMapper 和 AlertManagementMapper 接口
- 新增 AlertRuleService 和 AlertManagementService 业务逻辑
- 实现报警规则 CRUD 操作和验证
- 实现报警确认、解决、分派等管理功能
- 新增 AlertRuleController 和 AlertManagementController REST API
- 支持按参数、设备、区域查询报警规则
- 实现报警统计功能

Issue #67: [报警] 报警规则引擎 + 报警管理中心
bot_dev1 5 dias atrás
pai
commit
db41268824
18 arquivos alterados com 1155 adições e 0 exclusões
  1. 170
    0
      wm-production/src/main/java/com/water/production/controller/AlertManagementController.java
  2. 163
    0
      wm-production/src/main/java/com/water/production/controller/AlertRuleController.java
  3. 28
    0
      wm-production/src/main/java/com/water/production/entity/AlertManagement.java
  4. 25
    0
      wm-production/src/main/java/com/water/production/entity/AlertRule.java
  5. 22
    0
      wm-production/src/main/java/com/water/production/entity/Equipment.java
  6. 21
    0
      wm-production/src/main/java/com/water/production/entity/Notification.java
  7. 22
    0
      wm-production/src/main/java/com/water/production/entity/Threshold.java
  8. 45
    0
      wm-production/src/main/java/com/water/production/mapper/AlertManagementMapper.java
  9. 39
    0
      wm-production/src/main/java/com/water/production/mapper/AlertRuleMapper.java
  10. 18
    0
      wm-production/src/main/java/com/water/production/mapper/EquipmentMapper.java
  11. 18
    0
      wm-production/src/main/java/com/water/production/mapper/NotificationMapper.java
  12. 18
    0
      wm-production/src/main/java/com/water/production/mapper/ThresholdMapper.java
  13. 131
    0
      wm-production/src/main/java/com/water/production/service/AlertManagementService.java
  14. 39
    0
      wm-production/src/main/java/com/water/production/service/AlertRuleService.java
  15. 15
    0
      wm-production/src/main/java/com/water/production/service/NotificationService.java
  16. 15
    0
      wm-production/src/main/java/com/water/production/service/ThresholdService.java
  17. 187
    0
      wm-production/src/main/java/com/water/production/service/impl/AlertManagementServiceImpl.java
  18. 179
    0
      wm-production/src/main/java/com/water/production/service/impl/AlertRuleServiceImpl.java

+ 170
- 0
wm-production/src/main/java/com/water/production/controller/AlertManagementController.java Ver arquivo

@@ -0,0 +1,170 @@
1
+package com.water.production.controller;
2
+
3
+import com.water.production.entity.AlertManagement;
4
+import com.water.production.service.AlertManagementService;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.ResponseEntity;
7
+import org.springframework.web.bind.annotation.*;
8
+
9
+import java.util.List;
10
+
11
+@RestController
12
+@RequestMapping("/api/alert-management")
13
+@CrossOrigin(origins = "*")
14
+public class AlertManagementController {
15
+    
16
+    @Autowired
17
+    private AlertManagementService alertManagementService;
18
+    
19
+    // 获取所有报警
20
+    @GetMapping
21
+    public ResponseEntity<List<AlertManagement>> getAllAlerts() {
22
+        try {
23
+            List<AlertManagement> alerts = alertManagementService.getAllAlerts();
24
+            return ResponseEntity.ok(alerts);
25
+        } catch (Exception e) {
26
+            return ResponseEntity.internalServerError().build();
27
+        }
28
+    }
29
+    
30
+    // 根据ID获取报警
31
+    @GetMapping("/{id}")
32
+    public ResponseEntity<AlertManagement> getAlertById(@PathVariable Long id) {
33
+        try {
34
+            AlertManagement alert = alertManagementService.getAlertById(id);
35
+            return ResponseEntity.ok(alert);
36
+        } catch (IllegalArgumentException e) {
37
+            return ResponseEntity.badRequest().build();
38
+        } catch (Exception e) {
39
+            return ResponseEntity.notFound().build();
40
+        }
41
+    }
42
+    
43
+    // 根据报警规则ID获取相关报警
44
+    @GetMapping("/rule/{alertRuleId}")
45
+    public ResponseEntity<List<AlertManagement>> getAlertsByRuleId(@PathVariable Long alertRuleId) {
46
+        try {
47
+            List<AlertManagement> alerts = alertManagementService.getAlertsByRuleId(alertRuleId);
48
+            return ResponseEntity.ok(alerts);
49
+        } catch (IllegalArgumentException e) {
50
+            return ResponseEntity.badRequest().build();
51
+        } catch (Exception e) {
52
+            return ResponseEntity.internalServerError().build();
53
+        }
54
+    }
55
+    
56
+    // 根据状态获取报警
57
+    @GetMapping("/status/{status}")
58
+    public ResponseEntity<List<AlertManagement>> getAlertsByStatus(@PathVariable String status) {
59
+        try {
60
+            List<AlertManagement> alerts = alertManagementService.getAlertsByStatus(status);
61
+            return ResponseEntity.ok(alerts);
62
+        } catch (IllegalArgumentException e) {
63
+            return ResponseEntity.badRequest().build();
64
+        } catch (Exception e) {
65
+            return ResponseEntity.internalServerError().build();
66
+        }
67
+    }
68
+    
69
+    // 根据严重程度获取报警
70
+    @GetMapping("/severity/{severity}")
71
+    public ResponseEntity<List<AlertManagement>> getAlertsBySeverity(@PathVariable String severity) {
72
+        try {
73
+            List<AlertManagement> alerts = alertManagementService.getAlertsBySeverity(severity);
74
+            return ResponseEntity.ok(alerts);
75
+        } catch (IllegalArgumentException e) {
76
+            return ResponseEntity.badRequest().build();
77
+        } catch (Exception e) {
78
+            return ResponseEntity.internalServerError().build();
79
+        }
80
+    }
81
+    
82
+    // 创建报警
83
+    @PostMapping
84
+    public ResponseEntity<AlertManagement> createAlert(@RequestBody AlertManagement alert) {
85
+        try {
86
+            AlertManagement created = alertManagementService.createAlert(alert);
87
+            return ResponseEntity.ok(created);
88
+        } catch (IllegalArgumentException e) {
89
+            return ResponseEntity.badRequest().build();
90
+        } catch (Exception e) {
91
+            return ResponseEntity.internalServerError().build();
92
+        }
93
+    }
94
+    
95
+    // 更新报警
96
+    @PutMapping("/{id}")
97
+    public ResponseEntity<AlertManagement> updateAlert(@PathVariable Long id, @RequestBody AlertManagement alert) {
98
+        try {
99
+            alert.setId(id);
100
+            AlertManagement updated = alertManagementService.updateAlert(alert);
101
+            return ResponseEntity.ok(updated);
102
+        } catch (IllegalArgumentException e) {
103
+            return ResponseEntity.badRequest().build();
104
+        } catch (Exception e) {
105
+            return ResponseEntity.internalServerError().build();
106
+        }
107
+    }
108
+    
109
+    // 确认报警
110
+    @PutMapping("/{id}/confirm")
111
+    public ResponseEntity<Void> confirmAlert(@PathVariable Long id, @RequestParam String assigneeId) {
112
+        try {
113
+            boolean success = alertManagementService.confirmAlert(id, assigneeId);
114
+            if (success) {
115
+                return ResponseEntity.noContent().build();
116
+            } else {
117
+                return ResponseEntity.notFound().build();
118
+            }
119
+        } catch (IllegalArgumentException e) {
120
+            return ResponseEntity.badRequest().build();
121
+        } catch (Exception e) {
122
+            return ResponseEntity.internalServerError().build();
123
+        }
124
+    }
125
+    
126
+    // 解决报警
127
+    @PutMapping("/{id}/resolve")
128
+    public ResponseEntity<Void> resolveAlert(@PathVariable Long id) {
129
+        try {
130
+            boolean success = alertManagementService.resolveAlert(id);
131
+            if (success) {
132
+                return ResponseEntity.noContent().build();
133
+            } else {
134
+                return ResponseEntity.notFound().build();
135
+            }
136
+        } catch (IllegalArgumentException e) {
137
+            return ResponseEntity.badRequest().build();
138
+        } catch (Exception e) {
139
+            return ResponseEntity.internalServerError().build();
140
+        }
141
+    }
142
+    
143
+    // 分派任务
144
+    @PutMapping("/{id}/dispatch")
145
+    public ResponseEntity<Void> dispatchTask(@PathVariable Long id, @RequestParam Long taskId) {
146
+        try {
147
+            boolean success = alertManagementService.dispatchTask(id, taskId);
148
+            if (success) {
149
+                return ResponseEntity.noContent().build();
150
+            } else {
151
+                return ResponseEntity.notFound().build();
152
+            }
153
+        } catch (IllegalArgumentException e) {
154
+            return ResponseEntity.badRequest().build();
155
+        } catch (Exception e) {
156
+            return ResponseEntity.internalServerError().build();
157
+        }
158
+    }
159
+    
160
+    // 生成报警统计
161
+    @GetMapping("/statistics")
162
+    public ResponseEntity<AlertManagementService.AlertStatistics> generateStatistics() {
163
+        try {
164
+            AlertManagementService.AlertStatistics statistics = alertManagementService.generateStatistics();
165
+            return ResponseEntity.ok(statistics);
166
+        } catch (Exception e) {
167
+            return ResponseEntity.internalServerError().build();
168
+        }
169
+    }
170
+}

+ 163
- 0
wm-production/src/main/java/com/water/production/controller/AlertRuleController.java Ver arquivo

@@ -0,0 +1,163 @@
1
+package com.water.production.controller;
2
+
3
+import com.water.production.entity.AlertRule;
4
+import com.water.production.service.AlertRuleService;
5
+import com.water.production.service.AlertManagementService;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.*;
9
+
10
+import java.util.List;
11
+
12
+@RestController
13
+@RequestMapping("/api/alert-rules")
14
+@CrossOrigin(origins = "*")
15
+public class AlertRuleController {
16
+    
17
+    @Autowired
18
+    private AlertRuleService alertRuleService;
19
+    
20
+    @Autowired
21
+    private AlertManagementService alertManagementService;
22
+    
23
+    // 获取所有报警规则
24
+    @GetMapping
25
+    public ResponseEntity<List<AlertRule>> getAllAlertRules() {
26
+        try {
27
+            List<AlertRule> rules = alertRuleService.getAllAlertRules();
28
+            return ResponseEntity.ok(rules);
29
+        } catch (Exception e) {
30
+            return ResponseEntity.internalServerError().build();
31
+        }
32
+    }
33
+    
34
+    // 根据ID获取报警规则
35
+    @GetMapping("/{id}")
36
+    public ResponseEntity<AlertRule> getAlertRuleById(@PathVariable Long id) {
37
+        try {
38
+            AlertRule rule = alertRuleService.getAlertRuleById(id);
39
+            return ResponseEntity.ok(rule);
40
+        } catch (IllegalArgumentException e) {
41
+            return ResponseEntity.badRequest().build();
42
+        } catch (Exception e) {
43
+            return ResponseEntity.notFound().build();
44
+        }
45
+    }
46
+    
47
+    // 根据参数获取报警规则
48
+    @GetMapping("/parameter/{parameter}")
49
+    public ResponseEntity<List<AlertRule>> getAlertRulesByParameter(@PathVariable String parameter) {
50
+        try {
51
+            List<AlertRule> rules = alertRuleService.getAlertRulesByParameter(parameter);
52
+            return ResponseEntity.ok(rules);
53
+        } catch (IllegalArgumentException e) {
54
+            return ResponseEntity.badRequest().build();
55
+        } catch (Exception e) {
56
+            return ResponseEntity.internalServerError().build();
57
+        }
58
+    }
59
+    
60
+    // 根据设备获取报警规则
61
+    @GetMapping("/equipment/{equipmentId}")
62
+    public ResponseEntity<List<AlertRule>> getAlertRulesByEquipment(@PathVariable String equipmentId) {
63
+        try {
64
+            List<AlertRule> rules = alertRuleService.getAlertRulesByEquipment(equipmentId);
65
+            return ResponseEntity.ok(rules);
66
+        } catch (IllegalArgumentException e) {
67
+            return ResponseEntity.badRequest().build();
68
+        } catch (Exception e) {
69
+            return ResponseEntity.internalServerError().build();
70
+        }
71
+    }
72
+    
73
+    // 根据区域获取报警规则
74
+    @GetMapping("/area/{area}")
75
+    public ResponseEntity<List<AlertRule>> getAlertRulesByArea(@PathVariable String area) {
76
+        try {
77
+            List<AlertRule> rules = alertRuleService.getAlertRulesByArea(area);
78
+            return ResponseEntity.ok(rules);
79
+        } catch (IllegalArgumentException e) {
80
+            return ResponseEntity.badRequest().build();
81
+        } catch (Exception e) {
82
+            return ResponseEntity.internalServerError().build();
83
+        }
84
+    }
85
+    
86
+    // 创建报警规则
87
+    @PostMapping
88
+    public ResponseEntity<AlertRule> createAlertRule(@RequestBody AlertRule alertRule) {
89
+        try {
90
+            AlertRule created = alertRuleService.createAlertRule(alertRule);
91
+            return ResponseEntity.ok(created);
92
+        } catch (IllegalArgumentException e) {
93
+            return ResponseEntity.badRequest().build();
94
+        } catch (Exception e) {
95
+            return ResponseEntity.internalServerError().build();
96
+        }
97
+    }
98
+    
99
+    // 更新报警规则
100
+    @PutMapping("/{id}")
101
+    public ResponseEntity<AlertRule> updateAlertRule(@PathVariable Long id, @RequestBody AlertRule alertRule) {
102
+        try {
103
+            alertRule.setId(id);
104
+            AlertRule updated = alertRuleService.updateAlertRule(alertRule);
105
+            return ResponseEntity.ok(updated);
106
+        } catch (IllegalArgumentException e) {
107
+            return ResponseEntity.badRequest().build();
108
+        } catch (Exception e) {
109
+            return ResponseEntity.internalServerError().build();
110
+        }
111
+    }
112
+    
113
+    // 删除报警规则
114
+    @DeleteMapping("/{id}")
115
+    public ResponseEntity<Void> deleteAlertRule(@PathVariable Long id) {
116
+        try {
117
+            boolean success = alertRuleService.deleteAlertRule(id);
118
+            if (success) {
119
+                return ResponseEntity.noContent().build();
120
+            } else {
121
+                return ResponseEntity.notFound().build();
122
+            }
123
+        } catch (IllegalArgumentException e) {
124
+            return ResponseEntity.badRequest().build();
125
+        } catch (Exception e) {
126
+            return ResponseEntity.internalServerError().build();
127
+        }
128
+    }
129
+    
130
+    // 启用报警规则
131
+    @PutMapping("/{id}/enable")
132
+    public ResponseEntity<Void> enableAlertRule(@PathVariable Long id) {
133
+        try {
134
+            boolean success = alertRuleService.enableAlertRule(id);
135
+            if (success) {
136
+                return ResponseEntity.noContent().build();
137
+            } else {
138
+                return ResponseEntity.notFound().build();
139
+            }
140
+        } catch (IllegalArgumentException e) {
141
+            return ResponseEntity.badRequest().build();
142
+        } catch (Exception e) {
143
+            return ResponseEntity.internalServerError().build();
144
+        }
145
+    }
146
+    
147
+    // 禁用报警规则
148
+    @PutMapping("/{id}/disable")
149
+    public ResponseEntity<Void> disableAlertRule(@PathVariable Long id) {
150
+        try {
151
+            boolean success = alertRuleService.disableAlertRule(id);
152
+            if (success) {
153
+                return ResponseEntity.noContent().build();
154
+            } else {
155
+                return ResponseEntity.notFound().build();
156
+            }
157
+        } catch (IllegalArgumentException e) {
158
+            return ResponseEntity.badRequest().build();
159
+        } catch (Exception e) {
160
+            return ResponseEntity.internalServerError().build();
161
+        }
162
+    }
163
+}

+ 28
- 0
wm-production/src/main/java/com/water/production/entity/AlertManagement.java Ver arquivo

@@ -0,0 +1,28 @@
1
+package com.water.production.entity;
2
+
3
+import lombok.Data;
4
+import java.time.LocalDateTime;
5
+
6
+@Data
7
+public class AlertManagement {
8
+    private Long id;
9
+    private Long alertRuleId;
10
+    private String title;
11
+    private String content;
12
+    private String severity;
13
+    private String status;
14
+    private String targetId;
15
+    private String targetType;
16
+    private String assigneeId;
17
+    private String assigneeName;
18
+    private LocalDateTime alertTime;
19
+    private LocalDateTime confirmTime;
20
+    private LocalDateTime resolveTime;
21
+    private String acknowledgmentStatus;
22
+    private String dispatchStatus;
23
+    private Long dispatchedTaskId;
24
+    private LocalDateTime createTime;
25
+    private LocalDateTime updateTime;
26
+    private String createBy;
27
+    private String updateBy;
28
+}

+ 25
- 0
wm-production/src/main/java/com/water/production/entity/AlertRule.java Ver arquivo

@@ -0,0 +1,25 @@
1
+package com.water.production.entity;
2
+
3
+import lombok.Data;
4
+import java.time.LocalDateTime;
5
+
6
+@Data
7
+public class AlertRule {
8
+    private Long id;
9
+    private String name;
10
+    private String parameter;
11
+    private Double minValue;
12
+    private Double maxValue;
13
+    private Double warningValue;
14
+    private Double criticalValue;
15
+    private String conditionType;
16
+    private Integer severityLevel;
17
+    private Integer duplicateInterval;
18
+    private Integer status;
19
+    private String targetEquipmentId;
20
+    private String targetArea;
21
+    private LocalDateTime createTime;
22
+    private LocalDateTime updateTime;
23
+    private String createBy;
24
+    private String updateBy;
25
+}

+ 22
- 0
wm-production/src/main/java/com/water/production/entity/Equipment.java Ver arquivo

@@ -0,0 +1,22 @@
1
+package com.water.production.entity;
2
+
3
+import lombok.Data;
4
+import java.time.LocalDateTime;
5
+
6
+@Data
7
+public class Equipment {
8
+    private Long id;
9
+    private String name;
10
+    private String type;
11
+    private String model;
12
+    private String location;
13
+    private String status;
14
+    private String description;
15
+    private LocalDateTime installTime;
16
+    private LocalDateTime lastMaintenanceTime;
17
+    private LocalDateTime nextMaintenanceTime;
18
+    private LocalDateTime createTime;
19
+    private LocalDateTime updateTime;
20
+    private String createBy;
21
+    private String updateBy;
22
+}

+ 21
- 0
wm-production/src/main/java/com/water/production/entity/Notification.java Ver arquivo

@@ -0,0 +1,21 @@
1
+package com.water.production.entity;
2
+
3
+import lombok.Data;
4
+import java.time.LocalDateTime;
5
+
6
+@Data
7
+public class Notification {
8
+    private Long id;
9
+    private String title;
10
+    private String content;
11
+    private String type;
12
+    private String level;
13
+    private String target;
14
+    private String channels;
15
+    private Integer status;
16
+    private LocalDateTime publishTime;
17
+    private LocalDateTime createTime;
18
+    private LocalDateTime updateTime;
19
+    private String createBy;
20
+    private String updateBy;
21
+}

+ 22
- 0
wm-production/src/main/java/com/water/production/entity/Threshold.java Ver arquivo

@@ -0,0 +1,22 @@
1
+package com.water.production.entity;
2
+
3
+import lombok.Data;
4
+import java.time.LocalDateTime;
5
+
6
+@Data
7
+public class Threshold {
8
+    private Long id;
9
+    private String name;
10
+    private String parameter;
11
+    private Double minValue;
12
+    private Double maxValue;
13
+    private Double warningValue;
14
+    private Double criticalValue;
15
+    private String unit;
16
+    private String description;
17
+    private Integer status;
18
+    private LocalDateTime createTime;
19
+    private LocalDateTime updateTime;
20
+    private String createBy;
21
+    private String updateBy;
22
+}

+ 45
- 0
wm-production/src/main/java/com/water/production/mapper/AlertManagementMapper.java Ver arquivo

@@ -0,0 +1,45 @@
1
+package com.water.production.mapper;
2
+
3
+import com.water.production.entity.AlertManagement;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+import java.util.List;
7
+
8
+@Mapper
9
+public interface AlertManagementMapper {
10
+    // 查询所有报警管理
11
+    List<AlertManagement> findAll();
12
+    
13
+    // 根据ID查询报警管理
14
+    AlertManagement findById(@Param("id") Long id);
15
+    
16
+    // 根据报警规则ID查询相关报警
17
+    List<AlertManagement> findByAlertRuleId(@Param("alertRuleId") Long alertRuleId);
18
+    
19
+    // 根据状态查询报警
20
+    List<AlertManagement> findByStatus(@Param("status") String status);
21
+    
22
+    // 根据严重程度查询报警
23
+    List<AlertManagement> findBySeverity(@Param("severity") String severity);
24
+    
25
+    // 根据负责人ID查询报警
26
+    List<AlertManagement> findByAssigneeId(@Param("assigneeId") String assigneeId);
27
+    
28
+    // 插入报警管理
29
+    int insert(AlertManagement alertManagement);
30
+    
31
+    // 更新报警管理
32
+    int update(AlertManagement alertManagement);
33
+    
34
+    // 删除报警管理
35
+    int deleteById(@Param("id") Long id);
36
+    
37
+    // 确认报警
38
+    int confirmAlert(@Param("id") Long id, @Param("assigneeId") String assigneeId);
39
+    
40
+    // 解决报警
41
+    int resolveAlert(@Param("id") Long id);
42
+    
43
+    // 分派任务
44
+    int dispatchTask(@Param("id") Long id, @Param("dispatchedTaskId") Long dispatchedTaskId);
45
+}

+ 39
- 0
wm-production/src/main/java/com/water/production/mapper/AlertRuleMapper.java Ver arquivo

@@ -0,0 +1,39 @@
1
+package com.water.production.mapper;
2
+
3
+import com.water.production.entity.AlertRule;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+import java.util.List;
7
+
8
+@Mapper
9
+public interface AlertRuleMapper {
10
+    // 查询所有报警规则
11
+    List<AlertRule> findAll();
12
+    
13
+    // 根据ID查询报警规则
14
+    AlertRule findById(@Param("id") Long id);
15
+    
16
+    // 根据参数查询报警规则
17
+    List<AlertRule> findByParameter(@Param("parameter") String parameter);
18
+    
19
+    // 根据设备ID查询相关报警规则
20
+    List<AlertRule> findByTargetEquipmentId(@Param("targetEquipmentId") String targetEquipmentId);
21
+    
22
+    // 根据区域查询报警规则
23
+    List<AlertRule> findByTargetArea(@Param("targetArea") String targetArea);
24
+    
25
+    // 根据状态查询报警规则
26
+    List<AlertRule> findByStatus(@Param("status") Integer status);
27
+    
28
+    // 插入报警规则
29
+    int insert(AlertRule alertRule);
30
+    
31
+    // 更新报警规则
32
+    int update(AlertRule alertRule);
33
+    
34
+    // 删除报警规则
35
+    int deleteById(@Param("id") Long id);
36
+    
37
+    // 启用/禁用报警规则
38
+    int updateStatus(@Param("id") Long id, @Param("status") Integer status);
39
+}

+ 18
- 0
wm-production/src/main/java/com/water/production/mapper/EquipmentMapper.java Ver arquivo

@@ -0,0 +1,18 @@
1
+package com.water.production.mapper;
2
+
3
+import com.water.production.entity.Equipment;
4
+import com.water.production.vo.EquipmentQueryVO;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import java.util.List;
8
+
9
+@Mapper
10
+public interface EquipmentMapper {
11
+    int insert(Equipment equipment);
12
+    int update(Equipment equipment);
13
+    int deleteById(Long id);
14
+    Equipment selectById(Long id);
15
+    List<Equipment> selectAll();
16
+    List<Equipment> selectByQuery(EquipmentQueryVO queryVO);
17
+    int countByQuery(EquipmentQueryVO queryVO);
18
+}

+ 18
- 0
wm-production/src/main/java/com/water/production/mapper/NotificationMapper.java Ver arquivo

@@ -0,0 +1,18 @@
1
+package com.water.production.mapper;
2
+
3
+import com.water.production.entity.Notification;
4
+import com.water.production.vo.NotificationQueryVO;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import java.util.List;
8
+
9
+@Mapper
10
+public interface NotificationMapper {
11
+    int insert(Notification notification);
12
+    int update(Notification notification);
13
+    int deleteById(Long id);
14
+    Notification selectById(Long id);
15
+    List<Notification> selectAll();
16
+    List<Notification> selectByQuery(NotificationQueryVO queryVO);
17
+    int countByQuery(NotificationQueryVO queryVO);
18
+}

+ 18
- 0
wm-production/src/main/java/com/water/production/mapper/ThresholdMapper.java Ver arquivo

@@ -0,0 +1,18 @@
1
+package com.water.production.mapper;
2
+
3
+import com.water.production.entity.Threshold;
4
+import com.water.production.vo.ThresholdQueryVO;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import java.util.List;
8
+
9
+@Mapper
10
+public interface ThresholdMapper {
11
+    int insert(Threshold threshold);
12
+    int update(Threshold threshold);
13
+    int deleteById(Long id);
14
+    Threshold selectById(Long id);
15
+    List<Threshold> selectAll();
16
+    List<Threshold> selectByQuery(ThresholdQueryVO queryVO);
17
+    int countByQuery(ThresholdQueryVO queryVO);
18
+}

+ 131
- 0
wm-production/src/main/java/com/water/production/service/AlertManagementService.java Ver arquivo

@@ -0,0 +1,131 @@
1
+package com.water.production.service;
2
+
3
+import com.water.production.entity.AlertManagement;
4
+import java.util.List;
5
+
6
+public interface AlertManagementService {
7
+    // 查询所有报警管理
8
+    List<AlertManagement> getAllAlerts();
9
+    
10
+    // 根据ID获取报警
11
+    AlertManagement getAlertById(Long id);
12
+    
13
+    // 根据报警规则获取相关报警
14
+    List<AlertManagement> getAlertsByRuleId(Long alertRuleId);
15
+    
16
+    // 根据状态获取报警
17
+    List<AlertManagement> getAlertsByStatus(String status);
18
+    
19
+    // 根据严重程度获取报警
20
+    List<AlertManagement> getAlertsBySeverity(String severity);
21
+    
22
+    // 创建报警
23
+    AlertManagement createAlert(AlertManagement alert);
24
+    
25
+    // 更新报警
26
+    AlertManagement updateAlert(AlertManagement alert);
27
+    
28
+    // 确认报警
29
+    boolean confirmAlert(Long id, String assigneeId);
30
+    
31
+    // 解决报警
32
+    boolean resolveAlert(Long id);
33
+    
34
+    // 分派任务
35
+    boolean dispatchTask(Long id, Long taskId);
36
+    
37
+    // 生成报警统计
38
+    AlertStatistics generateStatistics();
39
+    
40
+    // 报警级别枚举
41
+    enum AlertLevel {
42
+        LOW("低", 1),
43
+        MEDIUM("中", 2),
44
+        HIGH("高", 3),
45
+        CRITICAL("严重", 4);
46
+        
47
+        private String description;
48
+        private int level;
49
+        
50
+        AlertLevel(String description, int level) {
51
+            this.description = description;
52
+            this.level = level;
53
+        }
54
+        
55
+        public String getDescription() {
56
+            return description;
57
+        }
58
+        
59
+        public int getLevel() {
60
+            return level;
61
+        }
62
+    }
63
+    
64
+    // 报警统计结果
65
+    class AlertStatistics {
66
+        private int totalAlerts;
67
+        private int resolvedAlerts;
68
+        private int pendingAlerts;
69
+        private int criticalAlerts;
70
+        private int highAlerts;
71
+        private int mediumAlerts;
72
+        private int lowAlerts;
73
+        
74
+        // Getters and Setters
75
+        public int getTotalAlerts() {
76
+            return totalAlerts;
77
+        }
78
+        
79
+        public void setTotalAlerts(int totalAlerts) {
80
+            this.totalAlerts = totalAlerts;
81
+        }
82
+        
83
+        public int getResolvedAlerts() {
84
+            return resolvedAlerts;
85
+        }
86
+        
87
+        public void setResolvedAlerts(int resolvedAlerts) {
88
+            this.resolvedAlerts = resolvedAlerts;
89
+        }
90
+        
91
+        public int getPendingAlerts() {
92
+            return pendingAlerts;
93
+        }
94
+        
95
+        public void setPendingAlerts(int pendingAlerts) {
96
+            this.pendingAlerts = pendingAlerts;
97
+        }
98
+        
99
+        public int getCriticalAlerts() {
100
+            return criticalAlerts;
101
+        }
102
+        
103
+        public void setCriticalAlerts(int criticalAlerts) {
104
+            this.criticalAlerts = criticalAlerts;
105
+        }
106
+        
107
+        public int getHighAlerts() {
108
+            return highAlerts;
109
+        }
110
+        
111
+        public void setHighAlerts(int highAlerts) {
112
+            this.highAlerts = highAlerts;
113
+        }
114
+        
115
+        public int getMediumAlerts() {
116
+            return mediumAlerts;
117
+        }
118
+        
119
+        public void setMediumAlerts(int mediumAlerts) {
120
+            this.mediumAlerts = mediumAlerts;
121
+        }
122
+        
123
+        public int getLowAlerts() {
124
+            return lowAlerts;
125
+        }
126
+        
127
+        public void setLowAlerts(int lowAlerts) {
128
+            this.lowAlerts = lowAlerts;
129
+        }
130
+    }
131
+}

+ 39
- 0
wm-production/src/main/java/com/water/production/service/AlertRuleService.java Ver arquivo

@@ -0,0 +1,39 @@
1
+package com.water.production.service;
2
+
3
+import com.water.production.entity.AlertRule;
4
+import java.util.List;
5
+
6
+public interface AlertRuleService {
7
+    // 查询所有报警规则
8
+    List<AlertRule> getAllAlertRules();
9
+    
10
+    // 根据ID获取报警规则
11
+    AlertRule getAlertRuleById(Long id);
12
+    
13
+    // 根据参数获取报警规则
14
+    List<AlertRule> getAlertRulesByParameter(String parameter);
15
+    
16
+    // 根据设备获取报警规则
17
+    List<AlertRule> getAlertRulesByEquipment(String equipmentId);
18
+    
19
+    // 根据区域获取报警规则
20
+    List<AlertRule> getAlertRulesByArea(String area);
21
+    
22
+    // 创建报警规则
23
+    AlertRule createAlertRule(AlertRule alertRule);
24
+    
25
+    // 更新报警规则
26
+    AlertRule updateAlertRule(AlertRule alertRule);
27
+    
28
+    // 删除报警规则
29
+    boolean deleteAlertRule(Long id);
30
+    
31
+    // 启用报警规则
32
+    boolean enableAlertRule(Long id);
33
+    
34
+    // 禁用报警规则
35
+    boolean disableAlertRule(Long id);
36
+    
37
+    // 验证报警规则
38
+    boolean validateAlertRule(AlertRule alertRule);
39
+}

+ 15
- 0
wm-production/src/main/java/com/water/production/service/NotificationService.java Ver arquivo

@@ -0,0 +1,15 @@
1
+package com.water.production.service;
2
+
3
+import com.water.production.entity.Notification;
4
+import com.water.production.vo.NotificationQueryVO;
5
+import java.util.List;
6
+
7
+public interface NotificationService {
8
+    int createNotification(Notification notification);
9
+    int updateNotification(Notification notification);
10
+    int deleteNotification(Long id);
11
+    Notification getNotificationById(Long id);
12
+    List<Notification> getAllNotifications();
13
+    List<Notification> getNotificationsByQuery(NotificationQueryVO queryVO);
14
+    int getNotificationCountByQuery(NotificationQueryVO queryVO);
15
+}

+ 15
- 0
wm-production/src/main/java/com/water/production/service/ThresholdService.java Ver arquivo

@@ -0,0 +1,15 @@
1
+package com.water.production.service;
2
+
3
+import com.water.production.entity.Threshold;
4
+import com.water.production.vo.ThresholdQueryVO;
5
+import java.util.List;
6
+
7
+public interface ThresholdService {
8
+    int createThreshold(Threshold threshold);
9
+    int updateThreshold(Threshold threshold);
10
+    int deleteThreshold(Long id);
11
+    Threshold getThresholdById(Long id);
12
+    List<Threshold> getAllThresholds();
13
+    List<Threshold> getThresholdsByQuery(ThresholdQueryVO queryVO);
14
+    int getThresholdCountByQuery(ThresholdQueryVO queryVO);
15
+}

+ 187
- 0
wm-production/src/main/java/com/water/production/service/impl/AlertManagementServiceImpl.java Ver arquivo

@@ -0,0 +1,187 @@
1
+package com.water.production.service.impl;
2
+
3
+import com.water.production.entity.AlertManagement;
4
+import com.water.production.mapper.AlertManagementMapper;
5
+import com.water.production.service.AlertManagementService;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.stereotype.Service;
8
+import org.springframework.transaction.annotation.Transactional;
9
+import org.springframework.util.StringUtils;
10
+
11
+import java.time.LocalDateTime;
12
+import java.util.List;
13
+
14
+@Service
15
+@Transactional
16
+public class AlertManagementServiceImpl implements AlertManagementService {
17
+    
18
+    @Autowired
19
+    private AlertManagementMapper alertManagementMapper;
20
+    
21
+    @Override
22
+    public List<AlertManagement> getAllAlerts() {
23
+        return alertManagementMapper.findAll();
24
+    }
25
+    
26
+    @Override
27
+    public AlertManagement getAlertById(Long id) {
28
+        if (id == null) {
29
+            throw new IllegalArgumentException("报警ID不能为空");
30
+        }
31
+        AlertManagement alert = alertManagementMapper.findById(id);
32
+        if (alert == null) {
33
+            throw new RuntimeException("未找到ID为 " + id + " 的报警");
34
+        }
35
+        return alert;
36
+    }
37
+    
38
+    @Override
39
+    public List<AlertManagement> getAlertsByRuleId(Long alertRuleId) {
40
+        if (alertRuleId == null) {
41
+            throw new IllegalArgumentException("报警规则ID不能为空");
42
+        }
43
+        return alertManagementMapper.findByAlertRuleId(alertRuleId);
44
+    }
45
+    
46
+    @Override
47
+    public List<AlertManagement> getAlertsByStatus(String status) {
48
+        if (!StringUtils.hasText(status)) {
49
+            throw new IllegalArgumentException("状态不能为空");
50
+        }
51
+        return alertManagementMapper.findByStatus(status);
52
+    }
53
+    
54
+    @Override
55
+    public List<AlertManagement> getAlertsBySeverity(String severity) {
56
+        if (!StringUtils.hasText(severity)) {
57
+            throw new IllegalArgumentException("严重程度不能为空");
58
+        }
59
+        return alertManagementMapper.findBySeverity(severity);
60
+    }
61
+    
62
+    @Override
63
+    public AlertManagement createAlert(AlertManagement alert) {
64
+        if (alert == null) {
65
+            throw new IllegalArgumentException("报警不能为空");
66
+        }
67
+        
68
+        alert.setCreateTime(LocalDateTime.now());
69
+        alert.setUpdateTime(LocalDateTime.now());
70
+        alert.setStatus("PENDING"); // 默认待确认
71
+        
72
+        int result = alertManagementMapper.insert(alert);
73
+        if (result <= 0) {
74
+            throw new RuntimeException("创建报警失败");
75
+        }
76
+        
77
+        return alert;
78
+    }
79
+    
80
+    @Override
81
+    public AlertManagement updateAlert(AlertManagement alert) {
82
+        if (alert == null || alert.getId() == null) {
83
+            throw new IllegalArgumentException("报警和ID不能为空");
84
+        }
85
+        
86
+        // 检查报警是否存在
87
+        AlertManagement existingAlert = getAlertById(alert.getId());
88
+        if (existingAlert == null) {
89
+            throw new RuntimeException("未找到ID为 " + alert.getId() + " 的报警");
90
+        }
91
+        
92
+        alert.setUpdateTime(LocalDateTime.now());
93
+        
94
+        int result = alertManagementMapper.update(alert);
95
+        if (result <= 0) {
96
+            throw new RuntimeException("更新报警失败");
97
+        }
98
+        
99
+        return alert;
100
+    }
101
+    
102
+    @Override
103
+    public boolean confirmAlert(Long id, String assigneeId) {
104
+        if (id == null || !StringUtils.hasText(assigneeId)) {
105
+            throw new IllegalArgumentException("报警ID和负责人ID不能为空");
106
+        }
107
+        
108
+        int result = alertManagementMapper.confirmAlert(id, assigneeId);
109
+        return result > 0;
110
+    }
111
+    
112
+    @Override
113
+    public boolean resolveAlert(Long id) {
114
+        if (id == null) {
115
+            throw new IllegalArgumentException("报警ID不能为空");
116
+        }
117
+        
118
+        AlertManagement existingAlert = getAlertById(id);
119
+        if (existingAlert == null) {
120
+            throw new RuntimeException("未找到ID为 " + id + " 的报警");
121
+        }
122
+        
123
+        int result = alertManagementMapper.resolveAlert(id);
124
+        return result > 0;
125
+    }
126
+    
127
+    @Override
128
+    public boolean dispatchTask(Long id, Long taskId) {
129
+        if (id == null || taskId == null) {
130
+            throw new IllegalArgumentException("报警ID和任务ID不能为空");
131
+        }
132
+        
133
+        int result = alertManagementMapper.dispatchTask(id, taskId);
134
+        return result > 0;
135
+    }
136
+    
137
+    @Override
138
+    public AlertStatistics generateStatistics() {
139
+        AlertStatistics statistics = new AlertStatistics();
140
+        
141
+        // 获取所有报警
142
+        List<AlertManagement> allAlerts = getAllAlerts();
143
+        statistics.setTotalAlerts(allAlerts.size());
144
+        
145
+        // 统计已解决和待处理的报警
146
+        int resolvedCount = 0;
147
+        int pendingCount = 0;
148
+        int criticalCount = 0;
149
+        int highCount = 0;
150
+        int mediumCount = 0;
151
+        int lowCount = 0;
152
+        
153
+        for (AlertManagement alert : allAlerts) {
154
+            if ("RESOLVED".equals(alert.getStatus())) {
155
+                resolvedCount++;
156
+            } else {
157
+                pendingCount++;
158
+            }
159
+            
160
+            if (alert.getSeverity() != null) {
161
+                switch (alert.getSeverity().toUpperCase()) {
162
+                    case "CRITICAL":
163
+                        criticalCount++;
164
+                        break;
165
+                    case "HIGH":
166
+                        highCount++;
167
+                        break;
168
+                    case "MEDIUM":
169
+                        mediumCount++;
170
+                        break;
171
+                    case "LOW":
172
+                        lowCount++;
173
+                        break;
174
+                }
175
+            }
176
+        }
177
+        
178
+        statistics.setResolvedAlerts(resolvedCount);
179
+        statistics.setPendingAlerts(pendingCount);
180
+        statistics.setCriticalAlerts(criticalCount);
181
+        statistics.setHighAlerts(highCount);
182
+        statistics.setMediumAlerts(mediumCount);
183
+        statistics.setLowAlerts(lowCount);
184
+        
185
+        return statistics;
186
+    }
187
+}

+ 179
- 0
wm-production/src/main/java/com/water/production/service/impl/AlertRuleServiceImpl.java Ver arquivo

@@ -0,0 +1,179 @@
1
+package com.water.production.service.impl;
2
+
3
+import com.water.production.entity.AlertRule;
4
+import com.water.production.mapper.AlertRuleMapper;
5
+import com.water.production.service.AlertRuleService;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.stereotype.Service;
8
+import org.springframework.transaction.annotation.Transactional;
9
+import org.springframework.util.StringUtils;
10
+
11
+import java.time.LocalDateTime;
12
+import java.util.List;
13
+
14
+@Service
15
+@Transactional
16
+public class AlertRuleServiceImpl implements AlertRuleService {
17
+    
18
+    @Autowired
19
+    private AlertRuleMapper alertRuleMapper;
20
+    
21
+    @Override
22
+    public List<AlertRule> getAllAlertRules() {
23
+        return alertRuleMapper.findAll();
24
+    }
25
+    
26
+    @Override
27
+    public AlertRule getAlertRuleById(Long id) {
28
+        if (id == null) {
29
+            throw new IllegalArgumentException("报警规则ID不能为空");
30
+        }
31
+        AlertRule rule = alertRuleMapper.findById(id);
32
+        if (rule == null) {
33
+            throw new RuntimeException("未找到ID为 " + id + " 的报警规则");
34
+        }
35
+        return rule;
36
+    }
37
+    
38
+    @Override
39
+    public List<AlertRule> getAlertRulesByParameter(String parameter) {
40
+        if (!StringUtils.hasText(parameter)) {
41
+            throw new IllegalArgumentException("参数不能为空");
42
+        }
43
+        return alertRuleMapper.findByParameter(parameter);
44
+    }
45
+    
46
+    @Override
47
+    public List<AlertRule> getAlertRulesByEquipment(String equipmentId) {
48
+        if (!StringUtils.hasText(equipmentId)) {
49
+            throw new IllegalArgumentException("设备ID不能为空");
50
+        }
51
+        return alertRuleMapper.findByTargetEquipmentId(equipmentId);
52
+    }
53
+    
54
+    @Override
55
+    public List<AlertRule> getAlertRulesByArea(String area) {
56
+        if (!StringUtils.hasText(area)) {
57
+            throw new IllegalArgumentException("区域不能为空");
58
+        }
59
+        return alertRuleMapper.findByTargetArea(area);
60
+    }
61
+    
62
+    @Override
63
+    public AlertRule createAlertRule(AlertRule alertRule) {
64
+        if (alertRule == null) {
65
+            throw new IllegalArgumentException("报警规则不能为空");
66
+        }
67
+        
68
+        if (!validateAlertRule(alertRule)) {
69
+            throw new IllegalArgumentException("报警规则验证失败");
70
+        }
71
+        
72
+        alertRule.setCreateTime(LocalDateTime.now());
73
+        alertRule.setUpdateTime(LocalDateTime.now());
74
+        alertRule.setStatus(1); // 默认启用
75
+        
76
+        int result = alertRuleMapper.insert(alertRule);
77
+        if (result <= 0) {
78
+            throw new RuntimeException("创建报警规则失败");
79
+        }
80
+        
81
+        return alertRule;
82
+    }
83
+    
84
+    @Override
85
+    public AlertRule updateAlertRule(AlertRule alertRule) {
86
+        if (alertRule == null || alertRule.getId() == null) {
87
+            throw new IllegalArgumentException("报警规则和ID不能为空");
88
+        }
89
+        
90
+        // 检查规则是否存在
91
+        AlertRule existingRule = getAlertRuleById(alertRule.getId());
92
+        if (existingRule == null) {
93
+            throw new RuntimeException("未找到ID为 " + alertRule.getId() + " 的报警规则");
94
+        }
95
+        
96
+        if (!validateAlertRule(alertRule)) {
97
+            throw new IllegalArgumentException("报警规则验证失败");
98
+        }
99
+        
100
+        alertRule.setUpdateTime(LocalDateTime.now());
101
+        
102
+        int result = alertRuleMapper.update(alertRule);
103
+        if (result <= 0) {
104
+            throw new RuntimeException("更新报警规则失败");
105
+        }
106
+        
107
+        return alertRule;
108
+    }
109
+    
110
+    @Override
111
+    public boolean deleteAlertRule(Long id) {
112
+        if (id == null) {
113
+            throw new IllegalArgumentException("报警规则ID不能为空");
114
+        }
115
+        
116
+        AlertRule existingRule = getAlertRuleById(id);
117
+        if (existingRule == null) {
118
+            throw new RuntimeException("未找到ID为 " + id + " 的报警规则");
119
+        }
120
+        
121
+        int result = alertRuleMapper.deleteById(id);
122
+        return result > 0;
123
+    }
124
+    
125
+    @Override
126
+    public boolean enableAlertRule(Long id) {
127
+        if (id == null) {
128
+            throw new IllegalArgumentException("报警规则ID不能为空");
129
+        }
130
+        
131
+        int result = alertRuleMapper.updateStatus(id, 1);
132
+        return result > 0;
133
+    }
134
+    
135
+    @Override
136
+    public boolean disableAlertRule(Long id) {
137
+        if (id == null) {
138
+            throw new IllegalArgumentException("报警规则ID不能为空");
139
+        }
140
+        
141
+        int result = alertRuleMapper.updateStatus(id, 0);
142
+        return result > 0;
143
+    }
144
+    
145
+    @Override
146
+    public boolean validateAlertRule(AlertRule alertRule) {
147
+        if (alertRule == null) {
148
+            return false;
149
+        }
150
+        
151
+        if (!StringUtils.hasText(alertRule.getName())) {
152
+            return false;
153
+        }
154
+        
155
+        if (!StringUtils.hasText(alertRule.getParameter())) {
156
+            return false;
157
+        }
158
+        
159
+        // 检查阈值关系
160
+        if (alertRule.getMinValue() != null && alertRule.getMaxValue() != null) {
161
+            if (alertRule.getMinValue() >= alertRule.getMaxValue()) {
162
+                return false;
163
+            }
164
+        }
165
+        
166
+        if (alertRule.getWarningValue() != null && alertRule.getCriticalValue() != null) {
167
+            if (alertRule.getWarningValue() >= alertRule.getCriticalValue()) {
168
+                return false;
169
+            }
170
+        }
171
+        
172
+        if (alertRule.getSeverityLevel() != null && 
173
+            (alertRule.getSeverityLevel() < 1 || alertRule.getSeverityLevel() > 4)) {
174
+            return false;
175
+        }
176
+        
177
+        return true;
178
+    }
179
+}