|
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.attendance.service.leave;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
|
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
@@ -14,6 +15,9 @@ import cn.iocoder.yudao.module.employee.api.EmployeeApi;
|
|
|
import cn.iocoder.yudao.module.employee.api.dto.EmployeeRespDTO;
|
|
|
import cn.iocoder.yudao.module.employee.api.dto.EmployeeSaveReqDTO;
|
|
|
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dicttenant.DictDataTenantApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dicttenant.dto.DictDataTenantRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.enums.dicttenant.DictTypeTenantEnum;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -23,6 +27,7 @@ import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.attendance.enums.ErrorCodeConstants.*;
|
|
@@ -42,6 +47,8 @@ public class AttendanceLeaveServiceImpl implements AttendanceLeaveService {
|
|
|
private EmployeeApi employeeApi;
|
|
|
@Resource
|
|
|
private FileApi fileApi;
|
|
|
+ @Resource
|
|
|
+ private DictDataTenantApi dictDataTenantApi;
|
|
|
|
|
|
@Override
|
|
|
@DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
|
@@ -71,7 +78,11 @@ public class AttendanceLeaveServiceImpl implements AttendanceLeaveService {
|
|
|
leaveMapper.insert(leave);
|
|
|
// 保存业务uuid到附件中
|
|
|
fileApi.updateFileBiz(createReqVO.getFileIdList(), infoId);
|
|
|
- if ("年假".equals(createReqVO.getLeaveType())) {
|
|
|
+ // 请假类型
|
|
|
+ List<DictDataTenantRespDTO> dictDataList = dictDataTenantApi.getDictDataList(DictTypeTenantEnum.TENANT_LEAVE_TYPE.getType());
|
|
|
+ Map<String, String> dictDataMap = CollectionUtils.convertMap(dictDataList, DictDataTenantRespDTO::getValue, DictDataTenantRespDTO::getLabel);
|
|
|
+ String leaveTypeDesc = dictDataMap.get(createReqVO.getLeaveType());
|
|
|
+ if ("年假".equals(createReqVO.getLeaveType()) || "年假".equals(leaveTypeDesc)) {
|
|
|
// 获取剩余年假和申请天数
|
|
|
BigDecimal remainingAnnualLeave = employee.getRemainingAnnualLeave();
|
|
|
String requestDayStr = createReqVO.getDay(); // 更清晰的变量名
|
|
@@ -105,7 +116,11 @@ public class AttendanceLeaveServiceImpl implements AttendanceLeaveService {
|
|
|
leaveMapper.insert(attendanceLeaveDO);
|
|
|
// 请假人信息
|
|
|
EmployeeRespDTO employee = employeeApi.getEmployeeById(attendanceLeaveDO.getEmployeeId());
|
|
|
- if ("年假".equals(attendanceLeaveDO.getLeaveType())) {
|
|
|
+ // 请假类型
|
|
|
+ List<DictDataTenantRespDTO> dictDataList = dictDataTenantApi.getDictDataList(DictTypeTenantEnum.TENANT_LEAVE_TYPE.getType());
|
|
|
+ Map<String, String> dictDataMap = CollectionUtils.convertMap(dictDataList, DictDataTenantRespDTO::getValue, DictDataTenantRespDTO::getLabel);
|
|
|
+ String leaveTypeDesc = dictDataMap.get(attendanceLeaveDO.getLeaveType());
|
|
|
+ if ("年假".equals(attendanceLeaveDO.getLeaveType()) || "年假".equals(leaveTypeDesc)) {
|
|
|
// 获取剩余年假和申请天数
|
|
|
BigDecimal remainingAnnualLeave = employee.getRemainingAnnualLeave();
|
|
|
String requestDayStr = attendanceLeaveDO.getDay(); // 更清晰的变量名
|
|
@@ -138,8 +153,13 @@ public class AttendanceLeaveServiceImpl implements AttendanceLeaveService {
|
|
|
AttendanceLeaveDO oldLeave = leaveMapper.selectById(updateReqVO.getId());
|
|
|
// 请假人信息
|
|
|
EmployeeRespDTO employee = employeeApi.getEmployeeById(updateReqVO.getEmployeeId());
|
|
|
+ // 请假类型
|
|
|
+ List<DictDataTenantRespDTO> dictDataList = dictDataTenantApi.getDictDataList(DictTypeTenantEnum.TENANT_LEAVE_TYPE.getType());
|
|
|
+ Map<String, String> dictDataMap = CollectionUtils.convertMap(dictDataList, DictDataTenantRespDTO::getValue, DictDataTenantRespDTO::getLabel);
|
|
|
+ String oldLeaveTypeDesc = dictDataMap.get(oldLeave.getLeaveType());
|
|
|
+ String leaveTypeDesc = dictDataMap.get(updateReqVO.getLeaveType());
|
|
|
if (oldLeave.getEmployeeId().equals(employee.getId())) {// 员工ID不变
|
|
|
- if ("年假".equals(oldLeave.getLeaveType()) && "年假".equals(updateReqVO.getLeaveType())) {
|
|
|
+ if ("年假".equals(oldLeaveTypeDesc) && "年假".equals(leaveTypeDesc)) {
|
|
|
// 新旧都是年假,对比天数进行增减
|
|
|
BigDecimal oldDays = new BigDecimal(oldLeave.getDay());
|
|
|
BigDecimal newDays = new BigDecimal(updateReqVO.getDay());
|
|
@@ -160,7 +180,7 @@ public class AttendanceLeaveServiceImpl implements AttendanceLeaveService {
|
|
|
throw exception(ATTENDANCE_UPDATING_EMPLOYEE_INFO_ERROR);
|
|
|
}
|
|
|
}
|
|
|
- if (!"年假".equals(oldLeave.getLeaveType()) && "年假".equals(updateReqVO.getLeaveType())) {
|
|
|
+ if (!"年假".equals(oldLeaveTypeDesc) && "年假".equals(leaveTypeDesc)) {
|
|
|
// 新的是年假、旧的不是
|
|
|
BigDecimal remainingAnnualLeave = employee.getRemainingAnnualLeave();
|
|
|
String requestDayStr = updateReqVO.getDay();
|
|
@@ -180,7 +200,7 @@ public class AttendanceLeaveServiceImpl implements AttendanceLeaveService {
|
|
|
throw exception(ATTENDANCE_UPDATING_EMPLOYEE_INFO_ERROR);
|
|
|
}
|
|
|
}
|
|
|
- if ("年假".equals(oldLeave.getLeaveType()) && !"年假".equals(updateReqVO.getLeaveType())) {
|
|
|
+ if ("年假".equals(oldLeaveTypeDesc) && !"年假".equals(leaveTypeDesc)) {
|
|
|
// 旧的是年假,新的不是,归还年假天数
|
|
|
BigDecimal remainingAnnualLeave = employee.getRemainingAnnualLeave();
|
|
|
BigDecimal oldDays = new BigDecimal(oldLeave.getDay());
|
|
@@ -229,7 +249,11 @@ public class AttendanceLeaveServiceImpl implements AttendanceLeaveService {
|
|
|
AttendanceLeaveDO oldLeave = leaveMapper.selectById(id);
|
|
|
// 请假人信息
|
|
|
EmployeeRespDTO employee = employeeApi.getEmployeeById(oldLeave.getEmployeeId());
|
|
|
- if ("年假".equals(oldLeave.getLeaveType())) {
|
|
|
+ // 请假类型
|
|
|
+ List<DictDataTenantRespDTO> dictDataList = dictDataTenantApi.getDictDataList(DictTypeTenantEnum.TENANT_LEAVE_TYPE.getType());
|
|
|
+ Map<String, String> dictDataMap = CollectionUtils.convertMap(dictDataList, DictDataTenantRespDTO::getValue, DictDataTenantRespDTO::getLabel);
|
|
|
+ String leaveTypeDesc = dictDataMap.get(oldLeave.getLeaveType());
|
|
|
+ if ("年假".equals(oldLeave.getLeaveType()) || "事假".equals(leaveTypeDesc)) {
|
|
|
BigDecimal remainingAnnualLeave = employee.getRemainingAnnualLeave();
|
|
|
BigDecimal oldDays = new BigDecimal(oldLeave.getDay());
|
|
|
employee.setRemainingAnnualLeave(remainingAnnualLeave.add(oldDays));
|