Ver Fonte

修改包

lisonglin há 2 semanas atrás
pai
commit
4722a0095c

+ 0 - 24
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/adapter/SiReconClient.java

@@ -1,24 +0,0 @@
-package com.hdkj.lt.bf.adapter;
-
-import com.hdkj.hussar.ApiResponse;
-import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-
-import java.util.Map;
-
-/**
- * Feign 客户端:远程调用 SI 模块的重构结果入库接口
- * <p>
- * 同事端点 POST /recon/trigger 接收 {eventId, params}
- * 其中 params 包含 feeder_id + point_time,同事自行组装 county/拓扑等信息。
- *
- * @author lsl
- * @since 2026-07-26
- */
-@FeignClient(value = "load-transfer-si", contextId = "SiReconClient")
-public interface SiReconClient {
-
-    @PostMapping("/recon/trigger")
-    ApiResponse<Map> triggerRecon(@RequestBody Map<String, Object> request);
-}

+ 2 - 1
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/adapter/SiStateEstimationClient.java

@@ -2,6 +2,7 @@ package com.hdkj.lt.bf.adapter;
 
 import com.hdkj.fhzg.optimization.request.MaintOrgRequest;
 import com.hdkj.hussar.ApiResponse;
+import com.hdkj.lt.base.constants.SystemGlobalConstant;
 import com.hdkj.lt.core.bizms.modle.dto.StateEstimation;
 import com.hdkj.lt.core.bizms.modle.request.StateEstimationEquipRequest;
 import com.hdkj.lt.core.bizms.modle.request.StateEstimationRequest;
@@ -15,7 +16,7 @@ import java.util.List;
 /**
  * 服务调用si状估集成接口
  */
