|
|
@ -10,6 +10,7 @@ import com.hnac.hzims.electric.service.ThreeService; |
|
|
|
import com.hnac.hzims.electric.vo.TableHeadVo; |
|
|
|
import com.hnac.hzims.electric.vo.TableHeadVo; |
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import com.hnac.hzims.operational.station.feign.IStationClient; |
|
|
|
import com.hnac.hzims.operational.station.feign.IStationClient; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.station.vo.StationsByDeptIdsParamVo; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
@ -67,7 +68,7 @@ public class ElectricReportServiceImpl implements IElectricReportService { |
|
|
|
return this.area(deptIds,type,time); |
|
|
|
return this.area(deptIds,type,time); |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
//return this.group();
|
|
|
|
return this.group(depts.getData(),type,time); |
|
|
|
default: |
|
|
|
default: |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
@ -103,7 +104,9 @@ public class ElectricReportServiceImpl implements IElectricReportService { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Map<String, Object> area(List<Long> deptIds, Long type, String time) { |
|
|
|
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())){ |
|
|
|
if(!stations.isSuccess() || ObjectUtil.isEmpty(stations.getData())){ |
|
|
|
return new HashMap<>(); |
|
|
|
return new HashMap<>(); |
|
|
|
} |
|
|
|
} |
|
|
@ -175,7 +178,7 @@ public class ElectricReportServiceImpl implements IElectricReportService { |
|
|
|
else if (type == 2) { |
|
|
|
else if (type == 2) { |
|
|
|
// 查询月数据
|
|
|
|
// 查询月数据
|
|
|
|
List<ThreeEntity> threes = threeService.list(Wrappers.<ThreeEntity>lambdaQuery() |
|
|
|
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())) |
|
|
|
.in(ThreeEntity::getStationId,stations.getData().stream().map(StationEntity::getCode).collect(Collectors.toList())) |
|
|
|
.like(ThreeEntity::getStrMonth,time) |
|
|
|
.like(ThreeEntity::getStrMonth,time) |
|
|
|
); |
|
|
|
); |
|
|
@ -236,6 +239,182 @@ public class ElectricReportServiceImpl implements IElectricReportService { |
|
|
|
return result; |
|
|
|
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 |
|
|
|
* @param deptId |
|
|
|