|
@@ -934,4 +934,173 @@ public class KYCDServiceImpl extends ServiceImpl<AdvancedLeaveMapper, AdvancedLe
|
|
|
return bodyList.containsKey(msg);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Map> getEmpLeaveList() {
|
|
|
+ //获取accessToken
|
|
|
+ String access_token = ddClient.getAccessToken(appKey, appSecret);
|
|
|
+
|
|
|
+ //获取员工userId集合
|
|
|
+ List<String> userIdList = getEmployeeUserId();
|
|
|
+
|
|
|
+ List<Map> result = new ArrayList<>();
|
|
|
+
|
|
|
+ //遍历集合给所有员工更新年假余额
|
|
|
+ if (Objects.nonNull(userIdList) && !userIdList.isEmpty()) {
|
|
|
+ Map map = new HashMap();
|
|
|
+
|
|
|
+ //查询接口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,80292628-1c88-4c25-9c40-3e91283552e7,sys01-employeeType");
|
|
|
+ map.put("agentid", agentId);
|
|
|
+
|
|
|
+ for (String userId : userIdList) {
|
|
|
+ map.put("userid_list", userId);
|
|
|
+ //获取员工花名册字段信息
|
|
|
+ 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();
|
|
|
+ String year = DateUtil.year(new Date()) + "";
|
|
|
+ //遍历员工信息
|
|
|
+ for (Map data : employeeData) {
|
|
|
+ //入职日期
|
|
|
+ String confirmJoinTime = "";
|
|
|
+ //职级
|
|
|
+ String positionLevel = "";
|
|
|
+ //姓名
|
|
|
+ String name = "";
|
|
|
+ //原职级
|
|
|
+ String oldPositionLevel = "";
|
|
|
+ //升职日期
|
|
|
+ String promotionTime = "";
|
|
|
+ //员工类型
|
|
|
+ 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");
|
|
|
+
|
|
|
+ if (Objects.nonNull(fieldValueList.get(0).get("value"))) {
|
|
|
+ String value = getString(fieldValueList.get(0).get("value"));
|
|
|
+ String label = getString(fieldValueList.get(0).get("label"));
|
|
|
+ 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;//高级假期原职级
|
|
|
+ case "80292628-1c88-4c25-9c40-3e91283552e7":
|
|
|
+ promotionTime = value;
|
|
|
+ break;//升职日期
|
|
|
+ case "sys01-employeeType":
|
|
|
+ employeeType = label;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //若员工类型为劳务外包或实习 不发放年假
|
|
|
+ if (!employeeType.equals("全职")) {
|
|
|
+ result.add(new HashMap<String, Object>() {{put(userId,"不为全职员工不发放年假");}});
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //若没有原职级 则默认原职级是现职级
|
|
|
+ if ("".equals(oldPositionLevel)) {
|
|
|
+ oldPositionLevel = positionLevel;
|
|
|
+ }
|
|
|
+ //若没有升职日期 则默认升职日期是入职日期
|
|
|
+ if ("".equals(promotionTime)) {
|
|
|
+ promotionTime = confirmJoinTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("".equals(confirmJoinTime) || "".equals(positionLevel) || "".equals(name) || "".equals(oldPositionLevel)) {
|
|
|
+ result.add(new HashMap<String, Object>() {{put(userId,"参数缺了");}});
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //假期有效开始日期为当年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;
|
|
|
+
|
|
|
+ //获取原职级年假基数
|
|
|
+ int oldPositionLevelBaseNum = getAnnualLeaveBaseNum(oldPositionLevel);
|
|
|
+ //获取现职级年假基数
|
|
|
+ int positionLevelBaseNum = getAnnualLeaveBaseNum(positionLevel);
|
|
|
+
|
|
|
+ //获取入职日期的月日
|
|
|
+ String confirmJoinMonthAndDay = confirmJoinTime.substring(5);
|
|
|
+
|
|
|
+ //今年入职周年日
|
|
|
+ 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), DateUtil.parse(promotionTime), true);
|
|
|
+ long day2 = DateUtil.betweenDay(DateUtil.parse(promotionTime), endDate, true);
|
|
|
+ yearLeave = (double) (day1 * oldPositionLevelBaseNum + day2 * positionLevelBaseNum) / yearDays;
|
|
|
+ } else {
|
|
|
+ //升职日期在今年入职周年日之前
|
|
|
+ if (DateUtil.compare(anniversaryOfEmployment, DateUtil.parse(promotionTime)) >= 0) {
|
|
|
+ //升职日期在今年
|
|
|
+ if (DateUtil.compare(DateUtil.parse(promotionTime), today) >= 0) {
|
|
|
+ //获取年初到升职日的天数
|
|
|
+ int day1 = DateUtil.dayOfYear(DateUtil.parse(promotionTime));
|
|
|
+ //获升职值日到入职周年日的天数
|
|
|
+ long day2 = DateUtil.betweenDay(DateUtil.parse(promotionTime), 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, endDate, true);
|
|
|
+ //分两段计算:年初到入职周年日,入职周年日到年底
|
|
|
+ yearLeave = (double) (day1 * (positionLevelBaseNum + (anniversary > 4 ? 4 : anniversary)) + day2 * (positionLevelBaseNum + (anniversary + 1 > 4 ? 4 : anniversary + 1))) / yearDays;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //升职日在今年入职周年日之后
|
|
|
+ //获取年初到入职周年日的天数
|
|
|
+ int day1 = DateUtil.dayOfYear(anniversaryOfEmployment);
|
|
|
+ //获取入职周年日到升职日的天数
|
|
|
+ long day2 = DateUtil.betweenDay(anniversaryOfEmployment, DateUtil.parse(promotionTime), true);
|
|
|
+ //获取升职日到年底的天数
|
|
|
+ long day3 = DateUtil.betweenDay(DateUtil.parse(promotionTime), 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ yearLeave = Math.round(yearLeave * 100.0) / 100.0;
|
|
|
+
|
|
|
+ double finalYearLeave = yearLeave;
|
|
|
+ result.add(new HashMap<String, Object>() {{put(userId, finalYearLeave);}});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|