Browse Source

重传火运实绩-->环保,拉长响应过期时间

yi eason 1 tháng trước cách đây
mục cha
commit
5622abd66e

+ 1 - 1
pom.xml

@@ -6,7 +6,7 @@
 
     <groupId>org.example</groupId>
     <artifactId>antai-wltms-api</artifactId>
-    <version>2.1</version>
+    <version>2.3</version>
 
     <parent>
         <groupId>org.springframework.boot</groupId>

+ 4 - 3
src/main/java/com/steerinfo/dil/controller/OmsTransOrderController.java

@@ -682,7 +682,7 @@ public class OmsTransOrderController extends BaseRESTfulController {
             return success("没有需要重传的数据(传输类型:" + ("0".equals(busiType) ? "采购" : "销售")
                     + ",时间范围:" + (startDate == null ? "不限" : startDate) + " ~ " + (endDate == null ? "不限" : endDate) + ")");
         }
-        int index= 0,section = 300;//分片大小
+        int index= 0,section = 50;//分片大小(客户平台单批处理慢,50条/片约3-5秒,避免读超时)
         int total = listXt.size();
         int successCount = 0;
         log.info("重传火运实绩->环保:busiType=" + busiType + ",时间范围 " + startDate + " ~ " + endDate + ",共 " + total + " 条");
@@ -696,7 +696,8 @@ public class OmsTransOrderController extends BaseRESTfulController {
             }
             Map<String,Object>[]  paramArray = tempList.toArray(new Map[tempList.size()]);
             try {
-                daZongUtil.executeEnvironment("/train/saveOrUpdate", paramArray);
+                //重传为批量推送,读取超时放到60秒(默认sendPost只有10秒,客户平台处理不完会Read timed out)
+                daZongUtil.executeEnvironment("/train/saveOrUpdate", paramArray, 5000, 60000);
             } catch (Exception e) {
                 log.error("重传火运实绩失败:第 " + index + " 片(" + tempList.size() + " 条)", e);
                 throw new Exception("重传中止:第 " + index + " 片(" + tempList.size() + " 条)推送失败,已成功 "
@@ -715,7 +716,7 @@ public class OmsTransOrderController extends BaseRESTfulController {
         //        tempList = listHa.subList((index - 1) * section, listHa.size());
         //    }
         //    Map<String,Object>[]  paramArray = tempList.toArray(new Map[tempList.size()]);
-        //    daZongUtil.executeEnvironment("/ha/train/saveOrUpdate", paramArray);
+        //    daZongUtil.executeEnvironment("/ha/train/saveOrUpdate", paramArray, 5000, 60000);
         //}
         return success("重传完成:传输类型 " + ("0".equals(busiType) ? "采购" : "销售")
                 + ",共 " + total + " 条,分 " + index + " 片推送成功");

+ 12 - 2
src/main/java/com/steerinfo/dil/util/DaZongUtil.java

@@ -270,6 +270,16 @@ public class DaZongUtil {
      * @return
      */
     public JSONObject executeEnvironment(String url,Map<String,Object>[] args) throws Exception {
+        //默认超时与原逻辑保持一致:连接1秒、读取10秒
+        return executeEnvironment(url, args, 1000, 10000);
+    }
+
+    /**
+     * 推送清洁能源(可指定超时,重传等批量场景用长超时)
+     * @param connectTimeout 连接超时(ms)
+     * @param socketTimeout  读取超时(ms)
+     */
+    public JSONObject executeEnvironment(String url,Map<String,Object>[] args,int connectTimeout,int socketTimeout) throws Exception {
         if(!isPush){
             log.info("大宗推送关闭!");
             return null;
@@ -277,8 +287,8 @@ public class DaZongUtil {
         JSONObject result = null;
         try{
             url = environmentHost + url;
-            log.info("调用清洁能源接口,url:"+url+",参数:"+JSONObject.toJSONString(args));
-            JSONObject response = HttpUtil.sendPost(url,JSONObject.toJSONString(args));
+            log.info("调用清洁能源接口,url:"+url+",条数:"+(args==null?0:args.length)+",参数:"+JSONObject.toJSONString(args));
+            JSONObject response = HttpUtil.sendPost(url,JSONObject.toJSONString(args),connectTimeout,socketTimeout);
             log.info("调用清洁能源接口,url:"+url+"+返回:"+response);
             result = response;
             if(result!=null && "200".equals(result.getString("code"))){

+ 11 - 2
src/main/java/com/steerinfo/dil/util/HttpUtil.java

@@ -41,11 +41,20 @@ public class HttpUtil {
 
 
     public static JSONObject sendPost(String url,String param) throws HttpException, IOException {
+        return sendPost(url, param, 1000, 10000);
+    }
+
+    /**
+     * 可指定超时的 POST(批量推送等耗时场景使用)
+     * @param connectTimeout 连接超时(ms)
+     * @param socketTimeout  读取(等待响应)超时(ms)
+     */
+    public static JSONObject sendPost(String url, String param, int connectTimeout, int socketTimeout) throws HttpException, IOException {
         // 创建httpClient实例对象
         HttpClient httpClient = new HttpClient();
         // 设置httpClient连接/执行超时时间(ms)
-        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(1000);
-        httpClient.getHttpConnectionManager().getParams().setSoTimeout(10000);
+        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectTimeout);
+        httpClient.getHttpConnectionManager().getParams().setSoTimeout(socketTimeout);
         // 创建post请求方法实例对象
         PostMethod postMethod = new PostMethod(url);
         postMethod.addRequestHeader("Content-Type", "application/json;charset=utf-8");