19 changed files with 529 additions and 19 deletions
@ -0,0 +1,64 @@
|
||||
package com.mh.web.controller.alarm; |
||||
|
||||
import com.mh.common.annotation.Log; |
||||
import com.mh.common.core.controller.BaseController; |
||||
import com.mh.common.core.domain.AjaxResult; |
||||
import com.mh.common.core.domain.entity.AlarmRecords; |
||||
import com.mh.common.core.page.TableDataInfo; |
||||
import com.mh.common.enums.BusinessType; |
||||
import com.mh.system.service.operation.IAlarmRecordsService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.security.access.prepost.PreAuthorize; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 报警记录查询规则 |
||||
* @date 2025-01-14 17:32:55 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/alarm/ard") |
||||
public class AlarmRecordsController extends BaseController { |
||||
|
||||
@Autowired |
||||
private IAlarmRecordsService alarmRecordsService; |
||||
|
||||
/** |
||||
* 获取报警规则记录列表内容数据 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:ard:list')") |
||||
@GetMapping("/list") |
||||
public TableDataInfo list(AlarmRecords alarmRecords) |
||||
{ |
||||
startPage(); |
||||
List<AlarmRecords> list = alarmRecordsService.selectAlarmRecordsList(alarmRecords); |
||||
return getDataTable(list); |
||||
} |
||||
|
||||
/** |
||||
* 根据报警规则记录id获取详细信息 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:ard:query')") |
||||
@GetMapping(value = "/{acdId}") |
||||
public AjaxResult getInfo(@PathVariable String acdId) |
||||
{ |
||||
return success(alarmRecordsService.selectAlarmRecordsById(acdId)); |
||||
} |
||||
|
||||
/** |
||||
* 删除报警规则记录管理 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:ard:remove')") |
||||
@Log(title = "报警规则记录管理", businessType = BusinessType.DELETE) |
||||
@DeleteMapping("/{acdIds}") |
||||
public AjaxResult remove(@PathVariable String[] acdIds) |
||||
{ |
||||
return toAjax(alarmRecordsService.deleteAlarmRecordsByIds(acdIds)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.mh.common.utils; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.function.BiPredicate; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 数据比较值 |
||||
* @date 2025-02-21 15:56:56 |
||||
*/ |
||||
public class BigDecimalUtils { |
||||
// 定义运算符与比较逻辑的映射
|
||||
private static final Map<String, BiPredicate<BigDecimal, BigDecimal>> OPERATORS = new HashMap<>(); |
||||
|
||||
static { |
||||
// 初始化支持的运算符
|
||||
OPERATORS.put(">", (a, b) -> a.compareTo(b) > 0); |
||||
OPERATORS.put(">=", (a, b) -> a.compareTo(b) >= 0); |
||||
OPERATORS.put("<", (a, b) -> a.compareTo(b) < 0); |
||||
OPERATORS.put("<=", (a, b) -> a.compareTo(b) <= 0); |
||||
OPERATORS.put("==", (a, b) -> a.compareTo(b) == 0); |
||||
OPERATORS.put("!=", (a, b) -> a.compareTo(b) != 0); |
||||
} |
||||
|
||||
/** |
||||
* 根据运算符比较两个 BigDecimal |
||||
* @param operator 运算符(如 ">", ">=") |
||||
* @param a 第一个数值 |
||||
* @param b 第二个数值 |
||||
* @return 比较结果 |
||||
* @throws IllegalArgumentException 如果运算符无效 |
||||
*/ |
||||
public static boolean compare(String operator, BigDecimal a, BigDecimal b) { |
||||
BiPredicate<BigDecimal, BigDecimal> predicate = OPERATORS.get(operator); |
||||
if (predicate == null) { |
||||
throw new IllegalArgumentException("不支持的运算符: " + operator); |
||||
} |
||||
return predicate.test(a, b); |
||||
} |
||||
} |
@ -0,0 +1,111 @@
|
||||
package com.mh.quartz.task; |
||||
|
||||
import com.mh.common.core.domain.entity.AlarmCode; |
||||
import com.mh.common.core.domain.entity.AlarmRecords; |
||||
import com.mh.common.core.domain.entity.AlarmRules; |
||||
import com.mh.common.core.domain.entity.CollectionParamsManage; |
||||
import com.mh.common.utils.BigDecimalUtils; |
||||
import com.mh.common.utils.DateUtils; |
||||
import com.mh.system.service.device.ICollectionParamsManageService; |
||||
import com.mh.system.service.operation.IAlarmCodeService; |
||||
import com.mh.system.service.operation.IAlarmRecordsService; |
||||
import com.mh.system.service.operation.IAlarmRulesService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 创建报警记录 |
||||
* @date 2025-02-21 08:48:48 |
||||
*/ |
||||
@Slf4j |
||||
@Component("createAlarmTask") |
||||
public class CreateAlarmTask { |
||||
|
||||
private final IAlarmRulesService alarmRulesService; |
||||
|
||||
private final IAlarmCodeService alarmCodeService; |
||||
|
||||
private final ICollectionParamsManageService collectionParamsManageService; |
||||
|
||||
private final IAlarmRecordsService alarmRecordService; |
||||
|
||||
@Autowired |
||||
public CreateAlarmTask(IAlarmRulesService alarmRulesService, IAlarmCodeService alarmCodeService, ICollectionParamsManageService collectionParamsManageService, IAlarmRecordsService alarmRecordService) { |
||||
this.alarmRulesService = alarmRulesService; |
||||
this.alarmCodeService = alarmCodeService; |
||||
this.collectionParamsManageService = collectionParamsManageService; |
||||
this.alarmRecordService = alarmRecordService; |
||||
} |
||||
|
||||
public void createAlarmTask() { |
||||
log.info("创建报警记录"); |
||||
// 查询仪表报警规则记录,查看哪些规则启用了
|
||||
List<AlarmRules> alarmRules = alarmRulesService.selectAlarmRulesListByStatus(0); |
||||
// 循环查询报警规则,判断是否满足报警条件
|
||||
for (AlarmRules alarmRule : alarmRules) { |
||||
// 判断报警类型
|
||||
if ("0".equals(alarmRule.getAlarmType())) { |
||||
// 当前是越限事件
|
||||
// 查询事件类型查询对应的报警模板内容
|
||||
AlarmCode alarmCode = alarmCodeService.selectAlarmCodeByAlarmType(alarmRule.getEventType()); |
||||
// 获取当前采集参数值
|
||||
CollectionParamsManage collectionParamsManage = collectionParamsManageService.selectCollectionParamsManageById(alarmRule.getCpmId()); |
||||
// 判断当前值是否是当前事件
|
||||
AlarmRecords alarmRecords = new AlarmRecords(); |
||||
BigDecimal curValue = collectionParamsManage.getCurValue(); |
||||
Date curTime = collectionParamsManage.getCurTime(); |
||||
// 阈值
|
||||
String threshold1 = alarmRule.getThreshold1(); |
||||
if (alarmRule.getTimePeriodSet() == 0 && DateUtils.isSameDay(curTime, new Date())) { |
||||
// 执行相关操作
|
||||
insertOrUpdateRecord(alarmRule, curValue, threshold1, alarmCode, alarmRecords, collectionParamsManage); |
||||
} else if (alarmRule.getTimePeriodSet() == 1 |
||||
&& DateUtils.isSameDay(collectionParamsManage.getCurTime(), new Date()) |
||||
&& DateUtils.isCurrentTimeInRange(alarmRule.getBeginTime(), alarmRule.getEndTime(), curTime) |
||||
) { |
||||
// 执行相关操作
|
||||
insertOrUpdateRecord(alarmRule, curValue, threshold1, alarmCode, alarmRecords, collectionParamsManage); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void insertOrUpdateRecord(AlarmRules alarmRule, BigDecimal curValue, String threshold1, AlarmCode alarmCode, AlarmRecords alarmRecords, CollectionParamsManage collectionParamsManage) { |
||||
boolean compare = BigDecimalUtils.compare(alarmRule.getCondition1(), curValue, new BigDecimal(threshold1)); |
||||
if (compare) { |
||||
// 创建报警记录
|
||||
String content = alarmCode.getMsgContent(); |
||||
content.replace("#{curValue}", curValue.toString()); |
||||
content.replace("#{setValue}", alarmRule.getCondition1() + threshold1); |
||||
alarmRecords.setContent(content); |
||||
alarmRecords.setAlarmType(alarmRule.getAlarmType()); |
||||
alarmRecords.setEventType(alarmRule.getEventType()); |
||||
alarmRecords.setAlarmLevel(alarmRule.getAlarmLevel()); |
||||
alarmRecords.setLedgerId(alarmRule.getLedgerId()); |
||||
alarmRecords.setCpmId(alarmRule.getCpmId()); |
||||
alarmRecords.setDeviceName(alarmRule.getDeviceName()); |
||||
alarmRecords.setCpmName(alarmRule.getCpmName()); |
||||
alarmRecords.setCreateTime(collectionParamsManage.getCurTime()); |
||||
// 判断报警记录是否已经存在
|
||||
AlarmRecords isExits = alarmRecordService.selectIsExist(alarmRecords); |
||||
if (isExits == null) { |
||||
alarmRecordService.insertAlarmRecord(alarmRecords); |
||||
} else { |
||||
// 更新报警记录
|
||||
alarmRecords.setContent(content); |
||||
alarmRecords.setCreateTime(collectionParamsManage.getCurTime()); |
||||
alarmRecordService.updateAlarmRecord(alarmRecords); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.mh.system.mapper.operation; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.mh.common.core.domain.entity.AlarmRecords; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 报警记录mapper |
||||
* @date 2025-02-21 14:14:31 |
||||
*/ |
||||
@Mapper |
||||
public interface AlarmRecordsMapper extends BaseMapper<AlarmRecords> { |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.mh.system.service.device; |
||||
|
||||
import com.alibaba.fastjson2.JSONObject; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 室内温湿度查询 |
||||
* @date 2025-02-21 16:32:02 |
||||
*/ |
||||
public interface IIndoorTempMonitorService { |
||||
|
||||
JSONObject getIndoorTempByFloor(String floorId); |
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.mh.system.service.device.impl; |
||||
|
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.mh.common.core.domain.entity.CollectionParamsManage; |
||||
import com.mh.system.mapper.device.CollectionParamsManageMapper; |
||||
import com.mh.system.service.device.IIndoorTempMonitorService; |
||||
import jakarta.annotation.Resource; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 室内温湿度查询实现类 |
||||
* @date 2025-02-21 16:32:23 |
||||
*/ |
||||
@Service |
||||
public class IndoorTempMonitorServiceImpl implements IIndoorTempMonitorService { |
||||
|
||||
@Resource |
||||
private CollectionParamsManageMapper collectionParamsManageMapper; |
||||
|
||||
@Override |
||||
public JSONObject getIndoorTempByFloor(String floorId) { |
||||
// 查询采集类型是温度的参数,采集参数是99
|
||||
List<Map<String, Objects>> collectionParamsManages = collectionParamsManageMapper.selectByParamType(floorId,"99"); |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,27 @@
|
||||
package com.mh.system.service.operation; |
||||
|
||||
import com.mh.common.core.domain.entity.AlarmRecords; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 报警记录生成 |
||||
* @date 2025-02-21 10:13:37 |
||||
*/ |
||||
public interface IAlarmRecordsService { |
||||
|
||||
AlarmRecords selectIsExist(AlarmRecords alarmRecords); |
||||
|
||||
void insertAlarmRecord(AlarmRecords alarmRecords); |
||||
|
||||
void updateAlarmRecord(AlarmRecords alarmRecords); |
||||
|
||||
List<AlarmRecords> selectAlarmRecordsList(AlarmRecords alarmRecords); |
||||
|
||||
AlarmRecords selectAlarmRecordsById(String acdId); |
||||
|
||||
int deleteAlarmRecordsByIds(String[] acdIds); |
||||
} |
@ -0,0 +1,114 @@
|
||||
package com.mh.system.service.operation.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.mh.common.core.domain.entity.AlarmRecords; |
||||
import com.mh.system.mapper.operation.AlarmRecordsMapper; |
||||
import com.mh.system.service.operation.IAlarmRecordsService; |
||||
import jakarta.annotation.Resource; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.text.SimpleDateFormat; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 报警记录实现类 |
||||
* @date 2025-02-21 14:13:13 |
||||
*/ |
||||
@Service |
||||
public class AlarmRecordsServiceImpl implements IAlarmRecordsService { |
||||
|
||||
@Resource |
||||
private AlarmRecordsMapper alarmRecordsMapper; |
||||
|
||||
@Override |
||||
public AlarmRecords selectIsExist(AlarmRecords alarmRecords) { |
||||
QueryWrapper<AlarmRecords> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("alarm_type", alarmRecords.getAlarmType()); |
||||
queryWrapper.eq("event_type", alarmRecords.getEventType()); |
||||
queryWrapper.eq("alarm_level", alarmRecords.getAlarmLevel()); |
||||
queryWrapper.eq("ledger_id", alarmRecords.getLedgerId()); |
||||
queryWrapper.eq("cpm_id", alarmRecords.getCpmId()); |
||||
|
||||
// 添加PostgreSQL特有的时间格式判断
|
||||
queryWrapper.apply("to_char(create_time, 'YYYY-MM-DD HH24') = {0}", |
||||
new SimpleDateFormat("yyyy-MM-dd HH").format(alarmRecords.getCreateTime())); |
||||
|
||||
return alarmRecordsMapper.selectOne(queryWrapper); |
||||
} |
||||
|
||||
@Override |
||||
public void insertAlarmRecord(AlarmRecords alarmRecords) { |
||||
alarmRecordsMapper.insert(alarmRecords); |
||||
} |
||||
|
||||
@Override |
||||
public void updateAlarmRecord(AlarmRecords alarmRecords) { |
||||
alarmRecordsMapper.updateById(alarmRecords); |
||||
} |
||||
|
||||
@Override |
||||
public List<AlarmRecords> selectAlarmRecordsList(AlarmRecords alarmRecords) { |
||||
if (alarmRecords == null) { |
||||
return List.of(); |
||||
} |
||||
QueryWrapper<AlarmRecords> queryWrapper = new QueryWrapper<>(); |
||||
// 报警类型
|
||||
if (!alarmRecords.getAlarmType().isEmpty()) { |
||||
queryWrapper.eq("alarm_type", alarmRecords.getAlarmType()); |
||||
} |
||||
// 事件类型
|
||||
if (!alarmRecords.getEventType().isEmpty()) { |
||||
queryWrapper.eq("event_type", alarmRecords.getEventType()); |
||||
} |
||||
// 报警等级
|
||||
if (!alarmRecords.getAlarmLevel().isEmpty()) { |
||||
queryWrapper.eq("alarm_level", alarmRecords.getAlarmLevel()); |
||||
} |
||||
// 设备名称
|
||||
if (!alarmRecords.getDeviceName().isEmpty()) { |
||||
queryWrapper.like("device_name", alarmRecords.getDeviceName()); |
||||
} |
||||
// 报警时间
|
||||
if (alarmRecords.getCreateTime() != null) { |
||||
queryWrapper.apply("to_char(create_time, 'YYYY-MM-DD HH24') = {0}", |
||||
new SimpleDateFormat("yyyy-MM-dd HH").format(alarmRecords.getCreateTime())); |
||||
} |
||||
// 台账id
|
||||
if (!alarmRecords.getLedgerId().isEmpty()) { |
||||
queryWrapper.eq("ledger_id", alarmRecords.getLedgerId()); |
||||
} |
||||
// 仪表参数id
|
||||
if (!alarmRecords.getCpmId().isEmpty()) { |
||||
queryWrapper.eq("cpm_id", alarmRecords.getCpmId()); |
||||
} |
||||
// 仪表参数名称
|
||||
if (!alarmRecords.getCpmName().isEmpty()) { |
||||
queryWrapper.like("cpm_name", alarmRecords.getCpmName()); |
||||
} |
||||
// 报警内容
|
||||
if (!alarmRecords.getContent().isEmpty()) { |
||||
queryWrapper.like("content", alarmRecords.getContent()); |
||||
} |
||||
queryWrapper.orderByDesc("create_time"); |
||||
return alarmRecordsMapper.selectList(queryWrapper); |
||||
} |
||||
|
||||
@Override |
||||
public AlarmRecords selectAlarmRecordsById(String acdId) { |
||||
return alarmRecordsMapper.selectById(acdId); |
||||
} |
||||
|
||||
@Override |
||||
public int deleteAlarmRecordsByIds(String[] acdIds) { |
||||
if (acdIds != null && acdIds.length > 0) { |
||||
for (String acdId : acdIds) { |
||||
alarmRecordsMapper.deleteById(acdId); |
||||
} |
||||
return acdIds.length; |
||||
} |
||||
return 0; |
||||
} |
||||
} |
Loading…
Reference in new issue