Procházet zdrojové kódy

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	electricity/meter/src/main/resources/application.properties
malijun před 1 rokem
rodič
revize
e0b7ba2c37
95 změnil soubory, kde provedl 2900 přidání a 287 odebrání
  1. 1 1
      .gitignore
  2. 1 1
      common/data/src/main/java/com/gyee/gaia/common/data/alarm/FaultInfo.java
  3. 1 1
      state/cause/src/main/java/com/gyee/gaia/cause/entity/PointData.java
  4. 20 20
      common/data/src/main/java/com/gyee/gaia/common/data/point/TestingPoint.java
  5. 11 11
      common/data/src/main/java/com/gyee/gaia/common/data/point/UniformCode.java
  6. 95 0
      common/data/src/main/java/com/gyee/gaia/common/data/power/ModelPowerDetails.java
  7. 139 0
      common/data/src/main/java/com/gyee/gaia/common/data/taos/RealtimeAverageTarget.java
  8. 1 1
      common/data/src/main/java/com/gyee/gaia/common/data/timeseries/BooleanTsData.java
  9. 15 15
      common/data/src/main/java/com/gyee/gaia/common/data/windturbine/Booststation.java
  10. 1 1
      electricity/meter/src/main/java/com/gyee/gaia/meter/entity/MeterInfoBottomcode.java
  11. 4 5
      electricity/meter/src/main/java/com/gyee/gaia/meter/entity/MeterInfoCalculating.java
  12. 19 19
      electricity/meter/src/main/java/com/gyee/gaia/meter/util/AlarmScript.java
  13. 5 5
      electricity/meter/src/main/java/com/gyee/gaia/meter/util/TestScriptShell.java
  14. 11 0
      electricity/wind/README.md
  15. 50 0
      electricity/wind/build.gradle
  16. 21 0
      electricity/wind/src/main/java/com/gyee/gaia/WindPowergenApp.java
  17. 42 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/adapter/IAdapterApi.java
  18. 21 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/adapter/IShardingApi.java
  19. 27 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/config/AppConfig.java
  20. 75 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/config/ThreadPoolConfig.java
  21. 78 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/config/XxlJobConfig.java
  22. 377 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/entity/EquipPowerGenDay.java
  23. 91 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/entity/MeterInfoEquipment.java
  24. 68 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/init/CacheContext.java
  25. 16 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/iservice/IEquipPowerGenDayService.java
  26. 16 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/iservice/IMeterInfoEquipmentService.java
  27. 147 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/job/CalcEquipPowerGenDay.java
  28. 18 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/mapper/EquipPowerGenDayMapper.java
  29. 10 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/mapper/MeterInfoEquipmentMapper.java
  30. 20 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/serviceimpl/EquipPowerGenDayServiceImpl.java
  31. 12 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/serviceimpl/MeterInfoEquipmentServiceImpl.java
  32. 6 0
      electricity/wind/src/main/resources/banner.txt
  33. 105 0
      electricity/wind/src/main/resources/bootstrap.yaml
  34. 49 0
      electricity/wind/src/main/resources/log4j2.xml
  35. 40 0
      electricity/wind/src/test/java/com/gyee/gaia/MyAppTests.java
  36. 119 0
      electricity/wind/src/test/resources/bootstrap.yaml
  37. 1 0
      metrics/HELP.md
  38. 2 2
      metrics/src/main/java/com/gyee/gaia/metrics/cache/InfoCache.java
  39. 0 1
      metrics/src/main/java/com/gyee/gaia/metrics/dao/repsoitory/TsPointRepository.java
  40. 1 1
      metrics/src/main/java/com/gyee/gaia/metrics/services/BasicInformationService.java
  41. 11 0
      realtime/wind/README.md
  42. 53 0
      realtime/wind/build.gradle
  43. 21 0
      realtime/wind/src/main/java/com/gyee/gaia/WindRealtimeApp.java
  44. 27 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/adapter/IAdapterApi.java
  45. 21 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/adapter/IShardingApi.java
  46. 27 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/config/AppConfig.java
  47. 75 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/config/ThreadPoolConfig.java
  48. 78 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/config/XxlJobConfig.java
  49. 56 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/init/CacheContext.java
  50. 220 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/job/CauseJobHandler.java
  51. 41 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/service/impl/RealtimeAverageTargetServiceImpl.java
  52. 6 0
      realtime/wind/src/main/resources/banner.txt
  53. 116 0
      realtime/wind/src/main/resources/bootstrap.yaml
  54. 49 0
      realtime/wind/src/main/resources/log4j2.xml
  55. 45 0
      realtime/wind/src/test/java/com/gyee/gaia/MyAppTests.java
  56. 3 0
      settings.gradle
  57. 3 16
      state/cause/README.md
  58. 4 5
      state/cause/src/main/java/com/gyee/gaia/cause/adapter/AdapterApi.java
  59. 1 2
      state/cause/src/main/java/com/gyee/gaia/cause/adapter/ShardingApi.java
  60. 2 2
      state/cause/src/main/java/com/gyee/gaia/cause/config/AppConfig.java
  61. 1 0
      state/cause/src/main/java/com/gyee/gaia/cause/entity/EquipmentInfo.java
  62. 1 2
      state/cause/src/main/java/com/gyee/gaia/cause/entity/StateCause.java
  63. 11 11
      state/cause/src/main/java/com/gyee/gaia/init/CacheContext.java
  64. 3 10
      state/cause/src/main/java/com/gyee/gaia/cause/job/CauseJobHandler.java
  65. 99 96
      state/cause/src/main/java/com/gyee/gaia/cause/service/CalculateService.java
  66. 26 10
      state/cause/src/test/java/com/gyee/gaia/MyAppTests.java
  67. 7 0
      state/cause/src/test/java/com/gyee/gaia/MyTest.java
  68. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/config/AppConfig.java
  69. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/config/NacosConfig.java
  70. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/config/Status8Properties.java
  71. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/config/WindturbineGroup.java
  72. 3 3
      state/wind/src/main/java/com/gyee/gaia/wind/controller/ConfigController.java
  73. 2 2
      state/wind/src/main/java/com/gyee/gaia/wind/controller/NacosController.java
  74. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/entity/StationInfo.java
  75. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/entity/TagInfo.java
  76. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/entity/TestTb.java
  77. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/entity/WindturbineInfo.java
  78. 2 2
      state/wind/src/main/java/com/gyee/gaia/wind/restful/RestfulClient.java
  79. 2 2
      state/wind/src/main/java/com/gyee/gaia/wind/runner/ApplicationReadyEventListener.java
  80. 6 6
      state/wind/src/main/java/com/gyee/gaia/wind/service/CalculateServer.java
  81. 6 6
      state/wind/src/main/java/com/gyee/gaia/wind/service/Status8Service.java
  82. 3 3
      state/wind/src/main/resources/bootstrap.yaml
  83. 0 12
      state/wind/src/main/resources/mappers-postgresql/TestTb.xml
  84. 18 0
      timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/power/ModelPowerDetailsMapper.java
  85. 21 0
      timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/taos/RealtimeAverageTargetMapper.java
  86. 1 1
      timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/windturbine/BooststationMapper.java
  87. 1 1
      timeseries/dao-sql/build.gradle
  88. 1 1
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/Windturbine/BooststationServiceImpl.java
  89. 1 1
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/Windturbine/IBooststationService.java
  90. 16 0
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/power/IModelPowerDetailsService.java
  91. 19 0
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/power/ModelPowerDetailsServiceImpl.java
  92. 20 0
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/taos/IRealtimeAverageTargetService.java
  93. 2 1
      timeseries/data-adapter/src/main/resources/application-nx.yaml
  94. 1 0
      资源文件/sql/jsfw.realtime_average_target.txt
  95. 24 0
      资源文件/sql/taossql.sql

+ 1 - 1
.gitignore

@@ -50,4 +50,4 @@ build/
 !gradle/wrapper/gradle-wrapper.jar
 !**/src/main/**/build/
 !**/src/test/**/build/
-/electricity/meter/logs/
+/**/logs

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

