From cef87107198e3d1983c7fd082d590f223449ac36 Mon Sep 17 00:00:00 2001 From: tyty Date: Tue, 14 Nov 2023 18:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=82=A8=E8=83=BD=E3=80=81?= =?UTF-8?q?=E9=A3=8E=E7=94=B5=E4=BB=A5=E5=8F=8A=E5=8F=91=E7=94=B5=E9=87=8F?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/operational/fill/vo/QueryVo.java | 2 - .../operational/main/constant/MainConstants.java | 4 + .../scheduled/mapper/operation/StorageMapper.java | 14 +++ .../scheduled/mapper/operation/WindMapper.java | 11 ++ .../scheduled/RealTargetScheduledTask.java | 34 +++-- .../scheduled/scheduled/ReportScheduledTask.java | 35 +++++- .../service/operation/fill/StorageService.java | 20 +++ .../service/operation/fill/WindService.java | 15 +++ .../operation/fill/impl/StorageServiceImpl.java | 51 ++++++++ .../operation/fill/impl/WindServiceImpl.java | 52 ++++++++ .../service/operation/home/RealTargetService.java | 1 + .../operation/home/impl/RealTargetServiceImpl.java | 76 ++++++++++-- .../service/operation/report/ReportService.java | 1 + .../operation/report/impl/ReportServiceImpl.java | 39 ++++++ .../resources/mapper/operation/StorageMapper.xml | 4 + .../main/resources/mapper/operation/WindMapper.xml | 5 + .../fill/controller/GenerateController.java | 11 ++ .../operational/fill/service/GenerateService.java | 6 +- .../fill/service/impl/GenerateServiceImpl.java | 22 ++++ .../main/controller/AreaMonthReportController.java | 35 +++++- .../main/service/IAreaMonthReportService.java | 5 + .../service/impl/AreaMonthReportServiceImpl.java | 137 ++++++++++++++++++++- 22 files changed, 550 insertions(+), 30 deletions(-) create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/StorageMapper.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/WindMapper.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/StorageService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/WindService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/StorageServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/WindServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/resources/mapper/operation/StorageMapper.xml create mode 100644 hzims-service/hzims-scheduled/src/main/resources/mapper/operation/WindMapper.xml diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/vo/QueryVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/vo/QueryVo.java index 3f7d66b..18d92ee 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/vo/QueryVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/vo/QueryVo.java @@ -3,8 +3,6 @@ package com.hnac.hzims.operational.fill.vo; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import java.util.Date; - /** * @author ysj * @date 2023/04/10 11:16:07 diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java index e8b21ab..dcc66fc 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java @@ -48,6 +48,8 @@ public interface MainConstants { // 近年发电量 String ELECTRICITY_GENERATION_RECENT_YEAR = "electricityGenerationRecentYear"; + // 風電儲能近年发电量 + String WIND_POWER_GENERATION_RECENT_YEAR = "windPowerGenerationRecentYear"; // 区域值班信息 String REGIONAL_DUTY_INFO = "regionalDutyInfo"; @@ -57,6 +59,8 @@ public interface MainConstants { // 区域月报 String AREA_MONTH_REPORT = "areaMonthReport"; + String WIND_AREA_MONTH_REPORT = "windAreaMonthReport"; + String ENERGY_AREA_MONTH_REPORT = "energyAreaMonthReport"; // 站点数据统计 String STATION_DATA_COUNT = "stationDataCount"; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/StorageMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/StorageMapper.java new file mode 100644 index 0000000..57b5d21 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/StorageMapper.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.scheduled.mapper.operation; + +import com.hnac.hzims.operational.fill.entity.StorageEntity; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + +/** + * @author ysj + * @date 2023/03/09 16:12:22 + * @version 4.0.0 + */ +public interface StorageMapper extends UserDataScopeBaseMapper { + + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/WindMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/WindMapper.java new file mode 100644 index 0000000..87a8aac --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/WindMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.scheduled.mapper.operation; + +import com.hnac.hzims.operational.fill.entity.WindEntity; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + +/** + * @author ysj + */ +public interface WindMapper extends UserDataScopeBaseMapper { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java index 878486f..75b7745 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java @@ -8,12 +8,12 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.Date; -import static com.hnac.hzims.fdp.constants.ScheduledConstant.LOAD_EM_INFO; import static com.hnac.hzims.operational.main.constant.MainConstants.*; @@ -33,9 +33,9 @@ public class RealTargetScheduledTask { * @return * @throws Exception */ - @XxlJob(LOAD_EM_INFO) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT loadEmInfo(String param) { +// @XxlJob(LOAD_EM_INFO) +// @Scheduled(cron = "0/40 * * * * ? ") + public ReturnT loadEmInfo() { service.loadEmInfo(); return new ReturnT<>("SUCCESS"); } @@ -128,12 +128,26 @@ public class RealTargetScheduledTask { /** * 获取站点近3年发电量数据 */ - @XxlJob(ELECTRICITY_GENERATION_RECENT_YEAR) - public ReturnT loadPowerData(String param) { - if (Func.isBlank(param)) { - param = DateUtil.format(new Date(), "yyyy-MM"); - } - service.loadPowerData(param, Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC),2,3); +// @XxlJob(ELECTRICITY_GENERATION_RECENT_YEAR) + @Scheduled(cron = "0/40 * * * * ? ") + public ReturnT loadPowerData() { +// if (Func.isBlank(param)) { +// param = DateUtil.format(new Date(), "yyyy-MM"); +// } + service.loadPowerData("", Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC),2,3); + return new ReturnT<>("SUCCESS"); + } + /** + * 获取風電和儲能站点近3年发电量数据 + */ + private final static String wind_recent_year_power_data = "hzims:operation:wind:power:data"; +// @XxlJob(WIND_POWER_GENERATION_RECENT_YEAR) + @Scheduled(cron = "0/40 * * * * ? ") + public ReturnT loadWindPowerData() { +// if (Func.isBlank(param)) { +// param = DateUtil.format(new Date(), "yyyy-MM"); +// } + service.loadPowerDataByWindEnergy("", Arrays.asList(HomePageConstant.WIND_POWER,HomePageConstant.ENERGY_STORAGE),2,3,wind_recent_year_power_data); return new ReturnT<>("SUCCESS"); } } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ReportScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ReportScheduledTask.java index 7010e3b..438bfc7 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ReportScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ReportScheduledTask.java @@ -1,5 +1,6 @@ package com.hnac.hzims.scheduled.scheduled; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.scheduled.service.operation.report.ReportService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; @@ -7,11 +8,13 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.Date; -import static com.hnac.hzims.operational.main.constant.MainConstants.AREA_MONTH_REPORT; +import static com.hnac.hzims.operational.main.constant.MainConstants.*; +import static com.hnac.hzims.scheduled.service.operation.report.impl.ReportServiceImpl.wind_recent_year_cache; /** @@ -25,6 +28,11 @@ public class ReportScheduledTask { @Autowired private ReportService service; + + @Value("${hzims.operation.wind.report}") + private String wind_report_month_cache_final; + @Value("${hzims.operation.energy.report}") + private String energy_report_month_cache_final; /** * 首页-生产月报表 * @return ReturnT @@ -37,5 +45,30 @@ public class ReportScheduledTask { service.loadMonthReport(param,1); return new ReturnT<>("SUCCESS"); } + /** + * 首页-生产月报表 + * @return ReturnT + */ + @XxlJob(WIND_AREA_MONTH_REPORT) + public ReturnT loadWindMonthReport(String param) { + if (Func.isBlank(param)) { + param = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); + } + service.loadMonthReportByType(param,1, HomePageConstant.WIND_POWER,wind_recent_year_cache,wind_report_month_cache_final); + return new ReturnT<>("SUCCESS"); + } + /** + * 首页-生产月报表 + * @return ReturnT + */ + @XxlJob(ENERGY_AREA_MONTH_REPORT) + public ReturnT loadEnergyMonthReport(String param) { + if (Func.isBlank(param)) { + param = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); + } + service.loadMonthReportByType(param,1,HomePageConstant.ENERGY_STORAGE,wind_recent_year_cache,energy_report_month_cache_final); + return new ReturnT<>("SUCCESS"); + } + } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/StorageService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/StorageService.java new file mode 100644 index 0000000..a9d9825 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/StorageService.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + +import com.hnac.hzims.operational.fill.entity.StorageEntity; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/09 16:12:22 + * @version 4.0.0 + */ + +/** + * 接入电站历史发电量填报 + */ +public interface StorageService extends BaseService { + List generateThreeYear(String start, String end, Long station); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/WindService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/WindService.java new file mode 100644 index 0000000..3885df8 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/WindService.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + +import com.hnac.hzims.operational.fill.entity.WindEntity; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author ysj + */ +public interface WindService extends BaseService { + List generateThreeYear(String start, String end, Long station); + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/StorageServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/StorageServiceImpl.java new file mode 100644 index 0000000..fb5ccf9 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/StorageServiceImpl.java @@ -0,0 +1,51 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.operational.fill.entity.StorageEntity; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.scheduled.mapper.operation.StorageMapper; +import com.hnac.hzims.scheduled.service.operation.fill.StorageService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + * @date 2023/03/09 16:12:22 + * @version 4.0.0 + */ +@Slf4j +@Service +@AllArgsConstructor +public class StorageServiceImpl extends BaseServiceImpl implements StorageService { + + @Override + public List generateThreeYear(String start, String end, Long station) { + List fills = this.list(Wrappers.lambdaQuery() + .between(StorageEntity::getFillDate,start,end) + .eq(StorageEntity::getCreateDept,station) + ); + if(CollectionUtil.isEmpty(fills)){ + return new ArrayList<>(); + + } + return fills.stream().map(fill->{ + PowerMonthVo mon = new PowerMonthVo(); + mon.setStrMonth(DateUtil.format(fill.getFillDate(),DateUtil.PATTERN_DATE)); + if(Math.abs(fill.getPower().intValue()) <= 0){ + mon.setPower(0f); + }else{ + mon.setPower(Float.parseFloat(fill.getPower().toString())); + } + return mon; + }).collect(Collectors.toList()); + } + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/WindServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/WindServiceImpl.java new file mode 100644 index 0000000..2a82ea5 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/WindServiceImpl.java @@ -0,0 +1,52 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.operational.fill.entity.WindEntity; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.scheduled.mapper.operation.WindMapper; +import com.hnac.hzims.scheduled.service.operation.fill.WindService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + * @date 2023/04/10 11:16:07 + * @version 4.0.0 + */ +@Slf4j +@Service +@AllArgsConstructor +public class WindServiceImpl extends BaseServiceImpl implements WindService { + + + @Override + public List generateThreeYear(String start, String end, Long station) { + List fills = this.list(Wrappers.lambdaQuery() + .between(WindEntity::getFillDate,start,end) + .eq(WindEntity::getCreateDept,station) + ); + if(CollectionUtil.isEmpty(fills)){ + return new ArrayList<>(); + + } + return fills.stream().map(fill->{ + PowerMonthVo mon = new PowerMonthVo(); + mon.setStrMonth(DateUtil.format(DateUtil.parse(fill.getFillDate(),DateUtil.PATTERN_DATE),DateUtil.PATTERN_DATE)); + if(Math.abs(fill.getPower()) <= 0){ + mon.setPower(0f); + }else{ + mon.setPower(Float.parseFloat(fill.getPower().toString())); + } + return mon; + }).collect(Collectors.toList()); + } + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java index a675773..8d6f2d7 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java @@ -34,4 +34,5 @@ public interface RealTargetService { // 光伏、水电站近3年发电量 void loadPowerData(String param, List types, Integer serveType, int year); + void loadPowerDataByWindEnergy(String param, List types, Integer serveType, int year,String key); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java index e9e9d73..d8ec750 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -14,18 +14,15 @@ import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.scheduled.service.equipment.DeviceParamService; import com.hnac.hzims.scheduled.service.equipment.DeviceService; +import com.hnac.hzims.scheduled.service.operation.fill.*; import com.hnac.hzims.scheduled.service.operation.home.ModelStationService; import com.hnac.hzims.scheduled.service.operation.home.RealTargetService; -import com.hnac.hzims.scheduled.service.operation.fill.GenerateService; -import com.hnac.hzims.scheduled.service.operation.fill.PowerService; -import com.hnac.hzims.scheduled.service.operation.fill.UseService; +import com.hnac.hzims.scheduled.service.operation.plate.DataService; import com.hnac.hzims.scheduled.service.operation.station.StationAttributeService; import com.hnac.hzims.scheduled.service.operation.station.StationService; -import com.hnac.hzims.scheduled.service.operation.plate.DataService; import com.hnac.hzinfo.datasearch.PointData; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; @@ -80,6 +77,8 @@ public class RealTargetServiceImpl implements RealTargetService { private final ModelStationService modelStationService; private final RedisTemplate redisTemplate; + private final WindService windService; + private final StorageService storageService; private final IHistoryDataSearchClient historyDataSearchClient; @@ -1111,7 +1110,50 @@ public class RealTargetServiceImpl implements RealTargetService { redisTemplate.opsForValue().set(recent_year_power_data, powerMap); } - + /** + * 近年发电量数据 + * + * @param param 时间 + * @param serveType 站点类型 + * @param year 近几年 + */ + @Override + public void loadPowerDataByWindEnergy(String param, List types, Integer serveType, int year,String key) { + // 站点查询 + List stationList = stationService.list(new LambdaQueryWrapper() {{ + if (ObjectUtil.isNotEmpty(serveType)) { + eq(StationEntity::getServeType, serveType); + } + if (CollectionUtil.isNotEmpty(types)) { + in(StationEntity::getType, types); + } + }}); + // 设备信息 +// List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() { +// }); + // 开始时间 + 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<>(); + stationList.forEach(station -> { + // 站点设备集合 +// List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); +// log.error("load_power_data station :" + station.getCode() + "==== device :" + stationDevices ); + Map generateMap = this.getGenerateYearByWindEnergy(station,start,end); + if(MapUtils.isEmpty(generateMap)){ + return; + } + powerMap.put(station.getId(),generateMap); + }); + redisTemplate.opsForValue().set(key, powerMap); + } /** * 当天有功功率 * @param device @@ -1165,7 +1207,21 @@ public class RealTargetServiceImpl implements RealTargetService { } return datas.stream().collect(Collectors.toMap(PowerMonthVo::getStrMonth, PowerMonthVo::getPower, Float::sum)); } - + /** + * 获取风电或者储能的年发电量 + * @param start + * @param end + * @return + */ + private Map getGenerateYearByWindEnergy(StationEntity station, String start, String end) { + List datas = new ArrayList<>(); + // 补充填报数据 + datas.addAll(this.generateFill(station,start,end)); + if(CollectionUtil.isEmpty(datas)){ + return null; + } + return datas.stream().collect(Collectors.toMap(PowerMonthVo::getStrMonth, PowerMonthVo::getPower, Float::sum)); + } /** * 获取填报用电量 @@ -1207,6 +1263,12 @@ public class RealTargetServiceImpl implements RealTargetService { if(HomePageConstant.PHOTOVOLTAIC.equals(station.getType())){ return powerService.generateThreeYear(start,end,station.getRefDept()); } + if(HomePageConstant.WIND_POWER.equals(station.getType())){ + return windService.generateThreeYear(start,end,station.getRefDept()); + } + if(HomePageConstant.ENERGY_STORAGE.equals(station.getType())){ + return storageService.generateThreeYear(start,end,station.getRefDept()); + } // 水电 return generateService.generateThreeYear(start,end,station.getCode()); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/ReportService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/ReportService.java index 2612f12..24b3bd0 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/ReportService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/ReportService.java @@ -6,4 +6,5 @@ package com.hnac.hzims.scheduled.service.operation.report; public interface ReportService { void loadMonthReport(String param, int i); + void loadMonthReportByType(String param, int year,Integer type,String key,String saveKey); } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java index 59e3839..c38748b 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java @@ -72,6 +72,7 @@ public class ReportServiceImpl implements ReportService { private final static String recent_year_cache_final = "hzims:operation:key:power:data"; + public final static String wind_recent_year_cache = "hzims:operation:wind:power:data"; @Value("${hzims.operation.area.report}") private String report_month_cache_final; @@ -115,6 +116,44 @@ public class ReportServiceImpl implements ReportService { } /** + * 区域-月报-风电/储能/水利 + * @param param + * @param year + */ + @Override + public void loadMonthReportByType(String param, int year,Integer type,String key,String saveKey) { + // 获取所有机构 + R> R = sysClient.getDeptList(); + if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { + return; + } + // 查询所有服务类型——"运维服务"、站点类型——"水电站" + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,type) + ); + if (CollectionUtil.isEmpty(stations)) { + return; + } + // 站点近年发电数据 + Map> powerMap = (Map>) redisTemplate.opsForValue().get(key); + // 存储数据节点 key - 月份 value - 区域数据集合 + Map> map = new HashMap<>(); + // 月份集合 + List monthList = getMonthList(year, Calendar.getInstance().get(Calendar.MONTH)); + monthList.forEach(mon -> { + List list = this.getAreaReportByMon(R.getData(), powerMap, stations, mon); + if (CollectionUtil.isEmpty(list)) { + return; + } + map.put(mon, list); + }); + // 推送当月报表邮件 + this.sendMonthReport(map, R.getData()); + redisTemplate.opsForValue().set(report_month_cache_final, map); + } + + /** * 获取近年月份集合 * * @param year diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/StorageMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/StorageMapper.xml new file mode 100644 index 0000000..d3a9441 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/StorageMapper.xml @@ -0,0 +1,4 @@ + + + + diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/WindMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/WindMapper.xml new file mode 100644 index 0000000..61392dc --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/WindMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/controller/GenerateController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/controller/GenerateController.java index 999e9bf..4a56847 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/controller/GenerateController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/controller/GenerateController.java @@ -20,6 +20,8 @@ import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springframework.web.bind.annotation.*; +import java.util.List; + /** * @author ysj @@ -43,6 +45,15 @@ public class GenerateController extends BladeController { public R saveOrUpdate(@RequestBody GenerateEntity entity) { return R.status(service.saveUpdate(entity)); } + /** + * 新增 + */ + @PostMapping("/saveOrUpdateList") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "新增", notes = "传入InsertPowerEntity对象") + public R saveOrUpdateList(@RequestBody List entity) { + return service.saveUpdateList(entity); + } /** * 删除 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java index 29bb8aa..dc7e967 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java @@ -2,19 +2,15 @@ package com.hnac.hzims.operational.fill.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.fill.entity.GenerateEntity; -import com.hnac.hzims.operational.fill.entity.RainfallEntity; import com.hnac.hzims.operational.fill.vo.GenerateVo; import com.hnac.hzims.operational.fill.vo.QueryVo; -import com.hnac.hzims.operational.fill.vo.RainfallVo; import com.hnac.hzims.operational.main.vo.GenerationPowerVo; import com.hnac.hzims.operational.main.vo.PowerMonthVo; -import com.hnac.hzims.operational.main.vo.UsrPowerVo; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import java.util.List; -import java.util.Map; /** * @author ysj @@ -28,7 +24,7 @@ public interface GenerateService extends BaseService { // 新增/修改发电量填报数据 boolean saveUpdate(GenerateEntity entity); - + R saveUpdateList(List entity); // 查询填报用电量 Float generate(String date,String station); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java index 0a53e2b..5c7e1d6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java @@ -24,6 +24,7 @@ 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 org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Calendar; @@ -86,7 +87,28 @@ public class GenerateServiceImpl extends BaseServiceImpl entityList) { + //发电量不为空的,保存或者编辑 + List addList = entityList.stream().filter(s -> ObjectUtil.isNotEmpty(s.getGenerate())).collect(Collectors.toList()); + boolean saveFlag = this.saveOrUpdateBatch(addList); + //发电量为空的,且有ID的为删除 + List ids = entityList.stream(). + filter(s -> ObjectUtil.isEmpty(s.getGenerate())) + .filter(s -> ObjectUtil.isNotEmpty(s.getId())) + .map(GenerateEntity::getId).collect(Collectors.toList()); + boolean deleteFlag =true; + if (CollectionUtil.isNotEmpty(ids)){ + deleteFlag= this.deleteLogic(ids); + } + if (saveFlag&&deleteFlag){ + return R.success("保存成功"); + }else { + return R.fail("保存失败"); + } + } /** * 根据时间、机构查询用电量 * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java index 7720bc9..707307f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java @@ -20,6 +20,7 @@ import org.springblade.core.log.annotation.ApiLog; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.system.feign.ISysClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -54,7 +55,14 @@ public class AreaMonthReportController extends BladeController { service.loadMonthReport(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"), 1); return R.success("success"); } - + @ApiLog + @ApiOperationSupport(order = 1) + @ApiOperation("生成区域月报") + @GetMapping("/loadMonthReportByType") + public R loadMonthReportByType(int type) { + service.loadMonthReportByType(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"), 1,type); + return R.success("success"); + } @ApiLog @ApiOperationSupport(order = 2) @ApiOperation("获取区域月报") @@ -66,7 +74,30 @@ public class AreaMonthReportController extends BladeController { public R> getAreaMonthReport(@ApiParam(value = "日期-年月", required = true) String date) { return service.getReport(date); } - + @ApiLog + @ApiOperationSupport(order = 2) + @ApiOperation("获取区域月报") + @GetMapping("/getAreaMonthReportByType") + @OperationAnnotation( + moduleName = "生产月报", + title = "水电生产运行月报", operatorType = OperatorType.MOBILE, businessType = BusinessType.GENCODE, + action = "获取区域月报") + public R> getAreaMonthReportByType(@ApiParam(value = "日期-年月", required = true) String date,Integer type) { + if (ObjectUtil.isEmpty(type)){ + type=0; + } + return service.getReportByType(date,type); + } + @ApiLog + @ApiOperationSupport(order = 3) + @ApiOperation("导出区域月报") + @GetMapping("/exportAreaMonthReportByType") + public R exportAreaMonthReportByType(HttpServletResponse response, @ApiParam(value = "日期-年月", required = true) String date,Integer type) { + if (ObjectUtil.isEmpty(type)){ + type=0; + } + return service.exportByType(response, date,type); + } @ApiLog @ApiOperationSupport(order = 3) @ApiOperation("导出区域月报") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAreaMonthReportService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAreaMonthReportService.java index 14a7882..dfb672c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAreaMonthReportService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAreaMonthReportService.java @@ -13,10 +13,15 @@ import java.util.List; public interface IAreaMonthReportService { void loadMonthReport(String param,int year); + void loadMonthReportByType(String param,int year,int type); R> getReport(String date); R export(HttpServletResponse response, String date); R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month,Long deptId,String name); + + R> getReportByType(String date, Integer type); + + R exportByType(HttpServletResponse response, String date, Integer type); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java index baa6714..143b7d8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java @@ -121,7 +121,10 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { @Value("${hzims.operation.area.report}") private String area_month_report_key; - + @Value("${hzims.operation.wind.report}") + private String wind_report_month_cache_final; + @Value("${hzims.operation.energy.report}") + private String energy_report_month_cache_final; private final static String RECENT_YEAR_POWER_DATA = "hzims:operation:key:power:data"; private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; @@ -153,7 +156,61 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { //根据用户权限获取机构 return R.data(areaMonthReportVoList.stream().sorted(Comparator.comparing(AreaMonthReportVo::getActualPower, Comparator.reverseOrder())).collect(Collectors.toList())); } + @Override + public R> getReportByType(String date, Integer type){ + List areaMonthReportVoList = this.getAreaMonthReportByType(date, false,type); + if (CollectionUtil.isEmpty(areaMonthReportVoList)) { + return R.fail("选择月份无统计报表数据"); + } + //根据用户权限获取机构 + return R.data(areaMonthReportVoList.stream().sorted(Comparator.comparing(AreaMonthReportVo::getActualPower, Comparator.reverseOrder())).collect(Collectors.toList())); + } + /** + * 导出区域月报 + * + * @param response + * @param date + */ + @Override + public R exportByType(HttpServletResponse response, String date, Integer type) { + List monthReportVoList = this.getAreaMonthReportByType(date, true,type); + // 创建Excel文件 + HSSFWorkbook hssWB = new HSSFWorkbook(); + // 添加sheet页 + HSSFSheet sheet = hssWB.createSheet("运行月报(" + date + ")"); + // 行高 + sheet.setDefaultRowHeight((short) (20 * 25)); + // 列宽 + sheet.setDefaultColumnWidth(20); + this.setFirstHeader(hssWB, sheet); + // 第二行/三行 表头格式设置 + this.setWorkHeader(hssWB, sheet); + if (!CollectionUtil.isEmpty(monthReportVoList)) { + // 数据填充 + this.setWorkData(hssWB, sheet, monthReportVoList); + } + // 下载导出 + String filename = "(" + date + ")水电站生产运行月报"; + // 设置头信息 + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/vnd.ms-excel"); + ServletOutputStream outputStream; + try { + //设置xlsx格式 + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xlsx", "UTF-8")); + //创建一个输出流 + outputStream = response.getOutputStream(); + //写入数据 + hssWB.write(outputStream); + // 关闭 + outputStream.close(); + hssWB.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return R.data("success"); + } /** * 导出区域月报 * @@ -1103,6 +1160,37 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { /** + * 获取区域月报数据 + * + * @return + */ + private List getAreaMonthReportByType(String date, boolean isSendFlag,Integer type) { + R> D = sysClient.getDeptByCurrentUser(); + if (!D.isSuccess() || CollectionUtil.isEmpty(D.getData())) { + return null; + } + List authList = D.getData().stream().filter(o -> o.getDeptCategory().equals(3)).map(Dept::getId).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(authList)) { + return null; + } + String key = area_month_report_key; + if (type.equals(HomePageConstant.WIND_POWER)){ + key= wind_report_month_cache_final; + } + if (type.equals(HomePageConstant.ENERGY_STORAGE)){ + key= energy_report_month_cache_final; + } + Map> map = (Map>) redisTemplate.opsForValue().get(key); + if (MapUtils.isEmpty(map)) { + return null; + } + if (isSendFlag) { + // 发送邮件 + this.sendMonthReport(map, D.getData()); + } + return map.get(date); + } + /** * 区域-加载月报数据 * * @param param @@ -1133,10 +1221,53 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { map.put(mon, list); }); // 推送当月报表邮件 - this.sendMonthReport(map, R.getData()); +// this.sendMonthReport(map, R.getData()); redisTemplate.opsForValue().set(area_month_report_key, map); } - + /** + * 区域-加载月报数据 + * + * @param param + */ + @Override + public void loadMonthReportByType(String param, int year,int type) { + // 获取所有机构 + R> R = sysClient.getDeptList(); + if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { + return; + } + if (ObjectUtil.isEmpty(type)){ + type=HomePageConstant.HYDROPOWER; + } + String saveKey=area_month_report_key; + if (type==HomePageConstant.WIND_POWER){ + saveKey=wind_report_month_cache_final; + } + if (type==HomePageConstant.ENERGY_STORAGE){ + saveKey=energy_report_month_cache_final; + } + // 查询所有服务类型——"运维服务"、站点类型——"水电站" + List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(type), null,true); + if (CollectionUtil.isEmpty(stationList)) { + return; + } + // 站点近年发电数据 + Map> powerMap = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); + // 存储数据节点 key - 月份 value - 区域数据集合 + Map> map = new HashMap<>(); + // 月份集合 + List monthList = getMonthList(year, Calendar.getInstance().get(Calendar.MONTH)); + monthList.forEach(mon -> { + List list = this.getAreaReportByMon(R.getData(), powerMap, stationList, mon); + if (CollectionUtil.isEmpty(list)) { + return; + } + map.put(mon, list); + }); + // 推送当月报表邮件 +// this.sendMonthReport(map, R.getData()); + redisTemplate.opsForValue().set(saveKey, map); + } /** * 获取近年月份集合 *