|
@@ -1,10 +1,14 @@
|
|
|
package com.malk.lanyun.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.malk.lanyun.service.DingTalkService;
|
|
|
import com.malk.lanyun.service.SyncAssetsService;
|
|
|
import com.malk.server.aliwork.YDConf;
|
|
|
import com.malk.server.aliwork.YDParam;
|
|
|
+import com.malk.server.dingtalk.DDConf;
|
|
|
import com.malk.service.aliwork.YDClient;
|
|
|
+import com.malk.service.dingtalk.DDClient;
|
|
|
+import com.malk.service.dingtalk.DDClient_Contacts;
|
|
|
import com.malk.utils.UtilDateTime;
|
|
|
import com.malk.utils.UtilMap;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -12,10 +16,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.chrono.ChronoLocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -72,4 +78,129 @@ public class SyncAssetsImpl implements SyncAssetsService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DingTalkService dingTalkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DDClient ddClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DDConf ddConf;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取在职人员 与当月入职人员信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void SynDingUserNumber() {
|
|
|
+ Number nextCursor = 0; // 初始的offset值设置为"0"
|
|
|
+ List<String> allUserIds = new ArrayList<>();
|
|
|
+ while (nextCursor != null ) {
|
|
|
+ Map userIds = dingTalkService.getAllUserIdInfo(ddClient.getAccessToken(),"2,3,5",nextCursor,50);
|
|
|
+ //获取在职人员信息
|
|
|
+ List<String> userIdList = (List<String>) userIds.get("data_list");
|
|
|
+ Number newNextCursor = (Number) userIds.getOrDefault("next_cursor", null);
|
|
|
+ if (!userIdList.isEmpty()) {
|
|
|
+ allUserIds.addAll(userIdList);
|
|
|
+ }
|
|
|
+ // 更新nextCursor为下一次请求的offset
|
|
|
+ nextCursor = newNextCursor;
|
|
|
+ }
|
|
|
+ // 获取当前日期
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ // 获取当月的第一天
|
|
|
+ LocalDate firstDayOfMonth = today.withDayOfMonth(1);
|
|
|
+
|
|
|
+ // 获取当月的最后一天
|
|
|
+ LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth());
|
|
|
+
|
|
|
+ log.info("在职人员数量:"+allUserIds.size());
|
|
|
+
|
|
|
+ if (allUserIds.size()>0){
|
|
|
+ for (String strUserId:allUserIds){
|
|
|
+ Map hashMap = new HashMap();
|
|
|
+ List<Map> userinfo = dingTalkService.getDDUserInfoById(ddClient.getAccessToken(), strUserId, ddConf.getAgentId());
|
|
|
+ List<Map> dataList = (List<Map>) userinfo.get(0).get("field_data_list");
|
|
|
+ for (Map map:dataList){
|
|
|
+ //成员
|
|
|
+ hashMap.put("employeeField_lwyn4q8k",strUserId);
|
|
|
+ // 入职时间
|
|
|
+ if (map.get("field_code").equals("sys00-confirmJoinTime")) {
|
|
|
+ List<Map> mapList = (List<Map>) map.get("field_value_list");
|
|
|
+ if (!mapList.isEmpty() && mapList.get(0).containsKey("value")) {
|
|
|
+ // 假设value是一个可以转换为LocalDate的字符串
|
|
|
+ Object valueObj = mapList.get(0).get("value");
|
|
|
+ LocalDate joinDate = null;
|
|
|
+ if (valueObj instanceof LocalDate) {
|
|
|
+ joinDate = (LocalDate) valueObj;
|
|
|
+ } else if (valueObj instanceof String) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ joinDate = LocalDate.parse((String) valueObj, formatter);
|
|
|
+ }
|
|
|
+ if (joinDate != null) {
|
|
|
+ // 判断入职为当月
|
|
|
+ if (!joinDate.isBefore(ChronoLocalDate.from(firstDayOfMonth.atStartOfDay())) && !joinDate.isAfter(ChronoLocalDate.from(lastDayOfMonth.atStartOfDay()))) {
|
|
|
+ hashMap.put("dateField_m0htvxao", UtilDateTime.parse(String.valueOf(today),"yyyy-MM"));
|
|
|
+ hashMap.put("textField_m0htvxal",allUserIds.size());
|
|
|
+ hashMap.put("employeeField_m0htvxav",strUserId);
|
|
|
+ hashMap.put("dateField_m0htvxaw",UtilDateTime.parse(String.valueOf(joinDate),"yyyy-MM-dd"));
|
|
|
+
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
+ .appType("APP_ERBDTFS82HOVBPL3NFH0")
|
|
|
+ .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
|
|
|
+ .formUuid("FORM-C785CE8A85AF4EF79664775A60F3527FXUBX")
|
|
|
+ .formDataJson(JSON.toJSONString(hashMap))
|
|
|
+ .build(), YDConf.FORM_OPERATION.create);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DDClient_Contacts ddClientContacts;
|
|
|
+ @Override
|
|
|
+ public void SynDingLeaveUserNumber() {
|
|
|
+
|
|
|
+
|
|
|
+ Number nextToken = 0; // 初始的offset值设置为"0"
|
|
|
+
|
|
|
+ // 创建一个 LocalDate 对象
|
|
|
+ LocalDate localDate = LocalDate.now(); // 获取当前日期
|
|
|
+
|
|
|
+ // 获取当月的第一天
|
|
|
+ LocalDate firstDayOfMonth = localDate.withDayOfMonth(1);
|
|
|
+
|
|
|
+ // 将 LocalDate 转换为 Date
|
|
|
+ Date date = Date.from(firstDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+ Map param = UtilMap.map("nextToken, maxResults", nextToken, 50);
|
|
|
+
|
|
|
+ //查询离职日期 传入开始时间,结束时间默认为当前日期。
|
|
|
+ List<Map<String, String>> mapList = ddClientContacts.getLeaveEmployeeRecords(ddClient.getAccessToken(),date,param);
|
|
|
+
|
|
|
+ log.info("userIds:"+mapList);
|
|
|
+
|
|
|
+ Map hashMap = new HashMap();
|
|
|
+ for (Map<String, String> record : mapList) {
|
|
|
+
|
|
|
+ hashMap.put("dateField_m0htvxao", UtilDateTime.parse(String.valueOf(localDate),"yyyy-MM"));
|
|
|
+ hashMap.put("employeeField_m0htvxav",record.get("userId"));
|
|
|
+ hashMap.put("dateField_m0htvxaw",UtilDateTime.parse(String.valueOf(record.get("leaveTime")),"yyyy-MM-dd"));
|
|
|
+
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
+ .appType("APP_ERBDTFS82HOVBPL3NFH0")
|
|
|
+ .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
|
|
|
+ .formUuid("FORM-6F080FBEAF924FB8B4412010434966BE4DPF")
|
|
|
+ .formDataJson(JSON.toJSONString(hashMap))
|
|
|
+ .build(), YDConf.FORM_OPERATION.create);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|