|
|
@@ -3,7 +3,10 @@ package com.hdkj.lt.si.service.simulation.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.hdkj.lt.base.constants.ErrorLogConstant;
|
|
|
import com.hdkj.lt.base.enums.EventTypeEnum;
|
|
|
import com.hdkj.lt.base.enums.OperationStepEnum;
|
|
|
@@ -16,14 +19,15 @@ import com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanPowerCutSwitch;
|
|
|
import com.hdkj.lt.core.bizms.modle.po.plan.PlanAwaitTransferAreaResultPO;
|
|
|
import com.hdkj.lt.core.log.exception.ExceptionErrorLogCast;
|
|
|
import com.hdkj.lt.core.log.model.param.ErrorLogParam;
|
|
|
-import com.hdkj.lt.modle.dto.simulation.ElectricalModelRequest;
|
|
|
-import com.hdkj.lt.modle.dto.simulation.ElectricalModelResponse;
|
|
|
-import com.hdkj.lt.modle.dto.simulation.FaultTransferSchemeDTO;
|
|
|
-import com.hdkj.lt.modle.dto.simulation.OperationSchemeDTO;
|
|
|
-import com.hdkj.lt.modle.dto.simulation.PlanTransferSchemeDTO;
|
|
|
+import com.hdkj.lt.core.rest.config.HttpClientConfig;
|
|
|
+import com.hdkj.lt.modle.dto.recon.RawResultDTO;
|
|
|
+import com.hdkj.lt.modle.dto.simulation.*;
|
|
|
+import com.hdkj.lt.modle.po.FhzgReconResult;
|
|
|
import com.hdkj.lt.si.dao.*;
|
|
|
+import com.hdkj.lt.si.service.recon.ReconResultService;
|
|
|
import com.hdkj.lt.si.service.simulation.ISimulationService;
|
|
|
import com.hdkj.lt.si.service.simulation.TyptResponseEntity;
|
|
|
+import com.hdkj.hussar.ApiResponse;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -36,7 +40,10 @@ import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* @author rj
|
|
|
@@ -54,15 +61,28 @@ public class SimulationServiceImpl implements ISimulationService {
|
|
|
private final PlanAwaitTransferAreaResultMapper planAwaitTransferAreaResultMapper;
|
|
|
private final FaultAwaitTransferAreaResultMapper faultAwaitTransferAreaResultMapper;
|
|
|
private final FhzgOperationAbnormalityTransferAreaResultMapper operationAbnormalityTransferAreaResultMapper;
|
|
|
+ private final FhzgReconResultMapper fhzgReconResultMapper;
|
|
|
+ private final ReconResultService reconResultService;
|
|
|
private final String BASE_URL = "http://25.91.83.252:28081";
|
|
|
|
|
|
+ private static final ObjectMapper OM = new ObjectMapper();
|
|
|
+
|
|
|
@Value("${simulation.xToken}")
|
|
|
private String xToken;
|
|
|
|
|
|
+ @Value("${remote.recon.request-uri}")
|
|
|
+ private String reconRequestUri;
|
|
|
+
|
|
|
+ @Value("${remote.recon.recon-uri}")
|
|
|
+ private String reconUri;
|
|
|
+
|
|
|
@Autowired
|
|
|
@Qualifier("simpleRestTemplate")
|
|
|
private RestTemplate simpleRestTemplate;
|
|
|
|
|
|
+ @Resource(name = HttpClientConfig.CONN_POOL_REST_TEMPLATE)
|
|
|
+ private RestTemplate connPoolRestTemplate;
|
|
|
+
|
|
|
@Override
|
|
|
public String getPlanTransferScheme(PlanTransferSchemeDTO planTransferSchemeDTO) {
|
|
|
String url = BASE_URL + "/api/power/power-transfer/plan-analysis";
|
|
|
@@ -251,4 +271,70 @@ public class SimulationServiceImpl implements ISimulationService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ApiResponse<String> startOperationCalTask(OperationModeStartDTO dto) {
|
|
|
+ // 1. 生成任务ID
|
|
|
+ String taskId = UUID.randomUUID().toString();
|
|
|
+ log.info("启动重构计算, taskId: {}, request: {}", taskId, JSON.toJSONString(dto));
|
|
|
+
|
|
|
+ // 2. 调用远程重构接口
|
|
|
+ String requestUrl = reconRequestUri.concat(reconUri);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity<>(JSON.toJSONString(dto), headers);
|
|
|
+ String responseStr;
|
|
|
+ try {
|
|
|
+ responseStr = connPoolRestTemplate.postForObject(requestUrl, httpEntity, String.class);
|
|
|
+ log.info("重构计算接口返回, taskId: {}, response: {}", taskId, responseStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用重构算法接口失败, taskId: {}", taskId, e);
|
|
|
+ return ApiResponse.fail("调用重构算法接口失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 提取 raw_result 节点并入库
|
|
|
+ try {
|
|
|
+ JsonNode root = OM.readTree(responseStr);
|
|
|
+ JsonNode rawNode = root.get("raw_result");
|
|
|
+ if (rawNode == null || rawNode.isNull()) {
|
|
|
+ log.error("算法响应缺少 raw_result 节点, taskId: {}", taskId);
|
|
|
+ return ApiResponse.fail("算法响应缺少 raw_result 节点");
|
|
|
+ }
|
|
|
+ String rawResultJson = OM.writeValueAsString(rawNode);
|
|
|
+ reconResultService.parseAndSaveReconResult(rawResultJson, taskId);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("解析算法响应失败, taskId: {}", taskId, e);
|
|
|
+ return ApiResponse.fail("解析算法响应失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return ApiResponse.success(taskId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse<QueryOperationModeDTO> queryOperationResult(String taskId) {
|
|
|
+ log.info("查询重构结果, taskId: {}", taskId);
|
|
|
+
|
|
|
+ // 查询主表
|
|
|
+ FhzgReconResult reconResult = fhzgReconResultMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<FhzgReconResult>().eq(FhzgReconResult::getEventId, taskId));
|
|
|
+ if (reconResult == null) {
|
|
|
+ return ApiResponse.fail("任务不存在或未完成: " + taskId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 反序列化 rawResult JSON -> RawResultDTO
|
|
|
+ RawResultDTO rawResultDTO = null;
|
|
|
+ String rawResultJson = reconResult.getRawResult();
|
|
|
+ if (rawResultJson != null && !rawResultJson.isEmpty()) {
|
|
|
+ try {
|
|
|
+ rawResultDTO = OM.readValue(rawResultJson, RawResultDTO.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("反序列化 rawResult 失败, taskId: {}", taskId, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryOperationModeDTO resultDTO = new QueryOperationModeDTO();
|
|
|
+ resultDTO.setId(taskId);
|
|
|
+ resultDTO.setResult(rawResultDTO);
|
|
|
+ return ApiResponse.success(resultDTO);
|
|
|
+ }
|
|
|
+
|
|
|
}
|