diff --git a/wm-production/src/main/java/com/water/production/controller/AlertManagementController.java b/wm-production/src/main/java/com/water/production/controller/AlertManagementController.java new file mode 100644 index 00000000..18622cec --- /dev/null +++ b/wm-production/src/main/java/com/water/production/controller/AlertManagementController.java @@ -0,0 +1,170 @@ +package com.water.production.controller; + +import com.water.production.entity.AlertManagement; +import com.water.production.service.AlertManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/alert-management") +@CrossOrigin(origins = "*") +public class AlertManagementController { + + @Autowired + private AlertManagementService alertManagementService; + + // 获取所有报警 + @GetMapping + public ResponseEntity> getAllAlerts() { + try { + List alerts = alertManagementService.getAllAlerts(); + return ResponseEntity.ok(alerts); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 根据ID获取报警 + @GetMapping("/{id}") + public ResponseEntity getAlertById(@PathVariable Long id) { + try { + AlertManagement alert = alertManagementService.getAlertById(id); + return ResponseEntity.ok(alert); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.notFound().build(); + } + } + + // 根据报警规则ID获取相关报警 + @GetMapping("/rule/{alertRuleId}") + public ResponseEntity> getAlertsByRuleId(@PathVariable Long alertRuleId) { + try { + List alerts = alertManagementService.getAlertsByRuleId(alertRuleId); + return ResponseEntity.ok(alerts); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 根据状态获取报警 + @GetMapping("/status/{status}") + public ResponseEntity> getAlertsByStatus(@PathVariable String status) { + try { + List alerts = alertManagementService.getAlertsByStatus(status); + return ResponseEntity.ok(alerts); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 根据严重程度获取报警 + @GetMapping("/severity/{severity}") + public ResponseEntity> getAlertsBySeverity(@PathVariable String severity) { + try { + List alerts = alertManagementService.getAlertsBySeverity(severity); + return ResponseEntity.ok(alerts); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 创建报警 + @PostMapping + public ResponseEntity createAlert(@RequestBody AlertManagement alert) { + try { + AlertManagement created = alertManagementService.createAlert(alert); + return ResponseEntity.ok(created); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 更新报警 + @PutMapping("/{id}") + public ResponseEntity updateAlert(@PathVariable Long id, @RequestBody AlertManagement alert) { + try { + alert.setId(id); + AlertManagement updated = alertManagementService.updateAlert(alert); + return ResponseEntity.ok(updated); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 确认报警 + @PutMapping("/{id}/confirm") + public ResponseEntity confirmAlert(@PathVariable Long id, @RequestParam String assigneeId) { + try { + boolean success = alertManagementService.confirmAlert(id, assigneeId); + if (success) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 解决报警 + @PutMapping("/{id}/resolve") + public ResponseEntity resolveAlert(@PathVariable Long id) { + try { + boolean success = alertManagementService.resolveAlert(id); + if (success) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 分派任务 + @PutMapping("/{id}/dispatch") + public ResponseEntity dispatchTask(@PathVariable Long id, @RequestParam Long taskId) { + try { + boolean success = alertManagementService.dispatchTask(id, taskId); + if (success) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 生成报警统计 + @GetMapping("/statistics") + public ResponseEntity generateStatistics() { + try { + AlertManagementService.AlertStatistics statistics = alertManagementService.generateStatistics(); + return ResponseEntity.ok(statistics); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/controller/AlertRuleController.java b/wm-production/src/main/java/com/water/production/controller/AlertRuleController.java new file mode 100644 index 00000000..12259a73 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/controller/AlertRuleController.java @@ -0,0 +1,163 @@ +package com.water.production.controller; + +import com.water.production.entity.AlertRule; +import com.water.production.service.AlertRuleService; +import com.water.production.service.AlertManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/alert-rules") +@CrossOrigin(origins = "*") +public class AlertRuleController { + + @Autowired + private AlertRuleService alertRuleService; + + @Autowired + private AlertManagementService alertManagementService; + + // 获取所有报警规则 + @GetMapping + public ResponseEntity> getAllAlertRules() { + try { + List rules = alertRuleService.getAllAlertRules(); + return ResponseEntity.ok(rules); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 根据ID获取报警规则 + @GetMapping("/{id}") + public ResponseEntity getAlertRuleById(@PathVariable Long id) { + try { + AlertRule rule = alertRuleService.getAlertRuleById(id); + return ResponseEntity.ok(rule); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.notFound().build(); + } + } + + // 根据参数获取报警规则 + @GetMapping("/parameter/{parameter}") + public ResponseEntity> getAlertRulesByParameter(@PathVariable String parameter) { + try { + List rules = alertRuleService.getAlertRulesByParameter(parameter); + return ResponseEntity.ok(rules); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 根据设备获取报警规则 + @GetMapping("/equipment/{equipmentId}") + public ResponseEntity> getAlertRulesByEquipment(@PathVariable String equipmentId) { + try { + List rules = alertRuleService.getAlertRulesByEquipment(equipmentId); + return ResponseEntity.ok(rules); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 根据区域获取报警规则 + @GetMapping("/area/{area}") + public ResponseEntity> getAlertRulesByArea(@PathVariable String area) { + try { + List rules = alertRuleService.getAlertRulesByArea(area); + return ResponseEntity.ok(rules); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 创建报警规则 + @PostMapping + public ResponseEntity createAlertRule(@RequestBody AlertRule alertRule) { + try { + AlertRule created = alertRuleService.createAlertRule(alertRule); + return ResponseEntity.ok(created); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 更新报警规则 + @PutMapping("/{id}") + public ResponseEntity updateAlertRule(@PathVariable Long id, @RequestBody AlertRule alertRule) { + try { + alertRule.setId(id); + AlertRule updated = alertRuleService.updateAlertRule(alertRule); + return ResponseEntity.ok(updated); + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 删除报警规则 + @DeleteMapping("/{id}") + public ResponseEntity deleteAlertRule(@PathVariable Long id) { + try { + boolean success = alertRuleService.deleteAlertRule(id); + if (success) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 启用报警规则 + @PutMapping("/{id}/enable") + public ResponseEntity enableAlertRule(@PathVariable Long id) { + try { + boolean success = alertRuleService.enableAlertRule(id); + if (success) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } + + // 禁用报警规则 + @PutMapping("/{id}/disable") + public ResponseEntity disableAlertRule(@PathVariable Long id) { + try { + boolean success = alertRuleService.disableAlertRule(id); + if (success) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } catch (IllegalArgumentException e) { + return ResponseEntity.badRequest().build(); + } catch (Exception e) { + return ResponseEntity.internalServerError().build(); + } + } +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/entity/AlertManagement.java b/wm-production/src/main/java/com/water/production/entity/AlertManagement.java new file mode 100644 index 00000000..3a788684 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/entity/AlertManagement.java @@ -0,0 +1,28 @@ +package com.water.production.entity; + +import lombok.Data; +import java.time.LocalDateTime; + +@Data +public class AlertManagement { + private Long id; + private Long alertRuleId; + private String title; + private String content; + private String severity; + private String status; + private String targetId; + private String targetType; + private String assigneeId; + private String assigneeName; + private LocalDateTime alertTime; + private LocalDateTime confirmTime; + private LocalDateTime resolveTime; + private String acknowledgmentStatus; + private String dispatchStatus; + private Long dispatchedTaskId; + private LocalDateTime createTime; + private LocalDateTime updateTime; + private String createBy; + private String updateBy; +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/entity/AlertRule.java b/wm-production/src/main/java/com/water/production/entity/AlertRule.java new file mode 100644 index 00000000..8271f566 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/entity/AlertRule.java @@ -0,0 +1,25 @@ +package com.water.production.entity; + +import lombok.Data; +import java.time.LocalDateTime; + +@Data +public class AlertRule { + private Long id; + private String name; + private String parameter; + private Double minValue; + private Double maxValue; + private Double warningValue; + private Double criticalValue; + private String conditionType; + private Integer severityLevel; + private Integer duplicateInterval; + private Integer status; + private String targetEquipmentId; + private String targetArea; + private LocalDateTime createTime; + private LocalDateTime updateTime; + private String createBy; + private String updateBy; +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/entity/Equipment.java b/wm-production/src/main/java/com/water/production/entity/Equipment.java new file mode 100644 index 00000000..97b42b95 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/entity/Equipment.java @@ -0,0 +1,22 @@ +package com.water.production.entity; + +import lombok.Data; +import java.time.LocalDateTime; + +@Data +public class Equipment { + private Long id; + private String name; + private String type; + private String model; + private String location; + private String status; + private String description; + private LocalDateTime installTime; + private LocalDateTime lastMaintenanceTime; + private LocalDateTime nextMaintenanceTime; + private LocalDateTime createTime; + private LocalDateTime updateTime; + private String createBy; + private String updateBy; +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/entity/Notification.java b/wm-production/src/main/java/com/water/production/entity/Notification.java new file mode 100644 index 00000000..b9135540 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/entity/Notification.java @@ -0,0 +1,21 @@ +package com.water.production.entity; + +import lombok.Data; +import java.time.LocalDateTime; + +@Data +public class Notification { + private Long id; + private String title; + private String content; + private String type; + private String level; + private String target; + private String channels; + private Integer status; + private LocalDateTime publishTime; + private LocalDateTime createTime; + private LocalDateTime updateTime; + private String createBy; + private String updateBy; +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/entity/Threshold.java b/wm-production/src/main/java/com/water/production/entity/Threshold.java new file mode 100644 index 00000000..953017d1 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/entity/Threshold.java @@ -0,0 +1,22 @@ +package com.water.production.entity; + +import lombok.Data; +import java.time.LocalDateTime; + +@Data +public class Threshold { + private Long id; + private String name; + private String parameter; + private Double minValue; + private Double maxValue; + private Double warningValue; + private Double criticalValue; + private String unit; + private String description; + private Integer status; + private LocalDateTime createTime; + private LocalDateTime updateTime; + private String createBy; + private String updateBy; +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/mapper/AlertManagementMapper.java b/wm-production/src/main/java/com/water/production/mapper/AlertManagementMapper.java new file mode 100644 index 00000000..6d7f6c42 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/mapper/AlertManagementMapper.java @@ -0,0 +1,45 @@ +package com.water.production.mapper; + +import com.water.production.entity.AlertManagement; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import java.util.List; + +@Mapper +public interface AlertManagementMapper { + // 查询所有报警管理 + List findAll(); + + // 根据ID查询报警管理 + AlertManagement findById(@Param("id") Long id); + + // 根据报警规则ID查询相关报警 + List findByAlertRuleId(@Param("alertRuleId") Long alertRuleId); + + // 根据状态查询报警 + List findByStatus(@Param("status") String status); + + // 根据严重程度查询报警 + List findBySeverity(@Param("severity") String severity); + + // 根据负责人ID查询报警 + List findByAssigneeId(@Param("assigneeId") String assigneeId); + + // 插入报警管理 + int insert(AlertManagement alertManagement); + + // 更新报警管理 + int update(AlertManagement alertManagement); + + // 删除报警管理 + int deleteById(@Param("id") Long id); + + // 确认报警 + int confirmAlert(@Param("id") Long id, @Param("assigneeId") String assigneeId); + + // 解决报警 + int resolveAlert(@Param("id") Long id); + + // 分派任务 + int dispatchTask(@Param("id") Long id, @Param("dispatchedTaskId") Long dispatchedTaskId); +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/mapper/AlertRuleMapper.java b/wm-production/src/main/java/com/water/production/mapper/AlertRuleMapper.java new file mode 100644 index 00000000..2acd5b6a --- /dev/null +++ b/wm-production/src/main/java/com/water/production/mapper/AlertRuleMapper.java @@ -0,0 +1,39 @@ +package com.water.production.mapper; + +import com.water.production.entity.AlertRule; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import java.util.List; + +@Mapper +public interface AlertRuleMapper { + // 查询所有报警规则 + List findAll(); + + // 根据ID查询报警规则 + AlertRule findById(@Param("id") Long id); + + // 根据参数查询报警规则 + List findByParameter(@Param("parameter") String parameter); + + // 根据设备ID查询相关报警规则 + List findByTargetEquipmentId(@Param("targetEquipmentId") String targetEquipmentId); + + // 根据区域查询报警规则 + List findByTargetArea(@Param("targetArea") String targetArea); + + // 根据状态查询报警规则 + List findByStatus(@Param("status") Integer status); + + // 插入报警规则 + int insert(AlertRule alertRule); + + // 更新报警规则 + int update(AlertRule alertRule); + + // 删除报警规则 + int deleteById(@Param("id") Long id); + + // 启用/禁用报警规则 + int updateStatus(@Param("id") Long id, @Param("status") Integer status); +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/mapper/EquipmentMapper.java b/wm-production/src/main/java/com/water/production/mapper/EquipmentMapper.java new file mode 100644 index 00000000..4bfe939f --- /dev/null +++ b/wm-production/src/main/java/com/water/production/mapper/EquipmentMapper.java @@ -0,0 +1,18 @@ +package com.water.production.mapper; + +import com.water.production.entity.Equipment; +import com.water.production.vo.EquipmentQueryVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import java.util.List; + +@Mapper +public interface EquipmentMapper { + int insert(Equipment equipment); + int update(Equipment equipment); + int deleteById(Long id); + Equipment selectById(Long id); + List selectAll(); + List selectByQuery(EquipmentQueryVO queryVO); + int countByQuery(EquipmentQueryVO queryVO); +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/mapper/NotificationMapper.java b/wm-production/src/main/java/com/water/production/mapper/NotificationMapper.java new file mode 100644 index 00000000..e3f40e8d --- /dev/null +++ b/wm-production/src/main/java/com/water/production/mapper/NotificationMapper.java @@ -0,0 +1,18 @@ +package com.water.production.mapper; + +import com.water.production.entity.Notification; +import com.water.production.vo.NotificationQueryVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import java.util.List; + +@Mapper +public interface NotificationMapper { + int insert(Notification notification); + int update(Notification notification); + int deleteById(Long id); + Notification selectById(Long id); + List selectAll(); + List selectByQuery(NotificationQueryVO queryVO); + int countByQuery(NotificationQueryVO queryVO); +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/mapper/ThresholdMapper.java b/wm-production/src/main/java/com/water/production/mapper/ThresholdMapper.java new file mode 100644 index 00000000..c0de5f82 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/mapper/ThresholdMapper.java @@ -0,0 +1,18 @@ +package com.water.production.mapper; + +import com.water.production.entity.Threshold; +import com.water.production.vo.ThresholdQueryVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import java.util.List; + +@Mapper +public interface ThresholdMapper { + int insert(Threshold threshold); + int update(Threshold threshold); + int deleteById(Long id); + Threshold selectById(Long id); + List selectAll(); + List selectByQuery(ThresholdQueryVO queryVO); + int countByQuery(ThresholdQueryVO queryVO); +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/service/AlertManagementService.java b/wm-production/src/main/java/com/water/production/service/AlertManagementService.java new file mode 100644 index 00000000..93b6c2a4 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/service/AlertManagementService.java @@ -0,0 +1,131 @@ +package com.water.production.service; + +import com.water.production.entity.AlertManagement; +import java.util.List; + +public interface AlertManagementService { + // 查询所有报警管理 + List getAllAlerts(); + + // 根据ID获取报警 + AlertManagement getAlertById(Long id); + + // 根据报警规则获取相关报警 + List getAlertsByRuleId(Long alertRuleId); + + // 根据状态获取报警 + List getAlertsByStatus(String status); + + // 根据严重程度获取报警 + List getAlertsBySeverity(String severity); + + // 创建报警 + AlertManagement createAlert(AlertManagement alert); + + // 更新报警 + AlertManagement updateAlert(AlertManagement alert); + + // 确认报警 + boolean confirmAlert(Long id, String assigneeId); + + // 解决报警 + boolean resolveAlert(Long id); + + // 分派任务 + boolean dispatchTask(Long id, Long taskId); + + // 生成报警统计 + AlertStatistics generateStatistics(); + + // 报警级别枚举 + enum AlertLevel { + LOW("低", 1), + MEDIUM("中", 2), + HIGH("高", 3), + CRITICAL("严重", 4); + + private String description; + private int level; + + AlertLevel(String description, int level) { + this.description = description; + this.level = level; + } + + public String getDescription() { + return description; + } + + public int getLevel() { + return level; + } + } + + // 报警统计结果 + class AlertStatistics { + private int totalAlerts; + private int resolvedAlerts; + private int pendingAlerts; + private int criticalAlerts; + private int highAlerts; + private int mediumAlerts; + private int lowAlerts; + + // Getters and Setters + public int getTotalAlerts() { + return totalAlerts; + } + + public void setTotalAlerts(int totalAlerts) { + this.totalAlerts = totalAlerts; + } + + public int getResolvedAlerts() { + return resolvedAlerts; + } + + public void setResolvedAlerts(int resolvedAlerts) { + this.resolvedAlerts = resolvedAlerts; + } + + public int getPendingAlerts() { + return pendingAlerts; + } + + public void setPendingAlerts(int pendingAlerts) { + this.pendingAlerts = pendingAlerts; + } + + public int getCriticalAlerts() { + return criticalAlerts; + } + + public void setCriticalAlerts(int criticalAlerts) { + this.criticalAlerts = criticalAlerts; + } + + public int getHighAlerts() { + return highAlerts; + } + + public void setHighAlerts(int highAlerts) { + this.highAlerts = highAlerts; + } + + public int getMediumAlerts() { + return mediumAlerts; + } + + public void setMediumAlerts(int mediumAlerts) { + this.mediumAlerts = mediumAlerts; + } + + public int getLowAlerts() { + return lowAlerts; + } + + public void setLowAlerts(int lowAlerts) { + this.lowAlerts = lowAlerts; + } + } +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/service/AlertRuleService.java b/wm-production/src/main/java/com/water/production/service/AlertRuleService.java new file mode 100644 index 00000000..478fb148 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/service/AlertRuleService.java @@ -0,0 +1,39 @@ +package com.water.production.service; + +import com.water.production.entity.AlertRule; +import java.util.List; + +public interface AlertRuleService { + // 查询所有报警规则 + List getAllAlertRules(); + + // 根据ID获取报警规则 + AlertRule getAlertRuleById(Long id); + + // 根据参数获取报警规则 + List getAlertRulesByParameter(String parameter); + + // 根据设备获取报警规则 + List getAlertRulesByEquipment(String equipmentId); + + // 根据区域获取报警规则 + List getAlertRulesByArea(String area); + + // 创建报警规则 + AlertRule createAlertRule(AlertRule alertRule); + + // 更新报警规则 + AlertRule updateAlertRule(AlertRule alertRule); + + // 删除报警规则 + boolean deleteAlertRule(Long id); + + // 启用报警规则 + boolean enableAlertRule(Long id); + + // 禁用报警规则 + boolean disableAlertRule(Long id); + + // 验证报警规则 + boolean validateAlertRule(AlertRule alertRule); +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/service/NotificationService.java b/wm-production/src/main/java/com/water/production/service/NotificationService.java new file mode 100644 index 00000000..a68a1258 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/service/NotificationService.java @@ -0,0 +1,15 @@ +package com.water.production.service; + +import com.water.production.entity.Notification; +import com.water.production.vo.NotificationQueryVO; +import java.util.List; + +public interface NotificationService { + int createNotification(Notification notification); + int updateNotification(Notification notification); + int deleteNotification(Long id); + Notification getNotificationById(Long id); + List getAllNotifications(); + List getNotificationsByQuery(NotificationQueryVO queryVO); + int getNotificationCountByQuery(NotificationQueryVO queryVO); +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/service/ThresholdService.java b/wm-production/src/main/java/com/water/production/service/ThresholdService.java new file mode 100644 index 00000000..41cbfa81 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/service/ThresholdService.java @@ -0,0 +1,15 @@ +package com.water.production.service; + +import com.water.production.entity.Threshold; +import com.water.production.vo.ThresholdQueryVO; +import java.util.List; + +public interface ThresholdService { + int createThreshold(Threshold threshold); + int updateThreshold(Threshold threshold); + int deleteThreshold(Long id); + Threshold getThresholdById(Long id); + List getAllThresholds(); + List getThresholdsByQuery(ThresholdQueryVO queryVO); + int getThresholdCountByQuery(ThresholdQueryVO queryVO); +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/service/impl/AlertManagementServiceImpl.java b/wm-production/src/main/java/com/water/production/service/impl/AlertManagementServiceImpl.java new file mode 100644 index 00000000..9e270b58 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/service/impl/AlertManagementServiceImpl.java @@ -0,0 +1,187 @@ +package com.water.production.service.impl; + +import com.water.production.entity.AlertManagement; +import com.water.production.mapper.AlertManagementMapper; +import com.water.production.service.AlertManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +import java.time.LocalDateTime; +import java.util.List; + +@Service +@Transactional +public class AlertManagementServiceImpl implements AlertManagementService { + + @Autowired + private AlertManagementMapper alertManagementMapper; + + @Override + public List getAllAlerts() { + return alertManagementMapper.findAll(); + } + + @Override + public AlertManagement getAlertById(Long id) { + if (id == null) { + throw new IllegalArgumentException("报警ID不能为空"); + } + AlertManagement alert = alertManagementMapper.findById(id); + if (alert == null) { + throw new RuntimeException("未找到ID为 " + id + " 的报警"); + } + return alert; + } + + @Override + public List getAlertsByRuleId(Long alertRuleId) { + if (alertRuleId == null) { + throw new IllegalArgumentException("报警规则ID不能为空"); + } + return alertManagementMapper.findByAlertRuleId(alertRuleId); + } + + @Override + public List getAlertsByStatus(String status) { + if (!StringUtils.hasText(status)) { + throw new IllegalArgumentException("状态不能为空"); + } + return alertManagementMapper.findByStatus(status); + } + + @Override + public List getAlertsBySeverity(String severity) { + if (!StringUtils.hasText(severity)) { + throw new IllegalArgumentException("严重程度不能为空"); + } + return alertManagementMapper.findBySeverity(severity); + } + + @Override + public AlertManagement createAlert(AlertManagement alert) { + if (alert == null) { + throw new IllegalArgumentException("报警不能为空"); + } + + alert.setCreateTime(LocalDateTime.now()); + alert.setUpdateTime(LocalDateTime.now()); + alert.setStatus("PENDING"); // 默认待确认 + + int result = alertManagementMapper.insert(alert); + if (result <= 0) { + throw new RuntimeException("创建报警失败"); + } + + return alert; + } + + @Override + public AlertManagement updateAlert(AlertManagement alert) { + if (alert == null || alert.getId() == null) { + throw new IllegalArgumentException("报警和ID不能为空"); + } + + // 检查报警是否存在 + AlertManagement existingAlert = getAlertById(alert.getId()); + if (existingAlert == null) { + throw new RuntimeException("未找到ID为 " + alert.getId() + " 的报警"); + } + + alert.setUpdateTime(LocalDateTime.now()); + + int result = alertManagementMapper.update(alert); + if (result <= 0) { + throw new RuntimeException("更新报警失败"); + } + + return alert; + } + + @Override + public boolean confirmAlert(Long id, String assigneeId) { + if (id == null || !StringUtils.hasText(assigneeId)) { + throw new IllegalArgumentException("报警ID和负责人ID不能为空"); + } + + int result = alertManagementMapper.confirmAlert(id, assigneeId); + return result > 0; + } + + @Override + public boolean resolveAlert(Long id) { + if (id == null) { + throw new IllegalArgumentException("报警ID不能为空"); + } + + AlertManagement existingAlert = getAlertById(id); + if (existingAlert == null) { + throw new RuntimeException("未找到ID为 " + id + " 的报警"); + } + + int result = alertManagementMapper.resolveAlert(id); + return result > 0; + } + + @Override + public boolean dispatchTask(Long id, Long taskId) { + if (id == null || taskId == null) { + throw new IllegalArgumentException("报警ID和任务ID不能为空"); + } + + int result = alertManagementMapper.dispatchTask(id, taskId); + return result > 0; + } + + @Override + public AlertStatistics generateStatistics() { + AlertStatistics statistics = new AlertStatistics(); + + // 获取所有报警 + List allAlerts = getAllAlerts(); + statistics.setTotalAlerts(allAlerts.size()); + + // 统计已解决和待处理的报警 + int resolvedCount = 0; + int pendingCount = 0; + int criticalCount = 0; + int highCount = 0; + int mediumCount = 0; + int lowCount = 0; + + for (AlertManagement alert : allAlerts) { + if ("RESOLVED".equals(alert.getStatus())) { + resolvedCount++; + } else { + pendingCount++; + } + + if (alert.getSeverity() != null) { + switch (alert.getSeverity().toUpperCase()) { + case "CRITICAL": + criticalCount++; + break; + case "HIGH": + highCount++; + break; + case "MEDIUM": + mediumCount++; + break; + case "LOW": + lowCount++; + break; + } + } + } + + statistics.setResolvedAlerts(resolvedCount); + statistics.setPendingAlerts(pendingCount); + statistics.setCriticalAlerts(criticalCount); + statistics.setHighAlerts(highCount); + statistics.setMediumAlerts(mediumCount); + statistics.setLowAlerts(lowCount); + + return statistics; + } +} \ No newline at end of file diff --git a/wm-production/src/main/java/com/water/production/service/impl/AlertRuleServiceImpl.java b/wm-production/src/main/java/com/water/production/service/impl/AlertRuleServiceImpl.java new file mode 100644 index 00000000..6d9e27a1 --- /dev/null +++ b/wm-production/src/main/java/com/water/production/service/impl/AlertRuleServiceImpl.java @@ -0,0 +1,179 @@ +package com.water.production.service.impl; + +import com.water.production.entity.AlertRule; +import com.water.production.mapper.AlertRuleMapper; +import com.water.production.service.AlertRuleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +import java.time.LocalDateTime; +import java.util.List; + +@Service +@Transactional +public class AlertRuleServiceImpl implements AlertRuleService { + + @Autowired + private AlertRuleMapper alertRuleMapper; + + @Override + public List getAllAlertRules() { + return alertRuleMapper.findAll(); + } + + @Override + public AlertRule getAlertRuleById(Long id) { + if (id == null) { + throw new IllegalArgumentException("报警规则ID不能为空"); + } + AlertRule rule = alertRuleMapper.findById(id); + if (rule == null) { + throw new RuntimeException("未找到ID为 " + id + " 的报警规则"); + } + return rule; + } + + @Override + public List getAlertRulesByParameter(String parameter) { + if (!StringUtils.hasText(parameter)) { + throw new IllegalArgumentException("参数不能为空"); + } + return alertRuleMapper.findByParameter(parameter); + } + + @Override + public List getAlertRulesByEquipment(String equipmentId) { + if (!StringUtils.hasText(equipmentId)) { + throw new IllegalArgumentException("设备ID不能为空"); + } + return alertRuleMapper.findByTargetEquipmentId(equipmentId); + } + + @Override + public List getAlertRulesByArea(String area) { + if (!StringUtils.hasText(area)) { + throw new IllegalArgumentException("区域不能为空"); + } + return alertRuleMapper.findByTargetArea(area); + } + + @Override + public AlertRule createAlertRule(AlertRule alertRule) { + if (alertRule == null) { + throw new IllegalArgumentException("报警规则不能为空"); + } + + if (!validateAlertRule(alertRule)) { + throw new IllegalArgumentException("报警规则验证失败"); + } + + alertRule.setCreateTime(LocalDateTime.now()); + alertRule.setUpdateTime(LocalDateTime.now()); + alertRule.setStatus(1); // 默认启用 + + int result = alertRuleMapper.insert(alertRule); + if (result <= 0) { + throw new RuntimeException("创建报警规则失败"); + } + + return alertRule; + } + + @Override + public AlertRule updateAlertRule(AlertRule alertRule) { + if (alertRule == null || alertRule.getId() == null) { + throw new IllegalArgumentException("报警规则和ID不能为空"); + } + + // 检查规则是否存在 + AlertRule existingRule = getAlertRuleById(alertRule.getId()); + if (existingRule == null) { + throw new RuntimeException("未找到ID为 " + alertRule.getId() + " 的报警规则"); + } + + if (!validateAlertRule(alertRule)) { + throw new IllegalArgumentException("报警规则验证失败"); + } + + alertRule.setUpdateTime(LocalDateTime.now()); + + int result = alertRuleMapper.update(alertRule); + if (result <= 0) { + throw new RuntimeException("更新报警规则失败"); + } + + return alertRule; + } + + @Override + public boolean deleteAlertRule(Long id) { + if (id == null) { + throw new IllegalArgumentException("报警规则ID不能为空"); + } + + AlertRule existingRule = getAlertRuleById(id); + if (existingRule == null) { + throw new RuntimeException("未找到ID为 " + id + " 的报警规则"); + } + + int result = alertRuleMapper.deleteById(id); + return result > 0; + } + + @Override + public boolean enableAlertRule(Long id) { + if (id == null) { + throw new IllegalArgumentException("报警规则ID不能为空"); + } + + int result = alertRuleMapper.updateStatus(id, 1); + return result > 0; + } + + @Override + public boolean disableAlertRule(Long id) { + if (id == null) { + throw new IllegalArgumentException("报警规则ID不能为空"); + } + + int result = alertRuleMapper.updateStatus(id, 0); + return result > 0; + } + + @Override + public boolean validateAlertRule(AlertRule alertRule) { + if (alertRule == null) { + return false; + } + + if (!StringUtils.hasText(alertRule.getName())) { + return false; + } + + if (!StringUtils.hasText(alertRule.getParameter())) { + return false; + } + + // 检查阈值关系 + if (alertRule.getMinValue() != null && alertRule.getMaxValue() != null) { + if (alertRule.getMinValue() >= alertRule.getMaxValue()) { + return false; + } + } + + if (alertRule.getWarningValue() != null && alertRule.getCriticalValue() != null) { + if (alertRule.getWarningValue() >= alertRule.getCriticalValue()) { + return false; + } + } + + if (alertRule.getSeverityLevel() != null && + (alertRule.getSeverityLevel() < 1 || alertRule.getSeverityLevel() > 4)) { + return false; + } + + return true; + } +} \ No newline at end of file