From 4abd5e9c815cbbfccfe97fc0b2bca612b2b24991 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 24 Jul 2024 10:50:46 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=B0=B4=E4=BD=8D=E8=B0=83=E5=BA=A6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduled/RealTargetScheduledTask.java | 1 + .../home/impl/ObtainGenerationServiceImpl.java | 25 +++++++++++----------- .../operation/home/impl/RealTargetServiceImpl.java | 11 ++++++---- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java index 4e68cab..9591c87 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Arrays; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java index a6ff70d..0259de2 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java @@ -19,7 +19,6 @@ import com.hnac.hzims.scheduled.service.operation.home.ObtainGenerationService; import com.hnac.hzims.scheduled.service.operation.plate.DataService; import com.hnac.hzims.scheduled.service.operation.station.StationService; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; -import io.undertow.util.CopyOnWriteMap; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.CollectionUtil; @@ -65,6 +64,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { 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年发电量数据 : 按月分割 * @param param @@ -135,8 +135,8 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { CountDownLatch countDownLatch = new CountDownLatch(limits.size()); List saves = new CopyOnWriteArrayList<>(); for(List item : limits){ - try{ - pool.submit(()->{ + pool.submit(()->{ + try{ item.forEach(station->{ // 站点设备集合 List eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); @@ -179,10 +179,11 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { }); countDownLatch.countDown(); log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); - }); - }catch (Exception e){ - log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); - } + }catch (Exception e){ + countDownLatch.countDown(); + log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); + } + }); } // 等待所有线程执行完成 try { @@ -220,9 +221,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - stations.forEach(station->{ - this.threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end)); - }); + stations.forEach(station-> this.threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end))); } /** @@ -310,6 +309,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); }); }catch (Exception e){ + countDownLatch.countDown(); log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); } } @@ -382,6 +382,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); }); }catch (Exception e){ + countDownLatch.countDown(); log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); } } @@ -486,9 +487,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { // 接收月份发电量对象 Map 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()); - }); + 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); diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java index 67f90ce..52e5fd1 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -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(20, 20, 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) { @@ -573,19 +573,22 @@ public class RealTargetServiceImpl implements RealTargetService { waterLevelVo.setRearCurveMap(rearCurveMap); list.add(waterLevelVo); } + log.error("load_water_level : 线程执行完成 {}", item.getInstanceCode()); countDownLatch.countDown(); - }catch (Exception exception){ - log.error("load_water_level_error : {}",exception.getMessage()); + } catch (Exception exception) { + log.error("load_water_level_error : 线程执行失败 {}", exception.getMessage()); countDownLatch.countDown(); } }); } try { + log.error("load_water_level :等待线程执行"); countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); Thread.currentThread().interrupt(); } + log.error("load_water_level :线程执行完成"); redisTemplate.opsForValue().set(loadwater_level_key,list); } @@ -1132,7 +1135,7 @@ public class RealTargetServiceImpl implements RealTargetService { } /** - * 获取水位当年数据 + * 获取水位当日数据 * @param instanceCode * @param signage * @return