|
@@ -0,0 +1,304 @@
|
|
|
+package com.gyee.health.service.health;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.gyee.health.init.CacheContext;
|
|
|
+import com.gyee.health.mapper.auto.AlarmTsMapper;
|
|
|
+import com.gyee.health.model.auto.*;
|
|
|
+import com.gyee.health.model.vo.AlarmStatVo;
|
|
|
+import com.gyee.health.model.vo.AlarmSuperTalbeType;
|
|
|
+import com.gyee.health.model.vo.AlarmTime;
|
|
|
+import com.gyee.health.model.vo.AlarmTypeValue;
|
|
|
+import com.gyee.health.util.DateUtils;
|
|
|
+import com.gyee.health.util.SnowflakeGenerator;
|
|
|
+import com.gyee.health.util.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+
|
|
|
+public class AlarmHistoryService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AlarmTsMapper alarmTsMapper;
|
|
|
+
|
|
|
+ @Value("${home_pagep_size}")
|
|
|
+ private int home_pagep_size;
|
|
|
+
|
|
|
+
|
|
|
+ public List<ProBasicFeatureStat> findWtFeatureStat(Date startTime, Date endTime, String deviceid, String alarmType, String timeType) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<ProBasicFeatureStat> fsls = new ArrayList<>();
|
|
|
+ if(alarmType.equals(AlarmTypeValue.BT.getCode()))
|
|
|
+ {
|
|
|
+ fsls = alarmTsMapper.findWtFeatureStatWt(AlarmSuperTalbeType.BT.getCode(), startTime.getTime(), endTime.getTime(),deviceid);
|
|
|
+
|
|
|
+ }else if(alarmType.equals(AlarmTypeValue.WT.getCode()))
|
|
|
+ {
|
|
|
+ fsls = alarmTsMapper.findWtFeatureStatWt(AlarmSuperTalbeType.WT.getCode(),startTime.getTime(), endTime.getTime(),deviceid);
|
|
|
+ }else if(alarmType.equals(AlarmTypeValue.IN.getCode()))
|
|
|
+ {
|
|
|
+ fsls = alarmTsMapper.findWtFeatureStatWt(AlarmSuperTalbeType.WT.getCode(),startTime.getTime(), endTime.getTime(),deviceid);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!fsls.isEmpty()) {
|
|
|
+ for (ProBasicFeatureStat fs : fsls) {
|
|
|
+ if (StringUtils.notEmp(fs.getTypeCode()) && CacheContext.alarmTypeMap.containsKey(fs.getTypeCode())) {
|
|
|
+ ProEconAlarmType at = CacheContext.alarmTypeMap.get(fs.getTypeCode());
|
|
|
+ fs.setTypeName(at.getName());
|
|
|
+ }
|
|
|
+ double times= new BigDecimal(fs.getTotalSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
|
|
|
+ fs.setTotalSeconds(times);
|
|
|
+ times= new BigDecimal(fs.getMaxSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
|
|
|
+ fs.setMaxSeconds(times);
|
|
|
+ times= new BigDecimal(fs.getMinSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
|
|
|
+ fs.setMinSeconds(times);
|
|
|
+ times= new BigDecimal(fs.getAvgSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
|
|
|
+ fs.setAvgSeconds(times);
|
|
|
+ if(CacheContext.wtmap.containsKey(fs.getWtId()))
|
|
|
+ {
|
|
|
+ fs.setCode(CacheContext.wtmap.get(fs.getWtId()).getNemCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return fsls;
|
|
|
+ }
|
|
|
+ private static void setWtValues(Date statDate,Map<String, ProBasicFeatureStat> map, List<ProBasicFeatureStat> vos, ProBasicEquipment wt, ProEconAlarmConfiguration at) {
|
|
|
+
|
|
|
+ ProBasicFeatureStat fs = new ProBasicFeatureStat();
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append(wt.getId()).append("_").append(at.getId());
|
|
|
+ if (map.containsKey(String.valueOf(sb))) {
|
|
|
+ ProBasicFeatureStat old = map.get(String.valueOf(sb));
|
|
|
+ BeanUtil.copyProperties(old, fs);
|
|
|
+ } else {
|
|
|
+ fs.setStatDate(new Timestamp(statDate.getTime()));
|
|
|
+ fs.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ fs.setWtId(wt.getId());
|
|
|
+ fs.setStationId(wt.getWindpowerstationId());
|
|
|
+ fs.setTypeCode(at.getComponents());
|
|
|
+ if(CacheContext.alarmTypeMap.containsKey(at.getComponents()))
|
|
|
+ {
|
|
|
+ fs.setTypeName(CacheContext.alarmTypeMap.get(at.getComponents()).getName());
|
|
|
+ }
|
|
|
+ fs.setAlarmid(at.getId());
|
|
|
+ fs.setDescription(at.getDescription());
|
|
|
+ fs.setTotal(0l);
|
|
|
+ fs.setAvgSeconds(0.0);
|
|
|
+ fs.setMaxSeconds(0.0);
|
|
|
+ fs.setMinSeconds(0.0);
|
|
|
+ fs.setTotalSeconds(0.0);
|
|
|
+
|
|
|
+ }
|
|
|
+ vos.add(fs);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<AlarmStatVo> findCtFeatureStat(String wtId,String stationId,String modelId, Date startTime, Date endTime,String components,String deviceType,String alarmIds,String timeType) {
|
|
|
+ List<AlarmStatVo> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ StringBuilder alarmIdList=new StringBuilder();
|
|
|
+ StringBuilder componentsList=new StringBuilder();
|
|
|
+
|
|
|
+ Map<String,String> alarmIdMap=new HashMap<>();
|
|
|
+ Map<String,String> componentsMap=new HashMap();
|
|
|
+
|
|
|
+ if(StringUtils.notEmp(components))
|
|
|
+ {
|
|
|
+ String [] componentsStr=components.split(",");
|
|
|
+ for(String c:componentsStr)
|
|
|
+ {
|
|
|
+ componentsList.append("'").append(c).append("',");
|
|
|
+ componentsMap.put(c,c);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if(StringUtils.notEmp(alarmIds))
|
|
|
+ {
|
|
|
+ String [] alarmIdStr=alarmIds.split(",");
|
|
|
+ for(String c:alarmIdStr)
|
|
|
+ {
|
|
|
+ alarmIdList.append("'").append(c).append("',");
|
|
|
+ alarmIdMap.put(c,c);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ String alarmId=null;
|
|
|
+ String component=null;
|
|
|
+ if(alarmIdList.length()>0)
|
|
|
+ {
|
|
|
+ alarmId=String.valueOf(alarmIdList.substring(0,alarmIdList.length()-1));
|
|
|
+ }
|
|
|
+ if(componentsList.length()>0)
|
|
|
+ {
|
|
|
+ component=String.valueOf(componentsList.substring(0,componentsList.length()-1));
|
|
|
+ }
|
|
|
+ List<ProBasicFeatureStat> fsls = alarmTsMapper.findCtFeatureStat(wtId,startTime.getTime(), endTime.getTime(),stationId,modelId,component,alarmId,deviceType);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, ProBasicFeatureStat> map = new HashMap<>();
|
|
|
+ Date statDate=DateUtils.truncate(new Date());
|
|
|
+
|
|
|
+ if (!fsls.isEmpty()) {
|
|
|
+ for (ProBasicFeatureStat fs : fsls) {
|
|
|
+ if (StringUtils.notEmp(fs.getTypeCode()) && CacheContext.alarmTypeMap.containsKey(fs.getTypeCode())) {
|
|
|
+ ProEconAlarmType at = CacheContext.alarmTypeMap.get(fs.getTypeCode());
|
|
|
+ fs.setTypeName(at.getName());
|
|
|
+ }
|
|
|
+ fs.setStatDate(new Timestamp(statDate.getTime()));
|
|
|
+ fs.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append(fs.getWtId()).append("_").append(fs.getAlarmid());
|
|
|
+ map.put(String.valueOf(sb), fs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<ProBasicFeatureStat> vos = new ArrayList<>();
|
|
|
+
|
|
|
+ if(CacheContext.wpwtmap.containsKey(stationId))
|
|
|
+ {
|
|
|
+ List<ProBasicEquipment> wtls=CacheContext.wpwtmap.get(stationId);
|
|
|
+ for (ProBasicEquipment wt : wtls) {
|
|
|
+
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append(wt.getWindpowerstationId()).append(wt.getModelId());
|
|
|
+
|
|
|
+ if(CacheContext.ctAlarmlsMap.containsKey(String.valueOf(sb))) {
|
|
|
+
|
|
|
+ List<ProEconAlarmRule> wtCustomls=CacheContext.ctAlarmlsMap.get(String.valueOf(sb));
|
|
|
+
|
|
|
+ for (ProEconAlarmRule at : wtCustomls) {
|
|
|
+
|
|
|
+ if(StringUtils.notEmp(components) )
|
|
|
+ {
|
|
|
+ if(componentsMap.containsKey(at.getRelatedParts()) )
|
|
|
+ {
|
|
|
+ if(StringUtils.notEmp(alarmIdMap) && !alarmIdMap.isEmpty())
|
|
|
+ {
|
|
|
+ if( alarmIdMap.containsKey(at.getId()))
|
|
|
+ {
|
|
|
+ setCtValues(statDate, map, vos, wt, at);
|
|
|
+ }
|
|
|
+
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ setCtValues(statDate, map, vos, wt, at);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ setCtValues(statDate, map, vos, wt, at);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map<String,List<AlarmStatVo>> vomap=new HashMap<>();
|
|
|
+ for(ProBasicFeatureStat fs:vos)
|
|
|
+ {
|
|
|
+ AlarmStatVo d = new AlarmStatVo();
|
|
|
+ d.setRelateParts(fs.getTypeCode());
|
|
|
+ d.setRelatePartsText(fs.getTypeName());
|
|
|
+ d.setAlertText(fs.getDescription());
|
|
|
+ d.setCount(fs.getTotal());
|
|
|
+ if(StringUtils.notEmp(timeType))
|
|
|
+ {
|
|
|
+ if(AlarmTime.H.getCode().equals(timeType))
|
|
|
+ {
|
|
|
+ double times= new BigDecimal(fs.getTotalSeconds()).divide(new BigDecimal(360), 2, RoundingMode.HALF_EVEN).doubleValue();
|
|
|
+ d.setTime(times);
|
|
|
+ }else if(AlarmTime.M.getCode().equals(timeType))
|
|
|
+ {
|
|
|
+ double times= new BigDecimal(fs.getTotalSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
|
|
|
+ d.setTime(times);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ d.setTime(fs.getTotalSeconds());
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ double times= new BigDecimal(fs.getTotalSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
|
|
|
+ d.setTime(times);
|
|
|
+ }
|
|
|
+ d.setStationId(fs.getStationId());
|
|
|
+ d.setSnapId(SnowflakeGenerator.generateId());
|
|
|
+ d.setWindturbineId(fs.getWtId());
|
|
|
+ if(CacheContext.wtmap.containsKey(fs.getWtId()))
|
|
|
+ {
|
|
|
+ ProBasicEquipment wt= CacheContext.wtmap.get(fs.getWtId());
|
|
|
+ d.setWindturbineCode(wt.getNemCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append(fs.getWtId()).append("_").append(fs.getTypeCode()).append("_").append(fs.getAlarmid());
|
|
|
+
|
|
|
+ if(map.containsKey(String.valueOf(sb)))
|
|
|
+ {
|
|
|
+ List<AlarmStatVo> ls=vomap.get(String.valueOf(sb));
|
|
|
+ ls.add(d);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ List<AlarmStatVo> ls=new ArrayList<>();
|
|
|
+ ls.add(d);
|
|
|
+ vomap.put(String.valueOf(sb),ls);
|
|
|
+ }
|
|
|
+ resultList.add(d);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+ private static void setCtValues(Date statDate,Map<String, ProBasicFeatureStat> map, List<ProBasicFeatureStat> vos, ProBasicEquipment wt, ProEconAlarmRule at) {
|
|
|
+
|
|
|
+ ProBasicFeatureStat fs = new ProBasicFeatureStat();
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append(fs.getWtId()).append("_").append(at.getId());
|
|
|
+ if (map.containsKey(String.valueOf(sb))) {
|
|
|
+ ProBasicFeatureStat old = map.get(String.valueOf(sb));
|
|
|
+ BeanUtil.copyProperties(old, fs);
|
|
|
+ } else {
|
|
|
+ fs.setStatDate(new Timestamp(statDate.getTime()));
|
|
|
+ fs.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ fs.setWtId(wt.getId());
|
|
|
+ fs.setStationId(wt.getWindpowerstationId());
|
|
|
+ fs.setTypeCode(at.getCategory());
|
|
|
+ if(CacheContext.alarmTypeMap.containsKey(at.getCategory()))
|
|
|
+ {
|
|
|
+ fs.setTypeName(CacheContext.alarmTypeMap.get(at.getCategory()).getName());
|
|
|
+ }
|
|
|
+ fs.setAlarmid(at.getId());
|
|
|
+ fs.setDescription(at.getDescription());
|
|
|
+ fs.setTotal(0l);
|
|
|
+ fs.setAvgSeconds(0.0);
|
|
|
+ fs.setMaxSeconds(0.0);
|
|
|
+ fs.setMinSeconds(0.0);
|
|
|
+ fs.setTotalSeconds(0.0);
|
|
|
+
|
|
|
+ }
|
|
|
+ vos.add(fs);
|
|
|
+ }
|
|
|
+}
|