From 7069843ced21a3644fae850a1dd56a1240464356 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Fri, 23 Aug 2024 11:47:12 +0800 Subject: [PATCH] =?UTF-8?q?#=E7=BB=BC=E5=90=88=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/electric/vo/ComprehensiveElectricVo.java | 65 ++++++++++++ .../hnac/hzims/electric/vo/DeviceElectricVo.java | 2 +- .../com/hnac/hzims/electric/vo/TableHeadVo.java | 2 +- .../controller/ElectricReportController.java | 10 ++ .../electric/service/IElectricReportService.java | 5 + .../service/impl/ElectricReportServiceImpl.java | 114 ++++++++++++++++----- 6 files changed, 168 insertions(+), 30 deletions(-) create mode 100644 hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java new file mode 100644 index 0000000..6d4da72 --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java @@ -0,0 +1,65 @@ +package com.hnac.hzims.electric.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + + +/** + * @author ysj + */ +@Data +public class ComprehensiveElectricVo { + + @ApiModelProperty(value = "月份") + private String month; + + @ApiModelProperty(value = "本月电量") + private Double monthGenerate; + + @ApiModelProperty(value = "去年同月") + private Double lastMonthGenerate; + + @ApiModelProperty(value = "月同比") + private Double lastMonthGenerateRate; + + @ApiModelProperty(value = "年发电量") + private Double yearGenerate; + + @ApiModelProperty(value = "去年同期") + private Double lastYearGenerate; + + @ApiModelProperty(value = "年同比") + private Double lastYearGenerateRate; + + + @ApiModelProperty(value = "本月降雨") + private Double monthRain; + + @ApiModelProperty(value = "去年同月") + private Double lastMonthRain; + + @ApiModelProperty(value = "月同比") + private Double lastMonthRainRate; + + @ApiModelProperty(value = "年降雨量") + private Double yearRain; + + @ApiModelProperty(value = "去年同期") + private Double lastYearRain; + + @ApiModelProperty(value = "年同比") + private Double lastYearRainRate; + + + @ApiModelProperty(value = "本月等效小时") + private Double monthEquivalent; + + @ApiModelProperty(value = "去年同月") + private Double lastMonthEquivalent; + + @ApiModelProperty(value = "年等效小时") + private Double yearEquivalent; + + @ApiModelProperty(value = "去年同期") + private Double lastYearEquivalent; +} \ No newline at end of file diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/DeviceElectricVo.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/DeviceElectricVo.java index 9c1f934..a709db1 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/DeviceElectricVo.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/DeviceElectricVo.java @@ -5,7 +5,7 @@ import lombok.Data; /** - * @author 表头 + * @author ysj */ @Data public class DeviceElectricVo { diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/TableHeadVo.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/TableHeadVo.java index 2cfcb83..cddb9fa 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/TableHeadVo.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/TableHeadVo.java @@ -7,7 +7,7 @@ import java.util.List; /** - * @author 表头 + * @author ysj */ @Data public class TableHeadVo { diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/controller/ElectricReportController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/controller/ElectricReportController.java index 361658b..8dde5c1 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/controller/ElectricReportController.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/controller/ElectricReportController.java @@ -2,6 +2,7 @@ package com.hnac.hzims.electric.controller; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.electric.service.IElectricReportService; +import com.hnac.hzims.electric.vo.ComprehensiveElectricVo; import com.hnac.hzims.equipment.entity.EmAssociationEntity; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.List; import java.util.Map; /** @@ -35,4 +37,12 @@ public class ElectricReportController extends BladeController { @RequestParam(value = "time") String time) { return R.data(service.basics(deptId,type,time)); } + + @GetMapping("/comprehensive") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "综合报表", notes = "传入 deptId") + public R> comprehensive(@RequestParam(value = "deptId") Long deptId, + @RequestParam(value = "year") String year) { + return R.data(service.comprehensive(deptId,year)); + } } \ No newline at end of file diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/IElectricReportService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/IElectricReportService.java index a579675..24bc9a2 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/IElectricReportService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/IElectricReportService.java @@ -1,5 +1,8 @@ package com.hnac.hzims.electric.service; +import com.hnac.hzims.electric.vo.ComprehensiveElectricVo; + +import java.util.List; import java.util.Map; /** @@ -9,4 +12,6 @@ public interface IElectricReportService { Map basics(Long deptId, Long type,String time); + + List comprehensive(Long deptId,String year); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java index 2c7e061..59276ea 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java @@ -1,6 +1,9 @@ package com.hnac.hzims.electric.service.impl; +import cn.hutool.core.io.unit.DataUnit; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.electric.entity.ThirtyEntity; @@ -8,17 +11,15 @@ import com.hnac.hzims.electric.entity.ThreeEntity; import com.hnac.hzims.electric.service.IElectricReportService; import com.hnac.hzims.electric.service.ThirtyService; import com.hnac.hzims.electric.service.ThreeService; +import com.hnac.hzims.electric.vo.ComprehensiveElectricVo; import com.hnac.hzims.electric.vo.DeviceElectricVo; import com.hnac.hzims.electric.vo.TableHeadVo; -import com.hnac.hzims.equipment.entity.EmInfoEntity; -import com.hnac.hzims.equipment.service.IEmInfoService; +import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.feign.IStationClient; -import com.hnac.hzims.operational.station.vo.StationsByDeptIdsParamVo; 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.AnalyzeDataConditionVO; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -26,9 +27,9 @@ 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.springblade.system.entity.Dept; import org.springblade.system.feign.ISysClient; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -48,14 +49,16 @@ public class ElectricReportServiceImpl implements IElectricReportService { private final ThirtyService thirtyService; - private final IEmInfoService deviceService; - private final ISysClient sysClient; private final IStationClient stationClient; private final IAnalyseDataSearchClient analyseDataSearchClient; + private final RedisTemplate redisTemplate; + + public final static String DEVICE_CACHE_COFIG_FINAL = "hzims:equipment:emInfo:deviceCode.emInfoList"; + /** * 基础报表 * @param deptId @@ -92,6 +95,57 @@ public class ElectricReportServiceImpl implements IElectricReportService { } /** + * 综合报表 + * @param deptId + * @return + */ + @Override + public List comprehensive(Long deptId,String year) { + // 查询站点 + StationEntity param = new StationEntity(); + param.setRefDept(deptId); + R station = stationClient.getStationByCodeOrRedDept(param); + if(!station.isSuccess() || ObjectUtil.isEmpty(station.getData())){ + return new ArrayList<>(); + } + // 查询设备 + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(DEVICE_CACHE_COFIG_FINAL).toString(), new TypeReference>() {}); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); + } + // 设备装机容量 + double installedCapacity = devices.stream().filter(device->device.getCreateDept().equals(deptId)).mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum(); + // 查询两年发电量 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(year,"yyyy")); + calendar.add(Calendar.YEAR,1); + Date end = calendar.getTime(); + calendar.add(Calendar.YEAR,-2); + Date start = calendar.getTime(); + List threes = threeService.list(Wrappers.lambdaQuery() + .eq(ThreeEntity::getStationId,station.getData().getCode()) + .ge(ThreeEntity::getStrMonth, DateUtil.format(start,DateUtil.PATTERN_DATE)) + .le(ThreeEntity::getStrMonth, DateUtil.format(end,DateUtil.PATTERN_DATE)) + ); + + + calendar.setTime(DateUtil.parse(year,"yyyy")); + calendar.add(Calendar.YEAR,1); + Date finish = calendar.getTime(); + calendar.add(Calendar.YEAR,-1); + Date current = calendar.getTime(); + while (current.compareTo(finish) < 0){ + + + calendar.add(Calendar.MONTH,1); + current = calendar.getTime(); + } + + return null; + } + + + /** * 确认机构级别 * @param deptId * @return @@ -450,17 +504,17 @@ public class ElectricReportServiceImpl implements IElectricReportService { // 日 if (type == 0) { // 站点设备集合 - List devices = deviceService.list(Wrappers.lambdaQuery() - .eq(EmInfoEntity::getCreateDept,station.getData().getRefDept()) - .eq(EmInfoEntity::getEmType,2) - .eq(EmInfoEntity::getHomePageDisplay,1) - ); + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(DEVICE_CACHE_COFIG_FINAL).toString(), new TypeReference>() {}); if(CollectionUtil.isEmpty(devices)){ return new HashMap<>(); } + List stationDevices = devices.stream().filter(device->device.getCreateDept().equals(station.getData().getRefDept())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(stationDevices)){ + return new HashMap<>(); + } Date date = DateUtil.parse(time,DateUtil.PATTERN_DATE); // 根据设备查询当日有功/无功电量 - List electrics = this.deviceElectrics(devices,date); + List electrics = this.deviceElectrics(stationDevices,date); // 表头 List tableHeads = new ArrayList<>(); @@ -475,7 +529,7 @@ public class ElectricReportServiceImpl implements IElectricReportService { tableHeads.add(secondHead); // 根据设备分组 - devices.forEach(device->{ + stationDevices.forEach(device->{ TableHeadVo tableHead = new TableHeadVo(); tableHead.setTableName(device.getName() + "发电量(kWh)"); tableHead.setIsChildren(true); @@ -486,24 +540,25 @@ public class ElectricReportServiceImpl implements IElectricReportService { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); + calendar.add(Calendar.DAY_OF_MONTH,1); Date end = calendar.getTime(); - calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.DAY_OF_MONTH,-1); Date start = calendar.getTime(); List> tableDate = new ArrayList<>(); while (start.compareTo(end) < 0){ List item = new ArrayList<>(); String hours = DateUtil.format(start,"yyyy-MM-dd HH"); - item.add(start.getMonth() + 1 + "月"); + item.add(start.getHours() + "时"); // 总计:有功、无功 item.add(electrics.stream().filter(electric -> electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum()); item.add(electrics.stream().filter(electric -> electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum()); // 遍历机组 - devices.stream().sorted(Comparator.comparing(EmInfoEntity::getEmIndex)).forEach(device->{ - item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getNumber()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum()); - item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getNumber()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum()); + stationDevices.stream().sorted(Comparator.comparing(EminfoAndEmParamVo::getOrd)).forEach(device->{ + item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getEmCode()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum()); + item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getEmCode()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum()); }); - calendar.add(Calendar.DAY_OF_MONTH,1); + calendar.add(Calendar.HOUR_OF_DAY,1); start = calendar.getTime(); tableDate.add(item); } @@ -641,18 +696,19 @@ public class ElectricReportServiceImpl implements IElectricReportService { * @param devices * @return */ - private List deviceElectrics(List devices,Date date) { + private List deviceElectrics(List devices,Date date) { List electrics = new ArrayList<>(); devices.forEach(device->{ Calendar calendar = Calendar.getInstance(); calendar.setTime(date); + calendar.add(Calendar.DAY_OF_MONTH,1); Date endTime = calendar.getTime(); LocalDateTime end = LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(endTime,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)); - calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.DAY_OF_MONTH,-1); Date startTime = calendar.getTime(); LocalDateTime start = LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(startTime,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)); AnalyseCodeByAnalyseDataPO param = new AnalyseCodeByAnalyseDataPO(); - param.setDeviceCode(device.getNumber()); + param.setDeviceCode(device.getEmCode()); List conditions = new ArrayList<>(); // 有功电量 AnalyzeDataConditionPO generate = new AnalyzeDataConditionPO(); @@ -674,7 +730,8 @@ public class ElectricReportServiceImpl implements IElectricReportService { reactive.setSignages("reactive_generation"); reactive.setTimeInterval(1); reactive.setBeginTime(start); - reactive.setEndTime(end);conditions.add(reactive); + reactive.setEndTime(end); + conditions.add(reactive); param.setSignboardConditions(conditions); R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(param); if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData())){ @@ -682,24 +739,25 @@ public class ElectricReportServiceImpl implements IElectricReportService { } while (startTime.compareTo(endTime) < 0){ DeviceElectricVo electric = new DeviceElectricVo(); + electric.setDeviceCode(device.getEmCode()); electric.setStrTime(DateUtil.format(startTime,"yyyy-MM-dd HH")); electric.setTime(startTime.getHours()); - if(ObjectUtil.isEmpty(result.getData().get(0)) || CollectionUtil.isEmpty(result.getData().get(0).getList())){ + if(CollectionUtil.isNotEmpty(result.getData()) && ObjectUtil.isNotEmpty(result.getData().get(0)) && CollectionUtil.isNotEmpty(result.getData().get(0).getList())){ electric.setGenerate(result.getData().get(0).getList().stream().filter(o->o.getTs().contains(electric.getStrTime())).mapToDouble(val->{ if(StringUtils.isEmpty(val.getVal())){ return 0.0; } - return Double.parseDouble(val.getVal()); + return Double.parseDouble(val.getVal()) * device.getRideCount(); }).sum()); }else{ electric.setGenerate(0.0); } - if(ObjectUtil.isEmpty(result.getData().get(1)) || CollectionUtil.isEmpty(result.getData().get(1).getList())){ + if(CollectionUtil.isNotEmpty(result.getData()) && result.getData().size() > 1 && ObjectUtil.isNotEmpty(result.getData().get(1)) && CollectionUtil.isNotEmpty(result.getData().get(1).getList())){ electric.setReactiveGenerate(result.getData().get(1).getList().stream().filter(o->o.getTs().contains(electric.getStrTime())).mapToDouble(val->{ if(StringUtils.isEmpty(val.getVal())){ return 0.0; } - return Double.parseDouble(val.getVal()); + return Double.parseDouble(val.getVal()) * device.getRideCount(); }).sum()); }else{ electric.setReactiveGenerate(0.0);