Compare commits

..

No commits in common. '58cbb0d94f15b418a1467bb309869c8797af604c' and '4030b204a736f468d68c5e68774f63807b86a642' have entirely different histories.

  1. 1
      ALOps_sys_backend/alops-admin/src/main/java/com/alops/web/controller/equManagement/ScheduleRulesController.java
  2. 1
      ALOps_sys_backend/alops-admin/src/main/java/com/alops/web/controller/exceptionController/AlertMessageController.java
  3. 1
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/AlertRule.java
  4. 1
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/vo/AlertRuleVo.java
  5. 4
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/mapper/DictAlarmParamMapper.java
  6. 10
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/AlertLaunchServiceImpl.java
  7. 124
      ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/AlertRuleServiceImpl.java
  8. 8
      ALOps_sys_backend/alops-system/src/main/resources/mapper/system/DictAlarmParamMapper.xml

@ -106,7 +106,6 @@ public class ScheduleRulesController extends BaseController
// util.exportExcel(response, list, "定时采集规则数据");
// }
//
/**
* 获取定时采集规则详细信息
*/

@ -1,7 +1,6 @@
package com.alops.web.controller.exceptionController;
import java.util.List;
import java.util.Map;
import com.alops.common.annotation.Log;
import com.alops.common.core.controller.BaseController;

@ -54,7 +54,6 @@ public class AlertRule extends BaseEntity
/** 预警模版(参数用数据库命名法) */
@Excel(name = "预警模版", readConverterExp = "参=数用数据库命名法")
@JsonIgnore
private String alertTemplate;
/** 预警类型 */

