123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package org.jeecg.modules.fpgJob;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import lombok.extern.slf4j.Slf4j;
- import org.jeecg.common.util.oConvertUtils;
- import org.jeecg.modules.common.enums.EDeviceInformationType;
- import org.jeecg.modules.device.service.IDeviceInformationService;
- import org.jeecg.modules.devicePoint.service.IDevicePointService;
- import org.jeecg.modules.events.entity.LeanEventsHost;
- import org.jeecg.modules.events.service.ILeanEventsHostService;
- import org.jeecg.modules.gatherData.entity.FpgGatherData;
- import org.jeecg.modules.gatherData.service.IFpgGatherDataService;
- import org.jeecg.modules.leanEventWarn.service.ILeanEventWarnInfoService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.mongodb.core.MongoTemplate;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.scheduling.annotation.EnableAsync;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- @Slf4j
- @EnableAsync
- @Component
- @EnableScheduling
- public class LeanEventTriggerWarnTask {
- @Autowired
- IDeviceInformationService deviceInformationService;
- @Autowired
- IDevicePointService devicePointService;
- @Autowired
- IFpgGatherDataService fpgGatherDataService;
- @Autowired
- MongoTemplate mongoTemplate;
- @Autowired
- RedisTemplate redisTemplate;
- @Autowired
- ILeanEventsHostService leanEventsHostService;
- @Autowired
- ILeanEventWarnInfoService leanEventWarnInfoService;
- @Scheduled(cron = "0 */1 * * * *")
- public void leanEventTriggerWarnHandle(){
- LambdaQueryWrapper<FpgGatherData> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(FpgGatherData::getEventWarnState, "0").isNotNull(FpgGatherData::getDeviceInformationId).orderByDesc(FpgGatherData::getCreateTime);
- List<FpgGatherData> fpgGatherDataList = fpgGatherDataService.list(queryWrapper);
- if (oConvertUtils.listIsNotEmpty(fpgGatherDataList)){
- fpgGatherDataList.forEach(x ->{
- // 触发告警信息逻辑处理
- leanEventsHostTriggerWarnHandle(x);
- });
- }
- // 逻辑删除已校验完精益事件告警的采集数据,事件告警使用状态0:使用中1:使用结束
- List<FpgGatherData> updateFpgGatherDataList = fpgGatherDataList.stream().map(s -> s.setEventWarnState("1")).collect(Collectors.toList());
- if (oConvertUtils.listIsNotEmpty(updateFpgGatherDataList)){
- fpgGatherDataService.updateBatchById(updateFpgGatherDataList);
- }
- }
- /**
- * 根据采集过来的数据、运行电流、精益事件配置(设备开启、设备关闭、FPG开启、FPG关闭《峰平谷的时间区间配置》),来触发告警信息,并保存
- * @param fpgGatherData
- */
- public void leanEventsHostTriggerWarnHandle(FpgGatherData fpgGatherData){
- String keyMainString = String.format("sys:opcSynData::%s","deviceInformationMainIds");
- String keySubString = String.format("sys:opcSynData::%s","deviceInformationSubIds");
- // 1、根据采集过来的数据,根据主设备ID,处理精益事件配置信息(host_open;host_stop)
- if (redisTemplate.hasKey(keyMainString)){
- List<String> deviceInformationIdIds = (List<String>) redisTemplate.opsForValue().get(keyMainString);
- boolean exists = deviceInformationIdIds.stream().anyMatch(x -> x.contains(fpgGatherData.getDeviceInformationId()));
- if (exists){
- // 根据主设备ID查询多条精益事件设备启停信息 处理事件类型为host_open、host_stop
- LambdaQueryWrapper<LeanEventsHost> queryLeanEventsHost = new LambdaQueryWrapper<LeanEventsHost>().eq(LeanEventsHost::getDeviceInformationId, fpgGatherData.getDeviceInformationId()).isNotNull(LeanEventsHost::getDeviceInformationType);
- List<LeanEventsHost> leanEventsHostList = leanEventsHostService.list(queryLeanEventsHost);
- leanEventsHostList.forEach(y ->{
- // 事件类型为host_stop、host_open
- if (EDeviceInformationType.HOST_OPEN.getCode().equals(y.getDeviceInformationType())){
- leanEventWarnInfoService.openDeviceTriggerWarnInfo(fpgGatherData);
- }
- if (EDeviceInformationType.HOST_STOP.getCode().equals(y.getDeviceInformationType())){
- leanEventWarnInfoService.stopDeviceTriggerWarnInfo(fpgGatherData);
- }
- });
- }
- }
- // 2、根据采集过来的数据,根据辅设备ID,处理精益事件配置信息3:FPG开,4:FPG关
- if (redisTemplate.hasKey(keySubString)){
- List<String> deviceInformationIdList = (List<String>) redisTemplate.opsForValue().get(keySubString);
- boolean exists = deviceInformationIdList.stream().anyMatch(x -> x.contains(fpgGatherData.getDeviceInformationId()));
- if (exists){
- // 根据辅设备ID模糊查询多条关于FPG精益事件设备启停信息 处理事件类型为fpg_open、fpg_close、fpg_ing_time、fpg_power_limit
- List<LeanEventsHost> leanEventsHostList = leanEventsHostService.getFpgLeanEventsHostList(fpgGatherData.getDeviceInformationId());
- leanEventsHostList.forEach(s ->{
- // 事件类型为 fpg_open
- if (EDeviceInformationType.FPG_OPEN.getCode().equals(s.getDeviceInformationType())){
- leanEventWarnInfoService.openFpgTriggerWarnInfo(fpgGatherData);
- }
- // 事件类型为 fpg_close
- if (EDeviceInformationType.FPG_CLOSE.getCode().equals(s.getDeviceInformationType())){
- leanEventWarnInfoService.closeFpgTriggerWarnInfo(fpgGatherData);
- }
- // 事件类型为 fpg_ing_time
- if (EDeviceInformationType.FPG_ING_TIME.getCode().equals(s.getDeviceInformationType())){
- leanEventWarnInfoService.runTimeTriggerWarnInfo(fpgGatherData, s);
- }
- // 事件类型为 fpg_power_limit
- if (EDeviceInformationType.FPG_POWER_LIMIT.getCode().equals(s.getDeviceInformationType())){
- leanEventWarnInfoService.powerLimitTriggerWarnInfo(fpgGatherData, s);
- }
- });
- }
- }
- }
- /**
- * 峰平谷采集数据 过期数据定时删除
- */
- // @Scheduled(cron = "0 */10 * * * *")
- public void removeFpgGatherDataHandle(){
- }
- }
|