|
|
@@ -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("请选择数据库字典中的预警状态");
|
|
|
+ }
|
|
|
+}
|