排班按月份查询重构
This commit is contained in:
parent
b91201cf7f
commit
0a18e0c1a6
@ -2,6 +2,7 @@ package org.dromara.property.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -44,6 +45,7 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
|
|||||||
|
|
||||||
private final AttendanceGroupMapper attendanceGroupMapper;
|
private final AttendanceGroupMapper attendanceGroupMapper;
|
||||||
|
|
||||||
|
|
||||||
// private final AttendanceArrangementGroupMapper arrangementGroupMapper;
|
// private final AttendanceArrangementGroupMapper arrangementGroupMapper;
|
||||||
|
|
||||||
private final AttendanceWeekSetMapper weekSetMapper;
|
private final AttendanceWeekSetMapper weekSetMapper;
|
||||||
@ -125,7 +127,7 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
|
|||||||
vo.setShift(attendanceShift);
|
vo.setShift(attendanceShift);
|
||||||
|
|
||||||
|
|
||||||
}else if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.SHIFTSCHEDULE)) {
|
} else if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.SHIFTSCHEDULE)) {
|
||||||
//3.2排班制
|
//3.2排班制
|
||||||
|
|
||||||
//将startDate作为第一天,endDate作为最后一天,循环判断当前日期是第几天,取出当前天数的班次信息。
|
//将startDate作为第一天,endDate作为最后一天,循环判断当前日期是第几天,取出当前天数的班次信息。
|
||||||
@ -163,7 +165,6 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//根据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存到vo中
|
//将cycle存到vo中
|
||||||
@ -260,85 +261,153 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
|
|||||||
public TableDataInfo<AttendanceArrangementVo> queryList(AttendanceArrangementBo bo) {
|
public TableDataInfo<AttendanceArrangementVo> queryList(AttendanceArrangementBo bo) {
|
||||||
|
|
||||||
LocalDate month = bo.getMonth().atEndOfMonth();
|
LocalDate month = bo.getMonth().atEndOfMonth();
|
||||||
// 1. 拿到日历的开始时间和结束时间
|
|
||||||
LocalDate calendarStartDate = month.withDayOfMonth(1);
|
LocalDate calendarStartDate = month.withDayOfMonth(1);
|
||||||
LocalDate calendarEndDate = month.withDayOfMonth(calendarStartDate.lengthOfMonth());
|
LocalDate calendarEndDate = month.withDayOfMonth(calendarStartDate.lengthOfMonth());
|
||||||
|
|
||||||
// 2. 根据日历的开始时间和结束时间查询出每一天的排班信息
|
//使用mybatisplus的between查询在calendarStartDate和calendarEndDate之间的排班信息
|
||||||
// 2.1 循环日历的开始时间和结束时间,判断 calendarStartDate 在哪些排班中
|
List<AttendanceArrangementVo> startResult = baseMapper.selectVoList(Wrappers.<AttendanceArrangement>lambdaQuery()
|
||||||
List<AttendanceArrangementVo> result = new ArrayList<>();
|
.between(AttendanceArrangement::getStartDate, calendarStartDate.atStartOfDay(ZoneId.systemDefault()).toInstant(),
|
||||||
|
calendarEndDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant().minusSeconds(1)));
|
||||||
|
|
||||||
|
//查询结束时间在calendarStartDate和calendarEndDate之间的排班信息
|
||||||
|
List<AttendanceArrangement> endResult = baseMapper.selectList(Wrappers.<AttendanceArrangement>lambdaQuery()
|
||||||
|
.between(AttendanceArrangement::getEndDate, calendarStartDate.atStartOfDay(ZoneId.systemDefault()).toInstant(),
|
||||||
|
calendarEndDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant().minusSeconds(1)));
|
||||||
|
|
||||||
for (LocalDate date = calendarStartDate; date.isBefore(calendarEndDate); date = date.plusDays(1)) {
|
//合并两个list,并去重
|
||||||
// 2.2 根据当前日期查询在开始时间和结束时间之间的排班信息
|
List<AttendanceArrangementVo> result = new ArrayList<>(startResult.stream().distinct().toList());
|
||||||
//查询当前日期在哪些排班中,当前日期大于等于排班开始日期,小于等于排班结束日期
|
result.addAll(endResult.stream().map(vo -> {
|
||||||
// 查询指定日期在哪些排班中
|
AttendanceArrangementVo newVo = MapstructUtils.convert(vo, AttendanceArrangementVo.class);
|
||||||
List<AttendanceArrangement> arrangementList = baseMapper.selectList(
|
newVo.setStartDate(vo.getStartDate());
|
||||||
Wrappers.<AttendanceArrangement>lambdaQuery()
|
newVo.setEndDate(vo.getEndDate());
|
||||||
.between(AttendanceArrangement::getStartDate, date.atStartOfDay(ZoneId.systemDefault()).toInstant(),
|
return newVo;
|
||||||
date.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant().minusSeconds(1)));
|
}).toList());
|
||||||
|
|
||||||
// //根据arrangementList查询出排班的id
|
//去掉result中id重复的排班信息
|
||||||
// List<Long> scheduleIdList = arrangementList.stream().map(AttendanceArrangement::getId).toList();
|
result = result.stream().distinct().toList();
|
||||||
// //根据排班的id查询出排班的人员详细信息
|
|
||||||
// List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList));
|
|
||||||
|
|
||||||
|
//根据排班查询出考勤组id
|
||||||
// 根据排班查询出考勤组id
|
List<Long> groupIds = result.stream().map(AttendanceArrangementVo::getGroupId).distinct().toList();
|
||||||
List<Long> groupIds = arrangementList.stream()
|
// 循环 groupIds,循环和 AttendanceGroup 中的 id 做对比,如果有相同的,则取出 attendanceGroup 中的所有数据
|
||||||
.map(AttendanceArrangement::getGroupId)
|
for (Long groupId : groupIds) {
|
||||||
.distinct()
|
AttendanceGroup attendanceGroup = attendanceGroupMapper.selectById(groupId);
|
||||||
.toList();
|
if (attendanceGroup != null) {
|
||||||
|
// 循环排班列表,将排班信息和考勤组信息添加到vo中
|
||||||
// 如果当前日期没有排班,则跳过当前日期
|
for (AttendanceArrangementVo vo : result) {
|
||||||
if (groupIds.isEmpty()) {
|
if (vo.getGroupId().equals(groupId)) {
|
||||||
continue;
|
vo.setAttendanceGroup(attendanceGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 循环 groupIds,循环和 AttendanceGroup 中的 id 做对比,如果有相同的,则取出 attendanceGroup 中的所有数据
|
|
||||||
for (Long groupId : groupIds) {
|
|
||||||
AttendanceGroup attendanceGroup = attendanceGroupMapper.selectById(groupId);
|
|
||||||
if (attendanceGroup != null) {
|
|
||||||
// 创建 AttendanceArrangementVo 对象并设置属性
|
|
||||||
AttendanceArrangementVo vo = new AttendanceArrangementVo();
|
|
||||||
vo.setId(arrangementList.get(0).getId());
|
|
||||||
vo.setStartDate(arrangementList.get(0).getStartDate());
|
|
||||||
vo.setEndDate(arrangementList.get(0).getEndDate());
|
|
||||||
|
|
||||||
//获取到第一个排班的id
|
|
||||||
Long arrangementId = arrangementList.get(0).getId();
|
|
||||||
//根据arrangementId查询出人员组的详细信息
|
|
||||||
AttendanceGroup group = attendanceGroupMapper.selectById(arrangementId);
|
|
||||||
//将group存到vo中
|
|
||||||
vo.setAttendanceGroup(group);
|
|
||||||
|
|
||||||
//根据arrangementList查询出排班的id
|
|
||||||
List<Long> scheduleIdList = arrangementList.stream().map(AttendanceArrangement::getId).distinct().toList();
|
|
||||||
//根据排班的id查询出排班的人员详细信息
|
|
||||||
List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList));
|
|
||||||
|
|
||||||
|
|
||||||
//新建attendanceGroup对象,将排班信息和考勤组信息添加到vo中
|
|
||||||
vo.setAttendanceGroup(attendanceGroup);
|
|
||||||
//将排班人员信息添加到排班信息中
|
|
||||||
vo.setUserGroupList(userGroupList);
|
|
||||||
|
|
||||||
result.add(vo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 循环排班列表,查询排班人员信息
|
||||||
|
for (AttendanceArrangementVo vo : result) {
|
||||||
|
// 根据排班查询出人员组的详细信息
|
||||||
|
List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().eq(AttendanceUserGroup::getScheduleId, vo.getId()));
|
||||||
|
// 将排班人员信息添加到排班信息中
|
||||||
|
vo.setUserGroupList(userGroupList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocalDate month = bo.getMonth().atEndOfMonth();
|
||||||
|
// // 1. 拿到日历的开始时间和结束时间
|
||||||
|
// LocalDate calendarStartDate = month.withDayOfMonth(1);
|
||||||
|
// LocalDate calendarEndDate = month.withDayOfMonth(calendarStartDate.lengthOfMonth());
|
||||||
|
//
|
||||||
|
// // 2. 根据日历的开始时间和结束时间查询出每一天的排班信息
|
||||||
|
// // 2.1 循环日历的开始时间和结束时间,判断 calendarStartDate 在哪些排班中
|
||||||
|
// List<AttendanceArrangementVo> result = new ArrayList<>();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //查询所有排班信息
|
||||||
|
// List<AttendanceArrangement> arrangementList1 = baseMapper.selectList();
|
||||||
|
// //取出排班的开始时间和结束时间
|
||||||
|
// List<LocalDate> startDateList = arrangementList1.stream().map(AttendanceArrangement::getStartDate).toList();
|
||||||
|
// List<LocalDate> endDateList = arrangementList1.stream().map(AttendanceArrangement::getEndDate).toList();
|
||||||
|
//
|
||||||
|
// int count = 0;
|
||||||
|
//
|
||||||
|
// for (LocalDate date = calendarStartDate; date.isBefore(calendarEndDate); date = date.plusDays(1)) {
|
||||||
|
// // 2.2 根据当前日期查询在开始时间和结束时间之间的排班信息
|
||||||
|
// //查询当前日期在哪些排班中,当前日期大于等于排班开始日期,小于等于排班结束日期
|
||||||
|
//
|
||||||
|
// if (count >= startDateList.size() || count >= endDateList.size()){
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// // 查询指定日期在哪些排班中
|
||||||
|
//// List<AttendanceArrangement> arrangementList = baseMapper.selectList(
|
||||||
|
//// Wrappers.<AttendanceArrangement>lambdaQuery()
|
||||||
|
//// .between(AttendanceArrangement::getStartDate, date.atStartOfDay(ZoneId.systemDefault()).toInstant(),
|
||||||
|
//// date.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant().minusSeconds(1)));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // 查询指定日期在哪些排班中
|
||||||
|
// List<AttendanceArrangement> arrangementList = baseMapper.selectList(
|
||||||
|
// Wrappers.<AttendanceArrangement>lambdaQuery()
|
||||||
|
// .between(AttendanceArrangement::getStartDate, startDateList.get(count).atStartOfDay(ZoneId.systemDefault()).toInstant(),
|
||||||
|
// endDateList.get(count).atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant().minusSeconds(1)));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// //根据arrangementList查询出排班的id
|
||||||
|
//// List<Long> scheduleIdList = arrangementList.stream().map(AttendanceArrangement::getId).toList();
|
||||||
|
//// //根据排班的id查询出排班的人员详细信息
|
||||||
|
//// List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // 根据排班查询出考勤组id
|
||||||
|
// List<Long> groupIds = arrangementList.stream()
|
||||||
|
// .map(AttendanceArrangement::getGroupId)
|
||||||
|
// .distinct()
|
||||||
|
// .toList();
|
||||||
|
//
|
||||||
|
// // 如果当前日期没有排班,则跳过当前日期
|
||||||
|
// if (groupIds.isEmpty()) {
|
||||||
|
// count++;
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 循环 groupIds,循环和 AttendanceGroup 中的 id 做对比,如果有相同的,则取出 attendanceGroup 中的所有数据
|
||||||
|
// for (Long groupId : groupIds) {
|
||||||
|
// AttendanceGroup attendanceGroup = attendanceGroupMapper.selectById(groupId);
|
||||||
|
// if (attendanceGroup != null) {
|
||||||
|
// // 创建 AttendanceArrangementVo 对象并设置属性
|
||||||
|
// AttendanceArrangementVo vo = new AttendanceArrangementVo();
|
||||||
|
// vo.setId(arrangementList.get(0).getId());
|
||||||
|
// vo.setStartDate(arrangementList.get(0).getStartDate());
|
||||||
|
// vo.setEndDate(arrangementList.get(0).getEndDate());
|
||||||
|
//
|
||||||
|
// //获取到第一个排班的id
|
||||||
|
// Long arrangementId = arrangementList.get(0).getId();
|
||||||
|
// //根据arrangementId查询出人员组的详细信息
|
||||||
|
// AttendanceGroup group = attendanceGroupMapper.selectById(arrangementId);
|
||||||
|
// //将group存到vo中
|
||||||
|
// vo.setAttendanceGroup(group);
|
||||||
|
//
|
||||||
|
// //根据arrangementList查询出排班的id
|
||||||
|
// List<Long> scheduleIdList = arrangementList.stream().map(AttendanceArrangement::getId).distinct().toList();
|
||||||
|
// //根据排班的id查询出排班的人员详细信息
|
||||||
|
// List<AttendanceUserGroup> userGroupList = userGroupMapper.selectList(Wrappers.<AttendanceUserGroup>lambdaQuery().in(AttendanceUserGroup::getScheduleId, scheduleIdList));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //新建attendanceGroup对象,将排班信息和考勤组信息添加到vo中
|
||||||
|
// vo.setAttendanceGroup(attendanceGroup);
|
||||||
|
// //将排班人员信息添加到排班信息中
|
||||||
|
// vo.setUserGroupList(userGroupList);
|
||||||
|
//
|
||||||
|
// result.add(vo);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// count++;
|
||||||
|
// }
|
||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
|
|
||||||
// // 计算交集的开始时间(取较晚的开始时间)和结束时间(取较早的结束时间)
|
|
||||||
// Date overlapStart = calendarStartDate.after(startDate)
|
|
||||||
// ? calendarStartDate : startDate;
|
|
||||||
// Date overlapEnd = calendarEndTimeDate.before(endDate)
|
|
||||||
// ? calendarEndTimeDate : endDate;
|
|
||||||
|
|
||||||
//根据交集的时间范围查询排班信息
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user