feat(ems): 新增设备隐患记录和安全环保制度文档模块前后端

- 添加设备隐患记录实体类、业务对象和视图对象
- 实现设备隐患记录的增删改查接口及业务逻辑
- 添加安全环保制度文档实体类、业务对象和视图对象
- 实现安全环保制度文档的增删改查接口及业务逻辑
- 配置MyBatis映射文件和Mapper接口- 添加定时任务用于生成模拟报警记录
- 实现Excel导出功能及相关数据转换逻辑
This commit is contained in:
2025-10-13 11:39:55 +08:00
parent 0a366b054c
commit a63387e069
22 changed files with 2312 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
package com.klp.ems.schedule;
import com.klp.common.core.domain.PageQuery;
import com.klp.common.core.page.TableDataInfo;
import com.klp.ems.domain.bo.EmsAlarmDeviceBo;
import com.klp.ems.domain.bo.EmsAlarmRecordBo;
import com.klp.ems.domain.vo.EmsAlarmDeviceVo;
import com.klp.ems.service.IEmsAlarmDeviceService;
import com.klp.ems.service.IEmsAlarmRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Random;
/**
* 每30分钟自动生成一条报警记录随机数据占位用
*/
@Component
public class EmsAlarmRecordScheduler {
private static final Logger log = LoggerFactory.getLogger(EmsAlarmRecordScheduler.class);
private static final String[] ALARM_TYPES = {"温度告警", "电压告警", "震动告警", "网络告警"};
private static final String[] ALARM_CONTENT_TEMPLATES = {
"检测到{type},数值异常",
"{type}触发,阈值超限",
"{type}持续波动,需要关注",
"{type}恢复后再次触发"
};
private final Random random = new Random();
private final IEmsAlarmRecordService alarmRecordService;
private final IEmsAlarmDeviceService alarmDeviceService;
public EmsAlarmRecordScheduler(IEmsAlarmRecordService alarmRecordService,
IEmsAlarmDeviceService alarmDeviceService) {
this.alarmRecordService = alarmRecordService;
this.alarmDeviceService = alarmDeviceService;
}
@Scheduled(cron = "0 0/30 * * * ?")
public void autoGenerateAlarmRecord() {
try {
Long deviceId = chooseRandomDeviceId();
String type = ALARM_TYPES[random.nextInt(ALARM_TYPES.length)];
int level = random.nextInt(3) + 1; // 1~3
String contentTpl = ALARM_CONTENT_TEMPLATES[random.nextInt(ALARM_CONTENT_TEMPLATES.length)];
String content = contentTpl.replace("{type}", type);
EmsAlarmRecordBo bo = new EmsAlarmRecordBo();
bo.setDeviceId(deviceId);
bo.setAlarmType(type);
bo.setAlarmLevel((long) level);
bo.setAlarmContent(content);
bo.setAlarmTime(new Date());
bo.setHandleStatus(0L); // 未处理
bo.setRemark("需解决");
Boolean ok = alarmRecordService.insertByBo(bo);
log.info("[AlarmScheduler] auto insert alarm record result={}, deviceId={}, type={}, level={}",
ok, deviceId, type, level);
} catch (Exception e) {
log.error("[AlarmScheduler] autoGenerateAlarmRecord error", e);
}
}
private Long chooseRandomDeviceId() {
try {
// 查询少量设备用于随机选取
EmsAlarmDeviceBo bo = new EmsAlarmDeviceBo();
TableDataInfo<EmsAlarmDeviceVo> page = alarmDeviceService.queryPageList(bo, new PageQuery());
List<EmsAlarmDeviceVo> list = page.getRows();
if (list != null && !list.isEmpty()) {
EmsAlarmDeviceVo any = list.get(random.nextInt(list.size()));
if (any != null && any.getDeviceId() != null) {
return any.getDeviceId();
}
}
} catch (Exception ignore) {
}
// 兜底
return 1L;
}
}