排班详情修改

This commit is contained in:
dy 2025-08-04 23:39:43 +08:00
parent f7db092af8
commit 7b37ed293f
2 changed files with 161 additions and 76 deletions

View File

@ -75,16 +75,20 @@ public class AttendanceArrangementVo implements Serializable {
@ExcelProperty(value = "状态0-未生效1-已生效") @ExcelProperty(value = "状态0-未生效1-已生效")
private Long status; private Long status;
//考勤组
private AttendanceGroup attendanceGroup; private AttendanceGroup attendanceGroup;
//用户组
private List<AttendanceUserGroup> userGroupList; private List<AttendanceUserGroup> userGroupList;
//固定排班
private AttendanceWeekSet weekSet; private AttendanceWeekSet weekSet;
//班次
private AttendanceShift shift; private AttendanceShift shift;
private AttendanceScheduleCycle cycle; //排班制
private AttendanceScheduleCycle scheduleCycle;
private AttendanceUserGroup userGroup;
} }

View File

@ -20,8 +20,10 @@ 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.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.temporal.WeekFields;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -78,90 +80,170 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
@Override @Override
public TableDataInfo<AttendanceArrangementVo> queryPageList(AttendanceArrangementBo bo, PageQuery pageQuery) { public TableDataInfo<AttendanceArrangementVo> queryPageList(AttendanceArrangementBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<AttendanceArrangement> lqw = buildQueryWrapper(bo); LambdaQueryWrapper<AttendanceArrangement> lqw = buildQueryWrapper(bo);
Page<AttendanceArrangementVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
//查询当前日期在哪些排班中当前日期大于等于排班开始日期小于等于排班结束日期
LambdaQueryWrapper<AttendanceArrangement> ge = lqw
.le(AttendanceArrangement::getStartDate, bo.getCurrentDate())
.ge(AttendanceArrangement::getEndDate, bo.getCurrentDate());
Page<AttendanceArrangementVo> result = baseMapper.selectVoPage(pageQuery.build(), ge);
Page<AttendanceArrangementVo> attendanceArrangementVoPage = result.setRecords(result.getRecords().stream().map(vo -> {
//根据当前日期查询在开始时间和结束时间之间的排班信息
//从前端查询出来的当前日期判断是否在排班时间内
if (bo.getCurrentDate().isAfter(vo.getStartDate()) && bo.getCurrentDate().isBefore(vo.getEndDate())) {
//1.查询人员表信息
//根据查询出来的result取出shceduleId
Long scheduleId = vo.getId();
//根据排班的id查询出排班的人员详细信息
List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleId));
vo.setUserGroupList(userGroupList);
//2.查询考勤组信息
//根据查询出来的信息取出考勤组的id
Long groupId = vo.getGroupId();
//根据考勤组的id查询出考勤组的详细信息
AttendanceGroup attendanceGroup = attendanceGroupMapper.selectById(groupId);
//将考勤组的信息存到vo中
vo.setAttendanceGroup(attendanceGroup);
//3.查询班制信息
//判断当前考勤组的班制是固定班制还是排班制
if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.FIXEDSCHEDULE)) {
//3.1固定班制
//根据考勤组id查询出班制信息的dayOfWeek
List<AttendanceWeekSet> weekSetList = weekSetMapper.selectList(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, groupId));
//将当前日期转换为周几
int weekNumber = bo.getCurrentDate().getDayOfWeek().getValue();
//匹配weekNumber和weekSetList中的dayOfWeek匹配成功则将weekSet存到vo中
AttendanceWeekSet attendanceWeekSet = weekSetList.stream().filter(weekSet -> weekSet.getDayOfWeek() == weekNumber).findFirst().orElse(null);
//根据过滤出来的attendanceWeekSet的weekSetId查询出shiftId
Long shiftId = attendanceWeekSet.getShiftId();
//根据shiftId查询出班次的详细信息
AttendanceShift attendanceShift = attendanceShiftMapper.selectById(shiftId);
//将attendanceShift存到vo中
vo.setShift(attendanceShift);
Page<AttendanceArrangementVo> attendanceArrangementVoPage = result.setRecords(result.getRecords().stream().peek(vo -> { }else if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.SHIFTSCHEDULE)) {
//1.根据当前日期查询在开始时间和结束时间之间的排班信息 //3.2排班制
//查询指定日期查询在哪些排班中并返回arrangementList
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设置到考勤组中 //将startDate作为第一天endDate作为最后一天循环判断当前日期是第几天取出当前天数的班次信息
//循环groupIds循环和AttendanceGroup中的id做对比如果有相同的则取出attendanceGroup中的所有数据 LocalDate startDate = vo.getStartDate();
groupIds.forEach( LocalDate endDate = vo.getEndDate();
groupId -> { LocalDate currentDate = bo.getCurrentDate();
//从数据库查询出当前考勤组的所有数据 // //统计当前考勤组有多少条数据
AttendanceGroup group = attendanceGroupMapper.selectOne(Wrappers.<AttendanceGroup>lambdaQuery().eq(AttendanceGroup::getId, groupId)); // int count = Math.toIntExact(scheduleCycleMapper.selectCount(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)));
// 3.查询出当前考勤组的所有数据从考勤组判断当前id是固定班制还是排班制 //取出attendanceScheduleCycle表中的天数
if (group.getAttendanceType().equals(StatusConstant.FIXEDSCHEDULE)) { List<Integer> cycleDaysList = scheduleCycleMapper.selectList(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).stream().map(AttendanceScheduleCycle::getDayNumber).collect(Collectors.toList());
// 3.1固定班制将当前的日期转为周几然后与数据库中的班次周数作对比取出当前日期的班次信息 // 在startDate和endDate之间循环判端当前日期是cycleDays中的第几天
//将传来的日期参数转为周几 int cycleDay = 1; // 初始化 cycleDay 1
// int week = DateUtil.dayOfWeek(bo.getCurrentDate()); for (LocalDate date = startDate; date.isBefore(endDate) || date.isEqual(endDate); date = date.plusDays(1)) {
int week = 1; if (date.isEqual(currentDate)) {
//取出当前日期的周数与数据库中的班次周数作对比取出当前日期的班次信息 // 判断当前日期是cycleDays中的第几天
AttendanceWeekSet weekSet = weekSetMapper.selectOne(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, groupId).eq(AttendanceWeekSet::getDayOfWeek, week)); int dayNumber = date.getDayOfYear() - startDate.getDayOfYear() + 1;
//将weekSet存到结果中 cycleDay = dayNumber % cycleDaysList.size();
vo.setWeekSet(weekSet); if (cycleDay == 0) {
//根据weekSet取出id根据id查询出attendanceWeekSetShift表中的shiftId cycleDay = cycleDaysList.size();
Long shiftId = weekSet.getId();
//根据shiftId查询attendanceShift表中对应的id的数据
AttendanceShift shift = attendanceShiftMapper.selectById(shiftId);
//将shift存到结果中
vo.setShift(shift);
} else if (group.getAttendanceType().equals(StatusConstant.SHIFTSCHEDULE)) {
// 3.2排班制判断第一天是从几号开始循环判断判断当前是循环中的第几天取出当前天数的班次信息
//取出排班中的开始时间和结束时间
LocalDate startDate = bo.getStartDate();
LocalDate endDate = bo.getEndDate();
LocalDate currentDate = bo.getCurrentDate();
//统计当前考勤组有多少条数据
int count = Math.toIntExact(scheduleCycleMapper.selectCount(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)));
//todo: 匹配天数
//取出attendanceScheduleCycle表中的天数
Integer cycleDays = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).getDayNumber();
//在startDate和endDate之间循环判端当前日期是cycleDays中的第几天
int cycleDay = 0;
while (startDate.isBefore(currentDate) || endDate.isAfter(currentDate)) {
cycleDay++;
// startDate = DateUtil.offsetDay(startDate, 1);
//判断当前日期是clcleDays中的第几天
if (cycleDay > cycleDays) {
cycleDay = 1;
} }
// 根据cycleDay查询出当前日期的班次信息
AttendanceScheduleCycle cycle = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery()
.eq(AttendanceScheduleCycle::getGroupId, groupId)
.eq(AttendanceScheduleCycle::getDayNumber, cycleDay));
//将cycle存到vo中
vo.setScheduleCycle(cycle);
//根据cycleId查询出shiftId
Long cycleId = cycle.getId();
AttendanceShift shift = attendanceShiftMapper.selectOne(Wrappers.<AttendanceShift>lambdaQuery().eq(AttendanceShift::getId, cycle.getShiftId()));
//将shift存到vo中
vo.setShift(shift);
break; // 找到当前日期后跳出循环
} }
//根据cycleDay查询出当前日期的班次信息
AttendanceScheduleCycle cycle = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId).eq(AttendanceScheduleCycle::getDayNumber, cycleDay));
//将cycle存到结果中
vo.setCycle(cycle);
} }
//根据cycleDay查询出当前日期的班次信息
AttendanceScheduleCycle cycle = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId).eq(AttendanceScheduleCycle::getDayNumber, cycleDay));
//将cycle存到vo中
vo.setScheduleCycle(cycle);
} }
);
// AttendanceArrangementVo arrangementvo = baseMapper.selectVoByTime(bo.getCurrentDate()); } else {
// //2.查询人员组的信息 TableDataInfo.build();
// //根据开始时间查询出所有的排班id }
// List<Long> scheduleIdList = baseMapper.selectList(Wrappers.<AttendanceArrangement>lambdaQuery().ge(AttendanceArrangement::getStartDate, bo.getCurrentDate())).stream().map(AttendanceArrangement::getId).collect(Collectors.toList());
// //根据排班的id查询出排班的人员详细信息 // //1.根据当前日期查询在开始时间和结束时间之间的排班信息
// List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList)); // //查询指定日期查询在哪些排班中并返回arrangementList
// //将排班人员信息添加到排班信息中 // List<AttendanceArrangement> arrangementList = baseMapper.selectList(
// arrangementvo.setUserGroupList(userGroupList); // Wrappers.<AttendanceArrangement>lambdaQuery()
// .ge(AttendanceArrangement::getStartDate, bo.getCurrentDate())
// .le(AttendanceArrangement::getEndDate, bo.getCurrentDate())
// );
// //根据排班查询出考勤组id
// List<Long> groupIds = arrangementList.stream().map(AttendanceArrangement::getGroupId).distinct().toList();
// //
// //3.根据排班的id查询出排班的考勤组id // // 2.循环将所有的考勤组id设置到考勤组中
// List<Long> groupIds = baseMapper.selectList(Wrappers.<AttendanceArrangement>lambdaQuery().ge(AttendanceArrangement::getStartDate, bo.getCurrentDate())).stream().map(AttendanceArrangement::getGroupId).distinct().collect(Collectors.toList()); // //循环groupIds循环和AttendanceGroup中的id做对比如果有相同的则取出attendanceGroup中的所有数据
// //判断考勤组是排班制还是固定班制 // groupIds.forEach(
// groupId -> {
// //从数据库查询出当前考勤组的所有数据
// AttendanceGroup group = attendanceGroupMapper.selectOne(Wrappers.<AttendanceGroup>lambdaQuery().eq(AttendanceGroup::getId, groupId));
//
// // 3.查询出当前考勤组的所有数据从考勤组判断当前id是固定班制还是排班制
// if (group.getAttendanceType().equals(StatusConstant.FIXEDSCHEDULE)) {
// // 3.1固定班制将当前的日期转为周几然后与数据库中的班次周数作对比取出当前日期的班次信息
// //将传来的日期参数转为周几
//// int week = DateUtil.dayOfWeek(bo.getCurrentDate());
// int week = 1;
// //取出当前日期的周数与数据库中的班次周数作对比取出当前日期的班次信息
// AttendanceWeekSet weekSet = weekSetMapper.selectOne(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, groupId).eq(AttendanceWeekSet::getDayOfWeek, week));
// //将weekSet存到结果中
// vo.setWeekSet(weekSet);
// //根据weekSet取出id根据id查询出attendanceWeekSetShift表中的shiftId
// Long shiftId = weekSet.getId();
// //根据shiftId查询attendanceShift表中对应的id的数据
// AttendanceShift shift = attendanceShiftMapper.selectById(shiftId);
// //将shift存到结果中
// vo.setShift(shift);
// } else if (group.getAttendanceType().equals(StatusConstant.SHIFTSCHEDULE)) {
// // 3.2排班制判断第一天是从几号开始循环判断判断当前是循环中的第几天取出当前天数的班次信息
// //取出排班中的开始时间和结束时间
// LocalDate startDate = bo.getStartDate();
// LocalDate endDate = bo.getEndDate();
// LocalDate currentDate = bo.getCurrentDate();
// //统计当前考勤组有多少条数据
// int count = Math.toIntExact(scheduleCycleMapper.selectCount(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)));
//
//
// //todo: 匹配天数
//
//
// //取出attendanceScheduleCycle表中的天数
// Integer cycleDays = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).getDayNumber();
// //在startDate和endDate之间循环判端当前日期是cycleDays中的第几天
// int cycleDay = 0;
// while (startDate.isBefore(currentDate) || endDate.isAfter(currentDate)) {
// cycleDay++;
//// startDate = DateUtil.offsetDay(startDate, 1);
// //判断当前日期是clcleDays中的第几天
// if (cycleDay > cycleDays) {
// cycleDay = 1;
// }
// }
// //根据cycleDay查询出当前日期的班次信息
// AttendanceScheduleCycle cycle = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId).eq(AttendanceScheduleCycle::getDayNumber, cycleDay));
// //将cycle存到结果中
// vo.setCycle(cycle);
//
// }
// }
// );
return vo;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
@ -202,7 +284,6 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
// List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList)); // List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList));
// 根据排班查询出考勤组id // 根据排班查询出考勤组id
List<Long> groupIds = arrangementList.stream() List<Long> groupIds = arrangementList.stream()
.map(AttendanceArrangement::getGroupId) .map(AttendanceArrangement::getGroupId)