|
@@ -1,6 +1,7 @@
|
|
package com.malk.yiyao.service.impl;
|
|
package com.malk.yiyao.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.io.IORuntimeException;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.malk.server.aliwork.YDConf;
|
|
import com.malk.server.aliwork.YDConf;
|
|
@@ -18,6 +19,7 @@ import org.apache.logging.log4j.util.Strings;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.net.UnknownHostException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -1590,58 +1592,67 @@ public class YiyaoServiceImpl implements YiyaoService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void getCheckInData(JSONObject eventJson) {
|
|
public void getCheckInData(JSONObject eventJson) {
|
|
- String timeStamp = eventJson.getString("timeStamp");//签到时间戳
|
|
|
|
-
|
|
|
|
- timeStamp = roundToNearestThousand(Long.parseLong(timeStamp)) + "";
|
|
|
|
-
|
|
|
|
- String staffId = eventJson.getString("StaffId");//签到人userId
|
|
|
|
-
|
|
|
|
- //获取签到数据
|
|
|
|
- Map body = new HashMap();
|
|
|
|
- body.put("cursor",0);
|
|
|
|
- body.put("size",100);
|
|
|
|
- body.put("start_time",timeStamp);
|
|
|
|
- body.put("end_time",timeStamp);
|
|
|
|
- body.put("userid_list",staffId);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //查询用户详情
|
|
|
|
- DDR_New ddrNew1 = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/v2/user/get", null, ddClient.initTokenParams(), UtilMap.map("userid", staffId), DDR_New.class);
|
|
|
|
-
|
|
|
|
- Map result1 = (Map) ddrNew1.getResult();
|
|
|
|
-
|
|
|
|
- String userName = UtilMap.getString(result1, "name");
|
|
|
|
-
|
|
|
|
- //查询用户考勤数据
|
|
|
|
- DDR_New ddrNew = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/checkin/record/get", null, ddClient.initTokenParams(), body, DDR_New.class);
|
|
|
|
-
|
|
|
|
- Map result = (Map) ddrNew.getResult();
|
|
|
|
-
|
|
|
|
- List list = UtilMap.getList(result, "page_list");
|
|
|
|
-
|
|
|
|
- if (!list.isEmpty()){
|
|
|
|
- Map formData = new HashMap();
|
|
|
|
-
|
|
|
|
- Map checkInData = (Map) list.get(0);
|
|
|
|
-
|
|
|
|
- Long checkinTime = UtilMap.getLong(checkInData, "checkin_time");
|
|
|
|
- String detailPlace = UtilMap.getString(checkInData, "detail_place");
|
|
|
|
- String remark = UtilMap.getString(checkInData,"remark");
|
|
|
|
-
|
|
|
|
- formData.put("employeeField_mbypt8ro",Arrays.asList(staffId));//签到人
|
|
|
|
- formData.put("textField_mbyq1cji",userName);//签到人-文本
|
|
|
|
- formData.put("dateField_mbrb3qfy",checkinTime);//签到时间
|
|
|
|
- formData.put("textField_mbrb3qfx",detailPlace);//签到地点
|
|
|
|
- formData.put("textareaField_mbypt8rp",remark);//备注
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
- String formattedDate = sdf.format(Long.parseLong(timeStamp));
|
|
|
|
- formData.put("textField_mbrbdyl4","签到人:" +userName + ",签到时间:" + formattedDate + ",签到地点:" + detailPlace);//标题
|
|
|
|
|
|
+ int retryCount = 0;
|
|
|
|
+ int maxRetries = 3;
|
|
|
|
+ while (retryCount <= maxRetries) {
|
|
|
|
+ try {
|
|
|
|
+ String timeStamp = eventJson.getString("timeStamp");//签到时间戳
|
|
|
|
+ timeStamp = roundToNearestThousand(Long.parseLong(timeStamp)) + "";
|
|
|
|
+ String staffId = eventJson.getString("StaffId");//签到人userId
|
|
|
|
+
|
|
|
|
+ //获取签到数据
|
|
|
|
+ Map body = new HashMap();
|
|
|
|
+ body.put("cursor",0);
|
|
|
|
+ body.put("size",100);
|
|
|
|
+ body.put("start_time",timeStamp);
|
|
|
|
+ body.put("end_time",timeStamp);
|
|
|
|
+ body.put("userid_list",staffId);
|
|
|
|
+
|
|
|
|
+ //查询用户详情
|
|
|
|
+ DDR_New ddrNew1 = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/v2/user/get", null, ddClient.initTokenParams(), UtilMap.map("userid", staffId), DDR_New.class);
|
|
|
|
+ Map result1 = (Map) ddrNew1.getResult();
|
|
|
|
+ String userName = UtilMap.getString(result1, "name");
|
|
|
|
+
|
|
|
|
+ //查询用户考勤数据
|
|
|
|
+ DDR_New ddrNew = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/checkin/record/get", null, ddClient.initTokenParams(), body, DDR_New.class);
|
|
|
|
+ Map result = (Map) ddrNew.getResult();
|
|
|
|
+ List list = UtilMap.getList(result, "page_list");
|
|
|
|
+
|
|
|
|
+ if (!list.isEmpty()){
|
|
|
|
+ Map formData = new HashMap();
|
|
|
|
+ Map checkInData = (Map) list.get(0);
|
|
|
|
+ Long checkinTime = UtilMap.getLong(checkInData, "checkin_time");
|
|
|
|
+ String detailPlace = UtilMap.getString(checkInData, "detail_place");
|
|
|
|
+ String remark = UtilMap.getString(checkInData,"remark");
|
|
|
|
+ formData.put("employeeField_mbypt8ro",Arrays.asList(staffId));//签到人
|
|
|
|
+ formData.put("textField_mbyq1cji",userName);//签到人-文本
|
|
|
|
+ formData.put("dateField_mbrb3qfy",checkinTime);//签到时间
|
|
|
|
+ formData.put("textField_mbrb3qfx",detailPlace);//签到地点
|
|
|
|
+ formData.put("textareaField_mbypt8rp",remark);//备注
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
+ String formattedDate = sdf.format(Long.parseLong(timeStamp));
|
|
|
|
+ formData.put("textField_mbrbdyl4","签到人:" +userName + ",签到时间:" + formattedDate + ",签到地点:" + detailPlace);//标题
|
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
|
+ .formUuid("FORM-D4389CDAD1704F959E9D38CB64927AD8PKCH")
|
|
|
|
+ .formDataJson(JSONObject.toJSONString(formData))
|
|
|
|
+ .build(),YDConf.FORM_OPERATION.create);
|
|
|
|
+ }
|
|
|
|
|
|
- ydClient.operateData(YDParam.builder()
|
|
|
|
- .formUuid("FORM-D4389CDAD1704F959E9D38CB64927AD8PKCH")
|
|
|
|
- .formDataJson(JSONObject.toJSONString(formData))
|
|
|
|
- .build(),YDConf.FORM_OPERATION.create);
|
|
|
|
|
|
+ break;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ if (retryCount < maxRetries){
|
|
|
|
+ retryCount++;
|
|
|
|
+ log.info("第{}次重试,异常信息:{}", retryCount, e.getMessage());
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(1000 * retryCount); // 指数退避
|
|
|
|
+ } catch (InterruptedException ie) {
|
|
|
|
+ Thread.currentThread().interrupt();// 如果线程在等待期间被中断,恢复中断状态
|
|
|
|
+ throw new RuntimeException("Request interrupted", ie);// 抛出运行时异常,终止重试
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ throw new RuntimeException("超出最大重试次数,异常信息:" + e.getMessage());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|