|
@@ -1,9 +1,12 @@
|
|
|
package com.gyee.gaia.cause.service;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import com.gyee.gaia.cause.adapter.AdapterApi;
|
|
|
+import com.gyee.gaia.cause.adapter.ShardingApi;
|
|
|
import com.gyee.gaia.cause.config.AppConfig;
|
|
|
import com.gyee.gaia.cause.entity.PointData;
|
|
|
import com.gyee.gaia.cause.entity.StateCause;
|
|
|
+import com.gyee.gaia.common.data.alarm.FaultInfo;
|
|
|
import com.gyee.gaia.common.data.point.TestingPoint;
|
|
|
import com.gyee.gaia.common.data.power.ModelPower;
|
|
|
import com.gyee.gaia.init.CacheContext;
|
|
@@ -21,6 +24,8 @@ public class CalculateService {
|
|
|
@Resource
|
|
|
private AdapterApi adapterApi;
|
|
|
@Resource
|
|
|
+ private ShardingApi shardingApi;
|
|
|
+ @Resource
|
|
|
private AppConfig appConfig;
|
|
|
@Resource
|
|
|
private IStateCauseService stateCauseService;
|
|
@@ -29,6 +34,7 @@ public class CalculateService {
|
|
|
* 设备id,状态点列表
|
|
|
*/
|
|
|
private Map<String, List<PointData>> stateDatas;
|
|
|
+ Map<Double, String> stateMap = CacheContext.stateMap;
|
|
|
|
|
|
public void refresh(long starttime, long endtime){
|
|
|
log.info("刷新测点值!");
|
|
@@ -41,7 +47,7 @@ public class CalculateService {
|
|
|
//风机的8种原始状态:0-停机、 1-上电、2-待机、3-启动、4-并网、5-故障、6-维护、 7-离线
|
|
|
public void calculate() {
|
|
|
List<StateCause> stateCauseList = new ArrayList<>();
|
|
|
- stateDatas.forEach((key,value)->{
|
|
|
+ stateDatas.forEach((thingId,value)->{
|
|
|
//事前状态
|
|
|
double advanceState = value.get(0).getDoubleValue();
|
|
|
//事前时间
|
|
@@ -59,42 +65,40 @@ public class CalculateService {
|
|
|
//判断事前状态
|
|
|
if(advanceState==4){
|
|
|
//计算限电
|
|
|
- calcElectricityRation(stateCauseList,key,advanceTime,ts,doubleValue);
|
|
|
+ calcElectricityRation(stateCauseList,thingId,advanceTime,ts,doubleValue);
|
|
|
//TODO 判断限停
|
|
|
}else if(advanceState==2){
|
|
|
- StateCause cause = new StateCause();
|
|
|
- cause.setStationId(CacheContext.equipPointsMap.get(key).getWindpowerstationId());
|
|
|
- cause.setEquipmentId(CacheContext.equipPointsMap.get(key).getId());
|
|
|
- cause.setEvent("待机");
|
|
|
- cause.setStartTime(new Date(advanceTime));
|
|
|
- cause.setEndTime(new Date(ts));
|
|
|
- cause.setAdvanceState("待机");
|
|
|
- cause.setAfterState(CacheContext.stateMap.get(doubleValue));
|
|
|
- cause.setTime(ts -advanceTime);
|
|
|
- stateCauseList.add(cause);
|
|
|
+ if(judgmentStop(stateCauseList,thingId,advanceTime,ts)){
|
|
|
+ StateCause cause = new StateCause(thingId2Stationid(thingId),thingId, stateMap.get(8.0),
|
|
|
+ new Date(advanceTime),new Date(ts), stateMap.get(2.0),stateMap.get(doubleValue),ts -advanceTime);
|
|
|
+ stateCauseList.add(cause);
|
|
|
+ }else {
|
|
|
+ StateCause cause = new StateCause(thingId2Stationid(thingId),thingId, stateMap.get(2.0),
|
|
|
+ new Date(advanceTime),new Date(ts), stateMap.get(2.0),stateMap.get(doubleValue),ts -advanceTime);
|
|
|
+ stateCauseList.add(cause);
|
|
|
+ }
|
|
|
}else if(advanceState==6){
|
|
|
- if(isHasFaultEvent()){
|
|
|
+ if(isHasFaultEvent(thingId,advanceTime,ts)){
|
|
|
//故障
|
|
|
+ StateCause cause = new StateCause(thingId2Stationid(thingId),thingId, stateMap.get(5.0),
|
|
|
+ new Date(advanceTime),new Date(ts), stateMap.get(6.0),stateMap.get(doubleValue),ts -advanceTime);
|
|
|
+ stateCauseList.add(cause);
|
|
|
}else {
|
|
|
//计划检修
|
|
|
+ StateCause cause = new StateCause(thingId2Stationid(thingId),thingId, stateMap.get(9.0),
|
|
|
+ new Date(advanceTime),new Date(ts), stateMap.get(6.0),stateMap.get(doubleValue),ts -advanceTime);
|
|
|
+ stateCauseList.add(cause);
|
|
|
}
|
|
|
}else if(advanceState==5){
|
|
|
if(ts-advanceTime<appConfig.getFaulttime()*60000) continue;
|
|
|
//计算受累、故障、计划检修
|
|
|
- calcBurdened(stateCauseList,key,advanceTime, ts,5,doubleValue);
|
|
|
+ calcBurdened(stateCauseList,thingId,advanceTime, ts,5,doubleValue);
|
|
|
}else if(advanceState==7){
|
|
|
//计算受累、故障、计划检修
|
|
|
- calcBurdened(stateCauseList,key,advanceTime, ts,7,doubleValue);
|
|
|
+ calcBurdened(stateCauseList,thingId,advanceTime, ts,7,doubleValue);
|
|
|
}else if(advanceState==0){
|
|
|
- StateCause cause = new StateCause();
|
|
|
- cause.setStationId(CacheContext.equipPointsMap.get(key).getWindpowerstationId());
|
|
|
- cause.setEquipmentId(CacheContext.equipPointsMap.get(key).getId());
|
|
|
- cause.setEvent("停机");
|
|
|
- cause.setStartTime(new Date(advanceTime));
|
|
|
- cause.setEndTime(new Date(ts));
|
|
|
- cause.setAdvanceState("停机");
|
|
|
- cause.setAfterState(CacheContext.stateMap.get(doubleValue));
|
|
|
- cause.setTime(ts -advanceTime);
|
|
|
+ StateCause cause = new StateCause(thingId2Stationid(thingId),thingId, stateMap.get(0.0),
|
|
|
+ new Date(advanceTime),new Date(ts), stateMap.get(2.0),stateMap.get(doubleValue),ts -advanceTime);
|
|
|
stateCauseList.add(cause);
|
|
|
}
|
|
|
|
|
@@ -106,16 +110,64 @@ public class CalculateService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 判断限停
|
|
|
+ */
|
|
|
+ private boolean judgmentStop(List<StateCause> stateCauseList, String thingId, long start, long end) {
|
|
|
+ if(isHasFaultEvent(thingId,start,end)) return false;
|
|
|
+ String stationid = thingId2Stationid(thingId);
|
|
|
+
|
|
|
+ List<PointData> apsRbk = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("active-power-set").get(stationid).getCode(), start, end,30);
|
|
|
+ List<PointData> apRbk = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("apparent-power").get(stationid).getCode(), start, end,30);
|
|
|
+ List<PointData> opRbk = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("output-power").get(stationid).getCode(), start, end,30);
|
|
|
+ double apsDouble = apsRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble();
|
|
|
+ double apDouble = apRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble();
|
|
|
+ double opDouble = opRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble();
|
|
|
+ //有功设定小于出线功率
|
|
|
+ if(apsDouble<opDouble) return true;
|
|
|
+ //有功设定小于应发的85% 并且 出线功率大于有功设定94%
|
|
|
+ if(apsDouble<=apDouble*0.85&&opDouble>=apsDouble*0.94) return true;
|
|
|
+
|
|
|
+ List<StateCause> collect = stateCauseList.stream().filter(sc -> stationid.equals(sc.getStationId()) && stateMap.get(8.0).equals(sc.getEvent())
|
|
|
+ && sc.getStartTime().getTime() >= start && sc.getEndTime().getTime() <= end).collect(Collectors.toList());
|
|
|
+ //有功设定小于应发的70% 并且 出线功率大于有功设定80% 并且 当前场站限电台数大于等于3
|
|
|
+ if(apsDouble<=apDouble*0.7&&opDouble>=apsDouble*0.8&&collect.size()>=3) return true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断30分钟内是否有故障
|
|
|
+ */
|
|
|
+ private boolean isHasFaultEvent(String thingId, long start, long end) {
|
|
|
+ String stationid = thingId2Stationid(thingId);
|
|
|
+ String startStr = DateTime.of(start - 30 * 60 * 1000).toDateStr();
|
|
|
+ String endStr = DateTime.of(end).toDateStr();
|
|
|
+ List<FaultInfo> fj = shardingApi.getFaultInfoList("FJ", startStr, endStr, stationid, null,1);
|
|
|
+ List<FaultInfo> collect = fj.stream().filter(fi -> thingId.equals(fi.getWindturbineId())).collect(Collectors.toList());
|
|
|
+ if(collect.isEmpty()){
|
|
|
+ List<FaultInfo> infos = shardingApi.getFaultInfoList("SYZ", startStr, endStr, stationid, "位状态", 1);
|
|
|
+ if(infos.isEmpty()) return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 风机查找返回所属场站
|
|
|
+ */
|
|
|
+ private String thingId2Stationid(String thingId) {
|
|
|
+ return CacheContext.equipPointsMap.get(thingId).getWindpowerstationId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 计算受累
|
|
|
*/
|
|
|
- private void calcBurdened(List<StateCause> stateCauseList, String equipment, long start, long end, double starteventstate, double endeventstate) {
|
|
|
+ private void calcBurdened(List<StateCause> stateCauseList, String thingId, long start, long end, double starteventstate, double endeventstate) {
|
|
|
//全站故障或者离线
|
|
|
Map<String, TestingPoint> state8 = CacheContext.pointMapMap.get("state8");
|
|
|
- String station = state8.get(equipment).getStationId();
|
|
|
+ String stationId = state8.get(thingId).getStationId();
|
|
|
|
|
|
List<List<PointData>> stationState = new ArrayList<>();
|
|
|
//当前风机的场站所有风机
|
|
|
- List<TestingPoint> points = state8.values().stream().filter(tp -> station.equals(tp.getStationId())).collect(Collectors.toList());
|
|
|
+ List<TestingPoint> points = state8.values().stream().filter(tp -> stationId.equals(tp.getStationId())).collect(Collectors.toList());
|
|
|
points.forEach(tp->{
|
|
|
List<PointData> valuesByKey = adapterApi.getValuesByKey(state8.get(tp.getThingId()).getCode(), start, end, 30);
|
|
|
stationState.add(valuesByKey);
|
|
@@ -167,17 +219,22 @@ public class CalculateService {
|
|
|
}
|
|
|
if(k/size>9.5){
|
|
|
//受累
|
|
|
- }else if(isHasFaultEvent()){
|
|
|
+ StateCause cause = new StateCause(stationId,thingId,stateMap.get(10.0),new Date(start),new Date(end),
|
|
|
+ stateMap.get(starteventstate),stateMap.get(endeventstate),end - start);
|
|
|
+ stateCauseList.add(cause);
|
|
|
+ }else if(isHasFaultEvent(thingId,start,end)){
|
|
|
//故障
|
|
|
+ StateCause cause = new StateCause(stationId,thingId,stateMap.get(5.0),new Date(start),new Date(end),
|
|
|
+ stateMap.get(starteventstate),stateMap.get(endeventstate),end - start);
|
|
|
+ stateCauseList.add(cause);
|
|
|
}else {
|
|
|
//计划检修
|
|
|
+ StateCause cause = new StateCause(stationId,thingId,stateMap.get(9.0),new Date(start),new Date(end),
|
|
|
+ stateMap.get(starteventstate),stateMap.get(endeventstate),end - start);
|
|
|
+ stateCauseList.add(cause);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private boolean isHasFaultEvent() {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 计算限电
|
|
|
* @param equipment 设备id
|
|
@@ -220,20 +277,15 @@ public class CalculateService {
|
|
|
}
|
|
|
isElectricityRation = true;
|
|
|
}else if(isElectricityRation){
|
|
|
- StateCause cause = new StateCause();
|
|
|
- cause.setStationId(CacheContext.equipPointsMap.get(equipment).getWindpowerstationId());
|
|
|
- cause.setEquipmentId(equipment);
|
|
|
- cause.setEvent(CacheContext.stateMap.get(8.0));
|
|
|
- cause.setStartTime(new Date(t1));
|
|
|
- cause.setEndTime(new Date(ts));
|
|
|
- cause.setAdvanceState(CacheContext.stateMap.get(4.0));
|
|
|
- if(i==speedList.size()-1){
|
|
|
- cause.setAfterState(CacheContext.stateMap.get(endeventstate));
|
|
|
+ if(i==speedList.size()-1) {
|
|
|
+ StateCause cause = new StateCause(thingId2Stationid(equipment),equipment, stateMap.get(8.0),
|
|
|
+ new Date(t1),new Date(ts), stateMap.get(4.0),stateMap.get(endeventstate),ts -t1);
|
|
|
+ stateCauseList.add(cause);
|
|
|
}else {
|
|
|
- cause.setAfterState(CacheContext.stateMap.get(4.0));
|
|
|
+ StateCause cause = new StateCause(thingId2Stationid(equipment),equipment, stateMap.get(8.0),
|
|
|
+ new Date(t1),new Date(ts), stateMap.get(4.0),stateMap.get(4.0),ts -t1);
|
|
|
+ stateCauseList.add(cause);
|
|
|
}
|
|
|
- cause.setTime(ts - t1);
|
|
|
- stateCauseList.add(cause);
|
|
|
isElectricityRation = false;
|
|
|
}
|
|
|
}
|