123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- package com.malk.kaiyue.service.impl;
- import cn.hutool.core.collection.CollectionUtil;
- import cn.hutool.core.date.DateTime;
- import cn.hutool.core.date.DateUtil;
- import com.malk.kaiyue.service.KYNTService;
- import com.malk.kaiyue.service.KYSXService;
- import com.malk.server.common.McR;
- import com.malk.server.dingtalk.DDConf;
- import com.malk.server.dingtalk.DDR;
- import com.malk.server.dingtalk.DDR_New;
- import com.malk.service.dingtalk.DDClient;
- import com.malk.utils.UtilHttp;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- import java.util.stream.Collectors;
- @Slf4j
- @Service
- public class KYSXServiceImpl implements KYSXService {
- @Autowired
- private DDClient ddClient;
- @Autowired
- private DDConf ddConf;
- @Value("${dingtalk_sx.appKey}")
- private String appKey;
- @Value("${dingtalk_sx.appSecret}")
- private String appSecret;
- @Value("${dingtalk_sx.agentId}")
- private String agentId;
- @Value("${dingtalk_sx.operator}")
- private String opUserId;
- //绍兴凯悦-年假(测)
- // private static final String LEAVE_CODE = "1eecac0a-18b3-4596-b696-ba60d71c8306";
- //绍兴凯悦-年假
- private static final String LEAVE_CODE = "597d0415-b863-4b16-bc3a-3a5e9d9d2b77";
- //绍兴凯悦-调休假
- private static final String COMPENSATORY_LEAVE_CODE = "4429b500-6492-403e-891b-6aeca4590bef";
- @Override
- public List<Map> getEmployeeRosterInfo(Map<String, Object> map) {
- //获取accessToken
- String access_token = ddClient.getAccessToken(appKey,appSecret);
- //获取员工花名册字段信息
- if (Objects.nonNull(map)){
- DDR ddr = (DDR) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/list", null, DDConf.initTokenParams(access_token), map, DDR.class);
- return (List<Map>)ddr.getResult();
- }
- return null;
- }
- @Override
- public List<String> getEmployeeUserId() {
- Map<String,Object> map = new HashMap<>();
- //在职员工状态筛选,可以查询多个状态。不同状态之间使用英文逗号分隔。
- //2:试用期 3:正式 5:待离职 -1:无状态
- map.put("status_list","2,3");
- //分页游标,从0开始。根据返回结果里的next_cursor是否为空来判断是否还有下一页,且再次调用时offset设置成next_cursor的值。
- map.put("offset",0);
- //分页大小,最大50。
- map.put("size",50);
- //获取员工userId集合
- List<String> userIdList = new ArrayList<>();
- getUserIdList(map,userIdList);
- return userIdList;
- }
- public List<String> getUserIdList(Map map,List<String> userIdList){
- //获取accessToken
- String access_token = ddClient.getAccessToken(appKey,appSecret);
- //调用钉钉接口获取在职员工userId集合
- DDR ddr = (DDR) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/queryonjob", null, DDConf.initTokenParams(access_token), map, DDR.class);
- Map result = (Map) ddr.getResult();
- //将返回结果里的data_list合并到userIdList
- userIdList.addAll((List<String>) result.get("data_list"));
- //判断是否还有下一页
- if (Objects.nonNull(result.get("next_cursor"))){
- map.put("offset",result.get("next_cursor"));
- //递归将集合合并到userIdList
- getUserIdList(map,userIdList);
- }
- return userIdList;
- }
- //保存5s内已处理的更新假期余额事件
- private Map<String, Long> bodyList = new HashMap<>();
- @Async
- public Map getEmployeeAnnualLeaveNum(Map<String, Object> map) {
- //获取accessToken
- String access_token = ddClient.getAccessToken(appKey,appSecret);
- //查询接口body添加参数
- //field_filter_list:要查询字段(花名册字段信息参考:https://open.dingtalk.com/document/orgapp/roster-custom-field-business-code)
- //agentid:企业内部应用AgentId
- map.put("field_filter_list","sys00-name,sys01-positionLevel,sys01-employeeType,9bd53d78-3008-4927-aef8-152a1b44f29b,434d3cd0-3b02-4250-9e7d-7748c31efa84,sys00-confirmJoinTime,sys02-joinWorkingTime,sys05-nowContractStartTime,sys05-contractRenewCount");
- map.put("agentid",agentId);
- List<Map> errorList = new ArrayList<>();
- List<Map> successList = new ArrayList<>();
- //获取员工花名册字段信息
- if (Objects.nonNull(map)){
- DDR ddr = (DDR) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/list", null, DDConf.initTokenParams(access_token), map, DDR.class);
- List<Map> employeeData = (List<Map>) ddr.getResult();
- //遍历员工信息
- for (Map data : employeeData) {
- String userId = data.get("userid").toString();
- try {
- //首次参加工作日期(计算工龄)
- String joinWorkingTime = "";
- //入职日期
- String confirmJoinTime = "";
- //职级
- String positionLevel = "";
- //原职级
- String oldPositionLevel = "";
- //升职日期
- String promotionTime = "";
- //姓名
- String name = "";
- //现合同开始日期
- String contractStartTime = "";
- //合同续签次数
- int contractRenewCount = 0;
- //员工类型
- String employeeType = "";
- List<Map> fieldDataList = (List<Map>) data.get("field_data_list");
- for (Map fieldData : fieldDataList) {
- String fieldCode = fieldData.get("field_code").toString();
- List<Map> fieldValueList = (List<Map>) fieldData.get("field_value_list");
- String value = getString(fieldValueList.get(0).get("value"));
- String label = getString(fieldValueList.get(0).get("label"));
- switch (fieldCode){
- case "sys02-joinWorkingTime": joinWorkingTime = value;break;
- case "sys00-confirmJoinTime": confirmJoinTime = value;break;
- case "sys01-positionLevel": positionLevel = value;break;
- case "9bd53d78-3008-4927-aef8-152a1b44f29b": oldPositionLevel = label;break;
- case "434d3cd0-3b02-4250-9e7d-7748c31efa84": promotionTime = value;break;
- case "sys00-name": name = value;break;
- case "sys05-nowContractStartTime": contractStartTime = value;break;
- case "sys05-contractRenewCount": contractRenewCount = value.equals("") ? 0 : Integer.valueOf(value);break;
- case "sys01-employeeType": employeeType = label;break;
- default:break;
- }
- }
- if (employeeType.equals("劳务外包") || employeeType.equals("实习") || employeeType.equals("兼职")){
- Map successMap = new HashMap();
- successMap.put(userId,"姓名:"+name+",劳务外包、实习、兼职员工不发放年假");
- successList.add(successMap);
- continue;
- }
- //若没有原职级 则默认原职级是现职级
- if ("".equals(oldPositionLevel)){
- oldPositionLevel = positionLevel;
- }
- //若没有升职日期 则默认当天是升职日期
- if ("".equals(promotionTime)){
- promotionTime = confirmJoinTime;
- }
- //若没有现合同开始日期 则默认现合同开始日期是入职日期
- if ("".equals(contractStartTime)){
- contractStartTime = confirmJoinTime;
- }
- //若没有首次参加工作日期 则默认入职日期是首次参加工作日期
- if ("".equals(joinWorkingTime)){
- joinWorkingTime = confirmJoinTime;
- }
- if ("".equals(confirmJoinTime) || "".equals(positionLevel) || "".equals(name)){
- Map errorMap = new HashMap();
- errorMap.put(userId,"参数缺失!");
- errorList.add(errorMap);
- // log.info("更新员工userid:{} 参数缺失!", userId);
- continue;
- }
- //旧合同续签次数等于合同续签数-1 最小为0
- int oldContractRenewCount = Math.max(0, contractRenewCount - 1);
- //假期有效开始日期为当年1月1日
- DateTime beginDate = DateUtil.beginOfYear(new Date());
- //假期有效截至日期为当年12月31日
- DateTime endDate = DateUtil.endOfYear(new Date());
- //当年天数
- int yearDays = DateUtil.dayOfYear(endDate);
- //工龄(年) 计算规则:首次工作时间至当年一月一日 数值向下取整
- int workAge =(int) (DateUtil.betweenYear(DateUtil.parse(joinWorkingTime), beginDate, true));
- if (DateUtil.dayOfYear(DateUtil.parse(joinWorkingTime)) != 1 && workAge > 0){
- workAge --;
- }
- System.out.println("截至今年1月1日,工龄为:"+workAge + "年");
- //年假数
- double yearLeave = getLeaveNum(confirmJoinTime,beginDate,endDate,promotionTime,contractStartTime,oldPositionLevel,positionLevel,workAge,oldContractRenewCount,contractRenewCount,yearDays);
- //年假小数
- double yearLeaveDecimalPart = yearLeave - (int) yearLeave;
- if (yearLeaveDecimalPart < 0.25){
- yearLeave = (int) yearLeave;
- }else if (yearLeaveDecimalPart < 0.75){
- yearLeave = (int) yearLeave + 0.5;
- }else if (yearLeaveDecimalPart < 1){
- yearLeave = (int) yearLeave + 1;
- }
- //查询出用户消费年假记录 当返回leaveRecords中calType为null或不返回该字段则为请假消耗 将计算出的年假数减去请假消耗的数量
- Map body = new HashMap();
- body.put("opUserId",opUserId);
- body.put("leaveCode",LEAVE_CODE);
- body.put("userIds",new String[]{userId});
- body.put("pageNumber",0);
- body.put("pageSize",50);
- DDR_New useDdr = (DDR_New) UtilHttp.doPost("https://api.dingtalk.com/v1.0/attendance/vacations/records/query", DDConf.initTokenHeader(access_token), null, body, DDR_New.class);
- Map useResult = (Map) useDdr.getResult();
- List<Map> useList = (List<Map>) useResult.get("leaveRecords");
- Double useLeaveNum = 0d;
- if (Objects.nonNull(useList) && !useList.isEmpty()){
- for (Map use : useList) {
- //判断是否为今年请假
- DateTime gmtCreate = DateUtil.date((long) use.get("gmtCreate"));
- if (DateUtil.year(gmtCreate) == DateUtil.year(new Date())){
- //判断是否为正常请假而不是接口测试或期初假期发放
- if (Objects.nonNull(use.get("leaveReason"))){
- if (!"接口年假发放".equals(use.get("leaveReason").toString()) && !"期初假期发放".equals(use.get("leaveReason").toString())){
- //若是请假消耗或管理员手动减少
- if (use.containsKey("calType") && Objects.nonNull(use.get("calType"))){
- if ("delete".equals(use.get("calType").toString())){
- useLeaveNum += (int) use.get("recordNumPerDay");
- }
- }
- /*if (!use.containsKey("calType") || Objects.isNull(use.get("calType")) || "delete".equals(use.get("calType").toString())){
- useLeaveNum += (int) use.get("recordNumPerDay") / 100;
- }*/
- //注:若是管理员手动增加 则假期余额会多出一个高级假期记录增加的假期天数 最终会在设置的假期余额的基础上加上这些天数
- //故此处手动新增的假期余额不做处理
- }
- }
- }
- }
- }
- //实际年假数
- double realYearLeave = (yearLeave * 100 - useLeaveNum) < 0 ? 0 : (yearLeave * 100 - useLeaveNum);
- //更新假期余额接口的body
- Map<String,Object> updateBody = new HashMap<>();
- Map<String,Object> leave_quotas = new HashMap<>();
- //额度有效期开始时间,毫秒级时间戳
- leave_quotas.put("start_time",beginDate.getTime());
- //额度有效期结束时间,毫秒级时间戳。
- leave_quotas.put("end_time",endDate.getTime());
- //操作原因
- leave_quotas.put("reason","接口年假发放");
- //以天计算的额度总数 假期类型按天计算时,该值不为空且按百分之一天折算。 例如:1000=10天。
- leave_quotas.put("quota_num_per_day",(int) realYearLeave );
- //以小时计算的额度总数 假期类型按小时,计算该值不为空且按百分之一小时折算。例如:1000=10小时。
- leave_quotas.put("quota_num_per_hour",0);
- //额度所对应的周期,格式必须是"yyyy",例如"2021"
- leave_quotas.put("quota_cycle",DateUtil.year(new Date())+"");
- //自定义添加的假期类型:年假开发测试的leave_code
- leave_quotas.put("leave_code",LEAVE_CODE);
- //要更新的员工的userId
- leave_quotas.put("userid",userId);
- updateBody.put("leave_quotas",leave_quotas);
- //当前企业内拥有OA审批应用权限的管理员的userId
- updateBody.put("op_userid",opUserId);
- String bodyStr = yearLeave + userId;
- // 检查更新事件是否已经处理过,如果是,则忽略该更新
- if (isUpdateLeave(bodyStr)) {
- log.info("更新事件已处理,忽略该回调...");
- return null;
- }
- // 将更新和当前时间戳添加到已处理集合中
- long currentTime = System.currentTimeMillis();
- bodyList.put(bodyStr, currentTime);
- //更新假期余额
- UtilHttp.doPost("https://oapi.dingtalk.com/topapi/attendance/vacation/quota/update", null, DDConf.initTokenParams(access_token), updateBody, DDR.class);
- Map successMap = new HashMap();
- successMap.put(userId,"姓名:"+name+",职级:" + positionLevel+",原职级:" + oldPositionLevel+",入职日期:" + confirmJoinTime + ",升职日期:" + promotionTime + ",年假数:"+ realYearLeave + ",开始日期:" + beginDate+",截止日期:" + endDate);
- successList.add(successMap);
- }catch (Exception e){
- log.info("更新员工年假失败:{}",e);
- Map errorMap = new HashMap();
- errorMap.put(userId,e.getMessage());
- errorList.add(errorMap);
- }
- }
- }
- log.info("更新失败列表:{}",errorList);
- log.info("更新成功列表:{}",successList);
- Map result = new HashMap();
- result.put("errorList",errorList);
- result.put("successList",successList);
- return result;
- }
- private String getString(Object label) {
- return Objects.isNull(label) ? "" : label.toString();
- }
- private double getLeaveNum(String confirmJoinTime,Date beginDate,Date endDate,String promotionTime,String owContractStartTime,String oldPositionLevel,String positionLevel,int workAge,int oldContractRenewCount,int contractRenewCount,int yearDays) {
- double yearLeave = 0.0;
- long day1 = 0;
- long day2 = 0;
- long day3 = 0;
- //判断员工是否当年新入职
- if (DateUtil.year(DateUtil.parse(confirmJoinTime)) == DateUtil.year(new Date())){
- beginDate = DateUtil.parse(confirmJoinTime);
- }
- //判断员工是否当年升职
- if (DateUtil.year(DateUtil.parse(promotionTime)) == DateUtil.year(new Date())){
- //判断现合同开始日期是否当年
- if (DateUtil.year(DateUtil.parse(owContractStartTime)) == DateUtil.year(new Date())){
- //判断现合同开始日期和升职日期先后顺序
- if (DateUtil.parse(owContractStartTime).before(DateUtil.parse(promotionTime))){
- day1 = DateUtil.betweenDay(beginDate,DateUtil.parse(owContractStartTime),true);
- day2 = DateUtil.betweenDay(DateUtil.parse(owContractStartTime),DateUtil.parse(promotionTime),true);
- day3 = DateUtil.betweenDay(DateUtil.parse(promotionTime),endDate,true);
- yearLeave = (double) (day1 * getAnnualLeaveBaseNum(oldPositionLevel,workAge,oldContractRenewCount) + day2 * getAnnualLeaveBaseNum(oldPositionLevel,workAge,contractRenewCount) + day3 * getAnnualLeaveBaseNum(positionLevel,workAge,contractRenewCount)) / yearDays;
- }else {
- day1 = DateUtil.betweenDay(beginDate,DateUtil.parse(promotionTime),true);
- day2 = DateUtil.betweenDay(DateUtil.parse(promotionTime),DateUtil.parse(owContractStartTime),true);
- day3 = DateUtil.betweenDay(DateUtil.parse(owContractStartTime),endDate,true);
- yearLeave = (double) (day1 * getAnnualLeaveBaseNum(oldPositionLevel,workAge,oldContractRenewCount) + day2 * getAnnualLeaveBaseNum(positionLevel,workAge,oldContractRenewCount) + day3 * getAnnualLeaveBaseNum(positionLevel,workAge,contractRenewCount)) / yearDays;
- }
- }else {
- day1 = DateUtil.betweenDay(beginDate,DateUtil.parse(promotionTime),true);
- day2 = DateUtil.betweenDay(DateUtil.parse(promotionTime),endDate,true);
- yearLeave = (double) (day1 * getAnnualLeaveBaseNum(oldPositionLevel,workAge,contractRenewCount) + day2 * getAnnualLeaveBaseNum(positionLevel,workAge,contractRenewCount)) / yearDays;
- }
- }else {
- //判断现合同开始日期是否当年
- if (DateUtil.year(DateUtil.parse(owContractStartTime)) == DateUtil.year(new Date())){
- day1 = DateUtil.betweenDay(beginDate,DateUtil.parse(owContractStartTime),true);
- day2 = DateUtil.betweenDay(DateUtil.parse(owContractStartTime),endDate,true);
- yearLeave = (double) (day1 * getAnnualLeaveBaseNum(positionLevel,workAge,oldContractRenewCount) + day2 * getAnnualLeaveBaseNum(positionLevel,workAge,contractRenewCount)) / yearDays;
- }else {
- yearLeave = getAnnualLeaveBaseNum(positionLevel,workAge,contractRenewCount);
- }
- }
- return yearLeave;
- }
- private int getAnnualLeaveBaseNum(String positionLevel, int workAge, int contractRenewCount) {
- //法定年假
- int legalAnnualLeave = 0;
- //福利年假
- int welfareAnnualLeave = 0;
- //根据职级、工龄和合同续签数计算年假基数
- if (positionLevel.equals("总经理")){
- if (workAge < 10){
- legalAnnualLeave = 5;
- welfareAnnualLeave = 15;
- }else if (workAge >= 10 && workAge < 20){
- legalAnnualLeave = 10;
- welfareAnnualLeave = 10;
- }else if (workAge >= 20){
- legalAnnualLeave = 15;
- welfareAnnualLeave = 5;
- }
- }else if (positionLevel.equals("部门总监") || positionLevel.equals("经理级")){
- if (workAge < 10){
- legalAnnualLeave = 5;
- welfareAnnualLeave = 7 + 2 * (Math.min(contractRenewCount, 2));
- }else if (workAge >= 10 && workAge < 20){
- legalAnnualLeave = 10;
- welfareAnnualLeave = 2 + 2 * (Math.min(contractRenewCount, 2));
- }else if (workAge >= 20){
- legalAnnualLeave = 15;
- welfareAnnualLeave = 1;
- }
- }else if (positionLevel.equals("主管")){
- if (workAge < 10){
- legalAnnualLeave = 5;
- welfareAnnualLeave = 5 + 2 * (Math.min(contractRenewCount, 2));
- }else if (workAge >= 10 && workAge < 20){
- legalAnnualLeave = 10;
- welfareAnnualLeave = 0 + 2 * (Math.min(contractRenewCount, 2));
- }else if (workAge >= 20){
- legalAnnualLeave = 15;
- welfareAnnualLeave = 0;
- }
- }else if (positionLevel.equals("员工")){
- if (workAge < 10){
- legalAnnualLeave = 5;
- welfareAnnualLeave = 3 + 2 * (Math.min(contractRenewCount, 2));
- }else if (workAge >= 10 && workAge < 20){
- legalAnnualLeave = 10;
- welfareAnnualLeave = 0 + 2 * (Math.min(contractRenewCount, 1));
- }else if (workAge >= 20){
- legalAnnualLeave = 15;
- welfareAnnualLeave = 0;
- }
- }else {
- legalAnnualLeave = 0;
- welfareAnnualLeave = 0;
- }
- int annualLeave = legalAnnualLeave + welfareAnnualLeave;
- return annualLeave;
- }
- @Override
- public McR updateEmployeeAnnualLeaveNum() {
- //获取员工userId集合
- List<String> userIdList = getEmployeeUserId();
- //遍历集合给所有员工更新年假余额
- List<Map> result = new ArrayList<>();
- if (Objects.nonNull(userIdList) && !userIdList.isEmpty()){
- Map map = new HashMap();
- //将userIdList拆分成50长度的多个数组
- List<List<String>> userIdListList = CollectionUtil.splitList(userIdList,50);
- for (List<String> userIdList1 : userIdListList) {
- map.put("userid_list",String.join(",",userIdList1));
- result.add(getEmployeeAnnualLeaveNum(map));
- }
- log.info("result:{}",result);
- }
- return McR.success();
- }
- @Override
- public Map getUserLeaveInfo(String userId) {
- long currentTime = System.currentTimeMillis();
- Map leaveMap = new HashMap();
- //获取员工调休假余额
- List<Map> leaveQuotasList = new ArrayList<>();
- getLeaveNum(COMPENSATORY_LEAVE_CODE,userId,0,50,leaveQuotasList);
- //查询员工调休假余额
- BigDecimal compensatoryLeaveNum = new BigDecimal(0.00);
- if (Objects.nonNull(leaveQuotasList)){
- for (Map leaveQuotas : leaveQuotasList) {
- if ((long) leaveQuotas.get("start_time") <= currentTime && currentTime <= (long) leaveQuotas.get("end_time")){
- if (Objects.isNull(leaveQuotas.get("quota_num_per_day")) && Objects.nonNull(leaveQuotas.get("quota_num_per_hour"))){
- compensatoryLeaveNum = compensatoryLeaveNum.add(new BigDecimal(String.valueOf(leaveQuotas.get("quota_num_per_hour"))).divide(new BigDecimal(100)));
- }
- if (Objects.nonNull(leaveQuotas.get("used_num_per_hour"))){
- compensatoryLeaveNum = compensatoryLeaveNum.subtract(new BigDecimal(String.valueOf(leaveQuotas.get("used_num_per_hour"))).divide(new BigDecimal(100)));
- }
- }
- }
- }
- if (compensatoryLeaveNum.compareTo(new BigDecimal(80)) >= 0){
- leaveMap.put("可预支调休",80);
- leaveMap.put("实际加班小时数",compensatoryLeaveNum.subtract(new BigDecimal(80)));
- leaveMap.put("已预支调休",0);
- }else {
- leaveMap.put("可预支调休",compensatoryLeaveNum);
- leaveMap.put("实际加班小时数",0);
- leaveMap.put("已预支调休",new BigDecimal(80).subtract(compensatoryLeaveNum));
- }
- return leaveMap;
- }
- private List<Map> getLeaveNum(String leave_code,String userId,int offset,int size,List<Map> leaveQuotasList) {
- String access_token = ddClient.getAccessToken(appKey,appSecret);
- Map body = new HashMap();
- body.put("leave_code",leave_code);
- body.put("op_userid",opUserId);
- body.put("userids",userId);
- body.put("offset",offset);
- body.put("size",size);
- DDR_New ddrNew = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/attendance/vacation/quota/list", null, DDConf.initTokenParams(access_token), body, DDR_New.class);
- Map result = (Map) ddrNew.getResult();
- if (Objects.nonNull(result.get("leave_quotas"))){
- leaveQuotasList.addAll((List<Map>) result.get("leave_quotas"));
- }
- if ((boolean) result.get("has_more")){
- getLeaveNum(leave_code,userId,offset+size,size,leaveQuotasList);
- }
- return leaveQuotasList;
- }
- /**
- * 检查该更新事件在5s内是否处理过,应对钉钉瞬间重复回调
- *
- * @param msg 回调事件
- * @return 是否处理过
- */
- private boolean isUpdateLeave(String msg) {
- // 清理超过10s的回调事件
- long currentTime = System.currentTimeMillis();
- long expirationTime = currentTime - TimeUnit.SECONDS.toMillis(5);
- bodyList.entrySet().removeIf(entry -> entry.getValue() < expirationTime);
- return bodyList.containsKey(msg);
- }
- }
|