Prechádzať zdrojové kódy

五损状态计算--bug修复

xushili 1 rok pred
rodič
commit
d1dfca5019
28 zmenil súbory, kde vykonal 484 pridanie a 139 odobranie
  1. 31 53
      common/data/src/main/java/com/gyee/gaia/common/data/point/TestingPoint.java
  2. 0 1
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/BasicTsData.java
  3. 5 0
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/BlobTsData.java
  4. 4 0
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/BooleanTsData.java
  5. 4 0
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/CoordinateTsData.java
  6. 4 0
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/DoubleTsData.java
  7. 4 0
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/GeneralTsData.java
  8. 5 0
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/IntegerTsData.java
  9. 5 0
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/LongTsData.java
  10. 4 0
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/StringTsData.java
  11. 1 1
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/TsData.java
  12. 168 0
      common/data/src/main/java/com/gyee/gaia/common/data/windturbine/Booststation.java
  13. 5 0
      state/cause/src/main/java/com/gyee/gaia/cause/adapter/AdapterApi.java
  14. 7 7
      state/cause/src/main/java/com/gyee/gaia/cause/adapter/ShardingApi.java
  15. 1 1
      state/cause/src/main/java/com/gyee/gaia/cause/config/AppConfig.java
  16. 9 7
      state/cause/src/main/java/com/gyee/gaia/cause/job/CauseJobHandler.java
  17. 100 43
      state/cause/src/main/java/com/gyee/gaia/cause/service/CalculateService.java
  18. 31 9
      state/cause/src/main/java/com/gyee/gaia/init/CacheContext.java
  19. 10 10
      state/cause/src/main/resources/bootstrap.yaml
  20. 24 0
      timeseries/dao-golden/src/main/java/com/gyee/gaia/dao/golden/GoldenHistoryDao.java
  21. 2 0
      timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/point/UniformCodeMapper.java
  22. 18 0
      timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/windturbine/BooststationMapper.java
  23. 19 0
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/Windturbine/BooststationServiceImpl.java
  24. 16 0
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/Windturbine/IBooststationService.java
  25. 2 2
      timeseries/data-adapter/build.gradle
  26. 1 1
      timeseries/data-adapter/src/main/resources/application-nx.yaml
  27. 1 1
      timeseries/data-adapter/src/main/resources/application.yaml
  28. 3 3
      timeseries/data-adapter/src/main/resources/bootstrap.yaml

+ 31 - 53
common/data/src/main/java/com/gyee/gaia/common/data/point/TestingPoint.java

@@ -6,11 +6,11 @@ import java.io.Serializable;
 
 /**
  * <p>
- * 逻辑测点
+ * 
  * </p>
  *
  * @author gfhd
- * @since 2023-04-24
+ * @since 2023-05-11
  */
 @TableName("pro_econ_testing_point")
 public class TestingPoint implements Serializable {
@@ -19,71 +19,40 @@ public class TestingPoint implements Serializable {
 
     private String id;
 
-    /**
-     * 测点
-     */
     private String code;
 
-    /**
-     * 描述
-     */
     private String name;
 
-    /**
-     * 机型
-     */
     private String model;
 
     private String typeId;
 
-    /**
-     * 原始统一编码
-     */
     private String originalUniformCode;
 
-    /**
-     * 统一编码
-     */
     private String uniformCode;
 
-    /**
-     * 统一编码备用
-     */
     private String ucv1;
 
     private String ucv2;
 
     private String ucv3;
 
-    /**
-     * 设备id
-     */
     private String thingId;
 
-    /**
-     * 场站,风机,部件
-     */
     private String thingType;
 
-    /**
-     * 数据类型
-     */
     private String dataType;
 
-    /**
-     * 场站
-     */
     private String stationId;
 
-    /**
-     * 部件编号
-     */
     private String logicalUnitId;
 
     private Boolean isDisplay;
 
     private String spare;
 
+    private Double rate;
+
     public String getId() {
         return id;
     }
@@ -220,26 +189,35 @@ public class TestingPoint implements Serializable {
         this.spare = spare;
     }
 
+    public Double getRate() {
+        return rate;
+    }
+
+    public void setRate(Double rate) {
+        this.rate = rate;
+    }
+
     @Override
     public String toString() {
         return "TestingPoint{" +
-                "id = " + id +
-                ", code = " + code +
-                ", name = " + name +
-                ", model = " + model +
-                ", typeId = " + typeId +
-                ", originalUniformCode  = " + originalUniformCode +
-                ", uniformCode = " + uniformCode +
-                ", ucv1 = " + ucv1 +
-                ", ucv2 = " + ucv2 +
-                ", ucv3 = " + ucv3 +
-                ", thingId = " + thingId +
-                ", thingType = " + thingType +
-                ", dataType = " + dataType +
-                ", stationId = " + stationId +
-                ", logicalUnitId = " + logicalUnitId +
-                ", isDisplay = " + isDisplay +
-                ", spare = " + spare +
-                "}";
+            "id = " + id +
+            ", code = " + code +
+            ", name = " + name +
+            ", model = " + model +
+            ", typeId = " + typeId +
+            ", originalUniformCode = " + originalUniformCode +
+            ", uniformCode = " + uniformCode +
+            ", ucv1 = " + ucv1 +
+            ", ucv2 = " + ucv2 +
+            ", ucv3 = " + ucv3 +
+            ", thingId = " + thingId +
+            ", thingType = " + thingType +
+            ", dataType = " + dataType +
+            ", stationId = " + stationId +
+            ", logicalUnitId = " + logicalUnitId +
+            ", isDisplay = " + isDisplay +
+            ", spare = " + spare +
+            ", rate = " + rate +
+        "}";
     }
 }

+ 0 - 1
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/BasicTsData.java

@@ -35,6 +35,5 @@ public abstract class BasicTsData implements TsData, Comparable<BasicTsData> {
                 "', status='" + this.getStatus() +
                 "'}";
     }
-
 }
 

