瀏覽代碼

方案重构参数重构

liuaini 2 周之前
父節點
當前提交
14166e93a4

+ 2 - 3
api/load-transfer-si-api/src/main/java/com/hdkj/lt/modle/vo/recon/ReconstructionParam.java

@@ -19,9 +19,8 @@ public class ReconstructionParam {
 //    private List<String> feederIds;
 
 //    {
-//        "county_sid":"",
-//        "county_name":"",
-//        "problem_feeder_ids":[]
+//        "feeder_id":"",
+//        "point_time":"",
 //    }
     Map<String, Object> params = new HashMap<>();
 }

+ 39 - 0
services/load-transfer-si/src/main/java/com/hdkj/lt/si/config/SeConfig.java

@@ -0,0 +1,39 @@
+package com.hdkj.lt.si.config;
+
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * 状估模块 Bean 配置: RestTemplate (带超时) + 有界线程池.
+ */
+@Configuration
+public class SeConfig {
+
+    /**
+     * 状估查询专用线程池 (有界). 跨所有请求共享, 大小 = poolSize,
+     * 即并发调用远程接口的全局上限. 守护线程, 应用关闭时 shutdown.
+     */
+    @Bean(name = "seQueryExecutor", destroyMethod = "shutdown")
+    public ExecutorService seQueryExecutor() {
+        ThreadFactory factory = new ThreadFactory() {
+            private final AtomicInteger counter = new AtomicInteger(0);
+
+            @Override
+            public Thread newThread(Runnable r) {
+                Thread t = new Thread(r, "se-query-" + counter.incrementAndGet());
+//                t.setDaemon(true);
+                return t;
+            }
+        };
+        return new ThreadPoolExecutor(
+                8,8,0L, TimeUnit.MILLISECONDS,
+                new ArrayBlockingQueue<>(200),factory,new ThreadPoolExecutor.AbortPolicy()
+        );
+    }
+}

+ 6 - 8
services/load-transfer-si/src/main/java/com/hdkj/lt/si/service/estimation/impl/StateEstimationServiceImpl.java

@@ -40,10 +40,7 @@ import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
 import java.util.*;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -189,7 +186,7 @@ public class StateEstimationServiceImpl implements StateEstimationService {
             List<String> pointTime = Lists.newArrayList();
             for (CompletableFuture<StateEstimation> f : futures) {
                 // 任一批失败 -> 抛 CompletionException -> 整体失败
-                StateEstimation part = f.join();
+                StateEstimation part = f.get(15,TimeUnit.SECONDS);
                 if (pointTime.isEmpty()) {
                     pointTime = part.getPointTime();
                 }
@@ -200,11 +197,12 @@ public class StateEstimationServiceImpl implements StateEstimationService {
             return mergedList;
         } catch (CompletionException e) {
             // 取消尚未完成的批次, 减少无效远程调用
-            for (CompletableFuture<?> f : futures) {
-                f.cancel(true);
-            }
+            futures.forEach(f -> f.cancel(true));
             log.error("[SE] 查询状估失败: {}", e.getMessage(), e);
             ExceptionCast.cast("调用状估接口失败");
+        } catch (ExecutionException | InterruptedException | TimeoutException e) {
+            futures.forEach(f -> f.cancel(true));
+            ExceptionCast.cast("调用状估接口失败");
         }
         return mergedList;
     }