From d55729d47445fcc95c0a0350a312ac84a600402f Mon Sep 17 00:00:00 2001 From: yang_shj Date: Tue, 11 Apr 2023 11:49:52 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=85=89=E4=BC=8F=E7=AB=99=E7=82=B9=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/fill/entity/GenerateEntity.java | 3 + .../hzims/operational/fill/entity/UseEntity.java | 3 + .../main/constant/HomePageConstant.java | 454 +-- .../operational/main/vo/PhotovoltaicDeviceVo.java | 11 +- .../operational/main/vo/PhotovoltaicRealVo.java | 196 ++ .../operational/main/vo/PhotovoltaicStationVo.java | 21 +- .../impl/HistoryAbnormalAlarmServiceImpl.java | 8 +- .../config/scheduled/StAlamRecordTask.java | 3 +- .../main/scheduled/ScheduledCreateTask.java | 7 +- .../operational/main/service/IHomePageService.java | 6 - .../main/service/impl/AnalyseDataServiceImpl.java | 7 +- .../main/service/impl/HomePageServiceImpl.java | 158 +- .../main/service/impl/PhotovoltaicServiceImpl.java | 2936 ++++++++++---------- .../main/service/impl/SideHustleServiceImpl.java | 27 +- .../main/service/impl/WaterServiceImpl.java | 82 +- .../main/service/impl/WebHomeServiceImpl.java | 83 +- 16 files changed, 2146 insertions(+), 1859 deletions(-) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/GenerateEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/GenerateEntity.java index 1da1247..52c1bea 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/GenerateEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/GenerateEntity.java @@ -22,6 +22,9 @@ public class GenerateEntity extends TenantEntity implements Serializable { @ApiModelProperty("站点名称") private String stationName; + @ApiModelProperty("站点来源类型: 0 - 数据采集 1 - 数据填报") + private String dataOrigin; + @ApiModelProperty("发电量") private BigDecimal generate; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java index 9611d69..6ae9334 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java @@ -22,6 +22,9 @@ public class UseEntity extends TenantEntity implements Serializable { @ApiModelProperty("站点名称") private String stationName; + @ApiModelProperty("站点数据类型: 0 - 接入站点 1 - 未接入站点") + private String dataOrigin; + @ApiModelProperty("发电量") private BigDecimal use; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java index 2a696c7..7283b3c 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java @@ -1,200 +1,298 @@ package com.hnac.hzims.operational.main.constant; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModelProperty; + import java.util.Arrays; import java.util.List; /** * 首页-常量 + * * @author 11423 */ public interface HomePageConstant { + /** + * 水电站 + */ + Integer HYDROPOWER = 0; + /** + * 风电站 + */ + Integer WIND_POWER = 1; + /** + * 水利 + */ + Integer WATER_CONSERVANCY = 2; + /** + * 储能站 + */ + Integer ENERGY_STORAGE = 3; + /** + * 配网 + */ + Integer DISTRIBUTION_NETWORK = 4; + /** + * 光伏 + */ + Integer PHOTOVOLTAIC = 5; + /** + * 水务 + */ + Integer WATER_AFFAIRS = 6; + /** + * 充电站 + */ + Integer CHARGE = 7; + /** + * 泵站 + */ + Integer PUMPING = 8; + /** + * 闸门 + */ + Integer GATE = 9; + /** + * 水利集合 + */ + List waterList = Arrays.asList(HomePageConstant.WATER_CONSERVANCY, HomePageConstant.PUMPING, HomePageConstant.GATE); + + List types = Arrays.asList(HomePageConstant.HYDROPOWER, HomePageConstant.WIND_POWER, HomePageConstant.WATER_CONSERVANCY, HomePageConstant.ENERGY_STORAGE, + HomePageConstant.DISTRIBUTION_NETWORK, HomePageConstant.PHOTOVOLTAIC, HomePageConstant.WATER_AFFAIRS, HomePageConstant.CHARGE, HomePageConstant.PUMPING, + HomePageConstant.GATE); + /** - * 水电站 - */ - Integer HYDROPOWER = 0; - /** - * 风电站 - */ - Integer WIND_POWER = 1; - /** - * 水利 - */ - Integer WATER_CONSERVANCY = 2; - /** - * 储能站 - */ - Integer ENERGY_STORAGE = 3; - /** - * 配网 - */ - Integer DISTRIBUTION_NETWORK = 4; - /** - * 光伏 - */ - Integer PHOTOVOLTAIC = 5; - /** - * 水务 - */ - Integer WATER_AFFAIRS = 6; - /** - * 充电站 - */ - Integer CHARGE = 7; - /** - * 泵站 - */ - Integer PUMPING = 8; - /** - * 闸门 - */ - Integer GATE = 9; - /** - * 水利集合 + * 实时指标 */ - List waterList = Arrays.asList(HomePageConstant.WATER_CONSERVANCY,HomePageConstant.PUMPING,HomePageConstant.GATE); + List SIGNAGES = Arrays.asList( + // 泵站、水电站 + HomePageConstant.JOINT_RELAY, HomePageConstant.SWITCH_ON_OFF, HomePageConstant.ELECTRICITY_CONSUMPTION, + HomePageConstant.ACTIVE_POWER, HomePageConstant.REACTIVE_POWER, HomePageConstant.POWER_FACTOR, HomePageConstant.VOLTAGE, HomePageConstant.CURRENT, + HomePageConstant.HYDROPOWER_GENERATE_POWER, HomePageConstant.HYDROPOWER_POWERFACTOR, HomePageConstant.HYDROPOWER_FREQUENCY, HomePageConstant.HYDROPOWER_GUIDEOPEN, + HomePageConstant.HYDROPOWER_VOLTAGE, HomePageConstant.HYDROPOWER_CURRENT, HomePageConstant.UNIT_SPEED, HomePageConstant.ACTIVE_POWER_GIVEN, HomePageConstant.REACTIVE_POWER_GIVEN, + // 光伏 + HomePageConstant.PV_GENERATION_DAY, + HomePageConstant.DIRECT_ONE, HomePageConstant.DIRECT_TWO, HomePageConstant.DIRECT_THREE, HomePageConstant.DIRECT_FOUR, HomePageConstant.DIRECT_FIVE, HomePageConstant.DIRECT_SIX, + HomePageConstant.DIRECT_SEVEN, HomePageConstant.DIRECT_EIGHT, HomePageConstant.DIRECT_NINE, HomePageConstant.DIRECT_TEN, HomePageConstant.DIRECT_ELEVEN, HomePageConstant.DIRECT_TWELVE, + HomePageConstant.DC_VOLTAGE_ONE, HomePageConstant.DC_VOLTAGE_TWO, HomePageConstant.DC_VOLTAGE_THREE, HomePageConstant.DC_VOLTAGE_FOUR, HomePageConstant.DC_VOLTAGE_FIVE, HomePageConstant.DC_VOLTAGE_SIX, + HomePageConstant.DC_VOLTAGE_SEVEN, HomePageConstant.DC_VOLTAGE_EIGHT, HomePageConstant.DC_VOLTAGE_NINE, HomePageConstant.DC_VOLTAGE_TEN, HomePageConstant.DC_VOLTAGE_ELEVEN, HomePageConstant.DC_VOLTAGE_TWELVE, + HomePageConstant.SERIES_ONE, HomePageConstant.SERIES_TWO, HomePageConstant.SERIES_THREE, HomePageConstant.SERIES_FOUR, HomePageConstant.SERIES_FIVE, HomePageConstant.SERIES_SIX, + HomePageConstant.SERIES_SEVEN, HomePageConstant.SERIES_EIGHT, HomePageConstant.SERIES_NINE, HomePageConstant.SERIES_TEN, HomePageConstant.SERIES_ELEVEN, HomePageConstant.SERIES_TWELVE, HomePageConstant.SE_VOLTAGE_ONE, + HomePageConstant.SE_VOLTAGE_TWO, HomePageConstant.SE_VOLTAGE_THREE, HomePageConstant.SE_VOLTAGE_FOUR, HomePageConstant.SE_VOLTAGE_FIVE, HomePageConstant.SE_VOLTAGE_SIX, + HomePageConstant.SE_VOLTAGE_SEVEN, HomePageConstant.SE_VOLTAGE_EIGHT, HomePageConstant.SE_VOLTAGE_NINE, HomePageConstant.SE_VOLTAGE_TEN, HomePageConstant.SE_VOLTAGE_ELEVEN, HomePageConstant.SE_VOLTAGE_TWELVE + ); - List types = Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.WIND_POWER,HomePageConstant.WATER_CONSERVANCY,HomePageConstant.ENERGY_STORAGE, - HomePageConstant.DISTRIBUTION_NETWORK,HomePageConstant.PHOTOVOLTAIC,HomePageConstant.WATER_AFFAIRS,HomePageConstant.CHARGE,HomePageConstant.PUMPING, - HomePageConstant.GATE); + /** + * 站点类型 : 运维服务 + */ + Integer HYDROPOWER_SERVETYPE = 2; - List SIGNAGES = Arrays.asList(HomePageConstant.JOINT_RELAY,HomePageConstant.SWITCH_ON_OFF,HomePageConstant.ELECTRICITY_CONSUMPTION, - HomePageConstant.ACTIVE_POWER,HomePageConstant.REACTIVE_POWER,HomePageConstant.POWER_FACTOR,HomePageConstant.VOLTAGE,HomePageConstant.CURRENT, - HomePageConstant.HYDROPOWER_GENERATE_POWER,HomePageConstant.HYDROPOWER_POWERFACTOR,HomePageConstant.HYDROPOWER_FREQUENCY,HomePageConstant.HYDROPOWER_GUIDEOPEN, - HomePageConstant.HYDROPOWER_VOLTAGE,HomePageConstant.HYDROPOWER_CURRENT,HomePageConstant.UNIT_SPEED,HomePageConstant.ACTIVE_POWER_GIVEN,HomePageConstant.REACTIVE_POWER_GIVEN, - HomePageConstant.PV_GENERATION_DAY); + /** + * 站点类型 : 云服务 + */ + Integer CLOUD_SERVETYPE = 1; - /** - * 站点类型 : 运维服务 - */ - Integer HYDROPOWER_SERVETYPE = 2; + /** + * 0-风电 + */ + Integer WIND_POWER_TYPE = 0; + /** + * 1-光伏 + */ + Integer PHOTOVOLTAIC_TYPE = 1; - /** - * 站点类型 : 云服务 - */ - Integer CLOUD_SERVETYPE = 1; + /** + * 故障 + */ + String FAULT = "fault"; + /** + * 保养 + */ + String MAINTAIN = "maintain"; + /** + * 检修 + */ + String OVERHAUL = "overhaul"; + /** + * 运行 + */ + String RUN = "run"; + /** + * 备用 + */ + String SPARE = "spare"; - /** - * 0-风电 - */ - Integer WIND_POWER_TYPE = 0; - /** - * 1-光伏 - */ - Integer PHOTOVOLTAIC_TYPE = 1; + /** + * 集团 + */ + Integer GROUP = 1; + /** + * 区域 + */ + Integer AREA = 3; + /** + * 站点 + */ + Integer STATION = 4; - /** - * 故障 - */ - String FAULT = "fault"; - /** - * 保养 - */ - String MAINTAIN = "maintain"; - /** - * 检修 - */ - String OVERHAUL = "overhaul"; - /** - * 运行 - */ - String RUN = "run"; - /** - * 备用 - */ - String SPARE = "spare"; + /** + * 有功功率 + */ + List powerList = Arrays.asList("p", "P"); - /** - * 集团 - */ - Integer GROUP = 1; - /** - * 区域 - */ - Integer AREA = 3; - /** - * 站点 - */ - Integer STATION = 4; + // 水利-泵组实时属性名称 + String JOINT_RELAY = "joint_relay"; // 开机状态 + String SWITCH_ON_OFF = "switch_on_off"; // 开机状态 + String OFF = "1"; // 开机 - /** - * 有功功率 - */ - List powerList = Arrays.asList("p","P"); - - // 水利-泵组实时属性名称 - String JOINT_RELAY = "joint_relay"; // 开机状态 - String SWITCH_ON_OFF = "switch_on_off"; // 开机状态 - String OFF = "1"; // 开机 - String ON = "0"; // 关机 - String ELECTRICITY_CONSUMPTION = "electricity_consumption"; // 用电量 - String ACTIVE_POWER = "active_power"; // 有功功率 - String REACTIVE_POWER = "reactive_power"; // 无功功率 - String POWER_FACTOR = "power_factor"; // 功率因数 - String VOLTAGE = "voltage"; // 电压 - String CURRENT = "current"; // 电流 - String UNIT_SPEED = "index_jzzs"; // 机组转速 - String ACTIVE_POWER_GIVEN = "index_ygtzgd"; // 有功调整给定 - String REACTIVE_POWER_GIVEN = "index_wgtzgd"; // 无功调整给定 - - // 水利-站点实时属性名称 - String FRONT_WATER_LEVEL = "front_water_level"; // 前水位 - String REAR_WATER_LEVEL = "rear_water_level"; // 后水位 - - // 水电站实时属性名称 - String HYDROPOWER_GENERATE_POWER = "generation_capacity"; // 发电量 - String HYDROPOWER_ACTIVE_POWER = "active_power"; // 有功功率 - String HYDROPOWER_REACTIVE_POWER = "reactive_power"; // 有功功率 - String HYDROPOWER_POWERFACTOR = "index_jz_cos"; // 功率因数 - String HYDROPOWER_FREQUENCY = "index_jz_f"; // 机组频率 - String HYDROPOWER_GUIDEOPEN = "index_dykd"; // 导叶开度 - String HYDROPOWER_VOLTAGE = "stator_voltage"; // 定子电压 - String HYDROPOWER_CURRENT = "stator_current"; // 定子电流 - - // 单位设置 - String CONCAT_P = "-P"; // 有功功率单位拼接值 - String CONCAT_Q = "-Q"; // 有功功率单位拼接值 - String CONCAT_UAB = "-UAB"; // 有功功率单位拼接值 - String CONCAT_IA = "-IA"; // 有功功率单位拼接值 -/*==========================================================================================*/ - // 设备/厂房参数 - /**ct**/ - String CT = "ct"; - /**pt**/ - String PT = "pt"; - /**装机容量**/ - String INSTALLED_CAPACITY = "installedCapacity"; -/*==========================================================================================*/ - /**站点数据配置-有功功率**/ - String P_ATTRIBUTES = "P"; -/*==========================================================================================*/ - // 光伏电站-电表-物模型监测点标识 - /**开关机状态**/ - String PV_JOINT_RELAY = "joint_relay"; - /**总有功电度**/ - String PV_GENERATION_CAPACITY = "generation_capacity"; - /**日发电量**/ - String PV_GENERATION_DAY = "generate_day"; - /**有功功率**/ - String PV_LOAD = "active_power"; - /**正向无功**/ - String PV_REACTIVE_POWER = "reactive_power"; - /**电压**/ - String PV_VOLTAGE = "voltage"; - /**电流**/ - String PV_CURRENT = "current"; - -/*==========================================================================================*/ - // 光伏指标属性 - String PHOTOVOLTAIC_OFF = "1.0"; // 开机 - - String PHOTOVOLTAIC_LOAD_TARGET = "0"; -/*==========================================================================================*/ - // 水电集团、区域指标关联 - /**功率**/ - Integer POWER = 0; -/*==========================================================================================*/ - // 水利集团、区域指标关联 - /**功率**/ - Integer LOADING = 0; + String ON = "0"; // 关机 + String ELECTRICITY_CONSUMPTION = "electricity_consumption"; // 用电量 + String ACTIVE_POWER = "active_power"; // 有功功率 + String REACTIVE_POWER = "reactive_power"; // 无功功率 + String POWER_FACTOR = "power_factor"; // 功率因数 + String VOLTAGE = "voltage"; // 电压 + String CURRENT = "current"; // 电流 + String UNIT_SPEED = "index_jzzs"; // 机组转速 + String ACTIVE_POWER_GIVEN = "index_ygtzgd"; // 有功调整给定 + String REACTIVE_POWER_GIVEN = "index_wgtzgd"; // 无功调整给定 + + // 水利-站点实时属性名称 + String FRONT_WATER_LEVEL = "front_water_level"; // 前水位 + String REAR_WATER_LEVEL = "rear_water_level"; // 后水位 + + // 水电站实时属性名称 + String HYDROPOWER_GENERATE_POWER = "generation_capacity"; // 发电量 + String HYDROPOWER_ACTIVE_POWER = "active_power"; // 有功功率 + String HYDROPOWER_REACTIVE_POWER = "reactive_power"; // 有功功率 + String HYDROPOWER_POWERFACTOR = "index_jz_cos"; // 功率因数 + String HYDROPOWER_FREQUENCY = "index_jz_f"; // 机组频率 + String HYDROPOWER_GUIDEOPEN = "index_dykd"; // 导叶开度 + String HYDROPOWER_VOLTAGE = "stator_voltage"; // 定子电压 + String HYDROPOWER_CURRENT = "stator_current"; // 定子电流 + + // 单位设置 + String CONCAT_P = "-P"; // 有功功率单位拼接值 + String CONCAT_Q = "-Q"; // 有功功率单位拼接值 + String CONCAT_UAB = "-UAB"; // 有功功率单位拼接值 + String CONCAT_IA = "-IA"; // 有功功率单位拼接值 + + // 光伏 + String DIRECT_ONE = "direct_one"; // 直流电流1 + String DIRECT_TWO = "direct_two"; // 直流电流2 + String DIRECT_THREE = "direct_three"; // 直流电流3 + String DIRECT_FOUR = "direct_four"; // 直流电流4 + String DIRECT_FIVE = "direct_five"; // 直流电流5 + String DIRECT_SIX = "direct_six"; // 直流电流6 + String DIRECT_SEVEN = "direct_seven"; // 直流电流7 + String DIRECT_EIGHT = "direct_eight"; // 直流电流8 + String DIRECT_NINE = "direct_nine"; // 直流电流9 + String DIRECT_TEN = "direct_ten"; // 直流电流10 + String DIRECT_ELEVEN = "direct_eleven"; // 直流电流11 + String DIRECT_TWELVE = "direct_twelve"; // 直流电流12 + String DC_VOLTAGE_ONE = "dc_voltage_one"; // 直流电压1 + String DC_VOLTAGE_TWO = "dc_voltage_two"; // 直流电压2 + String DC_VOLTAGE_THREE = "dc_voltage_three"; // 直流电压3 + String DC_VOLTAGE_FOUR = "dc_voltage_four"; // 直流电压4 + String DC_VOLTAGE_FIVE = "dc_voltage_five"; // 直流电压5 + String DC_VOLTAGE_SIX = "dc_voltage_six"; // 直流电压6 + String DC_VOLTAGE_SEVEN = "dc_voltage_seven"; // 直流电压7 + String DC_VOLTAGE_EIGHT = "dc_voltage_eight"; // 直流电压8 + String DC_VOLTAGE_NINE = "dc_voltage_nine"; // 直流电压9 + String DC_VOLTAGE_TEN = "dc_voltage_ten"; // 直流电压10 + String DC_VOLTAGE_ELEVEN = "dc_voltage_eleven"; // 直流电压11 + String DC_VOLTAGE_TWELVE = "dc_voltage_twelve"; // 直流电压12 + String SERIES_ONE = "series_one"; // 串流电流1 + String SERIES_TWO = "series_two"; // 串流电流2 + String SERIES_THREE = "series_three"; // 串流电流3 + String SERIES_FOUR = "series_four"; // 串流电流4 + String SERIES_FIVE = "series_five"; // 串流电流5 + String SERIES_SIX = "series_six"; // 串流电流6 + String SERIES_SEVEN = "series_seven"; // 串流电流7 + String SERIES_EIGHT = "series_eight"; // 串流电流8 + String SERIES_NINE = "series_nine"; // 串流电流9 + String SERIES_TEN = "series_ten"; // 串流电流10 + String SERIES_ELEVEN = "series_eleven"; // 串流电流11 + String SERIES_TWELVE = "series_twelve"; // 串流电流12 + String SE_VOLTAGE_ONE = "se_voltage_one"; // 串流电压1 + String SE_VOLTAGE_TWO = "se_voltage_two"; // 串流电压2 + String SE_VOLTAGE_THREE = "se_voltage_three"; // 串流电压3 + String SE_VOLTAGE_FOUR = "se_voltage_four"; // 串流电压4 + String SE_VOLTAGE_FIVE = "se_voltage_five"; // 串流电压5 + String SE_VOLTAGE_SIX = "se_voltage_six"; // 串流电压6 + String SE_VOLTAGE_SEVEN = "se_voltage_seven"; // 串流电压7 + String SE_VOLTAGE_EIGHT = "se_voltage_eight"; // 串流电压8 + String SE_VOLTAGE_NINE = "se_voltage_nine"; // 串流电压9 + String SE_VOLTAGE_TEN = "se_voltage_ten"; // 串流电压10 + String SE_VOLTAGE_ELEVEN = "se_voltage_eleven"; // 串流电压11 + String SE_VOLTAGE_TWELVE = "se_voltage_twelve"; // 串流电压12 + + /*==========================================================================================*/ + // 设备/厂房参数 + /** + * ct + **/ + String CT = "ct"; + /** + * pt + **/ + String PT = "pt"; + /** + * 装机容量 + **/ + String INSTALLED_CAPACITY = "installedCapacity"; + /*==========================================================================================*/ + /** + * 站点数据配置-有功功率 + **/ + String P_ATTRIBUTES = "P"; + /*==========================================================================================*/ + // 光伏电站-电表-物模型监测点标识 + /** + * 开关机状态 + **/ + String PV_JOINT_RELAY = "joint_relay"; + /** + * 总有功电度 + **/ + String PV_GENERATION_CAPACITY = "generation_capacity"; + /** + * 日发电量 + **/ + String PV_GENERATION_DAY = "generate_day"; + /** + * 有功功率 + **/ + String PV_LOAD = "active_power"; + /** + * 正向无功 + **/ + String PV_REACTIVE_POWER = "reactive_power"; + /** + * 电压 + **/ + String PV_VOLTAGE = "voltage"; + /** + * 电流 + **/ + String PV_CURRENT = "current"; + + /*==========================================================================================*/ + // 光伏指标属性 + String PHOTOVOLTAIC_OFF = "1.0"; // 开机 + + String PHOTOVOLTAIC_LOAD_TARGET = "0"; + /*==========================================================================================*/ + // 水电集团、区域指标关联 + /** + * 功率 + **/ + Integer POWER = 0; + /*==========================================================================================*/ + // 水利集团、区域指标关联 + /** + * 功率 + **/ + Integer LOADING = 0; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceVo.java index b4b9c05..3264158 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceVo.java @@ -35,6 +35,10 @@ public class PhotovoltaicDeviceVo { @JsonSerialize(nullsUsing = NullSerializer.class) private Double load; + @ApiModelProperty(value = "上次功率: kW") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double lastLoad; + @ApiModelProperty(value = "环比功率") @JsonSerialize(nullsUsing = NullSerializer.class) private Double loadRatio; @@ -43,11 +47,16 @@ public class PhotovoltaicDeviceVo { @JsonSerialize(nullsUsing = NullSerializer.class) private Double generate; + @ApiModelProperty(value = "日发电量: kWh") @JsonSerialize(nullsUsing = NullSerializer.class) private Double generateDay; - @ApiModelProperty(value = "环比功率") + @ApiModelProperty(value = "昨日发电量: kWh") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generationYesterday; + + @ApiModelProperty(value = "环比发电量") @JsonSerialize(nullsUsing = NullSerializer.class) private Double generateDayRatio; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicRealVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicRealVo.java index 4f265ef..3bdd639 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicRealVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicRealVo.java @@ -51,4 +51,200 @@ public class PhotovoltaicRealVo { @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastLoad; + @ApiModelProperty(value = "直流电流1") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_one; + + @ApiModelProperty(value = "直流电流2") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_two; + + @ApiModelProperty(value = "直流电流3") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_three; + + @ApiModelProperty(value = "直流电流4") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_four; + + @ApiModelProperty(value = "直流电流5") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_five; + + @ApiModelProperty(value = "直流电流6") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_six; + + @ApiModelProperty(value = "直流电流7") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_seven; + + @ApiModelProperty(value = "直流电流8") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_eight; + + @ApiModelProperty(value = "直流电流9") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_nine; + + @ApiModelProperty(value = "直流电流10") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_ten; + + @ApiModelProperty(value = "直流电流11") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_eleven; + + @ApiModelProperty(value = "直流电流12") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double direct_twelve; + + @ApiModelProperty(value = "直流电压1") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_one; + + @ApiModelProperty(value = "直流电压2") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_two; + + @ApiModelProperty(value = "直流电压3") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_three; + + @ApiModelProperty(value = "直流电压4") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_four; + + @ApiModelProperty(value = "直流电压5") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_five; + + @ApiModelProperty(value = "直流电压6") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_six; + + @ApiModelProperty(value = "直流电压7") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_seven; + + @ApiModelProperty(value = "直流电压8") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_eight; + + @ApiModelProperty(value = "直流电压9") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_nine; + + + @ApiModelProperty(value = "直流电压10") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_ten; + + @ApiModelProperty(value = "直流电压11") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_eleven; + + @ApiModelProperty(value = "直流电压12") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double dc_voltage_twelve; + + + @ApiModelProperty(value = "直流电流1") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_one; + + @ApiModelProperty(value = "直流电流2") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_two; + + @ApiModelProperty(value = "直流电流3") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_three; + + @ApiModelProperty(value = "直流电流4") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_four; + + @ApiModelProperty(value = "直流电流5") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_five; + + @ApiModelProperty(value = "直流电流6") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_six; + + @ApiModelProperty(value = "直流电流7") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_seven; + + @ApiModelProperty(value = "直流电流8") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_eight; + + @ApiModelProperty(value = "直流电流9") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_nine; + + + @ApiModelProperty(value = "直流电流10") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_ten; + + @ApiModelProperty(value = "直流电流11") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_eleven; + + @ApiModelProperty(value = "直流电流12") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double series_twelve; + + @ApiModelProperty(value = "直流电压1") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_one; + + @ApiModelProperty(value = "直流电压2") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_two; + + @ApiModelProperty(value = "直流电压3") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_three; + + @ApiModelProperty(value = "直流电压4") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_four; + + @ApiModelProperty(value = "直流电压5") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_five; + + @ApiModelProperty(value = "直流电压6") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_six; + + @ApiModelProperty(value = "直流电压7") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_seven; + + @ApiModelProperty(value = "直流电压8") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_eight; + + @ApiModelProperty(value = "直流电压9") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_nine; + + + @ApiModelProperty(value = "直流电压10") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_ten; + + @ApiModelProperty(value = "直流电压11") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_eleven; + + @ApiModelProperty(value = "直流电压12") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double se_voltage_twelve; + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationVo.java index a516548..8138281 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationVo.java @@ -50,10 +50,22 @@ public class PhotovoltaicStationVo { @JsonSerialize(nullsUsing = NullSerializer.class) private Double load; + @ApiModelProperty(value = "环比功率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double loadRatio; + @ApiModelProperty(value = "日发电量") @JsonSerialize(nullsUsing = NullSerializer.class) private Double generateDay; + @ApiModelProperty(value = "昨日发电量: kWh") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generationYesterday; + + @ApiModelProperty(value = "环比发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generateDayRatio; + @ApiModelProperty(value = "月发电量") @JsonSerialize(nullsUsing = NullSerializer.class) private Double generateMon; @@ -81,9 +93,12 @@ public class PhotovoltaicStationVo { @ApiModelProperty(value = "发电排行") private List devices; - @ApiModelProperty(value = "年发电量完成百分比") - private List generateSurvey; - @ApiModelProperty(value = "设备信息") private List charts; + + @ApiModelProperty(value = "当日机组有功功率") + private List activePowerVoList; + + @ApiModelProperty(value = "近30天用电量") + private List generationPowerVoList; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java index 0ad4b3e..e28aaa2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.fasterxml.jackson.core.type.TypeReference; import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; @@ -23,6 +24,7 @@ import com.hnac.hzinfo.datasearch.soe.domian.SoeData; import com.hnac.hzinfo.datasearch.soe.domian.SoeQueryConditionByStation; import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; +import com.hnac.hzinfo.sdk.core.utils.JsonUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import net.logstash.logback.encoder.org.apache.commons.lang3.ObjectUtils; @@ -231,12 +233,13 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl> result = alarmClient.getByStationsAndTime(condition); if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())){ @@ -277,6 +280,7 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl */ - @XxlJob(ELECTRICITY_GENERATION_RECENT_YEAR) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT powerGenerationRecentYear(String param) throws Exception { + //@XxlJob(ELECTRICITY_GENERATION_RECENT_YEAR) + @Scheduled(cron = "0/40 * * * * ? ") + public ReturnT powerGenerationRecentYear() throws Exception { + String param = ""; if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IHomePageService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IHomePageService.java index 1ed52cf..8a641ed 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IHomePageService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IHomePageService.java @@ -44,12 +44,6 @@ public interface IHomePageService { List getChildArea(List departList, Long deptId,List list); - float getPowerGeneration(List list, String startTime, String endTime,Integer cycleType); - - float getEmInfoPower(EminfoAndEmParamVo em, String startTime, String endTime,Integer cycleType); - - float getAnalyzeCodeAndSignages(EminfoAndEmParamVo em, String startTime, String endTime, Integer cycleType, String signages); - List planActualTrend(Long deptId); List homeStation(Long deptId); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java index c7acf95..8b44a39 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java @@ -21,10 +21,7 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Random; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -128,7 +125,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { return 0f; } - return Float.parseFloat(analyseDataTaosVO.getVal()) * ride; + return Float.parseFloat(Optional.ofNullable(analyseDataTaosVO.getVal()).orElse("0")) * ride; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java index e2fc91b..a2b0b17 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java @@ -3,7 +3,6 @@ package com.hnac.hzims.operational.main.service.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.equipment.entity.PlanGenerationEntity; import com.hnac.hzims.equipment.feign.IPlanGenertionClient; import com.hnac.hzims.equipment.vo.EmInfoExtendVo; @@ -11,23 +10,19 @@ import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.monitor.utils.DateUtils; import com.hnac.hzims.operational.fill.entity.*; import com.hnac.hzims.operational.fill.service.*; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzims.operational.main.service.IHomePageService; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; import com.hnac.hzims.operational.main.service.IMainTaskStatisticService; import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient; import com.hnac.hzims.ticket.allTicket.vo.DoublePassRateVO; import com.hnac.hzims.ticket.allTicket.vo.DoublePassVO; -import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.IAnalyseInstanceClient; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; import com.hnac.hzinfo.datasearch.soe.ISoeClient; import com.hnac.hzinfo.datasearch.soe.domian.SoeData; import com.hnac.hzinfo.sdk.core.response.Result; @@ -70,7 +65,6 @@ import java.util.stream.Collectors; @Slf4j public class HomePageServiceImpl implements IHomePageService { - private final IAnalyseDataService analyseDataService; private final IPlanGenertionClient planGenertionClient; private final IMainSystemMonitoringService maintenanceTaskService; @@ -229,7 +223,7 @@ public class HomePageServiceImpl implements IHomePageService { List stationList = stationService.getStationType(serveType, types, null); // 设备信息 List devices = maintenanceTaskService.getEmInfoList(); - // 开始事件 + // 开始时间 Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); @@ -390,18 +384,26 @@ public class HomePageServiceImpl implements IHomePageService { double installedCapacity = getInstalledCapacity(equipmentInfoList, station); powerStationTotalVo.setInstalledCapacity(installedCapacity); // 当月发电量 - String startTime = DateUtil.format(new Date(),"yyyy-MM") + "-01 00:00:00"; - String endTime = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); - float powerGeneration = this.getPowerGeneration(effEmInfoList, startTime, endTime,EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType()); + String start = DateUtil.format(new Date(),"yyyy-MM") + "-01 00:00:00"; + String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); + float powerGeneration = this.generateByDevices(effEmInfoList, start, end,5); powerStationTotalVo.setPowerGeneration((double)powerGeneration); // 计划发电量 double plannedPowerGeneration = this.getPlannedPowerGeneration(planGenerationEntityList, station); powerStationTotalVo.setPlannedPowerGeneration(plannedPowerGeneration); // 当年发电量 - float currentYearPowerGeneration = getPlannedYearGeneration(effEmInfoList); + end = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.DAY_OF_MONTH,-calendar.get(Calendar.DAY_OF_MONTH)); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND,-calendar.get(Calendar.SECOND)); + start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + float currentYearPowerGeneration = this.generateByDevices(effEmInfoList, start+ " 00:00:00", end + " 00:00:00",6);; powerStationTotalVo.setCurrentYearPowerGeneration(currentYearPowerGeneration); // 当日发电量 - float currentDayPowerGeneration = getPowerGeneration(effEmInfoList, getCurrentTime() + " 00:00:00", getAddDayTime(1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType()); + float currentDayPowerGeneration = this.generateByDevices(effEmInfoList, getCurrentTime() + " 00:00:00", getAddDayTime(1) + " 00:00:00",3); powerStationTotalVo.setCurrentDayPowerGeneration(currentDayPowerGeneration); // 告警列表 Result> S = soeClient.getByLastLimitTime(null, station.getCode(), 1); @@ -413,6 +415,24 @@ public class HomePageServiceImpl implements IHomePageService { } /** + * 获取设备发电量 + * @param devices + * @param start + * @param end + * @return + */ + private float generateByDevices(List devices, String start, String end,int accessRules) { + float generate = 0f; + if(CollectionUtil.isEmpty(devices)){ + return generate; + } + for(EminfoAndEmParamVo device : devices ){ + generate += analyseDataService.periodTargetFloat(start,end,accessRules,5,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + }; + return generate; + } + + /** * 获取站点装机容量 * * @param equipmentInfoList @@ -446,96 +466,6 @@ public class HomePageServiceImpl implements IHomePageService { /** - * 获取发电量 - * - * @param list - * @param startTime - * @param endTime - * @return - */ - @Override - public float getPowerGeneration(List list, String startTime, String endTime,Integer cycleType) { - float allPower = 0F; - for (EminfoAndEmParamVo em : list) { - float power = this.getEmInfoPower(em, startTime, endTime,cycleType); - allPower += power; - } - return allPower; - } - - /** - * 获取发电量 - * - * @param em - * @param startTime - * @param endTime - * @return - */ - @Override - public float getEmInfoPower(EminfoAndEmParamVo em, String startTime, String endTime,Integer cycleType) { - return this.getAnalyzeCodeAndSignages(em,startTime,endTime,cycleType,GENERATE_ELECTRICITY); - } - - /** - * - * @param em - * @param startTime - * @param endTime - * @param cycleType - * @param signages - * @return - */ - @Override - public float getAnalyzeCodeAndSignages(EminfoAndEmParamVo em, String startTime, String endTime, Integer cycleType, String signages) { - // FIXME 光伏测试 - Random random = new Random(); - return random.nextFloat() * 250000; - /*// 发电量 - float aFloat = 0F; - AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); - List signboardConditions = new ArrayList<>(); - AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); - analyzeDataConditionPO.setFull(1); - analyzeDataConditionPO.setSignages(signages); - // 取数规则: 0=(整点值/最早值)、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值) 6=最新值 - analyzeDataConditionPO.setAccessRules(EquipmentConstants.AccessRulesEnum.DIFF_CYCLE.getType()); - // 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时)3->、d(天)4->、w(周)5->、n(自然月)、6->y(自然年) - analyzeDataConditionPO.setSaveTimeType(cycleType); - // 间隔 - analyzeDataConditionPO.setTimeInterval(1); - analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); - analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); - signboardConditions.add(analyzeDataConditionPO); - po.setDeviceCode(em.getEmCode()); - po.setSignboardConditions(signboardConditions); - R> analyzeData = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); - if (!analyzeData.isSuccess() || CollectionUtil.isEmpty(analyzeData.getData())) { - return aFloat; - } - List records = analyzeData.getData(); - AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0); - if (ObjectUtil.isEmpty(analyzeDataConditionVO)) { - return aFloat; - } - List analyseDataTaosVOList = analyzeDataConditionVO.getList(); - if (CollectionUtil.isEmpty(analyseDataTaosVOList)) { - return aFloat; - } - AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0); - if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { - return aFloat; - } - float childFloat = Float.parseFloat(analyseDataTaosVO.getVal()); - if (0 != em.getRideCount()) { - //获取发电量的值 且 * rideCount - aFloat = childFloat * em.getRideCount(); - } else { - aFloat = childFloat; - } - return aFloat;*/ - } - - /** * 年计划发电完成趋势 * @param deptId * @return @@ -641,27 +571,6 @@ public class HomePageServiceImpl implements IHomePageService { return planFloat; } - - /** - * 查询站点当年实际发电量 - * - * @param effEmInfoList - * @return - */ - private float getPlannedYearGeneration(List effEmInfoList) { - Calendar calendar = Calendar.getInstance(); - //记得要+1 - int month = calendar.get(Calendar.MONTH) + 1; - List monList = this.getMonthList(0, month,true); - float power = 0f; - for (int i = 0; i < monList.size() - 1; i++) { - float monthPower = getPowerGeneration(effEmInfoList, monList.get(i) + " 00:00:00", monList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType()); - power = power + monthPower; - } - return power; - } - - /** * 关键指标 - 发电站 * @@ -1498,7 +1407,6 @@ public class HomePageServiceImpl implements IHomePageService { } - /** * 获取近年月份集合 * @param year diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java index ff2ea0d..34b382e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java @@ -60,1160 +60,1195 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class PhotovoltaicServiceImpl implements PhotovoltaicService { - private final IStationService stationService; - - private final IMainSystemMonitoringService deviceService; - - private final ISideHustleService sideHustleService; - - private final IHomePageService homePageService; - - private final IWeatherService weatherService; - - private final IAnalyseDataService analyseDataService; - - private final IHistoryDataSearchClient historySearchClient; - - private final IMainTaskStatisticService taskService; - - private final ISysClient sysClient; - - private final ITicketInfoClient ticketInfoClient; - - private final RedisTemplate redisTemplate; - - private final static String load_photovoltaic_real_key = "hzims:operation:photovoltaic:real:key"; - - private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key"; - - private final static String recent_year_power_data = "hzims:operation:key:power:data"; - - @Value("${hzims.operation.realIdKey}") - public String real_id_key; - - // 线程数量 - private final static int POOL_QUANTITY = 4; - - /** - * 光伏站-逆变器实时加载 - * - * @param param - */ - @Override - public void loadPhotovoltaicReal(String param) { - // 查询设备 - List devices = this.getPhotovoltaicDevice(); - if (CollectionUtil.isEmpty(devices)) { - return; - } - // 取redis实时数据 - Map map = this.getRealData(); - if(MapUtils.isEmpty(map)){ - return; - } - // redis缓存设备实时数据 - List history = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); - // 设备实时数据 - List list = devices.stream().map(device -> { - PhotovoltaicRealVo real = new PhotovoltaicRealVo(); - real.setDeptId(device.getCreateDept()); - real.setDeviceCode(device.getEmCode()); - real.setDeviceName(device.getName()); - real.setState(this.getPhotovoltaicState(device,map)); - // 容量 - real.setCapacity(device.getInstalledCapacity()); - // 发电量 - real.setGenerate(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_GENERATION_CAPACITY))); - // 功率 - real.setLoad(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_LOAD))); - // 电压 - real.setVoltage(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_VOLTAGE))); - // 电流 - real.setCurrent(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_CURRENT))); - // 上次功率 - real.setLastLoad(this.getLastLoad(device,history)); - return real; - }).collect(Collectors.toList()); - // 存储redis - redisTemplate.opsForValue().set(load_photovoltaic_real_key, list); - } - - /** - * 光伏站-逆变器指标加载 - * - * @param param - */ - @Override - public void loadPhotovoltaicTarget(String param) { - // 有效设备 - List devices = this.getPhotovoltaicDevice(); - if (CollectionUtil.isEmpty(devices)) { - return; - } - List list = new ArrayList<>(); - devices.forEach(device -> { - PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); - target.setDeptId(device.getCreateDept()); - target.setDeviceCode(device.getEmCode()); - target.setDeviceName(device.getName()); - target.setDeptName(device.getName()); - // 当日运行时长 - //target.setRunHours(this.runHours(device.getPoint().get(HomePageConstant.PV_JOINT_RELAY))); - // 年发电量 - target.setGenerationYear((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"0")); - // 月发电量 - target.setGenerationMon((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"1")); - // 日发电量 - target.setGenerationDay((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"2")); - // 昨日发电量 - target.setGenerationYesterday((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"3")); - // 收益 - target.setIncome(target.getGenerationDay() * 0.34); - // 节约标准煤 - target.setTec(target.getGenerationMon() * 0.0001229); - // 二氧化碳减排 - target.setCo2(target.getGenerationMon() * 0.000997); - // 减少森林砍伐 - target.setDeforest(target.getGenerationMon() * 0.000553); - // 当天有功功率 - target.setActivePowerVoList(this.getLoadsByDay(device)); - // 30天发电量 - target.setGenerationPowerVoList(this.getGenerateByMon(device)); - list.add(target); - }); - redisTemplate.opsForValue().set(load_photovoltaic_target_key, list); - } - - /** - * 当天有功功率 - * @param device - * @return - */ - private List getLoadsByDay(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; - String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - List records = analyseDataService.periodTargetData(start,end,1,2,device.getEmCode(),HomePageConstant.PV_LOAD); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - return records.stream().map(record -> { - PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - load.setHour(time.getHours()); - load.setActivePower(Optional.ofNullable(record.getVal()).orElse("0")); - return load; - }).sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList()); - } - - /** - * 近30天发电量 - * @param device - * @return - */ - private List getGenerateByMon(EminfoAndEmParamVo device) { - Calendar calendar = Calendar.getInstance(); - String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); - calendar.add(Calendar.DAY_OF_MONTH, -29); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); - List records = analyseDataService.periodTargetData(start,end,5,3,device.getEmCode(),HomePageConstant.PV_GENERATION_CAPACITY); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - return records.stream().map(record -> { - GenerationPowerVo generate = new GenerationPowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); - generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); - return generate; - }).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()); - } - - - /** - * 根据事件查询数据值 - * @param deviceCode - * @param rideCount - * @param type - * @return - */ - private float sumValueByTime(String deviceCode, int rideCount,String type) { - Calendar calendar = Calendar.getInstance(); - String start = null,end = null; - Integer cycleType = 3; - switch (type){ - //年 - case "0": - calendar.add(Calendar.HOUR_OF_DAY, + 1); - end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - calendar.setTime(new Date()); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DAY_OF_MONTH, -calendar.get(Calendar.DATE) + 1); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - cycleType = 6; - break; - //月 - case "1": - start = DateUtil.format(new Date(),"yyyy-MM") + "-01 00:00:00"; - end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - cycleType = 5; - break; - //日 - case "2": - start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; - end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - break; - //昨日 - case "3": - calendar.add(Calendar.DAY_OF_MONTH, - 1); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - end = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; - break; - } - return analyseDataService.periodTargetFloat(start,end,5,cycleType,deviceCode,rideCount,HomePageConstant.PV_GENERATION_CAPACITY); - } - - /** - * 获取上一次功率 - * @param device - * @param history - * @return - */ - private Double getLastLoad(EminfoAndEmParamVo device, List history) { - if(CollectionUtil.isEmpty(history)){ - return 0.0; - } - List historyDevice = history.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(historyDevice)){ - return 0.0; - } - return historyDevice.get(0).getLoad(); - } - - /** - * 获取开机状态 - * @param device - * @return - */ - private int getPhotovoltaicState(EminfoAndEmParamVo device,Map map) { - // 获取开关机监测点实时数据 - String value = this.getSignageValue(device,map,HomePageConstant.PV_JOINT_RELAY); - // 开机状态 - if (HomePageConstant.OFF.equals(value)) { - return 0; - } - return 1; - } - - /** - * 获取监测点实时数据 - * @param em - * @param map - * @param targets - * @return - */ - private String getSignageValue(EminfoAndEmParamVo em,Map map, String targets) { - if(ObjectUtil.isEmpty(em) || MapUtils.isEmpty(map)){ - return "0"; - } - Map point = em.getPoint(); - if(MapUtils.isEmpty(point)){ - return "0"; - } - String realId = point.get(targets); - if(StringUtil.isEmpty(realId)){ - return "0"; - } - String value = map.get(realId); - if(StringUtil.isEmpty(realId)){ - return "0"; - } - // 获取value - return value; - } - - /** - * 当天运行时长 - * - * @param realId - * @return - */ - private Double runHours(String realId) { - Calendar calendar = Calendar.getInstance(); - Date end = calendar.getTime(); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - Date start = calendar.getTime(); - OriginalDataQuery originalDataQuery = new OriginalDataQuery(); - originalDataQuery.setRealId(realId); - originalDataQuery.setBeginTime(start); - originalDataQuery.setEndTime(end); - originalDataQuery.setLimit(100000); - originalDataQuery.setPage(1); - // 查询时间范围开关机监测点历史数据 - Result> R = historySearchClient.getOriginalDataByRealIds(originalDataQuery); - if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { - return 0.0; - } - // 过滤相邻开关机状态相同数据 - List result = this.filterData(R.getData().getRecords()); - if (CollectionUtil.isEmpty(result)) { - return 0.0; - } - // 开机运行时长 - long time = this.runTime(result, start, end); - return BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - } - - /** - * 当天运行时长 - * - * @return - */ - private List getDayHours() { - List list = new ArrayList<>(); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - // 获取时间 - while (calendar.getTime().compareTo(new Date()) <= 0) { - list.add(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); - calendar.add(Calendar.HOUR_OF_DAY, +1); - } - return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); - } - - - /** - * 过滤相邻开关机状态相同数据 - * - * @param list - * @return - */ - private List filterData(List list) { - if (CollectionUtil.isEmpty(list)) { - return null; - } - List result = new ArrayList<>(); - // 遍历数据 - for (int i = 0; i < list.size(); i++) { - // 第一个数据保存下来 - if (i == 0) { - result.add(list.get(i)); - continue; - } - // 遍历数据状态 - String value = list.get(i).getValue(); - if (StringUtil.isBlank(value)) { - continue; - } - // 上一条数据状态 - String up_value = list.get(i - 1).getValue(); - if (value.equals(up_value)) { - continue; - } - result.add(list.get(i)); - } - return result; - } - - /** - * 获取运行时长 - * - * @param result - * @return - */ - private long runTime(List result, Date startDate, Date endDate) { - if (result.size() == 1) { - // 一直开机 - if (HomePageConstant.PHOTOVOLTAIC_OFF.equals(result.get(0).getValue())) { - return endDate.getTime() - startDate.getTime(); - } - // 一直关机 - return 0; - } - long time = 0; - // 遍历累计开机时长 - for (int i = 0; i < result.size(); i++) { - // 记录为开机状态 就计算到下次关机的时间差 - if (HomePageConstant.ON.equals(result.get(i).getValue())) { - continue; - } - Date endTime, startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); - // 遍历至最后一条数据,累计至当前时间 - if (i == result.size() - 1) { - endTime = endDate; - } else { - endTime = DateUtil.parse(result.get(i + 1).getTime(), DateUtil.PATTERN_DATETIME); - } - time += endTime.getTime() - startTime.getTime(); - } - return time; - } - - - /** - * 获取年、月、日发电量 - * - * @param device - * @param scope - * @return - */ - private float getGenerationPower(EminfoAndEmParamVo device, int scope) { - // 日期格式化yyyy-mm-dd - SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); - // 日期格式化yyyy-mm-dd - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); - String startTime, endTime; - int cycle; - switch (scope) { - // 年 - case 0: - Calendar calendar = Calendar.getInstance(); - endTime = sdf.format(calendar.getTime()); - calendar.setTime(new Date()); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - startTime = df.format(calendar.getTime()) + " 00:00:00"; - cycle = EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(); - break; - // 月 - case 1: - startTime = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - endTime = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - cycle = EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(); - break; - // 日 - case 2: - Calendar cal = Calendar.getInstance(); - String time = df.format(cal.getTime()); - startTime = time + " 00:00:00"; - endTime = time + " 23:59:59"; - cycle = EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(); - break; - default: - throw new IllegalStateException("Unexpected value: " + scope); - } - return homePageService.getAnalyzeCodeAndSignages(device, startTime, endTime, cycle, HomePageConstant.PV_GENERATION_CAPACITY); - } - - /** - * 当天功率 - * - * @return - */ - private List getTestDay() { - // 日期格式化yyyy-mm-dd - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH"); - List list = new ArrayList<>(); - // 开始日期 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.HOUR_OF_DAY, +1); - list.add(df.format(calendar.getTime())); - // 获取时间 - while (calendar.getTime().compareTo(new Date()) <= 0) { - calendar.add(Calendar.HOUR_OF_DAY, +1); - list.add(df.format(calendar.getTime())); - } - return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); - } - - /** - * 获取近30天集合 - * - * @return - */ - private List getRecentWeek() { - // 日期格式化yyyy-mm-dd - SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); - List list = new ArrayList<>(); - // 开始日期 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.add(Calendar.DATE, +1); - list.add(df.format(calendar.getTime())); - // 获取日期之间的月 - int i = 0; - while (i <= 7) { - list.add(df.format(calendar.getTime())); - calendar.add(Calendar.DATE, -1); - i++; - } - return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); - } - - /** - * 获取实时数据 - * - * @return - */ - private Map getRealData() { - String json = (String) redisTemplate.opsForValue().get(real_id_key); - if (StringUtil.isBlank(json)) { - return null; - } - return JSONObject.parseObject(json, new TypeReference>() { - }); - } - - /** - * 获取光伏设备 - * - * @return - */ - private List getPhotovoltaicDevice() { - // 光伏站点 - List stations = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), null); - if (CollectionUtil.isEmpty(stations)) { - return null; - } - // 设备 - List devices = deviceService.getEmInfoList(); - if (CollectionUtil.isEmpty(devices)) { - return null; - } - return devices.stream().filter(device -> - stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(device.getCreateDept()) - ).collect(Collectors.toList()); - } - - /** - * 集团/区域关键指标 - * - * @param deptId - * @return - */ - @Override - public PhotovoltaicKPIsVo KPIs(Long deptId) { - // 查询光伏站点 - List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); - if (CollectionUtil.isEmpty(stations)) { - return new PhotovoltaicKPIsVo(); - } - PhotovoltaicKPIsVo kpi = new PhotovoltaicKPIsVo(); - // 站点数量 - kpi.setCount(stations.size()); - // 实时数据 - List deviceReals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); - if (CollectionUtil.isNotEmpty(deviceReals)) { - List reals = deviceReals.stream().filter(device -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(device.getDeptId())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(reals)) { - // 容量 - kpi.setInstalledCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); - // 负荷 - kpi.setLoad(reals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); - } - } - // 指标数据 - List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - if (CollectionUtil.isEmpty(deviceTargets)) { - return kpi; - } - List targets = deviceTargets.stream().filter(device -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(device.getDeptId())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(targets)) { - return kpi; - } - // 年发电量 - kpi.setPowerYear(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum()); - // 月发电量 - kpi.setPowerMon(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationMon).sum()); - // 日发电量 - kpi.setPowerDay(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationDay).sum()); - // 节约标准煤 - kpi.setTec(targets.stream().mapToDouble(PhotovoltaicTargetVo::getTec).sum()); - // CO2减排 - kpi.setCo2(targets.stream().mapToDouble(PhotovoltaicTargetVo::getCo2).sum()); - // 减少森林砍伐 - kpi.setDeforest(targets.stream().mapToDouble(PhotovoltaicTargetVo::getDeforest).sum()); - // 近3年发电量 - kpi.setPowerYearVoList(this.getPowerList(stations.stream().map(StationEntity::getId).collect(Collectors.toList()))); - return kpi; - } - - /** - * 获取近3年发电量 - * - * @return - */ - private List getPowerList(List stations) { - // 站点近年发电数据 key - stationCode value - 月份,发电量 - Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); - if (MapUtils.isEmpty(map)) { - return new ArrayList<>(); - } - List> filter = map.entrySet().stream().filter(e -> stations.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(filter)) { - return new ArrayList<>(); - } - // 根据月份分组 - List powerMonthVos = new ArrayList<>(); - filter.forEach(item -> { - item.forEach((key, value) -> { - PowerMonthVo powerMonthVo = new PowerMonthVo(); - powerMonthVo.setStrMonth(key); - powerMonthVo.setPower(value); - powerMonthVos.add(powerMonthVo); - }); - }); - Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); - // 总和所有相同月份的发电量 - List powerMonthVoList = months.entrySet().stream().map(entry -> { - PowerMonthVo powerMonth = new PowerMonthVo(); - powerMonth.setStrMonth(entry.getKey()); - LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), entry.getKey()), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - powerMonth.setYear(localDate.getYear()); - powerMonth.setMonth(localDate.getMonthValue()); - powerMonth.setPower((float) entry.getValue().stream().mapToDouble(PowerMonthVo::getPower).sum()); - return powerMonth; - }).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(powerMonthVoList)) { - return new ArrayList<>(); - } - // 根据年份分组 - Map> year = powerMonthVoList.stream().collect(Collectors.groupingBy(PowerMonthVo::getYear)); - // 返回结果集 - return year.entrySet().stream().map(entry -> { - PowerYearVo powerYearVo = new PowerYearVo(); - powerYearVo.setYear(entry.getKey()); - List sortValue = entry.getValue().stream().sorted(Comparator.comparing(PowerMonthVo::getMonth)).collect(Collectors.toList()); - powerYearVo.setPowerMonthVoList(sortValue); - return powerYearVo; - }).collect(Collectors.toList()); - } - - /** - * 集团/区域发电量 - * - * @param deptId - * @param type - * @return - */ - @Override - public List generation(Long deptId, String type) { - // 查询光伏站点 - List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); - if (CollectionUtil.isEmpty(stations)) { - return new ArrayList<>(); - } - switch (type) { - // 周 - case "0": - return this.getGeneration(stations.stream().map(StationEntity::getRefDept).distinct().collect(Collectors.toList()), true); - // 月 - case "1": - return this.getGeneration(stations.stream().map(StationEntity::getRefDept).distinct().collect(Collectors.toList()), false); - // 年 - case "2": - return this.getGenerationYear(stations.stream().map(StationEntity::getId).distinct().collect(Collectors.toList())); - default: - throw new ServiceException("无效查询类型!"); - } - } - - /** - * 获取发电量(周/月) - * - * @return - */ - private List getGeneration(List stations, boolean flag) { - // redis实时数据 - List photovoltaics = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - if (CollectionUtil.isEmpty(photovoltaics)) { - return new ArrayList(); - } - // 过滤有效光伏设备 - List filters = photovoltaics.stream().filter(photovoltaic -> stations.contains(photovoltaic.getDeptId())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(filters)) { - return new ArrayList<>(); - } - // 数据集合 - List generations = new ArrayList<>(); - for (PhotovoltaicTargetVo target : filters) { - if (CollectionUtil.isEmpty(target.getGenerationPowerVoList())) { - continue; - } - generations.addAll(target.getGenerationPowerVoList()); - } - if (CollectionUtil.isEmpty(generations)) { - return new ArrayList<>(); - } - List weeks = this.getRecentWeek(); - // 周 - if (flag) { - // 根据日期分组 - return generations.stream().filter(generation -> weeks.contains(generation.getDate())).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { - GenerationVo generation = new GenerationVo(); - generation.setPeriod(entry.getKey()); - generation.setPower((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerate).sum()); - return generation; - }).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); - } - // 月 - return generations.stream().collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { - GenerationVo generation = new GenerationVo(); - generation.setPeriod(entry.getKey()); - generation.setPower((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerate).sum()); - return generation; - }).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); - } - - /** - * 获取发电量(年) - * - * @return - */ - private List getGenerationYear(List stations) { - // 站点近年发电数据 key - stationCode value - 月份,发电量 - Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); - if (MapUtils.isEmpty(map)) { - return new ArrayList<>(); - } - List> filter = map.entrySet().stream().filter(e -> stations.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(filter)) { - return new ArrayList<>(); - } - // 根据月份分组 - List powerMonthVos = new ArrayList<>(); - filter.forEach(item -> { - item.forEach((key, value) -> { - PowerMonthVo powerMonthVo = new PowerMonthVo(); - powerMonthVo.setStrMonth(key); - powerMonthVo.setPower(value); - powerMonthVos.add(powerMonthVo); - }); - }); - Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); - // 总和所有相同月份的发电量 - String year = String.valueOf(LocalDate.now().getYear()); - return months.entrySet().stream().filter(entry -> entry.getKey().contains(year)).map(entry -> { - GenerationVo generation = new GenerationVo(); - generation.setPeriod(entry.getKey()); - generation.setPower((float) entry.getValue().stream().mapToDouble(PowerMonthVo::getPower).sum()); - return generation; - }).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); - } - - - /** - * 集团/区域下属数据占比 - * - * @param deptId - * @return - */ - @Override - public List subordinate(Long deptId) { - // 获取区域或者站点map结构 - Map> map = sideHustleService.getAreaOrStaion(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); - if (MapUtils.isEmpty(map)) { - return new ArrayList<>(); - } - // 实时数据 - List deviceReals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); - // 指标数据 - List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - // 遍历数据 - List list = new ArrayList<>(); - for (Map.Entry> entry : map.entrySet()) { - PhotovoltaicSubordinateVo subordinate = new PhotovoltaicSubordinateVo(); - if (ObjectUtil.isEmpty(entry.getValue())) { - continue; - } - subordinate.setDeptId(entry.getKey().getId()); - subordinate.setDeptName(entry.getKey().getDeptName()); - subordinate.setSort(entry.getKey().getSort()); - // 获取第一个站点经纬度、行政编码信息 - StationEntity station = entry.getValue().get(0); - subordinate.setLttd(station.getLttd()); - subordinate.setLgtd(station.getLgtd()); - // 省市编码 - String areaCode = station.getAreaCode(); - subordinate.setAreaCode(areaCode); - if (!StringUtil.isEmpty(areaCode)) { - String[] arrCode = areaCode.split(","); - R R = sysClient.getRegion(arrCode[1]); - if (R.isSuccess() && ObjectUtil.isNotEmpty(R.getData())) { - subordinate.setAreaName(R.getData().getName()); - } - } - // 获取实时天气 - Map nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); - if (MapUtils.isNotEmpty(nowWeather)) { - subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); - } - // 获取七天天气 - Map weekWeather = weatherService.getWeekWeather(Collections.singletonList(station.getCode())); - if (MapUtils.isNotEmpty(weekWeather)) { - subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); - } - subordinate.setWeather(weekWeather.get(station.getCode()).getDaily()); - // 区域/站点 设备实时数据 - List reals = deviceReals.stream().filter(photovoltaic -> entry.getValue().stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(photovoltaic.getDeptId())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(reals)) { - subordinate.setStationCount(Long.valueOf(entry.getValue().size())); - subordinate.setStationUseCount(reals.stream().filter(device -> HomePageConstant.OFF.equals(device.getState())).map(PhotovoltaicRealVo::getDeptId).distinct().count()); - subordinate.setCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); - subordinate.setLoad(reals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); - } - // 区域/站点 设备指标数据 - List targets = deviceTargets.stream().filter(photovoltaic -> entry.getValue().stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(photovoltaic.getDeptId())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(targets)) { - subordinate.setGeneration(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum()); - } - list.add(subordinate); - } - if (CollectionUtil.isEmpty(list)) { - return new ArrayList<>(); - } - // 总数据 : 发电量 、 容量 、 电站数 - Double sumGeneration = list.stream().mapToDouble(PhotovoltaicSubordinateVo::getGeneration).sum(); - Double sumLoad = list.stream().mapToDouble(PhotovoltaicSubordinateVo::getCapacity).sum(); - Double sumStationCount = list.stream().mapToDouble(PhotovoltaicSubordinateVo::getStationCount).sum(); - // 计算 :集团发电占比 电站利用率 容量利用率 - return list.stream().map(subordinate -> { - if (Math.abs(sumGeneration) <= 0) { - subordinate.setGenerationRate(0.0); - } else { - subordinate.setGenerationRate(BigDecimal.valueOf(subordinate.getGeneration() / sumGeneration * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - if (Math.abs(sumLoad) <= 0) { - subordinate.setCapacityUse(0.0); - } else { - subordinate.setCapacityUse(BigDecimal.valueOf(subordinate.getLoad() / sumLoad * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - if (Math.abs(sumStationCount) <= 0) { - subordinate.setStationUse(0.0); - } else { - subordinate.setStationUse(BigDecimal.valueOf(subordinate.getStationUseCount() / sumStationCount * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - return subordinate; - }).sorted(Comparator.comparing(PhotovoltaicSubordinateVo::getCapacity)).collect(Collectors.toList()); - } - - /** - * 站点数据 - * - * @param deptId - * @return - */ - @Override - public PhotovoltaicStationVo station(Long deptId) { - // 参数检查 - if (ObjectUtil.isEmpty(deptId)) { - return new PhotovoltaicStationVo(); - } - // 查询站点 - StationEntity station = stationService.getOne(Wrappers.lambdaQuery().eq(StationEntity::getRefDept, deptId)); - if (ObjectUtil.isEmpty(station)) { - return new PhotovoltaicStationVo(); - } - // 实时监测点数据 - List reals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); - // 获取站点机组指标数据 - List targets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - // 站点设备 - List devices = deviceService.getEmInfoList().stream().filter(o -> o.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - // 实时天气 - Map weather = weatherService.getNowWeather(Collections.singletonList(station.getCode())); - // 七天天气 - Map weekWeather = weatherService.getWeekWeather(Collections.singletonList(station.getCode())); - PhotovoltaicStationVo photovoltaic = new PhotovoltaicStationVo(); - photovoltaic.setDeptId(station.getRefDept()); - photovoltaic.setDeptName(station.getName()); - photovoltaic.setStationCode(station.getCode()); - // 站点地址 - photovoltaic.setAddress(station.getAddress()); - // 站点投运时间 - photovoltaic.setOperationTime(station.getCommissionTime()); - // 站点实时天气 - photovoltaic.setTemp(this.temp(weather, station.getCode())); - // 站点七天天气 - photovoltaic.setWeather(this.week(weekWeather, station.getCode())); - // 逆变器数量 - photovoltaic.setInverterCount(devices.size()); - // 运行天数 - photovoltaic.setRunDay(this.run_day(station)); - // 设备实时数据、指标数据: 容量、发电量、实时功率、电流、co2、节约标准煤、30日发电量、当日功率 - photovoltaic.setDevices(this.deviceRealTarget(devices, reals, targets)); - // 设备排行榜 - photovoltaic.setCharts(this.deviceCharts(photovoltaic.getDevices())); - // 站点实时数据: 装机容量、总发电量、功率、收益 - this.real_data(photovoltaic); - // 年发电量比较概括 - photovoltaic.setGenerateSurvey(this.generateSurvey(station.getId())); - return photovoltaic; - } - - /** - * App区域下属数据 - * - * @param deptId - * @return - */ - @Override - public List app_subordinate(Long deptId) { - // 获取区域或者站点map结构 - Map> map = sideHustleService.getAreaOrStaion(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); - if (MapUtils.isEmpty(map)) { - return new ArrayList<>(); - } - // 实时数据 - List deviceReals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); - // 指标数据 - List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - // 遍历数据 - List subordinates = new ArrayList<>(); - for (Map.Entry> entry : map.entrySet()) { - PhotovoltaicSubordinateAppVo subordinate = new PhotovoltaicSubordinateAppVo(); - if (ObjectUtil.isEmpty(entry.getValue())) { - continue; - } - StationEntity station = entry.getValue().get(0); - subordinate.setDeptId(entry.getKey().getId()); - subordinate.setDeptName(entry.getKey().getDeptName()); - subordinate.setSort(entry.getKey().getSort()); - subordinate.setAddress(station.getAddress()); - // 获取实时天气 - Map nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); - if (MapUtils.isNotEmpty(nowWeather)) { - subordinate.setNow(nowWeather.get(station.getCode()).getNow()); - } - // 容量、实时功率、今日发电量 - this.subordinateTargetData(subordinate, entry.getValue().stream().collect(Collectors.toList()), deviceReals, deviceTargets); - // 当月任务执行情况 - this.subordinateTaskMon(subordinate,Collections.singletonList(entry.getKey().getId())); - subordinates.add(subordinate); - } - return subordinates; - } - - /** - * 当月任务执行情况 - * @param subordinate - */ - private void subordinateTaskMon(PhotovoltaicSubordinateAppVo subordinate,List depts) { - DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); - LocalDate firstDay = LocalDate.now().withDayOfMonth(1); - LocalDateTime startTime = LocalDateTime.of(firstDay, LocalTime.MIN); - LocalDateTime endTime = LocalDateTime.now(); - //通过线程池异步获取月报各模块内容 主要分为五块内容 - ExecutorService exe = Executors.newFixedThreadPool(POOL_QUANTITY); - //监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(POOL_QUANTITY); - // 日常维护 - exe.execute(()->{ - MaintainVo maintainVo = taskService.getMaintain(dtf.format(startTime),dtf.format(endTime),depts); - subordinate.setMaintenanceCount(maintainVo.getMaintain()); - subordinate.setMaintenanceFinishCount(maintainVo.getMaintainFinish()); - countDownLatch.countDown(); - }); - - // 消缺 - exe.execute(()->{ - ShortagesVo shortages = taskService.getShortages(depts); - subordinate.setDefectCount(shortages.getShortagesSum()); - subordinate.setDefectFinishCount(shortages.getShortages()); - countDownLatch.countDown(); - }); - // 检修 - exe.execute(()->{ - OverhaulVo overhaulVo = taskService.getOverhaul(dtf.format(startTime),dtf.format(endTime),depts); - int overhaul = overhaulVo.getOverhaul(); - int overhaulFinish = overhaulVo.getOverhaulFinish(); - subordinate.setOverhaulCount(overhaul); - subordinate.setOverhaulFinishCount(overhaulFinish); - countDownLatch.countDown(); - }); - // 操作票&工作票 - exe.execute(()->{ - Map map = new HashMap<>(); - map.put("startDate",dtf.format(startTime)); - map.put("endDate",dtf.format(endTime)); - map.put("deptList",depts); - R R = ticketInfoClient.getOperateWorkStatistic(map); - if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { - return; - } - TicketMonthVO ticketMonthVO = R.getData(); - // 操作票 - subordinate.setOperateCount(ticketMonthVO.getOperate()); - subordinate.setOperateFinishCount(ticketMonthVO.getOperateQualify()); - // 工作票 - subordinate.setWorkCount(ticketMonthVO.getWork()); - subordinate.setWorkFinishCount(ticketMonthVO.getWorkQualify()); - countDownLatch.countDown(); - }); - } - - /** - * App集团/区域指标数据 - * - * @param stations - * @param deviceReals - * @param deviceTargets - */ - private void subordinateTargetData(PhotovoltaicSubordinateAppVo subordinate, List stations, List deviceReals, List deviceTargets) { - if (CollectionUtil.isEmpty(deviceReals) && CollectionUtil.isEmpty(deviceTargets)) { - return; - } - List reals = deviceReals.stream().filter(o -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); - List targets = deviceTargets.stream().filter(o -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(reals)) { - // 容量 、 实时功率 - subordinate.setCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); - subordinate.setLoad(reals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); - subordinate.setStationLoads( - stations.stream().map(station -> { - PhotovoltaicLoadVo load = new PhotovoltaicLoadVo(); - load.setDeptId(station.getRefDept()); - load.setCode(station.getCode()); - load.setName(station.getName()); - load.setLoad(reals.stream().filter(o -> o.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicRealVo::getLoad).sum()); - return load; - }).sorted(Comparator.comparing(PhotovoltaicLoadVo::getLoad).reversed()).collect(Collectors.toList()) - ); - } - if (CollectionUtil.isNotEmpty(targets)) { - // 今日发电量 - subordinate.setGenerateDay(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationDay).sum()); - } - - } - - /** - * App光伏站点数据 - * - * @param deptId - * @return - */ - @Override - public PhotovoltaicStationAppVo app_station(Long deptId) { - // 参数检查 - if (ObjectUtil.isEmpty(deptId)) { - return new PhotovoltaicStationAppVo(); - } - // 查询站点 - StationEntity station = stationService.getOne(Wrappers.lambdaQuery().eq(StationEntity::getRefDept, deptId)); - if (ObjectUtil.isEmpty(station)) { - return new PhotovoltaicStationAppVo(); - } - PhotovoltaicStationAppVo photovoltaic = new PhotovoltaicStationAppVo(); - // 站点温度 - Map weather = weatherService.getNowWeather(Collections.singletonList(station.getCode())); - photovoltaic.setStationCode(station.getCode()); - photovoltaic.setDeptId(station.getRefDept()); - photovoltaic.setDeptName(station.getName()); - photovoltaic.setNow(weather.get(station.getCode()).getNow()); - photovoltaic.setAddress(station.getAddress()); - // 站点实时数据: 设备状态统计、实时功率、总发电量 、 日发电量 、 月发电量 、 co2减排 、 节约标准煤减排 、 减少森林砍伐 - this.app_data(photovoltaic); - return photovoltaic; - } - - /** - * 站点指标数据 - * - * @param photovoltaic - */ - private void app_data(PhotovoltaicStationAppVo photovoltaic) { - // 实时监测点数据 - List reals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); - // 获取站点机组指标数据 - List targets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - if (CollectionUtil.isEmpty(reals) && CollectionUtil.isEmpty(targets)) { - return; - } - List mateReals = reals.stream().filter(o -> o.getDeptId().equals(photovoltaic.getDeptId())).collect(Collectors.toList()); - List mateTargets = targets.stream().filter(o -> o.getDeptId().equals(photovoltaic.getDeptId())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(mateReals) && CollectionUtil.isEmpty(mateTargets)) { - return; - } - // 实时数据 : 实时功率、总发电量 - if (CollectionUtil.isNotEmpty(mateReals)) { - // 设备状态统计 - photovoltaic.setDeviceState( - mateReals.stream().collect(Collectors.groupingBy(PhotovoltaicRealVo::getState)).entrySet().stream().map(entry -> { - PhotovoltaicDeviceStateVo state = new PhotovoltaicDeviceStateVo(); - state.setState(entry.getKey()); - state.setCount(entry.getValue().size()); - return state; - }).collect(Collectors.toList()) - ); - photovoltaic.setLoad(mateReals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); - photovoltaic.setGenerate(mateReals.stream().mapToDouble(PhotovoltaicRealVo::getGenerate).sum()); - } - // 指标数据 : 日发电量 、 月发电量 、 co2减排 、 节约标准煤减排 、 减少森林砍伐 - if (CollectionUtil.isNotEmpty(mateTargets)) { - photovoltaic.setGenerateDay(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationDay).sum()); - photovoltaic.setGenerateMon(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationMon).sum()); - photovoltaic.setCo2(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getCo2).sum()); - photovoltaic.setTec(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getTec).sum()); - photovoltaic.setIncome(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getIncome).sum()); - photovoltaic.setDeforest(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getDeforest).sum()); - } - } - - /** - * App功率/发电量查询 - * - * @param deptId - * @param type - * @return - */ - @Override - public List app_load_generate(Long deptId, String type, String queryType) { - // 查询光伏站点 - List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); - if (CollectionUtil.isEmpty(stations)) { - return new ArrayList<>(); - } - // 区别查询周期 - switch (queryType) { - // 日 - case "0": - return this.periodLoadDay(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); - // 周 - case "1": - return this.periodLoadGenerate(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()), type, true); - // 月 - case "2": - return this.periodLoadGenerate(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()), type, false); - // 年 - case "3": - return this.periodLoadGenerateYear(stations.stream().map(StationEntity::getId).collect(Collectors.toList())); - default: - throw new ServiceException("无效查询类型!"); - - } - } - - /** - * 查询光伏设备日数据 - * - * @param stations - * @return - */ - private List periodLoadDay(List stations) { - // FIXME 测试数据 - List hours = getDayHours(); - Random random = new Random(); - return hours.stream().map(hour -> { - PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); - target.setPeriod(hour); - target.setValue((float) (random.nextDouble() * 500)); - return target; - }).sorted(Comparator.comparing(PhotovoltaicLoadGenerateVo::getPeriod)).collect(Collectors.toList()); + private final IStationService stationService; + + private final IMainSystemMonitoringService deviceService; + + private final ISideHustleService sideHustleService; + + private final IHomePageService homePageService; + + private final IWeatherService weatherService; + + private final IAnalyseDataService analyseDataService; + + private final IHistoryDataSearchClient historySearchClient; + + private final IMainTaskStatisticService taskService; + + private final ISysClient sysClient; + + private final ITicketInfoClient ticketInfoClient; + + private final RedisTemplate redisTemplate; + + private final static String load_photovoltaic_real_key = "hzims:operation:photovoltaic:real:key"; + + private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key"; + + private final static String recent_year_power_data = "hzims:operation:key:power:data"; + + @Value("${hzims.operation.realIdKey}") + public String real_id_key; + + // 线程数量 + private final static int POOL_QUANTITY = 4; + + /** + * 光伏站-逆变器实时加载 + * + * @param param + */ + @Override + public void loadPhotovoltaicReal(String param) { + // 查询设备 + List devices = this.getPhotovoltaicDevice(); + if (CollectionUtil.isEmpty(devices)) { + return; + } + // 取redis实时数据 + Map map = this.getRealData(); + if (MapUtils.isEmpty(map)) { + return; + } + // redis缓存设备实时数据 + List history = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + // 设备实时数据 + List list = devices.stream().map(device -> { + PhotovoltaicRealVo real = new PhotovoltaicRealVo(); + real.setDeptId(device.getCreateDept()); + real.setDeviceCode(device.getEmCode()); + real.setDeviceName(device.getName()); + real.setState(this.getPhotovoltaicState(device, map)); + // 容量 + real.setCapacity(device.getInstalledCapacity()); + // 发电量 + real.setGenerate(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.PV_GENERATION_CAPACITY))); + // 功率 + real.setLoad(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.PV_LOAD))); + // 电压 + real.setVoltage(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.PV_VOLTAGE))); + // 电流 + real.setCurrent(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.PV_CURRENT))); + // 直流电流1 + real.setDirect_one(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_ONE))); + // 直流电流2 + real.setDirect_two(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_TWO))); + // 直流电流3 + real.setDirect_three(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_THREE))); + // 直流电流4 + real.setDirect_four(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_FOUR))); + // 直流电流5 + real.setDirect_five(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_FIVE))); + // 直流电流6 + real.setDirect_six(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_SIX))); + // 直流电流7 + real.setDirect_seven(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_SEVEN))); + // 直流电流8 + real.setDirect_eight(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_EIGHT))); + // 直流电流9 + real.setDirect_nine(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_NINE))); + // 直流电流10 + real.setDirect_ten(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_TEN))); + // 直流电流11 + real.setDirect_eleven(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_ELEVEN))); + // 直流电流12 + real.setDirect_twelve(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_TWELVE))); + // 直流电压1 + real.setDc_voltage_one(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_ONE))); + // 直流电压2 + real.setDc_voltage_two(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TWO))); + // 直流电压3 + real.setDc_voltage_three(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_THREE))); + // 直流电压4 + real.setDc_voltage_four(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_FOUR))); + // 直流电压5 + real.setDc_voltage_five(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_FIVE))); + // 直流电压6 + real.setDc_voltage_six(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_SIX))); + // 直流电压7 + real.setDc_voltage_seven(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_SEVEN))); + // 直流电压8 + real.setDc_voltage_eight(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_EIGHT))); + // 直流电压9 + real.setDc_voltage_nine(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_NINE))); + // 直流电压10 + real.setDc_voltage_ten(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TEN))); + // 直流电压11 + real.setDc_voltage_eleven(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_ELEVEN))); + // 直流电压12 + real.setDc_voltage_twelve(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TWELVE))); + // 串流电流1 + real.setDirect_one(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.DIRECT_ONE))); + // 串流电流2 + real.setSeries_two(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_TWO))); + // 串流电流3 + real.setSeries_three(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_THREE))); + // 串流电流4 + real.setSeries_four(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_FOUR))); + // 串流电流5 + real.setSeries_five(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_FIVE))); + // 串流电流6 + real.setSeries_six(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_SIX))); + // 串流电流7 + real.setSeries_seven(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_SEVEN))); + // 串流电流8 + real.setSeries_eight(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_EIGHT))); + // 串流电流9 + real.setSeries_nine(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_NINE))); + // 串流电流10 + real.setSeries_ten(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_TEN))); + // 串流电流11 + real.setSeries_eleven(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_ELEVEN))); + // 串流电流12 + real.setSeries_twelve(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SERIES_TWELVE))); + // 串流电压1 + real.setSe_voltage_one(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_ONE))); + // 串流电压2 + real.setSe_voltage_two(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TWO))); + // 串流电压3 + real.setSe_voltage_three(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_THREE))); + // 串流电压4 + real.setSe_voltage_four(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_FOUR))); + // 串流电压5 + real.setSe_voltage_five(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_FIVE))); + // 串流电压6 + real.setSe_voltage_six(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_SIX))); + // 串流电压7 + real.setSe_voltage_seven(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_SEVEN))); + // 串流电压8 + real.setSe_voltage_eight(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_EIGHT))); + // 串流电压9 + real.setSe_voltage_nine(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_NINE))); + // 串流电压10 + real.setSe_voltage_ten(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TEN))); + // 串流电压11 + real.setSe_voltage_eleven(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_ELEVEN))); + // 串流电压12 + real.setSe_voltage_twelve(Double.valueOf(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TWELVE))); + // 上次功率 + real.setLastLoad(this.getLastLoad(device, history)); + return real; + }).collect(Collectors.toList()); + // 存储redis + redisTemplate.opsForValue().set(load_photovoltaic_real_key, list); + } + + /** + * 光伏站-逆变器指标加载 + * + * @param param + */ + @Override + public void loadPhotovoltaicTarget(String param) { + // 有效设备 + List devices = this.getPhotovoltaicDevice(); + if (CollectionUtil.isEmpty(devices)) { + return; + } + List list = new ArrayList<>(); + devices.forEach(device -> { + PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeviceName(device.getName()); + target.setDeptName(device.getName()); + // 当日运行时长 + //target.setRunHours(this.runHours(device.getPoint().get(HomePageConstant.PV_JOINT_RELAY))); + // 年发电量 + target.setGenerationYear((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "0")); + // 月发电量 + target.setGenerationMon((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "1")); + // 日发电量 + target.setGenerationDay((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "2")); + // 昨日发电量 + target.setGenerationYesterday((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "3")); + // 收益 + target.setIncome(target.getGenerationDay() * 0.34); + // 节约标准煤 + target.setTec(target.getGenerationMon() * 0.0001229); + // 二氧化碳减排 + target.setCo2(target.getGenerationMon() * 0.000997); + // 减少森林砍伐 + target.setDeforest(target.getGenerationMon() * 0.000553); + // 当天有功功率 + target.setActivePowerVoList(this.getLoadsByDay(device)); + // 30天发电量 + target.setGenerationPowerVoList(this.getGenerateByMon(device)); + list.add(target); + }); + redisTemplate.opsForValue().set(load_photovoltaic_target_key, list); + } + + /** + * 当天有功功率 + * + * @param device + * @return + */ + private List getLoadsByDay(EminfoAndEmParamVo device) { + String start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + List records = analyseDataService.periodTargetData(start, end, 1, 2, device.getEmCode(), HomePageConstant.PV_LOAD); + if (CollectionUtil.isEmpty(records)) { + return new ArrayList<>(); + } + return records.stream().map(record -> { + PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + load.setHour(time.getHours()); + load.setActivePower(Optional.ofNullable(record.getVal()).orElse("0")); + return load; + }).sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList()); + } + + /** + * 近30天发电量 + * + * @param device + * @return + */ + private List getGenerateByMon(EminfoAndEmParamVo device) { + Calendar calendar = Calendar.getInstance(); + String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.DAY_OF_MONTH, -29); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + List records = analyseDataService.periodTargetData(start, end, 5, 3, device.getEmCode(), HomePageConstant.PV_GENERATION_CAPACITY); + if (CollectionUtil.isEmpty(records)) { + return new ArrayList<>(); + } + return records.stream().map(record -> { + GenerationPowerVo generate = new GenerationPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setDate(DateUtil.format(time, DateUtil.PATTERN_DATE)); + generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); + return generate; + }).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()); + } + + + /** + * 根据事件查询数据值 + * + * @param deviceCode + * @param rideCount + * @param type + * @return + */ + private float sumValueByTime(String deviceCode, int rideCount, String type) { + Calendar calendar = Calendar.getInstance(); + String start = null, end = null; + Integer cycleType = 3; + switch (type) { + //年 + case "0": + calendar.add(Calendar.HOUR_OF_DAY, +1); + end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + calendar.setTime(new Date()); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DAY_OF_MONTH, -calendar.get(Calendar.DATE) + 1); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + cycleType = 6; + break; + //月 + case "1": + start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + cycleType = 5; + break; + //日 + case "2": + start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + break; + //昨日 + case "3": + calendar.add(Calendar.DAY_OF_MONTH, -1); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + break; + } + return analyseDataService.periodTargetFloat(start, end, 5, cycleType, deviceCode, rideCount, HomePageConstant.PV_GENERATION_CAPACITY); + } + + /** + * 获取上一次功率 + * + * @param device + * @param history + * @return + */ + private Double getLastLoad(EminfoAndEmParamVo device, List history) { + if (CollectionUtil.isEmpty(history)) { + return 0.0; + } + List historyDevice = history.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(historyDevice)) { + return 0.0; + } + return historyDevice.get(0).getLoad(); + } + + /** + * 获取开机状态 + * + * @param device + * @return + */ + private int getPhotovoltaicState(EminfoAndEmParamVo device, Map map) { + // 获取开关机监测点实时数据 + String value = this.getSignageValue(device, map, HomePageConstant.PV_JOINT_RELAY); + // 开机状态 + if (HomePageConstant.OFF.equals(value)) { + return 0; + } + return 1; + } + + /** + * 获取监测点实时数据 + * + * @param em + * @param map + * @param targets + * @return + */ + private String getSignageValue(EminfoAndEmParamVo em, Map map, String targets) { + if (ObjectUtil.isEmpty(em) || MapUtils.isEmpty(map)) { + return "0"; + } + Map point = em.getPoint(); + if (MapUtils.isEmpty(point)) { + return "0"; + } + String realId = point.get(targets); + if (StringUtil.isEmpty(realId)) { + return "0"; + } + String value = map.get(realId); + if (StringUtil.isEmpty(realId)) { + return "0"; + } + // 获取value + return value; + } + + /** + * 当天运行时长 + * + * @param realId + * @return + */ + private Double runHours(String realId) { + Calendar calendar = Calendar.getInstance(); + Date end = calendar.getTime(); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + Date start = calendar.getTime(); + OriginalDataQuery originalDataQuery = new OriginalDataQuery(); + originalDataQuery.setRealId(realId); + originalDataQuery.setBeginTime(start); + originalDataQuery.setEndTime(end); + originalDataQuery.setLimit(100000); + originalDataQuery.setPage(1); + // 查询时间范围开关机监测点历史数据 + Result> R = historySearchClient.getOriginalDataByRealIds(originalDataQuery); + if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { + return 0.0; + } + // 过滤相邻开关机状态相同数据 + List result = this.filterData(R.getData().getRecords()); + if (CollectionUtil.isEmpty(result)) { + return 0.0; + } + // 开机运行时长 + long time = this.runTime(result, start, end); + return BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + /** + * 当天运行时长 + * + * @return + */ + private List getDayHours() { + List list = new ArrayList<>(); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + // 获取时间 + while (calendar.getTime().compareTo(new Date()) <= 0) { + list.add(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); + calendar.add(Calendar.HOUR_OF_DAY, +1); + } + return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); + } + + + /** + * 过滤相邻开关机状态相同数据 + * + * @param list + * @return + */ + private List filterData(List list) { + if (CollectionUtil.isEmpty(list)) { + return null; + } + List result = new ArrayList<>(); + // 遍历数据 + for (int i = 0; i < list.size(); i++) { + // 第一个数据保存下来 + if (i == 0) { + result.add(list.get(i)); + continue; + } + // 遍历数据状态 + String value = list.get(i).getValue(); + if (StringUtil.isBlank(value)) { + continue; + } + // 上一条数据状态 + String up_value = list.get(i - 1).getValue(); + if (value.equals(up_value)) { + continue; + } + result.add(list.get(i)); + } + return result; + } + + /** + * 获取运行时长 + * + * @param result + * @return + */ + private long runTime(List result, Date startDate, Date endDate) { + if (result.size() == 1) { + // 一直开机 + if (HomePageConstant.PHOTOVOLTAIC_OFF.equals(result.get(0).getValue())) { + return endDate.getTime() - startDate.getTime(); + } + // 一直关机 + return 0; + } + long time = 0; + // 遍历累计开机时长 + for (int i = 0; i < result.size(); i++) { + // 记录为开机状态 就计算到下次关机的时间差 + if (HomePageConstant.ON.equals(result.get(i).getValue())) { + continue; + } + Date endTime, startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); + // 遍历至最后一条数据,累计至当前时间 + if (i == result.size() - 1) { + endTime = endDate; + } else { + endTime = DateUtil.parse(result.get(i + 1).getTime(), DateUtil.PATTERN_DATETIME); + } + time += endTime.getTime() - startTime.getTime(); + } + return time; + } + + + /** + * 获取近30天集合 + * + * @return + */ + private List getRecentWeek() { + // 日期格式化yyyy-mm-dd + SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); + List list = new ArrayList<>(); + // 开始日期 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + calendar.add(Calendar.DATE, +1); + list.add(df.format(calendar.getTime())); + // 获取日期之间的月 + int i = 0; + while (i <= 7) { + list.add(df.format(calendar.getTime())); + calendar.add(Calendar.DATE, -1); + i++; + } + return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); + } + + /** + * 获取实时数据 + * + * @return + */ + private Map getRealData() { + String json = (String) redisTemplate.opsForValue().get(real_id_key); + if (StringUtil.isBlank(json)) { + return null; + } + return JSONObject.parseObject(json, new TypeReference>() { + }); + } + + /** + * 获取光伏设备 + * + * @return + */ + private List getPhotovoltaicDevice() { + // 光伏站点 + List stations = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), null); + if (CollectionUtil.isEmpty(stations)) { + return null; + } + // 设备 + List devices = deviceService.getEmInfoList(); + if (CollectionUtil.isEmpty(devices)) { + return null; + } + return devices.stream().filter(device -> + stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(device.getCreateDept()) + ).collect(Collectors.toList()); + } + + /** + * 集团/区域关键指标 + * + * @param deptId + * @return + */ + @Override + public PhotovoltaicKPIsVo KPIs(Long deptId) { + // 查询光伏站点 + List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); + if (CollectionUtil.isEmpty(stations)) { + return new PhotovoltaicKPIsVo(); + } + PhotovoltaicKPIsVo kpi = new PhotovoltaicKPIsVo(); + // 站点数量 + kpi.setCount(stations.size()); + // 实时数据 + List deviceReals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + if (CollectionUtil.isNotEmpty(deviceReals)) { + List reals = deviceReals.stream().filter(device -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(device.getDeptId())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(reals)) { + // 容量 + kpi.setInstalledCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); + // 负荷 + kpi.setLoad(reals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); + } + } + // 指标数据 + List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + if (CollectionUtil.isEmpty(deviceTargets)) { + return kpi; + } + List targets = deviceTargets.stream().filter(device -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(device.getDeptId())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(targets)) { + return kpi; + } + // 年发电量 + kpi.setPowerYear(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum()); + // 月发电量 + kpi.setPowerMon(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationMon).sum()); + // 日发电量 + kpi.setPowerDay(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationDay).sum()); + // 节约标准煤 + kpi.setTec(targets.stream().mapToDouble(PhotovoltaicTargetVo::getTec).sum()); + // CO2减排 + kpi.setCo2(targets.stream().mapToDouble(PhotovoltaicTargetVo::getCo2).sum()); + // 减少森林砍伐 + kpi.setDeforest(targets.stream().mapToDouble(PhotovoltaicTargetVo::getDeforest).sum()); + // 近3年发电量 + kpi.setPowerYearVoList(this.getPowerList(stations.stream().map(StationEntity::getId).collect(Collectors.toList()))); + return kpi; + } + + /** + * 获取近3年发电量 + * + * @return + */ + private List getPowerList(List stations) { + // 站点近年发电数据 key - stationCode value - 月份,发电量 + Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); + if (MapUtils.isEmpty(map)) { + return new ArrayList<>(); + } + List> filter = map.entrySet().stream().filter(e -> stations.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(filter)) { + return new ArrayList<>(); + } + // 根据月份分组 + List powerMonthVos = new ArrayList<>(); + filter.forEach(item -> { + item.forEach((key, value) -> { + PowerMonthVo powerMonthVo = new PowerMonthVo(); + powerMonthVo.setStrMonth(key); + powerMonthVo.setPower(value); + powerMonthVos.add(powerMonthVo); + }); + }); + Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); + // 总和所有相同月份的发电量 + List powerMonthVoList = months.entrySet().stream().map(entry -> { + PowerMonthVo powerMonth = new PowerMonthVo(); + powerMonth.setStrMonth(entry.getKey()); + LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), entry.getKey()), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); + powerMonth.setYear(localDate.getYear()); + powerMonth.setMonth(localDate.getMonthValue()); + powerMonth.setPower((float) entry.getValue().stream().mapToDouble(PowerMonthVo::getPower).sum()); + return powerMonth; + }).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(powerMonthVoList)) { + return new ArrayList<>(); + } + // 根据年份分组 + Map> year = powerMonthVoList.stream().collect(Collectors.groupingBy(PowerMonthVo::getYear)); + // 返回结果集 + return year.entrySet().stream().map(entry -> { + PowerYearVo powerYearVo = new PowerYearVo(); + powerYearVo.setYear(entry.getKey()); + List sortValue = entry.getValue().stream().sorted(Comparator.comparing(PowerMonthVo::getMonth)).collect(Collectors.toList()); + powerYearVo.setPowerMonthVoList(sortValue); + return powerYearVo; + }).collect(Collectors.toList()); + } + + /** + * 集团/区域发电量 + * + * @param deptId + * @param type + * @return + */ + @Override + public List generation(Long deptId, String type) { + // 查询光伏站点 + List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); + if (CollectionUtil.isEmpty(stations)) { + return new ArrayList<>(); + } + switch (type) { + // 周 + case "0": + return this.getGeneration(stations.stream().map(StationEntity::getRefDept).distinct().collect(Collectors.toList()), true); + // 月 + case "1": + return this.getGeneration(stations.stream().map(StationEntity::getRefDept).distinct().collect(Collectors.toList()), false); + // 年 + case "2": + return this.getGenerationYear(stations.stream().map(StationEntity::getId).distinct().collect(Collectors.toList())); + default: + throw new ServiceException("无效查询类型!"); + } + } + + /** + * 获取发电量(周/月) + * + * @return + */ + private List getGeneration(List stations, boolean flag) { + // redis实时数据 + List photovoltaics = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + if (CollectionUtil.isEmpty(photovoltaics)) { + return new ArrayList(); + } + // 过滤有效光伏设备 + List filters = photovoltaics.stream().filter(photovoltaic -> stations.contains(photovoltaic.getDeptId())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(filters)) { + return new ArrayList<>(); + } + // 数据集合 + List generations = new ArrayList<>(); + for (PhotovoltaicTargetVo target : filters) { + if (CollectionUtil.isEmpty(target.getGenerationPowerVoList())) { + continue; + } + generations.addAll(target.getGenerationPowerVoList()); + } + if (CollectionUtil.isEmpty(generations)) { + return new ArrayList<>(); + } + List weeks = this.getRecentWeek(); + // 周 + if (flag) { + // 根据日期分组 + return generations.stream().filter(generation -> weeks.contains(generation.getDate())).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { + GenerationVo generation = new GenerationVo(); + generation.setPeriod(entry.getKey()); + generation.setPower((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerate).sum()); + return generation; + }).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); + } + // 月 + return generations.stream().collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { + GenerationVo generation = new GenerationVo(); + generation.setPeriod(entry.getKey()); + generation.setPower((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerate).sum()); + return generation; + }).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); + } + + /** + * 获取发电量(年) + * + * @return + */ + private List getGenerationYear(List stations) { + // 站点近年发电数据 key - stationCode value - 月份,发电量 + Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); + if (MapUtils.isEmpty(map)) { + return new ArrayList<>(); + } + List> filter = map.entrySet().stream().filter(e -> stations.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(filter)) { + return new ArrayList<>(); + } + // 根据月份分组 + List powerMonthVos = new ArrayList<>(); + filter.forEach(item -> { + item.forEach((key, value) -> { + PowerMonthVo powerMonthVo = new PowerMonthVo(); + powerMonthVo.setStrMonth(key); + powerMonthVo.setPower(value); + powerMonthVos.add(powerMonthVo); + }); + }); + Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); + // 总和所有相同月份的发电量 + String year = String.valueOf(LocalDate.now().getYear()); + return months.entrySet().stream().filter(entry -> entry.getKey().contains(year)).map(entry -> { + GenerationVo generation = new GenerationVo(); + generation.setPeriod(entry.getKey()); + generation.setPower((float) entry.getValue().stream().mapToDouble(PowerMonthVo::getPower).sum()); + return generation; + }).sorted(Comparator.comparing(GenerationVo::getPeriod)).collect(Collectors.toList()); + } + + + /** + * 集团/区域下属数据占比 + * + * @param deptId + * @return + */ + @Override + public List subordinate(Long deptId) { + // 获取区域或者站点map结构 + Map> map = sideHustleService.getAreaOrStaion(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); + if (MapUtils.isEmpty(map)) { + return new ArrayList<>(); + } + // 实时数据 + List deviceReals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + // 指标数据 + List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + // 遍历数据 + List list = new ArrayList<>(); + for (Map.Entry> entry : map.entrySet()) { + PhotovoltaicSubordinateVo subordinate = new PhotovoltaicSubordinateVo(); + if (ObjectUtil.isEmpty(entry.getValue())) { + continue; + } + subordinate.setDeptId(entry.getKey().getId()); + subordinate.setDeptName(entry.getKey().getDeptName()); + subordinate.setSort(entry.getKey().getSort()); + // 获取第一个站点经纬度、行政编码信息 + StationEntity station = entry.getValue().get(0); + subordinate.setLttd(station.getLttd()); + subordinate.setLgtd(station.getLgtd()); + // 省市编码 + String areaCode = station.getAreaCode(); + subordinate.setAreaCode(areaCode); + if (!StringUtil.isEmpty(areaCode)) { + String[] arrCode = areaCode.split(","); + R R = sysClient.getRegion(arrCode[1]); + if (R.isSuccess() && ObjectUtil.isNotEmpty(R.getData())) { + subordinate.setAreaName(R.getData().getName()); + } + } + // 获取实时天气 + Map nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); + if (MapUtils.isNotEmpty(nowWeather)) { + subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); + } + // 获取七天天气 + Map weekWeather = weatherService.getWeekWeather(Collections.singletonList(station.getCode())); + if (MapUtils.isNotEmpty(weekWeather)) { + subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); + } + subordinate.setWeather(weekWeather.get(station.getCode()).getDaily()); + // 区域/站点 设备实时数据 + List reals = deviceReals.stream().filter(photovoltaic -> entry.getValue().stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(photovoltaic.getDeptId())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(reals)) { + subordinate.setStationCount(Long.valueOf(entry.getValue().size())); + subordinate.setStationUseCount(reals.stream().filter(device -> HomePageConstant.OFF.equals(device.getState())).map(PhotovoltaicRealVo::getDeptId).distinct().count()); + subordinate.setCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); + subordinate.setLoad(reals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); + } + // 区域/站点 设备指标数据 + List targets = deviceTargets.stream().filter(photovoltaic -> entry.getValue().stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(photovoltaic.getDeptId())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(targets)) { + subordinate.setGeneration(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum()); + } + list.add(subordinate); + } + if (CollectionUtil.isEmpty(list)) { + return new ArrayList<>(); + } + // 总数据 : 发电量 、 容量 、 电站数 + Double sumGeneration = list.stream().mapToDouble(PhotovoltaicSubordinateVo::getGeneration).sum(); + Double sumLoad = list.stream().mapToDouble(PhotovoltaicSubordinateVo::getCapacity).sum(); + Double sumStationCount = list.stream().mapToDouble(PhotovoltaicSubordinateVo::getStationCount).sum(); + // 计算 :集团发电占比 电站利用率 容量利用率 + return list.stream().map(subordinate -> { + if (Math.abs(sumGeneration) <= 0) { + subordinate.setGenerationRate(0.0); + } else { + subordinate.setGenerationRate(BigDecimal.valueOf(subordinate.getGeneration() / sumGeneration * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + if (Math.abs(sumLoad) <= 0) { + subordinate.setCapacityUse(0.0); + } else { + subordinate.setCapacityUse(BigDecimal.valueOf(subordinate.getLoad() / sumLoad * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + if (Math.abs(sumStationCount) <= 0) { + subordinate.setStationUse(0.0); + } else { + subordinate.setStationUse(BigDecimal.valueOf(subordinate.getStationUseCount() / sumStationCount * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + return subordinate; + }).sorted(Comparator.comparing(PhotovoltaicSubordinateVo::getCapacity)).collect(Collectors.toList()); + } + + /** + * 站点数据 + * + * @param deptId + * @return + */ + @Override + public PhotovoltaicStationVo station(Long deptId) { + // 参数检查 + if (ObjectUtil.isEmpty(deptId)) { + return new PhotovoltaicStationVo(); + } + // 查询站点 + StationEntity station = stationService.getOne(Wrappers.lambdaQuery().eq(StationEntity::getRefDept, deptId)); + if (ObjectUtil.isEmpty(station)) { + return new PhotovoltaicStationVo(); + } + // 实时监测点数据 + List reals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + // 获取站点机组指标数据 + List targets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + // 站点设备 + List devices = deviceService.getEmInfoList().stream().filter(o -> o.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + // 实时天气 + Map weather = weatherService.getNowWeather(Collections.singletonList(station.getCode())); + // 七天天气 + Map weekWeather = weatherService.getWeekWeather(Collections.singletonList(station.getCode())); + PhotovoltaicStationVo photovoltaic = new PhotovoltaicStationVo(); + photovoltaic.setDeptId(station.getRefDept()); + photovoltaic.setDeptName(station.getName()); + photovoltaic.setStationCode(station.getCode()); + // 站点地址 + photovoltaic.setAddress(station.getAddress()); + // 站点投运时间 + photovoltaic.setOperationTime(station.getCommissionTime()); + // 站点实时天气 + photovoltaic.setTemp(this.temp(weather, station.getCode())); + // 站点七天天气 + photovoltaic.setWeather(this.week(weekWeather, station.getCode())); + // 逆变器数量 + photovoltaic.setInverterCount(devices.size()); + // 运行天数 + photovoltaic.setRunDay(this.run_day(station)); + // 设备实时数据、指标数据: 容量、发电量、实时功率、电流、co2、节约标准煤、30日发电量、当日功率 + photovoltaic.setDevices(this.deviceRealTarget(devices, reals, targets)); + // 设备排行榜 + photovoltaic.setCharts(this.deviceCharts(photovoltaic.getDevices())); + // 站点实时数据: 装机容量、总发电量、功率、收益 + this.real_data(photovoltaic); + // 站点今日功率,近年发电量 + this.target_data(photovoltaic); + return photovoltaic; + } + + /** + * App区域下属数据 + * + * @param deptId + * @return + */ + @Override + public List app_subordinate(Long deptId) { + // 获取区域或者站点map结构 + Map> map = sideHustleService.getAreaOrStaion(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); + if (MapUtils.isEmpty(map)) { + return new ArrayList<>(); + } + // 实时数据 + List deviceReals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + // 指标数据 + List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + // 遍历数据 + List subordinates = new ArrayList<>(); + for (Map.Entry> entry : map.entrySet()) { + PhotovoltaicSubordinateAppVo subordinate = new PhotovoltaicSubordinateAppVo(); + if (ObjectUtil.isEmpty(entry.getValue())) { + continue; + } + StationEntity station = entry.getValue().get(0); + subordinate.setDeptId(entry.getKey().getId()); + subordinate.setDeptName(entry.getKey().getDeptName()); + subordinate.setSort(entry.getKey().getSort()); + subordinate.setAddress(station.getAddress()); + // 获取实时天气 + Map nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); + if (MapUtils.isNotEmpty(nowWeather)) { + subordinate.setNow(nowWeather.get(station.getCode()).getNow()); + } + // 容量、实时功率、今日发电量 + this.subordinateTargetData(subordinate, entry.getValue().stream().collect(Collectors.toList()), deviceReals, deviceTargets); + // 当月任务执行情况 + this.subordinateTaskMon(subordinate, Collections.singletonList(entry.getKey().getId())); + subordinates.add(subordinate); + } + return subordinates; + } + + /** + * 当月任务执行情况 + * + * @param subordinate + */ + private void subordinateTaskMon(PhotovoltaicSubordinateAppVo subordinate, List depts) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); + LocalDate firstDay = LocalDate.now().withDayOfMonth(1); + LocalDateTime startTime = LocalDateTime.of(firstDay, LocalTime.MIN); + LocalDateTime endTime = LocalDateTime.now(); + //通过线程池异步获取月报各模块内容 主要分为五块内容 + ExecutorService exe = Executors.newFixedThreadPool(POOL_QUANTITY); + //监控线程执行完后返回结果 + CountDownLatch countDownLatch = new CountDownLatch(POOL_QUANTITY); + // 日常维护 + exe.execute(() -> { + MaintainVo maintainVo = taskService.getMaintain(dtf.format(startTime), dtf.format(endTime), depts); + subordinate.setMaintenanceCount(maintainVo.getMaintain()); + subordinate.setMaintenanceFinishCount(maintainVo.getMaintainFinish()); + countDownLatch.countDown(); + }); + + // 消缺 + exe.execute(() -> { + ShortagesVo shortages = taskService.getShortages(depts); + subordinate.setDefectCount(shortages.getShortagesSum()); + subordinate.setDefectFinishCount(shortages.getShortages()); + countDownLatch.countDown(); + }); + // 检修 + exe.execute(() -> { + OverhaulVo overhaulVo = taskService.getOverhaul(dtf.format(startTime), dtf.format(endTime), depts); + int overhaul = overhaulVo.getOverhaul(); + int overhaulFinish = overhaulVo.getOverhaulFinish(); + subordinate.setOverhaulCount(overhaul); + subordinate.setOverhaulFinishCount(overhaulFinish); + countDownLatch.countDown(); + }); + // 操作票&工作票 + exe.execute(() -> { + Map map = new HashMap<>(); + map.put("startDate", dtf.format(startTime)); + map.put("endDate", dtf.format(endTime)); + map.put("deptList", depts); + R R = ticketInfoClient.getOperateWorkStatistic(map); + if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { + return; + } + TicketMonthVO ticketMonthVO = R.getData(); + // 操作票 + subordinate.setOperateCount(ticketMonthVO.getOperate()); + subordinate.setOperateFinishCount(ticketMonthVO.getOperateQualify()); + // 工作票 + subordinate.setWorkCount(ticketMonthVO.getWork()); + subordinate.setWorkFinishCount(ticketMonthVO.getWorkQualify()); + countDownLatch.countDown(); + }); + } + + /** + * App集团/区域指标数据 + * + * @param stations + * @param deviceReals + * @param deviceTargets + */ + private void subordinateTargetData(PhotovoltaicSubordinateAppVo subordinate, List stations, List deviceReals, List deviceTargets) { + if (CollectionUtil.isEmpty(deviceReals) && CollectionUtil.isEmpty(deviceTargets)) { + return; + } + List reals = deviceReals.stream().filter(o -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); + List targets = deviceTargets.stream().filter(o -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(reals)) { + // 容量 、 实时功率 + subordinate.setCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); + subordinate.setLoad(reals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); + subordinate.setStationLoads( + stations.stream().map(station -> { + PhotovoltaicLoadVo load = new PhotovoltaicLoadVo(); + load.setDeptId(station.getRefDept()); + load.setCode(station.getCode()); + load.setName(station.getName()); + load.setLoad(reals.stream().filter(o -> o.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicRealVo::getLoad).sum()); + return load; + }).sorted(Comparator.comparing(PhotovoltaicLoadVo::getLoad).reversed()).collect(Collectors.toList()) + ); + } + if (CollectionUtil.isNotEmpty(targets)) { + // 今日发电量 + subordinate.setGenerateDay(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationDay).sum()); + } + + } + + /** + * App光伏站点数据 + * + * @param deptId + * @return + */ + @Override + public PhotovoltaicStationAppVo app_station(Long deptId) { + // 参数检查 + if (ObjectUtil.isEmpty(deptId)) { + return new PhotovoltaicStationAppVo(); + } + // 查询站点 + StationEntity station = stationService.getOne(Wrappers.lambdaQuery().eq(StationEntity::getRefDept, deptId)); + if (ObjectUtil.isEmpty(station)) { + return new PhotovoltaicStationAppVo(); + } + PhotovoltaicStationAppVo photovoltaic = new PhotovoltaicStationAppVo(); + // 站点温度 + Map weather = weatherService.getNowWeather(Collections.singletonList(station.getCode())); + photovoltaic.setStationCode(station.getCode()); + photovoltaic.setDeptId(station.getRefDept()); + photovoltaic.setDeptName(station.getName()); + photovoltaic.setNow(weather.get(station.getCode()).getNow()); + photovoltaic.setAddress(station.getAddress()); + // 站点实时数据: 设备状态统计、实时功率、总发电量 、 日发电量 、 月发电量 、 co2减排 、 节约标准煤减排 、 减少森林砍伐 + this.app_data(photovoltaic); + return photovoltaic; + } + + /** + * 站点指标数据 + * + * @param photovoltaic + */ + private void app_data(PhotovoltaicStationAppVo photovoltaic) { + // 实时监测点数据 + List reals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + // 获取站点机组指标数据 + List targets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + if (CollectionUtil.isEmpty(reals) && CollectionUtil.isEmpty(targets)) { + return; + } + List mateReals = reals.stream().filter(o -> o.getDeptId().equals(photovoltaic.getDeptId())).collect(Collectors.toList()); + List mateTargets = targets.stream().filter(o -> o.getDeptId().equals(photovoltaic.getDeptId())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(mateReals) && CollectionUtil.isEmpty(mateTargets)) { + return; + } + // 实时数据 : 实时功率、总发电量 + if (CollectionUtil.isNotEmpty(mateReals)) { + // 设备状态统计 + photovoltaic.setDeviceState( + mateReals.stream().collect(Collectors.groupingBy(PhotovoltaicRealVo::getState)).entrySet().stream().map(entry -> { + PhotovoltaicDeviceStateVo state = new PhotovoltaicDeviceStateVo(); + state.setState(entry.getKey()); + state.setCount(entry.getValue().size()); + return state; + }).collect(Collectors.toList()) + ); + photovoltaic.setLoad(mateReals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); + photovoltaic.setGenerate(mateReals.stream().mapToDouble(PhotovoltaicRealVo::getGenerate).sum()); + } + // 指标数据 : 日发电量 、 月发电量 、 co2减排 、 节约标准煤减排 、 减少森林砍伐 + if (CollectionUtil.isNotEmpty(mateTargets)) { + photovoltaic.setGenerateDay(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationDay).sum()); + photovoltaic.setGenerateMon(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationMon).sum()); + photovoltaic.setCo2(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getCo2).sum()); + photovoltaic.setTec(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getTec).sum()); + photovoltaic.setIncome(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getIncome).sum()); + photovoltaic.setDeforest(mateTargets.stream().mapToDouble(PhotovoltaicTargetVo::getDeforest).sum()); + } + } + + /** + * App功率/发电量查询 + * + * @param deptId + * @param type + * @return + */ + @Override + public List app_load_generate(Long deptId, String type, String queryType) { + // 查询光伏站点 + List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); + if (CollectionUtil.isEmpty(stations)) { + return new ArrayList<>(); + } + // 区别查询周期 + switch (queryType) { + // 日 + case "0": + return this.periodLoadDay(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + // 周 + case "1": + return this.periodLoadGenerate(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()), type, true); + // 月 + case "2": + return this.periodLoadGenerate(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()), type, false); + // 年 + case "3": + return this.periodLoadGenerateYear(stations.stream().map(StationEntity::getId).collect(Collectors.toList())); + default: + throw new ServiceException("无效查询类型!"); + + } + } + + /** + * 查询光伏设备日数据 + * + * @param stations + * @return + */ + private List periodLoadDay(List stations) { + // FIXME 测试数据 + List hours = getDayHours(); + Random random = new Random(); + return hours.stream().map(hour -> { + PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); + target.setPeriod(hour); + target.setValue((float) (random.nextDouble() * 500)); + return target; + }).sorted(Comparator.comparing(PhotovoltaicLoadGenerateVo::getPeriod)).collect(Collectors.toList()); /*// redis实时数据 List photovoltaics = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); @@ -1247,294 +1282,307 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { target.setValue((float) entry.getValue().stream().mapToDouble(o-> Double.parseDouble(String.valueOf(o.getVal()))).sum()); return target; }).collect(Collectors.toList());*/ - } - - /** - * 查询周、月数据 - * - * @param type - * @param flag - * @return - */ - private List periodLoadGenerate(List stations, String type, boolean flag) { - // redis实时数据 - List photovoltaics = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - if (CollectionUtil.isEmpty(photovoltaics)) { - return new ArrayList(); - } - // 过滤有效光伏设备 - List filters = photovoltaics.stream().filter(photovoltaic -> stations.contains(photovoltaic.getDeptId())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(filters)) { - return new ArrayList<>(); - } - // 数据集合 - List targets = new ArrayList<>(); - for (PhotovoltaicTargetVo target : filters) { - if (CollectionUtil.isEmpty(target.getGenerationPowerVoList())) { - continue; - } - targets.addAll(target.getGenerationPowerVoList()); - } - if (CollectionUtil.isEmpty(targets)) { - return new ArrayList<>(); - } - List weeks = this.getRecentWeek(); - // 周 - if (flag) { - // 根据日期分组 - return targets.stream().filter(generation -> weeks.contains(generation.getDate())).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { - PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); - target.setPeriod(entry.getKey()); - if (HomePageConstant.PHOTOVOLTAIC_LOAD_TARGET.equals(type)) { - target.setValue((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getLoad).sum()); - } else { - target.setValue((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerate).sum()); - } - return target; - }).sorted(Comparator.comparing(PhotovoltaicLoadGenerateVo::getPeriod)).collect(Collectors.toList()); - } - // 月 - return targets.stream().collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { - PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); - target.setPeriod(entry.getKey()); - if (HomePageConstant.PHOTOVOLTAIC_LOAD_TARGET.equals(type)) { - target.setValue((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getLoad).sum()); - } else { - target.setValue((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerate).sum()); - } - return target; - }).sorted(Comparator.comparing(PhotovoltaicLoadGenerateVo::getPeriod)).collect(Collectors.toList()); - } - - /** - * 光伏站点年数据查询 - * - * @param stations - * @return - */ - private List periodLoadGenerateYear(List stations) { - // 站点近年发电数据 key - stationCode value - 月份,发电量 - Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); - if (MapUtils.isEmpty(map)) { - return new ArrayList<>(); - } - List> filter = map.entrySet().stream().filter(e -> stations.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(filter)) { - return new ArrayList<>(); - } - // 根据月份分组 - List powerMonthVos = new ArrayList<>(); - filter.forEach(item -> { - item.forEach((key, value) -> { - PowerMonthVo powerMonthVo = new PowerMonthVo(); - powerMonthVo.setStrMonth(key); - powerMonthVo.setPower(value); - powerMonthVos.add(powerMonthVo); - }); - }); - Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); - // 总和所有相同月份的发电量 - String year = String.valueOf(LocalDate.now().getYear()); - return months.entrySet().stream().filter(entry -> entry.getKey().contains(year)).map(entry -> { - PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); - target.setPeriod(entry.getKey()); - target.setValue((float) entry.getValue().stream().mapToDouble(PowerMonthVo::getPower).sum()); - return target; - }).sorted(Comparator.comparing(PhotovoltaicLoadGenerateVo::getPeriod)).collect(Collectors.toList()); - } - - - /** - * 获取实时温度 - * - * @param weather - * @param code - * @return - */ - private String temp(Map weather, String code) { - if (MapUtils.isEmpty(weather)) { - return "21"; - } - HeWeatherWeatherNowResponse now = weather.get(code); - if (ObjectUtil.isEmpty(now) || ObjectUtil.isEmpty(now.getNow())) { - return "21"; - } - return now.getNow().getTemp(); - } - - /** - * 获取七天天气 - * - * @param weekWeather - * @param code - * @return - */ - private List week(Map weekWeather, String code) { - if (MapUtils.isEmpty(weekWeather)) { - return null; - } - HeWeatherWeatherDailyResponse week = weekWeather.get(code); - if (ObjectUtil.isEmpty(week)) { - return null; - } - return week.getDaily(); - } - - /** - * 获取站点运行天数 - * - * @param station - * @return - */ - private int run_day(StationEntity station) { - if (ObjectUtil.isEmpty(station.getCommissionTime())) { - return 0; - } - // 计算投运时间与当前时间相隔天数 - Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); - return (int) dur.toDays(); - } - - /** - * 站点实时数据统计 - * - * @param photovoltaic - */ - private void real_data(PhotovoltaicStationVo photovoltaic) { - // 站点设备检查 - if (CollectionUtil.isEmpty(photovoltaic.getDevices())) { - return; - } - // 容量 - photovoltaic.setCapacity(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getCapacity).sum()); - // 总发电量 - photovoltaic.setGenerate(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerate).sum()); - // 收益 - photovoltaic.setIncome(photovoltaic.getGenerate() * 0.34); - // 年发电量 - photovoltaic.setGenerateYear(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerateYear).sum()); - // 月发电量 - photovoltaic.setGenerateMon(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerateMon).sum()); - // 日发电量 - photovoltaic.setGenerateDay(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerateDay).sum()); - // 功率 - photovoltaic.setLoad(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getLoad).sum()); - } - - /** - * 光伏设备实时、指标数据 - * - * @param devices - * @param reals - * @param targets - * @return - */ - private List deviceRealTarget(List devices, List reals, List targets) { - if (CollectionUtil.isEmpty(devices)) { - return new ArrayList<>(); - } - return devices.stream().map(device -> { - PhotovoltaicDeviceVo item = new PhotovoltaicDeviceVo(); - item.setDeviceCode(device.getEmCode()); - item.setDeviceName(device.getName()); - item.setDeptId(device.getCreateDept()); - // 装机容量 - item.setCapacity(device.getInstalledCapacity()); - // 实时数据 - List mateReals = reals.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(mateReals)) { - // 总发电量、实时功率、电压、电流、环比功率 - item.setGenerate(mateReals.get(0).getGenerate()); - item.setLoad(mateReals.get(0).getLoad()); - item.setVoltage(mateReals.get(0).getVoltage()); - item.setCurrent(mateReals.get(0).getCurrent()); - // 环比功率 - if (Math.abs(mateReals.get(0).getLoad()) <= 0 || mateReals.get(0).getLastLoad() <= 0) { - item.setLoadRatio(0.0); - } else { - item.setLoadRatio(BigDecimal.valueOf((mateReals.get(0).getLoad() - mateReals.get(0).getLastLoad()) / mateReals.get(0).getLastLoad() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - - } - // 指标数据 - List mateTargets = targets.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(mateTargets)) { - // 年发电量、月发电量、日发电量、co2减排、节约标准煤、收益、30天发电量、当日功率、环比日发电量 - item.setGenerateYear(mateTargets.get(0).getGenerationYear()); - item.setGenerateMon(mateTargets.get(0).getGenerationMon()); - item.setGenerateDay(mateTargets.get(0).getGenerationDay()); - item.setCo2(mateTargets.get(0).getCo2()); - item.setTec(mateTargets.get(0).getTec()); - item.setDeforest(mateTargets.get(0).getDeforest()); - item.setIncome(mateTargets.get(0).getIncome()); - item.setActivePowerVoList(mateTargets.get(0).getActivePowerVoList()); - item.setGenerationPowerVoList(mateTargets.get(0).getGenerationPowerVoList()); - // 环比发电量 - if (Math.abs(mateTargets.get(0).getGenerationDay()) <= 0 || mateTargets.get(0).getGenerationYesterday() <= 0) { - item.setGenerateDayRatio(0.0); - } else { - item.setGenerateDayRatio(BigDecimal.valueOf((mateTargets.get(0).getGenerationDay() - mateTargets.get(0).getGenerationYesterday()) / mateTargets.get(0).getGenerationYesterday() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - } - return item; - }).collect(Collectors.toList()); - } - - /** - * 设备排行榜 - * - * @param devices - * @return - */ - private List deviceCharts(List devices) { - if (CollectionUtil.isEmpty(devices)) { - return new ArrayList<>(); - } - return devices.stream().map(device -> { - PhotovoltaicDeviceChartsVo chart = new PhotovoltaicDeviceChartsVo(); - chart.setDeptId(device.getDeptId()); - chart.setDeviceCode(device.getDeviceCode()); - chart.setDeviceName(device.getDeviceName()); - chart.setLoad(device.getLoad()); - chart.setGenerate(device.getGenerate()); - return chart; - }).sorted(Comparator.comparing(PhotovoltaicDeviceChartsVo::getGenerate)).collect(Collectors.toList()); - } - - /** - * 年发电量比较概括 - * - * @return - */ - private List generateSurvey(Long station) { - Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); - if (MapUtils.isEmpty(map)) { - return new ArrayList<>(); - } - // 站点发电数据 - if (!map.containsKey(station)) { - return new ArrayList<>(); - } - // 转换成集合 - List generates = new ArrayList<>(); - map.get(station).forEach((key, value) -> { - PowerMonthVo generate = new PowerMonthVo(); - LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), key), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - generate.setYear(localDate.getYear()); - generate.setMonth(localDate.getMonthValue()); - generate.setStrMonth(key); - generate.setPower(value); - generates.add(generate); - }); - // 根据年份分组 - Map> year = generates.stream().collect(Collectors.groupingBy(PowerMonthVo::getYear)); - // 返回结果集 - return year.entrySet().stream().map(entry -> { - PowerYearVo powerYearVo = new PowerYearVo(); - powerYearVo.setYear(entry.getKey()); - List sortValue = entry.getValue().stream().sorted(Comparator.comparing(PowerMonthVo::getMonth)).collect(Collectors.toList()); - powerYearVo.setPowerMonthVoList(sortValue); - return powerYearVo; - }).collect(Collectors.toList()); - } + } + + /** + * 查询周、月数据 + * + * @param type + * @param flag + * @return + */ + private List periodLoadGenerate(List stations, String type, boolean flag) { + // redis实时数据 + List photovoltaics = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); + if (CollectionUtil.isEmpty(photovoltaics)) { + return new ArrayList(); + } + // 过滤有效光伏设备 + List filters = photovoltaics.stream().filter(photovoltaic -> stations.contains(photovoltaic.getDeptId())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(filters)) { + return new ArrayList<>(); + } + // 数据集合 + List targets = new ArrayList<>(); + for (PhotovoltaicTargetVo target : filters) { + if (CollectionUtil.isEmpty(target.getGenerationPowerVoList())) { + continue; + } + targets.addAll(target.getGenerationPowerVoList()); + } + if (CollectionUtil.isEmpty(targets)) { + return new ArrayList<>(); + } + List weeks = this.getRecentWeek(); + // 周 + if (flag) { + // 根据日期分组 + return targets.stream().filter(generation -> weeks.contains(generation.getDate())).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { + PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); + target.setPeriod(entry.getKey()); + if (HomePageConstant.PHOTOVOLTAIC_LOAD_TARGET.equals(type)) { + target.setValue((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getLoad).sum()); + } else { + target.setValue((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerate).sum()); + } + return target; + }).sorted(Comparator.comparing(PhotovoltaicLoadGenerateVo::getPeriod)).collect(Collectors.toList()); + } + // 月 + return targets.stream().collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { + PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); + target.setPeriod(entry.getKey()); + if (HomePageConstant.PHOTOVOLTAIC_LOAD_TARGET.equals(type)) { + target.setValue((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getLoad).sum()); + } else { + target.setValue((float) entry.getValue().stream().mapToDouble(GenerationPowerVo::getGenerate).sum()); + } + return target; + }).sorted(Comparator.comparing(PhotovoltaicLoadGenerateVo::getPeriod)).collect(Collectors.toList()); + } + + /** + * 光伏站点年数据查询 + * + * @param stations + * @return + */ + private List periodLoadGenerateYear(List stations) { + // 站点近年发电数据 key - stationCode value - 月份,发电量 + Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); + if (MapUtils.isEmpty(map)) { + return new ArrayList<>(); + } + List> filter = map.entrySet().stream().filter(e -> stations.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(filter)) { + return new ArrayList<>(); + } + // 根据月份分组 + List powerMonthVos = new ArrayList<>(); + filter.forEach(item -> { + item.forEach((key, value) -> { + PowerMonthVo powerMonthVo = new PowerMonthVo(); + powerMonthVo.setStrMonth(key); + powerMonthVo.setPower(value); + powerMonthVos.add(powerMonthVo); + }); + }); + Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); + // 总和所有相同月份的发电量 + String year = String.valueOf(LocalDate.now().getYear()); + return months.entrySet().stream().filter(entry -> entry.getKey().contains(year)).map(entry -> { + PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); + target.setPeriod(entry.getKey()); + target.setValue((float) entry.getValue().stream().mapToDouble(PowerMonthVo::getPower).sum()); + return target; + }).sorted(Comparator.comparing(PhotovoltaicLoadGenerateVo::getPeriod)).collect(Collectors.toList()); + } + + + /** + * 获取实时温度 + * + * @param weather + * @param code + * @return + */ + private String temp(Map weather, String code) { + if (MapUtils.isEmpty(weather)) { + return "21"; + } + HeWeatherWeatherNowResponse now = weather.get(code); + if (ObjectUtil.isEmpty(now) || ObjectUtil.isEmpty(now.getNow())) { + return "21"; + } + return now.getNow().getTemp(); + } + + /** + * 获取七天天气 + * + * @param weekWeather + * @param code + * @return + */ + private List week(Map weekWeather, String code) { + if (MapUtils.isEmpty(weekWeather)) { + return null; + } + HeWeatherWeatherDailyResponse week = weekWeather.get(code); + if (ObjectUtil.isEmpty(week)) { + return null; + } + return week.getDaily(); + } + + /** + * 获取站点运行天数 + * + * @param station + * @return + */ + private int run_day(StationEntity station) { + if (ObjectUtil.isEmpty(station.getCommissionTime())) { + return 0; + } + // 计算投运时间与当前时间相隔天数 + Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); + return (int) dur.toDays(); + } + + /** + * 站点实时数据统计 + * + * @param photovoltaic + */ + private void real_data(PhotovoltaicStationVo photovoltaic) { + // 站点设备检查 + if (CollectionUtil.isEmpty(photovoltaic.getDevices())) { + return; + } + // 容量 + photovoltaic.setCapacity(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getCapacity).sum()); + // 总发电量 + photovoltaic.setGenerate(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerate).sum()); + // 收益 + photovoltaic.setIncome(photovoltaic.getGenerate() * 0.34); + // 年发电量 + photovoltaic.setGenerateYear(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerateYear).sum()); + // 月发电量 + photovoltaic.setGenerateMon(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerateMon).sum()); + // 日发电量 + photovoltaic.setGenerateDay(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerateDay).sum()); + // 功率 + photovoltaic.setLoad(photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getLoad).sum()); + double generationDay = photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerateDay).sum(); + double generationYesterday = photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getGenerationYesterday).sum(); + // 环比发电量 + if (Math.abs(generationDay) <= 0 || Math.abs(generationYesterday) <= 0) { + photovoltaic.setGenerateDayRatio(0.0); + } else { + photovoltaic.setGenerateDayRatio(BigDecimal.valueOf((generationDay - generationYesterday) / generationYesterday * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + double load = photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getLoad).sum(); + double lastLoad = photovoltaic.getDevices().stream().mapToDouble(PhotovoltaicDeviceVo::getLastLoad).sum(); + // 环比功率 + if (Math.abs(load) <= 0 || Math.abs(lastLoad) <= 0) { + photovoltaic.setLoadRatio(0.0); + } else { + photovoltaic.setLoadRatio(BigDecimal.valueOf((load - lastLoad) / lastLoad * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + + } + + /** + * 站点指标数据统计 + * + * @param photovoltaic + */ + private void target_data(PhotovoltaicStationVo photovoltaic) { + List devices = photovoltaic.getDevices(); + if (CollectionUtil.isEmpty(devices)) { + return; + } + // 功率 + photovoltaic.setActivePowerVoList( + devices.stream().map(PhotovoltaicDeviceVo::getActivePowerVoList).flatMap(Collection::stream).collect(Collectors.groupingBy(PhotovoltaicPowerVo::getHour)).entrySet().stream().map(entry -> { + PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); + load.setHour(entry.getKey()); + load.setActivePower(String.valueOf(entry.getValue().stream().mapToDouble(o -> Double.valueOf(o.getActivePower())).sum())); + return load; + }).sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList()) + ); + // 发电量 + photovoltaic.setGenerationPowerVoList( + devices.stream().map(PhotovoltaicDeviceVo::getGenerationPowerVoList).flatMap(Collection::stream).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { + GenerationPowerVo generate = new GenerationPowerVo(); + generate.setDate(entry.getKey()); + generate.setGenerate((float) entry.getValue().stream().mapToDouble(o -> Double.valueOf(o.getGenerate())).sum()); + return generate; + }).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()) + ); + } + + /** + * 光伏设备实时、指标数据 + * + * @param devices + * @param reals + * @param targets + * @return + */ + private List deviceRealTarget(List devices, List reals, List targets) { + if (CollectionUtil.isEmpty(devices)) { + return new ArrayList<>(); + } + return devices.stream().map(device -> { + PhotovoltaicDeviceVo item = new PhotovoltaicDeviceVo(); + item.setDeviceCode(device.getEmCode()); + item.setDeviceName(device.getName()); + item.setDeptId(device.getCreateDept()); + // 装机容量 + item.setCapacity(device.getInstalledCapacity()); + // 实时数据 + List mateReals = reals.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(mateReals)) { + // 总发电量、实时功率、电压、电流、环比功率 + item.setGenerate(mateReals.get(0).getGenerate()); + item.setLoad(mateReals.get(0).getLoad()); + item.setLastLoad(mateReals.get(0).getLastLoad()); + item.setVoltage(mateReals.get(0).getVoltage()); + item.setCurrent(mateReals.get(0).getCurrent()); + // 环比功率 + if (Math.abs(mateReals.get(0).getLoad()) <= 0 || mateReals.get(0).getLastLoad() <= 0) { + item.setLoadRatio(0.0); + } else { + item.setLoadRatio(BigDecimal.valueOf((mateReals.get(0).getLoad() - mateReals.get(0).getLastLoad()) / mateReals.get(0).getLastLoad() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + + } + // 指标数据 + List mateTargets = targets.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(mateTargets)) { + // 年发电量、月发电量、日发电量、co2减排、节约标准煤、收益、30天发电量、当日功率、环比日发电量 + item.setGenerateYear(mateTargets.get(0).getGenerationYear()); + item.setGenerateMon(mateTargets.get(0).getGenerationMon()); + item.setGenerateDay(mateTargets.get(0).getGenerationDay()); + item.setGenerationYesterday(mateTargets.get(0).getGenerationYesterday()); + item.setCo2(mateTargets.get(0).getCo2()); + item.setTec(mateTargets.get(0).getTec()); + item.setDeforest(mateTargets.get(0).getDeforest()); + item.setIncome(mateTargets.get(0).getIncome()); + item.setActivePowerVoList(mateTargets.get(0).getActivePowerVoList()); + item.setGenerationPowerVoList(mateTargets.get(0).getGenerationPowerVoList()); + // 环比发电量 + if (Math.abs(mateTargets.get(0).getGenerationDay()) <= 0 || mateTargets.get(0).getGenerationYesterday() <= 0) { + item.setGenerateDayRatio(0.0); + } else { + item.setGenerateDayRatio(BigDecimal.valueOf((mateTargets.get(0).getGenerationDay() - mateTargets.get(0).getGenerationYesterday()) / mateTargets.get(0).getGenerationYesterday() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + } + return item; + }).collect(Collectors.toList()); + } + + /** + * 设备排行榜 + * + * @param devices + * @return + */ + private List deviceCharts(List devices) { + if (CollectionUtil.isEmpty(devices)) { + return new ArrayList<>(); + } + return devices.stream().map(device -> { + PhotovoltaicDeviceChartsVo chart = new PhotovoltaicDeviceChartsVo(); + chart.setDeptId(device.getDeptId()); + chart.setDeviceCode(device.getDeviceCode()); + chart.setDeviceName(device.getDeviceName()); + chart.setLoad(device.getLoad()); + chart.setGenerate(device.getGenerate()); + return chart; + }).sorted(Comparator.comparing(PhotovoltaicDeviceChartsVo::getGenerate)).collect(Collectors.toList()); + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java index d68d83d..decfe3d 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java @@ -72,6 +72,8 @@ import java.util.stream.Collectors; public class SideHustleServiceImpl implements ISideHustleService { @NotNull + private final IAnalyseDataService analyseDataService; + @NotNull private final IHomePageService homePageService; @NotNull private final IStationService stationService; @@ -488,13 +490,12 @@ public class SideHustleServiceImpl implements ISideHustleService { return; } // 区域站点下设备 - List valid = deviceList.stream().filter(o->deptList.contains(o.getCreateDept())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(valid)){ + List devices = deviceList.stream().filter(o->deptList.contains(o.getCreateDept())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(devices)){ return; } // 获取当班时间内发电量 - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); - float generatingCapacity = homePageService.getPowerGeneration(valid,sdf.format(startDate),sdf.format(endDate),EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType()); + float generatingCapacity = this.generateByDuty(devices,startDate,endDate); // 是否为查询上一班组发电量 if(flag){ NextDutyInfoVo upDutyInfoVo = areaDutyVo.getUpDutyInfoVo(); @@ -505,6 +506,24 @@ public class SideHustleServiceImpl implements ISideHustleService { areaDutyVo.setGeneratingCapacity(generatingCapacity); } + /** + * 根据当班时间查询发电量 + * @param devices + * @param startDate + * @param endDate + * @return + */ + private float generateByDuty(List devices, Date start, Date end) { + float generate = 0f; + if(CollectionUtil.isEmpty(devices)){ + return generate; + } + for(EminfoAndEmParamVo device : devices ){ + generate += analyseDataService.periodTargetFloat(DateUtil.format(start,DateUtil.PATTERN_DATETIME),DateUtil.format(end,DateUtil.PATTERN_DATETIME),3,5,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + }; + return generate; + } + /** * 当班双票 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java index 2c20a7f..878208d 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java @@ -60,6 +60,8 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class WaterServiceImpl implements IWaterService { + private final IAnalyseDataService analyseDataService; + private final IHomePageService homePageService; private final IStationService stationService; @@ -571,13 +573,13 @@ public class WaterServiceImpl implements IWaterService { */ private float getUsrPowerYear(EminfoAndEmParamVo device) { Calendar calendar = Calendar.getInstance(); - String endTime = sdf.format(calendar.getTime()); + String end = sdf.format(calendar.getTime()); calendar.setTime(new Date()); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - String startTime = df.format(calendar.getTime()); + String start = df.format(calendar.getTime()); // 当年用电量 - return homePageService.getAnalyzeCodeAndSignages(device,startTime + " 00:00:00",endTime,EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(),HomePageConstant.ELECTRICITY_CONSUMPTION); + return analyseDataService.periodTargetFloat(start,end,6,5,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); } /** @@ -586,10 +588,10 @@ public class WaterServiceImpl implements IWaterService { * @return */ private float getUsrPowerMon(EminfoAndEmParamVo device) { - String startTime = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - String endTime = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + String start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; + String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); // 当月用电量 - return homePageService.getAnalyzeCodeAndSignages(device,startTime,endTime,EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(),HomePageConstant.ELECTRICITY_CONSUMPTION); + return analyseDataService.periodTargetFloat(start,end,5,5,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); } /** @@ -598,10 +600,9 @@ public class WaterServiceImpl implements IWaterService { * @return */ private float getUsrPowerDay(EminfoAndEmParamVo device) { - Calendar cal = Calendar.getInstance(); - String time = df.format(cal.getTime()); + String time = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); // 当日用电量 - return homePageService.getAnalyzeCodeAndSignages(device,time + " 00:00:00",time + " 23:59:59",EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),HomePageConstant.ELECTRICITY_CONSUMPTION); + return analyseDataService.periodTargetFloat(time + " 00:00:00",time + " 23:59:59",3,5,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); } @@ -751,40 +752,51 @@ public class WaterServiceImpl implements IWaterService { * @return */ private List getUsrPowerVoList(EminfoAndEmParamVo device) { - List usrPowerVoList = new ArrayList<>(); - // 近30天日期集合 - List dayList = this.getRecent30Day(); - for (int i = 0; i < dayList.size() - 1; i++) { - UsrPowerVo usrPowerVo = new UsrPowerVo(); - usrPowerVo.setDate(dayList.get(i)); - // 某天用电量 - float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),HomePageConstant.ELECTRICITY_CONSUMPTION); - usrPowerVo.setUsrPower(power); - usrPowerVoList.add(usrPowerVo); - } - return usrPowerVoList; + String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + List records = analyseDataService.periodTargetData(start,end,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),5,device.getEmCode(),HomePageConstant.ELECTRICITY_CONSUMPTION); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record -> { + UsrPowerVo usr = new UsrPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + usr.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); + usr.setUsrPower(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); + return usr; + }).collect(Collectors.toList()); } /** * 近3年发电量 + * * @param device * @return */ private Map getUsrYearMap(EminfoAndEmParamVo device) { - // 返回map - Map usrYearMap = new HashMap<>(); - // 获取需要遍历月份 - List monList = homePageService.getMonthList(2, 12,true); - for (int i = 0; i < monList.size() - 1; i++) { - if (homePageService.compareDate(monList.get(i))) { - usrYearMap.put(monList.get(i), 0f); - continue; - } - // 设备某月用电量 - float power = homePageService.getAnalyzeCodeAndSignages(device, monList.get(i) + " 00:00:00", monList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(),HomePageConstant.ELECTRICITY_CONSUMPTION); - usrYearMap.put(monList.get(i), power); - } - return usrYearMap; + // 开始时间 + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 结束日期 + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 查询数据 + List records = analyseDataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return new HashMap<>(); + } + return records.stream().map(record -> { + PowerMonthVo generate = new PowerMonthVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setStrMonth(DateUtil.format(time, DateUtil.PATTERN_DATE)); + generate.setPower(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); + return generate; + }).collect(Collectors.toMap(PowerMonthVo::getStrMonth,PowerMonthVo::getPower)); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WebHomeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WebHomeServiceImpl.java index e90839d..ef89f5a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WebHomeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WebHomeServiceImpl.java @@ -15,6 +15,7 @@ import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationAttributeService; import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; import com.hnac.hzinfo.datasearch.soe.ISoeClient; import com.hnac.hzinfo.datasearch.soe.domian.SoeData; import lombok.RequiredArgsConstructor; @@ -44,6 +45,8 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class WebHomeServiceImpl implements IWebHomeService { + private final IAnalyseDataService analyseDataService; + private final IHomePageService homePageService; private final IMainSystemMonitoringService maintenanceTaskService; @@ -70,10 +73,6 @@ public class WebHomeServiceImpl implements IWebHomeService { private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; - // 日期格式化yyyy-mm-dd - private final SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); - // 日期格式化yyyy-mm-dd - private final SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); /** * 加载水电站机组实时数据 @@ -275,37 +274,36 @@ public class WebHomeServiceImpl implements IWebHomeService { * @return */ private float getGenerationPower(EminfoAndEmParamVo device,int scope) { - String startTime,endTime; - int cycle; + String start,end; + int accessRules; + Calendar calendar = Calendar.getInstance(); switch (scope){ // 年 case 0: - Calendar calendar = Calendar.getInstance(); - endTime = sdf.format(calendar.getTime()); + end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); calendar.setTime(new Date()); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - startTime = df.format(calendar.getTime()) + " 00:00:00"; - cycle = EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(); + start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + accessRules = EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(); break; // 月 case 1: - startTime = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - endTime = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - cycle = EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(); + start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + accessRules = EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(); break; // 日 case 2: - Calendar cal = Calendar.getInstance(); - String time = df.format(cal.getTime()); - startTime = time + " 00:00:00"; - endTime = time + " 23:59:59"; - cycle = EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(); + String time = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + start = time + " 00:00:00"; + end = time + " 23:59:59"; + accessRules = EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(); break; default: throw new IllegalStateException("Unexpected value: " + scope); } - return homePageService.getAnalyzeCodeAndSignages(device,startTime,endTime,cycle,HomePageConstant.HYDROPOWER_GENERATE_POWER); + return analyseDataService.periodTargetFloat(start,end,accessRules,5,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); } /** @@ -314,40 +312,21 @@ public class WebHomeServiceImpl implements IWebHomeService { * @return */ private List getGenerationPowerList(EminfoAndEmParamVo device) { - List generationPowerVoList = new ArrayList<>(); - // 近30天日期集合 - List dayList = this.getRecent30Day(); - for (int i = 0; i < dayList.size() - 1; i++) { - GenerationPowerVo generationPowerVo = new GenerationPowerVo(); - generationPowerVo.setDate(dayList.get(i)); - // 某天发电量 - float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - generationPowerVo.setGenerate(power); - generationPowerVoList.add(generationPowerVo); - } - return generationPowerVoList; - } - - - /** - * 获取近30天集合 - * @return - */ - private List getRecent30Day() { - List list = new ArrayList<>(); - // 开始日期 + String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.add(Calendar.DATE, + 1); - list.add(df.format(calendar.getTime())); - // 获取日期之间的月 - int i = 0; - while (i < 30) { - calendar.add(Calendar.DATE, - 1); - list.add(df.format(calendar.getTime())); - i++; - } - return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + List records = analyseDataService.periodTargetData(start,end,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record -> { + GenerationPowerVo generate = new GenerationPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); + generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); + return generate; + }).collect(Collectors.toList()); } /**