Browse Source

#集团电量报表

zhongwei
yang_shj 3 months ago
parent
commit
982f4b50db
  1. 5
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java
  2. 3
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java
  3. 16
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/StationsByDeptIdsParamVo.java
  4. 185
      hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java
  5. 9
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java

5
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<List<StationEntity>> getStationsByRefDepts(@RequestParam(value = "deptIds",required = false) List<Long> deptIds);
@PostMapping(GET_STATIONS_BY_REF_DEPTS)
R<List<StationEntity>> getStationsByRefDepts(@RequestBody StationsByDeptIdsParamVo param);
}

3
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<List<StationEntity>> getStationsByRefDepts(List<Long> deptIds) {
public R<List<StationEntity>> getStationsByRefDepts(StationsByDeptIdsParamVo param) {
return R.fail("远程调用失败!");
}
}

16
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<Long> deptIds;
}

185
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<String, Object> area(List<Long> deptIds, Long type, String time) {
// 查询站点
R<List<StationEntity>> stations = stationClient.getStationsByRefDepts(deptIds);
StationEntity entity = new StationEntity();
entity.setType(0);
R<List<StationEntity>> 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<ThreeEntity> threes = threeService.list(Wrappers.<ThreeEntity>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<String, Object> group(List<Dept> depts, Long type, String time) {
// 查询站点
StationEntity entity = new StationEntity();
entity.setType(0);
R<List<StationEntity>> stations = stationClient.list(entity);
if(!stations.isSuccess() || ObjectUtil.isEmpty(stations.getData())){
return new HashMap<>();
}
List<Dept> areas = depts.stream().filter(dept -> dept.getDeptCategory().equals(3)).collect(Collectors.toList());
if(CollectionUtil.isEmpty(areas)){
return new HashMap<>();
}
Map<String,Object> result = new HashMap<>();
// 月
if (type == 1) {
// 查询月数据
List<ThirtyEntity> thirtys = thirtyService.list(Wrappers.<ThirtyEntity>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<TableHeadVo> 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<Long> childs = depts.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList());
if(CollectionUtil.isEmpty(childs)){
return;
}
List<String> 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<List<Object>> tableDate = new ArrayList<>();
while (start.compareTo(end) < 0){
List<Object> 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<Long> childs = depts.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList());
if(CollectionUtil.isEmpty(childs)){
return;
}
List<String> 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<ThreeEntity> threes = threeService.list(Wrappers.<ThreeEntity>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<TableHeadVo> 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<Long> childs = depts.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList());
if(CollectionUtil.isEmpty(childs)){
return;
}
List<String> 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<List<Object>> tableDate = new ArrayList<>();
while (start.compareTo(end) < 0){
List<Object> 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<Long> childs = depts.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList());
if(CollectionUtil.isEmpty(childs)){
return;
}
List<String> 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

9
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<List<StationEntity>> getStationsByRefDepts(@RequestParam(value = "deptIds" , required = false) List<Long> deptIds) {
@PostMapping("/getStationsByRefDepts")
public R<List<StationEntity>> getStationsByRefDepts(@RequestBody StationsByDeptIdsParamVo param) {
LambdaQueryWrapper<StationEntity> 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));
}

Loading…
Cancel
Save