From ad67c646d4c35ec2a938c7d170e669e7cea6026c Mon Sep 17 00:00:00 2001 From: yang_shj Date: Mon, 3 Apr 2023 11:59:40 +0800 Subject: [PATCH 1/3] =?UTF-8?q?#App=E5=85=89=E4=BC=8F=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/vo/PhotovoltaicLoadGenerateVo.java | 89 ++++++++++++++++++++++ .../main/vo/PhotovoltaicStationAppVo.java | 89 ++++++++++++++++++++++ .../main/vo/PhotovoltaicSubordinateAppVo.java | 87 +++++++++++++++++++++ .../main/vo/PhotovoltaicSubordinateVo.java | 87 +++++++++++++++++++++ .../hzims/operational/main/vo/SubordinateVo.java | 87 --------------------- .../main/controller/PhotovoltaicController.java | 31 +++++++- .../main/service/PhotovoltaicService.java | 16 ++-- .../main/service/impl/PhotovoltaicServiceImpl.java | 45 +++++++++-- 8 files changed, 431 insertions(+), 100 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadGenerateVo.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateVo.java delete mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/SubordinateVo.java 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 new file mode 100644 index 0000000..67124b7 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadGenerateVo.java @@ -0,0 +1,89 @@ +package com.hnac.hzims.operational.main.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import com.hnac.hzims.hzimsweather.response.weather.Daily; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * @author ysj + * @date 2023/03/29 15:14:34 + * @version 4.0.0 + */ +@Data +@ApiModel(value = "水利站点首页对象") +public class PhotovoltaicLoadGenerateVo { + + @ApiModelProperty(value = "机构Id") + private Long deptId; + + @ApiModelProperty(value = "机构名称") + private String deptName; + + @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/PhotovoltaicStationAppVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java new file mode 100644 index 0000000..3805891 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java @@ -0,0 +1,89 @@ +package com.hnac.hzims.operational.main.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import com.hnac.hzims.hzimsweather.response.weather.Daily; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * @author ysj + * @date 2023/03/29 15:14:34 + * @version 4.0.0 + */ +@Data +@ApiModel(value = "水利站点首页对象") +public class PhotovoltaicStationAppVo { + + @ApiModelProperty(value = "机构Id") + private Long deptId; + + @ApiModelProperty(value = "机构名称") + private String deptName; + + @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/PhotovoltaicSubordinateAppVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java new file mode 100644 index 0000000..dd267f3 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java @@ -0,0 +1,87 @@ +package com.hnac.hzims.operational.main.vo; + + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import com.hnac.hzims.hzimsweather.response.weather.Daily; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/24 09:58:57 + * @version 4.0.0 + */ +@Data +@ApiModel(value = "发电量数据") +public class PhotovoltaicSubordinateAppVo { + + @ApiModelProperty(value = "机构ID") + private Long deptId; + + @ApiModelProperty(value = "机构名称") + private String deptName; + + @ApiModelProperty(value = "地市编码") + private String areaCode; + + @ApiModelProperty(value = "地市名称") + private String areaName; + + @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 = "容量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double capacity; + + @ApiModelProperty(value = "功率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double load; + + @ApiModelProperty(value = "发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generation; + + @ApiModelProperty(value = "发电占比") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generationRate; + + @ApiModelProperty(value = "容量利用率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double capacityUse; + + @ApiModelProperty(value = "电站利用率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double stationUse; + + @ApiModelProperty(value = "站点实时温度") + private String temp; + + @ApiModelProperty(value = "七日内天气") + private List weather; + + @ApiModelProperty(value = "排序") + private Integer sort; + + @ApiModelProperty(value = "站点数量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long stationCount; + + @ApiModelProperty(value = "站点使用数量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long stationUseCount; + + +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateVo.java new file mode 100644 index 0000000..4dd253a --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateVo.java @@ -0,0 +1,87 @@ +package com.hnac.hzims.operational.main.vo; + + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import com.hnac.hzims.hzimsweather.response.weather.Daily; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/24 09:58:57 + * @version 4.0.0 + */ +@Data +@ApiModel(value = "发电量数据") +public class PhotovoltaicSubordinateVo { + + @ApiModelProperty(value = "机构ID") + private Long deptId; + + @ApiModelProperty(value = "机构名称") + private String deptName; + + @ApiModelProperty(value = "地市编码") + private String areaCode; + + @ApiModelProperty(value = "地市名称") + private String areaName; + + @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 = "容量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double capacity; + + @ApiModelProperty(value = "功率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double load; + + @ApiModelProperty(value = "发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generation; + + @ApiModelProperty(value = "发电占比") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double generationRate; + + @ApiModelProperty(value = "容量利用率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double capacityUse; + + @ApiModelProperty(value = "电站利用率") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Double stationUse; + + @ApiModelProperty(value = "站点实时温度") + private String temp; + + @ApiModelProperty(value = "七日内天气") + private List weather; + + @ApiModelProperty(value = "排序") + private Integer sort; + + @ApiModelProperty(value = "站点数量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long stationCount; + + @ApiModelProperty(value = "站点使用数量") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long stationUseCount; + + +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/SubordinateVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/SubordinateVo.java deleted file mode 100644 index 2baaa0b..0000000 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/SubordinateVo.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.hnac.hzims.operational.main.vo; - - -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.NullSerializer; -import com.hnac.hzims.hzimsweather.response.weather.Daily; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import java.util.List; - -/** - * @author ysj - * @date 2023/03/24 09:58:57 - * @version 4.0.0 - */ -@Data -@ApiModel(value = "发电量数据") -public class SubordinateVo { - - @ApiModelProperty(value = "机构ID") - private Long deptId; - - @ApiModelProperty(value = "机构名称") - private String deptName; - - @ApiModelProperty(value = "地市编码") - private String areaCode; - - @ApiModelProperty(value = "地市名称") - private String areaName; - - @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 = "容量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double capacity; - - @ApiModelProperty(value = "功率") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double load; - - @ApiModelProperty(value = "发电量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generation; - - @ApiModelProperty(value = "发电占比") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double generationRate; - - @ApiModelProperty(value = "容量利用率") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double capacityUse; - - @ApiModelProperty(value = "电站利用率") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Double stationUse; - - @ApiModelProperty(value = "站点实时温度") - private String temp; - - @ApiModelProperty(value = "七日内天气") - private List weather; - - @ApiModelProperty(value = "排序") - private Integer sort; - - @ApiModelProperty(value = "站点数量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Long stationCount; - - @ApiModelProperty(value = "站点使用数量") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Long stationUseCount; - - -} 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 506aaf3..2490482 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 @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController; public class PhotovoltaicController extends BladeController { private final PhotovoltaicService service; + @ApiLog @ApiOperation("集团/区域关键指标") @GetMapping("/KPIs") @@ -32,14 +33,16 @@ public class PhotovoltaicController extends BladeController { public R KPIs(@ApiParam(value = "集团/区域机构编号") Long deptId) { return R.data(service.KPIs(deptId)); } + @ApiLog @ApiOperation("集团/区域发电量") @GetMapping("/generation") @ApiOperationSupport(order = 2) public R generation(@ApiParam(value = "集团/区域机构编号") Long deptId, @ApiParam(value = "查询类型:0-周 1-月 -2年") String type) { - return R.data(service.generation(deptId,type)); + return R.data(service.generation(deptId, type)); } + @ApiLog @ApiOperation("集团/区域下属数据占比") @GetMapping("/subordinate") @@ -54,4 +57,30 @@ public class PhotovoltaicController extends BladeController { public R station(@ApiParam(value = "站点机构ID") Long deptId) { return R.data(service.station(deptId)); } + + + @ApiLog + @ApiOperation("App区域下属数据") + @GetMapping("/app_subordinate") + @ApiOperationSupport(order = 3) + public R app_subordinate(@ApiParam(value = "区域/站点机构编号") Long deptId) { + return R.data(service.app_subordinate(deptId)); + } + + @ApiLog + @ApiOperation("App光伏站点数据") + @GetMapping("/app_station") + @ApiOperationSupport(order = 3) + public R app_station(@ApiParam(value = "区域/站点机构编号") Long deptId) { + return R.data(service.app_station(deptId)); + } + + @ApiLog + @ApiOperation("App功率/发电量查询") + @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)); + } } 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 7f8fb6f..009cb18 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 @@ -1,9 +1,6 @@ package com.hnac.hzims.operational.main.service; -import com.hnac.hzims.operational.main.vo.GenerationVo; -import com.hnac.hzims.operational.main.vo.PhotovoltaicKPIsVo; -import com.hnac.hzims.operational.main.vo.PhotovoltaicStationVo; -import com.hnac.hzims.operational.main.vo.SubordinateVo; +import com.hnac.hzims.operational.main.vo.*; import java.util.List; @@ -27,8 +24,17 @@ public interface PhotovoltaicService { List generation(Long deptId,String type); // 集团/区域下属数据占比 - List subordinate(Long deptId); + List subordinate(Long deptId); // 站点数据 PhotovoltaicStationVo station(Long deptId); + + // app区域数据 + PhotovoltaicStationAppVo app_subordinate(Long deptId); + + // app站点数据 + PhotovoltaicStationAppVo app_station(Long deptId); + + // App功率/发电量查询 + PhotovoltaicLoadGenerateVo app_load_generate(Long deptId, Long type); } 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 e36e12e..c3c70c6 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 @@ -685,7 +685,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { * @return */ @Override - public List subordinate(Long deptId) { + public List subordinate(Long deptId) { // 获取区域或者站点map结构 Map> map = sideHustleService.getAreaOrStaion(deptId,Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); if(MapUtils.isEmpty(map)){ @@ -696,9 +696,9 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 指标数据 List deviceTargets = (List) redisTemplate.opsForValue().get(load_photovoltaic_target_key); // 遍历数据 - List list = new ArrayList<>(); + List list = new ArrayList<>(); for (Map.Entry> entry : map.entrySet()) { - SubordinateVo subordinate = new SubordinateVo(); + PhotovoltaicSubordinateVo subordinate = new PhotovoltaicSubordinateVo(); if(ObjectUtil.isEmpty(entry.getValue())){ continue; } @@ -753,9 +753,9 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { return new ArrayList<>(); } // 总数据 : 发电量 、 容量 、 电站数 - Double sumGeneration = list.stream().mapToDouble(SubordinateVo::getGeneration).sum(); - Double sumLoad = list.stream().mapToDouble(SubordinateVo::getCapacity).sum(); - Double sumStationCount = list.stream().mapToDouble(SubordinateVo::getStationCount).sum(); + 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) { @@ -774,7 +774,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { subordinate.setStationUse(BigDecimal.valueOf(subordinate.getStationUseCount() / sumStationCount * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); } return subordinate; - }).sorted(Comparator.comparing(SubordinateVo::getCapacity)).collect(Collectors.toList()); + }).sorted(Comparator.comparing(PhotovoltaicSubordinateVo::getCapacity)).collect(Collectors.toList()); } /** @@ -831,6 +831,37 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } /** + * App区域下属数据 + * @param deptId + * @return + */ + @Override + public PhotovoltaicStationAppVo app_subordinate(Long deptId) { + return null; + } + + /** + * App光伏站点数据 + * @param deptId + * @return + */ + @Override + public PhotovoltaicStationAppVo app_station(Long deptId) { + return null; + } + + /** + * App功率/发电量查询 + * @param deptId + * @param type + * @return + */ + @Override + public PhotovoltaicLoadGenerateVo app_load_generate(Long deptId, Long type) { + return null; + } + + /** * 获取实时温度 * @param weather * @param code From d4d0001e4abe1e4b69f6566baa104c61bd74093c Mon Sep 17 00:00:00 2001 From: yang_shj Date: Tue, 4 Apr 2023 10:53:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?#App=E5=85=89=E4=BC=8F=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/constant/HomePageConstant.java | 4 +- .../operational/main/vo/GenerationPowerVo.java | 5 +- .../hzims/operational/main/vo/GenerationVo.java | 2 +- .../main/vo/PhotovoltaicDeviceStateVo.java | 21 + .../operational/main/vo/PhotovoltaicDeviceVo.java | 5 + .../main/vo/PhotovoltaicLoadGenerateVo.java | 66 +- .../operational/main/vo/PhotovoltaicLoadVo.java | 31 + .../main/vo/PhotovoltaicStationAppVo.java | 41 +- .../main/vo/PhotovoltaicSubordinateAppVo.java | 72 +-- .../main/controller/PhotovoltaicController.java | 5 +- .../main/service/IAnalyseDataService.java | 7 +- .../main/service/PhotovoltaicService.java | 4 +- .../main/service/impl/AnalyseDataServiceImpl.java | 46 ++ .../main/service/impl/PhotovoltaicServiceImpl.java | 680 +++++++++++++++++---- .../main/service/impl/SideHustleServiceImpl.java | 2 +- .../main/service/impl/WebHomeServiceImpl.java | 2 +- 16 files changed, 732 insertions(+), 261 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceStateVo.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicLoadVo.java 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; From 3d5e2d6ac63ab2658535da7cf898d9b01985c152 Mon Sep 17 00:00:00 2001 From: yang_shj Date: Sat, 8 Apr 2023 16:45:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?#=E5=85=89=E4=BC=8F=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/constant/HomePageConstant.java | 19 +- .../operational/main/vo/PhotovoltaicPowerVo.java | 2 +- .../main/vo/PhotovoltaicStationAppVo.java | 5 +- .../main/vo/PhotovoltaicSubordinateAppVo.java | 6 +- .../impl/HistoryAbnormalAlarmServiceImpl.java | 1 + .../main/scheduled/ScheduledCreateTask.java | 22 +- .../main/service/IAnalyseDataService.java | 1 + .../main/service/impl/AnalyseDataServiceImpl.java | 65 ++++- .../main/service/impl/HomePageServiceImpl.java | 71 +++-- .../main/service/impl/PhotovoltaicServiceImpl.java | 299 +++++++++++++-------- .../service/impl/RealMonitorServiceImpl.java | 41 +-- 11 files changed, 351 insertions(+), 181 deletions(-) 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 f4f2773..2a696c7 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 @@ -61,7 +61,8 @@ public interface HomePageConstant { 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.HYDROPOWER_VOLTAGE,HomePageConstant.HYDROPOWER_CURRENT,HomePageConstant.UNIT_SPEED,HomePageConstant.ACTIVE_POWER_GIVEN,HomePageConstant.REACTIVE_POWER_GIVEN, + HomePageConstant.PV_GENERATION_DAY); /** * 站点类型 : 运维服务 @@ -168,16 +169,24 @@ public interface HomePageConstant { 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"; - /**遥信1**/ - String PV_JOINT_RELAY = "joint_relay"; + /**电压**/ + String PV_VOLTAGE = "voltage"; + /**电流**/ + String PV_CURRENT = "current"; + /*==========================================================================================*/ // 光伏指标属性 - String PHOTOVOLTAIC_GENERATE = "generation_capacity"; // 发电量 - String PHOTOVOLTAIC_LOAD = "active_power"; // 功率 + String PHOTOVOLTAIC_OFF = "1.0"; // 开机 String PHOTOVOLTAIC_LOAD_TARGET = "0"; /*==========================================================================================*/ diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicPowerVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicPowerVo.java index 94e760d..f1cd386 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicPowerVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicPowerVo.java @@ -10,7 +10,7 @@ import lombok.Data; public class PhotovoltaicPowerVo { @ApiModelProperty(value = "小时") - private String hour; + private Integer hour; @ApiModelProperty(value = "有功功率") private String activePower; 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 baea493..83cb0eb 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 @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; import com.hnac.hzims.hzimsweather.response.weather.Daily; +import com.hnac.hzims.hzimsweather.response.weather.Now; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -50,8 +51,8 @@ public class PhotovoltaicStationAppVo { @JsonSerialize(nullsUsing = NullSerializer.class) private Double generate; - @ApiModelProperty(value = "站点实时温度") - private String temp; + @ApiModelProperty(value = "天气") + private Now now; @ApiModelProperty(value = "站点收益") private Double income; 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 5c3e427..4ff8edd 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 @@ -3,7 +3,7 @@ package com.hnac.hzims.operational.main.vo; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; -import com.hnac.hzims.hzimsweather.response.weather.Daily; +import com.hnac.hzims.hzimsweather.response.weather.Now; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -25,8 +25,8 @@ public class PhotovoltaicSubordinateAppVo { @ApiModelProperty(value = "机构名称") private String deptName; - @ApiModelProperty(value = "温度") - private String temp; + @ApiModelProperty(value = "天气") + private Now now; @ApiModelProperty(value = "地址") private String address; 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 0d2f513..0ad4b3e 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 @@ -270,6 +270,7 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl("SUCCESS"); } @@ -292,30 +292,30 @@ public class ScheduledCreateTask { } /** - * 光伏站-逆变器指标加载 + * 光伏站-逆变器实时加载 * @return ReturnT */ - @XxlJob(LOAD_PHOTOVOLTAIC_TARGET) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT loadPhotovoltaicTarget(String param) throws Exception { + @XxlJob(LOAD_PHOTOVOLTAIC_REAL) + //@Scheduled(cron = "0/50 * * * * ? ") + public ReturnT loadPhotovoltaicReal(String param) throws Exception { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } - photovoltaicService.loadPhotovoltaicTarget(param); + photovoltaicService.loadPhotovoltaicReal(param); return new ReturnT<>("SUCCESS"); } /** - * 光伏站-逆变器实时加载 + * 光伏站-逆变器指标加载 * @return ReturnT */ - @XxlJob(LOAD_PHOTOVOLTAIC_REAL) - //@Scheduled(cron = "0/50 * * * * ? ") - public ReturnT loadPhotovoltaicReal(String param) throws Exception { + @XxlJob(LOAD_PHOTOVOLTAIC_TARGET) + //@Scheduled(cron = "0/40 * * * * ? ") + public ReturnT loadPhotovoltaicTarget(String param) throws Exception { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } - photovoltaicService.loadPhotovoltaicReal(param); + photovoltaicService.loadPhotovoltaicTarget(param); return new ReturnT<>("SUCCESS"); } } 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 8dbc37b..421d09e 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 @@ -18,4 +18,5 @@ public interface IAnalyseDataService { List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages); + Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, Integer ride ,String signages); } 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 fe95831..c7acf95 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 @@ -2,6 +2,7 @@ package com.hnac.hzims.operational.main.service.impl; import com.google.common.collect.Lists; import com.hnac.hzims.EquipmentConstants; +import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; @@ -14,6 +15,8 @@ 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.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -21,6 +24,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Random; import java.util.function.Function; import java.util.stream.Collectors; @@ -45,12 +49,13 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { } /*** - * 指标数据查询 + * 指标数据列表查询 * @param startTime 开始时间 * @param endTime 结束时间 - * @param cycleType - * @param deviceCode - * @param signages + * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCode 设备编号 + * @param signages 指标 * @return */ @Override @@ -61,9 +66,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { 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); @@ -78,5 +81,55 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { return result.getData().get(0).getList(); } + /*** + * 指标数据列表查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param accessRules 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param cycleType 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param deviceCode 设备编号 + * @param ride 配电比 + * @param signages 指标 + * @return + */ + @Override + public Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Integer ride,String signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setSignages(signages); + analyzeDataConditionPO.setAccessRules(accessRules); + 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 0f; + } + List records = result.getData(); + if(CollectionUtil.isEmpty(records)){ + return 0f; + } + AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0); + if (ObjectUtil.isEmpty(analyzeDataConditionVO)) { + return 0f; + } + List analyseDataTaosVOList = analyzeDataConditionVO.getList(); + if (CollectionUtil.isEmpty(analyseDataTaosVOList)) { + return 0f; + } + AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0); + if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { + return 0f; + } + return Float.parseFloat(analyseDataTaosVO.getVal()) * 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 06ce852..e2fc91b 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 @@ -11,6 +11,7 @@ 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.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; @@ -69,7 +70,8 @@ import java.util.stream.Collectors; @Slf4j public class HomePageServiceImpl implements IHomePageService { - private final IAnalyseDataSearchClient analyseDataSearchClient; + + private final IAnalyseDataService analyseDataService; private final IPlanGenertionClient planGenertionClient; private final IMainSystemMonitoringService maintenanceTaskService; private final IMainTaskStatisticService mainTaskStatisticService; @@ -219,41 +221,70 @@ public class HomePageServiceImpl implements IHomePageService { * * @param param 时间 * @param serveType 站点类型 - * @param yearCount 近几年 + * @param year 近几年 */ @Override - public void loadPowerData(String param,List types, Integer serveType, int yearCount) { + public void loadPowerData(String param,List types, Integer serveType, int year) { // 站点查询 List stationList = stationService.getStationType(serveType, types, null); // 设备信息 - List equipmentInfoList = maintenanceTaskService.getEmInfoList(); + 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); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 结束日期 + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; // 存储数据map :<站点id,<月份,发电量>> Map> powerMap = new HashMap<>(); - // 获取需要遍历月份 - List monList = this.getMonthList(yearCount, 12,true); - Random random = new Random(); stationList.forEach(station -> { - Long departId = station.getRefDept(); - // 获取对应站点设备 - List effEmInfoList = equipmentInfoList.stream().filter(o -> departId.equals(o.getCreateDept())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(effEmInfoList)) { + // 站点设备集合 + List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(stationDevices)){ return; } - Map floatMap = new HashMap<>(); - for (int i = 0; i < monList.size() - 1; i++) { - if (this.compareDate(monList.get(i))) { - floatMap.put(monList.get(i), 0f); - continue; - } - float power = getPowerGeneration(effEmInfoList, monList.get(i) + " 00:00:00", monList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType()); - floatMap.put(monList.get(i), power); + Map generateMap = this.getGenerateYear(stationDevices,start,end); + if(MapUtils.isEmpty(generateMap)){ + return; } - powerMap.put(station.getId(), floatMap); + powerMap.put(station.getId(),generateMap); }); redisTemplate.opsForValue().set(RECENT_YEAR_POWER_DATA, powerMap); } /** + * 获取年发电量 + * @param devices + * @param start + * @param end + * @return + */ + private Map getGenerateYear(List devices, String start, String end) { + List datas = new ArrayList<>(); + devices.forEach(device->{ + List records = analyseDataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return; + } + datas.addAll(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.toList())); + }); + if(CollectionUtil.isEmpty(datas)){ + return null; + } + return datas.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth, Collectors.collectingAndThen( + Collectors.mapping(PowerMonthVo::getPower, Collectors.reducing(Float::sum)),Optional::get))); + } + + /** * @param stationList * @return */ 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 7c3a028..b12c294 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 @@ -22,6 +22,7 @@ import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; import lombok.RequiredArgsConstructor; +import net.sf.jsqlparser.expression.StringValue; import org.apache.commons.collections4.MapUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; @@ -87,8 +88,6 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { 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; @@ -109,28 +108,33 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } // 取redis实时数据 Map map = this.getRealData(); - List list = new ArrayList<>(); - Random random = new Random(); - devices.forEach(device -> { + 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(random.nextInt(2) - 1); + real.setState(this.getPhotovoltaicState(device,map)); // 容量 real.setCapacity(device.getInstalledCapacity()); // 发电量 - real.setGenerate(random.nextDouble() * 25000 * 300 * 2); + 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(random.nextDouble() * 300); + real.setVoltage(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_VOLTAGE))); // 电流 - real.setCurrent(random.nextDouble() * 300); - // 功率 - real.setLoad(random.nextDouble() * 300); + real.setCurrent(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_CURRENT))); // 上次功率 - real.setLastLoad(random.nextDouble() * 300); - list.add(real); - }); + real.setLastLoad(this.getLastLoad(device,history)); + return real; + }).collect(Collectors.toList()); + // 存储redis redisTemplate.opsForValue().set(load_photovoltaic_real_key, list); } @@ -147,7 +151,6 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { return; } List list = new ArrayList<>(); - Random random = new Random(); devices.forEach(device -> { PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); target.setDeptId(device.getCreateDept()); @@ -155,53 +158,189 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { target.setDeviceName(device.getName()); target.setDeptName(device.getName()); // 当日运行时长 - // target.setRunHours(this.runHours(device.getPoint().get(HomePageConstant.PV_JOINT_RELAY))); - // 当天有功功率 - // List activePowerVoList = waterService.getActivePowerVoList(device); - // FIXME 测试数据 - // 当天运行时长 - target.setRunHours(new Random().nextDouble() * 24); + //target.setRunHours(this.runHours(device.getPoint().get(HomePageConstant.PV_JOINT_RELAY))); // 年发电量 - target.setGenerationYear(random.nextDouble() * 25000 * 360); + target.setGenerationYear((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"0")); // 月发电量 - target.setGenerationMon(random.nextDouble() * 25000 * 30); + target.setGenerationMon((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"1")); // 日发电量 - target.setGenerationDay(random.nextDouble() * 25000); + 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.setGenerationYesterday(random.nextDouble() * 25000); // 节约标准煤 target.setTec(target.getGenerationMon() * 0.0001229); // 二氧化碳减排 target.setCo2(target.getGenerationMon() * 0.000997); // 减少森林砍伐 target.setDeforest(target.getGenerationMon() * 0.000553); - // FIXME 测试模拟数据30天功率 - List photovoltaicPowers = this.activePowerVoList(device); - target.setActivePowerVoList(photovoltaicPowers); + // 当天有功功率 + target.setActivePowerVoList(this.getLoadsByDay(device)); // 30天发电量 - List generationPowerVoList = this.getGenerationPowerList(device); - target.setGenerationPowerVoList(generationPowerVoList); + target.setGenerationPowerVoList(this.getGenerateByMon(device)); list.add(target); }); redisTemplate.opsForValue().set(load_photovoltaic_target_key, list); } - // FIXME 测试模拟 - private List activePowerVoList(EminfoAndEmParamVo device) { - List hours = getTestDay(); - Random random = new Random(); - return hours.stream().map(hour -> { - PhotovoltaicPowerVo power = new PhotovoltaicPowerVo(); - power.setHour(hour); - power.setActivePower(String.valueOf(random.nextDouble() * 500)); - return power; - }).collect(Collectors.toList()); + /** + * 当天有功功率 + * @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 @@ -297,7 +436,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { private long runTime(List result, Date startDate, Date endDate) { if (result.size() == 1) { // 一直开机 - if (HomePageConstant.OFF.equals(result.get(0).getValue())) { + if (HomePageConstant.PHOTOVOLTAIC_OFF.equals(result.get(0).getValue())) { return endDate.getTime() - startDate.getTime(); } // 一直关机 @@ -365,56 +504,10 @@ 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.PV_GENERATION_CAPACITY); } /** - * 近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.setGenerate(power); - generationPowerVo.setLoad((float) (random.nextDouble() * 500)); - generationPowerVoList.add(generationPowerVo); - } - return generationPowerVoList; - } - - /** - * 近7天发电量 - * - * @param device - * @return - */ - private List getGenerationPowerWeek(EminfoAndEmParamVo device) { - List generationPowerVoList = new ArrayList<>(); - // 近一周日期集合 - List dayList = this.getRecentWeek(); - 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))); - // 某天发电量 - 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; - } - - - /** * 当天功率 * * @return @@ -462,30 +555,6 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } /** - * 获取近30天集合 - * - * @return - */ - private List getRecent30Day() { - // 日期格式化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 < 30) { - calendar.add(Calendar.DATE, -1); - list.add(df.format(calendar.getTime())); - i++; - } - return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); - } - - /** * 获取实时数据 * * @return @@ -922,7 +991,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 获取实时天气 Map nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); if (MapUtils.isNotEmpty(nowWeather)) { - subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); + subordinate.setNow(nowWeather.get(station.getCode()).getNow()); } // 容量、实时功率、今日发电量 this.subordinateTargetData(subordinate, entry.getValue().stream().collect(Collectors.toList()), deviceReals, deviceTargets); @@ -1049,7 +1118,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { photovoltaic.setStationCode(station.getCode()); photovoltaic.setDeptId(station.getRefDept()); photovoltaic.setDeptName(station.getName()); - photovoltaic.setTemp(this.temp(weather, station.getCode())); + photovoltaic.setNow(weather.get(station.getCode()).getNow()); photovoltaic.setAddress(station.getAddress()); // 站点实时数据: 设备状态统计、实时功率、总发电量 、 日发电量 、 月发电量 、 co2减排 、 节约标准煤减排 、 减少森林砍伐 this.app_data(photovoltaic); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index 3be9342..5181197 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -16,11 +16,11 @@ import com.hnac.hzims.operational.config.service.StAlamRecordService; import com.hnac.hzims.operational.config.service.StFocusPropertiesService; import com.hnac.hzims.operational.config.vo.MessageParamVo; import com.hnac.hzims.operational.config.vo.StationRealVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; import com.hnac.hzims.operational.main.service.IWeatherService; import com.hnac.hzims.operational.main.vo.JointRelayVo; import com.hnac.hzims.operational.main.vo.WaterLevelVo; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationAttributeEntity; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IRealMonitorService; @@ -31,6 +31,7 @@ import com.hnac.hzims.operational.station.vo.RealAttributeVo; import com.hnac.hzims.operational.station.vo.RealDeviceVo; import com.hnac.hzims.operational.station.vo.RealStationVo; import com.hnac.hzims.operational.station.vo.WeatherVo; +import com.hnac.hzinfo.sdk.v5.redis.RedisClient; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; @@ -88,6 +89,8 @@ public class RealMonitorServiceImpl implements IRealMonitorService { @NotNull private final AbnormalAlarmService abnormalAlarmService; + private final RedisClient redisClient; + @NotNull private final ISysClient sysClient; @@ -131,8 +134,6 @@ public class RealMonitorServiceImpl implements IRealMonitorService { private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; - private final static String redis_real_prefix_key = "iot:real:data:"; - @Override public void realTimeData(String param) { @@ -146,10 +147,14 @@ public class RealMonitorServiceImpl implements IRealMonitorService { return ""; } String jointRelay = points.get(HomePageConstant.JOINT_RELAY); - if(StringUtil.isBlank(jointRelay)){ - return ""; + if(!StringUtil.isEmpty(jointRelay)){ + return jointRelay; + } + String onOff = points.get(HomePageConstant.SWITCH_ON_OFF); + if(!StringUtil.isEmpty(onOff)){ + return onOff; } - return jointRelay; + return ""; }).collect(Collectors.toList()); // 获取站点缓存数据 List stationRealVos = (List) redisTemplate.opsForValue().get(moniter_realId_key); @@ -169,11 +174,11 @@ public class RealMonitorServiceImpl implements IRealMonitorService { list.forEach(stations -> { stations.forEach(stationReal -> { String[] realIdArr = stationReal.getRealId(); - List realIds = Stream.of(realIdArr).map(o-> redis_real_prefix_key + stationReal.getStation() + ":" + o).collect(Collectors.toList()); + List realIds = Stream.of(realIdArr).collect(Collectors.toList()); if(CollectionUtil.isEmpty(realIds)){ return; } - List objects = redisTemplate.opsForValue().multiGet(realIds); + List objects = redisClient.getBatchRealDataByRealId(stationReal.getStation(),realIds); if(CollectionUtil.isEmpty(objects)){ return; } @@ -182,11 +187,12 @@ public class RealMonitorServiceImpl implements IRealMonitorService { log.error(realIds.get(i) + "is null"); continue; } - Map attribute = (Map) objects.get(i); - attribute.put("realId",realIdArr[i]); + Map attribute = (Map) JSONObject.parse(objects.get(i)); + attribute.put("realId",attribute.get("k")); attribute.put("value",attribute.get("v")); attribute.put("time",attribute.get("t")); attribute.remove("v"); + attribute.remove("k"); attribute.remove("t"); this.getCheckMap(attribute,switchOnOff); valueMap.put(realIdArr[i],attribute.get("value")); @@ -217,15 +223,15 @@ public class RealMonitorServiceImpl implements IRealMonitorService { * @param value * @return */ - private Map getCheckMap(Map value,List switchOnOff){ + private void getCheckMap(Map value,List switchOnOff){ try{ - String time = value.get("time"); - if(StringUtil.isEmpty(time)){ - return value; - } // 不处理开机状态监测点 if(switchOnOff.contains(value.get("realId"))){ - return value; + return; + } + String time = value.get("time"); + if(StringUtil.isEmpty(time)){ + return; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); Date date = simpleDateFormat.parse(time); @@ -234,9 +240,8 @@ public class RealMonitorServiceImpl implements IRealMonitorService { value.put("value","0"); } }catch (ParseException e){ - return value; + return; } - return value; } /**