新增排班问题处理

This commit is contained in:
dy
2025-07-29 11:06:29 +08:00
parent 64c3355e05
commit bff00b7b4a
5 changed files with 100 additions and 60 deletions

View File

@@ -55,12 +55,12 @@ public class AttendanceArrangement extends TenantEntity {
/** /**
* 开始日期 * 开始日期
*/ */
private LocalDate startDate; private Date startDate;
/** /**
* 结束日期(仅date_type=3时有效) * 结束日期(仅date_type=3时有效)
*/ */
private LocalDate endDate; private Date endDate;
/** /**
* 状态0-未生效1-已生效 * 状态0-未生效1-已生效

View File

@@ -9,6 +9,7 @@ import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*; import jakarta.validation.constraints.*;
import org.dromara.property.domain.AttendanceScheduleCycle;
import org.dromara.property.domain.AttendanceUserGroup; import org.dromara.property.domain.AttendanceUserGroup;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@@ -52,7 +53,7 @@ public class AttendanceArrangementBo extends BaseEntity {
/** /**
* 日期类型1-单个日期2-长期有效3-期间有效 * 日期类型1-单个日期2-长期有效3-期间有效
*/ */
private Long dateType; private Integer dateType;
/** /**
* 开始日期 * 开始日期
@@ -69,8 +70,8 @@ public class AttendanceArrangementBo extends BaseEntity {
/** /**
* 前端传日历的开始时间和结束时间 * 前端传日历的开始时间和结束时间
*/ */
private LocalDate calendarStartDate; private Date calendarStartDate;
private LocalDate calendarEndTimeDate; private Date calendarEndTimeDate;
/** /**
* 前端传某天的当前日期 * 前端传某天的当前日期
@@ -83,7 +84,15 @@ public class AttendanceArrangementBo extends BaseEntity {
*/ */
private Long status; private Long status;
/**
*
* 排班用户组
*/
private List<AttendanceUserGroup> userGroupList; private List<AttendanceUserGroup> userGroupList;
/**
* 排班日期列表
*/
private List<AttendanceScheduleCycle> scheduleCycleList;
} }

View File

@@ -28,5 +28,11 @@ public class StatusConstant {
public static final Integer NORMAL = 1; public static final Integer NORMAL = 1;
//日期类型1-单个日期2-长期有效3-期间有效
public static final Integer SINGLE = 1;
public static final Integer LONGTIME = 2;
public static final Integer SHORTTIME = 3;
} }

View File

