|
|
|
@ -24,6 +24,7 @@ import com.hnac.hzinfo.sdk.core.response.HzPage;
|
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.jsoup.helper.DataUtil; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
@ -309,12 +310,12 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
Random random = new Random(); |
|
|
|
|
while (start.getTime().compareTo(new Date()) <= 0){ |
|
|
|
|
PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); |
|
|
|
|
load.setHour(DateUtil.format(start.getTime(),"yyyy-mm-dd HH")); |
|
|
|
|
load.setHour(start.get(Calendar.HOUR_OF_DAY)); |
|
|
|
|
load.setActivePower(String.valueOf(random.nextDouble() * 500)); |
|
|
|
|
list.add(load); |
|
|
|
|
start.add(Calendar.HOUR_OF_DAY,1); |
|
|
|
|
} |
|
|
|
|
return list; |
|
|
|
|
return list.stream().sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList()); |
|
|
|
|
/*String start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; |
|
|
|
|
String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); |
|
|
|
|
List<AnalyseDataTaosVO> records = analyseDataService.periodTargetData(start, end, 1, 2, device.getEmCode(), HomePageConstant.PV_LOAD); |
|
|
|
@ -324,7 +325,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
return records.stream().map(record -> { |
|
|
|
|
PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); |
|
|
|
|
Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); |
|
|
|
|
load.setHour(DateUtil.format(time,"yyyy-mm-dd HH")); |
|
|
|
|
load.setHour(time.getHours()); |
|
|
|
|
load.setActivePower(Optional.ofNullable(record.getVal()).orElse("0")); |
|
|
|
|
return load; |
|
|
|
|
}).sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList());*/ |
|
|
|
@ -1053,46 +1054,83 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* App区域下属数据 |
|
|
|
|
* |
|
|
|
|
* APP集团/省子公司数据 |
|
|
|
|
* @param deptId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<PhotovoltaicSubordinateAppVo> app_subordinate(Long deptId) { |
|
|
|
|
// 获取区域或者站点map结构
|
|
|
|
|
Map<Dept, List<StationEntity>> map = areaService.areaOrStaion(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); |
|
|
|
|
if (MapUtils.isEmpty(map)) { |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
public PhotovoltaicSubordinateAppVo app_subordinate(Long deptId) { |
|
|
|
|
// 查询光伏站点
|
|
|
|
|
List<StationEntity> stations = stationService.getHomeStationList(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC), HomePageConstant.HYDROPOWER_SERVETYPE); |
|
|
|
|
if (CollectionUtil.isEmpty(stations)) { |
|
|
|
|
return new PhotovoltaicSubordinateAppVo(); |
|
|
|
|
} |
|
|
|
|
PhotovoltaicSubordinateAppVo subordinate = new PhotovoltaicSubordinateAppVo(); |
|
|
|
|
// 实时数据
|
|
|
|
|
List<PhotovoltaicRealVo> deviceReals = (List<PhotovoltaicRealVo>) redisTemplate.opsForValue().get(load_photovoltaic_real_key); |
|
|
|
|
// 指标数据
|
|
|
|
|
List<PhotovoltaicTargetVo> deviceTargets = (List<PhotovoltaicTargetVo>) redisTemplate.opsForValue().get(load_photovoltaic_target_key); |
|
|
|
|
// 遍历数据
|
|
|
|
|
List<PhotovoltaicSubordinateAppVo> subordinates = new ArrayList<>(); |
|
|
|
|
for (Map.Entry<Dept, List<StationEntity>> entry : map.entrySet()) { |
|
|
|
|
PhotovoltaicSubordinateAppVo subordinate = new PhotovoltaicSubordinateAppVo(); |
|
|
|
|
if (ObjectUtil.isEmpty(entry.getValue())) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
StationEntity station = entry.getValue().get(0); |
|
|
|
|
subordinate.setDeptId(entry.getKey().getId()); |
|
|
|
|
subordinate.setDeptName(entry.getKey().getDeptName()); |
|
|
|
|
subordinate.setSort(entry.getKey().getSort()); |
|
|
|
|
subordinate.setAddress(station.getAddress()); |
|
|
|
|
// 获取区域或者站点map结构
|
|
|
|
|
Map<Dept, List<StationEntity>> map = areaService.areaOrStaion(deptId, Collections.singletonList(HomePageConstant.PHOTOVOLTAIC)); |
|
|
|
|
// 集团/省子公司名称
|
|
|
|
|
this.subordinateDept(subordinate,deptId); |
|
|
|
|
// 区域数据
|
|
|
|
|
this.subordinateTargetData(subordinate, stations, deviceReals, deviceTargets); |
|
|
|
|
if(HomePageConstant.AREA > subordinate.getType()){ |
|
|
|
|
// 集团数据
|
|
|
|
|
this.targetArea(subordinate, map, deviceReals); |
|
|
|
|
}else{ |
|
|
|
|
// 获取实时天气
|
|
|
|
|
Map<String, HeWeatherWeatherNowResponse> nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); |
|
|
|
|
Map<String, HeWeatherWeatherNowResponse> nowWeather = this.weatherService.getNowWeather(Collections.singletonList(stations.get(0).getCode())); |
|
|
|
|
if (MapUtils.isNotEmpty(nowWeather)) { |
|
|
|
|
subordinate.setNow(nowWeather.get(station.getCode()).getNow()); |
|
|
|
|
subordinate.setNow(nowWeather.get(stations.get(0).getCode()).getNow()); |
|
|
|
|
} |
|
|
|
|
// 容量、实时功率、今日发电量
|
|
|
|
|
this.subordinateTargetData(subordinate, new ArrayList<>(entry.getValue()), deviceReals, deviceTargets); |
|
|
|
|
// 当月任务执行情况
|
|
|
|
|
this.subordinateTaskMon(subordinate, Collections.singletonList(entry.getKey().getId())); |
|
|
|
|
subordinates.add(subordinate); |
|
|
|
|
} |
|
|
|
|
return subordinates; |
|
|
|
|
// 当月任务执行情况
|
|
|
|
|
this.subordinateTaskMon(subordinate, map.keySet().stream().map(Dept::getId).collect(Collectors.toList())); |
|
|
|
|
return subordinate; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 区域数据 |
|
|
|
|
* @param subordinate |
|
|
|
|
* @param map |
|
|
|
|
* @param reals |
|
|
|
|
*/ |
|
|
|
|
private void targetArea(PhotovoltaicSubordinateAppVo subordinate, Map<Dept, List<StationEntity>> map, List<PhotovoltaicRealVo> reals) { |
|
|
|
|
if(MapUtils.isEmpty(map)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
subordinate.setLoads(map.entrySet().stream().map(entry -> { |
|
|
|
|
PhotovoltaicLoadVo load = new PhotovoltaicLoadVo(); |
|
|
|
|
load.setDeptId(entry.getKey().getId()); |
|
|
|
|
load.setName(entry.getKey().getDeptName()); |
|
|
|
|
load.setLoad(reals.stream().filter(real -> entry.getValue().stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(real.getDeptId())).mapToDouble(PhotovoltaicRealVo::getLoad).sum()); |
|
|
|
|
return load; |
|
|
|
|
}).collect(Collectors.toList())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置省子公司名称 |
|
|
|
|
* @param subordinate |
|
|
|
|
*/ |
|
|
|
|
private void subordinateDept(PhotovoltaicSubordinateAppVo subordinate,Long deptId) { |
|
|
|
|
R<List<Dept>> result = sysClient.getDeptByCurrentUser(); |
|
|
|
|
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Optional<Dept> optional; |
|
|
|
|
if(ObjectUtil.isNotEmpty(deptId)){ |
|
|
|
|
optional = result.getData().stream().filter(dept -> dept.getId().equals(deptId)).min(Comparator.comparing(Dept::getDeptCategory)); |
|
|
|
|
}else{ |
|
|
|
|
optional = result.getData().stream().min(Comparator.comparing(Dept::getDeptCategory)); |
|
|
|
|
} |
|
|
|
|
optional.ifPresent(dept -> { |
|
|
|
|
subordinate.setDeptId(dept.getId()); |
|
|
|
|
subordinate.setDeptName(dept.getDeptName()); |
|
|
|
|
subordinate.setType(dept.getDeptCategory()); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1101,17 +1139,15 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
* @param subordinate |
|
|
|
|
*/ |
|
|
|
|
private void subordinateTaskMon(PhotovoltaicSubordinateAppVo subordinate, List<Long> depts) { |
|
|
|
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); |
|
|
|
|
LocalDate firstDay = LocalDate.now().withDayOfMonth(1); |
|
|
|
|
LocalDateTime startTime = LocalDateTime.of(firstDay, LocalTime.MIN); |
|
|
|
|
LocalDateTime endTime = LocalDateTime.now(); |
|
|
|
|
String start = DateUtil.format(new Date(),"yyyy-MM") + "-01 00:00:00"; |
|
|
|
|
String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); |
|
|
|
|
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("storage-taget-pool-%d").build(); |
|
|
|
|
ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(POOL_QUANTITY, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); |
|
|
|
|
//监控线程执行完后返回结果
|
|
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(POOL_QUANTITY); |
|
|
|
|
// 日常维护
|
|
|
|
|
exe.execute(() -> { |
|
|
|
|
MaintainVo maintainVo = taskService.getMaintain(dtf.format(startTime), dtf.format(endTime), depts); |
|
|
|
|
MaintainVo maintainVo = taskService.getMaintain(start, end, depts); |
|
|
|
|
subordinate.setMaintenanceCount(maintainVo.getMaintain()); |
|
|
|
|
subordinate.setMaintenanceFinishCount(maintainVo.getMaintainFinish()); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
@ -1126,7 +1162,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
}); |
|
|
|
|
// 检修
|
|
|
|
|
exe.execute(() -> { |
|
|
|
|
OverhaulVo overhaulVo = taskService.getOverhaul(dtf.format(startTime), dtf.format(endTime), depts); |
|
|
|
|
OverhaulVo overhaulVo = taskService.getOverhaul(start, end, depts); |
|
|
|
|
int overhaul = overhaulVo.getOverhaul(); |
|
|
|
|
int overhaulFinish = overhaulVo.getOverhaulFinish(); |
|
|
|
|
subordinate.setOverhaulCount(overhaul); |
|
|
|
@ -1136,8 +1172,8 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
// 操作票&工作票
|
|
|
|
|
exe.execute(() -> { |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
map.put("startDate", dtf.format(startTime)); |
|
|
|
|
map.put("endDate", dtf.format(endTime)); |
|
|
|
|
map.put("startDate", start); |
|
|
|
|
map.put("endDate", end); |
|
|
|
|
map.put("deptList", depts); |
|
|
|
|
R<TicketMonthVO> R = ticketInfoClient.getOperateWorkStatistic(map); |
|
|
|
|
if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { |
|
|
|
@ -1152,6 +1188,14 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
subordinate.setWorkFinishCount(ticketMonthVO.getWorkQualify()); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
}); |
|
|
|
|
// 等待所有线程执行完成
|
|
|
|
|
try { |
|
|
|
|
countDownLatch.await(); |
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
|
} |
|
|
|
|
exe.shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1167,26 +1211,31 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
} |
|
|
|
|
List<PhotovoltaicRealVo> reals = deviceReals.stream().filter(o -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); |
|
|
|
|
List<PhotovoltaicTargetVo> targets = deviceTargets.stream().filter(o -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); |
|
|
|
|
if (CollectionUtil.isNotEmpty(reals)) { |
|
|
|
|
// 容量 、 实时功率
|
|
|
|
|
subordinate.setCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); |
|
|
|
|
subordinate.setLoad(reals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); |
|
|
|
|
subordinate.setStationLoads( |
|
|
|
|
if(CollectionUtil.isNotEmpty(stations) && HomePageConstant.AREA.equals(subordinate.getType())){ |
|
|
|
|
subordinate.setLoads( |
|
|
|
|
stations.stream().map(station -> { |
|
|
|
|
PhotovoltaicLoadVo load = new PhotovoltaicLoadVo(); |
|
|
|
|
load.setDeptId(station.getRefDept()); |
|
|
|
|
load.setCode(station.getCode()); |
|
|
|
|
load.setName(station.getName()); |
|
|
|
|
load.setLoad(reals.stream().filter(o -> o.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicRealVo::getLoad).sum()); |
|
|
|
|
if(CollectionUtil.isNotEmpty(reals)){ |
|
|
|
|
load.setLoad(reals.stream().filter(o -> o.getDeptId().equals(station.getRefDept())).mapToDouble(PhotovoltaicRealVo::getLoad).sum()); |
|
|
|
|
}else{ |
|
|
|
|
load.setLoad(0.0); |
|
|
|
|
} |
|
|
|
|
return load; |
|
|
|
|
}).sorted(Comparator.comparing(PhotovoltaicLoadVo::getLoad).reversed()).collect(Collectors.toList()) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (CollectionUtil.isNotEmpty(reals)) { |
|
|
|
|
// 容量 、 实时功率
|
|
|
|
|
subordinate.setCapacity(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); |
|
|
|
|
subordinate.setLoad(reals.stream().mapToDouble(PhotovoltaicRealVo::getLoad).sum()); |
|
|
|
|
} |
|
|
|
|
if (CollectionUtil.isNotEmpty(targets)) { |
|
|
|
|
// 今日发电量
|
|
|
|
|
subordinate.setGenerateDay(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationDay).sum()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1547,15 +1596,15 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
|
|
|
|
|
return load; |
|
|
|
|
}).sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList()) |
|
|
|
|
); |
|
|
|
|
// 发电量
|
|
|
|
|
photovoltaic.setGenerationPowerVoList( |
|
|
|
|
devices.stream().map(PhotovoltaicDeviceVo::getGenerationPowerVoList).filter(ObjectUtil::isNotEmpty).flatMap(Collection::stream).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { |
|
|
|
|
GenerationPowerVo generate = new GenerationPowerVo(); |
|
|
|
|
generate.setDate(entry.getKey()); |
|
|
|
|
generate.setGenerate((float) entry.getValue().stream().mapToDouble(o -> Double.valueOf(o.getGenerate())).sum()); |
|
|
|
|
return generate; |
|
|
|
|
}).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()) |
|
|
|
|
); |
|
|
|
|
// 发电量
|
|
|
|
|
photovoltaic.setGenerationPowerVoList( |
|
|
|
|
devices.stream().map(PhotovoltaicDeviceVo::getGenerationPowerVoList).filter(ObjectUtil::isNotEmpty).flatMap(Collection::stream).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { |
|
|
|
|
GenerationPowerVo generate = new GenerationPowerVo(); |
|
|
|
|
generate.setDate(entry.getKey()); |
|
|
|
|
generate.setGenerate((float) entry.getValue().stream().mapToDouble(o -> Double.valueOf(o.getGenerate())).sum()); |
|
|
|
|
return generate; |
|
|
|
|
}).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|