@@ -75,7 +75,7 @@ public class FaultInfo implements Serializable {
     }
 
     public String getCategoryName() {
-        if(category1==null) return "未知";
+        if (category1 == null) return "未知";
         switch (category1) {
             case "FJ":
                 return "风机";

+ 1 - 1
state/cause/src/main/java/com/gyee/gaia/cause/entity/PointData.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.cause.entity;
+package com.gyee.gaia.common.data.point;
 
 /**
  * 测点数据

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

@@ -6,7 +6,7 @@ import java.io.Serializable;
 
 /**
  * <p>
- * 
+ *
  * </p>
  *
  * @author gfhd
@@ -200,24 +200,24 @@ public class TestingPoint implements Serializable {
     @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 +
-            ", rate = " + rate +
-        "}";
+                "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 +
+                "}";
     }
 }

+ 11 - 11
common/data/src/main/java/com/gyee/gaia/common/data/point/UniformCode.java

@@ -6,7 +6,7 @@ import java.io.Serializable;
 
 /**
  * <p>
- * 统一编码表			设备类型:风电/光伏	测点类型:遥测/遥信/计算	
+ * 统一编码表			设备类型:风电/光伏	测点类型:遥测/遥信/计算
  * </p>
  *
  * @author gfhd
@@ -137,15 +137,15 @@ public class UniformCode implements Serializable {
     @Override
     public String toString() {
         return "UniformCode{" +
-            "id = " + id +
-            ", nemCode = " + nemCode +
-            ", description = " + description +
-            ", equipmentType = " + equipmentType +
-            ", pointType = " + pointType +
-            ", spare1 = " + spare1 +
-            ", spare2 = " + spare2 +
-            ", spare3 = " + spare3 +
-            ", spare4 = " + spare4 +
-        "}";
+                "id = " + id +
+                ", nemCode = " + nemCode +
+                ", description = " + description +
+                ", equipmentType = " + equipmentType +
+                ", pointType = " + pointType +
+                ", spare1 = " + spare1 +
+                ", spare2 = " + spare2 +
+                ", spare3 = " + spare3 +
+                ", spare4 = " + spare4 +
+                "}";
     }
 }

+ 95 - 0
common/data/src/main/java/com/gyee/gaia/common/data/power/ModelPowerDetails.java

@@ -0,0 +1,95 @@
+package com.gyee.gaia.common.data.power;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-17
+ */
+@TableName("pro_basic_model_power_details")
+public class ModelPowerDetails implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 编号
+     */
+    private String id;
+
+    /**
+     * 型号编号
+     */
+    private String modelId;
+
+    /**
+     * 风速/光照度
+     */
+    private Double speed;
+
+    /**
+     * 稳态功率(相当于理论)
+     */
+    private Double theoryPower;
+
+    /**
+     * 动态功率(保证功率)
+     */
+    private Double ensurePower;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getModelId() {
+        return modelId;
+    }
+
+    public void setModelId(String modelId) {
+        this.modelId = modelId;
+    }
+
+    public Double getSpeed() {
+        return speed;
+    }
+
+    public void setSpeed(Double speed) {
+        this.speed = speed;
+    }
+
+    public Double getTheoryPower() {
+        return theoryPower;
+    }
+
+    public void setTheoryPower(Double theoryPower) {
+        this.theoryPower = theoryPower;
+    }
+
+    public Double getEnsurePower() {
+        return ensurePower;
+    }
+
+    public void setEnsurePower(Double ensurePower) {
+        this.ensurePower = ensurePower;
+    }
+
+    @Override
+    public String toString() {
+        return "ModelPowerDetails{" +
+                "id = " + id +
+                ", modelId = " + modelId +
+                ", speed = " + speed +
+                ", theoryPower = " + theoryPower +
+                ", ensurePower = " + ensurePower +
+                "}";
+    }
+}

+ 139 - 0
common/data/src/main/java/com/gyee/gaia/common/data/taos/RealtimeAverageTarget.java

@@ -0,0 +1,139 @@
+package com.gyee.gaia.common.data.taos;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-18
+ */
+@TableName("realtime_average_target")
+public class RealtimeAverageTarget implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private String tbname;
+
+    private Timestamp time;
+
+    private Double windSpeed;
+
+    private Double power;
+
+    private Double generatorSpeed;
+
+    private Double impellerSpeed;
+
+    private Double windDirection;
+
+    private String stationId;
+    private String equipmentId;
+    private String uniformCode;
+    private String description;
+
+    public String getTbname() {
+        return tbname;
+    }
+
+    public void setTbname(String tbname) {
+        this.tbname = tbname;
+    }
+
+    public Timestamp getTime() {
+        return time;
+    }
+
+    public void setTime(Timestamp time) {
+        this.time = time;
+    }
+
+    public String getEquipmentId() {
+        return equipmentId;
+    }
+
+    public void setEquipmentId(String equipmentId) {
+        this.equipmentId = equipmentId;
+    }
+
+    public Double getWindSpeed() {
+        return windSpeed;
+    }
+
+    public void setWindSpeed(Double windSpeed) {
+        this.windSpeed = windSpeed;
+    }
+
+    public Double getPower() {
+        return power;
+    }
+
+    public void setPower(Double power) {
+        this.power = power;
+    }
+
+    public Double getGeneratorSpeed() {
+        return generatorSpeed;
+    }
+
+    public void setGeneratorSpeed(Double generatorSpeed) {
+        this.generatorSpeed = generatorSpeed;
+    }
+
+    public Double getImpellerSpeed() {
+        return impellerSpeed;
+    }
+
+    public void setImpellerSpeed(Double impellerSpeed) {
+        this.impellerSpeed = impellerSpeed;
+    }
+
+    public Double getWindDirection() {
+        return windDirection;
+    }
+
+    public void setWindDirection(Double windDirection) {
+        this.windDirection = windDirection;
+    }
+
+    public String getStationId() {
+        return stationId;
+    }
+
+    public void setStationId(String stationId) {
+        this.stationId = stationId;
+    }
+
+    public String getUniformCode() {
+        return uniformCode;
+    }
+
+    public void setUniformCode(String uniformCode) {
+        this.uniformCode = uniformCode;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public String toString() {
+        return "RealtimeAverageTarget{" +
+                "time = " + time +
+                ", equipmentId = " + equipmentId +
+                ", windSpeed = " + windSpeed +
+                ", generatorSpeed = " + generatorSpeed +
+                ", impellerSpeed = " + impellerSpeed +
+                ", windDirection = " + windDirection +
+                "}";
+    }
+}

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

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

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

@@ -6,7 +6,7 @@ import java.io.Serializable;
 
 /**
  * <p>
- * 
+ *
  * </p>
  *
  * @author gfhd
@@ -150,19 +150,19 @@ public class Booststation implements Serializable {
     @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 +
-        "}";
+                "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 +
+                "}";
     }
 }

+ 1 - 1
electricity/meter/src/main/java/com/gyee/gaia/meter/entity/MeterInfoBottomcode.java

@@ -85,7 +85,7 @@ public class MeterInfoBottomcode extends Model<MeterInfoBottomcode> implements S
     private String remark;
 
     /**
-     *场站
+     * 场站
      */
     private String windpowerstationId;
 

+ 4 - 5
electricity/meter/src/main/java/com/gyee/gaia/meter/entity/MeterInfoCalculating.java

@@ -12,7 +12,7 @@ import java.time.LocalDateTime;
 
 /**
  * <p>
- * 计算日电量
+ * 线路日发电量表
  * </p>
  */
 @TableName("pro_meter_calculating")
@@ -28,12 +28,12 @@ public class MeterInfoCalculating extends Model<MeterInfoCalculating> implements
     private Integer id;
 
     /**
-     * 场站id
+     * 线路编码;线路编码
      */
     private String windpowerstationId;
 
     /**
-     * 名称
+     * 线路名称;线路名称
      */
     private String name;
 
@@ -43,7 +43,6 @@ public class MeterInfoCalculating extends Model<MeterInfoCalculating> implements
     private LocalDateTime date;
 
 
-
     /**
      * 日发电量;日发电量,单位kwh
      */
@@ -75,7 +74,7 @@ public class MeterInfoCalculating extends Model<MeterInfoCalculating> implements
     private String remark;
 
     /**
-     * 计算点code
+     * 计算点凑得
      */
     private String code;
 

+ 19 - 19
electricity/meter/src/main/java/com/gyee/gaia/meter/util/AlarmScript.java

@@ -17,23 +17,23 @@ public class AlarmScript extends Script {
      * 数据有变化就报警
      * @return
      */
-//    public boolean IsChanged() {
-//        long entityId = (long)getBinding().getVariable(ScriptShell.entityIdName);
-//        String variable = (String)getBinding().getVariable(ScriptShell.variableName);
-//        TsData currentData = (TsData)getBinding().getVariable(ScriptShell.tsDataName);
-//        TsData preData = ScriptShell.getPreTsData(entityId,variable);
-//        if (preData == null) {
-//            return  true;   //如果没有前值,直接触发报警?
-//        }
-//        if (preData.getTs() >= currentData.getTs()) {
-//            return false;   //过期的数据,不触发报警
-//        }
-//        if (preData.getValue().equals(currentData.getValue())) {
-//            return false;
-//        } else {
-//            return true;    //当前值与前值不一样,触发报警
-//        }
-//
-//    }
-//
+    //    public boolean IsChanged() {
+    //        long entityId = (long)getBinding().getVariable(ScriptShell.entityIdName);
+    //        String variable = (String)getBinding().getVariable(ScriptShell.variableName);
+    //        TsData currentData = (TsData)getBinding().getVariable(ScriptShell.tsDataName);
+    //        TsData preData = ScriptShell.getPreTsData(entityId,variable);
+    //        if (preData == null) {
+    //            return  true;   //如果没有前值,直接触发报警?
+    //        }
+    //        if (preData.getTs() >= currentData.getTs()) {
+    //            return false;   //过期的数据,不触发报警
+    //        }
+    //        if (preData.getValue().equals(currentData.getValue())) {
+    //            return false;
+    //        } else {
+    //            return true;    //当前值与前值不一样,触发报警
+    //        }
+    //
+    //    }
+    //
 }

+ 5 - 5
electricity/meter/src/main/java/com/gyee/gaia/meter/util/TestScriptShell.java

@@ -1,5 +1,6 @@
 package com.gyee.gaia.meter.util;
 
+import com.gyee.gaia.meter.entity.MeterPoint;
 import groovy.lang.Binding;
 import groovy.lang.GroovyShell;
 import groovy.lang.Script;
@@ -8,7 +9,6 @@ import org.codehaus.groovy.control.CompilerConfiguration;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import com.gyee.gaia.meter.entity.MeterPoint;
 
 public class TestScriptShell {
 
@@ -83,13 +83,13 @@ public class TestScriptShell {
         row.put("ai2", 2.1);
         row.put("di1", false);
 
-//        DoubleTsData tsd = new DoubleTsData(1,(short)1,335.98);
-//        row.put("AI128", tsd);
+        //        DoubleTsData tsd = new DoubleTsData(1,(short)1,335.98);
+        //        row.put("AI128", tsd);
 
         //double a = Math.max()
 
-//        Object obj = parseExpr("AI128",row);
-//        System.out.println(obj);
+        //        Object obj = parseExpr("AI128",row);
+        //        System.out.println(obj);
         Object obj1 = parseExpr("Math.max(ai1, ai2)", row);
         System.out.println(obj1);
         Object obj2 = parseExpr("ai1 > ai2 && di1", row);

+ 11 - 0
electricity/wind/README.md

@@ -0,0 +1,11 @@
+### cause 分析原因,故障损失,计划检修损失,受累损失,限电损失,性能损失等
+
+状态为: 并网--是否限电--风速小于11并且桨叶角度大于2;风速大于11并且有功功率小于满发功率减100 待机-- 是否限停-- 有故障--故障 无故障--有功设定小于出线功率;有功设定小于应发的85% 并且
+出线功率大于有功设定94%;有功设定小于应发的70% 并且 出线功率大于有功设定80% 并且 当前场站限电台数大于等于3--限停 待机 维护-- 有故障--故障 无故障--计划检修 故障--小于?(3)分钟故障忽略
+是否受累--全站故障或者离线 故障 离线-- 是否受累--全站故障或者离线 故障
+
+青山华创风机在停机的状态下应该算故障损失
+
+
+
+

+ 50 - 0
electricity/wind/build.gradle

@@ -0,0 +1,50 @@
+buildscript {
+    repositories {
+        mavenLocal()
+        maven {
+            allowInsecureProtocol = true
+            url "http://maven.aliyun.com/nexus/content/groups/public"
+        }
+        mavenCentral()
+    }
+    dependencies {
+        classpath("$bootGroup:spring-boot-gradle-plugin:$springBootVersion")
+    }
+}
+
+apply plugin: "$bootGroup"
+apply plugin: 'io.spring.dependency-management'
+
+dependencyManagement {
+    imports {
+        mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
+        mavenBom "org.springframework.boot:spring-boot-dependencies:$springBootVersion"
+        mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:$springCloudAlibabaVersion"
+    }
+}
+
+dependencies {
+    implementation project(":timeseries:dao-sql")
+
+    implementation("$bootGroup:spring-boot-starter-web")
+    implementation("$bootGroup:spring-boot-starter-undertow")
+
+
+    implementation("org.postgresql:postgresql:$postgresqlDriverVersion")
+    implementation "com.baomidou:mybatis-plus-boot-starter:$mybatisPlusVersion"
+    implementation("com.alibaba:druid:$alibabaDruidVersion")
+    implementation("com.alibaba:fastjson:$fastjsonVersion")
+
+    implementation("$bootGroup:spring-boot-starter-test")
+    implementation("com.xuxueli:xxl-job-core:$xxlJobVersion")
+    implementation("org.springframework.cloud:spring-cloud-starter-bootstrap")
+    implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery")
+    implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config")
+
+    implementation("$cloudGroup:spring-cloud-starter-openfeign")
+    implementation("cn.hutool:hutool-all:5.8.18")
+}
+
+test {
+    useJUnitPlatform()
+}

+ 21 - 0
electricity/wind/src/main/java/com/gyee/gaia/WindPowergenApp.java

@@ -0,0 +1,21 @@
+package com.gyee.gaia;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+
+@SpringBootApplication
+@EnableDiscoveryClient
+@EnableFeignClients
+public class WindPowergenApp {
+
+    public static void main(String[] args) {
+
+        SpringApplication.run(WindPowergenApp.class, args);
+
+    }
+}
+
+

+ 42 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/adapter/IAdapterApi.java

@@ -0,0 +1,42 @@
+package com.gyee.gaia.electricity.wind.adapter;
+
+import com.gyee.gaia.common.data.point.PointData;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+import java.util.Map;
+
+@FeignClient(name = "adapter", url = "${meter.adapter-url}")
+public interface IAdapterApi {
+
+    @GetMapping("/ts/latest")
+    Map<String, PointData> getHistoryLatest(
+            @RequestParam(value = "keys", required = false) String keyStr
+    );
+
+    //获取一个或多个测点,指定时间的数据(没有则返回前一个时间点的数据)
+    @GetMapping("/ts/history/section")
+    Map<String, PointData> getHistorySection(
+            @RequestParam(value = "tagNames", required = false) String tagNames,
+            @RequestParam(value = "ts", required = false) Long ts
+    );
+
+    //获取一个测点指定时间段内的数据(可以设置间隔时间单位S)
+    @GetMapping("/ts/history/snap")
+    List<PointData> getHistorySnap(
+            @RequestParam(value = "tagName", required = false) String tagName,
+            @RequestParam(value = "startTs", required = false) Long startTs,
+            @RequestParam(value = "endTs", required = false) Long endTs,
+            @RequestParam(value = "interval", required = false) Integer interval
+    );
+
+    //获取一个测点指定时间段内的数据
+    @GetMapping("/ts/history/raw")
+    List<PointData> getHistoryRaw(
+            @RequestParam(value = "tagName", required = false) String tagName,
+            @RequestParam(value = "startTs", required = false) Long startTs,
+            @RequestParam(value = "endTs", required = false) Long endTs
+    );
+}

+ 21 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/adapter/IShardingApi.java

@@ -0,0 +1,21 @@
+package com.gyee.gaia.electricity.wind.adapter;
+
+import com.gyee.gaia.common.data.alarm.FaultInfo;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+import java.util.List;
+
+@FeignClient(name = "sharding", url = "${meter.sharding-url}")
+public interface IShardingApi {
+
+    @GetMapping("/fault/history/list?category1={category1}&pagenum=1&pagesize=1000&stationid={stationid}&starttime={starttime}&endtime={endtime}&messagetype={messagetype}&keyword={keyword}")
+    List<FaultInfo> getFaultInfoList(
+            @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") Integer messagetype);
+}

+ 27 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/config/AppConfig.java

@@ -0,0 +1,27 @@
+package com.gyee.gaia.electricity.wind.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+
+@Data
+@Component
+@ConfigurationProperties("meter")
+public class AppConfig {
+
+    //场站范围
+    private String stations;
+    /**
+     * 统一编码名,统一编码
+     */
+    private Map<String, String> uniformcode;
+
+    @Override
+    public String toString() {
+        return "stations = " + stations;
+    }
+
+}

+ 75 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/config/ThreadPoolConfig.java

@@ -0,0 +1,75 @@
+package com.gyee.gaia.electricity.wind.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.ThreadPoolExecutor;
+
+/**
+ * 线程池配置
+ *
+ * @author xysn
+ */
+@Configuration
+public class ThreadPoolConfig {
+
+    /**
+     *   默认情况下,在创建了线程池后,线程池中的线程数为0,当有任务来之后,就会创建一个线程去执行任务,
+     *	当线程池中的线程数目达到corePoolSize后,就会把到达的任务放到缓存队列当中;
+     *  当队列满了,就继续创建线程,当线程数量大于等于maxPoolSize后,开始使用拒绝策略拒绝
+     */
+
+    /**
+     * 核心线程数(默认线程数)
+     */
+    private static final int corePoolSize = 40;
+    /**
+     * 最大线程数
+     */
+    private static final int maxPoolSize = 100;
+    /**
+     * 允许线程空闲时间(单位:默认为秒)
+     */
+    private static final int keepAliveTime = 60;
+    /**
+     * 缓冲队列大小
+     */
+    private static final int queueCapacity = 300;
+    /**
+     * 允许等待最长时间
+     */
+    private static final int awaitTime = 15;
+    /**
+     * 线程池名前缀
+     */
+    private static final String threadNamePrefix = "Alarm-Thread-";
+
+    private ThreadPoolTaskExecutor executor;
+
+    public ThreadPoolTaskExecutor getExecutor() {
+        if (executor == null) {
+            executor = taskExecutor();
+        }
+
+        return executor;
+    }
+
+    @Bean
+    public ThreadPoolTaskExecutor taskExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(corePoolSize);
+        executor.setMaxPoolSize(maxPoolSize);
+        executor.setQueueCapacity(queueCapacity);
+        executor.setKeepAliveSeconds(keepAliveTime);
+        executor.setThreadNamePrefix(threadNamePrefix);
+        executor.setAwaitTerminationSeconds(awaitTime);
+
+        // 线程池对拒绝任务的处理策略
+        // CallerRunsPolicy:由调用线程(提交任务的线程)处理该任务
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        // 初始化
+        executor.initialize();
+        return executor;
+    }
+}

+ 78 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/config/XxlJobConfig.java

@@ -0,0 +1,78 @@
+package com.gyee.gaia.electricity.wind.config;
+
+import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * xxl-job config
+ *
+ * @author xuxueli 2017-04-28
+ */
+@Configuration
+public class XxlJobConfig {
+    private Logger logger = LoggerFactory.getLogger(com.gyee.gaia.electricity.wind.config.XxlJobConfig.class);
+
+    @Value("${xxl.job.admin.addresses}")
+    private String adminAddresses;
+
+    @Value("${xxl.job.accessToken}")
+    private String accessToken;
+
+    @Value("${xxl.job.executor.appname}")
+    private String appname;
+
+    @Value("${xxl.job.executor.address}")
+    private String address;
+
+    @Value("${xxl.job.executor.ip}")
+    private String ip;
+
+    @Value("${xxl.job.executor.port}")
+    private int port;
+
+    @Value("${xxl.job.executor.logpath}")
+    private String logPath;
+
+    @Value("${xxl.job.executor.logretentiondays}")
+    private int logRetentionDays;
+
+
+    @Bean
+    public XxlJobSpringExecutor xxlJobExecutor() {
+        logger.info(">>>>>>>>>>> xxl-job config init.");
+        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
+        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
+        xxlJobSpringExecutor.setAppname(appname);
+        //xxlJobSpringExecutor.se(address);
+        xxlJobSpringExecutor.setIp(ip);
+        xxlJobSpringExecutor.setPort(port);
+        xxlJobSpringExecutor.setAccessToken(accessToken);
+        xxlJobSpringExecutor.setLogPath(logPath);
+        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
+
+        return xxlJobSpringExecutor;
+    }
+
+    /**
+     * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
+     *
+     *      1、引入依赖:
+     *          <dependency>
+     *             <groupId>org.springframework.cloud</groupId>
+     *             <artifactId>spring-cloud-commons</artifactId>
+     *             <version>${version}</version>
+     *         </dependency>
+     *
+     *      2、配置文件,或者容器启动变量
+     *          spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
+     *
+     *      3、获取IP
+     *          String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
+     */
+
+
+}

+ 377 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/entity/EquipPowerGenDay.java

@@ -0,0 +1,377 @@
+package com.gyee.gaia.electricity.wind.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-18
+ */
+@TableName("equip_power_gen_day")
+public class EquipPowerGenDay implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 时间
+     */
+    private LocalDate date;
+
+    /**
+     * 场站
+     */
+    private String station;
+
+    /**
+     * 类型
+     */
+    private String category;
+
+    /**
+     * 设备
+     */
+    private String facilityId;
+
+    /**
+     * 统一编码
+     */
+    private String uniformCode;
+
+    /**
+     * 发电量
+     */
+    private BigDecimal generatingCapacity;
+
+    /**
+     * 理论发电量
+     */
+    private BigDecimal theoryGeneration;
+
+    /**
+     * 损失发电量
+     */
+    private BigDecimal lossPower;
+
+    /**
+     * 故障损失电量
+     */
+    private BigDecimal faultLossPower;
+
+    /**
+     * 计划检修损失电量
+     */
+    private BigDecimal maintainLossPower;
+
+    /**
+     * 受累损失电量
+     */
+    private BigDecimal implicateLossPower;
+
+    /**
+     * 限电损失电量
+     */
+    private BigDecimal limitLossPower;
+
+    /**
+     * 性能损失电量
+     */
+    private BigDecimal performanceLossPower;
+
+    /**
+     * 停机时间
+     */
+    private Integer stopTime;
+
+    /**
+     * 启动时间
+     */
+    private Integer startTime;
+
+    /**
+     * 待机时间
+     */
+    private Integer standbyTime;
+
+    /**
+     * 并网时间
+     */
+    private Integer runTime;
+
+    /**
+     * 故障状态时间
+     */
+    private Integer faultStateTime;
+
+    /**
+     * 维护时间
+     */
+    private Integer maintainTime;
+
+    /**
+     * 离线时间
+     */
+    private Integer interruptTime;
+
+    /**
+     * 故障时间
+     */
+    private Integer faultTime;
+
+    /**
+     * 计划检修时间
+     */
+    private Integer planMaintenanceTime;
+
+    /**
+     * 受累时间
+     */
+    private Integer implicateTime;
+
+    /**
+     * 限电时间
+     */
+    private Integer limitTime;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public LocalDate getDate() {
+        return date;
+    }
+
+    public void setDate(LocalDate date) {
+        this.date = date;
+    }
+
+    public String getStation() {
+        return station;
+    }
+
+    public void setStation(String station) {
+        this.station = station;
+    }
+
+    public String getCategory() {
+        return category;
+    }
+
+    public void setCategory(String category) {
+        this.category = category;
+    }
+
+    public String getFacilityId() {
+        return facilityId;
+    }
+
+    public void setFacilityId(String facilityId) {
+        this.facilityId = facilityId;
+    }
+
+    public String getUniformCode() {
+        return uniformCode;
+    }
+
+    public void setUniformCode(String uniformCode) {
+        this.uniformCode = uniformCode;
+    }
+
+    public BigDecimal getGeneratingCapacity() {
+        return generatingCapacity;
+    }
+
+    public void setGeneratingCapacity(BigDecimal generatingCapacity) {
+        this.generatingCapacity = generatingCapacity;
+    }
+
+    public BigDecimal getTheoryGeneration() {
+        return theoryGeneration;
+    }
+
+    public void setTheoryGeneration(BigDecimal theoryGeneration) {
+        this.theoryGeneration = theoryGeneration;
+    }
+
+    public BigDecimal getLossPower() {
+        return lossPower;
+    }
+
+    public void setLossPower(BigDecimal lossPower) {
+        this.lossPower = lossPower;
+    }
+
+    public BigDecimal getFaultLossPower() {
+        return faultLossPower;
+    }
+
+    public void setFaultLossPower(BigDecimal faultLossPower) {
+        this.faultLossPower = faultLossPower;
+    }
+
+    public BigDecimal getMaintainLossPower() {
+        return maintainLossPower;
+    }
+
+    public void setMaintainLossPower(BigDecimal maintainLossPower) {
+        this.maintainLossPower = maintainLossPower;
+    }
+
+    public BigDecimal getImplicateLossPower() {
+        return implicateLossPower;
+    }
+
+    public void setImplicateLossPower(BigDecimal implicateLossPower) {
+        this.implicateLossPower = implicateLossPower;
+    }
+
+    public BigDecimal getLimitLossPower() {
+        return limitLossPower;
+    }
+
+    public void setLimitLossPower(BigDecimal limitLossPower) {
+        this.limitLossPower = limitLossPower;
+    }
+
+    public BigDecimal getPerformanceLossPower() {
+        return performanceLossPower;
+    }
+
+    public void setPerformanceLossPower(BigDecimal performanceLossPower) {
+        this.performanceLossPower = performanceLossPower;
+    }
+
+    public Integer getStopTime() {
+        return stopTime;
+    }
+
+    public void setStopTime(Integer stopTime) {
+        this.stopTime = stopTime;
+    }
+
+    public Integer getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Integer startTime) {
+        this.startTime = startTime;
+    }
+
+    public Integer getStandbyTime() {
+        return standbyTime;
+    }
+
+    public void setStandbyTime(Integer standbyTime) {
+        this.standbyTime = standbyTime;
+    }
+
+    public Integer getRunTime() {
+        return runTime;
+    }
+
+    public void setRunTime(Integer runTime) {
+        this.runTime = runTime;
+    }
+
+    public Integer getFaultStateTime() {
+        return faultStateTime;
+    }
+
+    public void setFaultStateTime(Integer faultStateTime) {
+        this.faultStateTime = faultStateTime;
+    }
+
+    public Integer getMaintainTime() {
+        return maintainTime;
+    }
+
+    public void setMaintainTime(Integer maintainTime) {
+        this.maintainTime = maintainTime;
+    }
+
+    public Integer getInterruptTime() {
+        return interruptTime;
+    }
+
+    public void setInterruptTime(Integer interruptTime) {
+        this.interruptTime = interruptTime;
+    }
+
+    public Integer getFaultTime() {
+        return faultTime;
+    }
+
+    public void setFaultTime(Integer faultTime) {
+        this.faultTime = faultTime;
+    }
+
+    public Integer getPlanMaintenanceTime() {
+        return planMaintenanceTime;
+    }
+
+    public void setPlanMaintenanceTime(Integer planMaintenanceTime) {
+        this.planMaintenanceTime = planMaintenanceTime;
+    }
+
+    public Integer getImplicateTime() {
+        return implicateTime;
+    }
+
+    public void setImplicateTime(Integer implicateTime) {
+        this.implicateTime = implicateTime;
+    }
+
+    public Integer getLimitTime() {
+        return limitTime;
+    }
+
+    public void setLimitTime(Integer limitTime) {
+        this.limitTime = limitTime;
+    }
+
+    @Override
+    public String toString() {
+        return "EquipPowerGenDay{" +
+                "id = " + id +
+                ", date = " + date +
+                ", station = " + station +
+                ", category = " + category +
+                ", facilityId = " + facilityId +
+                ", uniformCode = " + uniformCode +
+                ", generatingCapacity = " + generatingCapacity +
+                ", theoryGeneration = " + theoryGeneration +
+                ", lossPower = " + lossPower +
+                ", faultLossPower = " + faultLossPower +
+                ", maintainLossPower = " + maintainLossPower +
+                ", implicateLossPower = " + implicateLossPower +
+                ", limitLossPower = " + limitLossPower +
+                ", performanceLossPower = " + performanceLossPower +
+                ", stopTime = " + stopTime +
+                ", startTime = " + startTime +
+                ", standbyTime = " + standbyTime +
+                ", runTime = " + runTime +
+                ", faultStateTime = " + faultStateTime +
+                ", maintainTime = " + maintainTime +
+                ", interruptTime = " + interruptTime +
+                ", faultTime = " + faultTime +
+                ", planMaintenanceTime = " + planMaintenanceTime +
+                ", implicateTime = " + implicateTime +
+                ", limitTime = " + limitTime +
+                "}";
+    }
+}

+ 91 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/entity/MeterInfoEquipment.java

@@ -0,0 +1,91 @@
+package com.gyee.gaia.electricity.wind.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ * 风机日发电量表
+ * </p>
+ */
+@TableName("pro_meter_equipment")
+@Data
+public class MeterInfoEquipment extends Model<MeterInfoEquipment> implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键;主键自增
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+
+    /**
+     * 场站编码;场站编码
+     */
+    private String powerstationNemCode;
+
+    /**
+     * 项目期次编码;项目期次编码
+     */
+    private String projectNemCode;
+
+    /**
+     * 线路编码;线路编码
+     */
+    private String lineNemCode;
+
+    /**
+     * 风机编码;风机编码
+     */
+    private String equipmentNemCode;
+
+    /**
+     * 线路名称;分机名称
+     */
+    private String name;
+
+    /**
+     * 日期;日期
+     */
+    private LocalDateTime date;
+
+    /**
+     * 日发电量;日发电量,单位kwh
+     */
+    private BigDecimal rfdl;
+
+    /**
+     * 创建人;创建人
+     */
+    private String createBy;
+
+    /**
+     * 创建时间;创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新人;更新人
+     */
+    private String updateBy;
+
+    /**
+     * 更新时间;更新时间
+     */
+    private LocalDateTime updateTime;
+
+    /**
+     * 备注;备注
+     */
+    private String remark;
+
+}

