|
|
@@ -1,6 +1,7 @@
|
|
|
package com.malk.mc.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.io.IORuntimeException;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.crypto.digest.MD5;
|
|
|
@@ -33,6 +34,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.DecimalFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalTime;
|
|
|
import java.util.*;
|
|
|
@@ -975,6 +977,76 @@ public class McYdServiceImpl implements McYdService {
|
|
|
return McR.success();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getCheckInData(JSONObject eventJson) {
|
|
|
+ MDC.put("MDC_KEY_PID","1000");
|
|
|
+
|
|
|
+ int retryCount = 0;
|
|
|
+ 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) {
|
|
|
+ try {
|
|
|
+ //获取签到数据
|
|
|
+ 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(timeStamp);
|
|
|
+ formData.put("textField_mbrbdyl4","签到人:" +userName + ",签到时间:" + formattedDate + ",签到地点:" + detailPlace);//标题
|
|
|
+
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
+ .formUuid("FORM-94F65C7405A24E20AE70987AD1C39082SLIB")
|
|
|
+ .formDataJson(JSONObject.toJSONString(formData))
|
|
|
+ .build(),YDConf.FORM_OPERATION.create);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (retryCount < maxRetries){
|
|
|
+ retryCount++;
|
|
|
+ log.info("eventId:{},第{}次重试,异常信息:{}",eventId, retryCount, e.getMessage());
|
|
|
+ try {
|
|
|
+ Thread.sleep(5000);
|
|
|
+ } catch (InterruptedException ie) {
|
|
|
+ Thread.currentThread().interrupt();// 如果线程在等待期间被中断,恢复中断状态
|
|
|
+ throw new RuntimeException("Request interrupted", ie);// 抛出运行时异常,终止重试
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ throw new RuntimeException("eventId:" + eventId + ",超出最大重试次数,异常信息:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public String sendNotification(String access_token, List<String> userid_list, List<String> dept_id_list, boolean to_all_user, Map msg, String agent_id) {
|
|
|
Map body = UtilMap.map("agent_id, to_all_user, msg", new Object[]{agent_id, to_all_user, msg});
|
|
|
if (UtilList.isNotEmpty(userid_list)) {
|
|
|
@@ -988,6 +1060,17 @@ public class McYdServiceImpl implements McYdService {
|
|
|
return ddr.getTask_id();
|
|
|
}
|
|
|
|
|
|
+ public long roundToNearestThousand(long timestamp) {
|
|
|
+ // 将时间戳除以1000,得到秒级部分(带毫秒的小数部分)
|
|
|
+ double seconds = timestamp / 1000.0;
|
|
|
+
|
|
|
+ // 对秒级部分的个位数进行四舍五入(即对毫秒的千位四舍五入)
|
|
|
+ long roundedSeconds = Math.round(seconds);
|
|
|
+
|
|
|
+ // 将四舍五入后的秒级部分转换回毫秒时间戳
|
|
|
+ return roundedSeconds * 1000;
|
|
|
+ }
|
|
|
+
|
|
|
@Async
|
|
|
@Override
|
|
|
public void batchUpdateSpecifiedQuantityData(Map map) {
|