Преглед изворни кода

委外维修的流程发起,处理乱套问题

Zimo пре 10 часа
родитељ
комит
d47c400328

+ 15 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/oa/OaFlow.java

@@ -24,12 +24,15 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.client.LaxRedirectStrategy;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.stereotype.Component;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -228,6 +231,14 @@ public class OaFlow {
 
     @Autowired
     private RestTemplate restTemplate;
+    private RestTemplate getNewRestTemplateWithoutCookie() {
+        return new RestTemplate(new HttpComponentsClientHttpRequestFactory(
+                HttpClients.custom()
+                        .disableCookieManagement() // 彻底禁用Cookie,不保存、不携带
+                        .setRedirectStrategy(new LaxRedirectStrategy())
+                        .build()
+        ));
+    }
 
     public void createOutRepairFlow(IotMaintainDO iotMaintainDO) throws Exception {
         String token = getToken();
@@ -284,10 +295,13 @@ public class OaFlow {
         System.out.println("------------"+JSON.toJSONString(params));
         System.out.println(headersOut);
 
+        RestTemplate noCookieRestTemplate = getNewRestTemplateWithoutCookie();
+
+
         // 3. 组合请求头和请求体
         HttpEntity<MultiValueMap<String, Object>> requestEntityOut = new HttpEntity<>(params, headersOut);
 //        RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
-        String out = restTemplate.postForObject(outMaintainUrl, requestEntityOut, String.class);
+        String out = noCookieRestTemplate.postForObject(outMaintainUrl, requestEntityOut, String.class);
         JSONObject outInfo = JSON.parseObject(out);
         //请求成功
         if (Objects.isNull(outInfo) || !"success".equalsIgnoreCase(String.valueOf(outInfo.get("code")))) {