+ 68 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/init/CacheContext.java

@@ -0,0 +1,68 @@
+package com.gyee.gaia.electricity.wind.init;
+
+import com.gyee.gaia.common.data.power.ModelPowerDetails;
+import com.gyee.gaia.common.data.windturbine.Equipment;
+import com.gyee.gaia.common.data.windturbine.Powerstation;
+import com.gyee.gaia.dao.sql.Windturbine.IEquipmentService;
+import com.gyee.gaia.dao.sql.Windturbine.IPowerstationService;
+import com.gyee.gaia.dao.sql.power.IModelPowerDetailsService;
+import com.gyee.gaia.electricity.wind.job.CalcEquipPowerGenDay;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Order(1)
+@Slf4j
+@Component
+public class CacheContext implements ApplicationRunner {
+
+    @Resource
+    private IModelPowerDetailsService modelPowerDetailsService;
+    @Resource
+    private IEquipmentService equipmentService;
+    @Resource
+    private IPowerstationService powerstationService;
+    @Resource
+    private CalcEquipPowerGenDay calcEquipPowerGenDay;
+
+    public static Map<String, Map<Double, Double>> modelPowerMap;
+    /**
+     * 风机号,Equipment
+     */
+    public static Map<String, Equipment> equipMap;
+    /**
+     * 场站id,Powerstation
+     */
+    public static Map<String, Powerstation> stationMap;
+    /**
+     * 风场,风机
+     */
+    public static Map<String, List<Equipment>> stationEquipMap;
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+
+        log.info("加载风速功率!");
+        List<ModelPowerDetails> mpList = modelPowerDetailsService.list();
+        modelPowerMap = mpList.stream().collect(Collectors.groupingBy(ModelPowerDetails::getModelId, Collectors.toMap(ModelPowerDetails::getSpeed, ModelPowerDetails::getTheoryPower)));
+
+        log.info("加载风机!");
+        List<Equipment> emList = equipmentService.list();
+        equipMap = emList.stream().collect(Collectors.toMap(Equipment::getId, Function.identity()));
+        stationEquipMap = emList.stream().collect(Collectors.groupingBy(Equipment::getWindpowerstationId));
+
+        log.info("加载风场信息!");
+        List<Powerstation> stationList = powerstationService.list();
+        stationMap = stationList.stream().collect(Collectors.toMap(Powerstation::getId, Function.identity()));
+
+        calcEquipPowerGenDay.calcEquipPowerGenDay();
+    }
+}

+ 16 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/iservice/IEquipPowerGenDayService.java

@@ -0,0 +1,16 @@
+package com.gyee.gaia.electricity.wind.iservice;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.gaia.electricity.wind.entity.EquipPowerGenDay;
+
+/**
+ * <p>
+ * 服务类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-17
+ */
+public interface IEquipPowerGenDayService extends IService<EquipPowerGenDay> {
+
+}

+ 16 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/iservice/IMeterInfoEquipmentService.java

@@ -0,0 +1,16 @@
+package com.gyee.gaia.electricity.wind.iservice;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.gaia.electricity.wind.entity.MeterInfoEquipment;
+
+/**
+ * <p>
+ * 风机日发电量表 服务类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-04-28
+ */
+public interface IMeterInfoEquipmentService extends IService<MeterInfoEquipment> {
+
+}

+ 147 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/job/CalcEquipPowerGenDay.java

@@ -0,0 +1,147 @@
+package com.gyee.gaia.electricity.wind.job;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.gaia.common.data.point.PointData;
+import com.gyee.gaia.common.data.point.TestingPoint;
+import com.gyee.gaia.common.data.windturbine.Equipment;
+import com.gyee.gaia.dao.sql.Windturbine.IEquipmentService;
+import com.gyee.gaia.dao.sql.point.ITestingPointService;
+import com.gyee.gaia.electricity.wind.adapter.IAdapterApi;
+import com.gyee.gaia.electricity.wind.config.AppConfig;
+import com.gyee.gaia.electricity.wind.entity.EquipPowerGenDay;
+import com.gyee.gaia.electricity.wind.iservice.IEquipPowerGenDayService;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+public class CalcEquipPowerGenDay {
+
+    @Resource
+    private IAdapterApi adapter;
+    @Resource
+    private ITestingPointService testingPointService;
+    @Resource
+    private IEquipmentService equipmentService;
+    @Resource
+    private IEquipPowerGenDayService equipPowerGenDayService;
+    @Resource
+    private AppConfig appConfig;
+
+    @XxlJob("CalcEquipPowerGenDay")
+    public void calcEquipPowerGenDay() {
+
+        //2,获取当前日期,当日开始时间
+        DateTime startDateTime = DateUtil.beginOfDay(DateUtil.yesterday());
+        DateTime endDateTime = DateUtil.beginOfDay(DateUtil.date());
+
+        calcGeneratingCapacity(startDateTime, endDateTime);
+        calcTheoryGeneration(startDateTime, endDateTime);
+
+    }
+
+    private void calcTheoryGeneration(DateTime time1, DateTime time2) {
+        String speedUc = appConfig.getUniformcode().get("speed");
+        QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
+        tpWrapper.eq("thing_type", "windturbine").eq("uniform_code", speedUc);
+        List<TestingPoint> list = testingPointService.list(tpWrapper);
+        for (TestingPoint point : list) {
+            List<PointData> historyRaw = adapter.getHistoryRaw(point.getCode(), time1.getTime(), time2.getTime());
+
+        }
+
+    }
+
+    /**
+     * 计算日发电量
+     */
+    private List<EquipPowerGenDay> calcGeneratingCapacity(DateTime time1, DateTime time2) {
+
+        //开始时间00:00:01
+        DateTime dateTime1 = DateUtil.offsetSecond(time1, 1);
+        //结束时间第二天00:00:01
+        DateTime dateTime2 = DateUtil.offsetSecond(time2, 1);
+
+        List<EquipPowerGenDay> epgdList = new ArrayList<>();
+
+        //1,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
+        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").eq("thing_type", "windturbine"));
+        //2,遍历list,每次取出一个code
+        for (TestingPoint testingPoint : testingPointList) {
+            //获取测点code
+            String pointcode = testingPoint.getCode();
+            //获取设备ID
+            String thingId = testingPoint.getThingId();
+
+            //8,通过适配器拿到一天的发电量数据,
+            List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, dateTime1.getTime(), dateTime2.getTime());
+
+            //定义日发电量,先给0
+            BigDecimal rfdl = new BigDecimal(0);
+
+            //如果适配器拿到数据,计算日发电量
+            if (historyRaw.size() > 0) {
+                BigDecimal bigDecimal1 = new BigDecimal(Double.toString(historyRaw.get(0).getValue()));
+                BigDecimal bigDecimal2 = new BigDecimal(Double.toString(historyRaw.get(historyRaw.size() - 1).getValue()));
+                rfdl = bigDecimal2.subtract(bigDecimal1);
+
+                //如果日发电量大于50000千瓦时或者小于0,说明数据异常进行处理
+                if (rfdl.doubleValue() > 50000 || rfdl.doubleValue() < 0) {
+
+                    //数据集合放所有数据
+                    ArrayList<Double> arrayList = new ArrayList<>();
+                    for (PointData pointData : historyRaw) {
+                        arrayList.add(pointData.getValue());
+                    }
+
+                    //定义突变值索引
+                    int index = -1;
+                    //定于阈值
+                    double threshold = 50000;
+                    //遍历数组集合,拿出当前数和前值相减得到变化值
+                    for (int j = 1; j < arrayList.size(); j++) {
+                        double difference = arrayList.get(j) - arrayList.get(j - 1);
+                        //如果变化值difference大于阈值或者小于0,返回当前突变数据的索引
+                        if (difference > threshold || difference < 0) {
+                            index = j;
+                            break;
+                        }
+                    }
+
+                    //如果突变值索引不等于-1,进行数据处理
+                    if (index != -1) {
+                        //拿到突变数据
+                        double valueGrow2 = arrayList.get(index);
+                        BigDecimal bigDecimalGrow2 = new BigDecimal(Double.toString(valueGrow2));
+                        //拿到突变的前一个数据
+                        double valueGrow1 = arrayList.get(index - 1);
+                        BigDecimal bigDecimalGrow1 = new BigDecimal(Double.toString(valueGrow1));
+                        //计算日发电量(结束值-突变值)+(突变值前值-开始值)
+                        rfdl = (bigDecimal2.subtract(bigDecimalGrow2).add(bigDecimalGrow1).subtract(bigDecimal1));
+                    }
+                }
+            }
+
+            Equipment thingId1 = equipmentService.getOne(new QueryWrapper<Equipment>().eq("nem_code", thingId));
+
+            EquipPowerGenDay epgd = new EquipPowerGenDay();
+            epgd.setDate(time1.toLocalDateTime().toLocalDate());
+            epgd.setStation(testingPoint.getStationId());
+            epgd.setCategory(testingPoint.getThingType());
+            epgd.setGeneratingCapacity(rfdl);
+            epgdList.add(epgd);
+        }
+        return epgdList;
+    }
+
+
+}
+
+
+

+ 18 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/mapper/EquipPowerGenDayMapper.java

@@ -0,0 +1,18 @@
+package com.gyee.gaia.electricity.wind.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.gaia.electricity.wind.entity.EquipPowerGenDay;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ * Mapper 接口
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-17
+ */
+@Mapper
+public interface EquipPowerGenDayMapper extends BaseMapper<EquipPowerGenDay> {
+
+}

+ 10 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/mapper/MeterInfoEquipmentMapper.java

@@ -0,0 +1,10 @@
+package com.gyee.gaia.electricity.wind.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.gaia.electricity.wind.entity.MeterInfoEquipment;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface MeterInfoEquipmentMapper extends BaseMapper<MeterInfoEquipment> {
+
+}

