|
@@ -1,8 +1,9 @@
|
|
|
package com.gyee.wisdom.alarm.sharding.schedule;
|
|
|
|
|
|
+import com.gyee.wisdom.alarm.sharding.cache.DataDictionaryCache;
|
|
|
import com.gyee.wisdom.alarm.sharding.entity.*;
|
|
|
-import com.gyee.wisdom.alarm.sharding.mapper.AlarmPartsCountMapper;
|
|
|
-import com.gyee.wisdom.alarm.sharding.mapper.AlarmRuleCountMapper;
|
|
|
+import com.gyee.wisdom.alarm.sharding.mapper.WindturbineAlarmIdCountMapper;
|
|
|
+import com.gyee.wisdom.alarm.sharding.mapper.WindturbineAlarmPartsCountMapper;
|
|
|
import com.gyee.wisdom.alarm.sharding.service.*;
|
|
|
import com.gyee.wisdom.alarm.sharding.util.SnowflakeGenerator;
|
|
|
import com.gyee.wisdom.common.utils.DateUtil;
|
|
@@ -19,7 +20,7 @@ import java.util.stream.Collectors;
|
|
|
/**
|
|
|
* @author :xugp
|
|
|
* @date :Created in 2022/9/8 10:15
|
|
|
- * @description:风机报警统计根据部件、规则发生报警次数
|
|
|
+ * @description:风机报警 统计根据部件、规则发生报警次数
|
|
|
* @modified By:
|
|
|
* @version: $
|
|
|
*/
|
|
@@ -35,10 +36,10 @@ public class AlarmCountPartsScheduled {
|
|
|
private TableNameService tableNameService;
|
|
|
|
|
|
@Autowired
|
|
|
- private AlarmPartsCountMapper alarmPartsCountMapper;
|
|
|
+ private WindturbineAlarmIdCountMapper windturbineAlarmIdCountMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private AlarmRuleCountMapper alarmRuleCountMapper;
|
|
|
+ private WindturbineAlarmPartsCountMapper windturbineAlarmPartsCountMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private Warning2Service warning2Service;
|
|
@@ -49,7 +50,7 @@ public class AlarmCountPartsScheduled {
|
|
|
|
|
|
@Autowired
|
|
|
private AlarmHistoryService alarmHistoryService;
|
|
|
- /*@Scheduled(cron = "* 41 10 ? * 3")*/
|
|
|
+ /*@Scheduled(cron = "* 10 11 ? * 3")*/
|
|
|
public boolean doTask() {
|
|
|
|
|
|
try {
|
|
@@ -60,8 +61,8 @@ public class AlarmCountPartsScheduled {
|
|
|
Date dtEnd = DateUtil.addDays(dtStart, 1);
|
|
|
Date dtNow = new Date();
|
|
|
while (dtEnd.getTime() < dtNow.getTime()) {
|
|
|
- List<AlarmPartsCount> acList = new ArrayList<>();
|
|
|
- List<AlarmRuleCount> alarmRuleCounts = new ArrayList<>();
|
|
|
+ List<WindturbineAlarmPartsCount> acList = new ArrayList<>();
|
|
|
+ List<WindturbineAlarmIdCount> alarmRuleCounts = new ArrayList<>();
|
|
|
Map<String,List<AlarmHistory>> map = new HashMap<>();
|
|
|
//根据windturbineid分组
|
|
|
Map<String,List<AlarmSnap>> maps = snapList.stream().collect(Collectors.groupingBy(AlarmSnap::getWindturbineId));
|
|
@@ -79,58 +80,64 @@ public class AlarmCountPartsScheduled {
|
|
|
for (Map.Entry<String,List<AlarmHistory>> entry : map.entrySet()){
|
|
|
Map<String,String> map1 = new HashMap<>();
|
|
|
List<AlarmHistory> value = entry.getValue();
|
|
|
- for (AlarmHistory alarmHistory : value){
|
|
|
- AlarmSnap alarmSnap = alarmSnapService.queryById(alarmHistory.getSnapId());
|
|
|
- Warning2 warning2 = warning2Service.selectByModelidAndEdnvalue(alarmSnap.getModelId(),alarmSnap.getAlertValue());
|
|
|
- String id = alarmHistory.getId() + "_" + alarmHistory.getSnapId();
|
|
|
- map1.put(id, warning2.getRelatedParts());
|
|
|
- }
|
|
|
- //分组转化为key:parts,value:snapId
|
|
|
- Map<String, List<Map.Entry<String,String>>> result = map1.entrySet().stream().collect(Collectors.groupingBy(c -> c.getValue()));
|
|
|
- for (Map.Entry<String, List<Map.Entry<String,String>>> entry1 : result.entrySet()) {
|
|
|
- List<Map.Entry<String, String>> listValue = entry1.getValue();
|
|
|
- int count = 0;
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- for (Map.Entry<String, String> map2 : listValue) {
|
|
|
- String[] split = map2.getKey().split("_");
|
|
|
- long l = Long.parseLong(split[1]);
|
|
|
- AlarmSnap alarmSnap = alarmSnapService.queryById(l);
|
|
|
- Warning2 warning2 = warning2Service.selectByModelidAndEdnvalue(alarmSnap.getModelId(), alarmSnap.getAlertValue());
|
|
|
- String tbName = tableNameService.getAlarmHistoryTableName(alarmSnap.getStationId(), dtStart);
|
|
|
- count = count + alarmHistoryService.selectAlarmSnapCount(tbName,Long.parseLong(split[0]));
|
|
|
- list.add(warning2.getId());
|
|
|
- }
|
|
|
- Map<String, Integer> mapCount = list.stream().collect(Collectors.toMap(key -> key, values -> 1, (value1,value2) ->value1 + value2));
|
|
|
- for(Map.Entry<String,Integer> entryString : mapCount.entrySet()){
|
|
|
- //统计某一种规则的报警次数
|
|
|
- AlarmRuleCount alarmRuleCount = new AlarmRuleCount();
|
|
|
- alarmRuleCount.setId(SnowflakeGenerator.generateId());
|
|
|
- alarmRuleCount.setAlarmDate(dtStart);
|
|
|
- alarmRuleCount.setParts(entry1.getKey());
|
|
|
- alarmRuleCount.setRulesId(entryString.getKey());
|
|
|
- alarmRuleCount.setCount(entryString.getValue());
|
|
|
- alarmRuleCount.setWindturbineId(entry.getKey());
|
|
|
- alarmRuleCount.setWindpowerstationId(windturbineService.selectWindturbineByWindturbineid(entry.getKey()).getWindpowerstationid());
|
|
|
- alarmRuleCounts.add(alarmRuleCount);
|
|
|
+ if (value.size()>0) {
|
|
|
+ for (AlarmHistory alarmHistory : value) {
|
|
|
+ AlarmSnap alarmSnap = alarmSnapService.queryById(alarmHistory.getSnapId());
|
|
|
+ Warning2 warning2 = warning2Service.selectByEdnvalue(alarmSnap.getAlertValue());
|
|
|
+ if (warning2 != null){
|
|
|
+ String id = alarmHistory.getId() + "_" + alarmHistory.getSnapId();
|
|
|
+ map1.put(id, warning2.getRelatedParts());
|
|
|
+ }
|
|
|
}
|
|
|
- if (count > 0) {
|
|
|
- //统计部件分类的部件次数
|
|
|
- AlarmPartsCount alarmPartsCount = new AlarmPartsCount();
|
|
|
- alarmPartsCount.setId(SnowflakeGenerator.generateId());
|
|
|
- alarmPartsCount.setAlarmDate(dtStart);
|
|
|
- alarmPartsCount.setParts(entry1.getKey());
|
|
|
- alarmPartsCount.setCount(count);
|
|
|
- alarmPartsCount.setWindturbineId(entry.getKey());
|
|
|
- alarmPartsCount.setWindpowerstationId(windturbineService.selectWindturbineByWindturbineid(entry.getKey()).getWindpowerstationid());
|
|
|
- acList.add(alarmPartsCount);
|
|
|
+ //分组转化为key:parts,value:snapId
|
|
|
+ Map<String, List<Map.Entry<String,String>>> result = map1.entrySet().stream().collect(Collectors.groupingBy(c -> c.getValue()));
|
|
|
+ for (Map.Entry<String, List<Map.Entry<String,String>>> entry1 : result.entrySet()) {
|
|
|
+ List<Map.Entry<String, String>> listValue = entry1.getValue();
|
|
|
+ int count = 0;
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, String> map2 : listValue) {
|
|
|
+ String[] split = map2.getKey().split("_");
|
|
|
+ long l = Long.parseLong(split[1]);
|
|
|
+ AlarmSnap alarmSnap = alarmSnapService.queryById(l);
|
|
|
+ Warning2 warning2 = warning2Service.selectByEdnvalue(alarmSnap.getAlertValue());
|
|
|
+ String tbName = tableNameService.getAlarmHistoryTableName(alarmSnap.getStationId(), dtStart);
|
|
|
+ count = count + alarmHistoryService.selectAlarmSnapCount(tbName,Long.parseLong(split[0]));
|
|
|
+ list.add(warning2.getId());
|
|
|
+ }
|
|
|
+ Map<String, Integer> mapCount = list.stream().collect(Collectors.toMap(key -> key, values -> 1, (value1, value2) -> value1 + value2));
|
|
|
+ for (Map.Entry<String, Integer> entryString : mapCount.entrySet()) {
|
|
|
+ //统计某一种规则的报警次数
|
|
|
+ WindturbineAlarmIdCount windturbineAlarmIdCount = new WindturbineAlarmIdCount();
|
|
|
+ windturbineAlarmIdCount.setId(SnowflakeGenerator.generateId());
|
|
|
+ windturbineAlarmIdCount.setAlarmDate(dtStart);
|
|
|
+ windturbineAlarmIdCount.setParts(entry1.getKey());
|
|
|
+ windturbineAlarmIdCount.setRulesId(entryString.getKey());
|
|
|
+ windturbineAlarmIdCount.setCount(entryString.getValue());
|
|
|
+ windturbineAlarmIdCount.setWindturbineId(entry.getKey());
|
|
|
+ windturbineAlarmIdCount.setPartsName(DataDictionaryCache.getPartName(entry1.getKey()));
|
|
|
+ windturbineAlarmIdCount.setWindpowerstationId(windturbineService.selectWindturbineByWindturbineid(entry.getKey()).getWindpowerstationid());
|
|
|
+ alarmRuleCounts.add(windturbineAlarmIdCount);
|
|
|
+ }
|
|
|
+ if (count > 0) {
|
|
|
+ //统计部件分类的部件次数
|
|
|
+ WindturbineAlarmPartsCount windturbineAlarmPartsCount = new WindturbineAlarmPartsCount();
|
|
|
+ windturbineAlarmPartsCount.setId(SnowflakeGenerator.generateId());
|
|
|
+ windturbineAlarmPartsCount.setAlarmDate(dtStart);
|
|
|
+ windturbineAlarmPartsCount.setParts(entry1.getKey());
|
|
|
+ windturbineAlarmPartsCount.setCount(count);
|
|
|
+ windturbineAlarmPartsCount.setPartsName(DataDictionaryCache.getPartName(entry1.getKey()));
|
|
|
+ windturbineAlarmPartsCount.setWindturbineId(entry.getKey());
|
|
|
+ windturbineAlarmPartsCount.setWindpowerstationId(windturbineService.selectWindturbineByWindturbineid(entry.getKey()).getWindpowerstationid());
|
|
|
+ acList.add(windturbineAlarmPartsCount);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (alarmRuleCounts.size() > 0) {
|
|
|
- alarmRuleCountMapper.batchInsert(alarmRuleCounts);
|
|
|
+ windturbineAlarmIdCountMapper.batchInsert(alarmRuleCounts);
|
|
|
}
|
|
|
if (acList.size() > 0) {
|
|
|
- alarmPartsCountMapper.batchInsert(acList);
|
|
|
+ windturbineAlarmPartsCountMapper.batchInsert(acList);
|
|
|
}
|
|
|
dtStart = dtEnd;
|
|
|
dtEnd = DateUtil.addDays(dtStart, 1);
|