LeanEventTriggerWarnTask.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package org.jeecg.modules.fpgJob;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.jeecg.common.util.oConvertUtils;
  5. import org.jeecg.modules.common.enums.EDeviceInformationType;
  6. import org.jeecg.modules.device.service.IDeviceInformationService;
  7. import org.jeecg.modules.devicePoint.service.IDevicePointService;
  8. import org.jeecg.modules.events.entity.LeanEventsHost;
  9. import org.jeecg.modules.events.service.ILeanEventsHostService;
  10. import org.jeecg.modules.gatherData.entity.FpgGatherData;
  11. import org.jeecg.modules.gatherData.service.IFpgGatherDataService;
  12. import org.jeecg.modules.leanEventWarn.service.ILeanEventWarnInfoService;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.data.mongodb.core.MongoTemplate;
  15. import org.springframework.data.redis.core.RedisTemplate;
  16. import org.springframework.scheduling.annotation.EnableAsync;
  17. import org.springframework.scheduling.annotation.EnableScheduling;
  18. import org.springframework.scheduling.annotation.Scheduled;
  19. import org.springframework.stereotype.Component;
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22. import java.util.List;
  23. import java.util.stream.Collectors;
  24. @Slf4j
  25. @EnableAsync
  26. @Component
  27. @EnableScheduling
  28. public class LeanEventTriggerWarnTask {
  29. @Autowired
  30. IDeviceInformationService deviceInformationService;
  31. @Autowired
  32. IDevicePointService devicePointService;
  33. @Autowired
  34. IFpgGatherDataService fpgGatherDataService;
  35. @Autowired
  36. MongoTemplate mongoTemplate;
  37. @Autowired
  38. RedisTemplate redisTemplate;
  39. @Autowired
  40. ILeanEventsHostService leanEventsHostService;
  41. @Autowired
  42. ILeanEventWarnInfoService leanEventWarnInfoService;
  43. @Scheduled(cron = "0 */1 * * * *")
  44. public void leanEventTriggerWarnHandle(){
  45. LambdaQueryWrapper<FpgGatherData> queryWrapper = new LambdaQueryWrapper<>();
  46. queryWrapper.eq(FpgGatherData::getEventWarnState, "0").isNotNull(FpgGatherData::getDeviceInformationId).orderByDesc(FpgGatherData::getCreateTime);
  47. List<FpgGatherData> fpgGatherDataList = fpgGatherDataService.list(queryWrapper);
  48. if (oConvertUtils.listIsNotEmpty(fpgGatherDataList)){
  49. fpgGatherDataList.forEach(x ->{
  50. // 触发告警信息逻辑处理
  51. leanEventsHostTriggerWarnHandle(x);
  52. });
  53. }
  54. // 逻辑删除已校验完精益事件告警的采集数据,事件告警使用状态0:使用中1:使用结束
  55. List<FpgGatherData> updateFpgGatherDataList = fpgGatherDataList.stream().map(s -> s.setEventWarnState("1")).collect(Collectors.toList());
  56. if (oConvertUtils.listIsNotEmpty(updateFpgGatherDataList)){
  57. fpgGatherDataService.updateBatchById(updateFpgGatherDataList);
  58. }
  59. }
  60. /**
  61. * 根据采集过来的数据、运行电流、精益事件配置(设备开启、设备关闭、FPG开启、FPG关闭《峰平谷的时间区间配置》),来触发告警信息,并保存
  62. * @param fpgGatherData
  63. */
  64. public void leanEventsHostTriggerWarnHandle(FpgGatherData fpgGatherData){
  65. String keyMainString = String.format("sys:opcSynData::%s","deviceInformationMainIds");
  66. String keySubString = String.format("sys:opcSynData::%s","deviceInformationSubIds");
  67. // 1、根据采集过来的数据,根据主设备ID,处理精益事件配置信息(host_open;host_stop)
  68. if (redisTemplate.hasKey(keyMainString)){
  69. List<String> deviceInformationIdIds = (List<String>) redisTemplate.opsForValue().get(keyMainString);
  70. boolean exists = deviceInformationIdIds.stream().anyMatch(x -> x.contains(fpgGatherData.getDeviceInformationId()));
  71. if (exists){
  72. // 根据主设备ID查询多条精益事件设备启停信息 处理事件类型为host_open、host_stop
  73. LambdaQueryWrapper<LeanEventsHost> queryLeanEventsHost = new LambdaQueryWrapper<LeanEventsHost>().eq(LeanEventsHost::getDeviceInformationId, fpgGatherData.getDeviceInformationId()).isNotNull(LeanEventsHost::getDeviceInformationType);
  74. List<LeanEventsHost> leanEventsHostList = leanEventsHostService.list(queryLeanEventsHost);
  75. leanEventsHostList.forEach(y ->{
  76. // 事件类型为host_stop、host_open
  77. if (EDeviceInformationType.HOST_OPEN.getCode().equals(y.getDeviceInformationType())){
  78. leanEventWarnInfoService.openDeviceTriggerWarnInfo(fpgGatherData);
  79. }
  80. if (EDeviceInformationType.HOST_STOP.getCode().equals(y.getDeviceInformationType())){
  81. leanEventWarnInfoService.stopDeviceTriggerWarnInfo(fpgGatherData);
  82. }
  83. });
  84. }
  85. }
  86. // 2、根据采集过来的数据,根据辅设备ID,处理精益事件配置信息3:FPG开,4:FPG关
  87. if (redisTemplate.hasKey(keySubString)){
  88. List<String> deviceInformationIdList = (List<String>) redisTemplate.opsForValue().get(keySubString);
  89. boolean exists = deviceInformationIdList.stream().anyMatch(x -> x.contains(fpgGatherData.getDeviceInformationId()));
  90. if (exists){
  91. // 根据辅设备ID模糊查询多条关于FPG精益事件设备启停信息 处理事件类型为fpg_open、fpg_close、fpg_ing_time、fpg_power_limit
  92. List<LeanEventsHost> leanEventsHostList = leanEventsHostService.getFpgLeanEventsHostList(fpgGatherData.getDeviceInformationId());
  93. leanEventsHostList.forEach(s ->{
  94. // 事件类型为 fpg_open
  95. if (EDeviceInformationType.FPG_OPEN.getCode().equals(s.getDeviceInformationType())){
  96. leanEventWarnInfoService.openFpgTriggerWarnInfo(fpgGatherData);
  97. }
  98. // 事件类型为 fpg_close
  99. if (EDeviceInformationType.FPG_CLOSE.getCode().equals(s.getDeviceInformationType())){
  100. leanEventWarnInfoService.closeFpgTriggerWarnInfo(fpgGatherData);
  101. }
  102. // 事件类型为 fpg_ing_time
  103. if (EDeviceInformationType.FPG_ING_TIME.getCode().equals(s.getDeviceInformationType())){
  104. leanEventWarnInfoService.runTimeTriggerWarnInfo(fpgGatherData, s);
  105. }
  106. // 事件类型为 fpg_power_limit
  107. if (EDeviceInformationType.FPG_POWER_LIMIT.getCode().equals(s.getDeviceInformationType())){
  108. leanEventWarnInfoService.powerLimitTriggerWarnInfo(fpgGatherData, s);
  109. }
  110. });
  111. }
  112. }
  113. }
  114. /**
  115. * 峰平谷采集数据 过期数据定时删除
  116. */
  117. // @Scheduled(cron = "0 */10 * * * *")
  118. public void removeFpgGatherDataHandle(){
  119. }
  120. }