+ 20 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/serviceimpl/EquipPowerGenDayServiceImpl.java

@@ -0,0 +1,20 @@
+package com.gyee.gaia.electricity.wind.serviceimpl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.gaia.electricity.wind.entity.EquipPowerGenDay;
+import com.gyee.gaia.electricity.wind.iservice.IEquipPowerGenDayService;
+import com.gyee.gaia.electricity.wind.mapper.EquipPowerGenDayMapper;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-17
+ */
+@Service
+public class EquipPowerGenDayServiceImpl extends ServiceImpl<EquipPowerGenDayMapper, EquipPowerGenDay> implements IEquipPowerGenDayService {
+
+}

+ 12 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/serviceimpl/MeterInfoEquipmentServiceImpl.java

@@ -0,0 +1,12 @@
+package com.gyee.gaia.electricity.wind.serviceimpl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.gaia.electricity.wind.entity.MeterInfoEquipment;
+import com.gyee.gaia.electricity.wind.iservice.IMeterInfoEquipmentService;
+import com.gyee.gaia.electricity.wind.mapper.MeterInfoEquipmentMapper;
+import org.springframework.stereotype.Service;
+
+@Service
+public class MeterInfoEquipmentServiceImpl extends ServiceImpl<MeterInfoEquipmentMapper, MeterInfoEquipment> implements IMeterInfoEquipmentService {
+
+}

+ 6 - 0
electricity/wind/src/main/resources/banner.txt

@@ -0,0 +1,6 @@
+ ####  #####   ##   ##### ######        ####    ##   #    #  ####  ###### 
+#        #    #  #    #   #            #    #  #  #  #    # #      #      
+ ####    #   #    #   #   #####  ##### #      #    # #    #  ####  #####  
+     #   #   ######   #   #            #      ###### #    #      # #      
+#    #   #   #    #   #   #            #    # #    # #    # #    # #      
+ ####    #   #    #   #   ######        ####  #    #  ####   ####  ###### 

+ 105 - 0
electricity/wind/src/main/resources/bootstrap.yaml

@@ -0,0 +1,105 @@
+server:
+  port: 8022
+
+spring:
+  application:
+    name: state-cause
+  profiles:
+    # 环境配置
+    active: nx
+  cloud:
+    nacos:
+      discovery:
+        # 服务注册地址
+        server-addr: 192.168.10.18:8848
+      config:
+        # 配置中心地址
+        server-addr: 192.168.10.18:8848
+        # 配置文件格式
+        file-extension: yml
+        # 共享配置
+        shared-configs:
+          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+  cache:
+    type: SIMPLE
+  datasource:
+    driver-class-name: org.postgresql.Driver
+    url: jdbc:postgresql://192.168.1.67:5432/gyee
+    username: gyee
+    password: Gyee@2023!@#
+    type: com.alibaba.druid.pool.DruidDataSource
+    druid:
+      max-active: 20
+      initial-size: 1
+      min-idle: 3
+      max-wait: 60000
+      time-between-eviction-runs-millis: 60000
+      min-evictable-idle-time-millis: 300000
+      test-while-idle: true
+      test-on-borrow: false
+      test-on-return: false
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: GMT+8
+    default-property-inclusion: always
+
+meter:
+  stations: MHS_FDC,NSS_FDC
+  adapter-url: http://192.168.10.18:8011
+  sharding-url: http://192.168.10.18:8075
+  uniformcode:
+    #8种状态
+    state8: FJZT8
+    #桨叶角度
+    blade-angle: AI082
+    #功率-有功功率
+    active-power: AI130
+    #风速
+    speed: AI022
+
+
+mybatis-plus:
+  typeAliasesPackage: com.gyee.gaia.meter.entity
+  mapper-locations: classpath:mappers-postgresql/*.xml
+  global-config:
+    #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+    id-type: 3
+    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
+    field-strategy: 2
+    #驼峰下划线转换
+    db-column-underline: true
+    #mp2.3+ 全局表前缀 mp_
+    #table-prefix: mp_
+    #刷新mapper 调试神器
+    #refresh-mapper: true
+    #数据库大写下划线转换
+    #capital-mode: true
+    # Sequence序列接口实现类配置
+    key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator
+    #逻辑删除配置(下面3个配置)
+    logic-delete-value: 1
+    logic-not-delete-value: 0
+    #sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
+    #自定义填充策略接口实现
+    #meta-object-handler: com.baomidou.springboot.MyMetaObjectHandler
+  configuration:
+    #配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId)
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+    #配置JdbcTypeForNull, oracle数据库必须配置
+    jdbc-type-for-null: 'null'
+    callSettersOnNulls: true
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+
+xxl:
+  job:
+    admin:
+      addresses: http://192.168.10.18:8080/xxl-job-admin
+    accessToken:
+    executor:
+      appname: meter
+      address:
+      ip:
+      port: 9021
+      logpath: d:/xxl-job/meter/logs
+      logretentiondays: 30

+ 49 - 0
electricity/wind/src/main/resources/log4j2.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+    <Properties>
+        <Property name="Pattern">%d{yyyy-MM-dd HH:mm:ss.SSS} %5p %t %M(%F:%L) %m%n</Property>
+    </Properties>
+    <Filter type="ThresholdFilter" level="INFO"/>
+
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT">
+            <PatternLayout pattern="${Pattern}"/>
+        </Console>
+        <RollingFile name="RollingFileInfo" fileName="logs/info.log"
+                     filePattern="logs/%d{yyyy-MM}/info-%d{yyyy-MM-dd}.%i.log">
+            <PatternLayout pattern="${Pattern}"/>
+            <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
+            <Policies>
+                <TimeBasedTriggeringPolicy/>
+                <SizeBasedTriggeringPolicy size="100 MB"/>
+            </Policies>
+        </RollingFile>
+        <RollingFile name="RollingFileWarn" fileName="logs/warn.log"
+                     filePattern="logs/%d{yyyy-MM}/warn-%d{yyyy-MM-dd}.%i.log">
+            <PatternLayout pattern="${Pattern}"/>
+            <ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY"/>
+            <Policies>
+                <TimeBasedTriggeringPolicy/>
+                <SizeBasedTriggeringPolicy size="100 MB"/>
+            </Policies>
+        </RollingFile>
+        <RollingFile name="RollingFileError" fileName="logs/error.log"
+                     filePattern="logs/%d{yyyy-MM}/error-%d{yyyy-MM-dd}.%i.log">
+            <PatternLayout pattern="${Pattern}"/>
+            <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
+            <Policies>
+                <TimeBasedTriggeringPolicy/>
+                <SizeBasedTriggeringPolicy size="100 MB"/>
+            </Policies>
+        </RollingFile>
+    </Appenders>
+
+    <Loggers>
+        <Root level="INFO">
+            <AppenderRef ref="Console"/>
+            <!--<appender-ref ref="RollingFileInfo"/>-->
+            <appender-ref ref="RollingFileWarn"/>
+            <appender-ref ref="RollingFileError"/>
+        </Root>
+    </Loggers>
+</Configuration>

+ 40 - 0
electricity/wind/src/test/java/com/gyee/gaia/MyAppTests.java

@@ -0,0 +1,40 @@
+package com.gyee.gaia;
+
+import com.gyee.gaia.electricity.wind.adapter.IShardingApi;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+
+@SpringBootTest(classes = WindPowergenApp.class)
+class MyAppTests {
+
+    @Resource
+    private IShardingApi shardingApi;
+
+    @Test
+    void test() {
+
+        /*QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
+        scWrapper.select("max(end_time)");
+        Map<String, Object> map = stateCauseService.getMap(scWrapper);*/
+        /*List<FaultInfo> infos = shardingApi.getFaultInfoList("SYZ", "2023-05-10", "2023-05-13", CacheContext.stationMap.get("NX_GDDL_XS_FDC_STA").getCode(), null, null);
+        if(infos.size()>0){
+            infos = infos.stream().filter(fi -> fi.getAlertText().contains("位状态")).collect(Collectors.toList());
+            if(infos.isEmpty()) return;
+
+            Map<String, List<FaultInfo>> map = infos.stream().map(fi -> {
+                fi.setConfirmPerson(fi.getAlertText().substring(fi.getAlertText().indexOf("--")));
+                fi.setAlertText(fi.getAlertText().substring(0, fi.getAlertText().indexOf("--")));
+                return fi;
+            }).collect(Collectors.groupingBy(FaultInfo::getAlertText));
+
+            for (List<FaultInfo> value : map.values()) {
+                //判断当前故障是分位状态
+                if(value.get(0).getConfirmPerson().equals("分位状态")) return;
+            }
+        }*/
+
+
+    }
+}

+ 119 - 0
electricity/wind/src/test/resources/bootstrap.yaml

@@ -0,0 +1,119 @@
+server:
+  port: 8321
+
+spring:
+  application:
+    name: state-cause
+  profiles:
+    # 环境配置
+    active: nx
+  cloud:
+    nacos:
+      discovery:
+        # 服务注册地址
+        server-addr: 192.168.10.18:8848
+      config:
+        # 配置中心地址
+        server-addr: 192.168.10.18:8848
+        # 配置文件格式
+        file-extension: yml
+        # 共享配置
+        shared-configs:
+          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+  cache:
+    type: SIMPLE
+  datasource:
+    driver-class-name: org.postgresql.Driver
+    url: jdbc:postgresql://192.168.1.67:5432/gyee
+    username: gyee
+    password: Gyee@2023!@#
+    type: com.alibaba.druid.pool.DruidDataSource
+    druid:
+      max-active: 20
+      initial-size: 1
+      min-idle: 3
+      max-wait: 60000
+      time-between-eviction-runs-millis: 60000
+      min-evictable-idle-time-millis: 300000
+      test-while-idle: true
+      test-on-borrow: false
+      test-on-return: false
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: GMT+8
+    default-property-inclusion: always
+
+meter:
+  stations: MHS_FDC,NSS_FDC
+  adapter-url: http://192.168.10.18:8011
+  sharding-url: http://192.168.10.18:8075
+  time:
+    #小于多长时间的故障不计算在内,单位秒
+    fault-min: 180
+    #限电跳变,2次限电间隔多长时间认为是同一次限电,单位秒
+    ration: 180
+    #小于多长时间的限电不计算在内,单位秒
+    ration-min: 180
+  uniformcode:
+    #8种状态
+    state8: FJZT8
+    #桨叶角度
+    blade-angle: AI082
+    #功率-有功功率
+    active-power: AI130
+    #风速
+    speed: AI022
+  uniformcode-boost:
+    #有功设定限值
+    active-power-set: BTYGSDXZ
+    #理论功率
+    apparent-power: BTLLGL
+    #实发有功
+    output-power: BTSFYG
+
+
+mybatis-plus:
+  typeAliasesPackage: com.gyee.gaia.meter.entity
+  mapper-locations: classpath:mappers-postgresql/*.xml
+  global-config:
+    #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+    id-type: 3
+    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
+    field-strategy: 2
+    #驼峰下划线转换
+    db-column-underline: true
+    #mp2.3+ 全局表前缀 mp_
+    #table-prefix: mp_
+    #刷新mapper 调试神器
+    #refresh-mapper: true
+    #数据库大写下划线转换
+    #capital-mode: true
+    # Sequence序列接口实现类配置
+    key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator
+    #逻辑删除配置(下面3个配置)
+    logic-delete-value: 1
+    logic-not-delete-value: 0
+    #sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
+    #自定义填充策略接口实现
+    #meta-object-handler: com.baomidou.springboot.MyMetaObjectHandler
+  configuration:
+    #配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId)
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+    #配置JdbcTypeForNull, oracle数据库必须配置
+    jdbc-type-for-null: 'null'
+    callSettersOnNulls: true
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+
+xxl:
+  job:
+    admin:
+      addresses: http://192.168.10.18:8080/xxl-job-admin
+    accessToken:
+    executor:
+      appname: meter
+      address:
+      ip:
+      port: 9021
+      logpath: d:/xxl-job/meter/logs
+      logretentiondays: 30

+ 1 - 0
metrics/HELP.md

@@ -1,5 +1,6 @@
 # 指标计算服务
 
 ### 状态转换率计算服务
+
 用于计算风机状态转换率,以及提供数据查询接口
 

+ 2 - 2
metrics/src/main/java/com/gyee/gaia/metrics/cache/InfoCache.java

@@ -1,6 +1,5 @@
 package com.gyee.gaia.metrics.cache;
 
-import com.gyee.gaia.metrics.modles.TagInfo;
 import com.gyee.gaia.metrics.dao.entity.TsPointEntity;
 import com.gyee.gaia.metrics.dao.entity.WindturbineEntity;
 import com.gyee.gaia.metrics.dao.repsoitory.TsPointRepository;
@@ -8,6 +7,7 @@ import com.gyee.gaia.metrics.dao.repsoitory.WindturbineRepository;
 import com.gyee.gaia.metrics.manager.FileManager;
 import com.gyee.gaia.metrics.modles.BoostStation;
 import com.gyee.gaia.metrics.modles.ConversionRateWindTurbineInfo;
+import com.gyee.gaia.metrics.modles.TagInfo;
 import com.gyee.gaia.metrics.targets.UniformCode;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
@@ -45,7 +45,7 @@ public class InfoCache {
     }
 
     public InfoCache(TsPointRepository tsPointRepository, WindturbineRepository windturbineRepository
-    , FileManager fileManager, @Value("${no-maintain-model:}") String noMaintainModel) {
+            , FileManager fileManager, @Value("${no-maintain-model:}") String noMaintainModel) {
         this.windturbineRepository = windturbineRepository;
         this.tsPointRepository = tsPointRepository;
         this.fileManager = fileManager;

+ 0 - 1
metrics/src/main/java/com/gyee/gaia/metrics/dao/repsoitory/TsPointRepository.java

@@ -1,7 +1,6 @@
 package com.gyee.gaia.metrics.dao.repsoitory;
 
 import com.gyee.gaia.metrics.dao.entity.TsPointEntity;
-import org.springframework.cache.annotation.CacheConfig;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

+ 1 - 1
metrics/src/main/java/com/gyee/gaia/metrics/services/BasicInformationService.java

@@ -1,11 +1,11 @@
 package com.gyee.gaia.metrics.services;
 
-import com.gyee.gaia.metrics.modles.TagInfo;
 import com.gyee.gaia.metrics.cache.InfoCache;
 import com.gyee.gaia.metrics.feigns.IDataAdapter;
 import com.gyee.gaia.metrics.modles.BoostStation;
 import com.gyee.gaia.metrics.modles.ConversionRateWindTurbineInfo;
 import com.gyee.gaia.metrics.modles.PointData;
+import com.gyee.gaia.metrics.modles.TagInfo;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;

+ 11 - 0
realtime/wind/README.md

@@ -0,0 +1,11 @@
+### cause 分析原因,故障损失,计划检修损失,受累损失,限电损失,性能损失等
+
+状态为: 并网--是否限电--风速小于11并且桨叶角度大于2;风速大于11并且有功功率小于满发功率减100 待机-- 是否限停-- 有故障--故障 无故障--有功设定小于出线功率;有功设定小于应发的85% 并且
+出线功率大于有功设定94%;有功设定小于应发的70% 并且 出线功率大于有功设定80% 并且 当前场站限电台数大于等于3--限停 待机 维护-- 有故障--故障 无故障--计划检修 故障--小于?(3)分钟故障忽略
+是否受累--全站故障或者离线 故障 离线-- 是否受累--全站故障或者离线 故障
+
+青山华创风机在停机的状态下应该算故障损失
+
+
+
+

+ 53 - 0
realtime/wind/build.gradle

@@ -0,0 +1,53 @@
+buildscript {
+    repositories {
+        mavenLocal()
+        maven {
+            allowInsecureProtocol = true
+            url "http://maven.aliyun.com/nexus/content/groups/public"
+        }
+        mavenCentral()
+    }
+    dependencies {
+        classpath("$bootGroup:spring-boot-gradle-plugin:$springBootVersion")
+    }
+}
+
+apply plugin: "$bootGroup"
+apply plugin: 'io.spring.dependency-management'
+
+dependencyManagement {
+    imports {
+        mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
+        mavenBom "org.springframework.boot:spring-boot-dependencies:$springBootVersion"
+        mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:$springCloudAlibabaVersion"
+    }
+}
+
+dependencies {
+    implementation project(":timeseries:dao-sql")
+
+    implementation("$bootGroup:spring-boot-starter-web")
+    implementation("$bootGroup:spring-boot-starter-undertow")
+
+
+    implementation("org.postgresql:postgresql:$postgresqlDriverVersion")
+    implementation "com.baomidou:mybatis-plus-boot-starter:$mybatisPlusVersion"
+    implementation("com.alibaba:druid:$alibabaDruidVersion")
+    implementation("com.alibaba:fastjson:$fastjsonVersion")
+
+    implementation("$bootGroup:spring-boot-starter-test")
+    implementation("com.xuxueli:xxl-job-core:$xxlJobVersion")
+    implementation("org.springframework.cloud:spring-cloud-starter-bootstrap")
+    implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery")
+    implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config")
+
+    implementation("com.taosdata.jdbc:taos-jdbcdriver:$taosVersion2")
+
+    implementation("$cloudGroup:spring-cloud-starter-openfeign")
+    implementation("cn.hutool:hutool-all:5.8.18")
+    implementation("com.baomidou:dynamic-datasource-spring-boot-starter:$mybatisPlusVersion")
+}
+
+test {
+    useJUnitPlatform()
+}

+ 21 - 0
realtime/wind/src/main/java/com/gyee/gaia/WindRealtimeApp.java

@@ -0,0 +1,21 @@
+package com.gyee.gaia;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+
+@SpringBootApplication
+@EnableDiscoveryClient
+@EnableFeignClients
+public class WindRealtimeApp {
+
+    public static void main(String[] args) {
+
+        SpringApplication.run(WindRealtimeApp.class, args);
+
+    }
+}
+
+

+ 27 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/adapter/IAdapterApi.java

@@ -0,0 +1,27 @@
+package com.gyee.gaia.realtime.wind.adapter;
+
+import com.gyee.gaia.common.data.point.PointData;
+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 IAdapterApi {
+
+    @GetMapping("/ts/history/snap?tagName={tagName}&startTs={startTs}&endTs={endTs}&interval={interval}")
+    List<PointData> getValuesByKey(@PathVariable(value = "tagName") String tagName, @PathVariable(value = "startTs") long startTs,
+                                   @PathVariable(value = "endTs") long endTs, @PathVariable(value = "interval") int interval);
+
+    @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);
+
+    @GetMapping("/ts/latest?keys={keys}")
+    public Map<String, PointData> getLatest(@PathVariable(value = "keys") String keys);
+}

+ 21 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/adapter/IShardingApi.java

@@ -0,0 +1,21 @@
+package com.gyee.gaia.realtime.wind.adapter;
+
+import com.gyee.gaia.common.data.alarm.FaultInfo;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+import java.util.List;
+
+@FeignClient(name = "sharding", url = "${meter.sharding-url}")
+public interface IShardingApi {
+
+    @GetMapping("/fault/history/list?category1={category1}&pagenum=1&pagesize=1000&stationid={stationid}&starttime={starttime}&endtime={endtime}&messagetype={messagetype}&keyword={keyword}")
+    List<FaultInfo> getFaultInfoList(
+            @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") Integer messagetype);
+}

+ 27 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/config/AppConfig.java

@@ -0,0 +1,27 @@
+package com.gyee.gaia.realtime.wind.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+
+@Data
+@Component
+@ConfigurationProperties("meter")
+public class AppConfig {
+
+    //场站范围
+    private String stations;
+    /**
+     * 统一编码名,统一编码
+     */
+    private Map<String, String> uniformcodeOne;
+
+    @Override
+    public String toString() {
+        return "stations = " + stations;
+    }
+
+}

