Browse Source

逸曜重试逻辑调整

wzy 2 weeks ago
parent
commit
b92ca50713

+ 10 - 9
mjava-yiyao/src/main/java/com/malk/yiyao/service/impl/YiyaoServiceImpl.java

@@ -1593,13 +1593,14 @@ public class YiyaoServiceImpl implements YiyaoService {
     @Override
     @Override
     public void getCheckInData(JSONObject eventJson) {
     public void getCheckInData(JSONObject eventJson) {
         int retryCount = 0;
         int retryCount = 0;
-        int maxRetries = 3;
+        int maxRetries = 5;
+
+        long timeStamp = roundToNearestThousand(Long.parseLong(eventJson.getString("timeStamp")));//签到时间戳
+        String staffId = eventJson.getString("StaffId");//签到人userId
+        String eventId = eventJson.getString("eventId");//签到事件id
+
         while (retryCount <= maxRetries) {
         while (retryCount <= maxRetries) {
             try {
             try {
-                String timeStamp = eventJson.getString("timeStamp");//签到时间戳
-                timeStamp = roundToNearestThousand(Long.parseLong(timeStamp)) + "";
-                String staffId = eventJson.getString("StaffId");//签到人userId
-
                 //获取签到数据
                 //获取签到数据
                 Map body = new HashMap();
                 Map body = new HashMap();
                 body.put("cursor",0);
                 body.put("cursor",0);
@@ -1630,7 +1631,7 @@ public class YiyaoServiceImpl implements YiyaoService {
                     formData.put("textField_mbrb3qfx",detailPlace);//签到地点
                     formData.put("textField_mbrb3qfx",detailPlace);//签到地点
                     formData.put("textareaField_mbypt8rp",remark);//备注
                     formData.put("textareaField_mbypt8rp",remark);//备注
                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
-                    String formattedDate = sdf.format(Long.parseLong(timeStamp));
+                    String formattedDate = sdf.format(timeStamp);
                     formData.put("textField_mbrbdyl4","签到人:" +userName + ",签到时间:" + formattedDate + ",签到地点:" + detailPlace);//标题
                     formData.put("textField_mbrbdyl4","签到人:" +userName + ",签到时间:" + formattedDate + ",签到地点:" + detailPlace);//标题
                     ydClient.operateData(YDParam.builder()
                     ydClient.operateData(YDParam.builder()
                             .formUuid("FORM-D4389CDAD1704F959E9D38CB64927AD8PKCH")
                             .formUuid("FORM-D4389CDAD1704F959E9D38CB64927AD8PKCH")
@@ -1642,16 +1643,16 @@ public class YiyaoServiceImpl implements YiyaoService {
             } catch (Exception e) {
             } catch (Exception e) {
                 if (retryCount < maxRetries){
                 if (retryCount < maxRetries){
                     retryCount++;
                     retryCount++;
-                    log.info("第{}次重试,异常信息:{}", retryCount, e.getMessage());
+                    log.info("eventId:{},第{}次重试,异常信息:{}",eventId, retryCount, e.getMessage());
                     try {
                     try {
-                        Thread.sleep(1000 * retryCount); // 指数退避
+                        Thread.sleep(5000);
                     } catch (InterruptedException ie) {
                     } catch (InterruptedException ie) {
                         Thread.currentThread().interrupt();// 如果线程在等待期间被中断,恢复中断状态
                         Thread.currentThread().interrupt();// 如果线程在等待期间被中断,恢复中断状态
                         throw new RuntimeException("Request interrupted", ie);// 抛出运行时异常,终止重试
                         throw new RuntimeException("Request interrupted", ie);// 抛出运行时异常,终止重试
                     }
                     }
                     continue;
                     continue;
                 }
                 }
-                throw new RuntimeException("超出最大重试次数,异常信息:" + e.getMessage());
+                throw new RuntimeException("eventId:" + eventId + ",超出最大重试次数,异常信息:" + e.getMessage());
             }
             }
         }
         }
     }
     }

+ 7 - 7
mjava-yiyao/src/test/java/com/malk/yiyao/YiyaoTest.java

@@ -70,15 +70,15 @@ public class YiyaoTest {
     @Test
     @Test
     public void test11() {
     public void test11() {
         JSONObject json = new JSONObject();
         JSONObject json = new JSONObject();
-        json.put("timeStamp", 1750836577925L);
-        json.put("eventId","80057b2e91694a71b8c2cf6bd0e441a8");
+        json.put("timeStamp", 1752738143151L);
+        json.put("eventId","7a5a1a4b42724fceb799205f4363bebd");
         json.put("CorpId","dingf11f7d6ff834577b");
         json.put("CorpId","dingf11f7d6ff834577b");
-        json.put("StaffId","4537351301674351");
+        json.put("StaffId","694148202226282223");
         json.put("EventType","check_in");
         json.put("EventType","check_in");
-        json.put("EventTime",1750836577925L);
-        json.put("BizId","65164358-9bc3-44ea-9331-19062bc4676c");
-        json.put("staffId","4537351301674351");
-        json.put("TimeStamp", 1750836577925L);
+        json.put("EventTime",1752738143151L);
+        json.put("BizId","c3152e9b-793a-4a34-b7a5-86448aba1566");
+        json.put("staffId","694148202226282223");
+        json.put("TimeStamp", 1752738143151L);
 
 
         yiyaoService.getCheckInData(json);
         yiyaoService.getCheckInData(json);
     }
     }