Browse Source

五损状态计算--故障和限停

xushili 1 year ago
parent
commit
4292155dac

+ 104 - 0
common/data/src/main/java/com/gyee/gaia/common/data/alarm/FaultInfo.java

@@ -0,0 +1,104 @@
+package com.gyee.gaia.common.data.alarm;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+
+@Data
+public class FaultInfo implements Serializable {
+
+
+    private long id;
+    //报警时间
+    private Date faultTime;
+    //对象类型
+    private int messageType;
+    //报警内容
+    private long snapID;
+
+    private Integer confirmType;
+
+    private Date confirmTime;
+
+    private String confirmPerson;
+
+    private String stationId;
+
+    private String projectId;
+
+    private String lineId;
+
+    private String windturbineId;
+    //报警对应故障编码
+    private long alertValue;
+    //报警级别
+    private String rank;
+
+    private String category1;
+
+    private String category2;
+
+    private String category3;
+
+    private boolean isOpened;
+
+    private Date lastUpdateTime;
+
+    private String lastUpdatePerson;
+
+    private String stationName;
+
+    private String projectName;
+
+    private String lineName;
+
+    private String windturbineName;
+
+    private String alertText;
+
+    private String modelId;
+
+    public String getObjectName() {
+        if ("FJ".equals(category1))
+            return windturbineName;
+        else
+            return stationName;
+    }
+
+    public String getObjectId() {
+        if ("FJ".equals(category1))
+            return windturbineId;
+        else
+            return stationId;
+    }
+
+    public String getCategoryName() {
+        if(category1==null) return "未知";
+        switch (category1) {
+            case "FJ":
+                return "风机";
+            case "SYZ":
+                return "升压站";
+            default:
+                return "未知";
+        }
+    }
+
+    public String getMessageTypeString() {
+        String resultString = "";
+        if (messageType == 1) {
+            resultString = "触发";
+        } else if (messageType == 2) {
+            resultString = "";
+        } else if (messageType == 3) {
+            resultString = "解除";
+        }
+        return resultString;
+    }
+
+    public String getIdString() {
+        return id + "";
+    }
+}

+ 22 - 0
state/cause/src/main/java/com/gyee/gaia/cause/adapter/ShardingApi.java

@@ -0,0 +1,22 @@
+package com.gyee.gaia.cause.adapter;
+
+import com.gyee.gaia.common.data.alarm.FaultInfo;
+import feign.Param;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+
+@FeignClient(name = "sharding", url = "${meter.sharding-url}")
+public interface ShardingApi {
+
+    @GetMapping("/fault/history/list?category1={category1}&pagenum=1&pagesize=1000&stationid={stationid}&starttime={starttime}&endtime={endtime}&messagetype={messagetype}&keyword={keyword}")
+    List<FaultInfo> getFaultInfoList(
+            @Param(value = "category1") String category1,
+            @Param(value = "starttime") String starttime,
+            @Param(value = "endtime") String endtime,
+            @Param(value = "stationid") String stationid,
+            @Param(value = "keyword") String keyWord,
+            @Param(value = "messagetype") int messagetype);
+}

+ 1 - 0
state/cause/src/main/java/com/gyee/gaia/cause/config/AppConfig.java

@@ -18,6 +18,7 @@ public class AppConfig {
      * 统一编码名,统一编码
      */
     private Map<String, String> uniformcode;
+    private Map<String, String> uniformcodeStation;
     private int faulttime;
 
 

+ 12 - 0
state/cause/src/main/java/com/gyee/gaia/cause/entity/StateCause.java

@@ -3,6 +3,7 @@ package com.gyee.gaia.cause.entity;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
 
 import java.io.Serializable;
 import java.util.Date;
@@ -65,6 +66,17 @@ public class StateCause implements Serializable {
 
     private Long time;
 
+    public StateCause(String stationId, String equipmentId, String event, Date startTime, Date endTime, String advanceState, String afterState, Long time) {
+        this.stationId = stationId;
+        this.equipmentId = equipmentId;
+        this.event = event;
+        this.startTime = startTime;
+        this.endTime = endTime;
+        this.advanceState = advanceState;
+        this.afterState = afterState;
+        this.time = time;
+    }
+
     public Integer getId() {
         return id;
     }

+ 96 - 44
state/cause/src/main/java/com/gyee/gaia/cause/service/CalculateService.java

@@ -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;
             }
         }