-@FeignClient(value = "load-transfer-si", contextId = "SiStateEstimationClient")
+@FeignClient(value = SystemGlobalConstant.SERVICE_NAME_LOAD_TRANSFER_SI, contextId = "SiStateEstimationClient")
 public interface SiStateEstimationClient {
 
     @ApiOperation(value = "分时段查询中压线路下设备节点状估数据")

+ 0 - 15
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/config/BfScheduleConfig.java

@@ -1,15 +0,0 @@
-package com.hdkj.lt.bf.config;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.EnableScheduling;
-
-/**
- * 启用 @Scheduled 支持,用于状估断面定时拉取等任务。
- *
- * @author lsl
- * @since 2026-07-26
- */
-@Configuration
-@EnableScheduling
-public class BfScheduleConfig {
-}

+ 28 - 43
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/listener/ReconTriggerListener.java

@@ -1,12 +1,13 @@
 package com.hdkj.lt.bf.listener;
 
-import com.hdkj.hussar.ApiResponse;
-import com.hdkj.lt.bf.adapter.SiReconClient;
+import com.alibaba.fastjson.JSONObject;
 import com.hdkj.lt.bf.entity.FhzgSeCurrentEvent;
 import com.hdkj.lt.bf.entity.FhzgSeVoltageEvent;
 import com.hdkj.lt.bf.event.ReconTriggerEvent;
 import com.hdkj.lt.bf.mapper.FhzgSeCurrentEventMapper;
 import com.hdkj.lt.bf.mapper.FhzgSeVoltageEventMapper;
+import com.hdkj.lt.feign.IReconApiClient;
+import com.hdkj.lt.modle.vo.recon.ReconstructionParam;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.event.EventListener;
@@ -21,7 +22,7 @@ import java.util.Map;
  * 重构算法触发监听器
  * <p>
  * 当线路重过载/电压越限告警持续1小时触发时,异步调用同事编写的重构接口。
- * 通过 Feign 客户端 SiReconClient 调用 SI 模块的 POST /recon/trigger。
+ * 通过 Feign 客户端 IReconApiClient 调用 SI 模块的 POST /recon/trigger。
  * <p>
  * 调用过程中同步更新告警事件的 reconStatus:
  * <ul>
@@ -39,48 +40,38 @@ import java.util.Map;
 @RequiredArgsConstructor
 public class ReconTriggerListener {
 
-    private final SiReconClient siReconClient;
+    private final IReconApiClient reconApiClient;
     private final FhzgSeCurrentEventMapper currentEventMapper;
     private final FhzgSeVoltageEventMapper voltageEventMapper;
 
     private static final DateTimeFormatter DT_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
-    /** 重构状态常量 */
-    private static final int RECON_PENDING   = 0;  // 未触发
-    private static final int RECON_RUNNING   = 1;  // 生成中
-    private static final int RECON_COMPLETED = 2;  // 有方案
-    private static final int RECON_NO_PLAN   = 3;  // 无方案
-    private static final int RECON_FAILED    = -1; // 调用失败
+    private static final int RECON_RUNNING   = 1;
+    private static final int RECON_COMPLETED = 2;
+    private static final int RECON_NO_PLAN   = 3;
+    private static final int RECON_FAILED    = -1;
 
-    /**
-     * 异步监听:告警持续1h → 触发重构算法
-     */
     @Async
     @EventListener
     public void onReconTrigger(ReconTriggerEvent event) {
-        // 1. 标记为"生成中"
         updateReconStatus(event.getEventId(), event.getAlarmType(), RECON_RUNNING);
 
-        // 2. 构造请求参数
         Map<String, Object> params = new HashMap<>();
         params.put("feeder_id", event.getFeederId());
         params.put("point_time", event.getPointTime() != null
                 ? event.getPointTime().format(DT_FMT) : null);
 
-        Map<String, Object> request = new HashMap<>();
-        request.put("eventId", String.valueOf(event.getEventId()));
-        request.put("params", params);
+        ReconstructionParam param = new ReconstructionParam();
+        param.setEventId(String.valueOf(event.getEventId()));
+        param.setParams(params);
 
-        log.info("重构触发: eventId={}, feederId={}, alarmType={}, pointTime={}, request={}",
-                event.getEventId(), event.getFeederId(), event.getAlarmType(),
-                event.getPointTime(), request);
+        log.info("重构触发: eventId={}, feederId={}, alarmType={}, pointTime={}",
+                event.getEventId(), event.getFeederId(), event.getAlarmType(), event.getPointTime());
 
-        // 3. Feign 调用同事接口
         try {
-            ApiResponse<Map> resp = siReconClient.triggerRecon(request);
+            String resp = reconApiClient.triggerReconfiguration(param);
             log.info("重构接口调用成功: eventId={}, response={}", event.getEventId(), resp);
 
-            // 4. 解析响应判断是否有方案
             int status = parseReconResponse(resp);
             updateReconStatus(event.getEventId(), event.getAlarmType(), status);
         } catch (Exception e) {
@@ -90,32 +81,26 @@ public class ReconTriggerListener {
         }
     }
 
-    /**
-     * 解析同事重构接口响应,判断是否有方案
-     */
-    private int parseReconResponse(ApiResponse<Map> resp) {
-        if (resp == null || !resp.isSuccess()) {
-            return RECON_FAILED;
-        }
-        Map data = resp.getData();
-        if (data != null) {
-            Object success = data.get("success");
-            if (Boolean.TRUE.equals(success)) {
-                return RECON_COMPLETED;
-            } else if (Boolean.FALSE.equals(success)) {
-                return RECON_NO_PLAN;
+    private int parseReconResponse(String response) {
+        if (response == null || response.isEmpty()) return RECON_FAILED;
+        try {
+            JSONObject root = com.alibaba.fastjson.JSON.parseObject(response);
+            String status = root.getString("status");
+            if ("200".equals(status) || "success".equalsIgnoreCase(status)) {
+                Object data = root.get("data");
+                if (data instanceof JSONObject) {
+                    Boolean success = ((JSONObject) data).getBoolean("success");
+                    return Boolean.TRUE.equals(success) ? RECON_COMPLETED : RECON_NO_PLAN;
+                }
             }
+        } catch (Exception e) {
+            log.warn("解析重构接口响应失败: {}", e.getMessage());
         }
-        // 调通了但没有明确的 success 标记,保守返回"有方案"
         return RECON_COMPLETED;
     }
 
-    /**
-     * 根据 alarmType 前缀更新对应告警事件的 reconStatus
-     */
     private void updateReconStatus(Long eventId, String alarmType, int reconStatus) {
         if (eventId == null) return;
-
         try {
             if (alarmType != null && alarmType.startsWith("current_")) {
                 FhzgSeCurrentEvent update = new FhzgSeCurrentEvent();

+ 7 - 28
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/schedule/SeSnapshotScheduler.java → services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/scheduler/SeSnapshotScheduler.java

@@ -1,4 +1,4 @@
-package com.hdkj.lt.bf.schedule;
+package com.hdkj.lt.bf.scheduler;
 
 import com.alibaba.fastjson.JSON;
 import com.hdkj.fhzg.optimization.request.MaintOrgRequest;
@@ -49,7 +49,6 @@ public class SeSnapshotScheduler {
             futures.add(CompletableFuture.runAsync(() ->
                     pullByCounty(maintOrg, countySid, countyName)));
         }
-        // 等待所有县城拉取完成
         CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
     }
 
@@ -66,11 +65,9 @@ public class SeSnapshotScheduler {
                 return;
             }
 
-            // 将 List<StateEstimation> 聚合成单个 StateEstimation
             StateEstimation merged = mergeCountyResults(resp.getData());
             if (merged == null) return;
 
-            // 序列化 JSON 并喂给解析方法
             String json = JSON.toJSONString(merged);
             seSnapshotService.processSnapshot(json);
 
@@ -80,12 +77,6 @@ public class SeSnapshotScheduler {
         }
     }
 
-    /**
-     * 聚合 List<StateEstimation> → 单个 StateEstimation
-     * <p>
-     * queryEquipByCounty 返回每条馈线一个 StateEstimation 对象,
-     * 需要把 feeder/mvtrans/switch 等列表合并到一起。
-     */
     private StateEstimation mergeCountyResults(List<StateEstimation> list) {
         if (list == null || list.isEmpty()) return null;
 
@@ -99,24 +90,12 @@ public class SeSnapshotScheduler {
 
         for (StateEstimation se : list) {
             if (se == null) continue;
-            if (pointTime == null && se.getPointTime() != null) {
-                pointTime = se.getPointTime();
-            }
-            if (se.getPeriodFeederSeResult() != null) {
-                allFeeders.addAll(se.getPeriodFeederSeResult());
-            }
-            if (se.getPeriodMVTransSeResult() != null) {
-                allMvtrans.addAll(se.getPeriodMVTransSeResult());
-            }
-            if (se.getPeriodSwitchSeResult() != null) {
-                allSwitches.addAll(se.getPeriodSwitchSeResult());
-            }
-            if (se.getPeriodEquipResult() != null) {
-                allEquips.addAll(se.getPeriodEquipResult());
-            }
-            if (se.getPeriodSegmentSeResult() != null) {
-                allSegments.addAll(se.getPeriodSegmentSeResult());
-            }
+            if (pointTime == null && se.getPointTime() != null) pointTime = se.getPointTime();
+            if (se.getPeriodFeederSeResult() != null) allFeeders.addAll(se.getPeriodFeederSeResult());
+            if (se.getPeriodMVTransSeResult() != null) allMvtrans.addAll(se.getPeriodMVTransSeResult());
+            if (se.getPeriodSwitchSeResult() != null) allSwitches.addAll(se.getPeriodSwitchSeResult());
+            if (se.getPeriodEquipResult() != null) allEquips.addAll(se.getPeriodEquipResult());
+            if (se.getPeriodSegmentSeResult() != null) allSegments.addAll(se.getPeriodSegmentSeResult());
         }
 
         if (allFeeders.isEmpty() && allMvtrans.isEmpty()) {