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