|
@@ -1,12 +1,10 @@
|
|
|
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.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
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;
|
|
|
-
|
|
|
|
|
import com.hdkj.lt.base.exception.ExceptionCast;
|
|
import com.hdkj.lt.base.exception.ExceptionCast;
|
|
|
import com.hdkj.lt.core.bizms.modle.po.Jxz;
|
|
import com.hdkj.lt.core.bizms.modle.po.Jxz;
|
|
|
import com.hdkj.lt.core.rest.config.HttpClientConfig;
|
|
import com.hdkj.lt.core.rest.config.HttpClientConfig;
|
|
@@ -23,17 +21,17 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.Charsets;
|
|
import org.apache.commons.codec.Charsets;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
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.HttpEntity;
|
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
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.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-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;
|
|
@@ -135,7 +133,7 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
int i = 1;
|
|
int i = 1;
|
|
|
for (ReconfigurationSchemeDTO scheme : schemes) {
|
|
for (ReconfigurationSchemeDTO scheme : schemes) {
|
|
|
// 1. 主表
|
|
// 1. 主表
|
|
|
- FhzgReconResult main = buildMain(dto,scheme,i++);
|
|
|
|
|
|
|
+ FhzgReconResult main = buildMain(dto, scheme, i++);
|
|
|
main.setEventId(eventId);
|
|
main.setEventId(eventId);
|
|
|
main.setRawResult(rawResultJson);
|
|
main.setRawResult(rawResultJson);
|
|
|
resultMapper.insert(main);
|
|
resultMapper.insert(main);
|
|
@@ -161,9 +159,9 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
/**
|
|
/**
|
|
|
* 构建请求参数
|
|
* 构建请求参数
|
|
|
*/
|
|
*/
|
|
|
- private Map<String, Object> buildReconRequestParams(Map<String, Object> params){
|
|
|
|
|
|
|
+ private Map<String, Object> buildReconRequestParams(Map<String, Object> params) {
|
|
|
Map<String, Object> root = new HashMap<>();
|
|
Map<String, Object> root = new HashMap<>();
|
|
|
- if(Objects.nonNull(params)) {
|
|
|
|
|
|
|
+ if (Objects.nonNull(params)) {
|
|
|
String feederId = MapUtils.getString(params, "feeder_id");
|
|
String feederId = MapUtils.getString(params, "feeder_id");
|
|
|
String pointTime = MapUtils.getString(params, "point_time");
|
|
String pointTime = MapUtils.getString(params, "point_time");
|
|
|
List<Jxz> jxzList = getFeederGroup(feederId);
|
|
List<Jxz> jxzList = getFeederGroup(feederId);
|
|
@@ -205,12 +203,15 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
}
|
|
}
|
|
|
return root;
|
|
return root;
|
|
|
}
|
|
}
|
|
|
- private List<Jxz> getFeederGroup(String feederId){
|
|
|
|
|
- return jxzMapper.queryJxzXl(feederId);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private List<Jxz> getFeederGroup(String feederId) {
|
|
|
|
|
+ return jxzMapper.queryJxzXl(feederId);
|
|
|
}
|
|
}
|
|
|
// ==================== 构建主表 ====================
|
|
// ==================== 构建主表 ====================
|
|
|
|
|
|
|
|
- /** [FHZG-RECON-MULTI] 取方案列表; 容器或 list 为空时返回空表(不报错, 入 0 条)。 */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * [FHZG-RECON-MULTI] 取方案列表; 容器或 list 为空时返回空表(不报错, 入 0 条)。
|
|
|
|
|
+ */
|
|
|
private List<ReconfigurationSchemeDTO> extractSchemes(RawResultDTO dto) {
|
|
private List<ReconfigurationSchemeDTO> extractSchemes(RawResultDTO dto) {
|
|
|
if (dto.getReconfigurationSchemes() == null || dto.getReconfigurationSchemes().getList() == null) {
|
|
if (dto.getReconfigurationSchemes() == null || dto.getReconfigurationSchemes().getList() == null) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
@@ -218,21 +219,13 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
return dto.getReconfigurationSchemes().getList();
|
|
return dto.getReconfigurationSchemes().getList();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ==================== v2.4 格式解析 ====================
|
|
|
|
|
|
|
+ // ==================== 求解器 格式解析 ====================
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public ReconSaveResultVO parseAndSaveDnrResultV24(String jsonStr, String eventId) {
|
|
|
|
|
- log.info("解析 v2.4 DNR 结果, eventId: {}", eventId);
|
|
|
|
|
-
|
|
|
|
|
- // 1. 反序列化新结构
|
|
|
|
|
- DnrResultV24DTO root;
|
|
|
|
|
- try {
|
|
|
|
|
- root = OM.readValue(jsonStr, DnrResultV24DTO.class);
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- throw new RuntimeException("反序列化 v2.4 DNR 结果 JSON 失败", e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public ReconSaveResultVO saveDnrResultV24(DnrResultV24DTO resultV24DTO, String eventId) {
|
|
|
|
|
+ log.info("解析 求解器 结果, eventId: {}", eventId);
|
|
|
|
|
|
|
|
- if (root.getData() == null || root.getData().isEmpty()) {
|
|
|
|
|
|
|
+ if (resultV24DTO.getData() == null || resultV24DTO.getData().isEmpty()) {
|
|
|
log.warn("v2.4 结果无 data 数据, eventId: {}", eventId);
|
|
log.warn("v2.4 结果无 data 数据, eventId: {}", eventId);
|
|
|
ReconSaveResultVO vo = new ReconSaveResultVO();
|
|
ReconSaveResultVO vo = new ReconSaveResultVO();
|
|
|
vo.setSuccess(true);
|
|
vo.setSuccess(true);
|
|
@@ -242,13 +235,13 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
|
|
|
|
|
// 2. 遍历每个 group → soln,独立处理主表,复用分表方法
|
|
// 2. 遍历每个 group → soln,独立处理主表,复用分表方法
|
|
|
Map<String, Integer> counts = new LinkedHashMap<>();
|
|
Map<String, Integer> counts = new LinkedHashMap<>();
|
|
|
- for (DnrResultV24GroupDTO group : root.getData()) {
|
|
|
|
|
|
|
+ for (DnrResultV24GroupDTO group : resultV24DTO.getData()) {
|
|
|
if (group.getSolnList() == null || group.getSolnList().isEmpty()) {
|
|
if (group.getSolnList() == null || group.getSolnList().isEmpty()) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
for (DnrResultV24SolnDTO soln : group.getSolnList()) {
|
|
for (DnrResultV24SolnDTO soln : group.getSolnList()) {
|
|
|
// 主表
|
|
// 主表
|
|
|
- FhzgReconResult main = buildMainV24(group, soln, eventId, jsonStr);
|
|
|
|
|
|
|
+ FhzgReconResult main = buildMainV24(group, soln, eventId);
|
|
|
resultMapper.insert(main);
|
|
resultMapper.insert(main);
|
|
|
Long resultId = main.getId();
|
|
Long resultId = main.getId();
|
|
|
counts.merge("result", 1, Integer::sum);
|
|
counts.merge("result", 1, Integer::sum);
|
|
@@ -276,11 +269,11 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
* computeResult, detalDesc, soln_id, soln_name 等来自 soln 层.
|
|
* computeResult, detalDesc, soln_id, soln_name 等来自 soln 层.
|
|
|
*/
|
|
*/
|
|
|
private FhzgReconResult buildMainV24(DnrResultV24GroupDTO group, DnrResultV24SolnDTO soln,
|
|
private FhzgReconResult buildMainV24(DnrResultV24GroupDTO group, DnrResultV24SolnDTO soln,
|
|
|
- String eventId, String rawResultJson) {
|
|
|
|
|
|
|
+ String eventId) {
|
|
|
FhzgReconResult m = new FhzgReconResult();
|
|
FhzgReconResult m = new FhzgReconResult();
|
|
|
m.setId(IdWorker.getId());
|
|
m.setId(IdWorker.getId());
|
|
|
m.setEventId(eventId);
|
|
m.setEventId(eventId);
|
|
|
- m.setRawResult(rawResultJson);
|
|
|
|
|
|
|
+ m.setRawResult(null);
|
|
|
m.setGroupId(String.valueOf(group.getGroupId()));
|
|
m.setGroupId(String.valueOf(group.getGroupId()));
|
|
|
m.setGroupSid(group.getGroupSid());
|
|
m.setGroupSid(group.getGroupSid());
|
|
|
m.setGroupName(group.getGroupName());
|
|
m.setGroupName(group.getGroupName());
|
|
@@ -310,12 +303,11 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 插入所有子表记录(switchOp, switchSeq, feederResult, volResult, switchResultDetail, metrics).
|
|
* 插入所有子表记录(switchOp, switchSeq, feederResult, volResult, switchResultDetail, metrics).
|
|
|
- * 在 {@link #parseAndSaveReconResult} 和 {@link #parseAndSaveDnrResultV24} 中复用.
|
|
|
|
|
*/
|
|
*/
|
|
|
private void insertSubTables(SwitchOpDTO switchOp, SwitchSeqDTO switchSeq,
|
|
private void insertSubTables(SwitchOpDTO switchOp, SwitchSeqDTO switchSeq,
|
|
|
- FeederResultDTO feederResult, VolResultDTO volResult,
|
|
|
|
|
- SwitchResultDTO switchResult, MetricsDTO metrics,
|
|
|
|
|
- Long resultId, Map<String, Integer> counts) {
|
|
|
|
|
|
|
+ FeederResultDTO feederResult, VolResultDTO volResult,
|
|
|
|
|
+ SwitchResultDTO switchResult, MetricsDTO metrics,
|
|
|
|
|
+ Long resultId, Map<String, Integer> counts) {
|
|
|
// 开关操作(简化版)
|
|
// 开关操作(简化版)
|
|
|
if (switchOp != null) {
|
|
if (switchOp != null) {
|
|
|
counts.merge("switch_op", insertSwitchOp(switchOp, resultId), Integer::sum);
|
|
counts.merge("switch_op", insertSwitchOp(switchOp, resultId), Integer::sum);
|
|
@@ -349,7 +341,7 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private FhzgReconResult buildMain(RawResultDTO dto, ReconfigurationSchemeDTO scheme,int i) {
|
|
|
|
|
|
|
+ private FhzgReconResult buildMain(RawResultDTO dto, ReconfigurationSchemeDTO scheme, int i) {
|
|
|
FhzgReconResult m = new FhzgReconResult();
|
|
FhzgReconResult m = new FhzgReconResult();
|
|
|
// 共享标量(每个方案主记录重复)
|
|
// 共享标量(每个方案主记录重复)
|
|
|
m.setId(IdWorker.getId());
|
|
m.setId(IdWorker.getId());
|
|
@@ -591,7 +583,9 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 按 before/after 将指标子对象扁平写入实体对应字段; val 为 null 时跳过. */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 按 before/after 将指标子对象扁平写入实体对应字段; val 为 null 时跳过.
|
|
|
|
|
+ */
|
|
|
private void fillMetricsSide(FhzgReconMetrics e, MetricsDTO.MetricsBeforeAfterDTO m, boolean before) {
|
|
private void fillMetricsSide(FhzgReconMetrics e, MetricsDTO.MetricsBeforeAfterDTO m, boolean before) {
|
|
|
if (m == null) return;
|
|
if (m == null) return;
|
|
|
|
|
|
|
@@ -662,7 +656,9 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** before 时调 beforeSetter, 否则调 afterSetter; val 为 null 跳过. */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * before 时调 beforeSetter, 否则调 afterSetter; val 为 null 跳过.
|
|
|
|
|
+ */
|
|
|
private <T> void side(FhzgReconMetrics e, boolean before,
|
|
private <T> void side(FhzgReconMetrics e, boolean before,
|
|
|
BiConsumer<FhzgReconMetrics, T> beforeSetter,
|
|
BiConsumer<FhzgReconMetrics, T> beforeSetter,
|
|
|
BiConsumer<FhzgReconMetrics, T> afterSetter, T val) {
|
|
BiConsumer<FhzgReconMetrics, T> afterSetter, T val) {
|
|
@@ -672,7 +668,9 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
|
|
|
|
|
// ==================== 类型转换工具 ====================
|
|
// ==================== 类型转换工具 ====================
|
|
|
|
|
|
|
|
- /** ISO8601 字符串(含时区) -> LocalDateTime(取本地壁钟时间); 无法解析返回 null. */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * ISO8601 字符串(含时区) -> LocalDateTime(取本地壁钟时间); 无法解析返回 null.
|
|
|
|
|
+ */
|
|
|
private LocalDateTime parseTime(String s) {
|
|
private LocalDateTime parseTime(String s) {
|
|
|
if (s == null || s.trim().isEmpty()) return null;
|
|
if (s == null || s.trim().isEmpty()) return null;
|
|
|
try {
|
|
try {
|
|
@@ -686,7 +684,9 @@ public class ReconResultServiceImpl implements ReconResultService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** JsonNode -> JSON 字符串; null 或 null 节点返回 null. */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * JsonNode -> JSON 字符串; null 或 null 节点返回 null.
|
|
|
|
|
+ */
|
|
|
private String toJson(JsonNode node) {
|
|
private String toJson(JsonNode node) {
|
|
|
if (node == null || node.isNull()) return null;
|
|
if (node == null || node.isNull()) return null;
|
|
|
try {
|
|
try {
|