diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java index 53cc157..680bfa0 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java @@ -2,6 +2,7 @@ package com.hnac.hzims.operational.station.feign; import com.hnac.hzims.operational.OperationalConstants; import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.vo.StationsByDeptIdsParamVo; import org.springblade.core.tool.api.R; import org.springblade.system.user.entity.User; import org.springframework.cloud.openfeign.FeignClient; @@ -89,6 +90,6 @@ public interface IStationClient { @RequestParam(value = "endTime",required = false) String endTime, @RequestParam(value = "type",required = false) String type); - @GetMapping(GET_STATIONS_BY_REF_DEPTS) - R> getStationsByRefDepts(@RequestParam(value = "deptIds",required = false) List deptIds); + @PostMapping(GET_STATIONS_BY_REF_DEPTS) + R> getStationsByRefDepts(@RequestBody StationsByDeptIdsParamVo param); } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java index 171b0a4..b076ce4 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java @@ -3,6 +3,7 @@ package com.hnac.hzims.operational.station.feign; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.vo.StationsByDeptIdsParamVo; import org.springblade.core.tool.api.R; import org.springblade.system.user.entity.User; import org.springframework.stereotype.Component; @@ -84,7 +85,7 @@ public class IStationClientFallBack implements IStationClient { } @Override - public R> getStationsByRefDepts(List deptIds) { + public R> getStationsByRefDepts(StationsByDeptIdsParamVo param) { return R.fail("远程调用失败!"); } } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/StationsByDeptIdsParamVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/StationsByDeptIdsParamVo.java new file mode 100644 index 0000000..20ca59f --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/StationsByDeptIdsParamVo.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.operational.station.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author ysj + */ +@Data +public class StationsByDeptIdsParamVo { + + @ApiModelProperty("机构集合") + private List deptIds; +} 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 bd70dda..651732a 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 @@ -10,6 +10,7 @@ import com.hnac.hzims.electric.service.ThreeService; import com.hnac.hzims.electric.vo.TableHeadVo; 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 lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; @@ -67,7 +68,7 @@ public class ElectricReportServiceImpl implements IElectricReportService { return this.area(deptIds,type,time); case 2: case 1: - //return this.group(); + return this.group(depts.getData(),type,time); default: return result; @@ -103,7 +104,9 @@ public class ElectricReportServiceImpl implements IElectricReportService { */ private Map area(List deptIds, Long type, String time) { // 查询站点 - R> stations = stationClient.getStationsByRefDepts(deptIds); + StationEntity entity = new StationEntity(); + entity.setType(0); + R> stations = stationClient.list(entity); if(!stations.isSuccess() || ObjectUtil.isEmpty(stations.getData())){ return new HashMap<>(); } @@ -175,7 +178,7 @@ public class ElectricReportServiceImpl implements IElectricReportService { else if (type == 2) { // 查询月数据 List threes = threeService.list(Wrappers.lambdaQuery() - .isNotNull(ThreeEntity::getDeviceCode) + //.isNotNull(ThreeEntity::getDeviceCode) .in(ThreeEntity::getStationId,stations.getData().stream().map(StationEntity::getCode).collect(Collectors.toList())) .like(ThreeEntity::getStrMonth,time) ); @@ -236,6 +239,182 @@ public class ElectricReportServiceImpl implements IElectricReportService { return result; } + + /** + * 集团级别数据 + * @param depts + * @param type + * @param time + * @return + */ + private Map group(List depts, Long type, String time) { + // 查询站点 + StationEntity entity = new StationEntity(); + entity.setType(0); + R> stations = stationClient.list(entity); + if(!stations.isSuccess() || ObjectUtil.isEmpty(stations.getData())){ + return new HashMap<>(); + } + List areas = depts.stream().filter(dept -> dept.getDeptCategory().equals(3)).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(areas)){ + return new HashMap<>(); + } + + Map result = new HashMap<>(); + // 月 + if (type == 1) { + // 查询月数据 + List thirtys = thirtyService.list(Wrappers.lambdaQuery() + //.isNotNull(ThirtyEntity::getDeviceCode) + .in(ThirtyEntity::getStationId,stations.getData().stream().map(StationEntity::getCode).collect(Collectors.toList())) + .like(ThirtyEntity::getStrDay,time) + ); + if(CollectionUtil.isEmpty(thirtys)){ + return new HashMap<>(); + } + // 表头 + List tableHeads = new ArrayList<>(); + TableHeadVo firstHead = new TableHeadVo(); + firstHead.setTableName("日期"); + firstHead.setIsChildren(false); + tableHeads.add(firstHead); + TableHeadVo secondHead = new TableHeadVo(); + secondHead.setTableName("日总计发电量"); + secondHead.setIsChildren(true); + secondHead.setChildren(Arrays.asList("日总有功","日总无功")); + tableHeads.add(secondHead); + + // 根据区域分组 + areas.stream().sorted(Comparator.comparing(Dept::getDeptName)).forEach(area->{ + List childs = depts.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(childs)){ + return; + } + List codes = stations.getData().stream().filter(o-> childs.contains(o.getRefDept()) && ObjectUtil.isNotEmpty(o.getType()) && o.getType().equals(0)).map(StationEntity::getCode).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(codes)){ + return; + } + TableHeadVo tableHead = new TableHeadVo(); + tableHead.setTableName(area.getDeptName() + "发电量(kWh)"); + tableHead.setIsChildren(true); + tableHead.setChildren(Arrays.asList("日有功","日无功")); + tableHeads.add(tableHead); + }); + result.put("tableHead",tableHeads); + + // 组装数据 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(time + "-01 00:00:00",DateUtil.PATTERN_DATETIME)); + calendar.add(Calendar.MONTH,1); + Date end = calendar.getTime(); + calendar.add(Calendar.MONTH,-1); + Date start = calendar.getTime(); + List> tableDate = new ArrayList<>(); + while (start.compareTo(end) < 0){ + List item = new ArrayList<>(); + String day = DateUtil.format(start,DateUtil.PATTERN_DATE); + item.add(start.getDate() + "日"); + // 总计:有功、无功 + item.add(thirtys.stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); + item.add(thirtys.stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); + + // 遍历机组 + areas.stream().sorted(Comparator.comparing(Dept::getDeptName)).forEach(area->{ + List childs = depts.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(childs)){ + return; + } + List codes = stations.getData().stream().filter(o-> childs.contains(o.getRefDept()) && ObjectUtil.isNotEmpty(o.getType()) && o.getType().equals(0)).map(StationEntity::getCode).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(codes)){ + return; + } + item.add(thirtys.stream().filter(thirty -> thirty.getStrDay().contains(day) && codes.contains(thirty.getStationId())).mapToDouble(o->o.getGenerate().doubleValue()).sum()); + item.add(thirtys.stream().filter(thirty -> thirty.getStrDay().contains(day) && codes.contains(thirty.getStationId())).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); + }); + calendar.add(Calendar.DAY_OF_MONTH,1); + start = calendar.getTime(); + tableDate.add(item); + } + result.put("tableDate",tableDate); + + }else if(type == 2){ + // 查询月数据 + List threes = threeService.list(Wrappers.lambdaQuery() + //.isNotNull(ThreeEntity::getDeviceCode) + .in(ThreeEntity::getStationId,stations.getData().stream().map(StationEntity::getCode).collect(Collectors.toList())) + .like(ThreeEntity::getStrMonth,time) + ); + if(CollectionUtil.isEmpty(threes)){ + return new HashMap<>(); + } + // 表头 + List tableHeads = new ArrayList<>(); + TableHeadVo firstHead = new TableHeadVo(); + firstHead.setTableName("月份"); + firstHead.setIsChildren(false); + tableHeads.add(firstHead); + TableHeadVo secondHead = new TableHeadVo(); + secondHead.setTableName("月总计发电量"); + secondHead.setIsChildren(true); + secondHead.setChildren(Arrays.asList("月总有功","月总无功")); + tableHeads.add(secondHead); + + // 根据设备分组 + areas.stream().sorted(Comparator.comparing(Dept::getDeptName)).forEach(area->{ + List childs = depts.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(childs)){ + return; + } + List codes = stations.getData().stream().filter(o-> childs.contains(o.getRefDept()) && ObjectUtil.isNotEmpty(o.getType()) && o.getType().equals(0)).map(StationEntity::getCode).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(codes)){ + return; + } + TableHeadVo tableHead = new TableHeadVo(); + tableHead.setTableName(area.getDeptName() + "发电量(kWh)"); + tableHead.setIsChildren(true); + tableHead.setChildren(Arrays.asList("月有功","月无功")); + tableHeads.add(tableHead); + }); + result.put("tableHead",tableHeads); + + // 组装数据 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(time + "-01-01 00:00:00",DateUtil.PATTERN_DATETIME)); + calendar.add(Calendar.YEAR,1); + Date end = calendar.getTime(); + calendar.add(Calendar.YEAR,-1); + Date start = calendar.getTime(); + List> tableDate = new ArrayList<>(); + while (start.compareTo(end) < 0){ + List item = new ArrayList<>(); + String mon = DateUtil.format(start,"yyyy-MM"); + item.add(start.getMonth() + 1 + "月"); + // 总计:有功、无功 + item.add(threes.stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); + item.add(threes.stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); + + // 遍历机组 + areas.stream().sorted(Comparator.comparing(Dept::getDeptName)).forEach(area->{ + List childs = depts.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(childs)){ + return; + } + List codes = stations.getData().stream().filter(o-> childs.contains(o.getRefDept()) && ObjectUtil.isNotEmpty(o.getType()) && o.getType().equals(0)).map(StationEntity::getCode).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(codes)){ + return; + } + item.add(threes.stream().filter(thirty -> thirty.getStrMonth().contains(mon) && codes.contains(thirty.getStationId())).mapToDouble(o->o.getGenerate().doubleValue()).sum()); + item.add(threes.stream().filter(thirty -> thirty.getStrMonth().contains(mon) && codes.contains(thirty.getStationId())).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); + }); + calendar.add(Calendar.MONTH,1); + start = calendar.getTime(); + tableDate.add(item); + } + result.put("tableDate",tableDate); + } + return result; + } + /** * 站点级别数据 * @param deptId diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java index 8746669..2130642 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzims.operational.station.vo.StationsByDeptIdsParamVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; @@ -152,11 +153,11 @@ public class StationClient implements IStationClient { } @Override - @GetMapping("/getStationsByRefDepts") - public R> getStationsByRefDepts(@RequestParam(value = "deptIds" , required = false) List deptIds) { + @PostMapping("/getStationsByRefDepts") + public R> getStationsByRefDepts(@RequestBody StationsByDeptIdsParamVo param) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - if(CollectionUtil.isNotEmpty(deptIds)) { - wrapper.in(StationEntity::getRefDept,deptIds); + if(CollectionUtil.isNotEmpty(param.getDeptIds())) { + wrapper.in(StationEntity::getRefDept,param.getDeptIds()); } return R.data(stationService.list(wrapper)); }