+ 75 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/config/ThreadPoolConfig.java

@@ -0,0 +1,75 @@
+package com.gyee.gaia.realtime.wind.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.ThreadPoolExecutor;
+
+/**
+ * 线程池配置
+ *
+ * @author xysn
+ */
+@Configuration
+public class ThreadPoolConfig {
+
+    /**
+     *   默认情况下,在创建了线程池后,线程池中的线程数为0,当有任务来之后,就会创建一个线程去执行任务,
+     *	当线程池中的线程数目达到corePoolSize后,就会把到达的任务放到缓存队列当中;
+     *  当队列满了,就继续创建线程,当线程数量大于等于maxPoolSize后,开始使用拒绝策略拒绝
+     */
+
+    /**
+     * 核心线程数(默认线程数)
+     */
+    private static final int corePoolSize = 40;
+    /**
+     * 最大线程数
+     */
+    private static final int maxPoolSize = 100;
+    /**
+     * 允许线程空闲时间(单位:默认为秒)
+     */
+    private static final int keepAliveTime = 60;
+    /**
+     * 缓冲队列大小
+     */
+    private static final int queueCapacity = 300;
+    /**
+     * 允许等待最长时间
+     */
+    private static final int awaitTime = 15;
+    /**
+     * 线程池名前缀
+     */
+    private static final String threadNamePrefix = "Alarm-Thread-";
+
+    private ThreadPoolTaskExecutor executor;
+
+    public ThreadPoolTaskExecutor getExecutor() {
+        if (executor == null) {
+            executor = taskExecutor();
+        }
+
+        return executor;
+    }
+
+    @Bean
+    public ThreadPoolTaskExecutor taskExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(corePoolSize);
+        executor.setMaxPoolSize(maxPoolSize);
+        executor.setQueueCapacity(queueCapacity);
+        executor.setKeepAliveSeconds(keepAliveTime);
+        executor.setThreadNamePrefix(threadNamePrefix);
+        executor.setAwaitTerminationSeconds(awaitTime);
+
+        // 线程池对拒绝任务的处理策略
+        // CallerRunsPolicy:由调用线程(提交任务的线程)处理该任务
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        // 初始化
+        executor.initialize();
+        return executor;
+    }
+}

+ 78 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/config/XxlJobConfig.java

@@ -0,0 +1,78 @@
+package com.gyee.gaia.realtime.wind.config;
+
+import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * xxl-job config
+ *
+ * @author xuxueli 2017-04-28
+ */
+@Configuration
+public class XxlJobConfig {
+    private Logger logger = LoggerFactory.getLogger(com.gyee.gaia.realtime.wind.config.XxlJobConfig.class);
+
+    @Value("${xxl.job.admin.addresses}")
+    private String adminAddresses;
+
+    @Value("${xxl.job.accessToken}")
+    private String accessToken;
+
+    @Value("${xxl.job.executor.appname}")
+    private String appname;
+
+    @Value("${xxl.job.executor.address}")
+    private String address;
+
+    @Value("${xxl.job.executor.ip}")
+    private String ip;
+
+    @Value("${xxl.job.executor.port}")
+    private int port;
+
+    @Value("${xxl.job.executor.logpath}")
+    private String logPath;
+
+    @Value("${xxl.job.executor.logretentiondays}")
+    private int logRetentionDays;
+
+
+    @Bean
+    public XxlJobSpringExecutor xxlJobExecutor() {
+        logger.info(">>>>>>>>>>> xxl-job config init.");
+        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
+        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
+        xxlJobSpringExecutor.setAppname(appname);
+        //xxlJobSpringExecutor.se(address);
+        xxlJobSpringExecutor.setIp(ip);
+        xxlJobSpringExecutor.setPort(port);
+        xxlJobSpringExecutor.setAccessToken(accessToken);
+        xxlJobSpringExecutor.setLogPath(logPath);
+        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
+
+        return xxlJobSpringExecutor;
+    }
+
+    /**
+     * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
+     *
+     *      1、引入依赖:
+     *          <dependency>
+     *             <groupId>org.springframework.cloud</groupId>
+     *             <artifactId>spring-cloud-commons</artifactId>
+     *             <version>${version}</version>
+     *         </dependency>
+     *
+     *      2、配置文件,或者容器启动变量
+     *          spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
+     *
+     *      3、获取IP
+     *          String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
+     */
+
+
+}

+ 56 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/init/CacheContext.java

@@ -0,0 +1,56 @@
+package com.gyee.gaia.realtime.wind.init;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.gaia.common.data.windturbine.Equipment;
+import com.gyee.gaia.common.data.windturbine.Powerstation;
+import com.gyee.gaia.dao.sql.Windturbine.IEquipmentService;
+import com.gyee.gaia.dao.sql.Windturbine.IPowerstationService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Order(1)
+@Slf4j
+@Component
+public class CacheContext implements ApplicationRunner {
+
+    @Resource
+    private IEquipmentService equipmentService;
+    @Resource
+    private IPowerstationService powerstationService;
+    /**
+     * 风机号,Equipment
+     */
+    public static Map<String, Equipment> equipMap;
+    /**
+     * 场站id,Powerstation
+     */
+    public static Map<String, Powerstation> stationMap;
+    /**
+     * 风场,风机
+     */
+    public static Map<String, List<Equipment>> stationEquipMap;
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+
+        log.info("加载风机!");
+        QueryWrapper<Equipment> emWrapper = new QueryWrapper<>();
+        emWrapper.eq("spare1", "WT");
+        List<Equipment> emList = equipmentService.list(emWrapper);
+        equipMap = emList.stream().collect(Collectors.toMap(Equipment::getId, Function.identity()));
+        stationEquipMap = emList.stream().collect(Collectors.groupingBy(Equipment::getWindpowerstationId));
+
+        log.info("加载风场信息!");
+        List<Powerstation> stationList = powerstationService.list();
+        stationMap = stationList.stream().collect(Collectors.toMap(Powerstation::getId, Function.identity()));
+    }
+}

+ 220 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/job/CauseJobHandler.java

