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 38638c5..d0db6d4 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 @@ -123,11 +123,11 @@ public class AreaMonthReportController extends BladeController { @ApiOperation("导出水电站月报") @GetMapping("/exportHydropowerStationMonthReport") public R exportHydropowerStationMonthReport(HttpServletResponse response, @ApiParam(value = "日期-年", required = true) Integer year,@ApiParam(value = "日期-月", required = true) Integer month, - @ApiParam(value = "日期-日", required = true) Integer date,@ApiParam(value = "站点Id", required = true) Long stationId,@ApiParam(value = "月报类型", required = true) Long type) { + @ApiParam(value = "站点Id", required = true) Long deptId,@ApiParam(value = "月报类型", required = true) Long type) { HashMap map = new HashMap<>(); if (type==1){ - service.exportHydropowerStationMonthReport(response, map,year,month,date,stationId); + service.exportHydropowerStationMonthReport(response, map,year,month,deptId); //word模板相对路径、word生成路径、word生成的文件名称、数据源 } XWPFDocument xwpfDocument = WordUtils.exportWordV2("template/waterMonReport.docx", map); 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 3cf0c3a..e8007a3 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 @@ -18,5 +18,5 @@ public interface IAreaMonthReportService { R export(HttpServletResponse response, String date); - R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month, Integer date,Long stationId); + R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month,Long deptId); } 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 77f6308..67ec81b 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 @@ -202,7 +202,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { return R.data("success"); } @Override - public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month, Integer date, Long deptId) { + public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month, Long deptId) { R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); if (!deptByCurrentUser.isSuccess()||deptByCurrentUser.getData()!=null){ return R.fail("用户权限查询失败"); @@ -239,7 +239,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { map.put("month", month); Integer monthBefore = month - 1; map.put("monthBefore", monthBefore); - map.put("date", date); +// map.put("date", date); map.put("commissionTime", commissionTime.toString()); map.put("stationName", deptName); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); @@ -274,6 +274,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { .mapToDouble(HydropowerUnitRealVo::getInstalledCapacity).sum(); BigDecimal sumData=new BigDecimal(sum).divide(new BigDecimal(1000),2,BigDecimal.ROUND_UP); map.put("installedCapacity", sumData); + //各站点分组 Map> listMap = Optional.ofNullable(realsByDept) .orElse(new ArrayList<>()).stream() @@ -295,75 +296,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { ImageEntity capacityProportionChart = JFreeUtil.pieChartByDouble("水电项目装机容量占比图", capacityProportionMap, 500, 400); map.put("capacityProportionChart", capacityProportionChart); //各发电站发电量环比图+表格数据组装 - List deptIdsString = deptIds.stream().map(s -> String.valueOf(s)).collect(Collectors.toList()); - List planYearData = planGenertionClient.getPlanGenerationByParam(null, deptIdsString, year.toString()); - List powerPercentageVoList = new ArrayList<>(); - //水电站,光伏站和带代运维数据近三年数据 - Map> powerMapThree = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); - List listByYear = TimeUtils.getListByYear(year); - List listByYearBefore = TimeUtils.getListByYear(yearBefore); - String monStart = TimeUtils.getMon(year, month); - String monStartYearBefore = TimeUtils.getMon(yearBefore, month); - String monStartMonBefore = TimeUtils.getMon(year, monthBefore); - for (Map.Entry> deviceMap : powerMapThree.entrySet()) { - String deptNameByKey = ""; - if (stationIds.contains(deviceMap.getKey())) { - MonPowerPercentageVo powerVo = new MonPowerPercentageVo(); - powerVo.setDeptId(deviceMap.getKey()); - List collect = stationEntityList.stream().filter(s -> deviceMap.getKey().equals(s.getId())).collect(Collectors.toList()); - if (collect!=null) { - Long dept = collect.get(0).getRefDept(); - List dep = deptList.stream().filter(s -> dept.equals(s.getId())).collect(Collectors.toList()); - deptNameByKey=dep.get(0).getDeptName(); - } - powerVo.setDeptName(deptNameByKey); - BigDecimal powerYear = new BigDecimal(0); - BigDecimal powerYearBefore = new BigDecimal(0); - BigDecimal powerMonth = new BigDecimal(0); - BigDecimal powerMonthBefore = new BigDecimal(0); - BigDecimal powerMonthYearBefore = new BigDecimal(0); - Double planGeneration = 0d; - List planGenerationById = planYearData.stream().filter(s -> collect.get(0).getRefDept().equals(s.getStationDeptId())).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(planGenerationById)) { - planGeneration = Double.valueOf(planGenerationById.get(0).getPlanGeneration()); - } - //当前机构近三年的数据 - Map value = deviceMap.getValue(); - //今年发电量 - powerYear=value.entrySet().stream().filter(s->listByYear.contains(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); - //转换单位kwh-》万Kwh - powerYear=powerYear.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); - powerYearBefore=value.entrySet().stream().filter(s->listByYearBefore.contains(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); - powerYearBefore=powerYearBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); - powerMonth=value.entrySet().stream().filter(s->monStart.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); - powerMonth=powerMonth.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); - powerMonthBefore=value.entrySet().stream().filter(s->monStartMonBefore.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); - powerMonthBefore=powerMonthBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); - powerMonthYearBefore=value.entrySet().stream().filter(s->monStartYearBefore.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); - powerMonthYearBefore=powerMonthYearBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); - powerVo.setPowerYear(powerYear.doubleValue()); - powerVo.setPowerYearBefore(powerYearBefore.doubleValue()); - BigDecimal yearPercentage = new BigDecimal(0); - BigDecimal planPercentage = new BigDecimal(0); - if (powerYearBefore.compareTo(BigDecimal.ZERO) != 0) { - yearPercentage = (powerYear.subtract(powerYearBefore)).divide(powerYearBefore, 2, BigDecimal.ROUND_UP); - } - if (BigDecimal.valueOf(planGeneration).compareTo(BigDecimal.ZERO) != 0) { - planPercentage = powerYear.divide(BigDecimal.valueOf(planGeneration), 2, BigDecimal.ROUND_UP); - } - powerVo.setPlanPercentage(planPercentage.doubleValue()); - powerVo.setPowerYearPercentage(yearPercentage.doubleValue()); - powerVo.setPowerMon(powerMonth.doubleValue()); - powerVo.setPowerMonBefore(powerMonthBefore.doubleValue()); - powerVo.setPowerMonYearBefore(powerMonthYearBefore.doubleValue()); - BigDecimal monPercentage = new BigDecimal(0); - if (powerMonthYearBefore.compareTo(BigDecimal.ZERO) != 0) { - monPercentage = (powerMonth.subtract(powerMonthYearBefore)).divide(powerMonthYearBefore, 2, BigDecimal.ROUND_UP); - } - powerVo.setPowerMonPercentage(monPercentage.doubleValue()); - powerPercentageVoList.add(powerVo); - } - } + List powerPercentageVoList = getMonPowerPercentageVos(year, month, deptList, deptIds, stationEntityList, stationIds, yearBefore, monthBefore); // getPowerData(deptList, yearStart, yearEnd, yearBeforeStart, yearBeforeEnd, monthStart, monthEnd, beforeMonthStart, beforeMonthEnd, monthStartBeforeYear, monthEndBeforeYear, devices, planYearData, powerPercentageVoList); // 各发电站发电量环比图数据组装 //柱状图图数据 @@ -688,6 +621,79 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { return R.success("成功"); } + private List getMonPowerPercentageVos(Integer year, Integer month, List deptList, List deptIds, List stationEntityList, List stationIds, Integer yearBefore, Integer monthBefore) { + List deptIdsString = deptIds.stream().map(s -> String.valueOf(s)).collect(Collectors.toList()); + List planYearData = planGenertionClient.getPlanGenerationByParam(null, deptIdsString, year.toString()); + List powerPercentageVoList = new ArrayList<>(); + //水电站,光伏站和带代运维数据近三年数据 + Map> powerMapThree = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); + List listByYear = TimeUtils.getListByYear(year); + List listByYearBefore = TimeUtils.getListByYear(yearBefore); + String monStart = TimeUtils.getMon(year, month); + String monStartYearBefore = TimeUtils.getMon(yearBefore, month); + String monStartMonBefore = TimeUtils.getMon(year, monthBefore); + for (Map.Entry> deviceMap : powerMapThree.entrySet()) { + String deptNameByKey = ""; + if (stationIds.contains(deviceMap.getKey())) { + MonPowerPercentageVo powerVo = new MonPowerPercentageVo(); + powerVo.setDeptId(deviceMap.getKey()); + List collect = stationEntityList.stream().filter(s -> deviceMap.getKey().equals(s.getId())).collect(Collectors.toList()); + if (collect!=null) { + Long dept = collect.get(0).getRefDept(); + List dep = deptList.stream().filter(s -> dept.equals(s.getId())).collect(Collectors.toList()); + deptNameByKey=dep.get(0).getDeptName(); + } + powerVo.setDeptName(deptNameByKey); + BigDecimal powerYear = new BigDecimal(0); + BigDecimal powerYearBefore = new BigDecimal(0); + BigDecimal powerMonth = new BigDecimal(0); + BigDecimal powerMonthBefore = new BigDecimal(0); + BigDecimal powerMonthYearBefore = new BigDecimal(0); + Double planGeneration = 0d; + List planGenerationById = planYearData.stream().filter(s -> collect.get(0).getRefDept().equals(s.getStationDeptId())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(planGenerationById)) { + planGeneration = Double.valueOf(planGenerationById.get(0).getPlanGeneration()); + } + //当前机构近三年的数据 + Map value = deviceMap.getValue(); + //今年发电量 + powerYear=value.entrySet().stream().filter(s->listByYear.contains(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + //转换单位kwh-》万Kwh + powerYear=powerYear.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerYearBefore=value.entrySet().stream().filter(s->listByYearBefore.contains(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + powerYearBefore=powerYearBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerMonth=value.entrySet().stream().filter(s->monStart.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonth=powerMonth.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerMonthBefore=value.entrySet().stream().filter(s->monStartMonBefore.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonthBefore=powerMonthBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerMonthYearBefore=value.entrySet().stream().filter(s->monStartYearBefore.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonthYearBefore=powerMonthYearBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerVo.setPowerYear(powerYear.doubleValue()); + powerVo.setPowerYearBefore(powerYearBefore.doubleValue()); + BigDecimal yearPercentage = new BigDecimal(0); + BigDecimal planPercentage = new BigDecimal(0); + if (powerYearBefore.compareTo(BigDecimal.ZERO) != 0) { + yearPercentage = (powerYear.subtract(powerYearBefore)).divide(powerYearBefore, 2, BigDecimal.ROUND_UP); + } + if (BigDecimal.valueOf(planGeneration).compareTo(BigDecimal.ZERO) != 0) { + planPercentage = powerYear.divide(BigDecimal.valueOf(planGeneration), 2, BigDecimal.ROUND_UP); + } + powerVo.setPlanPercentage(planPercentage.doubleValue()); + powerVo.setPowerYearPercentage(yearPercentage.doubleValue()); + powerVo.setPowerMon(powerMonth.doubleValue()); + powerVo.setPowerMonBefore(powerMonthBefore.doubleValue()); + powerVo.setPowerMonYearBefore(powerMonthYearBefore.doubleValue()); + BigDecimal monPercentage = new BigDecimal(0); + if (powerMonthYearBefore.compareTo(BigDecimal.ZERO) != 0) { + monPercentage = (powerMonth.subtract(powerMonthYearBefore)).divide(powerMonthYearBefore, 2, BigDecimal.ROUND_UP); + } + powerVo.setPowerMonPercentage(monPercentage.doubleValue()); + powerPercentageVoList.add(powerVo); + } + } + return powerPercentageVoList; + } + private void getPowerData(List deptList, String yearStart, String yearEnd, String yearBeforeStart, String yearBeforeEnd, String monthStart, String monthEnd, String beforeMonthStart, String beforeMonthEnd, String monthStartBeforeYear, String monthEndBeforeYear, List devices, List planYearData, List powerPercentageVoList) { for (Dept dept : deptList) { MonPowerPercentageVo powerVo = new MonPowerPercentageVo();