瀏覽代碼

Merge remote-tracking branch 'origin/master'

syh 4 年之前
父節點
當前提交
8c7c40dd5d

+ 5 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouUploadServiceImpl.java

@@ -27,6 +27,7 @@ import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -161,10 +162,6 @@ public class KuaiShouUploadServiceImpl implements IKuaiShouUploadService {
             e.printStackTrace();
         }
     }
-
-    @Autowired
-    private RestTemplate rest;
-
     private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
         try {
             MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
@@ -178,6 +175,10 @@ public class KuaiShouUploadServiceImpl implements IKuaiShouUploadService {
                         headers.add(key, headerMap.get(key));
                     }
                 }
+                SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
+                requestFactory.setConnectTimeout(1000 * 500);// 设置超时
+                requestFactory.setReadTimeout(1000 * 500);
+                RestTemplate rest = new RestTemplate(requestFactory);
                 HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
                 ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
                 return responseEntity.getBody();

+ 5 - 3
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadImageServiceImpl.java

@@ -20,6 +20,7 @@ import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -122,9 +123,6 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
     }
 
 
-    @Autowired
-    private RestTemplate rest;
-
     private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
         try {
             MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
@@ -138,6 +136,10 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
                         headers.add(key, headerMap.get(key));
                     }
                 }
+                SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
+                requestFactory.setConnectTimeout(1000 * 500);// 设置超时
+                requestFactory.setReadTimeout(1000 * 500);
+                RestTemplate rest = new RestTemplate(requestFactory);
                 HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
                 ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
                 return responseEntity.getBody();

+ 7 - 3
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java

@@ -26,6 +26,7 @@ import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -261,11 +262,9 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     }
 
 
-    @Autowired
-    private RestTemplate rest;
-
     private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) {
         try {
+            long l = System.currentTimeMillis();
             MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
             if (!Check.isNullMap(paramMap)) {
                 for (String key : paramMap.keySet()) {
@@ -277,8 +276,13 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
                         headers.add(key, headerMap.get(key));
                     }
                 }
+                SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
+                requestFactory.setConnectTimeout(1000 * 500);// 设置超时
+                requestFactory.setReadTimeout(1000 * 500);
+                RestTemplate rest = new RestTemplate(requestFactory);
                 HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(param, headers);
                 ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
+                log.info("上传素材时间:{} s ,账户:{}。code:{}", (System.currentTimeMillis() - l) / 1000, paramMap.get("advertiser_id"), paramMap.get("signature"));
                 return responseEntity.getBody();
             }
         } catch (Exception e) {

+ 0 - 33
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -12,18 +12,10 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.http.ParseException;
 import org.jeecg.common.util.DateUtils;
 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.HttpMethod;
-import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.client.RestTemplate;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -61,8 +53,6 @@ public class BatchServiceImpl implements IBatchService {
     private IKuaishouInterfaceService kuaishouInterfaceService;
     @Autowired
     private IKuaiShouImageGetService imageGetService;
-    @Autowired
-    private RestTemplate rest;
 
 
     /**
@@ -1683,29 +1673,6 @@ public class BatchServiceImpl implements IBatchService {
         return returnJson;
     }
 
-
-    private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
-        try {
-            MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
-            if (!Check.isNullMap(paramMap)) {
-                for (String key : paramMap.keySet()) {
-                    param.add(key, paramMap.get(key));
-                }
-                HttpHeaders headers = new HttpHeaders();
-                if (!Check.isNullMap(headerMap)) {
-                    for (String key : headerMap.keySet()) {
-                        headers.add(key, headerMap.get(key));
-                    }
-                }
-                HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
-                ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
-                return responseEntity.getBody();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
 }
 
 

+ 5 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -39,6 +39,7 @@ import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -85,8 +86,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     @Autowired
     private KuaiShouAppListMapper appListMapper;
     @Autowired
-    private RestTemplate rest;
-    @Autowired
     private IKuaishouReportHourlyAccountService hourlyAccountService;
     @Autowired
     private KuaiShouAdvertiserBaseInfoMapper advertiserBaseInfoMapper;
@@ -2528,6 +2527,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         headers.add(key, headerMap.get(key));
                     }
                 }
+                SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
+                requestFactory.setConnectTimeout(1000 * 500);// 设置超时
+                requestFactory.setReadTimeout(1000 * 500);
+                RestTemplate rest = new RestTemplate(requestFactory);
                 HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
                 ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
                 return responseEntity.getBody();