排班详情修改
This commit is contained in:
parent
f7db092af8
commit
7b37ed293f
@ -75,16 +75,20 @@ public class AttendanceArrangementVo implements Serializable {
|
||||
@ExcelProperty(value = "状态:0-未生效,1-已生效")
|
||||
private Long status;
|
||||
|
||||
//考勤组
|
||||
private AttendanceGroup attendanceGroup;
|
||||
|
||||
//用户组
|
||||
private List<AttendanceUserGroup> userGroupList;
|
||||
|
||||
//固定排班
|
||||
private AttendanceWeekSet weekSet;
|
||||
|
||||
//班次
|
||||
private AttendanceShift shift;
|
||||
|
||||
private AttendanceScheduleCycle cycle;
|
||||
//排班制
|
||||
private AttendanceScheduleCycle scheduleCycle;
|
||||
|
||||
private AttendanceUserGroup userGroup;
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,10 @@ import org.dromara.property.service.IAttendanceArrangementService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.WeekFields;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -78,90 +80,170 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
|
||||
@Override
|
||||
public TableDataInfo<AttendanceArrangementVo> queryPageList(AttendanceArrangementBo bo, PageQuery pageQuery) {
|
||||
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 -> {
|
||||
//1.根据当前日期查询在开始时间和结束时间之间的排班信息
|
||||
//查询指定日期查询在哪些排班中,并返回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();
|
||||
}else if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.SHIFTSCHEDULE)) {
|
||||
//3.2排班制
|
||||
|
||||
// 2.循环将所有的考勤组id设置到考勤组中
|
||||
//循环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();
|
||||
//将startDate作为第一天,endDate作为最后一天,循环判断当前日期是第几天,取出当前天数的班次信息。
|
||||
LocalDate startDate = vo.getStartDate();
|
||||
LocalDate endDate = vo.getEndDate();
|
||||
LocalDate currentDate = bo.getCurrentDate();
|
||||
//统计当前考勤组有多少条数据
|
||||
int count = Math.toIntExact(scheduleCycleMapper.selectCount(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)));
|
||||
|
||||
|
||||
//todo: 匹配天数
|
||||
|
||||
// //统计当前考勤组有多少条数据
|
||||
// int count = Math.toIntExact(scheduleCycleMapper.selectCount(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)));
|
||||
|
||||
//取出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;
|
||||
List<Integer> cycleDaysList = scheduleCycleMapper.selectList(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).stream().map(AttendanceScheduleCycle::getDayNumber).collect(Collectors.toList());
|
||||
// 在startDate和endDate之间循环,判端当前日期是cycleDays中的第几天
|
||||
int cycleDay = 1; // 初始化 cycleDay 为 1
|
||||
for (LocalDate date = startDate; date.isBefore(endDate) || date.isEqual(endDate); date = date.plusDays(1)) {
|
||||
if (date.isEqual(currentDate)) {
|
||||
// 判断当前日期是cycleDays中的第几天
|
||||
int dayNumber = date.getDayOfYear() - startDate.getDayOfYear() + 1;
|
||||
cycleDay = dayNumber % cycleDaysList.size();
|
||||
if (cycleDay == 0) {
|
||||
cycleDay = cycleDaysList.size();
|
||||
}
|
||||
// 根据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);
|
||||
//将cycle存到vo中
|
||||
vo.setScheduleCycle(cycle);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
TableDataInfo.build();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// AttendanceArrangementVo arrangementvo = baseMapper.selectVoByTime(bo.getCurrentDate());
|
||||
// //2.查询人员组的信息
|
||||
// //根据开始时间查询出所有的排班id
|
||||
// List<Long> scheduleIdList = baseMapper.selectList(Wrappers.<AttendanceArrangement>lambdaQuery().ge(AttendanceArrangement::getStartDate, bo.getCurrentDate())).stream().map(AttendanceArrangement::getId).collect(Collectors.toList());
|
||||
// //根据排班的id查询出排班的人员详细信息
|
||||
// List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList));
|
||||
// //将排班人员信息添加到排班信息中
|
||||
// arrangementvo.setUserGroupList(userGroupList);
|
||||
// //1.根据当前日期查询在开始时间和结束时间之间的排班信息
|
||||
// //查询指定日期查询在哪些排班中,并返回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();
|
||||
//
|
||||
// //3.根据排班的id查询出排班的考勤组id
|
||||
// List<Long> groupIds = baseMapper.selectList(Wrappers.<AttendanceArrangement>lambdaQuery().ge(AttendanceArrangement::getStartDate, bo.getCurrentDate())).stream().map(AttendanceArrangement::getGroupId).distinct().collect(Collectors.toList());
|
||||
// //判断考勤组是排班制还是固定班制
|
||||
// // 2.循环将所有的考勤组id设置到考勤组中
|
||||
// //循环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()));
|
||||
|
||||
|
||||
@ -202,7 +284,6 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
|
||||
// List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList));
|
||||
|
||||
|
||||
|
||||
// 根据排班查询出考勤组id
|
||||
List<Long> groupIds = arrangementList.stream()
|
||||
.map(AttendanceArrangement::getGroupId)
|
||||
|
Loading…
Reference in New Issue
Block a user