完善定时请假的逻辑
This commit is contained in:
@ -13,14 +13,18 @@ import com.ruoyi.common.enums.RecruitApplyStatus;
|
||||
import com.ruoyi.fbs.domain.FbsProjectTask;
|
||||
import com.ruoyi.fbs.service.IFbsProjectTaskService;
|
||||
import com.ruoyi.wgz.domain.WgzAttendance;
|
||||
import com.ruoyi.wgz.domain.WgzLeave;
|
||||
import com.ruoyi.wgz.domain.WgzMessage;
|
||||
import com.ruoyi.wgz.service.IWgzAttendanceService;
|
||||
import com.ruoyi.wgz.service.IWgzLeaveService;
|
||||
import com.ruoyi.wgz.service.IWgzMessageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -53,6 +57,9 @@ public class BusinessTask
|
||||
@Autowired
|
||||
private IWgzAttendanceService iWgzAttendanceService;
|
||||
|
||||
@Autowired
|
||||
private IWgzLeaveService iWgzLeaveService;
|
||||
|
||||
/**
|
||||
* 招工任务招工时间结束自动拒绝未选择的务工者
|
||||
*/
|
||||
@ -217,4 +224,115 @@ public class BusinessTask
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 请假
|
||||
*/
|
||||
public void leave(){
|
||||
List<WgzLeave> updataList = new ArrayList<>();
|
||||
List<WgzAttendance> attendanceList = new ArrayList<>();
|
||||
List<WgzMessage> messagesList = new ArrayList<>();
|
||||
LocalDate now = LocalDate.now();
|
||||
Map<String, String> mp = new HashMap<>();
|
||||
mp.put("data",now.toString());
|
||||
//1、获取所有正在审核的请假消息,如果超时就批量改变状态为请假超时
|
||||
List<WgzLeave> wgzLeaveList = iWgzLeaveService.list(
|
||||
Wrappers.<WgzLeave>lambdaQuery()
|
||||
.in(WgzLeave::getAuditorType, new String[]{"0", "1"})
|
||||
);
|
||||
for (WgzLeave wgzLeave : wgzLeaveList) {
|
||||
LocalDate startTime = wgzLeave.getStartTime().toLocalDate();
|
||||
// startTime大于等于now,那么就修改状态为请假超时
|
||||
if (startTime.isEqual(now) || startTime.isAfter(now)){
|
||||
WgzLeave st = new WgzLeave()
|
||||
.setId(wgzLeave.getId())
|
||||
.setAuditorType("5");
|
||||
updataList.add(st);
|
||||
//组装请假超时的消息
|
||||
WgzMessage wgzMessage = new WgzMessage().
|
||||
setSenderType(USERTYPE_SYSTEM).
|
||||
setRecipientType(USERTYPE_WGZ).
|
||||
setRecipientId(wgzLeave.getUserId()).
|
||||
setHeadline(WgzAndBgtMessageConstant.wgzMessage(mp,"117")).
|
||||
setSubheading(WgzAndBgtMessageConstant.wgzMessage(mp,"118")).
|
||||
setMessageLargeType(LARGE_OTHER).
|
||||
setMessageSmallType(SMALL_SYSTEM);
|
||||
messagesList.add(wgzMessage); }
|
||||
}
|
||||
if (iWgzLeaveService.updateBatchById(updataList)){
|
||||
//3、发送请假超时的消息
|
||||
if (!iWgzMessageService.saveBatch(messagesList)){
|
||||
log.error("批量添加请假超时消息失败!");
|
||||
}
|
||||
//4、获取所有审批成功的请假消息,然后批量新增请假打卡数据到考勤表(如若需要日薪就需要连表查询)
|
||||
List<WgzLeave> wgzLeaveListTwo = iWgzLeaveService.list(
|
||||
Wrappers.<WgzLeave>lambdaQuery()
|
||||
.eq(WgzLeave::getAuditorType, "2")
|
||||
);
|
||||
for (WgzLeave wgzLeave : wgzLeaveListTwo) {
|
||||
//获取请假的具体天数(目前的请假是全天,没有分时间段)
|
||||
List<LocalDate> formattedDates = getFormattedDates(wgzLeave.getStartTime(), wgzLeave.getEndTime());
|
||||
//业务逻辑
|
||||
for (LocalDate formattedDate : formattedDates) {
|
||||
//如果formattedDate小于当前日期,就跳过
|
||||
if (formattedDate.isBefore(now)){
|
||||
continue;
|
||||
}
|
||||
//查询当前人、当前项目、当前打卡时间是否存在,如若存在就跳过
|
||||
int count = iWgzAttendanceService.count(
|
||||
Wrappers.<WgzAttendance>lambdaQuery()
|
||||
.eq(WgzAttendance::getUserId, wgzLeave.getUserId())
|
||||
.eq(WgzAttendance::getRecruitId, wgzLeave.getRecruitId())
|
||||
.eq(WgzAttendance::getDate, formattedDate)
|
||||
);
|
||||
if (count > 0){
|
||||
continue;
|
||||
}
|
||||
//获取到请假天数
|
||||
WgzAttendance wgzAttendance = new WgzAttendance().
|
||||
setRecruitId(wgzLeave.getRecruitId()).
|
||||
setUserId(wgzLeave.getUserId()).
|
||||
setLeaveMarkId(wgzLeave.getId()).
|
||||
setDate(formattedDate).
|
||||
setExceptionType("6,");
|
||||
attendanceList.add(wgzAttendance);
|
||||
}
|
||||
}
|
||||
if (!iWgzAttendanceService.addAMissingCardRecord(attendanceList)){
|
||||
log.error("批量添加上班缺卡信息失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两个LocalDateTime的年月日
|
||||
*
|
||||
* 2025-02-24 17:35:20
|
||||
* 2025-02-24 17:35:20
|
||||
* 得到2025-02-24
|
||||
* 2025-02-24 17:35:20
|
||||
* 2025-02-25 17:35:20
|
||||
* 得到2025-02-24 2025-02-25
|
||||
*/
|
||||
public static List<LocalDate> getFormattedDates(LocalDateTime dateTime1, LocalDateTime dateTime2) {
|
||||
// 获取两个 LocalDateTime 对象对应的 LocalDate 对象
|
||||
LocalDate localDate1 = dateTime1.toLocalDate();
|
||||
LocalDate localDate2 = dateTime2.toLocalDate();
|
||||
|
||||
// 创建一个集合来存储不同的日期
|
||||
List<LocalDate> dates = new ArrayList<>();
|
||||
if (!dates.contains(localDate1)) {
|
||||
dates.add(localDate1);
|
||||
}
|
||||
if (!dates.contains(localDate2)) {
|
||||
dates.add(localDate2);
|
||||
}
|
||||
|
||||
// 定义日期格式化器
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
// 将日期集合格式化为字符串并使用空格连接
|
||||
return dates;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user