@@ -8,7 +8,7 @@ import org.dromara.property.domain.*;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDate; import java.util.Date;
import java.util.List; import java.util.List;
@@ -60,13 +60,13 @@ public class AttendanceArrangementVo implements Serializable {
* 开始日期 * 开始日期
*/ */
@ExcelProperty(value = "开始日期") @ExcelProperty(value = "开始日期")
private LocalDate startDate; private Date startDate;
/** /**
* 结束日期(仅date_type=3时有效) * 结束日期(仅date_type=3时有效)
*/ */
@ExcelProperty(value = "结束日期(仅date_type=3时有效)") @ExcelProperty(value = "结束日期(仅date_type=3时有效)")
private LocalDate endDate; private Date endDate;
/** /**
* 状态0-未生效1-已生效 * 状态0-未生效1-已生效

View File

@@ -19,6 +19,8 @@ import org.dromara.property.service.IAttendanceArrangementService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -75,63 +77,69 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
LambdaQueryWrapper<AttendanceArrangement> lqw = buildQueryWrapper(bo); LambdaQueryWrapper<AttendanceArrangement> lqw = buildQueryWrapper(bo);
Page<AttendanceArrangementVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); Page<AttendanceArrangementVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
//1.如在2号到10号有固定班制和排班制根据当前日期查询出所有的考勤组id
//查询指定日期在哪些排班中
List<AttendanceArrangement> arrangementList = baseMapper.selectList(Wrappers.<AttendanceArrangement>lambdaQuery().ge(AttendanceArrangement::getStartDate, bo.getCurrentDate()).le(AttendanceArrangement::getEndDate, bo.getCurrentDate()));
//根据排班查询出考勤组id
List<Long> groupIds = arrangementList.stream().map(AttendanceArrangement::getGroupId).distinct().toList();
// 2.循环将所有的考勤组id设置到考勤组中 Page<AttendanceArrangementVo> attendanceArrangementVoPage = result.setRecords(result.getRecords().stream().peek(vo -> {
//循环groupIds循环和AttendanceGroup中的id做对比如果有相同的则取出attendanceGroup中的所有数据
groupIds.forEach(
groupId -> {
//从数据库查询出当前考勤组的所有数据
AttendanceGroup group = attendanceGroupMapper.selectOne(Wrappers.<AttendanceGroup>lambdaQuery().eq(AttendanceGroup::getId, groupId));
// 3.查询出当前考勤组的所有数据从考勤组判断当前id是固定班制还是排班制 //1.如在2号到10号有固定班制和排班制根据当前日期查询出所有的考勤组id
if (group.getAttendanceType().equals(StatusConstant.FIXEDSCHEDULE)) { //查询指定日期在哪些排班中
// 3.1固定班制:将当前的日期转为周几,然后与数据库中的班次周数作对比,取出当前日期的班次信息 List<AttendanceArrangement> arrangementList = baseMapper.selectList(Wrappers.<AttendanceArrangement>lambdaQuery().ge(AttendanceArrangement::getStartDate, bo.getCurrentDate()).le(AttendanceArrangement::getEndDate, bo.getCurrentDate()));
//将传来的日期参数转为周几 //根据排班查询出考勤组id
int week = DateUtil.dayOfWeek(bo.getCurrentDate()); List<Long> groupIds = arrangementList.stream().map(AttendanceArrangement::getGroupId).distinct().toList();
//取出当前日期的周数,与数据库中的班次周数作对比,取出当前日期的班次信息
AttendanceWeekSet weekSet = weekSetMapper.selectOne(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, groupId).eq(AttendanceWeekSet::getDayOfWeek, week));
//将weekSet存到结果中
AttendanceArrangementVo arrangementVo = new AttendanceArrangementVo();
arrangementVo.setWeekSet(weekSet);
//根据weekSet取出id根据id查询出attendanceWeekSetShift表中的shiftId
Long shiftId = weekSet.getId();
//根据shiftId查询attendanceShift表中对应的id的数据
AttendanceShift shift = attendanceShiftMapper.selectById(shiftId);
//将shift存到结果中
arrangementVo.setShift(shift);
} else if (group.getAttendanceType().equals(StatusConstant.SHIFTSCHEDULE)) { // 2.循环将所有的考勤组id设置到考勤组中
// 3.2排班制:判断第一天是从几号开始,循环判断,判断当前是循环中的第几天,取出当前天数的班次信息。 //循环groupIds循环和AttendanceGroup中的id做对比如果有相同的则取出attendanceGroup中的所有数据
//取出排班中的开始时间和结束时间 groupIds.forEach(
Date startDate = bo.getStartDate(); groupId -> {
Date endDate = bo.getEndDate(); //从数据库查询出当前考勤组的所有数据
Date currentDate = bo.getCurrentDate(); AttendanceGroup group = attendanceGroupMapper.selectOne(Wrappers.<AttendanceGroup>lambdaQuery().eq(AttendanceGroup::getId, groupId));
//取出attendanceScheduleCycle表中的天数
Integer cycleDays = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).getDayNumber(); // 3.查询出当前考勤组的所有数据从考勤组判断当前id是固定班制还是排班制
//在startDate和endDate之间循环判端当前日期是cycleDays中的第几天 if (group.getAttendanceType().equals(StatusConstant.FIXEDSCHEDULE)) {
int cycleDay = 0; // 3.1固定班制:将当前的日期转为周几,然后与数据库中的班次周数作对比,取出当前日期的班次信息
while (startDate.before(currentDate) || endDate.after(currentDate)) { //将传来的日期参数转为周几
cycleDay++; int week = DateUtil.dayOfWeek(bo.getCurrentDate());
startDate = DateUtil.offsetDay(startDate, 1); //取出当前日期的周数,与数据库中的班次周数作对比,取出当前日期的班次信息
//判断当前日期是clcleDays中的第几天 AttendanceWeekSet weekSet = weekSetMapper.selectOne(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, groupId).eq(AttendanceWeekSet::getDayOfWeek, week));
if (cycleDay > cycleDays) { //将weekSet存到结果中
cycleDay = 1; AttendanceArrangementVo arrangementVo = new AttendanceArrangementVo();
arrangementVo.setWeekSet(weekSet);
//根据weekSet取出id根据id查询出attendanceWeekSetShift表中的shiftId
Long shiftId = weekSet.getId();
//根据shiftId查询attendanceShift表中对应的id的数据
AttendanceShift shift = attendanceShiftMapper.selectById(shiftId);
//将shift存到结果中
arrangementVo.setShift(shift);
} else if (group.getAttendanceType().equals(StatusConstant.SHIFTSCHEDULE)) {
// 3.2排班制:判断第一天是从几号开始,循环判断,判断当前是循环中的第几天,取出当前天数的班次信息。
//取出排班中的开始时间和结束时间
Date startDate = bo.getStartDate();
Date endDate = bo.getEndDate();
Date currentDate = bo.getCurrentDate();
//取出attendanceScheduleCycle表中的天数
Integer cycleDays = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).getDayNumber();
//在startDate和endDate之间循环判端当前日期是cycleDays中的第几天
int cycleDay = 0;
while (startDate.before(currentDate) || endDate.after(currentDate)) {
cycleDay++;
startDate = DateUtil.offsetDay(startDate, 1);
//判断当前日期是clcleDays中的第几天
if (cycleDay > cycleDays) {
cycleDay = 1;
}
} }
} //根据cycleDay查询出当前日期的班次信息
//根据cycleDay查询出当前日期的班次信息 AttendanceScheduleCycle cycle = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId).eq(AttendanceScheduleCycle::getDayNumber, cycleDay));
AttendanceScheduleCycle cycle = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId).eq(AttendanceScheduleCycle::getDayNumber, cycleDay)); //将cycle存到结果中
//将cycle存到结果中 AttendanceArrangementVo arrangementVo = new AttendanceArrangementVo();
AttendanceArrangementVo arrangementVo = new AttendanceArrangementVo(); arrangementVo.setCycle(cycle);
arrangementVo.setCycle(cycle);
}
} }
} );
); }).collect(Collectors.toList()));
// //1.根据当前日期查询出排班信息 // //1.根据当前日期查询出排班信息
@@ -154,7 +162,7 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
// } // }
return TableDataInfo.build(result); return TableDataInfo.build(attendanceArrangementVoPage);
} }
/** /**
@@ -244,6 +252,23 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
if (flag) { if (flag) {
bo.setId(add.getId()); bo.setId(add.getId());
} }
//判断排班日期是单个日期还是从此日期开始循环有效还是从此日期开始有效
//1.单个日期
if (bo.getDateType().equals(StatusConstant.SINGLE)) {
add.setEndDate(null);
}
//2.从此日期开始长期有效
if (bo.getDateType().equals(StatusConstant.LONGTIME)) {
//设置长期时间为2099年12月31日
LocalDate longTimeEndDate = LocalDate.of(2099, 12, 31);
add.setEndDate(Date.from(longTimeEndDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
}
if (bo.getDateType().equals(StatusConstant.SHORTTIME)){
add.setEndDate(bo.getEndDate());
}
//取出当前新增的排班的id //取出当前新增的排班的id
Long ArrangementId = add.getId(); Long ArrangementId = add.getId();
//用获取到的排班id向attendanceUserGroup表中插入数据 //用获取到的排班id向attendanceUserGroup表中插入数据