@ -127,7 +127,7 @@ public class RealTargetServiceImpl implements RealTargetService {
private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key" ;
// 创建线程池
private static final ExecutorService pool = new ThreadPoolExecutor ( 10 , 10 , 0L , TimeUnit . MILLISECONDS , new LinkedBlockingQueue < > ( 1024 ) , new ThreadFactoryBuilder ( ) . setNameFormat ( "load-power-data-pool-%d" ) . build ( ) , new ThreadPoolExecutor . CallerRunsPolicy ( ) ) ;
//private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("load-power-data-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy());
@Override
public void loadEmInfo ( String param ) {
@ -1250,9 +1250,8 @@ public class RealTargetServiceImpl implements RealTargetService {
// 将站点切割
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 * 3 ) . limit ( 3 ) . parallel ( ) . collect ( Collectors . toList ( ) ) ) . collect ( Collectors . toList ( ) ) ;
CountDownLatch countDownLatch = new CountDownLatch ( limits . size ( ) ) ;
for ( List < StationEntity > item : limits ) {
pool . submit ( ( ) - > {
try {
item . forEach ( station - > {
// 站点设备集合
List < EminfoAndEmParamVo > stationDevices = devices . stream ( ) . filter ( device - > device . getCreateDept ( ) . equals ( station . getRefDept ( ) ) ) . collect ( Collectors . toList ( ) ) ;
@ -1260,74 +1259,16 @@ public class RealTargetServiceImpl implements RealTargetService {
if ( MapUtils . isEmpty ( generateMap ) ) {
return ;
}
log . error ( "pool_item_execute_complete: {}" , JSONObject . toJSONString ( generateMap ) ) ;
powerMap . put ( station . getId ( ) , generateMap ) ;
} ) ;
countDownLatch . countDown ( ) ;
log . error ( "pool_item_execute_complete: {}" , item . stream ( ) . map ( StationEntity : : getName ) . collect ( Collectors . toList ( ) ) ) ;
} ) ;
}
//所有模板数据获取完成后释放锁
try {
countDownLatch . await ( ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
Thread . currentThread ( ) . interrupt ( ) ;
} catch ( Exception exception ) {
log . error ( "pool_item_execute_complete_error: {}" , exception . getMessage ( ) ) ;
}
}
redisTemplate . opsForValue ( ) . set ( recent_year_power_data , powerMap ) ;
}
@Override
public void loadPowerDataNew ( 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 ) ;
}
} } ) ;
// 设备信息
List < EminfoAndEmParamVo > devices = JSONObject . parseObject ( redisTemplate . opsForValue ( ) . get ( device_cache_cofig_final ) . toString ( ) , new TypeReference < List < EminfoAndEmParamVo > > ( ) {
} ) ;
// 开始时间
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 ) + " 00:00:00" ;
// 结束日期
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 ) + " 00:00:00" ;
// 存储数据map :<站点id,<月份,发电量>>
Map < Long , Map < String , Float > > powerMap = new CopyOnWriteMap < > ( ) ;
// 将站点切割
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 * 3 ) . limit ( 3 ) . parallel ( ) . collect ( Collectors . toList ( ) ) ) . collect ( Collectors . toList ( ) ) ;
CountDownLatch countDownLatch = new CountDownLatch ( limits . size ( ) ) ;
for ( List < StationEntity > item : limits ) {
pool . submit ( ( ) - > {
item . forEach ( station - > {
// 站点设备集合
List < EminfoAndEmParamVo > stationDevices = devices . stream ( ) . filter ( device - > device . getCreateDept ( ) . equals ( station . getRefDept ( ) ) ) . collect ( Collectors . toList ( ) ) ;
Map < String , Float > generateMap = this . lastReduceFirst ( station , stationDevices , start , end ) ;
if ( MapUtils . isEmpty ( generateMap ) ) {
return ;
}
powerMap . put ( station . getId ( ) , generateMap ) ;
} ) ;
countDownLatch . countDown ( ) ;
log . error ( "pool_item_execute_complete: {}" , item . stream ( ) . map ( StationEntity : : getName ) . collect ( Collectors . toList ( ) ) ) ;
} ) ;
}
//所有模板数据获取完成后释放锁
try {
countDownLatch . await ( ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
Thread . currentThread ( ) . interrupt ( ) ;
}
redisTemplate . opsForValue ( ) . set ( recent_year_power_data_test , JSONObject . toJSONString ( powerMap ) ) ;
}
private Map < String , Float > lastReduceFirst ( StationEntity station , List < EminfoAndEmParamVo > devices , String start , String end ) {
List < PowerMonthVo > datas = new ArrayList < > ( ) ;