|
@@ -1,8 +1,450 @@
|
|
|
package com.malk.kaiyue_cd.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.malk.kaiyue_cd.service.KYCDService;
|
|
|
+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.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class KYCDServiceImpl implements KYCDService {
|
|
|
+ @Autowired
|
|
|
+ private DDClient ddClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DDConf ddConf;
|
|
|
+
|
|
|
+ //成都凯悦-年假(测试)
|
|
|
+ private static final String LEAVE_CODE = "609a84ed-54d4-4ecd-a44f-4c55b04c37ea";
|
|
|
+ //体验社-成都年假测试
|
|
|
+// private static final String LEAVE_CODE = "609a84ed-54d4-4ecd-a44f-4c55b04c37ea";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> getEmployeeUserId() {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ //在职员工状态筛选,可以查询多个状态。不同状态之间使用英文逗号分隔。
|
|
|
+ //2:试用期 3:正式 5:待离职 -1:无状态
|
|
|
+ map.put("status_list","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();
|
|
|
+ //调用钉钉接口获取在职员工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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map> getEmployeeRosterInfo(Map<String, Object> map) {
|
|
|
+ //获取accessToken
|
|
|
+ String access_token = ddClient.getAccessToken();
|
|
|
+ //获取员工花名册字段信息
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存10s内已处理的更新假期余额事件
|
|
|
+ private Map<String, Long> bodyList = new HashMap<>();
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public McR getEmployeeAnnualLeaveNum(Map<String, Object> map) {
|
|
|
+ //获取accessToken
|
|
|
+ String access_token = ddClient.getAccessToken();
|
|
|
+ //获取agentId
|
|
|
+ String agentId = ddConf.getAgentId().toString();
|
|
|
+ //获取OA管理员账号
|
|
|
+ String opUserId = ddConf.getOperator();
|
|
|
+ //查询接口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,sys00-confirmJoinTime,b433c687-c3b3-4f97-8498-d23944f3316b");
|
|
|
+ map.put("agentid",agentId);
|
|
|
+
|
|
|
+ List<String> result = 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();
|
|
|
+ //入职日期
|
|
|
+ String confirmJoinTime = "";
|
|
|
+ //职级
|
|
|
+ String positionLevel = "";
|
|
|
+ //姓名
|
|
|
+ String name = "";
|
|
|
+ //原职级
|
|
|
+ String oldPositionLevel = "";
|
|
|
+
|
|
|
+ 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");
|
|
|
+ if (Objects.nonNull(fieldValueList.get(0).get("value"))){
|
|
|
+ String value = fieldValueList.get(0).get("value").toString();
|
|
|
+ switch (fieldCode){
|
|
|
+ case "sys00-confirmJoinTime": confirmJoinTime = value;break;
|
|
|
+ case "sys01-positionLevel": positionLevel = value;break;
|
|
|
+ case "sys00-name": name = value;break;
|
|
|
+ case "b433c687-c3b3-4f97-8498-d23944f3316b": oldPositionLevel = value;break;//成都原职级
|
|
|
+// case "7482b192-9f1d-49fa-adab-6f33f7d0951e": oldPositionLevel = value;break;//高级假期原职级
|
|
|
+ default:break;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.info("更新员工年假余额:参数缺啦!");
|
|
|
+ return McR.errorParam("参数缺啦!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //若没有原职级 则默认原职级是现职级
|
|
|
+ if ("".equals(oldPositionLevel)){
|
|
|
+ oldPositionLevel = positionLevel;
|
|
|
+ }
|
|
|
+
|
|
|
+ //假期有效开始日期为当年1月1日
|
|
|
+ DateTime beginDate = DateUtil.beginOfYear(new Date());
|
|
|
+ //假期有效截至日期为当年12月31日
|
|
|
+ DateTime endDate = DateUtil.endOfYear(new Date());
|
|
|
+ //今天
|
|
|
+ DateTime today = DateUtil.date();
|
|
|
+ //当年天数
|
|
|
+ int yearDays = DateUtil.dayOfYear(endDate);
|
|
|
+ //年假
|
|
|
+ double yearLeave = 0.0;
|
|
|
+ //预支年假
|
|
|
+ double advanceLeave = 10.0;
|
|
|
+ //获取原职级年假基数
|
|
|
+ int oldPositionLevelBaseNum = getAnnualLeaveBaseNum(oldPositionLevel);
|
|
|
+ //获取现职级年假基数
|
|
|
+ int positionLevelBaseNum = getAnnualLeaveBaseNum(positionLevel);
|
|
|
+
|
|
|
+ //获取入职日期的月日
|
|
|
+ String confirmJoinMonthAndDay = confirmJoinTime.substring(5);
|
|
|
+ String year = DateUtil.year(new Date()) + "";
|
|
|
+ //今年入职周年日
|
|
|
+ DateTime anniversaryOfEmployment = DateUtil.parse(year + "-" + confirmJoinMonthAndDay);
|
|
|
+
|
|
|
+ //计算今天是入职第几周年
|
|
|
+ long anniversary = DateUtil.betweenYear(DateUtil.parse(confirmJoinTime), anniversaryOfEmployment, true) - 1;
|
|
|
+ //判断员工是否当年新入职
|
|
|
+ if (DateUtil.year(DateUtil.parse(confirmJoinTime)) == DateUtil.year(new Date())){
|
|
|
+ //分两段计算:入职日到今天,今天到年底
|
|
|
+ long day1 = DateUtil.betweenDay(DateUtil.parse(confirmJoinTime), today, true);
|
|
|
+ long day2 = DateUtil.betweenDay(today, endDate, true);
|
|
|
+ yearLeave = (double) (day1 * oldPositionLevelBaseNum + day2 * positionLevelBaseNum ) / yearDays;
|
|
|
+ }else {
|
|
|
+ //当前日期在今年入职周年日之前
|
|
|
+ if (DateUtil.compare(anniversaryOfEmployment, today) >= 0){
|
|
|
+ //获取年初到今天的天数
|
|
|
+ int day1 = DateUtil.dayOfYear(today);
|
|
|
+ //获取今天到入职周年日的天数
|
|
|
+ long day2 = DateUtil.betweenDay(today, anniversaryOfEmployment, true);
|
|
|
+ //获取入职周年日到年底的天数
|
|
|
+ long day3 = DateUtil.betweenDay(anniversaryOfEmployment, endDate, true);
|
|
|
+ //分三段计算:年初-今天,今天到入职周年日,入职周年日到年底
|
|
|
+ yearLeave = (double) (day1 * (oldPositionLevelBaseNum + anniversary > 4 ? 4 : anniversary) + day2 * (positionLevelBaseNum + anniversary > 4 ? 4 : anniversary) + day3 * (positionLevelBaseNum + (anniversary + 1) > 4 ? 4 : (anniversary + 1))) / yearDays ;
|
|
|
+ }else {
|
|
|
+ //当前日期在今年入职周年日之后
|
|
|
+ //获取年初到入职周年日的天数
|
|
|
+ int day1 = DateUtil.dayOfYear(anniversaryOfEmployment);
|
|
|
+ //获取入职周年日到今天的天数
|
|
|
+ long day2 = DateUtil.betweenDay(anniversaryOfEmployment, today, true);
|
|
|
+ //获取今天到年底的天数
|
|
|
+ long day3 = DateUtil.betweenDay(today, endDate, true);
|
|
|
+ //分三段计算:年初-入职周年日,入职周年日到今天,今天到年底
|
|
|
+ yearLeave = (double) (day1 * (oldPositionLevelBaseNum + (anniversary > 4 ? 4 : anniversary)) + day2 * (oldPositionLevelBaseNum + (anniversary + 1 > 4 ? 4 : anniversary + 1)) + day3 * (positionLevelBaseNum + (anniversary + 1 > 4 ? 4 : anniversary + 1))) / yearDays;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result.add("姓名:"+name+",职级:" + positionLevel+",原职级:" + oldPositionLevel+ ",年假基数:" + yearLeave + "天,入职日期:" + confirmJoinTime + ",开始日期:" + beginDate+",截止日期:" + endDate);
|
|
|
+
|
|
|
+ //年假小数
|
|
|
+ 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 (!"接口测试修改".equals(use.get("leaveReason").toString()) && !"期初假期发放".equals(use.get("leaveReason").toString())){
|
|
|
+ //若是请假消耗或管理员手动减少
|
|
|
+ if (!use.containsKey("calType") || Objects.isNull(use.get("calType")) || "delete".equals(use.get("calType").toString())){
|
|
|
+ useLeaveNum += (int) use.get("recordNumPerDay") / 100;
|
|
|
+ }
|
|
|
+ //注:若是管理员手动增加 则假期余额会多出一个BCXsunNm记录增加的假期天数 最终会在设置的假期余额的基础上加上这些天数
|
|
|
+ //故此处手动新增的假期余额不做处理
|
|
|
+ }
|
|
|
+ }else if (DateUtil.year(gmtCreate) == (DateUtil.year(new Date()) - 1)){
|
|
|
+ //获取去年预支年假使用情况
|
|
|
+ if ("预支年假".equals(use.get("leaveReason").toString())){
|
|
|
+ //若去年预支过则在今年预支年假数中相应减少
|
|
|
+ if (!use.containsKey("calType") || Objects.isNull(use.get("calType")) || "delete".equals(use.get("calType").toString())){
|
|
|
+ advanceLeave -= (int) use.get("recordNumPerDay") / 100;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //实际年假数
|
|
|
+ int realYearLeave = (int) ((yearLeave - useLeaveNum + advanceLeave) < 0 ? 0 : (yearLeave - useLeaveNum + advanceLeave) * 100);
|
|
|
+
|
|
|
+ //获取员工原年假余额 取较大值
|
|
|
+ Map balanceMap = new HashMap();
|
|
|
+ balanceMap.put("leave_code",LEAVE_CODE);
|
|
|
+ balanceMap.put("op_userid",opUserId);
|
|
|
+ balanceMap.put("userids",userId);
|
|
|
+ balanceMap.put("offset",0);
|
|
|
+ balanceMap.put("size",10);
|
|
|
+ DDR balanceDdr = (DDR) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/attendance/vacation/quota/list", null, DDConf.initTokenParams(access_token), balanceMap, DDR.class);
|
|
|
+ Map balanceResult = (Map) balanceDdr.getResult();
|
|
|
+ List<Map> leaveQuotas = (List<Map>) balanceResult.get("leave_quotas");
|
|
|
+ if (Objects.nonNull(leaveQuotas) && !leaveQuotas.isEmpty()){
|
|
|
+ for (Map leaveQuota : leaveQuotas) {
|
|
|
+ if (year.equals(leaveQuota.get("quota_cycle"))){
|
|
|
+ int balance = (int) leaveQuota.get("quota_num_per_day");
|
|
|
+ if (balance > realYearLeave){
|
|
|
+ realYearLeave = balance;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //更新假期余额接口的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 = realYearLeave + 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info(result.stream().collect(Collectors.joining(",")));
|
|
|
+ return McR.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public McR updateEmployeeOldPositionLevel() {
|
|
|
+ //获取accessToken
|
|
|
+ String access_token = ddClient.getAccessToken();
|
|
|
+ //获取agentId
|
|
|
+ String agentId = ddConf.getAgentId().toString();
|
|
|
+ //获取员工userId列表
|
|
|
+ List<String> userIdList = getEmployeeUserId();
|
|
|
+ for (String userId : userIdList) {
|
|
|
+ if ("344749020127590108".equals(userId)){//测试 只拿沃洲洋
|
|
|
+ //查询接口body添加参数
|
|
|
+ //field_filter_list:要查询字段(花名册字段信息参考:https://open.dingtalk.com/document/orgapp/roster-custom-field-business-code)
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("field_filter_list","sys00-name,sys01-positionLevel,b433c687-c3b3-4f97-8498-d23944f3316b");
|
|
|
+ map.put("agentid",agentId);
|
|
|
+ map.put("userid_list",userId);
|
|
|
+
|
|
|
+ List<String> result = 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> employeeDataList = (List<Map>) ddr.getResult();
|
|
|
+ List<Map> fieldDataList = (List<Map>) employeeDataList.get(0).get("field_data_list");
|
|
|
+
|
|
|
+ String positionLevel = "";
|
|
|
+ for (Map fieldData : fieldDataList) {
|
|
|
+ if ("sys01-positionLevel".equals(fieldData.get("field_code").toString())){
|
|
|
+ List<Map> fieldValueList = (List<Map>) fieldData.get("field_value_list");
|
|
|
+ if (Objects.nonNull(fieldValueList.get(0).get("value"))){
|
|
|
+ positionLevel = fieldValueList.get(0).get("value").toString();
|
|
|
+ Map updateBody = new HashMap();
|
|
|
+
|
|
|
+ Map param = new HashMap();
|
|
|
+
|
|
|
+ List<Map> groups = new ArrayList<>();
|
|
|
+
|
|
|
+ Map group = new HashMap();
|
|
|
+
|
|
|
+ List<Map> sections = new ArrayList<>();
|
|
|
+
|
|
|
+ Map oneSection = new HashMap();
|
|
|
+
|
|
|
+ List<Map> section = new ArrayList<>();
|
|
|
+ Map field = new HashMap<>();
|
|
|
+ field.put("field_code","b433c687-c3b3-4f97-8498-d23944f3316b");
|
|
|
+ field.put("value",positionLevel);
|
|
|
+ section.add(field);
|
|
|
+
|
|
|
+ oneSection.put("section",section);
|
|
|
+ oneSection.put("old_index",0);
|
|
|
+
|
|
|
+ sections.add(oneSection);
|
|
|
+
|
|
|
+ group.put("group_id","customa2cb92d853e34e1ab2cde45d4ee7cfdf");
|
|
|
+ group.put("sections",sections);
|
|
|
+
|
|
|
+ groups.add(group);
|
|
|
+
|
|
|
+ param.put("groups",groups);
|
|
|
+ param.put("userid",userId);
|
|
|
+
|
|
|
+ updateBody.put("param",param);
|
|
|
+ updateBody.put("agentid",agentId);
|
|
|
+
|
|
|
+ //设置给员工旧职级
|
|
|
+ UtilHttp.doPost("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/update", null, DDConf.initTokenParams(access_token), updateBody, DDR.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //获取员工职级
|
|
|
+
|
|
|
+ //设置职级给旧职级
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public McR updateEmployeeAnnualLeaveNum() {
|
|
|
+ //获取员工userId集合
|
|
|
+ List<String> userIdList = getEmployeeUserId();
|
|
|
+ //遍历集合给所有员工更新年假余额
|
|
|
+ if (Objects.nonNull(userIdList) && !userIdList.isEmpty()){
|
|
|
+ for (String userId : userIdList) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("userid_list",userId);
|
|
|
+ getEmployeeAnnualLeaveNum(map);
|
|
|
+ //线程等待10s
|
|
|
+ try {
|
|
|
+ log.info("线程睡眠10s");
|
|
|
+ Thread.sleep(10000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return McR.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getAnnualLeaveBaseNum(String positionLevel) {
|
|
|
+ int annualLeave = 0;
|
|
|
+ if (positionLevel.equals("MGR") || positionLevel.equals("DH") || positionLevel.equals("副主任医师")){
|
|
|
+ annualLeave = 12;
|
|
|
+ }else if (positionLevel.equals("LH") || positionLevel.equals("技术专员")){
|
|
|
+ annualLeave = 10;
|
|
|
+ }else if (positionLevel.equals("HST") || positionLevel.equals("高级管理员")){
|
|
|
+ annualLeave = 8;
|
|
|
+ }else if (positionLevel.equals("T") || positionLevel.equals("技术专家")){
|
|
|
+ annualLeave = 0;
|
|
|
+ }
|
|
|
+ return annualLeave;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查该更新事件在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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|