Przeglądaj źródła

计算推演平台增加鉴权

raojiang 4 miesięcy temu
rodzic
commit
0c2baf08ce

+ 21 - 8
services/load-transfer-si/src/main/java/com/hdkj/lt/si/service/simulation/impl/SimulationServiceImpl.java

@@ -1,6 +1,5 @@
 package com.hdkj.lt.si.service.simulation.impl;
 
-import cn.hutool.core.lang.generator.SnowflakeGenerator;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
@@ -27,8 +26,10 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
@@ -53,6 +54,9 @@ public class SimulationServiceImpl implements ISimulationService {
     private final FhzgOperationAbnormalityTransferAreaResultMapper operationAbnormalityTransferAreaResultMapper;
     private final String BASE_URL = "http://25.91.83.252:28081";
 
+    @Value("simulation.xToken")
+    private String xToken;
+
     @Autowired
     @Qualifier("simpleRestTemplate")
     private RestTemplate simpleRestTemplate;
@@ -68,12 +72,16 @@ public class SimulationServiceImpl implements ISimulationService {
         loopCheckRule.setVolDifMargin(5);
         loopCheckRule.setFeederLoadRate(80);
         planTransferSchemeDTO.setLoopCheckRule(loopCheckRule);
-        log.info("计划-推演平台参:{}", JSON.toJSONString(planTransferSchemeDTO));
+        log.info("计划:{} --请求推演平台参:{}", planTransferSchemeDTO.getPlanId(), JSON.toJSONString(planTransferSchemeDTO));
         FhzgPlanPowerCutSwitch planPowerCutSwitch = new FhzgPlanPowerCutSwitch();
         planPowerCutSwitch.setPlanId(planTransferSchemeDTO.getPlanId());
         planPowerCutSwitch.setAnalysisJson(JSON.toJSONString(planTransferSchemeDTO));
         planPowercutMapper.saveAnalysisJson(planPowerCutSwitch);
-        TyptResponseEntity rs = simpleRestTemplate.postForObject(url, planTransferSchemeDTO, TyptResponseEntity.class);
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        headers.set("x-token", xToken);
+        HttpEntity<String> requestEntity = new HttpEntity<>(JSON.toJSONString(planTransferSchemeDTO), headers);
+        TyptResponseEntity rs = simpleRestTemplate.postForObject(url, requestEntity, TyptResponseEntity.class);
         log.info("计划-推演平台结果:{}", JSONObject.toJSONString(rs.getSuccess()));
         if (rs.getSuccess()) {
             LambdaUpdateWrapper<PlanAwaitTransferAreaResultPO> wrapper = new LambdaUpdateWrapper<>();
@@ -110,7 +118,7 @@ public class SimulationServiceImpl implements ISimulationService {
     public String getFaultTransferScheme(FaultTransferSchemeDTO faultTransferSchemeDTO) {
         String url = BASE_URL + "/api/power/power-transfer/analysis";
         Long faultId = faultTransferSchemeDTO.getFaultId();
-        log.info("故障:{} --推演平台参:{}", faultId, faultTransferSchemeDTO.getFaultTransferSchemeParam());
+        log.info("故障:{} --请求推演平台参:{}", faultId, faultTransferSchemeDTO.getFaultTransferSchemeParam());
         LocalDateTime start = LocalDateTime.now();
         long startTime = System.currentTimeMillis();
         TyptResponseEntity rs;
@@ -118,6 +126,7 @@ public class SimulationServiceImpl implements ISimulationService {
         try {
             HttpHeaders httpHeaders = new HttpHeaders();
             httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+            httpHeaders.set("x-token", xToken);
             HttpEntity<String> httpEntity = new HttpEntity<>(faultTransferSchemeDTO.getFaultTransferSchemeParam(), httpHeaders);
             rs = simpleRestTemplate.postForObject(url, httpEntity, TyptResponseEntity.class);
         } finally {
@@ -169,10 +178,14 @@ public class SimulationServiceImpl implements ISimulationService {
         }
         Long oaID = operationSchemeDTO.getOaID();
         operationSchemeDTO.setOaID(null);
-        String url = BASE_URL + "/api/power/operationMode/queryResult?id=" + operationSchemeDTO.getId();
-        log.info("计划-推演平台入参:{}", JSON.toJSONString(operationSchemeDTO));
-        TyptResponseEntity rs = simpleRestTemplate.getForObject(url, TyptResponseEntity.class);
-        log.info("计划-推演平台结果:{}", JSONObject.toJSONString(rs.getSuccess()));
+        String url = BASE_URL + "/api/power/operationMode/queryResult?id={id}";
+        log.info("调优-请求推演平台参数:{}", JSON.toJSONString(operationSchemeDTO));
+        HttpHeaders httpHeaders = new HttpHeaders();
+        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+        httpHeaders.set("x-token", xToken);
+        HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders);
+        TyptResponseEntity rs = simpleRestTemplate.exchange(url, HttpMethod.GET,httpEntity,TyptResponseEntity.class,operationSchemeDTO.getId()).getBody();
+        log.info("调优-推演平台结果:{}", JSONObject.toJSONString(rs.getSuccess()));
         if (rs.getSuccess()) {
             operationAbnormalityTransferAreaResultMapper.delete(new LambdaUpdateWrapper<FhzgOperationAbnormalityTransferAreaResult>().eq(FhzgOperationAbnormalityTransferAreaResult::getOaId, operationSchemeDTO.getId()));
             FhzgOperationAbnormalityTransferAreaResult fhzgOperationAbnormalityTransferAreaResult = new FhzgOperationAbnormalityTransferAreaResult();