@@ -0,0 +1,220 @@
+package com.gyee.gaia.realtime.wind.job;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.NumberUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.gaia.common.data.point.PointData;
+import com.gyee.gaia.common.data.point.TestingPoint;
+import com.gyee.gaia.common.data.taos.RealtimeAverageTarget;
+import com.gyee.gaia.dao.sql.point.ITestingPointService;
+import com.gyee.gaia.dao.sql.taos.IRealtimeAverageTargetService;
+import com.gyee.gaia.realtime.wind.adapter.IAdapterApi;
+import com.gyee.gaia.realtime.wind.config.AppConfig;
+import com.gyee.gaia.realtime.wind.init.CacheContext;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.core.annotation.Order;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+@Order(2)
+@Component
+public class CauseJobHandler implements ApplicationRunner {
+
+    @Resource
+    private ITestingPointService testingPointService;
+    @Resource
+    private AppConfig appConfig;
+    @Resource
+    private IRealtimeAverageTargetService realtimeAverageTargetService;
+    @Resource
+    private IAdapterApi adapterApi;
+    @Resource
+    private ThreadPoolTaskExecutor taskExecutor;
+    private String pointCodes;
+    private Map<String, ArrayDeque<PointData>> pdaqMap = new ConcurrentHashMap<>();
+    /**
+     * 风机id,uniformcode,点名
+     */
+    private Map<String, Map<String, String>> equipUcMap = new HashMap<>();
+    private Map<String, String> pjzb1fzMap;
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+
+        CacheContext.equipMap.keySet().forEach(em -> equipUcMap.put(em, new HashMap<>()));
+
+        Collection<String> uniformCodeList = appConfig.getUniformcodeOne().values();
+
+        //根据uniformcode获取测点
+        QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
+        tpWrapper.eq("thing_type", "windturbine");
+        StringBuilder sb = new StringBuilder();
+
+        //获取最新更新时间
+        /*QueryWrapper<RealtimeAverageTarget> ratWrapper = new QueryWrapper<>();
+        ratWrapper.select("max(time)");
+        Map<String, Object> map = realtimeAverageTargetService.getMap(ratWrapper);
+        Date max;
+        if (map != null && map.size() > 0) {
+            max = (Date) map.get("max");
+        } else {
+            max = DateUtil.beginOfDay(DateUtil.date());
+        }*/
+
+        //风机号,时间,RealtimeAverageTarget
+        Map<String, Map<Long, RealtimeAverageTarget>> ratssmm = new HashMap<>();
+        List<RealtimeAverageTarget> rats = new ArrayList<>();
+        //5个指标
+        for (String value : uniformCodeList) {
+            //每个指标407个风机
+            List<TestingPoint> list = testingPointService.list(tpWrapper.clone().eq("uniform_code", value));
+
+            List<PointData> rawByKey;
+            RealtimeAverageTarget target = null;
+            //每个指标每个风机
+            for (TestingPoint point : list) {
+                String thingId = point.getThingId();
+                sb.append(",").append(point.getCode());
+                equipUcMap.get(thingId).put(value, point.getCode());
+                /*rawByKey = adapterApi.getRawByKey(point.getCode(), max.getTime(), System.currentTimeMillis());
+                Map<Long, Double> collect = rawByKey.stream().collect(Collectors.groupingBy(data -> data.getTs() / 60000, Collectors.averagingDouble(PointData::getDoubleValue)));
+                //TODO 补缺的时间
+                for (Map.Entry<Long, Double> entry : collect.entrySet()) {
+                    if(target==null){
+                        target = new RealtimeAverageTarget();
+                        target.setTime(new Timestamp(entry.getKey()*60000));
+                        target.setEquipmentId(thingId);
+                        setRats(target, value,entry.getValue());
+                        rats.add(target);
+
+                        if(!ratssmm.containsKey(thingId)) ratssmm.put(thingId, new HashMap<>());
+                        ratssmm.get(thingId).put(entry.getKey(), target);
+                    }else {
+                        RealtimeAverageTarget averageTarget = ratssmm.get(thingId).get(entry.getKey());
+                        if(averageTarget!=null) setRats(averageTarget, value, entry.getValue());
+                    }
+                }*/
+            }
+        }
+        //realtimeAverageTargetService.saveBatch(rats, 3000);
+        QueryWrapper<RealtimeAverageTarget> ratWrapper = new QueryWrapper<>();
+        ratWrapper.select("tbname", "equipment_id").eq("uniform_code", "1FZPJZB");
+        List<RealtimeAverageTarget> ratList = realtimeAverageTargetService.list(ratWrapper);
+        pjzb1fzMap = ratList.stream().collect(Collectors.toMap(RealtimeAverageTarget::getEquipmentId, RealtimeAverageTarget::getTbname));
+
+        pointCodes = sb.delete(0, 1).toString();
+        init();
+        taskExecutor.submit(this::refreshQueue);
+        taskExecutor.submit(this::calcRealtimeAverageTarget);
+    }
+
+    private void setRats(RealtimeAverageTarget target, String uc, double value) {
+        if (uc.equals(appConfig.getUniformcodeOne().get("wind-speed"))) {
+            target.setWindSpeed(value);
+        } else if (uc.equals(appConfig.getUniformcodeOne().get("active-power"))) {
+            target.setPower(value);
+        } else if (uc.equals(appConfig.getUniformcodeOne().get("generator_speed"))) {
+            target.setGeneratorSpeed(value);
+        } else if (uc.equals(appConfig.getUniformcodeOne().get("impeller_speed"))) {
+            target.setImpellerSpeed(value);
+        } else if (uc.equals(appConfig.getUniformcodeOne().get("wind_direction"))) {
+            target.setWindDirection(value);
+        }
+    }
+
+    private void init() throws InterruptedException {
+
+        //缓存1分钟的值填满pdaqMap
+        for (int i = 0; i < 60; i++) {
+            Map<String, PointData> latest = adapterApi.getLatest(pointCodes);
+            if (i == 0) {
+                latest.forEach((k, v) -> {
+                    ArrayDeque<PointData> pdaq = new ArrayDeque<>(60);
+                    pdaq.offer(v);
+                    pdaqMap.put(k, pdaq);
+                });
+            } else {
+                latest.forEach((k, v) -> {
+                    pdaqMap.get(k).offer(v);
+                });
+            }
+            Thread.sleep(1000);
+        }
+    }
+
+    private void refreshQueue() {
+
+        try {
+            while (true) {
+                Map<String, PointData> latest = adapterApi.getLatest(pointCodes);
+                latest.forEach((k, v) -> {
+                    pdaqMap.get(k).poll();
+                    pdaqMap.get(k).offer(v);
+                });
+                Thread.sleep(1000);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void calcRealtimeAverageTarget() {
+
+        String pointCode = null;
+        try {
+            while (true) {
+                if (LocalDateTime.now().getSecond() == 59) {
+
+                    RealtimeAverageTarget target;
+                    double v;
+                    List<RealtimeAverageTarget> targets = new ArrayList<>();
+                    for (Map.Entry<String, Map<String, String>> entry : equipUcMap.entrySet()) {
+                        target = new RealtimeAverageTarget();
+                        target.setTime(DateUtil.beginOfMinute(DateUtil.date()).toTimestamp());
+                        //target.setEquipmentId(entry.getKey());
+                        target.setTbname(pjzb1fzMap.get(entry.getKey()));
+
+                        pointCode = entry.getValue().get(appConfig.getUniformcodeOne().get("wind-speed"));
+                        if (pointCode != null) {
+                            v = pdaqMap.get(pointCode).stream().mapToDouble(data -> data.getDoubleValue()).average().orElse(0);
+                            target.setWindSpeed(NumberUtil.round(v, 2).doubleValue());
+                        }
+                        pointCode = entry.getValue().get(appConfig.getUniformcodeOne().get("active-power"));
+                        if (pointCode != null) {
+                            v = pdaqMap.get(pointCode).stream().mapToDouble(data -> data.getDoubleValue()).average().orElse(0);
+                            target.setPower(NumberUtil.round(v, 2).doubleValue());
+                        }
+                        pointCode = entry.getValue().get(appConfig.getUniformcodeOne().get("generator_speed"));
+                        if (pointCode != null) {
+                            v = pdaqMap.get(pointCode).stream().mapToDouble(data -> data.getDoubleValue()).average().orElse(0);
+                            target.setGeneratorSpeed(NumberUtil.round(v, 2).doubleValue());
+                        }
+                        pointCode = entry.getValue().get(appConfig.getUniformcodeOne().get("impeller_speed"));
+                        if (pointCode != null) {
+                            v = pdaqMap.get(pointCode).stream().mapToDouble(data -> data.getDoubleValue()).average().orElse(0);
+                            target.setImpellerSpeed(NumberUtil.round(v, 2).doubleValue());
+                        }
+                        pointCode = entry.getValue().get(appConfig.getUniformcodeOne().get("wind_direction"));
+                        if (pointCode != null) {
+                            v = pdaqMap.get(pointCode).stream().mapToDouble(data -> data.getDoubleValue()).average().orElse(0);
+                            target.setWindDirection(NumberUtil.round(v, 2).doubleValue());
+                        }
+                        targets.add(target);
+                    }
+                    realtimeAverageTargetService.saveBatch(targets);
+                }
+                Thread.sleep(1000);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+}

+ 41 - 0
realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/service/impl/RealtimeAverageTargetServiceImpl.java

@@ -0,0 +1,41 @@
+package com.gyee.gaia.realtime.wind.service.impl;
+
+import cn.hutool.core.collection.ListUtil;
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.gaia.common.data.taos.RealtimeAverageTarget;
+import com.gyee.gaia.dao.sql.taos.IRealtimeAverageTargetService;
+import com.gyee.gaia.dao.taos.RealtimeAverageTargetMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-18
+ */
+@DS("fjjsfw")
+@Service
+public class RealtimeAverageTargetServiceImpl extends ServiceImpl<RealtimeAverageTargetMapper, RealtimeAverageTarget> implements IRealtimeAverageTargetService {
+
+    public int saveBatch(List<RealtimeAverageTarget> entityList) {
+        List<List<RealtimeAverageTarget>> split = ListUtil.split(entityList, 3000);
+
+        int count = 0;
+        for (List<RealtimeAverageTarget> targets : split) {
+            StringBuilder sb = new StringBuilder();
+            for (RealtimeAverageTarget target : targets) {
+                sb.append(target.getTbname()).append(" values(").append(target.getTime().getTime())
+                        .append(",").append(target.getWindSpeed()).append(",").append(target.getPower())
+                        .append(",").append(target.getGeneratorSpeed()).append(",").append(target.getImpellerSpeed())
+                        .append(",").append(target.getWindDirection()).append(") ");
+            }
+            count += baseMapper.insert(sb.toString());
+        }
+        return count;
+    }
+}

+ 6 - 0
realtime/wind/src/main/resources/banner.txt

@@ -0,0 +1,6 @@
+#    # # #    # #####        #####  ######   ##   #      ##### # #    # ###### 
+#    # # ##   # #    #       #    # #       #  #  #        #   # ##  ## #      
+#    # # # #  # #    # ##### #    # #####  #    # #        #   # # ## # #####  
+# ## # # #  # # #    #       #####  #      ###### #        #   # #    # #      
+##  ## # #   ## #    #       #   #  #      #    # #        #   # #    # #      
+#    # # #    # #####        #    # ###### #    # ######   #   # #    # ###### 

+ 116 - 0
realtime/wind/src/main/resources/bootstrap.yaml

@@ -0,0 +1,116 @@
+server:
+  port: 8022
+
+spring:
+  application:
+    name: state-cause
+  profiles:
+    # 环境配置
+    active: nx
+  cloud:
+    nacos:
+      discovery:
+        # 服务注册地址
+        server-addr: 192.168.10.18:8848
+      config:
+        # 配置中心地址
+        server-addr: 192.168.10.18:8848
+        # 配置文件格式
+        file-extension: yml
+        # 共享配置
+        shared-configs:
+          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+  cache:
+    type: SIMPLE
+  datasource:
+    dynamic:
+      primary: master #设置默认的数据源或者数据源组,默认值即为master
+      strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
+      datasource:
+        master:
+          url: jdbc:postgresql://192.168.1.67:5432/gyee
+          username: gyee
+          password: Gyee@2023!@#
+          driver-class-name: org.postgresql.Driver
+          type: com.alibaba.druid.pool.DruidDataSource
+        fjjsfw:
+          url: jdbc:TAOS-RS://192.168.1.67:6041/jsfw?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
+          username: root
+          password: taosdata
+          driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
+    druid:
+      max-active: 20
+      initial-size: 1
+      min-idle: 3
+      max-wait: 60000
+      time-between-eviction-runs-millis: 60000
+      min-evictable-idle-time-millis: 300000
+      test-while-idle: false
+      test-on-borrow: false
+      test-on-return: false
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: GMT+8
+    default-property-inclusion: always
+
+meter:
+  stations: MHS_FDC,NSS_FDC
+  adapter-url: http://192.168.10.18:8011
+  sharding-url: http://192.168.10.18:8075
+  uniformcode-one:
+    wind-speed: AI022  #风速
+    active-power: AI130  #功率-有功功率
+    generator_speed: AI128  #发电机转速
+    impeller_speed: AI012  #叶轮转速
+    wind_direction: AI010  #风向
+
+
+mybatis-plus:
+  typeAliasesPackage: com.gyee.gaia.meter.entity
+  mapper-locations: classpath:mappers-postgresql/*.xml
+  global-config:
+    #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+    id-type: 3
+    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
+    field-strategy: 2
+    #驼峰下划线转换
+    db-column-underline: true
+    #mp2.3+ 全局表前缀 mp_
+    #table-prefix: mp_
+    #刷新mapper 调试神器
+    #refresh-mapper: true
+    #数据库大写下划线转换
+    #capital-mode: true
+    # Sequence序列接口实现类配置
+    key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator
+    #逻辑删除配置(下面3个配置)
+    logic-delete-value: 1
+    logic-not-delete-value: 0
+    #sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
+    #自定义填充策略接口实现
+    #meta-object-handler: com.baomidou.springboot.MyMetaObjectHandler
+  configuration:
+    #配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId)
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+    #配置JdbcTypeForNull, oracle数据库必须配置
+    jdbc-type-for-null: 'null'
+    callSettersOnNulls: true
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+
+xxl:
+  job:
+    admin:
+      addresses: http://192.168.10.18:8080/xxl-job-admin
+    accessToken:
+    executor:
+      appname: meter
+      address:
+      ip:
+      port: 9021
+      logpath: d:/xxl-job/meter/logs
+      logretentiondays: 30
+
+#logging:
+#  level:
+#    org.springframework: debug

+ 49 - 0
realtime/wind/src/main/resources/log4j2.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+    <Properties>
+        <Property name="Pattern">%d{yyyy-MM-dd HH:mm:ss.SSS} %5p %t %M(%F:%L) %m%n</Property>
+    </Properties>
+    <Filter type="ThresholdFilter" level="INFO"/>
+
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT">
+            <PatternLayout pattern="${Pattern}"/>
+        </Console>
+        <RollingFile name="RollingFileInfo" fileName="logs/info.log"
+                     filePattern="logs/%d{yyyy-MM}/info-%d{yyyy-MM-dd}.%i.log">
+            <PatternLayout pattern="${Pattern}"/>
+            <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
+            <Policies>
+                <TimeBasedTriggeringPolicy/>
+                <SizeBasedTriggeringPolicy size="100 MB"/>
+            </Policies>
+        </RollingFile>
+        <RollingFile name="RollingFileWarn" fileName="logs/warn.log"
+                     filePattern="logs/%d{yyyy-MM}/warn-%d{yyyy-MM-dd}.%i.log">
+            <PatternLayout pattern="${Pattern}"/>
+            <ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY"/>
+            <Policies>
+                <TimeBasedTriggeringPolicy/>
+                <SizeBasedTriggeringPolicy size="100 MB"/>
+            </Policies>
+        </RollingFile>
+        <RollingFile name="RollingFileError" fileName="logs/error.log"
+                     filePattern="logs/%d{yyyy-MM}/error-%d{yyyy-MM-dd}.%i.log">
+            <PatternLayout pattern="${Pattern}"/>
+            <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
+            <Policies>
+                <TimeBasedTriggeringPolicy/>
+                <SizeBasedTriggeringPolicy size="100 MB"/>
+            </Policies>
+        </RollingFile>
+    </Appenders>
+
+    <Loggers>
+        <Root level="INFO">
+            <AppenderRef ref="Console"/>
+            <!--<appender-ref ref="RollingFileInfo"/>-->
+            <appender-ref ref="RollingFileWarn"/>
+            <appender-ref ref="RollingFileError"/>
+        </Root>
+    </Loggers>
+</Configuration>

+ 45 - 0
realtime/wind/src/test/java/com/gyee/gaia/MyAppTests.java

@@ -0,0 +1,45 @@
+package com.gyee.gaia;
+
+import com.gyee.gaia.common.data.alarm.FaultInfo;
+import com.gyee.gaia.realtime.wind.adapter.IShardingApi;
+import com.gyee.gaia.realtime.wind.init.CacheContext;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@SpringBootTest
+class MyAppTests {
+
+    @Resource
+    private IShardingApi shardingApi;
+
+    @Test
+    void test() {
+
+        /*QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
+        scWrapper.select("max(end_time)");
+        Map<String, Object> map = stateCauseService.getMap(scWrapper);*/
+        List<FaultInfo> infos = shardingApi.getFaultInfoList("SYZ", "2023-05-10", "2023-05-13", CacheContext.stationMap.get("NX_GDDL_XS_FDC_STA").getCode(), null, null);
+        if (infos.size() > 0) {
+            infos = infos.stream().filter(fi -> fi.getAlertText().contains("位状态")).collect(Collectors.toList());
+            if (infos.isEmpty()) return;
+
+            Map<String, List<FaultInfo>> map = infos.stream().map(fi -> {
+                fi.setConfirmPerson(fi.getAlertText().substring(fi.getAlertText().indexOf("--")));
+                fi.setAlertText(fi.getAlertText().substring(0, fi.getAlertText().indexOf("--")));
+                return fi;
+            }).collect(Collectors.groupingBy(FaultInfo::getAlertText));
+
+            for (List<FaultInfo> value : map.values()) {
+                //判断当前故障是分位状态
+                if (value.get(0).getConfirmPerson().equals("分位状态")) return;
+            }
+        }
+
+
+    }
+}

+ 3 - 0
settings.gradle

@@ -13,8 +13,11 @@ include "timeseries:dao-redis-taos"
 include "timeseries:data-adapter"
 
 include "electricity:meter"
+include "electricity:wind"
 include "state:wind"
 include "state:cause"
 
+include "realtime:wind"
+
 include "metrics"
 

+ 3 - 16
state/cause/README.md

@@ -1,21 +1,8 @@
 ### cause 分析原因,故障损失,计划检修损失,受累损失,限电损失,性能损失等
 
-状态为:
-    并网--是否限电--风速小于11并且桨叶角度大于2;风速大于11并且有功功率小于满发功率减100
-    待机--
-        是否限停--
-            有故障--故障
-            无故障--有功设定小于出线功率;有功设定小于应发的85% 并且 出线功率大于有功设定94%;有功设定小于应发的70% 并且 出线功率大于有功设定80% 并且 当前场站限电台数大于等于3--限停
-        待机
-    维护--
-        有故障--故障
-        无故障--计划检修
-    故障--小于?(3)分钟故障忽略
-        是否受累--全站故障或者离线
-        故障
-    离线--
-        是否受累--全站故障或者离线
-        故障
+状态为: 并网--是否限电--风速小于11并且桨叶角度大于2;风速大于11并且有功功率小于满发功率减100 待机-- 是否限停-- 有故障--故障 无故障--有功设定小于出线功率;有功设定小于应发的85% 并且
+出线功率大于有功设定94%;有功设定小于应发的70% 并且 出线功率大于有功设定80% 并且 当前场站限电台数大于等于3--限停 待机 维护-- 有故障--故障 无故障--计划检修 故障--小于?(3)分钟故障忽略
+是否受累--全站故障或者离线 故障 离线-- 是否受累--全站故障或者离线 故障
 
 青山华创风机在停机的状态下应该算故障损失
 

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

@@ -1,8 +1,6 @@
 package com.gyee.gaia.cause.adapter;
 
-import com.gyee.gaia.cause.entity.PointData;
-import feign.Param;
-import feign.RequestLine;
+import com.gyee.gaia.common.data.point.PointData;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -11,7 +9,7 @@ import java.util.List;
 import java.util.Map;
 
 @FeignClient(name = "adapter", url = "${meter.adapter-url}")
-public interface AdapterApi {
+public interface IAdapterApi {
 
     @GetMapping("/ts/history/snap?tagName={tagName}&startTs={startTs}&endTs={endTs}&interval={interval}")
     List<PointData> getValuesByKey(@PathVariable(value = "tagName") String tagName, @PathVariable(value = "startTs") long startTs,
@@ -20,6 +18,7 @@ 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);
+    Map<String, PointData> getHistorySection(@PathVariable(value = "tagNames") String tagNames, @PathVariable(value = "ts") long ts);
 }

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

@@ -1,7 +1,6 @@
 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.PathVariable;
@@ -9,7 +8,7 @@ import org.springframework.web.bind.annotation.PathVariable;
 import java.util.List;
 
 @FeignClient(name = "sharding", url = "${meter.sharding-url}")
-public interface ShardingApi {
+public interface IShardingApi {
 
     @GetMapping("/fault/history/list?category1={category1}&pagenum=1&pagesize=1000&stationid={stationid}&starttime={starttime}&endtime={endtime}&messagetype={messagetype}&keyword={keyword}")
     List<FaultInfo> getFaultInfoList(

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

@@ -24,9 +24,9 @@ public class AppConfig {
     private Map<String, Long> longTime;
 
     public Map<String, Long> getLongTime() {
-        if(longTime==null){
+        if (longTime == null) {
             longTime = new HashMap<>();
-            time.forEach((k,v)->{
+            time.forEach((k, v) -> {
                 longTime.put(k, (v * 1000L));
             });
         }

+ 1 - 0
state/cause/src/main/java/com/gyee/gaia/cause/entity/EquipmentInfo.java

@@ -1,5 +1,6 @@
 package com.gyee.gaia.cause.entity;
 
+import com.gyee.gaia.common.data.point.PointData;
 import lombok.Data;
 
 @Data

+ 1 - 2
state/cause/src/main/java/com/gyee/gaia/cause/entity/StateCause.java

@@ -3,7 +3,6 @@ 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;
@@ -74,7 +73,7 @@ public class StateCause implements Serializable {
         this.endTime = endTime;
         this.advanceState = advanceState;
         this.afterState = afterState;
-        this.time = time;
+        this.time = time / 1000;
     }
 
     public Integer getId() {

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

@@ -1,4 +1,4 @@
-package com.gyee.gaia.init;
+package com.gyee.gaia.cause.init;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.gyee.gaia.cause.config.AppConfig;
@@ -48,11 +48,11 @@ public class CacheContext implements ApplicationRunner {
     /**
      * 统一编码名称,设备id,测点
      */
-    public static Map<String, Map<String, TestingPoint>> pointMapMap=new HashMap<>();
+    public static Map<String, Map<String, TestingPoint>> pointMapMap = new HashMap<>();
     /**
      * 风机号,Equipment
      */
-    public static Map<String,Equipment> equipMap;
+    public static Map<String, Equipment> equipMap;
     /**
      * 场站id,Powerstation
      */
@@ -60,11 +60,11 @@ public class CacheContext implements ApplicationRunner {
     /**
      * 期次,升压站信息
      */
-    public static Map<String,Booststation> boostStationMap=new HashMap<>();
+    public static Map<String, Booststation> boostStationMap = new HashMap<>();
     /**
      * 风场,风机
      */
-    public static Map<String,List<Equipment>> stationEquipMap;
+    public static Map<String, List<Equipment>> stationEquipMap;
 
     @Override
     public void run(ApplicationArguments args) throws Exception {
@@ -75,16 +75,16 @@ public class CacheContext implements ApplicationRunner {
         Map<String, String> uniformCodeMap = uniformCodeList.stream().collect(Collectors.toMap(UniformCode::getDescription, UniformCode::getNemCode));*/
 
         log.info("加载状态测点!");
-        appConfig.getUniformcode().forEach((k,v)->{
+        appConfig.getUniformcode().forEach((k, v) -> {
             QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
-            tpWrapper.eq("thing_type","windturbine").eq("uniform_code", v);
+            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.getUniformcodeBoost().forEach((k, v)->{
+        appConfig.getUniformcodeBoost().forEach((k, v) -> {
             QueryWrapper<TestingPoint> tpWrapper = new QueryWrapper<>();
-            tpWrapper.eq("thing_type","booststation").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);
@@ -113,8 +113,8 @@ public class CacheContext implements ApplicationRunner {
 
         log.info("加载风机!");
         List<Equipment> emList = equipmentService.list();
-        equipMap =emList.stream().collect(Collectors.toMap(Equipment::getId, Function.identity()));
-        stationEquipMap =emList.stream().collect(Collectors.groupingBy(Equipment::getWindpowerstationId));
+        equipMap = emList.stream().collect(Collectors.toMap(Equipment::getId, Function.identity()));
+        stationEquipMap = emList.stream().collect(Collectors.groupingBy(Equipment::getWindpowerstationId));
 
         log.info("加载升压站信息!");
         List<Booststation> bsList = booststationService.list();

+ 3 - 10
state/cause/src/main/java/com/gyee/gaia/cause/job/CauseJobHandler.java

@@ -3,26 +3,19 @@ package com.gyee.gaia.cause.job;
 
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gyee.gaia.cause.entity.PointData;
 import com.gyee.gaia.cause.entity.StateCause;
 import com.gyee.gaia.cause.service.CalculateService;
 import com.gyee.gaia.cause.service.IStateCauseService;
-import com.gyee.gaia.common.data.point.TestingPoint;
 import com.gyee.gaia.dao.sql.point.ITestingPointService;
-import com.gyee.gaia.init.CacheContext;
 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;
 
 import javax.annotation.Resource;
-import java.sql.Timestamp;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import static com.xxl.job.core.biz.model.ReturnT.SUCCESS_CODE;
@@ -54,9 +47,9 @@ public class CauseJobHandler implements ApplicationRunner {
         scWrapper.select("max(end_time)");
         Map<String, Object> map = stateCauseService.getMap(scWrapper);
         Date max;
-        if (map != null && map.size()>0) {
-            max = (Date)map.get("max");
-        }else {
+        if (map != null && map.size() > 0) {
+            max = (Date) map.get("max");
+        } else {
             max = DateUtil.yesterday();
         }
 

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

@@ -1,17 +1,17 @@
 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.adapter.IAdapterApi;
+import com.gyee.gaia.cause.adapter.IShardingApi;
 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.cause.init.CacheContext;
 import com.gyee.gaia.common.data.alarm.FaultInfo;
+import com.gyee.gaia.common.data.point.PointData;
 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;
 
@@ -24,9 +24,9 @@ import java.util.stream.Collectors;
 public class CalculateService {
 
     @Resource
-    private AdapterApi adapterApi;
+    private IAdapterApi adapterApi;
     @Resource
-    private ShardingApi shardingApi;
+    private IShardingApi shardingApi;
     @Resource
     private AppConfig appConfig;
     @Resource
@@ -35,14 +35,14 @@ public class CalculateService {
     /**
      * 设备id,状态点列表
      */
-    private final Map<String, List<PointData>> stateDatas=new HashMap<>();
+    private final Map<String, List<PointData>> stateDatas = new HashMap<>();
     private Map<Double, String> stateMap;
     private Map<String, List<FaultInfo>> fjGzMap;
     private Map<String, List<FaultInfo>> syzGzMap;
 
-    public void refresh(long starttime, long endtime){
+    public void refresh(long starttime, long endtime) {
         log.info("刷新测点值!");
-        CacheContext.pointMapMap.get("state8").forEach((k,v)->{
+        CacheContext.pointMapMap.get("state8").forEach((k, v) -> {
             List<PointData> rawByKey = adapterApi.getRawByKey(v.getCode(), starttime, endtime);
             stateDatas.put(k, rawByKey);
         });
@@ -69,8 +69,8 @@ public class CalculateService {
     //风机的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;
+        stateDatas.forEach((thingId, value) -> {
+            if (value.isEmpty()) return;
             //事前状态
             double advanceState = value.get(0).getDoubleValue();
             //事前时间
@@ -82,57 +82,58 @@ public class CalculateService {
                 ts = pointData.getTs();
                 doubleValue = pointData.getDoubleValue();
 
-                if(doubleValue ==1||doubleValue==3) continue;
-                if(doubleValue ==advanceState) continue;
+                if (doubleValue == 1 || doubleValue == 3) continue;
+                if (doubleValue == advanceState) continue;
 
                 //判断事前状态
-                if(advanceState==4){
+                if (advanceState == 4) {
                     //计算限电
                     LinkedHashMap<Long, Long> map = calcElectricityRation(thingId, advanceTime, ts);
                     StateCause cause;
                     for (Map.Entry<Long, Long> entry : map.entrySet()) {
-                        if(entry.getKey().equals(doubleValue)){
-                            cause = new StateCause(thingId2StationId(thingId), thingId, stateMap.get(8.0),new Date(entry.getKey()),
+                        if (entry.getKey().equals(doubleValue)) {
+                            cause = new StateCause(thingId2StationId(thingId), thingId, stateMap.get(8.0), new Date(entry.getKey()),
                                     new Date(entry.getValue()), stateMap.get(4.0), stateMap.get(doubleValue), entry.getValue() - entry.getKey());
-                        }else {
-                            cause = new StateCause(thingId2StationId(thingId), thingId, stateMap.get(8.0),new Date(entry.getKey()),
+                        } else {
+                            cause = new StateCause(thingId2StationId(thingId), thingId, stateMap.get(8.0), new Date(entry.getKey()),
                                     new Date(entry.getValue()), stateMap.get(4.0), stateMap.get(4.0), entry.getValue() - entry.getKey());
                         }
                         stateCauseList.add(cause);
                     }
-                }else if(advanceState==2){
-                    if(judgmentStop(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);
+                } else if (advanceState == 2) {
+                    //计算限停
+                    if (judgmentStop(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);
+                    } 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(hasFaultEvent(thingId,advanceTime,ts)){
+                } else if (advanceState == 6) {
+                    if (hasFaultEvent(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);
+                        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 {
+                    } 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);
+                        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.getLongTime().get("fault-min")) continue;
+                } else if (advanceState == 5) {
+                    if (ts - advanceTime < appConfig.getLongTime().get("fault-min")) continue;
                     //计算受累、故障
-                    calcBurdened(stateCauseList,thingId,advanceTime, ts,5,doubleValue);
-                }else if(advanceState==7){
+                    calcBurdened(stateCauseList, thingId, advanceTime, ts, 5, doubleValue);
+                } else if (advanceState == 7) {
                     //计算受累、故障、计划检修
-                    calcBurdened(stateCauseList,thingId,advanceTime, ts,7,doubleValue);
-                }else if(advanceState==0){
-                    if(ts-advanceTime<appConfig.getLongTime().get("fault-min")) continue;
-                    StateCause cause = new StateCause(thingId2StationId(thingId),thingId, stateMap.get(5.0),
-                            new Date(advanceTime),new Date(ts), stateMap.get(0.0),stateMap.get(doubleValue),ts -advanceTime);
+                    calcBurdened(stateCauseList, thingId, advanceTime, ts, 7, doubleValue);
+                } else if (advanceState == 0) {
+                    if (ts - advanceTime < appConfig.getLongTime().get("fault-min")) continue;
+                    StateCause cause = new StateCause(thingId2StationId(thingId), thingId, stateMap.get(5.0),
+                            new Date(advanceTime), new Date(ts), stateMap.get(0.0), stateMap.get(doubleValue), ts - advanceTime);
                     stateCauseList.add(cause);
                 }
 
@@ -147,44 +148,44 @@ public class CalculateService {
      * 判断限停
      */
     private boolean judgmentStop(String thingId, long start, long end) {
-        if(hasFaultEvent(thingId,start,end)) return false;
+        if (hasFaultEvent(thingId, start, end)) return false;
         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;
+        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;
+        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;
+        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 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());
-
-        }else {
-            apDouble = apRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble()*(apTp.getRate()==null?1:apTp.getRate());
+        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());
+
+        } 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());
+        double opDouble = opRbk.stream().mapToDouble(PointData::getDoubleValue).average().getAsDouble() * (opTp.getRate() == null ? 1 : opTp.getRate());
         //有功设定小于出线功率
-        if(apsDouble<opDouble) return true;
+        if (apsDouble < opDouble) return true;
         //有功设定小于应发的85% 并且 出线功率大于有功设定94%
-        if(apsDouble<=apDouble*0.85&&opDouble>=apsDouble*0.94) return true;
+        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
         String stationid = thingId2StationId(thingId);
-        return apsDouble <= apDouble * 0.7 && opDouble >= apsDouble * 0.8 && electricityRationCount(stationid, start,end) >= 3;
+        return apsDouble <= apDouble * 0.7 && opDouble >= apsDouble * 0.8 && electricityRationCount(stationid, start, end) >= 3;
     }
 
     /**
@@ -201,10 +202,10 @@ public class CalculateService {
             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);
-            List<PointData> speedPdl = adapterApi.getValuesByKey(speedStr, start, end,30);
-            List<PointData> bladeAnglePdl = adapterApi.getValuesByKey(bladeAngleStr, start, end,30);
-            List<PointData> activePowerPdl = adapterApi.getValuesByKey(activePowerStr, start, end,30);
-            if(bladeAnglePdl.size()<speedPdl.size()||activePowerPdl.size()<speedPdl.size()) continue;
+            List<PointData> speedPdl = adapterApi.getValuesByKey(speedStr, start, end, 30);
+            List<PointData> bladeAnglePdl = adapterApi.getValuesByKey(bladeAngleStr, start, end, 30);
+            List<PointData> activePowerPdl = adapterApi.getValuesByKey(activePowerStr, start, end, 30);
+            if (bladeAnglePdl.size() < speedPdl.size() || activePowerPdl.size() < speedPdl.size()) continue;
 
             double incount = 0;
             for (int i = 0; i < speedPdl.size(); i++) {
@@ -212,12 +213,12 @@ public class CalculateService {
                 if (speedPdl.get(i).getDoubleValue() <= modelPower.getSpeed() && bladeAnglePdl.get(i).getDoubleValue() > 2) {
                     incount++;
                     //风速大于11并且有功功率小于满发功率减100
-                } else if (speedPdl.get(i).getDoubleValue() > modelPower.getSpeed() && activePowerPdl.get(i).getDoubleValue() < modelPower.getTheoryPower()-100) {
+                } else if (speedPdl.get(i).getDoubleValue() > modelPower.getSpeed() && activePowerPdl.get(i).getDoubleValue() < modelPower.getTheoryPower() - 100) {
                     incount++;
                 }
             }
-            if(incount/speedPdl.size()>0.5) count++;
-            if(count>3) return count;
+            if (incount / speedPdl.size() > 0.5) count++;
+            if (count > 3) return count;
         }
         return count;
     }
@@ -227,23 +228,23 @@ public class CalculateService {
      */
     private boolean hasFaultEvent(String thingId, long start, long end) {
         List<FaultInfo> fjInfos = fjGzMap.get(CacheContext.equipMap.get(thingId).getCode());
-        fjInfos=fjInfos==null?null:fjInfos.stream().filter(fi->timeBetweenBefore30(fi.getFaultTime().getTime(),start,end)).collect(Collectors.toList());
+        fjInfos = fjInfos == null ? null : fjInfos.stream().filter(fi -> timeBetweenBefore30(fi.getFaultTime().getTime(), start, end)).collect(Collectors.toList());
 
-        if(fjInfos!=null&&fjInfos.size()>0){
+        if (fjInfos != null && fjInfos.size() > 0) {
             Map<String, List<FaultInfo>> map = fjInfos.stream().collect(Collectors.groupingBy(FaultInfo::getAlertText));
             //判断当前故障是触发还是解除
             for (List<FaultInfo> value : map.values()) {
-                if(value.get(0).getMessageType()==1) return true;
+                if (value.get(0).getMessageType() == 1) return true;
             }
-        }else {
+        } else {
             String stationid = thingId2StationId(thingId);
             List<FaultInfo> syzInfos = syzGzMap.get(CacheContext.stationMap.get(stationid).getCode());
-            syzInfos=syzInfos==null?null:syzInfos.stream().filter(fi->timeBetweenBefore30(fi.getFaultTime().getTime(),start,end)).collect(Collectors.toList());
-            if(syzInfos!=null&&syzInfos.size()>0){
+            syzInfos = syzInfos == null ? null : syzInfos.stream().filter(fi -> timeBetweenBefore30(fi.getFaultTime().getTime(), start, end)).collect(Collectors.toList());
+            if (syzInfos != null && syzInfos.size() > 0) {
                 Map<String, List<FaultInfo>> map = syzInfos.stream().collect(Collectors.groupingBy(FaultInfo::getAlertText));
                 //判断当前故障是分位状态
                 for (List<FaultInfo> value : map.values()) {
-                    if(value.get(0).getConfirmPerson().equals("--分位状态")) return true;
+                    if (value.get(0).getConfirmPerson().equals("--分位状态")) return true;
                 }
             }
         }
@@ -309,7 +310,7 @@ public class CalculateService {
         List<List<PointData>> stationState = new ArrayList<>();
         //当前风机的场站所有风机
         List<TestingPoint> points = state8.values().stream().filter(tp -> stationId.equals(tp.getStationId())).collect(Collectors.toList());
-        points.forEach(tp->{
+        points.forEach(tp -> {
             List<PointData> valuesByKey = adapterApi.getValuesByKey(state8.get(tp.getThingId()).getCode(), start, end, 30);
             stationState.add(valuesByKey);
         });
@@ -319,7 +320,7 @@ public class CalculateService {
         for (int i = 0; i < size; i++) {
             int finalI = i;
             boolean b = stationState.stream().filter(pds -> pds.get(finalI).getDoubleValue() == starteventstate).count() == stationState.size();
-            if(b){
+            if (b) {
                 k++;
             }
             /*if(b){
@@ -347,15 +348,15 @@ public class CalculateService {
                 isBurdened = false;
             }*/
         }
-        if(k/size>9.5){
+        if (k / size > 9.5) {
             //受累
-            StateCause cause = new StateCause(stationId,thingId,stateMap.get(10.0),new Date(start),new Date(end),
-                    stateMap.get(starteventstate),stateMap.get(endeventstate),end - start);
+            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(starteventstate==5 || isHasFaultEvent(thingId,start,end)){
+        } else {//if(starteventstate==5 || 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);
+            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 {
             //计划检修
@@ -367,9 +368,10 @@ public class CalculateService {
 
     /**
      * 计算限电
+     *
      * @param equipment 设备id
-     * @param start 并网开始时间
-     * @param end 并网结束时间
+     * @param start     并网开始时间
+     * @param end       并网结束时间
      */
     private LinkedHashMap<Long, Long> calcElectricityRation(String equipment, long start, long end) {
         //满发功率和满发最小风速
@@ -378,7 +380,8 @@ public class CalculateService {
         List<PointData> speedList = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("speed").get(equipment).getCode(), start, end, 5);
         List<PointData> bladeAngleList = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("blade-angle").get(equipment).getCode(), start, end, 5);
         List<PointData> activePowerList = adapterApi.getValuesByKey(CacheContext.pointMapMap.get("active-power").get(equipment).getCode(), start, end, 5);
-        if(bladeAngleList.size()<speedList.size()||activePowerList.size()<speedList.size()) return new LinkedHashMap<>();
+        if (bladeAngleList.size() < speedList.size() || activePowerList.size() < speedList.size())
+            return new LinkedHashMap<>();
         //是否限电
         boolean isElectricityRation = false;
         //限电开始时间
@@ -401,18 +404,18 @@ public class CalculateService {
             //风速小于11并且桨叶角度大于2
             if (speedPd <= modelPower.getSpeed() && bladeAnglePd > 2) {
                 //限电首次时间
-                if(!isElectricityRation){
+                if (!isElectricityRation) {
                     ts1 = ts;
                 }
                 isElectricityRation = true;
                 //风速大于11并且有功功率小于满发功率减100
-            } else if (speedPd > modelPower.getSpeed() && activePowerPd < modelPower.getTheoryPower()-100) {
+            } else if (speedPd > modelPower.getSpeed() && activePowerPd < modelPower.getTheoryPower() - 100) {
                 //限电首次时间
-                if(!isElectricityRation){
+                if (!isElectricityRation) {
                     ts1 = ts;
                 }
                 isElectricityRation = true;
-            }else if(isElectricityRation){
+            } else if (isElectricityRation) {
                 //记录限电
                 llm.put(ts1, ts);
                 /*StateCause cause;
@@ -435,18 +438,18 @@ public class CalculateService {
         LinkedHashMap<Long, Long> llm2 = new LinkedHashMap<>();
         //限电列表key2-key1小于3分钟,记录为一个限电,大于3分钟,记录为另一个限电
         for (Map.Entry<Long, Long> entry : llm.entrySet()) {
-            if(t0==0) {
+            if (t0 == 0) {
                 t0 = entry.getKey();
                 tstart = entry.getKey();
-                tend=llm.get(t0);
+                tend = llm.get(t0);
                 continue;
             }
             t1 = entry.getKey();
             if (t1 - t0 < appConfig.getLongTime().get("ration")) {
                 tend = llm.get(t1);
-            }else {
+            } else {
                 //3分钟内的限电忽略
-                if(tend-tstart>appConfig.getLongTime().get("ration-min")){
+                if (tend - tstart > appConfig.getLongTime().get("ration-min")) {
                     llm2.put(tstart, tend);
                 }
                 tend = llm.get(t1);
@@ -454,7 +457,7 @@ public class CalculateService {
             }
             t0 = t1;
         }
-        if(tend-tstart>appConfig.getLongTime().get("ration-min")){
+        if (tend - tstart > appConfig.getLongTime().get("ration-min")) {
             llm2.put(tstart, tend);
         }
         return llm2;

+ 26 - 10
state/cause/src/test/java/com/gyee/gaia/MyAppTests.java

@@ -1,29 +1,45 @@
 package com.gyee.gaia;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gyee.gaia.cause.entity.StateCause;
-import com.gyee.gaia.cause.service.IStateCauseService;
-import com.gyee.gaia.dao.sql.point.ITestingPointService;
+import com.gyee.gaia.cause.adapter.IShardingApi;
+import com.gyee.gaia.cause.init.CacheContext;
+import com.gyee.gaia.common.data.alarm.FaultInfo;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 
 import javax.annotation.Resource;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @SpringBootTest
 class MyAppTests {
 
     @Resource
-    private ITestingPointService testingPointService;
-    @Resource
-    private IStateCauseService stateCauseService;
+    private IShardingApi shardingApi;
 
     @Test
-    void postgrepsql() {
+    void test() {
 
-        QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
+        /*QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
         scWrapper.select("max(end_time)");
-        Map<String, Object> map = stateCauseService.getMap(scWrapper);
+        Map<String, Object> map = stateCauseService.getMap(scWrapper);*/
+        List<FaultInfo> infos = shardingApi.getFaultInfoList("SYZ", "2023-05-10", "2023-05-13", CacheContext.stationMap.get("NX_GDDL_XS_FDC_STA").getCode(), null, null);
+        if (infos.size() > 0) {
+            infos = infos.stream().filter(fi -> fi.getAlertText().contains("位状态")).collect(Collectors.toList());
+            if (infos.isEmpty()) return;
+
+            Map<String, List<FaultInfo>> map = infos.stream().map(fi -> {
+                fi.setConfirmPerson(fi.getAlertText().substring(fi.getAlertText().indexOf("--")));
+                fi.setAlertText(fi.getAlertText().substring(0, fi.getAlertText().indexOf("--")));
+                return fi;
+            }).collect(Collectors.groupingBy(FaultInfo::getAlertText));
+
+            for (List<FaultInfo> value : map.values()) {
+                //判断当前故障是分位状态
+                if (value.get(0).getConfirmPerson().equals("分位状态")) return;
+            }
+        }
+
 
     }
 }

+ 7 - 0
state/cause/src/test/java/com/gyee/gaia/MyTest.java

@@ -0,0 +1,7 @@
+package com.gyee.gaia;
+
+public class MyTest {
+    public static void main(String[] args) {
+
+    }
+}

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

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.config;
+package com.gyee.gaia.electricity.wind.config;
 
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;

+ 1 - 1
state/wind/src/main/java/com/gyee/gaia/wind/config/NacosConfig.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.config;
+package com.gyee.gaia.electricity.wind.config;
 
 import lombok.Data;
 import org.springframework.beans.factory.annotation.Value;

+ 1 - 1
state/wind/src/main/java/com/gyee/gaia/wind/config/Status8Properties.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.config;
+package com.gyee.gaia.electricity.wind.config;
 
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;

+ 1 - 1
state/wind/src/main/java/com/gyee/gaia/wind/config/WindturbineGroup.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.config;
+package com.gyee.gaia.electricity.wind.config;
 
 import lombok.Data;
 

+ 3 - 3
state/wind/src/main/java/com/gyee/gaia/wind/controller/ConfigController.java

@@ -1,7 +1,7 @@
-package com.gyee.gaia.wind.controller;
+package com.gyee.gaia.electricity.wind.controller;
 
-import com.gyee.gaia.wind.config.AppConfig;
-import com.gyee.gaia.wind.entity.TestTb;
+import com.gyee.gaia.electricity.wind.config.AppConfig;
+import com.gyee.gaia.electricity.wind.entity.TestTb;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;

+ 2 - 2
state/wind/src/main/java/com/gyee/gaia/wind/controller/NacosController.java

@@ -1,7 +1,7 @@
-package com.gyee.gaia.wind.controller;
+package com.gyee.gaia.electricity.wind.controller;
 
 
-import com.gyee.gaia.wind.config.NacosConfig;
+import com.gyee.gaia.electricity.wind.config.NacosConfig;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;

+ 1 - 1
state/wind/src/main/java/com/gyee/gaia/wind/entity/StationInfo.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.entity;
+package com.gyee.gaia.electricity.wind.entity;
 
 import lombok.Getter;
 import lombok.Setter;

+ 1 - 1
state/wind/src/main/java/com/gyee/gaia/wind/entity/TagInfo.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.entity;
+package com.gyee.gaia.electricity.wind.entity;
 
 import com.gyee.gaia.common.data.timeseries.DoubleTsData;
 import lombok.Data;

+ 1 - 1
state/wind/src/main/java/com/gyee/gaia/wind/entity/TestTb.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.entity;
+package com.gyee.gaia.electricity.wind.entity;
 
 import lombok.Data;
 

+ 1 - 1
state/wind/src/main/java/com/gyee/gaia/wind/entity/WindturbineInfo.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.entity;
+package com.gyee.gaia.electricity.wind.entity;
 
 import lombok.Data;
 

+ 2 - 2
state/wind/src/main/java/com/gyee/gaia/wind/restful/RestfulClient.java

@@ -1,9 +1,9 @@
-package com.gyee.gaia.wind.restful;
+package com.gyee.gaia.electricity.wind.restful;
 
 import com.alibaba.fastjson.JSONObject;
 import com.gyee.gaia.common.data.timeseries.DoubleTsData;
 import com.gyee.gaia.common.data.timeseries.TsPointData;
-import com.gyee.gaia.wind.config.Status8Properties;
+import com.gyee.gaia.electricity.wind.config.Status8Properties;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;

+ 2 - 2
state/wind/src/main/java/com/gyee/gaia/wind/runner/ApplicationReadyEventListener.java

@@ -1,7 +1,7 @@
-package com.gyee.gaia.wind.runner;
+package com.gyee.gaia.electricity.wind.runner;
 
 
-import com.gyee.gaia.wind.service.CalculateServer;
+import com.gyee.gaia.electricity.wind.service.CalculateServer;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.ApplicationListener;

+ 6 - 6
state/wind/src/main/java/com/gyee/gaia/wind/service/CalculateServer.java

@@ -1,13 +1,13 @@
-package com.gyee.gaia.wind.service;
+package com.gyee.gaia.electricity.wind.service;
 
 import com.gyee.gaia.common.data.timeseries.DoubleTsData;
 import com.gyee.gaia.common.data.timeseries.GeneralTsData;
 import com.gyee.gaia.common.data.timeseries.TsPointData;
-import com.gyee.gaia.wind.config.Status8Properties;
-import com.gyee.gaia.wind.entity.StationInfo;
-import com.gyee.gaia.wind.entity.TagInfo;
-import com.gyee.gaia.wind.entity.WindturbineInfo;
-import com.gyee.gaia.wind.restful.RestfulClient;
+import com.gyee.gaia.electricity.wind.config.Status8Properties;
+import com.gyee.gaia.electricity.wind.entity.StationInfo;
+import com.gyee.gaia.electricity.wind.entity.TagInfo;
+import com.gyee.gaia.electricity.wind.entity.WindturbineInfo;
+import com.gyee.gaia.electricity.wind.restful.RestfulClient;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;

+ 6 - 6
state/wind/src/main/java/com/gyee/gaia/wind/service/Status8Service.java

@@ -1,4 +1,4 @@
-package com.gyee.gaia.wind.service;
+package com.gyee.gaia.electricity.wind.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.gyee.gaia.common.data.point.TestingPoint;
@@ -6,11 +6,11 @@ import com.gyee.gaia.common.data.timeseries.DoubleTsData;
 import com.gyee.gaia.common.data.windturbine.Equipment;
 import com.gyee.gaia.dao.sql.Windturbine.IEquipmentService;
 import com.gyee.gaia.dao.sql.point.ITestingPointService;
-import com.gyee.gaia.wind.config.Status8Properties;
-import com.gyee.gaia.wind.config.WindturbineGroup;
-import com.gyee.gaia.wind.entity.StationInfo;
-import com.gyee.gaia.wind.entity.TagInfo;
-import com.gyee.gaia.wind.entity.WindturbineInfo;
+import com.gyee.gaia.electricity.wind.config.Status8Properties;
+import com.gyee.gaia.electricity.wind.config.WindturbineGroup;
+import com.gyee.gaia.electricity.wind.entity.StationInfo;
+import com.gyee.gaia.electricity.wind.entity.TagInfo;
+import com.gyee.gaia.electricity.wind.entity.WindturbineInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 

+ 3 - 3
state/wind/src/main/resources/bootstrap.yaml

@@ -26,9 +26,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

+ 0 - 12
state/wind/src/main/resources/mappers-postgresql/TestTb.xml

@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.gyee.gaia.state.wind.mapper.TestTbMapper">
-
-
-    <select id="getAll" parameterType="java.util.Map" resultType="com.gyee.gaia.wind.entity.TestTb">
-        select *
-        from testtb a
-    </select>
-
-
-</mapper>

+ 18 - 0
timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/power/ModelPowerDetailsMapper.java

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

+ 21 - 0
timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/taos/RealtimeAverageTargetMapper.java

@@ -0,0 +1,21 @@
+package com.gyee.gaia.dao.taos;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.gaia.common.data.taos.RealtimeAverageTarget;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ * Mapper 接口
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-18
+ */
+@Mapper
+public interface RealtimeAverageTargetMapper extends BaseMapper<RealtimeAverageTarget> {
+
+    @Insert("insert into ${entity}")
+    int insert(String entity);
+}

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

@@ -6,7 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
 
 /**
  * <p>
- *  Mapper 接口
+ * Mapper 接口
  * </p>
  *
  * @author gfhd

+ 1 - 1
timeseries/dao-sql/build.gradle

@@ -24,5 +24,5 @@ dependencies {
     api("$bootGroup:spring-boot-starter-data-jpa:$springBootVersion")
     api("$bootGroup:spring-boot-starter-cache:$springBootVersion")
     api("$bootGroup:spring-boot-starter-jdbc:$springBootVersion")
-
+    //api("com.baomidou:dynamic-datasource-spring-boot-starter:$mybatisPlusVersion")
 }

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

@@ -7,7 +7,7 @@ import org.springframework.stereotype.Service;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author gfhd

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

@@ -5,7 +5,7 @@ import com.gyee.gaia.common.data.windturbine.Booststation;
 
 /**
  * <p>
- *  服务类
+ * 服务类
  * </p>
  *
  * @author gfhd

+ 16 - 0
timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/power/IModelPowerDetailsService.java

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

+ 19 - 0
timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/power/ModelPowerDetailsServiceImpl.java

@@ -0,0 +1,19 @@
+package com.gyee.gaia.dao.sql.power;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.gaia.common.data.power.ModelPowerDetails;
+import com.gyee.gaia.dao.power.ModelPowerDetailsMapper;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-17
+ */
+@Service
+public class ModelPowerDetailsServiceImpl extends ServiceImpl<ModelPowerDetailsMapper, ModelPowerDetails> implements IModelPowerDetailsService {
+
+}

+ 20 - 0
timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/taos/IRealtimeAverageTargetService.java

@@ -0,0 +1,20 @@
+package com.gyee.gaia.dao.sql.taos;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.gaia.common.data.taos.RealtimeAverageTarget;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 服务类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-05-18
+ */
+
+public interface IRealtimeAverageTargetService extends IService<RealtimeAverageTarget> {
+
+    int saveBatch(List<RealtimeAverageTarget> entityList);
+}

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

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

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 0
资源文件/sql/jsfw.realtime_average_target.txt


+ 24 - 0
资源文件/sql/taossql.sql

@@ -0,0 +1,24 @@
+CREATE DATABASE IF NOT EXISTS fjjsfw UPDATE 2 cacheLast 1
+
+DROP DATABASE fjjsfw;
+CREATE DATABASE IF NOT EXISTS jsfw UPDATE 2 cacheLast 1
+CREATE
+STABLE IF NOT EXISTS jsfw.realtime_average_target
+(time TIMESTAMP, wind_speed FLOAT, power FLOAT, generator_speed FLOAT, impeller_speed FLOAT, wind_direction FLOAT)
+TAGS (station_id BINARY(30),equipment_id BINARY(30),uniform_code BINARY(20), description NCHAR(50))
+CREATE TABLE realtime_average_target.USING realtime_average_target TAGS
+(,
+);
+
+
+
+CREATE TABLE IF NOT EXISTS fjjsfw.realtime_average_target
+(
+    time            TIMESTAMP,
+    equipment_id BINARY (30),
+    wind_speed      FLOAT,
+    power           FLOAT,
+    generator_speed FLOAT,
+    impeller_speed  FLOAT,
+    wind_direction  FLOAT
+);