|
|
@ -2,6 +2,7 @@ package com.hnac.hzims.scheduled.service.operation.home.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
|
|
|
import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity; |
|
|
|
import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity; |
|
|
@ -59,8 +60,11 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { |
|
|
|
@Value("${hzims.equipment.emInfo.emInfoList}") |
|
|
|
@Value("${hzims.equipment.emInfo.emInfoList}") |
|
|
|
public String device_cache_cofig_final; |
|
|
|
public String device_cache_cofig_final; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final static String recent_year_power_data = "hzims:operation:key:power:data"; |
|
|
|
|
|
|
|
|
|
|
|
private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("obtain-generation-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); |
|
|
|
private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("obtain-generation-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设备近3年发电量数据 : 按月分割 |
|
|
|
* 设备近3年发电量数据 : 按月分割 |
|
|
|
* @param param |
|
|
|
* @param param |
|
|
@ -131,8 +135,8 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { |
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(limits.size()); |
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(limits.size()); |
|
|
|
List<ThirtyGenerationEntity> saves = new CopyOnWriteArrayList<>(); |
|
|
|
List<ThirtyGenerationEntity> saves = new CopyOnWriteArrayList<>(); |
|
|
|
for(List<StationEntity> item : limits){ |
|
|
|
for(List<StationEntity> item : limits){ |
|
|
|
try{ |
|
|
|
pool.submit(()->{ |
|
|
|
pool.submit(()->{ |
|
|
|
try{ |
|
|
|
item.forEach(station->{ |
|
|
|
item.forEach(station->{ |
|
|
|
// 站点设备集合
|
|
|
|
// 站点设备集合
|
|
|
|
List<EminfoAndEmParamVo> eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); |
|
|
|
List<EminfoAndEmParamVo> eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); |
|
|
@ -175,10 +179,11 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { |
|
|
|
}); |
|
|
|
}); |
|
|
|
countDownLatch.countDown(); |
|
|
|
countDownLatch.countDown(); |
|
|
|
log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); |
|
|
|
log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); |
|
|
|
}); |
|
|
|
}catch (Exception e){ |
|
|
|
}catch (Exception e){ |
|
|
|
countDownLatch.countDown(); |
|
|
|
log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); |
|
|
|
log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
// 等待所有线程执行完成
|
|
|
|
// 等待所有线程执行完成
|
|
|
|
try { |
|
|
|
try { |
|
|
@ -216,9 +221,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { |
|
|
|
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); |
|
|
|
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); |
|
|
|
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); |
|
|
|
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); |
|
|
|
String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; |
|
|
|
String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; |
|
|
|
stations.forEach(station->{ |
|
|
|
stations.forEach(station-> this.threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end))); |
|
|
|
this.threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -306,6 +309,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { |
|
|
|
log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); |
|
|
|
log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}catch (Exception e){ |
|
|
|
}catch (Exception e){ |
|
|
|
|
|
|
|
countDownLatch.countDown(); |
|
|
|
log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); |
|
|
|
log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -378,6 +382,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { |
|
|
|
log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); |
|
|
|
log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}catch (Exception e){ |
|
|
|
}catch (Exception e){ |
|
|
|
|
|
|
|
countDownLatch.countDown(); |
|
|
|
log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); |
|
|
|
log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -437,4 +442,54 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { |
|
|
|
private static Integer countStep(Integer size) { |
|
|
|
private static Integer countStep(Integer size) { |
|
|
|
return (size + 3 - 1) / 3; |
|
|
|
return (size + 3 - 1) / 3; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 新版-近3年发电量 |
|
|
|
|
|
|
|
* @param param |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void loadThreeYearPowerGeneration(String param, List<Integer> types, Integer serveType,int year) { |
|
|
|
|
|
|
|
// 站点查询
|
|
|
|
|
|
|
|
List<StationEntity> stations = stationService.list(new LambdaQueryWrapper<StationEntity>() {{ |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(types)) { |
|
|
|
|
|
|
|
in(StationEntity::getType, types); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}}); |
|
|
|
|
|
|
|
// 开始时间
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
|
|
|
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); |
|
|
|
|
|
|
|
calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); |
|
|
|
|
|
|
|
String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); |
|
|
|
|
|
|
|
// 结束日期
|
|
|
|
|
|
|
|
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); |
|
|
|
|
|
|
|
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); |
|
|
|
|
|
|
|
String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ThreeGenerationEntity> generations = threeGenerateService.list(Wrappers.<ThreeGenerationEntity>lambdaQuery() |
|
|
|
|
|
|
|
.in(ThreeGenerationEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())) |
|
|
|
|
|
|
|
.ge(ThreeGenerationEntity::getStrMonth,start) |
|
|
|
|
|
|
|
.le(ThreeGenerationEntity::getStrMonth,end) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(generations)){ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Map<String,List<ThreeGenerationEntity>> map = generations.stream().collect(Collectors.groupingBy(ThreeGenerationEntity::getStationId)); |
|
|
|
|
|
|
|
// 定义接收参数
|
|
|
|
|
|
|
|
Map<Long, Map<String, Float>> container = new HashMap<>(); |
|
|
|
|
|
|
|
map.forEach((key, value) -> { |
|
|
|
|
|
|
|
Optional<StationEntity> optional = stations.stream().filter(o -> o.getCode().equals(key)).findFirst(); |
|
|
|
|
|
|
|
if (!optional.isPresent()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 根据月份分组
|
|
|
|
|
|
|
|
Map<String, List<ThreeGenerationEntity>> months = value.stream().collect(Collectors.groupingBy(ThreeGenerationEntity::getStrMonth)); |
|
|
|
|
|
|
|
// 接收月份发电量对象
|
|
|
|
|
|
|
|
Map<String, Float> son = new HashMap<>(); |
|
|
|
|
|
|
|
// 遍历月份数据
|
|
|
|
|
|
|
|
months.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(iter -> son.put(iter.getKey(), (float) iter.getValue().stream().mapToDouble(o -> o.getGenerate().doubleValue()).sum())); |
|
|
|
|
|
|
|
container.put(optional.get().getId(), son); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
redisTemplate.opsForValue().set(recent_year_power_data, container); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |