fix: 优化逻辑
This commit is contained in:
parent
aea105c1f3
commit
8e8c5dc2f4
@ -24,7 +24,7 @@ public interface IMsWarnRuleBService extends IService<MsWarnRuleB> {
|
|||||||
/**
|
/**
|
||||||
* 获取告警类型对应的要素列表
|
* 获取告警类型对应的要素列表
|
||||||
*/
|
*/
|
||||||
List<WarnYsVo> getAllYs(String ruleType);
|
List<WarnYsVo> getAllYs(String ruleId,String ruleType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增或修改预警规则
|
* 新增或修改预警规则
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.yfd.platform.qgc_base.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@ -25,10 +26,12 @@ import com.yfd.platform.qgc_sys.warnRule.vo.WarnYsVo;
|
|||||||
import com.yfd.platform.utils.*;
|
import com.yfd.platform.utils.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -115,18 +118,59 @@ public class MsWarnRuleBServiceImpl extends ServiceImpl<MsWarnRuleBMapper, MsWar
|
|||||||
return count > 0;
|
return count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最小值
|
||||||
|
*/
|
||||||
|
private BigDecimal minVal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大值
|
||||||
|
*/
|
||||||
|
private BigDecimal maxVal;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WarnYsVo> getAllYs(String ruleType) {
|
public List<WarnYsVo> getAllYs(String ruleId, String ruleType) {
|
||||||
String dbRuleType = getOldRuleType(ruleType);
|
String dbRuleType = getOldRuleType(ruleType);
|
||||||
String sql = "SELECT t2.TB_ID AS tbId, t2.YS, t3.YS_SHOW_NAME AS ysName\n" +
|
boolean hasRuleId = (ruleId != null && !ruleId.isEmpty());
|
||||||
"FROM MS_WARN_RULE_B t1\n" +
|
|
||||||
"INNER JOIN MS_WARN_RULE_DETAIL_B t2 ON t1.ID = t2.RULE_ID\n" +
|
// 动态构建 SELECT 子句
|
||||||
"INNER JOIN ST_YS_B t3 ON t2.YS = t3.YS\n" +
|
StringBuilder selectClause = new StringBuilder(
|
||||||
"WHERE t1.RULE_TYPE ='" + dbRuleType + "'\n" +
|
"SELECT t2.TB_ID AS tbId, t2.YS, t3.YS_SHOW_NAME AS ysName"
|
||||||
" AND t1.IS_DELETED = 0\n" +
|
);
|
||||||
" AND t2.IS_DELETED = 0\n" +
|
// 有 ruleId 时额外查询 MIN_VAL 和 MAX_VAL
|
||||||
"GROUP BY t2.TB_ID, t2.YS, t3.YS_SHOW_NAME";
|
if (hasRuleId) {
|
||||||
|
selectClause.append(",t2.WARN_LEVEL,t2.MARK,t2.LVL, t2.MIN_VAL, t2.MAX_VAL");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 动态构建 GROUP BY 子句(与 SELECT 对应)
|
||||||
|
StringBuilder groupByClause = new StringBuilder(
|
||||||
|
"GROUP BY t2.TB_ID, t2.YS, t3.YS_SHOW_NAME"
|
||||||
|
);
|
||||||
|
if (hasRuleId) {
|
||||||
|
groupByClause.append(",t2.WARN_LEVEL,t2.MARK,t2.LVL, t2.MIN_VAL, t2.MAX_VAL");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 基础 FROM / JOIN 和固定过滤条件(删除标志)
|
||||||
|
String fromJoin = "\nFROM MS_WARN_RULE_B t1" +
|
||||||
|
"\nINNER JOIN MS_WARN_RULE_DETAIL_B t2 ON t1.ID = t2.RULE_ID" +
|
||||||
|
"\nINNER JOIN ST_YS_B t3 ON t2.YS = t3.YS" +
|
||||||
|
"\nWHERE t1.IS_DELETED = 0" +
|
||||||
|
"\n AND t2.IS_DELETED = 0";
|
||||||
|
|
||||||
|
// 动态条件(使用占位符)
|
||||||
|
String condition;
|
||||||
Map<String, Object> paramMap = new HashMap<>();
|
Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
if (hasRuleId) {
|
||||||
|
condition = "\n AND t1.ID = #{map.ruleId}";
|
||||||
|
paramMap.put("ruleId", ruleId);
|
||||||
|
} else {
|
||||||
|
condition = "\n AND t1.RULE_TYPE = #{map.ruleType}";
|
||||||
|
paramMap.put("ruleType", dbRuleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组装完整 SQL
|
||||||
|
String sql = selectClause + fromJoin + condition + "\n" + groupByClause;
|
||||||
|
|
||||||
return microservicDynamicSQLMapper.getAllListWithResultType(sql, paramMap, WarnYsVo.class);
|
return microservicDynamicSQLMapper.getAllListWithResultType(sql, paramMap, WarnYsVo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,11 +183,11 @@ public class MsWarnRuleBServiceImpl extends ServiceImpl<MsWarnRuleBMapper, MsWar
|
|||||||
org.springframework.beans.BeanUtils.copyProperties(vo, entity);
|
org.springframework.beans.BeanUtils.copyProperties(vo, entity);
|
||||||
entity.setId(vo.getId());
|
entity.setId(vo.getId());
|
||||||
entity.setModifyTime(new Date());
|
entity.setModifyTime(new Date());
|
||||||
|
// entity.setRuleType(getOldRuleType(entity.getRuleType()));
|
||||||
List<MsWarnRuleDetailVo> detail = vo.getDetail();
|
List<MsWarnRuleDetailVo> detail = vo.getDetail();
|
||||||
Integer lvl = null;
|
Integer lvl = null;
|
||||||
if (!CollectionUtils.isEmpty(detail) && detail.get(0) != null && detail.get(0).getLvl() != null) {
|
if (!CollectionUtils.isEmpty(detail) && detail.getFirst() != null && detail.getFirst().getLvl() != null) {
|
||||||
lvl = Integer.parseInt(detail.get(0).getLvl());
|
lvl = Integer.parseInt(detail.getFirst().getLvl());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MsWarnRuleDetailB> detailBList = new ArrayList<>();
|
List<MsWarnRuleDetailB> detailBList = new ArrayList<>();
|
||||||
@ -156,10 +200,13 @@ public class MsWarnRuleBServiceImpl extends ServiceImpl<MsWarnRuleBMapper, MsWar
|
|||||||
i.getAndIncrement();
|
i.getAndIncrement();
|
||||||
MsWarnRuleDetailB detailB = new MsWarnRuleDetailB();
|
MsWarnRuleDetailB detailB = new MsWarnRuleDetailB();
|
||||||
detailB.setRuleId(vo.getId());
|
detailB.setRuleId(vo.getId());
|
||||||
detailB.setTbId(ysVo.getTbId());
|
|
||||||
detailB.setYs(ysVo.getYs());
|
|
||||||
detailB.setWarnLevel(detailVo.getWarnLevel());
|
detailB.setWarnLevel(detailVo.getWarnLevel());
|
||||||
detailB.setLvl(detailVo.getLvl() != null ? Integer.parseInt(detailVo.getLvl()) : null);
|
detailB.setLvl(detailVo.getLvl() != null ? Integer.parseInt(detailVo.getLvl()) : null);
|
||||||
|
detailB.setTbId(ysVo.getTbId());
|
||||||
|
detailB.setYs(ysVo.getYs());
|
||||||
|
detailB.setMinVal(ysVo.getMinVal());
|
||||||
|
detailB.setMaxVal(ysVo.getMaxVal());
|
||||||
|
detailB.setMark(ysVo.getMark());
|
||||||
DateTime dateTime = DateUtil.offsetSecond(new Date(), i.get());
|
DateTime dateTime = DateUtil.offsetSecond(new Date(), i.get());
|
||||||
detailB.setTm(dateTime);
|
detailB.setTm(dateTime);
|
||||||
detailB.setRecordUser(SecurityUtils.getCurrentUsername());
|
detailB.setRecordUser(SecurityUtils.getCurrentUsername());
|
||||||
@ -326,15 +373,15 @@ public class MsWarnRuleBServiceImpl extends ServiceImpl<MsWarnRuleBMapper, MsWar
|
|||||||
DataSourceResult<MsWarnRuleBVo> dataSourceResult = new DataSourceResult<>();
|
DataSourceResult<MsWarnRuleBVo> dataSourceResult = new DataSourceResult<>();
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
sql.append("SELECT id AS bindId, STCD, STNM, STTP_CODE AS sttpCode, RULE_NAME AS ruleName, ")
|
sql.append("SELECT id AS bindId, STCD, STNM, STTP_CODE AS sttpCode, RULE_NAME AS ruleName, ")
|
||||||
.append("RULE_TYPE AS ruleType, recordUser, MODIFY_TIME AS modifyTime, isShow, RULE_CODE AS ruleCode ")
|
.append("RULE_TYPE AS ruleType, recordUser, MODIFY_TIME AS modifyTime, isShow, RULE_CODE AS ruleCode ")
|
||||||
.append("FROM (\n")
|
.append("FROM (\n")
|
||||||
.append("SELECT t1.ID, t1.STCD, t3.STNM, t3.STTP_CODE, t2.RULE_NAME, t2.RULE_TYPE, ")
|
.append("SELECT t1.ID, t1.STCD, t3.STNM, t3.STTP_CODE, t2.RULE_NAME, t2.RULE_TYPE, ")
|
||||||
.append("t2.RECORD_USER AS recordUser, t2.MODIFY_TIME, t2.DESCRIPTION, t2.IS_SHOW AS isShow, t2.RULE_CODE ")
|
.append("t2.RECORD_USER AS recordUser, t2.MODIFY_TIME, t2.DESCRIPTION, t2.IS_SHOW AS isShow, t2.RULE_CODE ")
|
||||||
.append("FROM MS_WARN_RULE_STBPRP_B t1\n")
|
.append("FROM MS_WARN_RULE_STBPRP_B t1\n")
|
||||||
.append("INNER JOIN MS_WARN_RULE_B t2 ON t1.RULE_ID = t2.ID\n")
|
.append("INNER JOIN MS_WARN_RULE_B t2 ON t1.RULE_ID = t2.ID\n")
|
||||||
.append("INNER JOIN V_MS_STBPRP_T t3 ON t1.STCD = t3.STCD\n")
|
.append("INNER JOIN V_MS_STBPRP_T t3 ON t1.STCD = t3.STCD\n")
|
||||||
.append("WHERE t2.RULE_CODE IN ('common','custom')\n")
|
.append("WHERE t2.RULE_CODE IN ('common','custom')\n")
|
||||||
.append(") WHERE 1=1");
|
.append(") WHERE 1=1");
|
||||||
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = new HashMap<>();
|
||||||
// 处理过滤条件
|
// 处理过滤条件
|
||||||
|
|||||||
@ -52,6 +52,7 @@ public class OverviewVmsstbprptVo implements Serializable {
|
|||||||
private BigDecimal inv;
|
private BigDecimal inv;
|
||||||
private Integer invinmn;
|
private Integer invinmn;
|
||||||
private Date stdsdt;
|
private Date stdsdt;
|
||||||
|
private String precis;
|
||||||
private Date pststdt;
|
private Date pststdt;
|
||||||
private Date pesstdt;
|
private Date pesstdt;
|
||||||
private Date swdt;
|
private Date swdt;
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package com.yfd.platform.qgc_sys.warnRule.controller;
|
package com.yfd.platform.qgc_sys.warnRule.controller;
|
||||||
|
|
||||||
|
import com.yfd.platform.common.DataSourceLoadOptionsBase;
|
||||||
import com.yfd.platform.common.DataSourceRequest;
|
import com.yfd.platform.common.DataSourceRequest;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.config.ResponseResult;
|
||||||
import com.yfd.platform.qgc_base.service.IMsWarnRuleBService;
|
import com.yfd.platform.qgc_base.service.IMsWarnRuleBService;
|
||||||
import com.yfd.platform.qgc_sys.warnRule.vo.MsWarnRuleBVo;
|
import com.yfd.platform.qgc_sys.warnRule.vo.MsWarnRuleBVo;
|
||||||
|
import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@ -33,11 +35,13 @@ public class MsWarnRuleBController {
|
|||||||
@PostMapping("/ysList")
|
@PostMapping("/ysList")
|
||||||
@Operation(summary = "获取告警类型对应的要素")
|
@Operation(summary = "获取告警类型对应的要素")
|
||||||
public ResponseResult getAllYs(@RequestBody DataSourceRequest dataSourceRequest) {
|
public ResponseResult getAllYs(@RequestBody DataSourceRequest dataSourceRequest) {
|
||||||
String ruleType = getFilterFieldValue(dataSourceRequest, "ruleType");
|
DataSourceLoadOptionsBase loadOptions = dataSourceRequest.toDevRequest();
|
||||||
|
String ruleType = QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "ruleType");
|
||||||
|
String ruleId = QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "ruleId");
|
||||||
if (ruleType == null || ruleType.isEmpty()) {
|
if (ruleType == null || ruleType.isEmpty()) {
|
||||||
return ResponseResult.error("ruleType 不能为空");
|
return ResponseResult.error("ruleType 不能为空");
|
||||||
}
|
}
|
||||||
return ResponseResult.successData(msWarnRuleBService.getAllYs(ruleType));
|
return ResponseResult.successData(msWarnRuleBService.getAllYs(ruleId,ruleType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/addOrUpdate")
|
@PostMapping("/addOrUpdate")
|
||||||
@ -108,31 +112,31 @@ public class MsWarnRuleBController {
|
|||||||
return ResponseResult.successData(msWarnRuleBService.getRuleListByStcd(stcd, ruleType, lvl));
|
return ResponseResult.successData(msWarnRuleBService.getRuleListByStcd(stcd, ruleType, lvl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 从 DataSourceRequest 过滤条件中提取指定字段的值
|
// * 从 DataSourceRequest 过滤条件中提取指定字段的值
|
||||||
*/
|
// */
|
||||||
private String getFilterFieldValue(DataSourceRequest request, String fieldName) {
|
// private String getFilterFieldValue(DataSourceRequest request, String fieldName) {
|
||||||
if (request == null || request.getFilter() == null) {
|
// if (request == null || request.getFilter() == null) {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
return findFilterValue(request.getFilter(), fieldName);
|
// return findFilterValue(request.getFilter(), fieldName);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private String findFilterValue(DataSourceRequest.FilterDescriptor filter, String fieldName) {
|
// private String findFilterValue(DataSourceRequest.FilterDescriptor filter, String fieldName) {
|
||||||
if (filter == null) {
|
// if (filter == null) {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
if (fieldName.equals(filter.getField()) && filter.getValue() != null) {
|
// if (fieldName.equals(filter.getField()) && filter.getValue() != null) {
|
||||||
return filter.getValue().toString();
|
// return filter.getValue().toString();
|
||||||
}
|
// }
|
||||||
if (filter.getFilters() != null) {
|
// if (filter.getFilters() != null) {
|
||||||
for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
|
// for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
|
||||||
String value = findFilterValue(child, fieldName);
|
// String value = findFilterValue(child, fieldName);
|
||||||
if (value != null) {
|
// if (value != null) {
|
||||||
return value;
|
// return value;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,12 @@ public class WarnYsVo {
|
|||||||
/** 要素编码 */
|
/** 要素编码 */
|
||||||
private String ys;
|
private String ys;
|
||||||
|
|
||||||
|
/** 等级 */
|
||||||
|
private String lvl;
|
||||||
|
|
||||||
|
/** 告警等级 */
|
||||||
|
private String warnLevel;
|
||||||
|
|
||||||
/** 要素名称 */
|
/** 要素名称 */
|
||||||
private String ysName;
|
private String ysName;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user