|
|
|
@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
|
|
|
|
import com.hnac.hzims.EquipmentConstants; |
|
|
|
|
import com.hnac.hzims.equipment.entity.EmParamEntity; |
|
|
|
|
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; |
|
|
|
|
import com.hnac.hzims.hzimsweather.feign.IHeWeatherWeatherClient; |
|
|
|
|
import com.hnac.hzims.hzimsweather.vo.RainFallCountByMonthVo; |
|
|
|
|
import com.hnac.hzims.operational.config.vo.StationRealVo; |
|
|
|
|
import com.hnac.hzims.operational.fill.entity.RainfallEntity; |
|
|
|
|
import com.hnac.hzims.operational.home.wind.RainMon; |
|
|
|
|
import com.hnac.hzims.operational.main.constant.HomePageConstant; |
|
|
|
@ -111,6 +113,9 @@ public class RealTargetServiceImpl implements RealTargetService {
|
|
|
|
|
@Value("${hzims.operation.realIdKey}") |
|
|
|
|
public String real_id_cofig_final; |
|
|
|
|
|
|
|
|
|
// 创建线程池
|
|
|
|
|
ExecutorService pool = new ThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("load-power-data-pool-%d").build(), new ThreadPoolExecutor.AbortPolicy()); |
|
|
|
|
|
|
|
|
|
private final static String recent_year_power_data = "hzims:operation:key:power:data"; |
|
|
|
|
private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; |
|
|
|
|
private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; |
|
|
|
@ -1220,11 +1225,9 @@ public class RealTargetServiceImpl implements RealTargetService {
|
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void loadPowerData(String param, List<Integer> types, Integer serveType, int year) { |
|
|
|
|
Long time=System.currentTimeMillis(); |
|
|
|
|
System.out.println("近年发电量接口耗时测试开始======================="); |
|
|
|
|
log.info("近年发电量接口耗时测试开始======================="); |
|
|
|
|
// 站点查询
|
|
|
|
|
List<StationEntity> stationList = stationService.list(new LambdaQueryWrapper<StationEntity>() {{ |
|
|
|
|
List<StationEntity> stations = stationService.list(new LambdaQueryWrapper<StationEntity>() {{ |
|
|
|
|
eq(StationEntity::getDataOrigin,HomePageConstant.DATA_ORIGIN); |
|
|
|
|
if (ObjectUtil.isNotEmpty(serveType)) { |
|
|
|
|
eq(StationEntity::getServeType, serveType); |
|
|
|
|
} |
|
|
|
@ -1245,22 +1248,35 @@ public class RealTargetServiceImpl implements RealTargetService {
|
|
|
|
|
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); |
|
|
|
|
String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; |
|
|
|
|
// 存储数据map :<站点id,<月份,发电量>>
|
|
|
|
|
Map<Long, Map<String, Float>> powerMap = new HashMap<>(); |
|
|
|
|
Long time2=System.currentTimeMillis(); |
|
|
|
|
log.info("近年发电量接口,数据组装"+(time2-time)); |
|
|
|
|
stationList.forEach(station -> { |
|
|
|
|
// 站点设备集合
|
|
|
|
|
List<EminfoAndEmParamVo> stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); |
|
|
|
|
log.error("load_power_data station :" + station.getCode() + "==== device :" + stationDevices ); |
|
|
|
|
Map<String, Float> generateMap = this.getGenerateYear(station,stationDevices,start,end); |
|
|
|
|
if(MapUtils.isEmpty(generateMap)){ |
|
|
|
|
return; |
|
|
|
|
Map<Long, Map<String, Float>> powerMap = new ConcurrentHashMap<>(); |
|
|
|
|
// 将站点切割
|
|
|
|
|
int limit = countStep(stations.size()); |
|
|
|
|
List<List<StationEntity>> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 5).limit(5).parallel().collect(Collectors.toList())).collect(Collectors.toList()); |
|
|
|
|
// 线程数量
|
|
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(limits.size()); |
|
|
|
|
pool.execute(()->{ |
|
|
|
|
for(List<StationEntity> item : limits){ |
|
|
|
|
item.forEach(station->{ |
|
|
|
|
// 站点设备集合
|
|
|
|
|
List<EminfoAndEmParamVo> stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); |
|
|
|
|
Map<String, Float> generateMap = this.getGenerateYear(station,stationDevices,start,end); |
|
|
|
|
if(MapUtils.isEmpty(generateMap)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
powerMap.put(station.getId(),generateMap); |
|
|
|
|
}); |
|
|
|
|
countDownLatch.countDown(); |
|
|
|
|
} |
|
|
|
|
powerMap.put(station.getId(),generateMap); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
// 等待所有线程执行完成
|
|
|
|
|
try { |
|
|
|
|
countDownLatch.await(); |
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
|
} |
|
|
|
|
pool.shutdown(); |
|
|
|
|
redisTemplate.opsForValue().set(recent_year_power_data, powerMap); |
|
|
|
|
Long time3=System.currentTimeMillis(); |
|
|
|
|
log.info("近年发电量数据接口,总耗时:"+(time3-time)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|