diff --git a/mh-admin/src/main/java/com/mh/web/controller/operate/AlarmCodeController.java b/mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmCodeController.java similarity index 97% rename from mh-admin/src/main/java/com/mh/web/controller/operate/AlarmCodeController.java rename to mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmCodeController.java index 52d5983..e009cfb 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/operate/AlarmCodeController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmCodeController.java @@ -1,4 +1,4 @@ -package com.mh.web.controller.operate; +package com.mh.web.controller.alarm; import com.mh.common.annotation.Log; import com.mh.common.core.controller.BaseController; @@ -22,7 +22,7 @@ import java.util.List; * @date 2025-01-14 16:40:58 */ @RestController -@RequestMapping("/operate/ac") +@RequestMapping("/alarm/ac") public class AlarmCodeController extends BaseController { @Autowired diff --git a/mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmRecordsController.java b/mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmRecordsController.java new file mode 100644 index 0000000..e6d1141 --- /dev/null +++ b/mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmRecordsController.java @@ -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 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)); + } + +} diff --git a/mh-admin/src/main/java/com/mh/web/controller/operate/AlarmRulesController.java b/mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmRulesController.java similarity index 97% rename from mh-admin/src/main/java/com/mh/web/controller/operate/AlarmRulesController.java rename to mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmRulesController.java index bc114a1..8fbb08f 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/operate/AlarmRulesController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/alarm/AlarmRulesController.java @@ -1,4 +1,4 @@ -package com.mh.web.controller.operate; +package com.mh.web.controller.alarm; import com.mh.common.annotation.Log; import com.mh.common.core.controller.BaseController; @@ -22,7 +22,7 @@ import java.util.List; * @date 2025-01-14 17:32:55 */ @RestController -@RequestMapping("/operate/ar") +@RequestMapping("/alarm/ar") public class AlarmRulesController extends BaseController { @Autowired diff --git a/mh-admin/src/main/java/com/mh/web/controller/monitor/IndoorTempMonitorController.java b/mh-admin/src/main/java/com/mh/web/controller/monitor/IndoorTempMonitorController.java index 684cfd6..4183a78 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/monitor/IndoorTempMonitorController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/monitor/IndoorTempMonitorController.java @@ -1,6 +1,10 @@ package com.mh.web.controller.monitor; import com.mh.common.core.controller.BaseController; +import com.mh.common.core.domain.AjaxResult; +import com.mh.system.service.device.IIndoorTempMonitorService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -12,6 +16,22 @@ import org.springframework.web.bind.annotation.RestController; * @date 2025-02-18 15:43:47 */ @RestController -@RequestMapping("/device/indoorTemp") +@RequestMapping("/device") public class IndoorTempMonitorController extends BaseController { + + private final IIndoorTempMonitorService indoorTempMonitorService; + + @Autowired + public IndoorTempMonitorController(IIndoorTempMonitorService indoorTempMonitorService) { + this.indoorTempMonitorService = indoorTempMonitorService; + } + + /** + * 根据楼层查询每一个房间的温度 + */ + @GetMapping("/indoorTemp") + public AjaxResult getIndoorTempByFloor(String floorId) { + return AjaxResult.success(indoorTempMonitorService.getIndoorTempByFloor(floorId)); + } + } diff --git a/mh-admin/src/main/java/com/mh/web/controller/space/SpaceController.java b/mh-admin/src/main/java/com/mh/web/controller/space/SpaceController.java index f02b201..85d1b04 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/space/SpaceController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/space/SpaceController.java @@ -1,14 +1,9 @@ package com.mh.web.controller.space; -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.CpmSpaceRelation; -import com.mh.common.core.domain.entity.HouseInfo; -import com.mh.common.enums.BusinessType; import com.mh.system.service.space.IHouseInfoService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; /** @@ -34,10 +29,4 @@ public class SpaceController extends BaseController { return AjaxResult.success(houseInfoService.buildTree()); } - @Log(title = "采集参数和区域、楼栋、楼层、房间的关联表", businessType = BusinessType.INSERT) - @PostMapping("/relation") - public AjaxResult relation(@Validated @RequestBody CpmSpaceRelation cpmSpaceRelation) { - cpmSpaceRelation.setCreateBy(getUsername()); - return AjaxResult.success(); - } } diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/AlarmRecords.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/AlarmRecords.java index 7618aa8..38b7ea4 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/entity/AlarmRecords.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/AlarmRecords.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import org.apache.commons.lang3.builder.ToStringBuilder; import java.io.Serializable; +import java.util.Date; /** * @author LJF @@ -30,7 +31,7 @@ public class AlarmRecords implements Serializable { /** * 创建时间 */ - private String createTime; + private Date createTime; /** * 报警类型 @@ -83,11 +84,11 @@ public class AlarmRecords implements Serializable { this.content = content; } - public String getCreateTime() { + public Date getCreateTime() { return createTime; } - public void setCreateTime(String createTime) { + public void setCreateTime(Date createTime) { this.createTime = createTime; } diff --git a/mh-common/src/main/java/com/mh/common/utils/BigDecimalUtils.java b/mh-common/src/main/java/com/mh/common/utils/BigDecimalUtils.java new file mode 100644 index 0000000..b5eee7c --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/utils/BigDecimalUtils.java @@ -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> 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 predicate = OPERATORS.get(operator); + if (predicate == null) { + throw new IllegalArgumentException("不支持的运算符: " + operator); + } + return predicate.test(a, b); + } +} diff --git a/mh-common/src/main/java/com/mh/common/utils/DateUtils.java b/mh-common/src/main/java/com/mh/common/utils/DateUtils.java index 30803f4..3b8a9b8 100644 --- a/mh-common/src/main/java/com/mh/common/utils/DateUtils.java +++ b/mh-common/src/main/java/com/mh/common/utils/DateUtils.java @@ -37,6 +37,40 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; + /** + * 将 Date 类型的 curTime 转换为 LocalTime + * + * @param curTime 需要转换的 Date 对象 + * @return 转换后的 LocalTime 对象 + */ + public static LocalTime convertDateToLocalTime(Date curTime) { + // 将 Date 转换为 Instant + java.time.Instant instant = curTime.toInstant(); + + // 获取系统默认时区,或者指定其他时区,例如 ZoneId.of("UTC") + ZoneId zone = ZoneId.systemDefault(); + + // 将 Instant 转换为 LocalTime + return instant.atZone(zone).toLocalTime(); + } + + public static boolean isCurrentTimeInRange(Date startTimeStr, Date endTimeStr, Date curTime) { + LocalTime startTime = convertDateToLocalTime(startTimeStr); + LocalTime endTime = convertDateToLocalTime(endTimeStr); + LocalTime currentTime = convertDateToLocalTime(curTime); + + if (startTime.equals(endTime)) { + // 开始和结束时间相同,视为全天范围内 + return true; + } else if (endTime.isAfter(startTime)) { + // 时间段不跨天,判断当前时间是否在[startTime, endTime]区间内 + return !currentTime.isBefore(startTime) && !currentTime.isAfter(endTime); + } else { + // 时间段跨天,判断当前时间是否在[startTime, 23:59:59.999999999]或[00:00:00, endTime] + return !currentTime.isBefore(startTime) || !currentTime.isAfter(endTime); + } + } + /** * 获取当前Date型日期 * diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/CreateAlarmTask.java b/mh-quartz/src/main/java/com/mh/quartz/task/CreateAlarmTask.java new file mode 100644 index 0000000..8562443 --- /dev/null +++ b/mh-quartz/src/main/java/com/mh/quartz/task/CreateAlarmTask.java @@ -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 = 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); + } + } + } + +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java index 53f6723..7ec519f 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java @@ -5,6 +5,8 @@ import com.mh.common.core.domain.entity.CollectionParamsManage; import org.apache.ibatis.annotations.*; import java.util.List; +import java.util.Map; +import java.util.Objects; /** * @author LJF @@ -95,4 +97,21 @@ public interface CollectionParamsManageMapper extends BaseMapper selectByAreaId(@Param("areaId") String areaId); + @Select("select " + + " csr.house_id, " + + " hi.house_name, " + + " cpm.cur_value," + + " cpm.cur_time " + + "from " + + " cpm_space_relation csr " + + "join collection_params_manage cpm " + + "on " + + " csr.cpm_id = cpm.id " + + "join house_info hi " + + "on " + + " csr.house_id = hi.id " + + " and csr.floor_id = #{floorId} " + + " and cpm.param_type = #{paramType} ") + List> selectByParamType(@Param("floorId") String floorId, + @Param("paramType") String paramType); } diff --git a/mh-system/src/main/java/com/mh/system/mapper/operation/AlarmRecordsMapper.java b/mh-system/src/main/java/com/mh/system/mapper/operation/AlarmRecordsMapper.java new file mode 100644 index 0000000..a1212b5 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/operation/AlarmRecordsMapper.java @@ -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 { +} diff --git a/mh-system/src/main/java/com/mh/system/service/device/IIndoorTempMonitorService.java b/mh-system/src/main/java/com/mh/system/service/device/IIndoorTempMonitorService.java new file mode 100644 index 0000000..4aaa58e --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/device/IIndoorTempMonitorService.java @@ -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); + +} diff --git a/mh-system/src/main/java/com/mh/system/service/device/impl/IndoorTempMonitorServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/device/impl/IndoorTempMonitorServiceImpl.java new file mode 100644 index 0000000..bd45fe9 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/device/impl/IndoorTempMonitorServiceImpl.java @@ -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> collectionParamsManages = collectionParamsManageMapper.selectByParamType(floorId,"99"); + return null; + } +} diff --git a/mh-system/src/main/java/com/mh/system/service/operation/IAlarmCodeService.java b/mh-system/src/main/java/com/mh/system/service/operation/IAlarmCodeService.java index 4d785db..05d9d76 100644 --- a/mh-system/src/main/java/com/mh/system/service/operation/IAlarmCodeService.java +++ b/mh-system/src/main/java/com/mh/system/service/operation/IAlarmCodeService.java @@ -21,4 +21,6 @@ public interface IAlarmCodeService { int updateAlarmCode(AlarmCode alarmCode); int deleteAlarmCodeByIds(String[] acIds); + + AlarmCode selectAlarmCodeByAlarmType(String eventType); } diff --git a/mh-system/src/main/java/com/mh/system/service/operation/IAlarmRecordsService.java b/mh-system/src/main/java/com/mh/system/service/operation/IAlarmRecordsService.java new file mode 100644 index 0000000..5eb24b4 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/operation/IAlarmRecordsService.java @@ -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 selectAlarmRecordsList(AlarmRecords alarmRecords); + + AlarmRecords selectAlarmRecordsById(String acdId); + + int deleteAlarmRecordsByIds(String[] acdIds); +} diff --git a/mh-system/src/main/java/com/mh/system/service/operation/IAlarmRulesService.java b/mh-system/src/main/java/com/mh/system/service/operation/IAlarmRulesService.java index cb0e432..3a692ad 100644 --- a/mh-system/src/main/java/com/mh/system/service/operation/IAlarmRulesService.java +++ b/mh-system/src/main/java/com/mh/system/service/operation/IAlarmRulesService.java @@ -21,4 +21,6 @@ public interface IAlarmRulesService { int updateAlarmRules(AlarmRules alarmCode); int deleteAlarmRulesByIds(String[] acIds); + + List selectAlarmRulesListByStatus(int status); } diff --git a/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmCodeServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmCodeServiceImpl.java index 0412d08..ced2e77 100644 --- a/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmCodeServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmCodeServiceImpl.java @@ -83,4 +83,14 @@ public class AlarmCodeServiceImpl implements IAlarmCodeService { } return 0; } + + @Override + public AlarmCode selectAlarmCodeByAlarmType(String eventType) { + if (StringUtils.isEmpty(eventType)) { + return null; + } + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("event_type", eventType); + return alarmCodeMapper.selectOne(queryWrapper); + } } diff --git a/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmRecordsServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmRecordsServiceImpl.java new file mode 100644 index 0000000..a26a3dc --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmRecordsServiceImpl.java @@ -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 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 selectAlarmRecordsList(AlarmRecords alarmRecords) { + if (alarmRecords == null) { + return List.of(); + } + QueryWrapper 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; + } +} diff --git a/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmRulesServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmRulesServiceImpl.java index 60f2301..ef2ca5e 100644 --- a/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmRulesServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/operation/impl/AlarmRulesServiceImpl.java @@ -79,4 +79,12 @@ public class AlarmRulesServiceImpl implements IAlarmRulesService { } return 0; } + + @Override + public List selectAlarmRulesListByStatus(int status) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("status", status); + queryWrapper.orderByDesc("create_time"); + return alarmRulesMapper.selectList(queryWrapper); + } }