From 4aff9e5429116118c3e647192688e0d5c686faa7 Mon Sep 17 00:00:00 2001 From: tyty Date: Tue, 8 Aug 2023 15:59:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=B0=B4=E7=94=B5=E7=AB=99?= =?UTF-8?q?=E6=9C=88=E6=8A=A5bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/controller/AreaMonthReportController.java | 10 ++++++--- .../main/service/IAreaMonthReportService.java | 2 +- .../service/impl/AreaMonthReportServiceImpl.java | 26 +++++++++++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) 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 d0db6d4..ad1c3b8 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 @@ -19,6 +19,7 @@ import org.springblade.core.boot.ctrl.BladeController; 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.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -42,7 +43,6 @@ public class AreaMonthReportController extends BladeController { @NotNull private final IAreaMonthReportService service; - private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; @ApiLog @ApiOperationSupport(order = 1) @@ -126,13 +126,17 @@ public class AreaMonthReportController extends BladeController { @ApiParam(value = "站点Id", required = true) Long deptId,@ApiParam(value = "月报类型", required = true) Long type) { HashMap map = new HashMap<>(); + if (Func.isEmpty(year)||Func.isEmpty(deptId)||Func.isEmpty(month)||year==0||deptId==0||month==0){ + return R.fail("传入格式不对,请重新导出"); + } + String deptName=""; if (type==1){ - service.exportHydropowerStationMonthReport(response, map,year,month,deptId); + service.exportHydropowerStationMonthReport(response, map,year,month,deptId,deptName); //word模板相对路径、word生成路径、word生成的文件名称、数据源 } XWPFDocument xwpfDocument = WordUtils.exportWordV2("template/waterMonReport.docx", map); // 下载导出 - String filename = "(" + year+"年"+month+"月"+ ")水电站月报"; + String filename = "(" + year+"年"+month+"月"+ ")"+deptName+"水电站月报"; // 设置头信息 response.setCharacterEncoding("UTF-8"); response.setContentType("application/vnd.ms-excel"); 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 e8007a3..14a7882 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,Long deptId); + R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month,Long deptId,String name); } 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 0773fa0..0e7ad35 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 @@ -204,7 +204,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { return R.data("success"); } @Override - public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month, Long deptId) { + public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month, Long deptId,String name) { R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); if (!deptByCurrentUser.isSuccess()||deptByCurrentUser.getData()==null){ return R.fail("用户权限查询失败"); @@ -214,6 +214,8 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { return R.fail("暂无该机构"); } String deptName = deptNameR.getData(); +// 赋值给导出表格名称 + name=deptName; R> deptR = sysClient.getDeptByType("200000", deptId, 4); if (!deptR.isSuccess() || deptR.getData() == null) { return R.fail("该机构不包含水站信息"); @@ -227,10 +229,17 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { List stationEntityList = stationService.list(Wrappers.lambdaQuery() .in(StationEntity::getRefDept, deptIds) .eq(StationEntity::getType, HomePageConstant.HYDROPOWER)); - Integer commissionTime = stationEntityList.stream().map(s -> { - Duration dur = Duration.between(s.getCommissionTime(), LocalDateTime.now()); - return (int) dur.toDays();}).reduce(Integer::max).get(); - List stationIds = stationEntityList.stream().map(BaseEntity::getId).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(stationEntityList)) { + Integer commissionTime = stationEntityList.stream().map(s -> { + Duration dur = Duration.between(s.getCommissionTime(), LocalDateTime.now()); + return (int) dur.toDays(); + }).reduce(Integer::max).get(); + map.put("commissionTime", commissionTime.toString()); + }else { + map.put("commissionTime", 0); + } + List stationIds = Optional.ofNullable(stationEntityList) + .orElse(new ArrayList<>()).stream().map(BaseEntity::getId).collect(Collectors.toList()); //其它普通数据 map.put("year", year); Integer yearBefore = year - 1; @@ -239,7 +248,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { Integer monthBefore = month - 1; map.put("monthBefore", monthBefore); // map.put("date", date); - map.put("commissionTime", commissionTime.toString()); + map.put("stationName", deptName); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); map.put("writeTime", simpleDateFormat.format(new Date())); @@ -294,7 +303,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { //装机容量占比图 ImageEntity capacityProportionChart = JFreeUtil.pieChartByDouble("水电项目装机容量占比图", capacityProportionMap, 500, 400); map.put("capacityProportionChart", capacityProportionChart); -//各发电站发电量环比图+表格数据组装 + //各发电站发电量环比图+表格数据组装 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); // 各发电站发电量环比图数据组装 @@ -384,7 +393,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { checkList.add(temp); } map.put("checkList", checkList); -//各电站缺陷统计表 + //各电站缺陷统计表 //本年缺陷 LambdaQueryWrapper wrapperYear = Wrappers.lambdaQuery(); wrapperYear.ge(OperPhenomenonEntity::getCreateTime, yearStart); @@ -626,6 +635,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { 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())) {