ソースを参照

feat(warning): 添加预警参考服务

- 实现 WarningReferenceService 类提供预警类型、状态查询功能
- 添加 types() 方法从监测指标表获取预警类型数据
- 添加 statuses() 方法从数据库字典获取预警状态数据
- 添加 validateType() 和 validateStatus() 方法验证参数合法性
- 统一返回格式为 Map 结构包含字典值和标签信息
- 集成 MyBatis-Plus 查询条件构建器优化数据检索
- 添加异常处理确保参数校验失败时抛出 Service 异常
林仔 1 週間 前
親
コミット
94971b5508

+ 44 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/service/WarningReferenceService.java

@@ -0,0 +1,44 @@
+package com.zksy.base.warning.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zksy.base.warning.domain.WarningType;
+import com.zksy.base.warning.mapper.WarningTypeMapper;
+import com.zksy.common.core.domain.entity.SysDictData;
+import com.zksy.common.exception.ServiceException;
+import com.zksy.system.mapper.SysDictDataMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import java.util.*;
+
+/** 类型来自监测指标表;等级和状态来自数据库字典。 */
+@Service
+public class WarningReferenceService {
+    @Autowired private WarningTypeMapper typeMapper;
+    @Autowired private SysDictDataMapper dictMapper;
+
+    public List<Map<String, Object>> types() {
+        List<Map<String, Object>> result = new ArrayList<>();
+        for (WarningType type : typeMapper.selectList(new LambdaQueryWrapper<WarningType>().orderByAsc(WarningType::getId))) {
+            Map<String, Object> option = new LinkedHashMap<>();
+            option.put("dictValue", type.getWarningCode());
+            option.put("dictLabel", type.getWarningName());
+            option.put("typeCode", type.getWarningCode());
+            option.put("typeName", type.getWarningName());
+            result.add(option);
+        }
+        return result;
+    }
+
+    public List<SysDictData> statuses() { return dictMapper.selectDictDataByType("pre_alarm_status"); }
+
+    public void validateType(String type) {
+        if (typeMapper.selectCount(new LambdaQueryWrapper<WarningType>().eq(WarningType::getWarningCode, type)) == 0)
+            throw new ServiceException("请选择监测指标表中的预警类型");
+    }
+
+    public void validateStatus(String status) {
+        if (status != null && !status.trim().isEmpty()
+                && statuses().stream().noneMatch(d -> status.equals(d.getDictValue())))
+            throw new ServiceException("请选择数据库字典中的预警状态");
+    }
+}