+ 5 - 0
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/BlobTsData.java

@@ -1,5 +1,6 @@
 package com.gyee.gaia.common.data.timeseries;
 
+import java.nio.ByteBuffer;
 import java.util.Base64;
 
 /**
@@ -20,5 +21,9 @@ public class BlobTsData extends BasicTsData {
         return Base64.getEncoder().encodeToString(blob);
     }
 
+    @Override
+    public double getValue() {
+        return ByteBuffer.wrap(blob).getDouble();
+    }
 }
 

+ 4 - 0
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/BooleanTsData.java

@@ -16,5 +16,9 @@ public class BooleanTsData extends BasicTsData {
         return actualValue;
     }
 
+    @Override
+    public double getValue() {
+        return actualValue?1:0;
+    }
 }
 

+ 4 - 0
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/CoordinateTsData.java

@@ -22,5 +22,9 @@ public class CoordinateTsData extends BasicTsData {
         //return String.format("{\"longitude\":%f,\"latitude\":\"%f\"}", longitude, latitude);
     }
 
+    @Override
+    public double getValue() {
+        return coordinate.getLongitude();
+    }
 }
 

+ 4 - 0
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/DoubleTsData.java

@@ -29,5 +29,9 @@ public class DoubleTsData extends BasicTsData {
                 "'}";
     }
 
+    @Override
+    public double getValue() {
+        return actualValue;
+    }
 }
 

+ 4 - 0
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/GeneralTsData.java

@@ -24,5 +24,9 @@ public class GeneralTsData implements TsData {
     private Optional<Coordinate> coordinateValue;
 
 
+    @Override
+    public double getValue() {
+        return doubleValue.get();
+    }
 }
 

+ 5 - 0
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/IntegerTsData.java

@@ -17,4 +17,9 @@ public class IntegerTsData extends BasicTsData {
     public Integer getIntegerValue() {
         return actualValue;
     }
+
+    @Override
+    public double getValue() {
+        return actualValue;
+    }
 }

+ 5 - 0
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/LongTsData.java

@@ -16,6 +16,11 @@ public class LongTsData extends BasicTsData {
         return actualValue;
     }
 
+    @Override
+    public double getValue() {
+        return actualValue;
+    }
+
     //    public String getValue() {
     //        return Long.toString(actualValue);
     //    }

+ 4 - 0
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/StringTsData.java

@@ -20,5 +20,9 @@ public class StringTsData extends BasicTsData {
         return actualValue;
     }
 
+    @Override
+    public double getValue() {
+        return Double.valueOf(actualValue);
+    }
 }
 

+ 1 - 1
common/data/src/main/java/com/gyee/gaia/common/data/timeseries/TsData.java

@@ -9,7 +9,7 @@ public interface TsData {
 
     short getStatus();
 
-    //double getValue();
+    double getValue();
 
 }
 

+ 168 - 0
common/data/src/main/java/com/gyee/gaia/common/data/windturbine/Booststation.java

@@ -0,0 +1,168 @@
+package com.gyee.gaia.common.data.windturbine;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-11
+ */
+@TableName("pro_basic_booststation")
+public class Booststation implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private String id;
+
+    private String code;
+
+    private String name;
+
+    private String aname;
+
+    private String stationid;
+
+    private String projects;
+
+    private String template;
+
+    private Object capacity;
+
+    private String capacityunit;
+
+    private Integer quantity;
+
+    private String model;
+
+    private Integer ordernum;
+
+    private String type;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getAname() {
+        return aname;
+    }
+
+    public void setAname(String aname) {
+        this.aname = aname;
+    }
+
+    public String getStationid() {
+        return stationid;
+    }
+
+    public void setStationid(String stationid) {
+        this.stationid = stationid;
+    }
+
+    public String getProjects() {
+        return projects;
+    }
+
+    public void setProjects(String projects) {
+        this.projects = projects;
+    }
+
+    public String getTemplate() {
+        return template;
+    }
+
+    public void setTemplate(String template) {
+        this.template = template;
+    }
+
+    public Object getCapacity() {
+        return capacity;
+    }
+
+    public void setCapacity(Object capacity) {
+        this.capacity = capacity;
+    }
+
+    public String getCapacityunit() {
+        return capacityunit;
+    }
+
+    public void setCapacityunit(String capacityunit) {
+        this.capacityunit = capacityunit;
+    }
+
+    public Integer getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(Integer quantity) {
+        this.quantity = quantity;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public Integer getOrdernum() {
+        return ordernum;
+    }
+
+    public void setOrdernum(Integer ordernum) {
+        this.ordernum = ordernum;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    @Override
+    public String toString() {
+        return "Booststation{" +
+            "id = " + id +
+            ", code = " + code +
+            ", name = " + name +
+            ", aname = " + aname +
+            ", stationid = " + stationid +
+            ", projects = " + projects +
+            ", template = " + template +
+            ", capacity = " + capacity +
+            ", capacityunit = " + capacityunit +
+            ", quantity = " + quantity +
+            ", model = " + model +
+            ", ordernum = " + ordernum +
+            ", type = " + type +
+        "}";
+    }
+}

+ 5 - 0
state/cause/src/main/java/com/gyee/gaia/cause/adapter/AdapterApi.java

@@ -1,11 +1,14 @@
 package com.gyee.gaia.cause.adapter;
 
 import com.gyee.gaia.cause.entity.PointData;
+import feign.Param;
+import feign.RequestLine;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 
 import java.util.List;
+import java.util.Map;
 
 @FeignClient(name = "adapter", url = "${meter.adapter-url}")
 public interface AdapterApi {
@@ -17,4 +20,6 @@ public interface AdapterApi {
     @GetMapping("/ts/history/raw?tagName={tagName}&startTs={startTs}&endTs={endTs}")
     List<PointData> getRawByKey(@PathVariable(value = "tagName") String tagName, @PathVariable(value = "startTs") long startTs,
                                 @PathVariable(value = "endTs") long endTs);
+    @GetMapping("/ts/history/section?tagNames={tagNames}&ts={ts}")
+    Map<String,PointData> getHistorySection(@PathVariable(value = "tagNames") String tagNames, @PathVariable(value = "ts") long ts);
 }

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

@@ -4,7 +4,7 @@ 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 org.springframework.web.bind.annotation.PathVariable;
 
 import java.util.List;
 
@@ -13,10 +13,10 @@ 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);
+            @PathVariable(value = "category1") String category1,
+            @PathVariable(value = "starttime") String starttime,
+            @PathVariable(value = "endtime") String endtime,
+            @PathVariable(value = "stationid") String stationid,
+            @PathVariable(value = "keyword") String keyWord,
+            @PathVariable(value = "messagetype") int messagetype);
 }

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

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

