wzy 1 week ago
parent
commit
e29d0e8e19

+ 41 - 4
mjava-huagao/src/main/java/com/malk/huagao/service/impl/KdHuaGaoServiceImpl.java

@@ -109,7 +109,7 @@ public class KdHuaGaoServiceImpl implements KdHuaGaoService {
             do {
                 pageNumber++;
 
-                ddrNew = ydClient.queryData(YDParam.builder()
+                ddrNew = retryQueryData(YDParam.builder()
                         .formUuid("FORM-3B2E5C93D7E6494B9AD920B48A90159F7DZ4")
                         .searchFieldJson(JSONObject.toJSONString(UtilMap.map("numberField_mev270x6, numberField_mev270x5, textField_mev2ers5", Arrays.asList(year,year), Arrays.asList(month,month), weekOfMonth)))
                         .pageNumber(pageNumber)
@@ -232,7 +232,7 @@ public class KdHuaGaoServiceImpl implements KdHuaGaoService {
             }
 
             //删除宜搭历史最新库存信息
-            List<Map> data = (List<Map>) ydClient.queryData(YDParam.builder()
+            List<Map> data = (List<Map>) retryQueryData(YDParam.builder()
                     .formUuid("FORM-4CB51E04B8344622BE880C9D573F68CANKWU")
                     .searchFieldJson(JSONObject.toJSONString(UtilMap.map("numberField_mev270x6, numberField_mev270x5",Arrays.asList(year,year), Arrays.asList(month,month))))
                     .build(), YDConf.FORM_QUERY.retrieve_list).getData();
@@ -250,7 +250,7 @@ public class KdHuaGaoServiceImpl implements KdHuaGaoService {
                         .build(), YDConf.FORM_OPERATION.delete_batch);
             }
 
-            List<Map> data2 = (List<Map>) ydClient.queryData(YDParam.builder()
+            List<Map> data2 = (List<Map>) retryQueryData(YDParam.builder()
                     .formUuid("FORM-5764CC3F6D964FD3A165BD7D4D75999FO8NQ")
                     .searchFieldJson(JSONObject.toJSONString(UtilMap.map("numberField_mev270x6",Arrays.asList(year,year))))
                     .build(), YDConf.FORM_QUERY.retrieve_list).getData();
@@ -1236,11 +1236,12 @@ public class KdHuaGaoServiceImpl implements KdHuaGaoService {
 
                 return result;
             } catch (McException e) {
+                log.info("错误信息:{}",e.getMessage());
                 if (e.getMessage().equals("The request has failed due to a temporary failure of the server.")) {
                     attempt++;
                     // 线程睡眠3秒
                     try {
-                        Thread.sleep(3000);
+                        Thread.sleep(5000);
                         log.info("尝试第{}次,param:{},FORM_OPERATION:{},异常信息:{}", attempt, JSONObject.toJSONString(param), formOperation,e.getMessage());
                     } catch (InterruptedException ie) {
                         Thread.currentThread().interrupt(); // 重新设置中断状态
@@ -1258,4 +1259,40 @@ public class KdHuaGaoServiceImpl implements KdHuaGaoService {
         throw new RuntimeException("超出最大重试次数,param:"+JSONObject.toJSONString(param)+",FORM_OPERATION:{}"+formOperation);
     }
 
+
+    //自带重试的queryData方法
+    private DDR_New retryQueryData(YDParam param, YDConf.FORM_QUERY formQuery) {
+        int maxAttempts = 3; // 尝试的最大次数
+        int attempt = 0;
+
+        DDR_New result = null;
+
+        while (attempt < maxAttempts) {
+            try {
+                result = ydClient.queryData(param, formQuery);
+
+                return result;
+            } catch (McException e) {
+                log.info("错误信息:{}",e.getMessage());
+                if (e.getMessage().equals("The request has failed due to a temporary failure of the server.")) {
+                    attempt++;
+                    // 线程睡眠3秒
+                    try {
+                        Thread.sleep(5000);
+                        log.info("尝试第{}次,param:{},FORM_QUERY:{},异常信息:{}", attempt, JSONObject.toJSONString(param), formQuery,e.getMessage());
+                    } catch (InterruptedException ie) {
+                        Thread.currentThread().interrupt(); // 重新设置中断状态
+                        System.err.println("Sleep interrupted: " + ie.getMessage());
+                    }
+                }
+            } catch (Exception e) {
+                log.error("操作失败,param:{},FORM_QUERY:{},异常信息:{}", JSONObject.toJSONString(param), formQuery,e.getMessage());
+
+                throw new RuntimeException(e);
+            }
+
+        }
+
+        throw new RuntimeException("超出最大重试次数,param:"+JSONObject.toJSONString(param)+",FORM_QUERY:{}"+formQuery);
+    }
 }

+ 3 - 3
mjava-huagao/src/test/java/com/malk/huagao/YyYdTest.java

@@ -114,9 +114,9 @@ public class YyYdTest {
 
     @Test
     public void test3() {
-        LocalDateTime startTime= LocalDate.now().minusDays(6).atTime(LocalTime.MIN);
-        LocalDateTime endTime= LocalDate.now().minusDays(4).atTime(LocalTime.MIN);
-//        LocalDateTime endTime= LocalDate.now().atTime(LocalTime.MIN);
+        LocalDateTime startTime= LocalDate.now().minusDays(4).atTime(LocalTime.MIN);
+//        LocalDateTime endTime= LocalDate.now().minusDays(4).atTime(LocalTime.MIN);
+        LocalDateTime endTime= LocalDate.now().atTime(LocalTime.MIN);
 
         huaGaoService.syncKqData(startTime,endTime);
     }