|
@@ -1,7 +1,6 @@
|
|
|
package com.hdkj.lt.si.service.recon.impl;
|
|
package com.hdkj.lt.si.service.recon.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@@ -17,16 +16,13 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.Charsets;
|
|
import org.apache.commons.codec.Charsets;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
import org.springframework.http.*;
|
|
import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.StreamUtils;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.OffsetDateTime;
|
|
import java.time.OffsetDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -68,18 +64,13 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public ReconSaveResultVO saveReconResult(String eventId, Map<String, Object> params) {
|
|
public ReconSaveResultVO saveReconResult(String eventId, Map<String, Object> params) {
|
|
|
- // 1. 构造请求参数
|
|
|
|
|
-// Map<String, Object> params = new HashMap<>();
|
|
|
|
|
-// params.put("county_sid", "honghu");
|
|
|
|
|
-// params.put("county_name", "honghu");
|
|
|
|
|
-// params.put("problem_feeder_ids", Collections.singletonList("15DKX-20690"));
|
|
|
|
|
|
|
+ // 1. 调用远程重构接口
|
|
|
String requestUrl = requestUri.concat(reconUri);
|
|
String requestUrl = requestUri.concat(reconUri);
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
|
headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
|
|
headers.set(HttpHeaders.ACCEPT_CHARSET, Charsets.UTF_8.toString());
|
|
headers.set(HttpHeaders.ACCEPT_CHARSET, Charsets.UTF_8.toString());
|
|
|
HttpEntity<Object> httpEntity = new HttpEntity<>(params, headers);
|
|
HttpEntity<Object> httpEntity = new HttpEntity<>(params, headers);
|
|
|
String str;
|
|
String str;
|
|
|
- RawResultDTO dto;
|
|
|
|
|
try {
|
|
try {
|
|
|
ResponseEntity<Object> restRespEntity = restTemplate.postForEntity(requestUrl, httpEntity, Object.class);
|
|
ResponseEntity<Object> restRespEntity = restTemplate.postForEntity(requestUrl, httpEntity, Object.class);
|
|
|
if (!restRespEntity.getStatusCode().is2xxSuccessful() || Objects.isNull(restRespEntity.getBody())) {
|
|
if (!restRespEntity.getStatusCode().is2xxSuccessful() || Objects.isNull(restRespEntity.getBody())) {
|
|
@@ -88,51 +79,70 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
log.error(errorMsg);
|
|
log.error(errorMsg);
|
|
|
ExceptionCast.cast(errorMsg);
|
|
ExceptionCast.cast(errorMsg);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
Object body = restRespEntity.getBody();
|
|
Object body = restRespEntity.getBody();
|
|
|
str = JSON.toJSONString(body);
|
|
str = JSON.toJSONString(body);
|
|
|
- log.info("调用重构方案接口成功, requestUrl: {}, result: {}",
|
|
|
|
|
- requestUrl, str);
|
|
|
|
|
- // 2. 解析返回的JSON数据
|
|
|
|
|
-// str = StreamUtils.copyToString(new ClassPathResource("1.txt").getInputStream(), StandardCharsets.UTF_8);
|
|
|
|
|
|
|
+ log.info("调用重构方案接口成功, requestUrl: {}, result: {}", requestUrl, str);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException("调用重构方案接口异常", e);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ // 2. 提取 raw_result 节点JSON字符串
|
|
|
|
|
+ String rawResultJson;
|
|
|
|
|
+ try {
|
|
|
JsonNode root = OM.readTree(str);
|
|
JsonNode root = OM.readTree(str);
|
|
|
JsonNode rawNode = root.get("raw_result");
|
|
JsonNode rawNode = root.get("raw_result");
|
|
|
if (rawNode == null || rawNode.isNull()) {
|
|
if (rawNode == null || rawNode.isNull()) {
|
|
|
throw new RuntimeException("算法响应缺少 raw_result 节点");
|
|
throw new RuntimeException("算法响应缺少 raw_result 节点");
|
|
|
}
|
|
}
|
|
|
- dto = OM.treeToValue(rawNode, RawResultDTO.class);
|
|
|
|
|
|
|
+ rawResultJson = OM.writeValueAsString(rawNode);
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException("解析算法响应 raw_result 失败", e);
|
|
throw new RuntimeException("解析算法响应 raw_result 失败", e);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 反序列化并入库
|
|
|
|
|
+ return parseAndSaveReconResult(rawResultJson, eventId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public ReconSaveResultVO parseAndSaveReconResult(String rawResultJson, String eventId) {
|
|
|
|
|
+ // 1. 反序列化 raw_result JSON -> RawResultDTO
|
|
|
|
|
+ RawResultDTO dto;
|
|
|
|
|
+ try {
|
|
|
|
|
+ dto = OM.readValue(rawResultJson, RawResultDTO.class);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException("反序列化 raw_result JSON 失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Map<String, Integer> counts = new LinkedHashMap<>();
|
|
Map<String, Integer> counts = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
- // 1. 主表
|
|
|
|
|
|
|
+ // 2. 主表
|
|
|
FhzgReconResult main = buildMain(dto);
|
|
FhzgReconResult main = buildMain(dto);
|
|
|
main.setEventId(eventId);
|
|
main.setEventId(eventId);
|
|
|
|
|
+ main.setRawResult(rawResultJson);
|
|
|
resultMapper.insert(main);
|
|
resultMapper.insert(main);
|
|
|
Long resultId = main.getId();
|
|
Long resultId = main.getId();
|
|
|
counts.put("result", 1);
|
|
counts.put("result", 1);
|
|
|
|
|
|
|
|
- // 2. 开关操作(简化版)
|
|
|
|
|
|
|
+ // 3. 开关操作(简化版)
|
|
|
if (dto.getSwitchOp() != null) {
|
|
if (dto.getSwitchOp() != null) {
|
|
|
int n = insertSwitchOp(dto.getSwitchOp(), resultId);
|
|
int n = insertSwitchOp(dto.getSwitchOp(), resultId);
|
|
|
counts.put("switch_op", n);
|
|
counts.put("switch_op", n);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 3. 开关操作序列(详细)
|
|
|
|
|
|
|
+ // 4. 开关操作序列(详细)
|
|
|
if (dto.getSwitchSeq() != null) {
|
|
if (dto.getSwitchSeq() != null) {
|
|
|
int n = insertSwitchSeq(dto.getSwitchSeq(), resultId);
|
|
int n = insertSwitchSeq(dto.getSwitchSeq(), resultId);
|
|
|
counts.put("switch_seq", n);
|
|
counts.put("switch_seq", n);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 4. 馈线结果
|
|
|
|
|
|
|
+ // 5. 馈线结果
|
|
|
if (dto.getFeederResult() != null) {
|
|
if (dto.getFeederResult() != null) {
|
|
|
int n = insertFeederResult(dto.getFeederResult(), resultId);
|
|
int n = insertFeederResult(dto.getFeederResult(), resultId);
|
|
|
counts.put("feeder_result", n);
|
|
counts.put("feeder_result", n);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 5. 电压结果(汇总+详情)
|
|
|
|
|
|
|
+ // 6. 电压结果(汇总+详情)
|
|
|
if (dto.getVolResult() != null) {
|
|
if (dto.getVolResult() != null) {
|
|
|
if (dto.getVolResult().getSummary() != null) {
|
|
if (dto.getVolResult().getSummary() != null) {
|
|
|
volResultMapper.insert(buildVolResult(dto.getVolResult().getSummary(), resultId));
|
|
volResultMapper.insert(buildVolResult(dto.getVolResult().getSummary(), resultId));
|
|
@@ -144,17 +154,18 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 6. 开关状态详情(summary 折叠进主表)
|
|
|
|
|
|
|
+ // 7. 开关状态详情(summary 折叠进主表)
|
|
|
if (dto.getSwitchResult() != null && dto.getSwitchResult().getDetails() != null) {
|
|
if (dto.getSwitchResult() != null && dto.getSwitchResult().getDetails() != null) {
|
|
|
int n = insertSwitchResultDetail(dto.getSwitchResult().getDetails(), resultId);
|
|
int n = insertSwitchResultDetail(dto.getSwitchResult().getDetails(), resultId);
|
|
|
counts.put("switch_result_detail", n);
|
|
counts.put("switch_result_detail", n);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 7. 运行指标
|
|
|
|
|
|
|
+ // 8. 运行指标
|
|
|
if (dto.getMetrics() != null) {
|
|
if (dto.getMetrics() != null) {
|
|
|
metricsMapper.insert(buildMetrics(dto.getMetrics(), resultId));
|
|
metricsMapper.insert(buildMetrics(dto.getMetrics(), resultId));
|
|
|
counts.put("metrics", 1);
|
|
counts.put("metrics", 1);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
log.info("重构方案counts:{}", JSON.toJSONString(counts));
|
|
log.info("重构方案counts:{}", JSON.toJSONString(counts));
|
|
|
ReconSaveResultVO vo = new ReconSaveResultVO();
|
|
ReconSaveResultVO vo = new ReconSaveResultVO();
|
|
|
vo.setSuccess(true);
|
|
vo.setSuccess(true);
|