+ 9 - 7
state/cause/src/main/java/com/gyee/gaia/cause/job/CauseJobHandler.java

@@ -14,6 +14,7 @@ import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.DefaultApplicationArguments;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
@@ -40,6 +41,7 @@ public class CauseJobHandler implements ApplicationRunner {
     public ReturnT<String> windCauseJobHandler() {
         //String command = XxlJobHelper.getJobParam();
         //Map<String, String> map = JSON.parseObject(command, Map.class);
+
         return new ReturnT(SUCCESS_CODE, "调度成功111");
     }
 
@@ -49,15 +51,15 @@ public class CauseJobHandler implements ApplicationRunner {
         QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
         scWrapper.select("max(end_time)");
         Map<String, Object> map = stateCauseService.getMap(scWrapper);
-        if (map == null) {
-            map = new HashMap<>();
-            map.put("max", DateUtil.yesterday().getTime());
+        long max=0;
+        if (map != null && map.size()>0) {
+            max = (long)map.get("max");
+        }else {
+            max = DateUtil.yesterday().getTime();
         }
-        Object max = map.get("max");
-        if (max == null) max = DateUtil.yesterday().getTime();
 
-        CalculateService calculateService = new CalculateService();
-        calculateService.refresh((long) max, System.currentTimeMillis());
+        //CalculateService calculateService = new CalculateService();
+        calculateService.refresh(max, System.currentTimeMillis());
         calculateService.calculate();
 
     }

+ 100 - 43
state/cause/src/main/java/com/gyee/gaia/cause/service/CalculateService.java

@@ -9,6 +9,8 @@ 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.common.data.windturbine.Booststation;
+import com.gyee.gaia.common.data.windturbine.Equipment;
 import com.gyee.gaia.init.CacheContext;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -33,8 +35,8 @@ public class CalculateService {
     /**
      * 设备id,状态点列表
      */
-    private Map<String, List<PointData>> stateDatas;
-    Map<Double, String> stateMap = CacheContext.stateMap;
+    private Map<String, List<PointData>> stateDatas=new HashMap<>();
+    Map<Double, String> stateMap;
 
     public void refresh(long starttime, long endtime){
         log.info("刷新测点值!");
@@ -42,12 +44,14 @@ public class CalculateService {
             List<PointData> rawByKey = adapterApi.getRawByKey(v.getCode(), starttime, endtime);
             stateDatas.put(k, rawByKey);
         });
+        stateMap = CacheContext.stateMap;
     }
 
     //风机的8种原始状态:0-停机、 1-上电、2-待机、3-启动、4-并网、5-故障、6-维护、 7-离线
     public void calculate() {
         List<StateCause> stateCauseList = new ArrayList<>();
         stateDatas.forEach((thingId,value)->{
+            if(value.isEmpty()) return;
             //事前状态
             double advanceState = value.get(0).getDoubleValue();
             //事前时间
@@ -69,35 +73,35 @@ public class CalculateService {
                 //TODO 判断限停
                 }else if(advanceState==2){
                     if(judgmentStop(stateCauseList,thingId,advanceTime,ts)){
-                        StateCause cause = new StateCause(thingId2Stationid(thingId),thingId, stateMap.get(8.0),
+                        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),
+                        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(thingId,advanceTime,ts)){
                         //故障
-                        StateCause cause = new StateCause(thingId2Stationid(thingId),thingId, stateMap.get(5.0),
+                        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),
+                        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;
+                    if(ts-advanceTime<appConfig.getFaulttime()* 60000L) continue;
                     //计算受累、故障、计划检修
                     calcBurdened(stateCauseList,thingId,advanceTime, ts,5,doubleValue);
                 }else if(advanceState==7){
                     //计算受累、故障、计划检修
                     calcBurdened(stateCauseList,thingId,advanceTime, ts,7,doubleValue);
                 }else if(advanceState==0){
-                    StateCause cause = new StateCause(thingId2Stationid(thingId),thingId, stateMap.get(0.0),
+                    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);
                 }
@@ -114,38 +118,95 @@ 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);
+        Booststation boostStation = thingId2BoostStation(thingId);
+        TestingPoint apsTp = CacheContext.pointMapMap.get("active-power-set").get(boostStation.getId());
+        List<PointData> apsRbk = adapterApi.getValuesByKey(apsTp.getCode(), start, end,30);
+        if(apsRbk.isEmpty()) return false;
+        TestingPoint apTp = CacheContext.pointMapMap.get("apparent-power").get(boostStation.getId());
+        List<PointData> apRbk = adapterApi.getValuesByKey(apTp.getCode(), start, end,30);
+        if(apRbk.isEmpty()) return false;
+        TestingPoint opTp = CacheContext.pointMapMap.get("output-power").get(boostStation.getId());
+        List<PointData> opRbk = adapterApi.getValuesByKey(opTp.getCode(), start, end,30);
+        if(opRbk.isEmpty()) return false;
+        //有功设定
+        double apsDouble = apsRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble()*(apsTp.getRate()==null?1:apsTp.getRate());
+        //应发功率
+        double apDouble = 0;
+        if(boostStation.getId().contains("QS")){
+            TestingPoint apTp2 = CacheContext.pointMapMap.get("apparent-power").get(boostStation.getId()+"2");
+            List<PointData> apRbk2 = adapterApi.getValuesByKey(apTp2.getCode(), start, end,30);
+            if(apRbk2.isEmpty()) return false;
+            apDouble = apRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble()*(apTp.getRate()==null?1:apTp.getRate());
+            apDouble+=apRbk2.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble()*(apTp.getRate()==null?1:apTp.getRate());
 
-        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();
+        }else {
+            apDouble = apRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble()*(apTp.getRate()==null?1:apTp.getRate());
+        }
+        //出线功率
+        double opDouble = opRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble()*(opTp.getRate()==null?1:opTp.getRate());
         //有功设定小于出线功率
         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());
+        //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;
+        String stationid = thingId2StationId(thingId);
+        return apsDouble <= apDouble * 0.7 && opDouble >= apsDouble * 0.8 && electricityRationCount(stationid, end) >= 3;
+    }
+
+    /**
+     * 计算风电场当前时刻限电台数
+     */
+    private int electricityRationCount(String stationid, long end) {
+        int count = 0;
+        for (Equipment equipment : CacheContext.stationMap.get(stationid)) {
+            //满发功率和满发最小风速
+            ModelPower modelPower = CacheContext.fullSpeeds.get(equipment.getModelId());
+            //并网时间内的风速列表
+            String speedStr = CacheContext.pointMapMap.get("speed").get(equipment.getId()).getCode();
+            String bladeAngleStr = CacheContext.pointMapMap.get("blade-angle").get(equipment.getId()).getCode();
+            String activePowerStr = CacheContext.pointMapMap.get("active-power").get(equipment.getId()).getCode();
+            String s = new StringBuilder().append(speedStr).append(",").append(bladeAngleStr).append(",").append(activePowerStr).toString();
+            Map<String, PointData> historySection = adapterApi.getHistorySection(s, end);
+
+            if(historySection.size()<3) continue;
+            double speed = historySection.get(speedStr).getDoubleValue();
+            double bladeAngle = historySection.get(bladeAngleStr).getDoubleValue();
+            double activePower = historySection.get(activePowerStr).getDoubleValue();
+
+            //风速小于11并且桨叶角度大于2
+            if (speed <= modelPower.getSpeed() && bladeAngle > 2) {
+                count++;
+            //风速大于11并且有功功率小于满发功率减100
+            } else if (speed > modelPower.getSpeed() && activePower < modelPower.getTheoryPower()-100) {
+                count++;
+            }
+        }
+        return count;
     }
 
     /**
      * 判断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();
+        String stationid = thingId2StationId(thingId);
+        String startStr = DateTime.of(start - 30 * 60 * 1000).toStringDefaultTimeZone();
+        String endStr = DateTime.of(end).toStringDefaultTimeZone();
         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;
+            if(infos.isEmpty()){
+                return false;
+            }else {
+                System.out.println("SYZ"+infos.get(0).getAlertText());
+            }
+            //return !infos.isEmpty();
+        }else {
+            System.out.println("FJ"+collect.get(0).getAlertText());
         }
         return true;
     }
@@ -153,8 +214,12 @@ public class CalculateService {
     /**
      * 风机查找返回所属场站
      */
-    private String thingId2Stationid(String thingId) {
-        return CacheContext.equipPointsMap.get(thingId).getWindpowerstationId();
+    private String thingId2StationId(String thingId) {
+        return CacheContext.equipMap.get(thingId).getWindpowerstationId();
+    }
+
+    private Booststation thingId2BoostStation(String thingId) {
+        return CacheContext.boostStationMap.get(CacheContext.equipMap.get(thingId).getProjectId());
     }
 
     /**
@@ -174,21 +239,10 @@ public class CalculateService {
         });
         int size = stationState.get(0).size();
 
-        //是否受累
-        boolean isBurdened = false;
-        //受累开始时间
-        long t1 = 0;
-        //是否有故障
-        boolean isHasFault = false;
-        //故障开始时间
-        long t2 = 0;
-        //全场故障或离线次数
         int k = 0;
         for (int i = 0; i < size; i++) {
             int finalI = i;
             boolean b = stationState.stream().filter(pds -> pds.get(finalI).getDoubleValue() == starteventstate).count() == stationState.size();
-            //boolean c = stationState.stream().filter(pds -> pds.get(finalI).getDoubleValue() == 7).count() == stationState.size();
-            long ts = stationState.get(0).get(finalI).getTs();
             if(b){
                 k++;
             }
@@ -244,7 +298,7 @@ public class CalculateService {
      */
     private void calcElectricityRation(List<StateCause> stateCauseList, String equipment, long start, long end, double endeventstate) {
         //满发功率和满发最小风速
-        ModelPower modelPower = CacheContext.fullSpeeds.get(CacheContext.equipPointsMap.get(equipment).getModelId());
+        ModelPower modelPower = CacheContext.fullSpeeds.get(CacheContext.equipMap.get(equipment).getModelId());
         //并网时间内的风速列表
         List<PointData> speedList = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("speed").get(equipment).getCode(), start, end, 30);
         List<PointData> bladeAngleList = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("blade-angle").get(equipment).getCode(), start, end, 30);
@@ -258,6 +312,9 @@ public class CalculateService {
             long ts = speedList.get(i).getTs();
             double speedPd = speedList.get(i).getDoubleValue();
             //当前时间戳的桨叶角度
+            if(bladeAngleList==null||bladeAngleList.size()<speedList.size()||bladeAngleList.get(i)==null){
+                System.out.println();
+            }
             double bladeAnglePd = bladeAngleList.get(i).getDoubleValue();
             //当前时间戳的有功功率
             double activePowerPd = activePowerList.get(i).getDoubleValue();
@@ -277,15 +334,15 @@ public class CalculateService {
                 }
                 isElectricityRation = true;
             }else if(isElectricityRation){
+                StateCause cause;
                 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);
+                    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);
                 }else {
-                    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 = 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);
                 isElectricityRation = false;
             }
         }