@ -49,7 +49,6 @@ public class AlertRuleVo extends BaseEntity {
@JsonIgnore
private String alertSql;
@JsonIgnore
/** 预警模版(参数用数据库命名法) */
@Excel(name = "预警模版", readConverterExp = "参=数用数据库命名法")
private String alertTemplate;

@ -2,7 +2,6 @@ package com.alops.system.mapper;
import com.alops.system.domain.DictAlarmParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;
import java.util.List;
@ -17,9 +16,6 @@ import java.util.List;
public interface DictAlarmParamMapper
{
String selectCnNameByParamName(@Param("paramName") String paramName);
List<DictAlarmParam> selectByTableName();
/**
* 查询请填写功能名称

@ -213,7 +213,7 @@ public class AlertLaunchServiceImpl implements IAlertLaunchService {
// 3. SQL:取每台设备最新记录和次新记录,比较该字段是否变化,并关联设备类型
String sql =
"SELECT g1.*, t.name AS equ_type, b.name AS equ_name, b.equ_number " +
"SELECT g1.*, t.name AS equ_type,b.name AS equ_name,b.equ_number" +
"FROM equ_gather g1 " +
"JOIN equ_gather g2 ON g1.equ_id = g2.equ_id " +
"JOIN equ_base b ON g1.equ_id = b.id " +
@ -222,8 +222,8 @@ public class AlertLaunchServiceImpl implements IAlertLaunchService {
" SELECT MAX(tg.gather_time) " +
" FROM equ_gather tg " +
" WHERE tg.equ_id = g1.equ_id " +
") " +
"AND g2.gather_time = ( " +
" ) " +
" AND g2.gather_time = ( " +
" SELECT MAX(t2.gather_time) " +
" FROM equ_gather t2 " +
" WHERE t2.equ_id = g1.equ_id " +
@ -232,8 +232,8 @@ public class AlertLaunchServiceImpl implements IAlertLaunchService {
" FROM equ_gather t3 " +
" WHERE t3.equ_id = g1.equ_id " +
" ) " +
") " +
"AND g1.`" + col + "` <> g2.`" + col + "`";
" ) " +
" AND g1.`" + col + "` <> g2.`" + col + "`";
// 4. 返回查询结果
return jdbcTemplate.queryForList(sql);

@ -11,7 +11,6 @@ import com.alops.system.domain.dto.AlertRuleAddDto;
import com.alops.system.domain.vo.AlertRuleVo;
import com.alops.system.mapper.AlertRuleConditionMapper;
import com.alops.system.mapper.AlertRuleMapper;
import com.alops.system.mapper.DictAlarmParamMapper;
import com.alops.system.service.IAlertRuleService;
import org.apache.commons.lang3.StringEscapeUtils;
@ -33,9 +32,6 @@ public class AlertRuleServiceImpl implements IAlertRuleService
@Autowired
private AlertRuleConditionMapper alertRuleConditionMapper;
@Autowired
private DictAlarmParamMapper dictAlarmParamMapper;
//生成预警规则
/**
* 保存预警规则及条件同时生成 SQL
@ -62,9 +58,6 @@ public class AlertRuleServiceImpl implements IAlertRuleService
}
rule.setAlertSql(sql);
rule.setEnable(1);
//生成模版
String alertTemplate=generateAlertTemplate(dto);
rule.setAlertTemplate(alertTemplate);
// 插入规则
alertRuleMapper.insertAlertRule(rule);
@ -98,11 +91,9 @@ public class AlertRuleServiceImpl implements IAlertRuleService
sql = buildSql(rule, conditions);
}
rule.setAlertSql(sql);
//生成模版
String alertTemplate=generateAlertTemplate(dto);
rule.setAlertTemplate(alertTemplate);
// 3. 更新规则表
alertRuleMapper.updateAlertRule(rule);
// 4. 先删旧条件,再插入新条件
@ -315,119 +306,6 @@ public class AlertRuleServiceImpl implements IAlertRuleService
}
/**
* 生成基础告警模板
*/
// public String generateAlertTemplate(AlertRuleAddDto dto) {
//
// AlertRuleCondition condition = dto.getAlertRuleConditionList().get(0);
// String paramName = condition.getParamName();
//
// // 查询字典表获取参数中文名
// String paramCnName = dictAlarmParamMapper.selectCnNameByParamName(paramName);
//
// if (paramCnName == null || paramCnName.isEmpty()) {
// paramCnName = paramName; // 查不到就用原名
// }
//
// String alertTemplate;
// if ("veneer_status".equalsIgnoreCase(paramName)) {
// // 单板运行状态模板
// alertTemplate = "设备名称{equ_name},设备号{equ_number},单板号是{veneer_id},单板运行状态是{veneer_status} 超出正常范围,请尽快检查,";
// } else {
// // 其他参数模板
// alertTemplate = String.format("设备名称{equ_name},设备号{equ_number},%s是{%s},超出正常范围,请尽快检查,", paramCnName, paramName);
// }
//
// return alertTemplate;
// }
public String generateAlertTemplate(AlertRuleAddDto dto) {
AlertRuleCondition condition = dto.getAlertRuleConditionList().get(0);
String paramName = condition.getParamName();
String operator = condition.getOperator();
String compareValue = condition.getCompareValue();
// 查询字典表获取参数中文名
String paramCnName = dictAlarmParamMapper.selectCnNameByParamName(paramName);
if (paramCnName == null || paramCnName.isEmpty()) {
paramCnName = paramName; // 查不到就用原名
}
String alertTemplate;
if ("veneer_status".equalsIgnoreCase(paramName)) {
// 单板运行状态模板
alertTemplate = "设备名称{equ_name},设备号{equ_number},单板号是{veneer_id},单板运行状态是{veneer_status} 超出正常范围,请尽快检查,";
} else {
// 判断是否有比较符号和比较值(即为新逻辑)
if (operator != null && !operator.isEmpty()) {
// 处理比较符号 -> 中文描述
String operatorDesc;
switch (operator) {
case "=":
operatorDesc = "等于";
break;
case "!=":
operatorDesc = "不等于";
break;
case "<":
operatorDesc = "小于";
break;
case "<=":
operatorDesc = "小于等于";
break;
case ">":
operatorDesc = "大于";
break;
case ">=":
operatorDesc = "大于等于";
break;
case "between":
// between 用逗号分隔两个值
String[] range = compareValue != null ? compareValue.split(",") : new String[0];
if (range.length == 2) {
operatorDesc = String.format("不在%s和%s之间", range[0], range[1]);
} else {
operatorDesc = "不在设定范围内";
}
break;
case "CHANGED":
operatorDesc = "发生了改变";
break;
default:
operatorDesc = operator;
}
// 根据不同符号生成模板
if ("CHANGED".equalsIgnoreCase(operator)) {
alertTemplate = String.format(
"设备名称{equ_name},设备号{equ_number},%s是{%s}, %s,请尽快检查,",
paramCnName, paramName, operatorDesc
);
} else if ("between".equalsIgnoreCase(operator)) {
alertTemplate = String.format(
"设备名称{equ_name},设备号{equ_number},%s{%s} %s,请尽快检查,",
paramCnName, paramName, operatorDesc
);
} else {
alertTemplate = String.format(
"设备名称{equ_name},设备号{equ_number},%s是{%s} %s %s,超出正常范围,请尽快检查,",
paramCnName, paramName, operatorDesc, compareValue
);
}
} else {
// 没有比较符号时,保持原逻辑
alertTemplate = String.format(
"设备名称{equ_name},设备号{equ_number},%s是{%s},超出正常范围,请尽快检查,",
paramCnName, paramName
);
}
}
return alertTemplate;
}
/**

@ -21,14 +21,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id, param_name, table_name, column_name, param_type from dict_alarm_param
</sql>
<!-- 根据参数英文名查询中文显示名 -->
<select id="selectCnNameByParamName" resultType="java.lang.String" parameterType="java.lang.String">
SELECT param_name
FROM dict_alarm_param
WHERE column_name = #{paramName}
LIMIT 1
</select>
<select id="selectDictAlarmParamList" parameterType="DictAlarmParam" resultMap="DictAlarmParamResult">
<include refid="selectDictAlarmParamVo"/>
<where>

Loading…
Cancel
Save