|
@@ -7,11 +7,14 @@ import com.gyee.wisdom.alarm.sharding.cache.WindturbineCache;
|
|
import com.gyee.wisdom.alarm.sharding.entity.*;
|
|
import com.gyee.wisdom.alarm.sharding.entity.*;
|
|
import com.gyee.wisdom.alarm.sharding.mapper.AlarmCountMapper;
|
|
import com.gyee.wisdom.alarm.sharding.mapper.AlarmCountMapper;
|
|
import com.gyee.wisdom.alarm.sharding.mapper.AlarmHisotryMapper;
|
|
import com.gyee.wisdom.alarm.sharding.mapper.AlarmHisotryMapper;
|
|
|
|
+import com.gyee.wisdom.alarm.sharding.model.AlarmCountStat;
|
|
import com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo;
|
|
import com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo;
|
|
import com.gyee.wisdom.alarm.sharding.model.CodeValue;
|
|
import com.gyee.wisdom.alarm.sharding.model.CodeValue;
|
|
|
|
+import com.gyee.wisdom.alarm.sharding.util.ResponseWrapper;
|
|
import com.gyee.wisdom.alarm.sharding.util.SnowflakeGenerator;
|
|
import com.gyee.wisdom.alarm.sharding.util.SnowflakeGenerator;
|
|
import com.gyee.wisdom.common.utils.DateUtil;
|
|
import com.gyee.wisdom.common.utils.DateUtil;
|
|
import com.gyee.wisdom.common.utils.StringUtil;
|
|
import com.gyee.wisdom.common.utils.StringUtil;
|
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -49,10 +52,125 @@ public class AlarmCountService extends ServiceImpl<AlarmCountMapper, AlarmCount>
|
|
@Autowired
|
|
@Autowired
|
|
private WindturbineService windturbineService;
|
|
private WindturbineService windturbineService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private Alertrule2Service alertrule2Service;
|
|
|
|
+
|
|
|
|
|
|
@Value("${count.custom}")
|
|
@Value("${count.custom}")
|
|
public boolean custom;
|
|
public boolean custom;
|
|
|
|
|
|
|
|
+ @Value("${homestat.alertIds}")
|
|
|
|
+ private String alertIds;
|
|
|
|
+
|
|
|
|
+ public List<AlarmSnap> getAllSnap(){
|
|
|
|
+ //分解规则id
|
|
|
|
+ String[] split = alertIds.split(",");
|
|
|
|
+ List<Alertrule2> alertrule2s = new ArrayList<>();
|
|
|
|
+ for (String id : split){
|
|
|
|
+ Alertrule2 alertrule2 = alertrule2Service.selectByAlertrule2Id(id);
|
|
|
|
+ if (alertrule2 != null){
|
|
|
|
+ alertrule2s.add(alertrule2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //根据alertrule2的alertvalue得到alarmsnap
|
|
|
|
+ List<AlarmSnap> alarmSnaps = new ArrayList<>();
|
|
|
|
+ for (Alertrule2 alertrule2 :alertrule2s){
|
|
|
|
+ alarmSnaps.addAll(alarmSnapService.selectByAlertValue(alertrule2.getEdnaValue()));
|
|
|
|
+ }
|
|
|
|
+ return alarmSnaps;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String,Double> hiddeDanger(){
|
|
|
|
+ try {
|
|
|
|
+ Map<String,Double> doubleMap =new HashMap<>();
|
|
|
|
+ List<AlarmSnap> alarmSnaps = getAllSnap();
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ String strDate = sdf.format(DateUtil.addDays(new Date(),-1));
|
|
|
|
+ Date dtStart = sdf.parse(strDate);
|
|
|
|
+ Date dtEnd = DateUtil.addDays(dtStart, 1);
|
|
|
|
+ Map<String,List<AlarmSnap>> map = alarmSnaps.stream().collect(Collectors.groupingBy(AlarmSnap::getCategory3));
|
|
|
|
+ for (Map.Entry<String,List<AlarmSnap>> stringListMap : map.entrySet()){
|
|
|
|
+ double time = 0;
|
|
|
|
+ for (AlarmSnap alarmSnap : stringListMap.getValue()){
|
|
|
|
+ AlarmCount alarmCount = alarmCountMapper.selectBySnapId(alarmSnap.getId(), dtStart, dtEnd);
|
|
|
|
+ if (alarmCount != null){
|
|
|
|
+ time = time + alarmCount.getTime();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ doubleMap.put(stringListMap.getKey(),time);
|
|
|
|
+ }
|
|
|
|
+ return doubleMap;
|
|
|
|
+ }catch (Exception ex) {
|
|
|
|
+ log.error(ex.getMessage());
|
|
|
|
+ log.error(ex.getStackTrace().toString());
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<AlarmCountStat> selectTotalDuration() {
|
|
|
|
+ try {
|
|
|
|
+ List<AlarmSnap> alarmSnaps = getAllSnap();
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ String strDate = sdf.format(DateUtil.addDays(new Date(),-1));
|
|
|
|
+ Date dtStart = sdf.parse(strDate);
|
|
|
|
+ Date dtEnd = DateUtil.addDays(dtStart, 1);
|
|
|
|
+ List<AlarmCountStat> oldList = new ArrayList<>();
|
|
|
|
+ for (AlarmSnap alarmSnap : alarmSnaps){
|
|
|
|
+ AlarmCount alarmCount = selectBySnapId(alarmSnap.getId(), dtStart, dtEnd);
|
|
|
|
+ if (alarmCount != null){
|
|
|
|
+ AlarmCountStat alarmCountStat = new AlarmCountStat();
|
|
|
|
+ alarmCountStat.setWindturbineId(alarmSnap.getWindturbineId());
|
|
|
|
+ alarmCountStat.setWindturbineName(alarmSnap.getWindturbineName());
|
|
|
|
+ alarmCountStat.setCount(alarmCount.getCount());
|
|
|
|
+ alarmCountStat.setTime(alarmCount.getTime());
|
|
|
|
+ oldList.add(alarmCountStat);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ //对重复的风机号进行合并
|
|
|
|
+ List<AlarmCountStat> newList = new ArrayList<>();
|
|
|
|
+ for (AlarmCountStat oldAlarmCountStat : oldList) {
|
|
|
|
+ // 遍历新的List,看是否存在,存在则相加,不存在则放入新的List
|
|
|
|
+ boolean flag = false;
|
|
|
|
+ if (newList.size() > 0){
|
|
|
|
+ for (AlarmCountStat newAlarmCountStat : newList) {
|
|
|
|
+ if (newAlarmCountStat.getWindturbineId().equals(oldAlarmCountStat.getWindturbineId())) {
|
|
|
|
+ newAlarmCountStat.setCount(newAlarmCountStat.getCount()+oldAlarmCountStat.getCount());
|
|
|
|
+ newAlarmCountStat.setTime(newAlarmCountStat.getTime()+oldAlarmCountStat.getTime());
|
|
|
|
+ flag = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!flag){
|
|
|
|
+ AlarmCountStat alarmCountStat = new AlarmCountStat();
|
|
|
|
+ alarmCountStat.setWindturbineId(oldAlarmCountStat.getWindturbineId());
|
|
|
|
+ alarmCountStat.setWindturbineName(oldAlarmCountStat.getWindturbineName());
|
|
|
|
+ alarmCountStat.setCount(oldAlarmCountStat.getCount());
|
|
|
|
+ alarmCountStat.setTime(oldAlarmCountStat.getTime());
|
|
|
|
+ newList.add(alarmCountStat);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //对集合进行降序排序,取前十个
|
|
|
|
+ Collections.sort(newList,new Comparator<AlarmCountStat>(){
|
|
|
|
+ @Override
|
|
|
|
+ public int compare(AlarmCountStat o1, AlarmCountStat o2) {
|
|
|
|
+ //会把集合里面的对象两两传进方法里面比较,这里比较age,降序就O2-O1,升序就O1-O2
|
|
|
|
+ return (int) (o2.getTime()-o1.getTime());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ List<AlarmCountStat> limitlist = newList.stream().limit(10).collect(Collectors.toList());
|
|
|
|
+ return limitlist;
|
|
|
|
+ }catch (Exception ex) {
|
|
|
|
+ log.error(ex.getMessage());
|
|
|
|
+ log.error(ex.getStackTrace().toString());
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public AlarmCount selectBySnapId(long id,Date dtStart,Date dtEnd){
|
|
|
|
+ return alarmCountMapper.selectBySnapId(id,dtStart,dtEnd);
|
|
|
|
+ }
|
|
|
|
+
|
|
public boolean startCount(String strDate) {
|
|
public boolean startCount(String strDate) {
|
|
try {
|
|
try {
|
|
List<AlarmSnap> snapList = alarmSnapService.queryAll(null, null, "custom", null, null, null, null, null, null, null);
|
|
List<AlarmSnap> snapList = alarmSnapService.queryAll(null, null, "custom", null, null, null, null, null, null, null);
|