diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/OperationalConstants.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/OperationalConstants.java index 93810fc..16f31e5 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/OperationalConstants.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/OperationalConstants.java @@ -4,7 +4,7 @@ import lombok.Getter; public class OperationalConstants { - public final static String APP_NAME = "hzims-operational"; + public final static String APP_NAME = "hzims-operational-ty"; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/TicketChartCell.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/TicketChartCell.java index bb752eb..2ff6caf 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/TicketChartCell.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/TicketChartCell.java @@ -17,10 +17,14 @@ public class TicketChartCell { private String ticketName; @ApiModelProperty(value = "本月数量") private int ticketMon; + @ApiModelProperty(value = "本月合格数量") + private int ticketMonPassCount; @ApiModelProperty(value = "本月合格率") private double ticketMonPerc; @ApiModelProperty(value = "本年数量") private int ticketYear; + @ApiModelProperty(value = "本年合格数量") + private int ticketYearPassCount; @ApiModelProperty(value = "本年合格率") private double ticketYeaPercr; } 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..6ce0cbd 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 @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import java.io.IOException; import java.net.URLEncoder; +import java.text.ParseException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -125,7 +126,7 @@ 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 = "站点Id", required = true) Long deptId,@ApiParam(value = "月报类型", required = true) Long type) { + @ApiParam(value = "站点Id", required = true) Long deptId,@ApiParam(value = "月报类型", required = true) Long type) throws ParseException { HashMap map = new HashMap<>(); if (Func.isEmpty(year)||Func.isEmpty(deptId)||Func.isEmpty(month)||year==0||deptId==0||month==0){ 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..b31145b 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 @@ -4,6 +4,7 @@ import com.hnac.hzims.operational.main.vo.AreaMonthReportVo; import org.springblade.core.tool.api.R; import javax.servlet.http.HttpServletResponse; +import java.text.ParseException; import java.util.HashMap; import java.util.List; @@ -18,5 +19,5 @@ public interface IAreaMonthReportService { R export(HttpServletResponse response, String date); - R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month,Long deptId,String name); + R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month,Long deptId,String name) throws ParseException; } 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..0a84df8 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 @@ -201,7 +201,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { return R.data("success"); } @Override - public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month, Long deptId,String deptName) { + public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month, Long deptId,String deptName) throws ParseException { R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); if (!deptByCurrentUser.isSuccess()||deptByCurrentUser.getData()==null){ return R.fail("用户权限查询失败"); @@ -219,9 +219,9 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { List stationEntityList = stationService.list(Wrappers.lambdaQuery() .in(StationEntity::getRefDept, deptIds) .eq(StationEntity::getType, HomePageConstant.HYDROPOWER)); - stationEntityList=Optional.ofNullable(stationEntityList).orElse(new ArrayList<>()).stream().filter(s->Func.isNotEmpty(s.getCommissionTime())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(stationEntityList)) { - int commissionTime = stationEntityList.stream().map(s -> { + List stationEntityListByCommissionTime=Optional.ofNullable(stationEntityList).orElse(new ArrayList<>()).stream().filter(s->Func.isNotEmpty(s.getCommissionTime())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(stationEntityListByCommissionTime)) { + int commissionTime = stationEntityListByCommissionTime.stream().map(s -> { Duration dur = Duration.between(s.getCommissionTime(), LocalDateTime.now()); return (int) dur.toDays(); }).reduce(Integer::max).get(); @@ -236,10 +236,11 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { Integer yearBefore = year - 1; map.put("yearBefore", yearBefore); map.put("month", month); - Integer monthBefore = month - 1; + String monStartMonBefore = TimeUtils.getEarlyTime(yearBefore, month); + String[] split = monStartMonBefore.split("-"); + Integer monthBefore = Integer.valueOf(split[1]); map.put("monthBefore", monthBefore); // map.put("date", date); - map.put("stationName", deptName); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); map.put("writeTime", simpleDateFormat.format(new Date())); @@ -262,7 +263,6 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { // 今年当月 String monthStart = TimeUtils.getMonthStart(year, month); String monthEndV2 = TimeUtils.getMonthEndV2(year, month); - List reals = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); List realsByDept = reals.stream().filter(s -> deptIds.contains(s.getDeptId())).collect(Collectors.toList()); // 装机容量占比数据组装 @@ -294,6 +294,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { //装机容量占比图 ImageEntity capacityProportionChart = JFreeUtil.pieChartByDouble("水电项目装机容量占比图", capacityProportionMap, 500, 400); map.put("capacityProportionChart", capacityProportionChart); + map.put("factoryComparisonChart", "---暂无数据---"); //各发电站发电量环比图+表格数据组装 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); @@ -315,14 +316,21 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { for (MonPowerPercentageVo monPowerPercentageVo : powerPercentageVoList) { HashMap power = new HashMap<>(); power.put("name", monPowerPercentageVo.getDeptName()); - power.put("monthBefore", monPowerPercentageVo.getPowerMonBefore()+"MW"); - power.put("month",monPowerPercentageVo.getPowerMon()+"MW"); + power.put("monthBefore", monPowerPercentageVo.getPowerMonBefore()+"MkWh"); + power.put("month",monPowerPercentageVo.getPowerMon()+"MkWh"); powerMap.add(power); } map.put("power", powerMap); + String dateFormat=""; + if (month<10){ + dateFormat=year+"-"+"0"+month; + }else { + dateFormat=year+"-"+month; + } //表格总计 - List planYearAll = planGenertionClient.getPlanGenerationByParam(null, Collections.singletonList(deptId.toString()), year.toString()); - List planMonAll = planGenertionClient.getPlanGenerationByParam(null, Collections.singletonList(deptId.toString()), year + "-" + month); + List deptIdsString = deptIds.stream().map(String::valueOf).collect(Collectors.toList()); + List planYearAll = planGenertionClient.getPlanGenerationByParam(null, deptIdsString, year.toString()); + List planMonAll = planGenertionClient.getPlanGenerationByParam(null, deptIdsString, dateFormat); getTabelSum(deptId, powerPercentageVoList, planYearAll, planMonAll, map); //发电情况统计表数据 ArrayList> list = new ArrayList<>(powerPercentageVoList.size()); @@ -335,7 +343,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { temp.put("year", String.valueOf(monPowerPercentageVo.getPowerYear())); temp.put("monPercentage", monPowerPercentageVo.getPowerMonPercentage() * 100 + "%"); temp.put("yearPercentage", monPowerPercentageVo.getPowerYearPercentage() * 100 + "%"); - temp.put("plan", monPowerPercentageVo.getPlanPercentage() * 100 + "%"); + temp.put("plan", monPowerPercentageVo.getPlanPercentage()+ "%"); list.add(temp); } map.put("powerGeneration", list); @@ -402,7 +410,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { //表格数据 HashMap temp = new HashMap<>(); temp.put("deptName", "总计"); - temp.put("checkLevel", "无等级"); + temp.put("checkLevel", ""); temp.put("findShortagesMon", "0"); temp.put("shortagesMon", "0"); temp.put("findShortagesYear", "0"); @@ -503,10 +511,12 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { int count = yearTicketCollect.size(); ticketChartCell.setTicketYear(count); List ticketIds = yearTicketCollect.stream().map(BaseEntity::getId).collect(Collectors.toList()); + ticketChartCell.setTicketYearPassCount(0); R ticketPassCount = ticketInfoClient.getTicketPassByIds(ticketIds); if (ticketPassCount.isSuccess() && ticketPassCount.getData() != null && count != 0) { double ticketYearPerc = BigDecimal.valueOf(ticketPassCount.getData()).divide(BigDecimal.valueOf(count), 2, BigDecimal.ROUND_UP).doubleValue(); ticketChartCell.setTicketYeaPercr(ticketYearPerc); + ticketChartCell.setTicketYearPassCount(ticketPassCount.getData().intValue()); } } if (CollectionUtils.isNotEmpty(monthTicketCollect)) { @@ -514,10 +524,13 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { int count = monthTicketCollect.size(); ticketChartCell.setTicketMon(count); List monthTicketIds = monthTicketCollect.stream().map(BaseEntity::getId).collect(Collectors.toList()); + //合格数量 R ticketMonthPassCount = ticketInfoClient.getTicketPassByIds(monthTicketIds); + ticketChartCell.setTicketMonPassCount(0); if (ticketMonthPassCount.isSuccess() && ticketMonthPassCount.getData() != null && count != 0) { double ticketMonthPerc = BigDecimal.valueOf(ticketMonthPassCount.getData()).divide(BigDecimal.valueOf(count), 2, BigDecimal.ROUND_UP).doubleValue(); ticketChartCell.setTicketMonPerc(ticketMonthPerc); + ticketChartCell.setTicketMonPassCount(ticketMonthPassCount.getData().intValue()); } } } @@ -536,9 +549,11 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { ticketChartCell.setTicketYear(count); List ticketIds = yearOperateCollect.stream().map(BaseEntity::getId).collect(Collectors.toList()); R ticketPassCount = ticketInfoClient.getTicketPassByIds(ticketIds); + ticketChartCell.setTicketYearPassCount(0); if (ticketPassCount.isSuccess() && ticketPassCount.getData() != null && count != 0) { double ticketYearPerc = BigDecimal.valueOf(ticketPassCount.getData()).divide(BigDecimal.valueOf(count), 2, BigDecimal.ROUND_UP).doubleValue(); ticketChartCell.setTicketYeaPercr(ticketYearPerc); + ticketChartCell.setTicketYearPassCount(ticketPassCount.getData().intValue()); } } if (CollectionUtils.isNotEmpty(monthOperateCollect)) { @@ -547,9 +562,11 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { ticketChartCell.setTicketMon(count); List monthTicketIds = monthOperateCollect.stream().map(BaseEntity::getId).collect(Collectors.toList()); R ticketMonthPassCount = ticketInfoClient.getTicketPassByIds(monthTicketIds); + ticketChartCell.setTicketMonPassCount(0); if (ticketMonthPassCount.isSuccess() && ticketMonthPassCount.getData() != null && count != 0) { double ticketMonthPerc = BigDecimal.valueOf(ticketMonthPassCount.getData()).divide(BigDecimal.valueOf(count), 2, BigDecimal.ROUND_UP).doubleValue(); ticketChartCell.setTicketMonPerc(ticketMonthPerc); + ticketChartCell.setTicketMonPassCount(ticketMonthPassCount.getData().intValue()); } } } @@ -569,10 +586,20 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { sumCell.setTicketType(mapTicketChart.getKey()); sumCell.setTicketName(TicketConstants.TicketTypeNameEnum.getTicketNameByType(mapTicketChart.getKey())); List ticketChartValue = mapTicketChart.getValue(); - sumCell.setTicketMon(ticketChartValue.stream().mapToInt(TicketChartCell::getTicketMon).sum()); - sumCell.setTicketYear(ticketChartValue.stream().mapToInt(TicketChartCell::getTicketYear).sum()); - sumCell.setTicketMonPerc(ticketChartValue.stream().mapToDouble(TicketChartCell::getTicketMonPerc).sum()); - sumCell.setTicketYeaPercr(ticketChartValue.stream().mapToDouble(TicketChartCell::getTicketYeaPercr).sum()); + int sumTicketMon = ticketChartValue.stream().mapToInt(TicketChartCell::getTicketMon).sum(); + sumCell.setTicketMon(sumTicketMon); + int sumTicketYear = ticketChartValue.stream().mapToInt(TicketChartCell::getTicketYear).sum(); + sumCell.setTicketYear(sumTicketYear); + int sumTicketMonPass = ticketChartValue.stream().mapToInt(TicketChartCell::getTicketMonPassCount).sum(); + int sumTicketYearPass = ticketChartValue.stream().mapToInt(TicketChartCell::getTicketYearPassCount).sum(); + if (sumTicketMonPass>0&&sumTicketMon>0){ + BigDecimal monPassPerc = new BigDecimal(sumTicketMonPass).divide(new BigDecimal(sumTicketMon), 2, BigDecimal.ROUND_UP); + sumCell.setTicketMonPerc(monPassPerc.doubleValue()); + } + if (sumTicketYear>0&&sumTicketYearPass>0){ + BigDecimal yearPassPerc = new BigDecimal(sumTicketYearPass).divide(new BigDecimal(sumTicketYear), 2, BigDecimal.ROUND_UP); + sumCell.setTicketYeaPercr(yearPassPerc.doubleValue()); + } sumCollect.add(sumCell); } TicketChartVo ticketChartVo = new TicketChartVo(); @@ -621,6 +648,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { private List getMonPowerPercentageVos(Integer year, Integer month, List deptList, List deptIds, List stationEntityList, List stationIds, Integer yearBefore, Integer monthBefore) { List deptIdsString = deptIds.stream().map(String::valueOf).collect(Collectors.toList()); + //年计划发电量 List planYearData = planGenertionClient.getPlanGenerationByParam(null, deptIdsString, year.toString()); List powerPercentageVoList = new ArrayList<>(); //水电站,光伏站和带代运维数据近三年数据 @@ -629,7 +657,8 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { List listByYearBefore = TimeUtils.getListByYear(yearBefore); String monStart = TimeUtils.getMon(year, month); String monStartYearBefore = TimeUtils.getMon(yearBefore, month); - String monStartMonBefore = TimeUtils.getMon(year, monthBefore); + String monStartMonBefore = TimeUtils.getEarlyTime(yearBefore, month); +// String monStartMonBefore = TimeUtils.getMon(year, monthBefore); // 格式:站点-日期-发电量 for (Map.Entry> deviceMap : powerMapThree.entrySet()) { String deptNameByKey; @@ -649,7 +678,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { 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()); + planGeneration = Double.valueOf(planGenerationById.stream().mapToDouble(PlanGenerationEntity::getPlanGeneration).sum()); } //当前机构近三年的数据 Map value = deviceMap.getValue(); @@ -778,11 +807,12 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { private static void getTabelSum(Long deptId, List powerPercentageVoList, List planYearAll, List planMonAll, HashMap map) { Float planGeneration = 0f; if (Func.isNotEmpty(planYearAll)) { - planGeneration = planYearAll.get(0).getPlanGeneration(); + planGeneration =Double.valueOf(planYearAll.stream().mapToDouble(PlanGenerationEntity::getPlanGeneration).sum()).floatValue() ; } Float planMonGeneration = 0f; if (Func.isNotEmpty(planMonAll)) { - planMonGeneration = planMonAll.get(0).getPlanGeneration(); + planMonGeneration =Double.valueOf(planMonAll.stream().mapToDouble(PlanGenerationEntity::getPlanGeneration).sum()).floatValue() ; +// planMonGeneration = planMonAll.get(0).getPlanGeneration(); } MonPowerPercentageVo powerVo = new MonPowerPercentageVo(); powerVo.setDeptId(deptId); @@ -803,7 +833,8 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { 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); + //因为计划发电量的单位是kwh,发电量已经转换为万kwh,再加上百分比转换所以需要乘以10000*100 + planPercentage = powerYear.divide(BigDecimal.valueOf(planGeneration).divide(new BigDecimal(1000000)), 2, BigDecimal.ROUND_UP); // 年计划完成率 map.put("yearCompletionRate", planPercentage.toString()); } else { @@ -820,7 +851,8 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { // 项目月计划完成量 BigDecimal planMonPercentage = new BigDecimal(0); if (powerMonth.compareTo(BigDecimal.ZERO) != 0 && BigDecimal.valueOf(planMonGeneration).compareTo(BigDecimal.ZERO) != 0) { - planMonPercentage = powerMonth.divide(BigDecimal.valueOf(planMonGeneration), 2, BigDecimal.ROUND_UP); + //因为计划发电量的单位是kwh,发电量已经转换为万kwh,再加上百分比转换所以需要乘以10000*100 + planMonPercentage = powerMonth.divide(BigDecimal.valueOf(planMonGeneration).divide(new BigDecimal(1000000)), 2, BigDecimal.ROUND_UP); } map.put("monCompletionRate", planMonPercentage); BigDecimal powerMonthBefore = powerPercentageVoList.stream() diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java index 58bf871..ddfd1f9 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java @@ -112,7 +112,7 @@ public class TimeUtils { } public static List getListByYear(Integer year) { List monthList=new ArrayList<>(); - for (int i = 1; i <13; i++) { + for (int i = 0; i <12; i++) { // 创建一个Calendar对象 Calendar calendar = Calendar.getInstance(); // 设置年份 @@ -143,4 +143,24 @@ public class TimeUtils { String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) ; return start; } + + + public static String getEarlyTime(Integer year, Integer month) { + // 创建一个Calendar对象 + Calendar calendar = Calendar.getInstance(); + // 设置年份 + calendar.set(Calendar.YEAR, year); + // 设置月份为1(即一月) + calendar.set(Calendar.MONTH, month-1); + // 设置日期为1 + calendar.set(Calendar.DATE, 1); + // 设置时间为0点0分0秒 + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.add(Calendar.MONTH, -1); + String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) ; + return start; + } + } diff --git a/hzims-service/operational/src/main/resources/template/waterMonReport.docx b/hzims-service/operational/src/main/resources/template/waterMonReport.docx index f29b321..5b3dd55 100644 Binary files a/hzims-service/operational/src/main/resources/template/waterMonReport.docx and b/hzims-service/operational/src/main/resources/template/waterMonReport.docx differ