|
|
|
@ -2,25 +2,37 @@ package com.hnac.hzims.electric.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.common.logs.utils.StringUtils; |
|
|
|
|
import com.hnac.hzims.electric.entity.ThirtyEntity; |
|
|
|
|
import com.hnac.hzims.electric.entity.ThreeEntity; |
|
|
|
|
import com.hnac.hzims.electric.service.IElectricReportService; |
|
|
|
|
import com.hnac.hzims.electric.service.ThirtyService; |
|
|
|
|
import com.hnac.hzims.electric.service.ThreeService; |
|
|
|
|
import com.hnac.hzims.electric.vo.DeviceElectricVo; |
|
|
|
|
import com.hnac.hzims.electric.vo.TableHeadVo; |
|
|
|
|
import com.hnac.hzims.equipment.entity.EmInfoEntity; |
|
|
|
|
import com.hnac.hzims.equipment.service.IEmInfoService; |
|
|
|
|
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 com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springblade.system.entity.Dept; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -36,10 +48,14 @@ public class ElectricReportServiceImpl implements IElectricReportService {
|
|
|
|
|
|
|
|
|
|
private final ThirtyService thirtyService; |
|
|
|
|
|
|
|
|
|
private final IEmInfoService deviceService; |
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
private final IStationClient stationClient; |
|
|
|
|
|
|
|
|
|
private final IAnalyseDataSearchClient analyseDataSearchClient; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 基础报表 |
|
|
|
|
* @param deptId |
|
|
|
@ -433,7 +449,65 @@ public class ElectricReportServiceImpl implements IElectricReportService {
|
|
|
|
|
Map<String,Object> result = new HashMap<>(); |
|
|
|
|
// 日
|
|
|
|
|
if (type == 0) { |
|
|
|
|
// 站点设备集合
|
|
|
|
|
List<EmInfoEntity> devices = deviceService.list(Wrappers.<EmInfoEntity>lambdaQuery() |
|
|
|
|
.eq(EmInfoEntity::getCreateDept,station.getData().getRefDept()) |
|
|
|
|
.eq(EmInfoEntity::getEmType,2) |
|
|
|
|
.eq(EmInfoEntity::getHomePageDisplay,1) |
|
|
|
|
); |
|
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
|
return new HashMap<>(); |
|
|
|
|
} |
|
|
|
|
Date date = DateUtil.parse(time,DateUtil.PATTERN_DATE); |
|
|
|
|
// 根据设备查询当日有功/无功电量
|
|
|
|
|
List<DeviceElectricVo> electrics = this.deviceElectrics(devices,date); |
|
|
|
|
|
|
|
|
|
// 表头
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
// 根据设备分组
|
|
|
|
|
devices.forEach(device->{ |
|
|
|
|
TableHeadVo tableHead = new TableHeadVo(); |
|
|
|
|
tableHead.setTableName(device.getName() + "发电量(kWh)"); |
|
|
|
|
tableHead.setIsChildren(true); |
|
|
|
|
tableHead.setChildren(Arrays.asList("时有功","时无功")); |
|
|
|
|
tableHeads.add(tableHead); |
|
|
|
|
}); |
|
|
|
|
result.put("tableHead",tableHeads); |
|
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTime(date); |
|
|
|
|
Date end = calendar.getTime(); |
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); |
|
|
|
|
Date start = calendar.getTime(); |
|
|
|
|
List<List<Object>> tableDate = new ArrayList<>(); |
|
|
|
|
while (start.compareTo(end) < 0){ |
|
|
|
|
List<Object> item = new ArrayList<>(); |
|
|
|
|
String hours = DateUtil.format(start,"yyyy-MM-dd HH"); |
|
|
|
|
item.add(start.getMonth() + 1 + "月"); |
|
|
|
|
// 总计:有功、无功
|
|
|
|
|
item.add(electrics.stream().filter(electric -> electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum()); |
|
|
|
|
item.add(electrics.stream().filter(electric -> electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum()); |
|
|
|
|
|
|
|
|
|
// 遍历机组
|
|
|
|
|
devices.stream().sorted(Comparator.comparing(EmInfoEntity::getEmIndex)).forEach(device->{ |
|
|
|
|
item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getNumber()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getGenerate).sum()); |
|
|
|
|
item.add(electrics.stream().filter(electric -> electric.getDeviceCode().equals(device.getNumber()) && electric.getStrTime().contains(hours)).mapToDouble(DeviceElectricVo::getReactiveGenerate).sum()); |
|
|
|
|
}); |
|
|
|
|
calendar.add(Calendar.DAY_OF_MONTH,1); |
|
|
|
|
start = calendar.getTime(); |
|
|
|
|
tableDate.add(item); |
|
|
|
|
} |
|
|
|
|
result.put("tableDate",tableDate); |
|
|
|
|
} |
|
|
|
|
// 月
|
|
|
|
|
else if (type == 1) { |
|
|
|
@ -561,4 +635,80 @@ public class ElectricReportServiceImpl implements IElectricReportService {
|
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询设备当日有功/无功电量 |
|
|
|
|
* @param devices |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<DeviceElectricVo> deviceElectrics(List<EmInfoEntity> devices,Date date) { |
|
|
|
|
List<DeviceElectricVo> electrics = new ArrayList<>(); |
|
|
|
|
devices.forEach(device->{ |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTime(date); |
|
|
|
|
Date endTime = calendar.getTime(); |
|
|
|
|
LocalDateTime end = LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(endTime,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)); |
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); |
|
|
|
|
Date startTime = calendar.getTime(); |
|
|
|
|
LocalDateTime start = LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(startTime,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)); |
|
|
|
|
AnalyseCodeByAnalyseDataPO param = new AnalyseCodeByAnalyseDataPO(); |
|
|
|
|
param.setDeviceCode(device.getNumber()); |
|
|
|
|
List<AnalyzeDataConditionPO> conditions = new ArrayList<>(); |
|
|
|
|
// 有功电量
|
|
|
|
|
AnalyzeDataConditionPO generate = new AnalyzeDataConditionPO(); |
|
|
|
|
generate.setFull(1); |
|
|
|
|
generate.setKeepFigures(2); |
|
|
|
|
generate.setAccessRules(6); |
|
|
|
|
generate.setSaveTimeType(2); |
|
|
|
|
generate.setSignages("generation_capacity"); |
|
|
|
|
generate.setTimeInterval(1); |
|
|
|
|
generate.setBeginTime(start); |
|
|
|
|
generate.setEndTime(end); |
|
|
|
|
conditions.add(generate); |
|
|
|
|
// 无功电量
|
|
|
|
|
AnalyzeDataConditionPO reactive = new AnalyzeDataConditionPO(); |
|
|
|
|
reactive.setFull(1); |
|
|
|
|
reactive.setKeepFigures(2); |
|
|
|
|
reactive.setAccessRules(6); |
|
|
|
|
reactive.setSaveTimeType(2); |
|
|
|
|
reactive.setSignages("reactive_generation"); |
|
|
|
|
reactive.setTimeInterval(1); |
|
|
|
|
reactive.setBeginTime(start); |
|
|
|
|
reactive.setEndTime(end);conditions.add(reactive); |
|
|
|
|
param.setSignboardConditions(conditions); |
|
|
|
|
R<List<AnalyzeDataConditionVO>> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(param); |
|
|
|
|
if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
while (startTime.compareTo(endTime) < 0){ |
|
|
|
|
DeviceElectricVo electric = new DeviceElectricVo(); |
|
|
|
|
electric.setStrTime(DateUtil.format(startTime,"yyyy-MM-dd HH")); |
|
|
|
|
electric.setTime(startTime.getHours()); |
|
|
|
|
if(ObjectUtil.isEmpty(result.getData().get(0)) || CollectionUtil.isEmpty(result.getData().get(0).getList())){ |
|
|
|
|
electric.setGenerate(result.getData().get(0).getList().stream().filter(o->o.getTs().contains(electric.getStrTime())).mapToDouble(val->{ |
|
|
|
|
if(StringUtils.isEmpty(val.getVal())){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
return Double.parseDouble(val.getVal()); |
|
|
|
|
}).sum()); |
|
|
|
|
}else{ |
|
|
|
|
electric.setGenerate(0.0); |
|
|
|
|
} |
|
|
|
|
if(ObjectUtil.isEmpty(result.getData().get(1)) || CollectionUtil.isEmpty(result.getData().get(1).getList())){ |
|
|
|
|
electric.setReactiveGenerate(result.getData().get(1).getList().stream().filter(o->o.getTs().contains(electric.getStrTime())).mapToDouble(val->{ |
|
|
|
|
if(StringUtils.isEmpty(val.getVal())){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
return Double.parseDouble(val.getVal()); |
|
|
|
|
}).sum()); |
|
|
|
|
}else{ |
|
|
|
|
electric.setReactiveGenerate(0.0); |
|
|
|
|
} |
|
|
|
|
electrics.add(electric); |
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY,+1); |
|
|
|
|
startTime = calendar.getTime(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return electrics; |
|
|
|
|
} |
|
|
|
|
} |