Browse Source

1分钟平均指标计算

xushili 1 year ago
parent
commit
171fd8b67f
50 changed files with 1368 additions and 171 deletions
  1. 1 0
      .gitignore
  2. 1 1
      state/cause/src/main/java/com/gyee/gaia/cause/entity/PointData.java
  3. 95 0
      common/data/src/main/java/com/gyee/gaia/common/data/power/ModelPowerDetails.java
  4. 139 0
      common/data/src/main/java/com/gyee/gaia/common/data/taos/RealtimeAverageTarget.java
  5. 377 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/entity/EquipPowerGenDay.java
  6. 91 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/entity/MeterInfoEquipment.java
  7. 68 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/init/CacheContext.java
  8. 16 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/iservice/IEquipPowerGenDayService.java
  9. 16 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/iservice/IMeterInfoEquipmentService.java
  10. 147 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/job/CalcEquipPowerGenDay.java
  11. 18 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/mapper/EquipPowerGenDayMapper.java
  12. 10 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/mapper/MeterInfoEquipmentMapper.java
  13. 20 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/serviceimpl/EquipPowerGenDayServiceImpl.java
  14. 12 0
      electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/serviceimpl/MeterInfoEquipmentServiceImpl.java
  15. 41 0
      realtime/wind/src/main/java/com/gyee/gaia/realtime/wind/service/impl/RealtimeAverageTargetServiceImpl.java
  16. 6 0
      realtime/wind/src/main/resources/banner.txt
  17. 3 0
      settings.gradle
  18. 4 5
      state/cause/src/main/java/com/gyee/gaia/cause/adapter/AdapterApi.java
  19. 1 2
      state/cause/src/main/java/com/gyee/gaia/cause/adapter/ShardingApi.java
  20. 1 0
      state/cause/src/main/java/com/gyee/gaia/cause/entity/EquipmentInfo.java
  21. 1 2
      state/cause/src/main/java/com/gyee/gaia/cause/entity/StateCause.java
  22. 11 11
      state/cause/src/main/java/com/gyee/gaia/init/CacheContext.java
  23. 3 10
      state/cause/src/main/java/com/gyee/gaia/cause/job/CauseJobHandler.java
  24. 99 96
      state/cause/src/main/java/com/gyee/gaia/cause/service/CalculateService.java
  25. 26 10
      state/cause/src/test/java/com/gyee/gaia/MyAppTests.java
  26. 7 0
      state/cause/src/test/java/com/gyee/gaia/MyTest.java
  27. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/config/AppConfig.java
  28. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/config/NacosConfig.java
  29. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/config/Status8Properties.java
  30. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/config/WindturbineGroup.java
  31. 3 3
      state/wind/src/main/java/com/gyee/gaia/wind/controller/ConfigController.java
  32. 2 2
      state/wind/src/main/java/com/gyee/gaia/wind/controller/NacosController.java
  33. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/entity/StationInfo.java
  34. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/entity/TagInfo.java
  35. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/entity/TestTb.java
  36. 1 1
      state/wind/src/main/java/com/gyee/gaia/wind/entity/WindturbineInfo.java
  37. 2 2
      state/wind/src/main/java/com/gyee/gaia/wind/restful/RestfulClient.java
  38. 2 2
      state/wind/src/main/java/com/gyee/gaia/wind/runner/ApplicationReadyEventListener.java
  39. 6 6
      state/wind/src/main/java/com/gyee/gaia/wind/service/CalculateServer.java
  40. 6 6
      state/wind/src/main/java/com/gyee/gaia/wind/service/Status8Service.java
  41. 3 3
      state/wind/src/main/resources/bootstrap.yaml
  42. 18 0
      timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/power/ModelPowerDetailsMapper.java
  43. 21 0
      timeseries/dao-interface/src/main/java/com/gyee/gaia/dao/taos/RealtimeAverageTargetMapper.java
  44. 1 1
      timeseries/dao-sql/build.gradle
  45. 16 0
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/power/IModelPowerDetailsService.java
  46. 19 0
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/power/ModelPowerDetailsServiceImpl.java
  47. 20 0
      timeseries/dao-sql/src/main/java/com/gyee/gaia/dao/sql/taos/IRealtimeAverageTargetService.java
  48. 2 1
      timeseries/data-adapter/src/main/resources/application-nx.yaml
  49. 1 0
      资源文件/sql/jsfw.realtime_average_target.txt
  50. 24 0
      资源文件/sql/taossql.sql

+ 1 - 0
.gitignore

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

+ 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;
 
 /**
  * 测点数据

+ 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 +
+                "}";
+    }
+}

+ 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 {
+
+}

+ 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 @@
+#    # # #    # #####        #####  ######   ##   #      ##### # #    # ###### 
+#    # # ##   # #    #       #    # #       #  #  #        #   # ##  ## #      
+#    # # # #  # #    # ##### #    # #####  #    # #        #   # # ## # #####  
+# ## # # #  # # #    #       #####  #      ###### #        #   # #    # #      
+##  ## # #   ## #    #       #   #  #      #    # #        #   # #    # #      
+#    # # #    # #####        #    # ###### #    # ######   #   # #    # ###### 

+ 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"
 

+ 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(

+ 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

+ 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-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")
 }

+ 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

File diff suppressed because it is too large
+ 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
+);