+ 31 - 9
state/cause/src/main/java/com/gyee/gaia/init/CacheContext.java

@@ -4,12 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.gyee.gaia.cause.config.AppConfig;
 import com.gyee.gaia.common.data.point.TestingPoint;
 import com.gyee.gaia.common.data.power.ModelPower;
+import com.gyee.gaia.common.data.windturbine.Booststation;
 import com.gyee.gaia.common.data.windturbine.Equipment;
+import com.gyee.gaia.dao.sql.Windturbine.IBooststationService;
 import com.gyee.gaia.dao.sql.Windturbine.IEquipmentService;
 import com.gyee.gaia.dao.sql.point.ITestingPointService;
 import com.gyee.gaia.dao.sql.power.IModelPowerService;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
@@ -23,7 +26,7 @@ import java.util.stream.Collectors;
 @Order(1)
 @Slf4j
 @Component
-public class CacheContext implements CommandLineRunner {
+public class CacheContext implements ApplicationRunner {
 
     @Resource
     private ITestingPointService testingPointService;
@@ -32,6 +35,8 @@ public class CacheContext implements CommandLineRunner {
     @Resource
     private IEquipmentService equipmentService;
     @Resource
+    private IBooststationService booststationService;
+    @Resource
     private AppConfig appConfig;
 
     public static Map<String, ModelPower> fullSpeeds;
@@ -39,14 +44,22 @@ public class CacheContext implements CommandLineRunner {
     /**
      * 统一编码名称,设备id,测点
      */
-    public static Map<String, Map<String, TestingPoint>> pointMapMap;
+    public static Map<String, Map<String, TestingPoint>> pointMapMap=new HashMap<>();
+    /**
+     * 风机号,Equipment
+     */
+    public static Map<String,Equipment> equipMap;
     /**
-     * 风机号,TestingPoint
+     * 期次,升压站信息
      */
-    public static Map<String,Equipment> equipPointsMap;
+    public static Map<String,Booststation> boostStationMap=new HashMap<>();
+    /**
+     * 风场,风机
+     */
+    public static Map<String,List<Equipment>> stationMap;
 
     @Override
-    public void run(String... args) throws Exception {
+    public void run(ApplicationArguments args) throws Exception {
         /*log.info("加载统一编码!");
         QueryWrapper<UniformCode> ucWrapper = new QueryWrapper<>();
         ucWrapper.eq("spare1", "计算五损");
@@ -61,9 +74,9 @@ public class CacheContext implements CommandLineRunner {
             Map<String, TestingPoint> collect = list.stream().collect(Collectors.toMap(TestingPoint::getThingId, Function.identity()));
             pointMapMap.put(k, collect);
         });
-        appConfig.getUniformcodeStation().forEach((k,v)->{
+        appConfig.getUniformcodeBoost().forEach((k, v)->{
             QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
-            tpWrapper.eq("thing_type","station").likeLeft("station_id","DC").eq("uniform_code", v);
+            tpWrapper.eq("thing_type","booststation").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);
@@ -92,6 +105,15 @@ public class CacheContext implements CommandLineRunner {
 
         log.info("加载风机!");
         List<Equipment> emList = equipmentService.list();
-        equipPointsMap=emList.stream().collect(Collectors.toMap(Equipment::getId, Function.identity()));
+        equipMap =emList.stream().collect(Collectors.toMap(Equipment::getId, Function.identity()));
+        stationMap=emList.stream().collect(Collectors.groupingBy(Equipment::getWindpowerstationId));
+
+        log.info("加载升压站信息!");
+        List<Booststation> bsList = booststationService.list();
+        for (Booststation bs : bsList) {
+            for (String pj : bs.getProjects().split(",")) {
+                boostStationMap.put(pj, bs);
+            }
+        }
     }
 }

+ 10 - 10
state/cause/src/main/resources/bootstrap.yaml

@@ -24,9 +24,9 @@ spring:
     type: SIMPLE
   datasource:
     driver-class-name: org.postgresql.Driver
-    url: jdbc:postgresql://192.168.10.18:5432/nx_dev
-    username: gdprod
-    password: gyee123
+    url: jdbc:postgresql://192.168.1.67:5432/gyee
+    username: gyee
+    password: Gyee@2023!@#
     type: com.alibaba.druid.pool.DruidDataSource
     druid:
       max-active: 20
@@ -58,13 +58,13 @@ meter:
     active-power: AI130
     #风速
     speed: AI022
-  uniformcode-station:
-    #有功设定
-    active-power-set: AGC002
-    #应发功率
-    apparent-power: ZLLGL
-    #出线功率
-    output-power: AGC001
+  uniformcode-boost:
+    #有功设定限值
+    active-power-set: BTYGSDXZ
+    #理论功率
+    apparent-power: BTLLGL
+    #实发有功
+    output-power: BTSFYG
 
 
 mybatis-plus:

+ 24 - 0
timeseries/dao-golden/src/main/java/com/gyee/gaia/dao/golden/GoldenHistoryDao.java

@@ -349,6 +349,30 @@ public class GoldenHistoryDao implements IHistoryDao {
                 result.putAll(getFloatHistorySection(dateTime, mode, tagNames));
             if (entry.getKey() == TsDataType.BOOLEAN)
                 result.putAll(getBooleanHistorySection(dateTime, mode, tagNames));
+            if (entry.getKey() == TsDataType.LONG)
+                result.putAll(getLongHistorySection(dateTime, mode, tagNames));
+        }
+        return result;
+    }
+
+    private Map<String, TsData> getLongHistorySection(Date[] dateTime, RtdbHisMode mode, String... tagName) throws Exception {
+        Map<String, TsData> result = new HashMap<>();
+        ServerImpl connection = null;
+        try {
+            connection = goldenConfig.getGoldenConnectionPool().getConnection();
+            HistorianImpl his = new HistorianImpl(connection);
+            BaseImpl base = new BaseImpl(connection);
+
+            List<MinPoint> pointList = base.findPoints(tagName);
+
+            List<IntData> intDataList = his.getIntCrossSectionValues(pointList.stream().mapToInt(MinPoint::getId).toArray(), dateTime, mode);
+            for (int i = 0; i < tagName.length; i++) {
+                result.put(tagName[i], new LongTsData(intDataList.get(i).getDateTime().getTime(), (short) 0,
+                        (long) intDataList.get(i).getValue()));
+            }
+        } finally {
+            if (connection != null)
+                goldenConfig.getGoldenConnectionPool().returnConnection(connection);
         }
         return result;
     }

+ 2 - 0
timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/point/UniformCodeMapper.java

@@ -2,6 +2,7 @@ package com.gyee.gaia.dao.point;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.gyee.gaia.common.data.point.UniformCode;
+import org.apache.ibatis.annotations.Mapper;
 
 /**
  * <p>
@@ -11,6 +12,7 @@ import com.gyee.gaia.common.data.point.UniformCode;
  * @author gfhd
  * @since 2023-05-05
  */
+@Mapper
 public interface UniformCodeMapper extends BaseMapper<UniformCode> {
 
 }

+ 18 - 0
timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/windturbine/BooststationMapper.java

@@ -0,0 +1,18 @@
+package com.gyee.gaia.dao.windturbine;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.gaia.common.data.windturbine.Booststation;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-11
+ */
+@Mapper
+public interface BooststationMapper extends BaseMapper<Booststation> {
+
+}

+ 19 - 0
timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/Windturbine/BooststationServiceImpl.java

@@ -0,0 +1,19 @@
+package com.gyee.gaia.dao.sql.Windturbine;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.gaia.common.data.windturbine.Booststation;
+import com.gyee.gaia.dao.windturbine.BooststationMapper;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-11
+ */
+@Service
+public class BooststationServiceImpl extends ServiceImpl<BooststationMapper, Booststation> implements IBooststationService {
+
+}

+ 16 - 0
timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/Windturbine/IBooststationService.java

@@ -0,0 +1,16 @@
+package com.gyee.gaia.dao.sql.Windturbine;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.gaia.common.data.windturbine.Booststation;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-11
+ */
+public interface IBooststationService extends IService<Booststation> {
+
+}

+ 2 - 2
timeseries/data-adapter/build.gradle

@@ -22,11 +22,11 @@ dependencies {
     implementation project(":timeseries:dao-sql")
     //compile project(":timeseries:dao-redis")
     // compile project(":timeseries:dao-simulator")
-    //implementation project(":timeseries:dao-golden")
+    implementation project(":timeseries:dao-golden")
     //compile project(":timeseries:dao-taos")
     //implementation project(":timeseries:dao-taoscz")
     //implementation project(":timeseries:dao-taos")
-    implementation project(":timeseries:dao-redis-taos")
+    //implementation project(":timeseries:dao-redis-taos")
     //compile project(":timeseries:dao-hive")
     //compile project(":timeseries:dao-hadoop")
     implementation fileTree(dir: 'src/main/lib', include: '*.jar') //// oracle连接驱动       2区使用

+ 1 - 1
timeseries/data-adapter/src/main/resources/application-nx.yaml

@@ -77,7 +77,7 @@ timeseries:
   #db-type: hadoop #"${DATABASE_TYPE:sql}" # cassandra/kairosDB/hbase/opentsDB/influxDB/TiDB
 #golden 数据库信息
 golden:
-  server_ip: 10.155.32.1
+  server_ip: 192.168.1.100
   #server_ip: 172.168.1.3
   server_port: 6327
   user_name: sa

+ 1 - 1
timeseries/data-adapter/src/main/resources/application.yaml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: nxcs
+    active: nx

+ 3 - 3
timeseries/data-adapter/src/main/resources/bootstrap.yaml

@@ -8,15 +8,15 @@ spring:
   application:
     name: data-adapter
   profiles:
-    active: nxcs
+    active: nx
   cloud:
     nacos:
       discovery:
         # 服务注册地址
-        server-addr: 192.168.10.18:8848
+        server-addr: 192.168.1.66:8848
       config:
         # 配置中心地址
-        server-addr: 192.168.10.18:8848
+        server-addr: 192.168.1.66:8848
         # 配置文件格式
         file-extension: yml
         # 共享配置