|
@@ -7,10 +7,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.hdkj.hussar.ApiResponse;
|
|
|
import com.hdkj.lt.base.constants.ErrorLogConstant;
|
|
import com.hdkj.lt.base.constants.ErrorLogConstant;
|
|
|
import com.hdkj.lt.base.enums.EventTypeEnum;
|
|
import com.hdkj.lt.base.enums.EventTypeEnum;
|
|
|
import com.hdkj.lt.base.enums.OperationStepEnum;
|
|
import com.hdkj.lt.base.enums.OperationStepEnum;
|
|
|
import com.hdkj.lt.base.exception.ExceptionCast;
|
|
import com.hdkj.lt.base.exception.ExceptionCast;
|
|
|
|
|
+import com.hdkj.lt.bf.entity.FhzgReconSimulationTask;
|
|
|
|
|
+import com.hdkj.lt.bf.service.FhzgReconSimulationTaskService;
|
|
|
import com.hdkj.lt.core.bizms.modle.po.fault.FaultAwaitTransferAreaResult;
|
|
import com.hdkj.lt.core.bizms.modle.po.fault.FaultAwaitTransferAreaResult;
|
|
|
import com.hdkj.lt.core.bizms.modle.po.fault.FaultPowerCut;
|
|
import com.hdkj.lt.core.bizms.modle.po.fault.FaultPowerCut;
|
|
|
import com.hdkj.lt.core.bizms.modle.po.operationAbnormality.FhzgOperationAbnormalityTransferAreaResult;
|
|
import com.hdkj.lt.core.bizms.modle.po.operationAbnormality.FhzgOperationAbnormalityTransferAreaResult;
|
|
@@ -20,14 +23,11 @@ import com.hdkj.lt.core.bizms.modle.po.plan.PlanAwaitTransferAreaResultPO;
|
|
|
import com.hdkj.lt.core.log.exception.ExceptionErrorLogCast;
|
|
import com.hdkj.lt.core.log.exception.ExceptionErrorLogCast;
|
|
|
import com.hdkj.lt.core.log.model.param.ErrorLogParam;
|
|
import com.hdkj.lt.core.log.model.param.ErrorLogParam;
|
|
|
import com.hdkj.lt.core.rest.config.HttpClientConfig;
|
|
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.dto.simulation.*;
|
|
|
-import com.hdkj.lt.modle.po.FhzgReconResult;
|
|
|
|
|
import com.hdkj.lt.si.dao.*;
|
|
import com.hdkj.lt.si.dao.*;
|
|
|
import com.hdkj.lt.si.service.recon.ReconResultService;
|
|
import com.hdkj.lt.si.service.recon.ReconResultService;
|
|
|
import com.hdkj.lt.si.service.simulation.ISimulationService;
|
|
import com.hdkj.lt.si.service.simulation.ISimulationService;
|
|
|
import com.hdkj.lt.si.service.simulation.TyptResponseEntity;
|
|
import com.hdkj.lt.si.service.simulation.TyptResponseEntity;
|
|
|
-import com.hdkj.hussar.ApiResponse;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -43,7 +43,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.UUID;
|
|
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author rj
|
|
* @author rj
|
|
@@ -61,8 +61,8 @@ public class SimulationServiceImpl implements ISimulationService {
|
|
|
private final PlanAwaitTransferAreaResultMapper planAwaitTransferAreaResultMapper;
|
|
private final PlanAwaitTransferAreaResultMapper planAwaitTransferAreaResultMapper;
|
|
|
private final FaultAwaitTransferAreaResultMapper faultAwaitTransferAreaResultMapper;
|
|
private final FaultAwaitTransferAreaResultMapper faultAwaitTransferAreaResultMapper;
|
|
|
private final FhzgOperationAbnormalityTransferAreaResultMapper operationAbnormalityTransferAreaResultMapper;
|
|
private final FhzgOperationAbnormalityTransferAreaResultMapper operationAbnormalityTransferAreaResultMapper;
|
|
|
- private final FhzgReconResultMapper fhzgReconResultMapper;
|
|
|
|
|
private final ReconResultService reconResultService;
|
|
private final ReconResultService reconResultService;
|
|
|
|
|
+ private final FhzgReconSimulationTaskService reconSimulationTaskService;
|
|
|
private final String BASE_URL = "http://25.91.83.252:28081";
|
|
private final String BASE_URL = "http://25.91.83.252:28081";
|
|
|
|
|
|
|
|
private static final ObjectMapper OM = new ObjectMapper();
|
|
private static final ObjectMapper OM = new ObjectMapper();
|
|
@@ -70,12 +70,6 @@ public class SimulationServiceImpl implements ISimulationService {
|
|
|
@Value("${simulation.xToken}")
|
|
@Value("${simulation.xToken}")
|
|
|
private String xToken;
|
|
private String xToken;
|
|
|
|
|
|
|
|
- @Value("${remote.recon.request-uri}")
|
|
|
|
|
- private String reconRequestUri;
|
|
|
|
|
-
|
|
|
|
|
- @Value("${remote.recon.recon-uri}")
|
|
|
|
|
- private String reconUri;
|
|
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
@Qualifier("simpleRestTemplate")
|
|
@Qualifier("simpleRestTemplate")
|
|
|
private RestTemplate simpleRestTemplate;
|
|
private RestTemplate simpleRestTemplate;
|
|
@@ -206,7 +200,7 @@ public class SimulationServiceImpl implements ISimulationService {
|
|
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
httpHeaders.set("x-token", xToken);
|
|
httpHeaders.set("x-token", xToken);
|
|
|
HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders);
|
|
HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders);
|
|
|
- TyptResponseEntity rs = simpleRestTemplate.exchange(url, HttpMethod.GET,httpEntity,TyptResponseEntity.class,operationSchemeDTO.getId()).getBody();
|
|
|
|
|
|
|
+ TyptResponseEntity rs = simpleRestTemplate.exchange(url, HttpMethod.GET, httpEntity, TyptResponseEntity.class, operationSchemeDTO.getId()).getBody();
|
|
|
log.info("调优-推演平台结果:{}", JSONObject.toJSONString(rs.getSuccess()));
|
|
log.info("调优-推演平台结果:{}", JSONObject.toJSONString(rs.getSuccess()));
|
|
|
if (rs.getSuccess()) {
|
|
if (rs.getSuccess()) {
|
|
|
operationAbnormalityTransferAreaResultMapper.delete(new LambdaUpdateWrapper<FhzgOperationAbnormalityTransferAreaResult>().eq(FhzgOperationAbnormalityTransferAreaResult::getOaId, operationSchemeDTO.getId()));
|
|
operationAbnormalityTransferAreaResultMapper.delete(new LambdaUpdateWrapper<FhzgOperationAbnormalityTransferAreaResult>().eq(FhzgOperationAbnormalityTransferAreaResult::getOaId, operationSchemeDTO.getId()));
|
|
@@ -272,69 +266,111 @@ public class SimulationServiceImpl implements ISimulationService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public ApiResponse<String> startOperationCalTask(OperationModeStartDTO dto) {
|
|
|
|
|
- // 1. 生成任务ID
|
|
|
|
|
- String taskId = UUID.randomUUID().toString();
|
|
|
|
|
- log.info("启动重构计算, taskId: {}, request: {}", taskId, JSON.toJSONString(dto));
|
|
|
|
|
|
|
+ public ApiResponse<String> startOperationCalTask(OperationModeDTO dto) {
|
|
|
|
|
+ OperationModeStartDTO operationModeStartDTO = dto.getOperationModeStartDTO();
|
|
|
|
|
+ log.info("启动重构计算, request: {}", JSON.toJSONString(operationModeStartDTO));
|
|
|
|
|
|
|
|
- // 2. 调用远程重构接口
|
|
|
|
|
- String requestUrl = reconRequestUri.concat(reconUri);
|
|
|
|
|
|
|
+ // 1. 调用远程接口启动重构计算任务
|
|
|
|
|
+ String requestUrl = BASE_URL + "/api/eac-operation/operationMode/startOperationCalTask";
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- HttpEntity<String> httpEntity = new HttpEntity<>(JSON.toJSONString(dto), headers);
|
|
|
|
|
|
|
+ headers.set("x-token", xToken);
|
|
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity<>(JSON.toJSONString(operationModeStartDTO), headers);
|
|
|
String responseStr;
|
|
String responseStr;
|
|
|
try {
|
|
try {
|
|
|
responseStr = connPoolRestTemplate.postForObject(requestUrl, httpEntity, String.class);
|
|
responseStr = connPoolRestTemplate.postForObject(requestUrl, httpEntity, String.class);
|
|
|
- log.info("重构计算接口返回, taskId: {}, response: {}", taskId, responseStr);
|
|
|
|
|
|
|
+ log.info("重构计算启动接口返回, response: {}", responseStr);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- log.error("调用重构算法接口失败, taskId: {}", taskId, e);
|
|
|
|
|
- return ApiResponse.fail("调用重构算法接口失败: " + e.getMessage());
|
|
|
|
|
|
|
+ log.error("调用重构计算启动接口失败", e);
|
|
|
|
|
+ return ApiResponse.fail("调用重构计算启动接口失败: " + e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 3. 提取 raw_result 节点并入库
|
|
|
|
|
|
|
+ // 2. 解析响应,提取任务ID
|
|
|
try {
|
|
try {
|
|
|
JsonNode root = OM.readTree(responseStr);
|
|
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 节点");
|
|
|
|
|
|
|
+ int code = root.get("code").asInt();
|
|
|
|
|
+ boolean success = root.get("success").asBoolean();
|
|
|
|
|
+ if (code != 0 || !success) {
|
|
|
|
|
+ String msg = root.has("msg") ? root.get("msg").asText() : "";
|
|
|
|
|
+ log.error("重构计算启动失败, code: {}, msg: {}", code, msg);
|
|
|
|
|
+ return ApiResponse.fail("重构计算启动失败: " + msg);
|
|
|
|
|
+ }
|
|
|
|
|
+ JsonNode dataNode = root.get("data");
|
|
|
|
|
+ if (dataNode == null || dataNode.isNull()) {
|
|
|
|
|
+ return ApiResponse.fail("重构计算启动响应缺少任务ID");
|
|
|
}
|
|
}
|
|
|
- String rawResultJson = OM.writeValueAsString(rawNode);
|
|
|
|
|
- reconResultService.parseAndSaveReconResult(rawResultJson, taskId);
|
|
|
|
|
|
|
+ String taskId = dataNode.asText();
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 保存任务ID和状态到任务追踪表
|
|
|
|
|
+ FhzgReconSimulationTask task = new FhzgReconSimulationTask();
|
|
|
|
|
+ task.setTaskId(taskId);
|
|
|
|
|
+ task.setEventId(dto.getEventId());
|
|
|
|
|
+ task.setStatus(0);
|
|
|
|
|
+ task.setCreateTime(new Date());
|
|
|
|
|
+ reconSimulationTaskService.save(task);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("重构计算任务已启动, taskId: {}", taskId);
|
|
|
|
|
+ return ApiResponse.success(taskId);
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
- log.error("解析算法响应失败, taskId: {}", taskId, e);
|
|
|
|
|
- return ApiResponse.fail("解析算法响应失败: " + e.getMessage());
|
|
|
|
|
|
|
+ log.error("解析重构计算启动响应失败", e);
|
|
|
|
|
+ return ApiResponse.fail("解析重构计算启动响应失败: " + e.getMessage());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- return ApiResponse.success(taskId);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public ApiResponse<QueryOperationModeDTO> queryOperationResult(String taskId) {
|
|
public ApiResponse<QueryOperationModeDTO> queryOperationResult(String taskId) {
|
|
|
log.info("查询重构结果, taskId: {}", taskId);
|
|
log.info("查询重构结果, taskId: {}", taskId);
|
|
|
|
|
|
|
|
- // 查询主表
|
|
|
|
|
- FhzgReconResult reconResult = fhzgReconResultMapper.selectOne(
|
|
|
|
|
- new LambdaQueryWrapper<FhzgReconResult>().eq(FhzgReconResult::getEventId, taskId));
|
|
|
|
|
- if (reconResult == null) {
|
|
|
|
|
- return ApiResponse.fail("任务不存在或未完成: " + taskId);
|
|
|
|
|
|
|
+ // 1. 调用远程接口查询重构结果
|
|
|
|
|
+ String requestUrl = BASE_URL + "/api/eac-operation/operationMode/queryOperationResult?id={taskId}";
|
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
+ headers.set("x-token", xToken);
|
|
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity<>(headers);
|
|
|
|
|
+ String responseStr;
|
|
|
|
|
+ try {
|
|
|
|
|
+ responseStr = connPoolRestTemplate.exchange(requestUrl, HttpMethod.GET, httpEntity, String.class, taskId).getBody();
|
|
|
|
|
+ log.info("重构结果查询接口返回, taskId: {}", taskId);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("调用重构结果查询接口失败, taskId: {}", taskId, e);
|
|
|
|
|
+ return ApiResponse.fail("调用重构结果查询接口失败: " + e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 反序列化 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);
|
|
|
|
|
|
|
+ FhzgReconSimulationTask one = reconSimulationTaskService.getOne(new LambdaQueryWrapper<FhzgReconSimulationTask>().eq(FhzgReconSimulationTask::getTaskId, taskId));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 解析响应
|
|
|
|
|
+ try {
|
|
|
|
|
+ JsonNode root = OM.readTree(responseStr);
|
|
|
|
|
+ int code = root.get("code").asInt();
|
|
|
|
|
+ boolean success = root.get("success").asBoolean();
|
|
|
|
|
+ if (code != 0 || !success) {
|
|
|
|
|
+ String msg = root.has("msg") ? root.get("msg").asText() : "";
|
|
|
|
|
+ log.error("重构结果查询失败, taskId: {}, code: {}, msg: {}", taskId, code, msg);
|
|
|
|
|
+ return ApiResponse.fail("重构结果查询失败: " + msg);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ JsonNode dataNode = root.get("data");
|
|
|
|
|
+ if (dataNode == null || dataNode.isNull()) {
|
|
|
|
|
+ return ApiResponse.fail("重构结果查询响应数据为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ QueryOperationModeDTO resultDTO = OM.treeToValue(dataNode, QueryOperationModeDTO.class);
|
|
|
|
|
|
|
|
- QueryOperationModeDTO resultDTO = new QueryOperationModeDTO();
|
|
|
|
|
- resultDTO.setId(taskId);
|
|
|
|
|
- resultDTO.setResult(rawResultDTO);
|
|
|
|
|
- return ApiResponse.success(resultDTO);
|
|
|
|
|
|
|
+ // 3. 保存结果到数据库
|
|
|
|
|
+ if (resultDTO.getResult() != null) {
|
|
|
|
|
+ // 将 result 序列化为 rawResult JSON 并入库
|
|
|
|
|
+ String rawResultJson = OM.writeValueAsString(resultDTO.getResult());
|
|
|
|
|
+ reconResultService.parseAndSaveDnrResultV24(rawResultJson, one.getEventId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (one != null) {
|
|
|
|
|
+ one.setStatus(1);
|
|
|
|
|
+ reconSimulationTaskService.saveOrUpdate(one);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ApiResponse.success(resultDTO);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("解析重构结果查询响应失败, taskId: {}", taskId, e);
|
|
|
|
|
+ return ApiResponse.fail("解析重构结果查询响应失败: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|