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 7819df5..f4f2773 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 @@ -177,7 +177,9 @@ public interface HomePageConstant { /*==========================================================================================*/ // 光伏指标属性 String PHOTOVOLTAIC_GENERATE = "generation_capacity"; // 发电量 - String PHOTOVOLTAIC_LOAD = "active_power"; // 功率 + String PHOTOVOLTAIC_LOAD = "active_power"; // 功率 + + String PHOTOVOLTAIC_LOAD_TARGET = "0"; /*==========================================================================================*/ // 水电集团、区域指标关联 /**功率**/ diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationPowerVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationPowerVo.java index afc10af..b744dba 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationPowerVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationPowerVo.java @@ -12,5 +12,8 @@ public class GenerationPowerVo { private String date; @ApiModelProperty(value = "发电量") - private Float generationPower; + private Float generate; + + @ApiModelProperty(value = "功率·") + private Float load; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationVo.java index cb1f13f..1c23bce 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationVo.java @@ -17,6 +17,6 @@ public class GenerationVo { @ApiModelProperty(value = "周期") private String period; - @ApiModelProperty(value = "月发电量") + @ApiModelProperty(value = "发电量") private Float power; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceStateVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceStateVo.java new file mode 100644 index 0000000..1cd5742 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceStateVo.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.operational.main.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + * @date 2023/04/03 16:57:22 + * @version 4.0.0 + */ +@Data +@ApiModel(value = "光伏站点设备状态对象") +public class PhotovoltaicDeviceStateVo { + + @ApiModelProperty(value = "设备装态 : 0 - 离线 1 - 在线 2 - 故障") + private Integer state; + + @ApiModelProperty(value = "数量") + private Integer count; +} 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 3e62dab..b4b9c05 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 @@ -75,6 +75,11 @@ public class PhotovoltaicDeviceVo { @JsonSerialize(nullsUsing = NullSerializer.class) private Double tec; + + @ApiModelProperty(value = "减少森林砍伐:1kwh = 0.000553") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double deforest; + @ApiModelProperty(value = "收益: 元") @JsonSerialize(nullsUsing = NullSerializer.class) private Double income; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadGenerateVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadGenerateVo.java index 67124b7..0a093a1 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadGenerateVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadGenerateVo.java @@ -22,68 +22,10 @@ import java.util.List; @ApiModel(value = "水利站点首页对象") public class PhotovoltaicLoadGenerateVo { - @ApiModelProperty(value = "机构Id") - private Long deptId; + @ApiModelProperty(value = "周期") + private String period; - @ApiModelProperty(value = "机构名称") - private String deptName; + @ApiModelProperty(value = "数据值") + private Float value; - @ApiModelProperty(value = "站点编码") - private String stationCode; - - @ApiModelProperty(value = "地址") - private String address; - - @ApiModelProperty(value = "投运时间") - @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) - @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) - private LocalDateTime operationTime; - - @ApiModelProperty(value = "总装机容量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double capacity; - - @ApiModelProperty(value = "安全运行天数") - private Integer runDay; - - @ApiModelProperty(value = "总发电负荷") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double load; - - @ApiModelProperty(value = "日发电量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generateDay; - - @ApiModelProperty(value = "月发电量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generateMon; - - @ApiModelProperty(value = "年发电量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generateYear; - - @ApiModelProperty(value = "总发电量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generate; - - @ApiModelProperty(value = "站点实时温度") - private String temp; - - @ApiModelProperty(value = "站点收益") - private Double income; - - @ApiModelProperty(value = "逆变器数量") - private Integer inverterCount; - - @ApiModelProperty(value = "七日内天气") - private List weather; - - @ApiModelProperty(value = "发电排行") - private List devices; - - @ApiModelProperty(value = "年发电量完成百分比") - private List generateSurvey; - - @ApiModelProperty(value = "设备信息") - private List charts; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadVo.java new file mode 100644 index 0000000..22733f7 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadVo.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.operational.main.vo; + + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + * @date 2023/04/04 09:28:34 + * @version 4.0.0 + */ +@Data +@ApiModel(value = "发电量数据") +public class PhotovoltaicLoadVo { + + @ApiModelProperty(value = "机构ID") + private Long deptId; + + @ApiModelProperty(value = "站点编码") + private String code; + + @ApiModelProperty(value = "站点名称") + private String name; + + @ApiModelProperty(value = "实时功率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double load; +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java index 3805891..baea493 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java @@ -19,7 +19,7 @@ import java.util.List; * @version 4.0.0 */ @Data -@ApiModel(value = "水利站点首页对象") +@ApiModel(value = "光伏站点首页对象") public class PhotovoltaicStationAppVo { @ApiModelProperty(value = "机构Id") @@ -34,18 +34,6 @@ public class PhotovoltaicStationAppVo { @ApiModelProperty(value = "地址") private String address; - @ApiModelProperty(value = "投运时间") - @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) - @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) - private LocalDateTime operationTime; - - @ApiModelProperty(value = "总装机容量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double capacity; - - @ApiModelProperty(value = "安全运行天数") - private Integer runDay; - @ApiModelProperty(value = "总发电负荷") @JsonSerialize(nullsUsing = NullSerializer.class) private Double load; @@ -58,10 +46,6 @@ public class PhotovoltaicStationAppVo { @JsonSerialize(nullsUsing = NullSerializer.class) private Double generateMon; - @ApiModelProperty(value = "年发电量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generateYear; - @ApiModelProperty(value = "总发电量") @JsonSerialize(nullsUsing = NullSerializer.class) private Double generate; @@ -72,18 +56,19 @@ public class PhotovoltaicStationAppVo { @ApiModelProperty(value = "站点收益") private Double income; - @ApiModelProperty(value = "逆变器数量") - private Integer inverterCount; - - @ApiModelProperty(value = "七日内天气") - private List weather; + @ApiModelProperty(value = "co2减排: kg") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double co2; - @ApiModelProperty(value = "发电排行") - private List devices; + @ApiModelProperty(value = "节约标准煤减排: kt") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double tec; - @ApiModelProperty(value = "年发电量完成百分比") - private List generateSurvey; + @ApiModelProperty(value = "减少森林砍伐:1kwh = 0.000553") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double deforest; - @ApiModelProperty(value = "设备信息") - private List charts; + @ApiModelProperty(value = "减少森林砍伐:1kwh = 0.000553") + @JsonSerialize(nullsUsing = NullSerializer.class) + private List deviceState; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java index dd267f3..5c3e427 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java @@ -25,63 +25,67 @@ public class PhotovoltaicSubordinateAppVo { @ApiModelProperty(value = "机构名称") private String deptName; - @ApiModelProperty(value = "地市编码") - private String areaCode; - - @ApiModelProperty(value = "地市名称") - private String areaName; + @ApiModelProperty(value = "温度") + private String temp; - @ApiModelProperty(value = "光伏站点类型:0-个体光伏站 1-厂房光伏站") - private Long type; - - @ApiModelProperty("经度(东经)") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Float lgtd; - - @ApiModelProperty("纬度(北纬)") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Float lttd; + @ApiModelProperty(value = "地址") + private String address; @ApiModelProperty(value = "容量") @JsonSerialize(nullsUsing = NullSerializer.class) private Double capacity; - @ApiModelProperty(value = "功率") + @ApiModelProperty(value = "今日发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generateDay; + + @ApiModelProperty(value = "实时功率") @JsonSerialize(nullsUsing = NullSerializer.class) private Double load; - @ApiModelProperty(value = "发电量") + @ApiModelProperty(value = "站点实时功率列表") + private List stationLoads; + + @ApiModelProperty(value = "日常任务数量") @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generation; + private Integer maintenanceCount; - @ApiModelProperty(value = "发电占比") + @ApiModelProperty(value = "日常任务完成数量") @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generationRate; + private Integer maintenanceFinishCount; - @ApiModelProperty(value = "容量利用率") + @ApiModelProperty(value = "缺陷任务数量") @JsonSerialize(nullsUsing = NullSerializer.class) - private Double capacityUse; + private Integer defectCount; - @ApiModelProperty(value = "电站利用率") + @ApiModelProperty(value = "缺陷任务完成数量") @JsonSerialize(nullsUsing = NullSerializer.class) - private Double stationUse; + private Integer defectFinishCount; - @ApiModelProperty(value = "站点实时温度") - private String temp; + @ApiModelProperty(value = "检修任务数量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Integer overhaulCount; - @ApiModelProperty(value = "七日内天气") - private List weather; + @ApiModelProperty(value = "检修任务完成数量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Integer overhaulFinishCount; - @ApiModelProperty(value = "排序") - private Integer sort; + @ApiModelProperty(value = "操作票任务数量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Integer operateCount; - @ApiModelProperty(value = "站点数量") + @ApiModelProperty(value = "操作票任务完成数量") @JsonSerialize(nullsUsing = NullSerializer.class) - private Long stationCount; + private Integer operateFinishCount; - @ApiModelProperty(value = "站点使用数量") + @ApiModelProperty(value = "操作票任务数量") @JsonSerialize(nullsUsing = NullSerializer.class) - private Long stationUseCount; + private Integer workCount; + @ApiModelProperty(value = "操作票任务完成数量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Integer workFinishCount; + @ApiModelProperty(value = "排序") + private Integer sort; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/PhotovoltaicController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/PhotovoltaicController.java index 2490482..9170069 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/PhotovoltaicController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/PhotovoltaicController.java @@ -80,7 +80,8 @@ public class PhotovoltaicController extends BladeController { @GetMapping("/app_load_generate") @ApiOperationSupport(order = 3) public R app_load_generate(@ApiParam(value = "区域/站点机构编号") Long deptId, - @ApiParam(value = "查询类型: 0 - 发电量 1 - 功率") Long type) { - return R.data(service.app_load_generate(deptId,type)); + @ApiParam(value = "数据类型: 0 - 功率 1 - 发电量") String type, + @ApiParam(value = "查询类型: 0 - 日 1 - 周 2 - 月 3 - 年") String queryType) { + return R.data(service.app_load_generate(deptId,type,queryType)); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java index ef30137..8dbc37b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java @@ -1,8 +1,9 @@ package com.hnac.hzims.operational.main.service; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; -import org.apache.poi.ss.formula.functions.T; import java.util.List; import java.util.function.Function; @@ -11,6 +12,10 @@ import java.util.function.Function; * @author hx */ public interface IAnalyseDataService { + List getAnalyzeCodeBySignages(Function convert, T resource); + + List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages); + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/PhotovoltaicService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/PhotovoltaicService.java index 009cb18..3ae3e87 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/PhotovoltaicService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/PhotovoltaicService.java @@ -30,11 +30,11 @@ public interface PhotovoltaicService { PhotovoltaicStationVo station(Long deptId); // app区域数据 - PhotovoltaicStationAppVo app_subordinate(Long deptId); + List app_subordinate(Long deptId); // app站点数据 PhotovoltaicStationAppVo app_station(Long deptId); // App功率/发电量查询 - PhotovoltaicLoadGenerateVo app_load_generate(Long deptId, Long type); + List app_load_generate(Long deptId, String type,String queryType); } 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 d2b360e..fe95831 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 @@ -1,15 +1,25 @@ package com.hnac.hzims.operational.main.service.impl; import com.google.common.collect.Lists; +import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; +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.AnalyzeCodeBySignagesVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; 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.function.Function; import java.util.stream.Collectors; @@ -33,4 +43,40 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { } return result; } + + /*** + * 指标数据查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param cycleType + * @param deviceCode + * @param signages + * @return + */ + @Override + public List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setSignages(signages); + // 取数规则: 0=(整点值/最早值)、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值) 6=最新值 + analyzeDataConditionPO.setAccessRules(accessRules); + // 周期类型: 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.setSignboardConditions(signboardConditions); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return new ArrayList<>(); + } + return result.getData().get(0).getList(); + } + + } 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 c3c70c6..7c3a028 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 @@ -13,7 +13,10 @@ import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzims.ticket.workTicket.feign.ITicketInfoClient; +import com.hnac.hzims.ticket.workTicket.vo.TicketMonthVO; import com.hnac.hzinfo.datasearch.PointData; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; import com.hnac.hzinfo.sdk.core.response.HzPage; @@ -38,15 +41,19 @@ import java.text.SimpleDateFormat; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.stream.Collectors; /** * @author ysj - * @date 2023/03/23 16:51:43 * @version 4.0.0 + * @date 2023/03/23 16:51:43 */ @Service @RequiredArgsConstructor @@ -62,42 +69,54 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { 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"; + private final static String recent_year_power_data = "hzims:operation:key:power:data"; + + private final static String recent_year_load_data = "hzims:operation:key:load: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)){ + if (CollectionUtil.isEmpty(devices)) { return; } // 取redis实时数据 Map map = this.getRealData(); List list = new ArrayList<>(); Random random = new Random(); - devices.forEach(device->{ + devices.forEach(device -> { PhotovoltaicRealVo real = new PhotovoltaicRealVo(); real.setDeptId(device.getCreateDept()); real.setDeviceCode(device.getEmCode()); real.setDeviceName(device.getName()); - real.setState(random.nextInt(2)-1); + real.setState(random.nextInt(2) - 1); // 容量 real.setCapacity(device.getInstalledCapacity()); // 发电量 @@ -112,23 +131,24 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { real.setLastLoad(random.nextDouble() * 300); list.add(real); }); - redisTemplate.opsForValue().set(load_photovoltaic_real_key,list); + redisTemplate.opsForValue().set(load_photovoltaic_real_key, list); } /** * 光伏站-逆变器指标加载 + * * @param param */ @Override public void loadPhotovoltaicTarget(String param) { // 有效设备 List devices = this.getPhotovoltaicDevice(); - if(CollectionUtil.isEmpty(devices)){ + if (CollectionUtil.isEmpty(devices)) { return; } List list = new ArrayList<>(); Random random = new Random(); - devices.forEach(device->{ + devices.forEach(device -> { PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); target.setDeptId(device.getCreateDept()); target.setDeviceCode(device.getEmCode()); @@ -165,7 +185,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { target.setGenerationPowerVoList(generationPowerVoList); list.add(target); }); - redisTemplate.opsForValue().set(load_photovoltaic_target_key,list); + redisTemplate.opsForValue().set(load_photovoltaic_target_key, list); } // FIXME 测试模拟 @@ -183,15 +203,16 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 当天运行时长 + * * @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)); + 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); @@ -201,44 +222,65 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { originalDataQuery.setPage(1); // 查询时间范围开关机监测点历史数据 Result> R = historySearchClient.getOriginalDataByRealIds(originalDataQuery); - if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ + if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { return 0.0; } // 过滤相邻开关机状态相同数据 List result = this.filterData(R.getData().getRecords()); - if(CollectionUtil.isEmpty(result)){ + if (CollectionUtil.isEmpty(result)) { return 0.0; } // 开机运行时长 - long time = this.runTime(result,start,end); + 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)){ + if (CollectionUtil.isEmpty(list)) { return null; } List result = new ArrayList<>(); // 遍历数据 - for(int i = 0; i< list.size() ; i++){ + for (int i = 0; i < list.size(); i++) { // 第一个数据保存下来 - if(i == 0){ + if (i == 0) { result.add(list.get(i)); continue; } // 遍历数据状态 String value = list.get(i).getValue(); - if(StringUtil.isBlank(value)){ + if (StringUtil.isBlank(value)) { continue; } // 上一条数据状态 - String up_value = list.get(i-1).getValue(); - if(value.equals(up_value)){ + String up_value = list.get(i - 1).getValue(); + if (value.equals(up_value)) { continue; } result.add(list.get(i)); @@ -248,32 +290,32 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取运行时长 + * * @param result * @return */ - private long runTime(List result,Date startDate,Date endDate) { - if(result.size() == 1){ + private long runTime(List result, Date startDate, Date endDate) { + if (result.size() == 1) { // 一直开机 - if(HomePageConstant.OFF.equals(result.get(0).getValue())){ + if (HomePageConstant.OFF.equals(result.get(0).getValue())) { return endDate.getTime() - startDate.getTime(); } // 一直关机 return 0; } - long time=0; + long time = 0; // 遍历累计开机时长 - for(int i = 0; i< result.size() ; i++){ + for (int i = 0; i < result.size(); i++) { // 记录为开机状态 就计算到下次关机的时间差 - if(HomePageConstant.ON.equals(result.get(i).getValue())){ + if (HomePageConstant.ON.equals(result.get(i).getValue())) { continue; } - Date endTime,startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); + Date endTime, startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); // 遍历至最后一条数据,累计至当前时间 - if(i == result.size() - 1){ + if (i == result.size() - 1) { endTime = endDate; - } - else { - endTime = DateUtil.parse(result.get(i+1).getTime(), DateUtil.PATTERN_DATETIME); + } else { + endTime = DateUtil.parse(result.get(i + 1).getTime(), DateUtil.PATTERN_DATETIME); } time += endTime.getTime() - startTime.getTime(); } @@ -283,18 +325,19 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取年、月、日发电量 + * * @param device * @param scope * @return */ - private float getGenerationPower(EminfoAndEmParamVo device,int scope) { + 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; + String startTime, endTime; int cycle; - switch (scope){ + switch (scope) { // 年 case 0: Calendar calendar = Calendar.getInstance(); @@ -322,24 +365,27 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { default: throw new IllegalStateException("Unexpected value: " + scope); } - return homePageService.getAnalyzeCodeAndSignages(device,startTime,endTime,cycle,HomePageConstant.PHOTOVOLTAIC_GENERATE); + return homePageService.getAnalyzeCodeAndSignages(device, startTime, endTime, cycle, HomePageConstant.PHOTOVOLTAIC_GENERATE); } /** * 近30天发电量 + * * @param device * @return */ private List getGenerationPowerList(EminfoAndEmParamVo device) { List generationPowerVoList = new ArrayList<>(); // 近30天日期集合 + Random random = new Random(); 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.PHOTOVOLTAIC_GENERATE); - generationPowerVo.setGenerationPower(power); + float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00", EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(), HomePageConstant.PHOTOVOLTAIC_GENERATE); + generationPowerVo.setGenerate(power); + generationPowerVo.setLoad((float) (random.nextDouble() * 500)); generationPowerVoList.add(generationPowerVo); } return generationPowerVoList; @@ -347,6 +393,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 近7天发电量 + * * @param device * @return */ @@ -357,10 +404,10 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { SimpleDateFormat sdf = new SimpleDateFormat("EEEE"); for (int i = 0; i < dayList.size() - 1; i++) { GenerationPowerVo generationPowerVo = new GenerationPowerVo(); - generationPowerVo.setDate(sdf.format(DateUtil.parse(dayList.get(i),DateUtil.PATTERN_DATE))); + generationPowerVo.setDate(sdf.format(DateUtil.parse(dayList.get(i), DateUtil.PATTERN_DATE))); // 某天发电量 - float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),HomePageConstant.PHOTOVOLTAIC_GENERATE); - generationPowerVo.setGenerationPower(power); + float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00", EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(), HomePageConstant.PHOTOVOLTAIC_GENERATE); + generationPowerVo.setGenerate(power); generationPowerVoList.add(generationPowerVo); } return generationPowerVoList; @@ -369,6 +416,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 当天功率 + * * @return */ private List getTestDay() { @@ -378,12 +426,12 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 开始日期 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); + 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); + calendar.add(Calendar.HOUR_OF_DAY, +1); list.add(df.format(calendar.getTime())); } return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); @@ -391,6 +439,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取近30天集合 + * * @return */ private List getRecentWeek() { @@ -400,13 +449,13 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 开始日期 Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); - calendar.add(Calendar.DATE, + 1); + calendar.add(Calendar.DATE, +1); list.add(df.format(calendar.getTime())); // 获取日期之间的月 int i = 0; - while (i < 7) { - calendar.add(Calendar.DATE, - 1); + 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()); @@ -414,6 +463,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取近30天集合 + * * @return */ private List getRecent30Day() { @@ -423,12 +473,12 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 开始日期 Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); - calendar.add(Calendar.DATE, + 1); + calendar.add(Calendar.DATE, +1); list.add(df.format(calendar.getTime())); // 获取日期之间的月 int i = 0; while (i < 30) { - calendar.add(Calendar.DATE, - 1); + calendar.add(Calendar.DATE, -1); list.add(df.format(calendar.getTime())); i++; } @@ -437,29 +487,32 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取实时数据 + * * @return */ private Map getRealData() { String json = (String) redisTemplate.opsForValue().get(real_id_key); - if(StringUtil.isBlank(json)){ + if (StringUtil.isBlank(json)) { return null; } - return JSONObject.parseObject(json, new TypeReference>() {}); + 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)){ + 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)){ + if (CollectionUtil.isEmpty(devices)) { return null; } return devices.stream().filter(device -> @@ -469,14 +522,15 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 集团/区域关键指标 + * * @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)){ + List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); + if (CollectionUtil.isEmpty(stations)) { return new PhotovoltaicKPIsVo(); } PhotovoltaicKPIsVo kpi = new PhotovoltaicKPIsVo(); @@ -484,9 +538,9 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { kpi.setCount(stations.size()); // 实时数据 List deviceReals = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); - if(CollectionUtil.isNotEmpty(deviceReals)){ + 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)){ + if (CollectionUtil.isNotEmpty(reals)) { // 容量 kpi.setInstalledCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); // 负荷 @@ -495,11 +549,11 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } // 指标数据 List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - if(CollectionUtil.isEmpty(deviceTargets)){ + 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)){ + if (CollectionUtil.isEmpty(targets)) { return kpi; } // 年发电量 @@ -521,12 +575,13 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取近3年发电量 + * * @return */ private List getPowerList(List stations) { // 站点近年发电数据 key - stationCode value - 月份,发电量 - Map> map = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); - if(MapUtils.isEmpty(map)){ + 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()); @@ -543,7 +598,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { powerMonthVos.add(powerMonthVo); }); }); - Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); + Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); // 总和所有相同月份的发电量 List powerMonthVoList = months.entrySet().stream().map(entry -> { PowerMonthVo powerMonth = new PowerMonthVo(); @@ -571,6 +626,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 集团/区域发电量 + * * @param deptId * @param type * @return @@ -578,17 +634,17 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { @Override public List generation(Long deptId, String type) { // 查询光伏站点 - List stations = stationService.getHomeStationList(deptId,Collections.singletonList(HomePageConstant.PHOTOVOLTAIC),HomePageConstant.HYDROPOWER_SERVETYPE); - if(CollectionUtil.isEmpty(stations)){ + List stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); + if (CollectionUtil.isEmpty(stations)) { return new ArrayList<>(); } - switch (type){ + switch (type) { // 周 case "0": - return this.getGeneration(stations.stream().map(StationEntity::getRefDept).distinct().collect(Collectors.toList()),true); + 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); + 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())); @@ -599,58 +655,60 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取发电量(周/月) + * * @return */ - private List getGeneration(List stations,boolean flag) { + private List getGeneration(List stations, boolean flag) { // redis实时数据 List photovoltaics = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); - if(CollectionUtil.isEmpty(photovoltaics)){ + if (CollectionUtil.isEmpty(photovoltaics)) { return new ArrayList(); } // 过滤有效光伏设备 List filters = photovoltaics.stream().filter(photovoltaic -> stations.contains(photovoltaic.getDeptId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(filters)){ + if (CollectionUtil.isEmpty(filters)) { return new ArrayList<>(); } // 数据集合 List generations = new ArrayList<>(); - for (PhotovoltaicTargetVo target : filters){ - if(CollectionUtil.isEmpty(target.getGenerationPowerVoList())){ + for (PhotovoltaicTargetVo target : filters) { + if (CollectionUtil.isEmpty(target.getGenerationPowerVoList())) { continue; } generations.addAll(target.getGenerationPowerVoList()); } - if(CollectionUtil.isEmpty(generations)){ + if (CollectionUtil.isEmpty(generations)) { return new ArrayList<>(); } List weeks = this.getRecentWeek(); // 周 - if(flag){ + if (flag) { // 根据日期分组 - return generations.stream().filter(generation -> weeks.contains(generation.getDate())).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry->{ + 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::getGenerationPower).sum()); + 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->{ + 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::getGenerationPower).sum()); + 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)){ + 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()); @@ -667,7 +725,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { powerMonthVos.add(powerMonthVo); }); }); - Map> months = powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); + 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 -> { @@ -681,14 +739,15 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 集团/区域下属数据占比 + * * @param deptId * @return */ @Override public List subordinate(Long deptId) { // 获取区域或者站点map结构 - Map> map = sideHustleService.getAreaOrStaion(deptId,Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); - if(MapUtils.isEmpty(map)){ + Map> map = sideHustleService.getAreaOrStaion(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); + if (MapUtils.isEmpty(map)) { return new ArrayList<>(); } // 实时数据 @@ -697,9 +756,9 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); // 遍历数据 List list = new ArrayList<>(); - for (Map.Entry> entry : map.entrySet()) { + for (Map.Entry> entry : map.entrySet()) { PhotovoltaicSubordinateVo subordinate = new PhotovoltaicSubordinateVo(); - if(ObjectUtil.isEmpty(entry.getValue())){ + if (ObjectUtil.isEmpty(entry.getValue())) { continue; } subordinate.setDeptId(entry.getKey().getId()); @@ -712,7 +771,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 省市编码 String areaCode = station.getAreaCode(); subordinate.setAreaCode(areaCode); - if(!StringUtil.isEmpty(areaCode)){ + if (!StringUtil.isEmpty(areaCode)) { String[] arrCode = areaCode.split(","); R R = sysClient.getRegion(arrCode[1]); if (R.isSuccess() && ObjectUtil.isNotEmpty(R.getData())) { @@ -720,23 +779,23 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } } // 站点类型 - if(HomePageConstant.STATION.equals(entry.getKey().getDeptCategory())){ + if (HomePageConstant.STATION.equals(entry.getKey().getDeptCategory())) { subordinate.setType(entry.getValue().get(0).getPhotovoltaicType()); } // 获取实时天气 Map nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); - if(MapUtils.isNotEmpty(nowWeather)){ + if (MapUtils.isNotEmpty(nowWeather)) { subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); } // 获取七天天气 Map weekWeather = weatherService.getWeekWeather(Collections.singletonList(station.getCode())); - if(MapUtils.isNotEmpty(weekWeather)){ + 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)){ + 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()); @@ -744,12 +803,12 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } // 区域/站点 设备指标数据 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)){ + if (CollectionUtil.isNotEmpty(targets)) { subordinate.setGeneration(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum()); } list.add(subordinate); } - if(CollectionUtil.isEmpty(list)){ + if (CollectionUtil.isEmpty(list)) { return new ArrayList<>(); } // 总数据 : 发电量 、 容量 、 电站数 @@ -757,7 +816,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { Double sumLoad = list.stream().mapToDouble(PhotovoltaicSubordinateVo::getCapacity).sum(); Double sumStationCount = list.stream().mapToDouble(PhotovoltaicSubordinateVo::getStationCount).sum(); // 计算 :集团发电占比 电站利用率 容量利用率 - return list.stream().map(subordinate ->{ + return list.stream().map(subordinate -> { if (Math.abs(sumGeneration) <= 0) { subordinate.setGenerationRate(0.0); } else { @@ -779,18 +838,19 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 站点数据 + * * @param deptId * @return */ @Override public PhotovoltaicStationVo station(Long deptId) { // 参数检查 - if(ObjectUtil.isEmpty(deptId)){ + if (ObjectUtil.isEmpty(deptId)) { return new PhotovoltaicStationVo(); } // 查询站点 - StationEntity station = stationService.getOne(Wrappers.lambdaQuery().eq(StationEntity::getRefDept,deptId)); - if(ObjectUtil.isEmpty(station)){ + StationEntity station = stationService.getOne(Wrappers.lambdaQuery().eq(StationEntity::getRefDept, deptId)); + if (ObjectUtil.isEmpty(station)) { return new PhotovoltaicStationVo(); } // 实时监测点数据 @@ -798,7 +858,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 获取站点机组指标数据 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()); + List devices = deviceService.getEmInfoList().stream().filter(o -> o.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); // 实时天气 Map weather = weatherService.getNowWeather(Collections.singletonList(station.getCode())); // 七天天气 @@ -812,15 +872,15 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 站点投运时间 photovoltaic.setOperationTime(station.getCommissionTime()); // 站点实时天气 - photovoltaic.setTemp(this.temp(weather,station.getCode())); + photovoltaic.setTemp(this.temp(weather, station.getCode())); // 站点七天天气 - photovoltaic.setWeather(this.week(weekWeather,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.setDevices(this.deviceRealTarget(devices, reals, targets)); // 设备排行榜 photovoltaic.setCharts(this.deviceCharts(photovoltaic.getDevices())); // 站点实时数据: 装机容量、总发电量、功率、收益 @@ -832,47 +892,406 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * App区域下属数据 + * * @param deptId * @return */ @Override - public PhotovoltaicStationAppVo app_subordinate(Long deptId) { - return null; + 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.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); + } + // 容量、实时功率、今日发电量 + 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) { - return null; + // 参数检查 + 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.setTemp(this.temp(weather, station.getCode())); + 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 PhotovoltaicLoadGenerateVo app_load_generate(Long deptId, Long type) { - return null; + 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); + if(CollectionUtil.isEmpty(photovoltaics)){ + return new ArrayList(); + } + // 过滤有效光伏设备 + List devices = photovoltaics.stream().filter(photovoltaic -> stations.contains(photovoltaic.getDeptId())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); + } + SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATE); + // 开始日期 + Calendar calendar = Calendar.getInstance(); + String start = sdf.format(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)); + String end = sdf.format(calendar.getTime()); + List list = new ArrayList<>(); + for(PhotovoltaicTargetVo device : devices){ + list.addAll(analyseDataService.periodTargetData(start,end,1,2,device.getDeviceCode(),HomePageConstant.PHOTOVOLTAIC_LOAD)); + }; + if(CollectionUtil.isEmpty(list)){ + return new ArrayList<>(); + } + return list.stream().collect(Collectors.groupingBy(AnalyseDataTaosVO::getTs)).entrySet().stream().map(entry ->{ + PhotovoltaicLoadGenerateVo target = new PhotovoltaicLoadGenerateVo(); + LocalDateTime time = LocalDateTime.parse(DateUtil.format(new Date(), entry.getKey()), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)); + target.setPeriod(String.valueOf(time.getHour())); + 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)){ + if (MapUtils.isEmpty(weather)) { return "21"; } HeWeatherWeatherNowResponse now = weather.get(code); - if(ObjectUtil.isEmpty(now) || ObjectUtil.isEmpty(now.getNow())){ + if (ObjectUtil.isEmpty(now) || ObjectUtil.isEmpty(now.getNow())) { return "21"; } return now.getNow().getTemp(); @@ -880,16 +1299,17 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取七天天气 + * * @param weekWeather * @param code * @return */ private List week(Map weekWeather, String code) { - if(MapUtils.isEmpty(weekWeather)){ + if (MapUtils.isEmpty(weekWeather)) { return null; } HeWeatherWeatherDailyResponse week = weekWeather.get(code); - if(ObjectUtil.isEmpty(week)){ + if (ObjectUtil.isEmpty(week)) { return null; } return week.getDaily(); @@ -897,6 +1317,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 获取站点运行天数 + * * @param station * @return */ @@ -911,11 +1332,12 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 站点实时数据统计 + * * @param photovoltaic */ private void real_data(PhotovoltaicStationVo photovoltaic) { // 站点设备检查 - if(CollectionUtil.isEmpty(photovoltaic.getDevices())){ + if (CollectionUtil.isEmpty(photovoltaic.getDevices())) { return; } // 容量 @@ -936,16 +1358,17 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 光伏设备实时、指标数据 + * * @param devices * @param reals * @param targets * @return */ private List deviceRealTarget(List devices, List reals, List targets) { - if(CollectionUtil.isEmpty(devices)){ + if (CollectionUtil.isEmpty(devices)) { return new ArrayList<>(); } - return devices.stream().map(device->{ + return devices.stream().map(device -> { PhotovoltaicDeviceVo item = new PhotovoltaicDeviceVo(); item.setDeviceCode(device.getEmCode()); item.setDeviceName(device.getName()); @@ -953,37 +1376,38 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 装机容量 item.setCapacity(device.getInstalledCapacity()); // 实时数据 - List mateReals = reals.stream().filter(o->o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(mateReals)){ + 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 ){ + if (Math.abs(mateReals.get(0).getLoad()) <= 0 || mateReals.get(0).getLastLoad() <= 0) { item.setLoadRatio(0.0); - }else{ + } 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)){ + 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 ){ + if (Math.abs(mateTargets.get(0).getGenerationDay()) <= 0 || mateTargets.get(0).getGenerationYesterday() <= 0) { item.setGenerateDayRatio(0.0); - }else{ + } 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()); } } @@ -993,14 +1417,15 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 设备排行榜 + * * @param devices * @return */ private List deviceCharts(List devices) { - if(CollectionUtil.isEmpty(devices)){ + if (CollectionUtil.isEmpty(devices)) { return new ArrayList<>(); } - return devices.stream().map(device->{ + return devices.stream().map(device -> { PhotovoltaicDeviceChartsVo chart = new PhotovoltaicDeviceChartsVo(); chart.setDeptId(device.getDeptId()); chart.setDeviceCode(device.getDeviceCode()); @@ -1013,20 +1438,21 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { /** * 年发电量比较概括 + * * @return */ private List generateSurvey(Long station) { - Map> map = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); - if(MapUtils.isEmpty(map)){ + Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); + if (MapUtils.isEmpty(map)) { return new ArrayList<>(); } // 站点发电数据 - if(!map.containsKey(station)){ + if (!map.containsKey(station)) { return new ArrayList<>(); } // 转换成集合 List generates = new ArrayList<>(); - map.get(station).forEach((key,value) -> { + 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()); 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 ceb6160..d68d83d 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 @@ -1634,7 +1634,7 @@ public class SideHustleServiceImpl implements ISideHustleService { if(CollectionUtil.isEmpty(list)){ return 0; } - return (float) list.stream().filter(v->o.equals(v.getDate())).mapToDouble(GenerationPowerVo::getGenerationPower).sum(); + return (float) list.stream().filter(v->o.equals(v.getDate())).mapToDouble(GenerationPowerVo::getGenerate).sum(); } /** 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 de93401..e90839d 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 @@ -322,7 +322,7 @@ public class WebHomeServiceImpl implements IWebHomeService { 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.setGenerationPower(power); + generationPowerVo.setGenerate(power); generationPowerVoList.add(generationPowerVo); } return generationPowerVoList;