+ 16 - 13
state/cause/src/main/java/com/gyee/gaia/init/CacheContext.java

@@ -47,14 +47,27 @@ public class CacheContext implements CommandLineRunner {
 
     @Override
     public void run(String... args) throws Exception {
-        log.info("加载统一编码!");
-        /*QueryWrapper<UniformCode> ucWrapper = new QueryWrapper<>();
+        /*log.info("加载统一编码!");
+        QueryWrapper<UniformCode> ucWrapper = new QueryWrapper<>();
         ucWrapper.eq("spare1", "计算五损");
         List<UniformCode> uniformCodeList = uniformCodeService.list(ucWrapper);
         Map<String, String> uniformCodeMap = uniformCodeList.stream().collect(Collectors.toMap(UniformCode::getDescription, UniformCode::getNemCode));*/
 
         log.info("加载状态测点!");
-        loadPoints(appConfig.getUniformcode());
+        appConfig.getUniformcode().forEach((k,v)->{
+            QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
+            tpWrapper.eq("thing_type","windturbine").eq("uniform_code", v);
+            List<TestingPoint> list = testingPointService.list(tpWrapper);
+            Map<String, TestingPoint> collect = list.stream().collect(Collectors.toMap(TestingPoint::getThingId, Function.identity()));
+            pointMapMap.put(k, collect);
+        });
+        appConfig.getUniformcodeStation().forEach((k,v)->{
+            QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
+            tpWrapper.eq("thing_type","station").likeLeft("station_id","DC").eq("uniform_code", v);
+            List<TestingPoint> list = testingPointService.list(tpWrapper);
+            Map<String, TestingPoint> collect = list.stream().collect(Collectors.toMap(TestingPoint::getThingId, Function.identity()));
+            pointMapMap.put(k, collect);
+        });
 
         log.info("加载机型满发最低风速!");
         QueryWrapper<ModelPower> mpWrapper = new QueryWrapper<>();
@@ -81,14 +94,4 @@ public class CacheContext implements CommandLineRunner {
         List<Equipment> emList = equipmentService.list();
         equipPointsMap=emList.stream().collect(Collectors.toMap(Equipment::getId, Function.identity()));
     }
-
-    private void loadPoints(Map<String, String> uniformcode) {
-        uniformcode.forEach((k,v)->{
-            QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
-            tpWrapper.eq("thing_type","windturbine").eq("uniform_code", v);
-            List<TestingPoint> list = testingPointService.list(tpWrapper);
-            Map<String, TestingPoint> collect = list.stream().collect(Collectors.toMap(TestingPoint::getThingId, Function.identity()));
-            pointMapMap.put(k, collect);
-        });
-    }
 }

+ 9 - 1
state/cause/src/main/resources/bootstrap.yaml

@@ -46,6 +46,7 @@ spring:
 meter:
   stations: MHS_FDC,NSS_FDC
   adapter-url: http://192.168.10.18:8011
+  sharding-url: http://192.168.10.18:8075
   #多长时间计算故障损失,单位分钟
   faulttime: 3
   uniformcode:
@@ -56,7 +57,14 @@ meter:
     #功率-有功功率
     active-power: AI130
     #风速
-    speed:
+    speed: AI022
+  uniformcode-station:
+    #有功设定
+    active-power-set: AGC002
+    #应发功率
+    apparent-power: ZLLGL
+    #出线功率
+    output-power: AGC001
 
 
 mybatis-plus: