|
@@ -2,6 +2,11 @@ package com.malk.kaiyue_cd.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.malk.kaiyue_cd.entity.AdvancedLeave;
|
|
|
+import com.malk.kaiyue_cd.mapper.AdvancedLeaveMapper;
|
|
|
import com.malk.kaiyue_cd.service.KYCDService;
|
|
|
import com.malk.server.common.McR;
|
|
|
import com.malk.server.dingtalk.DDConf;
|
|
@@ -14,18 +19,22 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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 KYCDServiceImpl implements KYCDService {
|
|
|
+public class KYCDServiceImpl extends ServiceImpl<AdvancedLeaveMapper, AdvancedLeave> implements KYCDService {
|
|
|
@Autowired
|
|
|
private DDClient ddClient;
|
|
|
|
|
|
@Autowired
|
|
|
private DDConf ddConf;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AdvancedLeaveMapper advancedLeaveMapper;
|
|
|
+
|
|
|
//成都凯悦-年假(测试)
|
|
|
private static final String LEAVE_CODE = "609a84ed-54d4-4ecd-a44f-4c55b04c37ea";
|
|
|
//体验社-成都年假测试
|
|
@@ -161,7 +170,9 @@ public class KYCDServiceImpl implements KYCDService {
|
|
|
//年假
|
|
|
double yearLeave = 0.0;
|
|
|
//预支年假
|
|
|
- double advanceLeave = 8.0;
|
|
|
+ double advanceLeave = 0.0;
|
|
|
+
|
|
|
+
|
|
|
//获取原职级年假基数
|
|
|
int oldPositionLevelBaseNum = getAnnualLeaveBaseNum(oldPositionLevel);
|
|
|
//获取现职级年假基数
|
|
@@ -252,20 +263,26 @@ public class KYCDServiceImpl implements KYCDService {
|
|
|
//注:若是管理员手动增加 则假期余额会多出一个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);
|
|
|
+ LambdaQueryWrapper<AdvancedLeave> advancedLeaveLambdaQueryWrapper = new LambdaQueryWrapper<>();;
|
|
|
+ advancedLeaveLambdaQueryWrapper.eq(AdvancedLeave::getUserId,userId)
|
|
|
+ .eq(AdvancedLeave::getValidFlag,"1");
|
|
|
+ AdvancedLeave advancedLeave = advancedLeaveMapper.selectOne(advancedLeaveLambdaQueryWrapper);
|
|
|
+ if (Objects.nonNull(advancedLeave)){
|
|
|
+ advanceLeave = advancedLeave.getLeaveNum();
|
|
|
+ }else {
|
|
|
+ advanceLeave = NumberUtil.sub(yearLeave - useLeaveNum).doubleValue() >= 8 ? 8 : NumberUtil.sub(yearLeave - useLeaveNum).intValue();
|
|
|
+ advancedLeave.setLeaveNum(Integer.parseInt(advanceLeave+""));
|
|
|
+ advancedLeave.setUserId(userId);
|
|
|
+ advancedLeave.setYear(String.valueOf(DateUtil.year(new Date())));
|
|
|
+ advancedLeaveMapper.insert(advancedLeave);
|
|
|
+ }
|
|
|
+
|
|
|
+ //年假总数
|
|
|
+ int realYearLeave = NumberUtil.sub(yearLeave, useLeaveNum, -advanceLeave).doubleValue() < 0 ? 0 : NumberUtil.sub(yearLeave, useLeaveNum, -advanceLeave).multiply(new BigDecimal(100)).intValue();
|
|
|
|
|
|
//获取员工原年假余额 取较大值
|
|
|
Map balanceMap = new HashMap();
|
|
@@ -336,7 +353,7 @@ public class KYCDServiceImpl implements KYCDService {
|
|
|
return McR.success(result);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ /* @Override
|
|
|
public McR updateEmployeeOldPositionLevel() {
|
|
|
//获取accessToken
|
|
|
String access_token = ddClient.getAccessToken();
|
|
@@ -417,7 +434,7 @@ public class KYCDServiceImpl implements KYCDService {
|
|
|
|
|
|
|
|
|
return null;
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
@Override
|
|
|
public McR updateEmployeeAnnualLeaveNum() {
|
|
@@ -441,6 +458,75 @@ public class KYCDServiceImpl implements KYCDService {
|
|
|
return McR.success();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map getUserLeaveInfo(String userId) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<AdvancedLeave> advancedLeaveLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ advancedLeaveLambdaQueryWrapper.eq(AdvancedLeave::getUserId,userId)
|
|
|
+ .eq(AdvancedLeave::getYear,String.valueOf(DateUtil.year(new Date())))
|
|
|
+ .eq(AdvancedLeave::getValidFlag,"1");
|
|
|
+ AdvancedLeave advancedLeave = advancedLeaveMapper.selectOne(advancedLeaveLambdaQueryWrapper);
|
|
|
+
|
|
|
+
|
|
|
+ Map leaveMap = new HashMap();
|
|
|
+ //查询员工年假余额
|
|
|
+ Map body1 = new HashMap();
|
|
|
+ body1.put("leave_code","609a84ed-54d4-4ecd-a44f-4c55b04c37ea");//年假(测试)
|
|
|
+ body1.put("op_userid",ddConf.getOperator());
|
|
|
+ body1.put("userids",userId);
|
|
|
+ body1.put("offset",0);
|
|
|
+ body1.put("size",10);
|
|
|
+ DDR_New ddrNew1 = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/attendance/vacation/quota/list", null, ddClient.initTokenParams(), body1, DDR_New.class);
|
|
|
+ Map result1 = (Map)ddrNew1.getResult();
|
|
|
+
|
|
|
+
|
|
|
+ //年假余额
|
|
|
+ double annualLeaveNum = 0;
|
|
|
+ if (Objects.nonNull(result1.get("leave_quotas"))){
|
|
|
+ for (Map leaveQuotas : (List<Map>) result1.get("leave_quotas")) {
|
|
|
+ if (Objects.isNull(leaveQuotas.get("quota_num_per_hour")) && Objects.nonNull(leaveQuotas.get("quota_num_per_day"))){
|
|
|
+ annualLeaveNum += ((int) leaveQuotas.get("quota_num_per_day")) / 100.0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //预支年假数量
|
|
|
+ int advancedLeaveNum = 0;
|
|
|
+ if (Objects.nonNull(advancedLeave)){
|
|
|
+ advancedLeaveNum = advancedLeave.getLeaveNum();
|
|
|
+ }else{
|
|
|
+ advancedLeaveNum = annualLeaveNum >= 8 ? 8 : (int)annualLeaveNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ leaveMap.put("可预支年假",advancedLeaveNum);
|
|
|
+ leaveMap.put("实际年假余额",Math.max(0,NumberUtil.sub(annualLeaveNum,advancedLeaveNum)));
|
|
|
+ leaveMap.put("已预支年假",Math.max(0,Math.ceil(advancedLeaveNum-annualLeaveNum)));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //查询员工调休假余额
|
|
|
+ Map body2 = new HashMap();
|
|
|
+ body2.put("leave_code","c7beb5e9-73ee-45f8-ae66-dfdb2a5ad0b8");//调休假
|
|
|
+ body2.put("op_userid",ddConf.getOperator());
|
|
|
+ body2.put("userids",userId);
|
|
|
+ body2.put("offset",0);
|
|
|
+ body2.put("size",10);
|
|
|
+ DDR_New ddrNew2 = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/attendance/vacation/quota/list", null, ddClient.initTokenParams(), body2, DDR_New.class);
|
|
|
+ Map result2 = (Map)ddrNew2.getResult();
|
|
|
+ //调休假余额
|
|
|
+ int compensatoryLeaveNum = 0;
|
|
|
+ if (Objects.nonNull(result2.get("leave_quotas"))){
|
|
|
+ for (Map leaveQuotas : (List<Map>) result2.get("leave_quotas")) {
|
|
|
+ if (Objects.isNull(leaveQuotas.get("quota_num_per_day")) && Objects.nonNull(leaveQuotas.get("quota_num_per_hour"))){
|
|
|
+ compensatoryLeaveNum += ((int) leaveQuotas.get("quota_num_per_hour")) / 100;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ leaveMap.put("可预支调休",compensatoryLeaveNum);
|
|
|
+ leaveMap.put("实际加班小时数",Math.max(0,compensatoryLeaveNum-80));
|
|
|
+ leaveMap.put("已预支调休",Math.max(0,80-compensatoryLeaveNum));
|
|
|
+ }
|
|
|
+ return leaveMap;
|
|
|
+ }
|
|
|
+
|
|
|
private int getAnnualLeaveBaseNum(String positionLevel) {
|
|
|
int annualLeave = 0;
|
|
|
if (positionLevel.equals("MGR") || positionLevel.equals("DH") || positionLevel.equals("副主任医师")){
|