通知规则设置的监测参数改成使用id关联

This commit is contained in:
guoshengxiong 2025-12-24 15:55:16 +08:00
parent 0178a065dd
commit c0e29aec93
9 changed files with 64 additions and 24 deletions

View File

@ -154,7 +154,7 @@ public class AsyncAiAnalyse {
);
if (rule != null) {
String monitoringLevelName = xzAiDeductRuleService.getLevelName(rule.getLevel());
EnableMessageDevRule messageDevRule = enableMessageDevRuleService.getEnableRule(ParamEnum.MessageModuleNameEnum.AIJC, hardwareId, dictionaryItem.getName(), monitoringLevelName, projectSn);
EnableMessageDevRule messageDevRule = enableMessageDevRuleService.getEnableRule(ParamEnum.MessageModuleNameEnum.AIJC, hardwareId, dictionaryItem.getId().toString(), monitoringLevelName, projectSn);
if (messageDevRule != null) {
if (Objects.equals(messageDevRule.getEnableSmsNotification(), 1) && Objects.equals(messageDevRule.getSmsPushFrequency(),0)) {
List<String> templateParams = new ArrayList<>();

View File

@ -96,7 +96,7 @@ public class DictionaryItemController {
if (dictionaryItemEntity == null) {
result.error500(MessageUtil.get("notFindErr"));
} else {
boolean ok = dictionaryItemService.updateById(dictionaryItem);
boolean ok = dictionaryItemService.edit(dictionaryItem);
if (ok) {
result.successMsg(MessageUtil.get("editSucess"));
}
@ -120,7 +120,7 @@ public class DictionaryItemController {
if (dictionaryItem == null) {
result.error500(MessageUtil.get("notFindErr"));
} else {
boolean ok = dictionaryItemService.removeById(MapUtils.getString(map, "id"));
boolean ok = dictionaryItemService.delete(map);
if (ok) {
result.successMsg(MessageUtil.get("deleteSucess"));
}

View File

@ -71,4 +71,8 @@ public interface IDictionaryItemService extends IService<DictionaryItem> {
* @return
*/
List<DictionaryItem> queryList(DictionaryItem dictionaryItem, HttpServletRequest req);
boolean edit(DictionaryItem dictionaryItem);
boolean delete(Map<String, Object> map);
}

View File

@ -2,6 +2,7 @@ package com.zhgd.xmgl.modules.basicdata.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.jeecg.common.execption.OpenAlertException;
import com.zhgd.jeecg.common.system.query.QueryGenerator;
@ -11,9 +12,13 @@ import com.zhgd.xmgl.modules.basicdata.entity.DictionaryItem;
import com.zhgd.xmgl.modules.basicdata.mapper.DictionaryItemMapper;
import com.zhgd.xmgl.modules.basicdata.mapper.DictionaryMapper;
import com.zhgd.xmgl.modules.basicdata.service.IDictionaryItemService;
import com.zhgd.xmgl.modules.project.entity.EnableMessageDevRule;
import com.zhgd.xmgl.modules.project.service.IEnableMessageDevRuleService;
import com.zhgd.xmgl.util.RefUtil;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@ -32,6 +37,9 @@ public class DictionaryItemServiceImpl extends ServiceImpl<DictionaryItemMapper,
private DictionaryItemMapper dictionaryItemMapper;
@Autowired
private DictionaryMapper dictionaryMapper;
@Lazy
@Autowired
private IEnableMessageDevRuleService enableMessageDevRuleService;
/**
* 获取字典列表
@ -51,7 +59,7 @@ public class DictionaryItemServiceImpl extends ServiceImpl<DictionaryItemMapper,
}
DictionaryItem di = new DictionaryItem();
di.setDictionaryEncoding(dictionaryEncoding);
HttpServletRequest request = Optional.ofNullable(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())).map(m->m.getRequest()).orElse(null);
HttpServletRequest request = Optional.ofNullable(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())).map(m -> m.getRequest()).orElse(null);
return queryList(di, request);
}
@ -136,4 +144,22 @@ public class DictionaryItemServiceImpl extends ServiceImpl<DictionaryItemMapper,
return pageList;
}
@Override
public boolean edit(DictionaryItem dictionaryItem) {
this.updateById(dictionaryItem);
enableMessageDevRuleService.update(null, new LambdaUpdateWrapper<EnableMessageDevRule>()
.set(EnableMessageDevRule::getMonitoringParameterName, dictionaryItem.getName())
.eq(EnableMessageDevRule::getParameterId, dictionaryItem.getId())
);
return true;
}
@Override
public boolean delete(Map<String, Object> map) {
String dicId = MapUtils.getString(map, "id");
this.removeById(dicId);
enableMessageDevRuleService.remove(new LambdaQueryWrapper<EnableMessageDevRule>().eq(EnableMessageDevRule::getParameterId, dicId));
return true;
}
}

View File

@ -821,7 +821,7 @@ public class EnvironmentAlarmServiceImpl extends ServiceImpl<EnvironmentAlarmMap
String threshold = NumberUtil.sub(environmentAlarm.getAlarmValue(), environmentAlarm.getExceed()) + "";
String time = DateUtil.formatDateTime(environmentAlarm.getAlarmTime());
String monitoringParameterName = environmentAlarmTypeService.getById(environmentAlarm.getAlarmTypeId()).getAlarmType();
EnableMessageDevRule messageDevRule = enableMessageDevRuleService.getEnableRule(ParamEnum.MessageModuleNameEnum.YCJC, environmentAlarm.getDeviceId(), monitoringParameterName, monitoringLevelName, environmentAlarm.getProjectSn());
EnableMessageDevRule messageDevRule = enableMessageDevRuleService.getEnableRule(ParamEnum.MessageModuleNameEnum.YCJC, environmentAlarm.getDeviceId(), environmentAlarm.getAlarmTypeId().toString(), monitoringLevelName, environmentAlarm.getProjectSn());
if (messageDevRule != null) {
if (Objects.equals(messageDevRule.getEnableSmsNotification(), 1) && Objects.equals(messageDevRule.getSmsPushFrequency(),0)) {
List<String> templateParams = new ArrayList<>();

View File

@ -155,24 +155,24 @@ public class EnableMessageDevRuleController {
Integer monitoringModule = MapUtils.getInteger(param, "monitoringModule");
List<EnableMessageDevRule> rtList = new ArrayList<>();
Map<String, Map<String, Map<String, EnableMessageDevRule>>> module2param2levelMap = enableMessageDevRuleService.queryList(param).stream().collect(Collectors.groupingBy(EnableMessageDevRule::getMonitoringModuleName,
Collectors.groupingBy(EnableMessageDevRule::getMonitoringParameterName,
Collectors.groupingBy(EnableMessageDevRule::getParameterId,
Collectors.toMap(EnableMessageDevRule::getMonitoringLevelName, Function.identity(), (existing, replacement) -> existing))));
if (Objects.equals(monitoringModule, ParamEnum.MessageModuleNameEnum.YCJC.getValue())) {
List<EnvironmentAlarmType> alarmTypes = environmentAlarmTypeService.list();
for (EnvironmentAlarmType alarmType : alarmTypes) {
String bj = "报警";
String yj = "预警";
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.YCJC.getDesc(), alarmType.getAlarmType(), bj));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.YCJC.getDesc(), alarmType.getAlarmType(), yj));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.YCJC.getDesc(), alarmType.getAlarmType(), bj, alarmType.getId().toString()));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.YCJC.getDesc(), alarmType.getAlarmType(), yj, alarmType.getId().toString()));
}
} else if (Objects.equals(monitoringModule, ParamEnum.MessageModuleNameEnum.AIJC.getValue())) {
List<DictionaryItem> dictList = dictionaryItemService.getDictList(DictionaryConstant.AI_ANALYSE_HARD_WARE_ALARM_RECORD_TYPE, projectSn);
for (DictionaryItem item : dictList) {
//问题等级1一级2二级3三级4四级
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "一级"));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "二级"));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "三级"));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "四级"));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "一级", item.getId().toString()));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "二级", item.getId().toString()));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "三级", item.getId().toString()));
rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "四级", item.getId().toString()));
}
}
Integer enableSmsNotification = MapUtils.getInteger(param, "enableSmsNotification");
@ -209,13 +209,15 @@ public class EnableMessageDevRuleController {
* @param moduleName 扬尘监测AI监测
* @param monitoringParameterName
* @param monitoringLevelName
* @param parameterId
* @return
*/
private EnableMessageDevRule getEnableMessageDevRuleVo(Map<String, Map<String, Map<String, EnableMessageDevRule>>> module2param2levelMap,
String moduleName,
String monitoringParameterName,
String monitoringLevelName) {
return Optional.ofNullable(module2param2levelMap.get(moduleName)).map(m -> m.get(monitoringParameterName)).map(m -> m.get(monitoringLevelName))
String monitoringLevelName,
String parameterId) {
return Optional.ofNullable(module2param2levelMap.get(moduleName)).map(m -> m.get(parameterId)).map(m -> m.get(monitoringLevelName))
.orElseGet(() -> {
EnableMessageDevRule v = new EnableMessageDevRule();
v.setIsEnabled(0);
@ -237,13 +239,13 @@ public class EnableMessageDevRuleController {
public Result editByCondition(@RequestBody EnableMessageDevRuleDto enableMessageDevRuleDto) {
String devSn = enableMessageDevRuleDto.getDevSn();
String monitoringModuleName = enableMessageDevRuleDto.getMonitoringModuleName();
String monitoringParameterName = enableMessageDevRuleDto.getMonitoringParameterName();
String parameterId = enableMessageDevRuleDto.getParameterId();
String monitoringLevelName = enableMessageDevRuleDto.getMonitoringLevelName();
EnableMessageDevRule db = enableMessageDevRuleService.getOne(new LambdaQueryWrapper<EnableMessageDevRule>()
.eq(EnableMessageDevRule::getDevSn, devSn)
.eq(EnableMessageDevRule::getProjectSn, enableMessageDevRuleDto.getProjectSn())
.eq(EnableMessageDevRule::getMonitoringModuleName, monitoringModuleName)
.eq(EnableMessageDevRule::getMonitoringParameterName, monitoringParameterName)
.eq(EnableMessageDevRule::getParameterId, parameterId)
.eq(EnableMessageDevRule::getMonitoringLevelName, monitoringLevelName));
if (db == null) {
enableMessageDevRuleService.save(enableMessageDevRuleDto);

View File

@ -169,4 +169,9 @@ public class EnableMessageDevRule implements Serializable {
*/
@ApiModelProperty(value = "短信告警接收人ids(多个,分割)")
private java.lang.String smsAlarmRecipientIds;
/**
* 监测参数id
*/
@ApiModelProperty(value = "监测参数id")
private java.lang.String parameterId;
}

View File

@ -172,7 +172,7 @@ public class EnableMessageDevRuleServiceImpl extends ServiceImpl<EnableMessageDe
}
@Override
public EnableMessageDevRule getEnableRule(ParamEnum.MessageModuleNameEnum moduleEnum, String devSn, String monitoringParameterName, String monitoringLevelName, String projectSn) {
public EnableMessageDevRule getEnableRule(ParamEnum.MessageModuleNameEnum moduleEnum, String devSn, String parameterId, String monitoringLevelName, String projectSn) {
EnableMessageDev messageDev = enableMessageDevService.getOne(new LambdaQueryWrapper<EnableMessageDev>()
.eq(EnableMessageDev::getMonitoringModule, moduleEnum.getValue())
.eq(EnableMessageDev::getDevSn, devSn)
@ -185,7 +185,7 @@ public class EnableMessageDevRuleServiceImpl extends ServiceImpl<EnableMessageDe
.eq(EnableMessageDevRule::getMonitoringModuleName, moduleEnum.getDesc())
.eq(EnableMessageDevRule::getDevSn, devSn)
.eq(EnableMessageDevRule::getProjectSn, messageDev.getProjectSn())
.eq(EnableMessageDevRule::getMonitoringParameterName, monitoringParameterName)
.eq(EnableMessageDevRule::getParameterId, parameterId)
.eq(EnableMessageDevRule::getMonitoringLevelName, monitoringLevelName)
.eq(EnableMessageDevRule::getIsEnabled, 1)
);
@ -223,8 +223,11 @@ public class EnableMessageDevRuleServiceImpl extends ServiceImpl<EnableMessageDe
@Override
public void sendSystemMessageIfEnable(EnableMessageDevRule rule, String type) {
if (rule != null && Objects.equals(rule.getEnableSystemMessagePush(), 1) && StrUtil.isNotBlank(rule.getAlarmRecipientIds()) && EnableMessageDevRuleServiceImpl.isInSystemTime(rule)) {
List<Long> ids = StrUtil.split(rule.getAlarmRecipientIds(), ",").stream().map(Convert::toLong).collect(Collectors.toList());
if (rule != null && Objects.equals(rule.getEnableSystemMessagePush(), 1) && EnableMessageDevRuleServiceImpl.isInSystemTime(rule)) {
List<Long> ids = new ArrayList<>();
if (StrUtil.isNotBlank(rule.getAlarmRecipientIds())) {
ids = StrUtil.split(rule.getAlarmRecipientIds(), ",").stream().map(Convert::toLong).collect(Collectors.toList());
}
NoticeMessagePromptTone tone = null;
//系统站内声音提示
if (Objects.equals(rule.getEnableSystemMessagePromptTone(), 1)) {

View File

@ -95,7 +95,7 @@ public class MessageDevRuleTask {
.le(EnvironmentAlarm::getAlarmTime, new Date())
).stream().collect(Collectors.groupingBy(EnvironmentAlarm::getDeviceId,
Collectors.groupingBy(EnvironmentAlarm::getProjectSn,
Collectors.groupingBy(ea -> environmentTypeMap.get(ea.getAlarmTypeId()).getAlarmType(),
Collectors.groupingBy(ea -> ea.getAlarmTypeId().toString(),
Collectors.groupingBy(ea -> Objects.equals(ea.getType(), 0) ? "报警" : "预警")))));
List<EnableMessageDevRule> ruleList = enableMessageDevRuleService.list(new LambdaQueryWrapper<EnableMessageDevRule>().eq(EnableMessageDevRule::getIsEnabled, 1));
Map<Long, SystemUser> userMap = systemUserService.list(new LambdaQueryWrapper<SystemUser>()).stream().collect(Collectors.toMap(SystemUser::getUserId, Function.identity(), (o1, o2) -> o1));
@ -114,7 +114,7 @@ public class MessageDevRuleTask {
return Objects.nonNull(Optional.ofNullable(dictDataMap.get(Convert.toStr(r.getAlarmType()))).map(m -> dicIdMap.get(m.getId())).map(XzAiDeductRule::getLevel).orElse(null));
}).collect(Collectors.groupingBy(AiAnalyseHardWareAlarmRecord::getHardwareId,
Collectors.groupingBy(AiAnalyseHardWareAlarmRecord::getProjectSn,
Collectors.groupingBy(r1 -> dictDataMap.get(Convert.toStr(r1.getAlarmType())).getName(),
Collectors.groupingBy(r1 -> dictDataMap.get(Convert.toStr(r1.getAlarmType())).getId().toString(),
Collectors.groupingBy(r -> Optional.of(dictDataMap.get(Convert.toStr(r.getAlarmType()))).map(m -> dicIdMap.get(m.getId())).map(r1 -> {
return xzAiDeductRuleService.getLevelName(r1.getLevel());
}).orElse(null))))));
@ -129,7 +129,7 @@ public class MessageDevRuleTask {
if (Objects.equals(ParamEnum.MessageModuleNameEnum.YCJC.getDesc(), moduleEntry.getKey())) {
List<EnvironmentAlarm> filterAlarms = Optional.ofNullable(devSn2ProjectSn2Parameter2LevelEnvironmentAlarmMap.get(rule.getDevSn()))
.map(m -> m.get(rule.getProjectSn()))
.map(m -> m.get(rule.getMonitoringParameterName())).map(m -> m.get(rule.getMonitoringLevelName())).orElse(new ArrayList<>());
.map(m -> m.get(rule.getParameterId())).map(m -> m.get(rule.getMonitoringLevelName())).orElse(new ArrayList<>());
List<EnvironmentAlarm> filterAlarms1 = getFilterEnvironmentAlarmRecords(filterAlarms, rule.getSmsPushFrequency());
if (CollUtil.isNotEmpty(filterAlarms1)) {
sendSmsNotice(rule, filterAlarms1.size(), userMap);
@ -150,7 +150,7 @@ public class MessageDevRuleTask {
else if (Objects.equals(ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), moduleEntry.getKey())) {
List<AiAnalyseHardWareAlarmRecord> filterAlarms = Optional.ofNullable(devSn2ProjectSn2Parameter2LevelAiMap.get(rule.getDevSn()))
.map(m -> m.get(rule.getProjectSn()))
.map(m -> m.get(rule.getMonitoringParameterName())).map(m -> m.get(rule.getMonitoringLevelName())).orElse(new ArrayList<>());
.map(m -> m.get(rule.getParameterId())).map(m -> m.get(rule.getMonitoringLevelName())).orElse(new ArrayList<>());
List<AiAnalyseHardWareAlarmRecord> filterAlarms1 = getFilterAiAlarmRecords(filterAlarms, rule.getSmsPushFrequency());
if (CollUtil.isNotEmpty(filterAlarms1)) {
sendSmsNotice(rule, filterAlarms1.size(), userMap);