排班区域

This commit is contained in:
dy
2025-08-14 15:41:00 +08:00
parent 2cc45acc37
commit 9abb69888b
6 changed files with 100 additions and 68 deletions

View File

@@ -41,6 +41,11 @@ public class AttendanceArrangement extends TenantEntity {
*/ */
private Long groupId; private Long groupId;
/**
* 区域id
*/
private Long areaId;
/** /**
* 排班类型1-固定班制2-排班制 * 排班类型1-固定班制2-排班制
*/ */

View File

@@ -45,6 +45,11 @@ public class AttendanceArrangementBo extends BaseEntity {
*/ */
private Long groupId; private Long groupId;
/**
* 区域id
*/
private Long areaId;
/** /**
* 排班类型1-固定班制2-排班制 * 排班类型1-固定班制2-排班制
*/ */
@@ -99,4 +104,5 @@ public class AttendanceArrangementBo extends BaseEntity {
private List<AttendanceScheduleCycle> scheduleCycleList; private List<AttendanceScheduleCycle> scheduleCycleList;
} }

View File

@@ -45,6 +45,12 @@ public class AttendanceArrangementVo implements Serializable {
@ExcelProperty(value = "考勤组ID") @ExcelProperty(value = "考勤组ID")
private Long groupId; private Long groupId;
@ExcelProperty(value = "区域Id")
/**
* 区域id
*/
private Long areaId;
/** /**
* 排班类型1-固定班制2-排班制 * 排班类型1-固定班制2-排班制
*/ */
@@ -90,5 +96,7 @@ public class AttendanceArrangementVo implements Serializable {
//排班制 //排班制
private AttendanceScheduleCycle scheduleCycle; private AttendanceScheduleCycle scheduleCycle;
private AttendanceArea attendanceArea;
} }

View File

@@ -91,5 +91,7 @@ public class AttendanceUserGroupVo implements Serializable {
private String deptName; private String deptName;
private AttendanceArea attendanceArea;
} }

View File

@@ -1,15 +1,11 @@
package org.dromara.property.service.impl; 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.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;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.PageQuery;
@@ -26,10 +22,8 @@ import org.dromara.system.api.domain.vo.RemoteUserVo;
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;
@@ -59,6 +53,8 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
private final AttendanceScheduleCycleMapper scheduleCycleMapper; private final AttendanceScheduleCycleMapper scheduleCycleMapper;
private final AttendanceAreaMapper attendanceAreaMapper;
@DubboReference @DubboReference
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
/** /**
@@ -149,7 +145,13 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
//将考勤组的信息存到vo中 //将考勤组的信息存到vo中
vo.setAttendanceGroup(attendanceGroup); vo.setAttendanceGroup(attendanceGroup);
//3.查询班制信息 //3.根据id查询区域信息
Long areaId = vo.getAreaId();
//根据区域id查询出区域的详细信息
AttendanceArea attendanceArea = attendanceAreaMapper.selectById(areaId);
vo.setAttendanceArea(attendanceArea);
//4.查询班制信息
//判断当前考勤组的班制是固定班制还是排班制 //判断当前考勤组的班制是固定班制还是排班制
if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.FIXEDSCHEDULE)) { if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.FIXEDSCHEDULE)) {
//3.1固定班制 //3.1固定班制
@@ -205,7 +207,7 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
} }
//根据cycleDay查询出当前日期的班次信息 //5.根据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中
vo.setScheduleCycle(cycle); vo.setScheduleCycle(cycle);

View File

@@ -48,6 +48,8 @@ public class AttendanceUserGroupServiceImpl implements IAttendanceUserGroupServi
private final AttendanceScheduleCycleMapper scheduleCycleMapper; private final AttendanceScheduleCycleMapper scheduleCycleMapper;
private final AttendanceAreaMapper attendanceAreaMapper;
@DubboReference @DubboReference
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@@ -194,73 +196,80 @@ public class AttendanceUserGroupServiceImpl implements IAttendanceUserGroupServi
//根据scheduleId查询出排班的详细信息 //根据scheduleId查询出排班的详细信息
AttendanceArrangement attendanceArrangement = arrangementMapper.selectOne(Wrappers.<AttendanceArrangement>lambdaQuery().eq(AttendanceArrangement::getId, scheduleId)); AttendanceArrangement attendanceArrangement = arrangementMapper.selectOne(Wrappers.<AttendanceArrangement>lambdaQuery().eq(AttendanceArrangement::getId, scheduleId));
// 假设每个vo只有一个scheduleId // 假设每个vo只有一个scheduleId
Long userGroupListScheduleId = attendanceArrangement.getId(); Long userGroupListScheduleId = attendanceArrangement.getId();
AttendanceArrangement arrangement = arrangementMapper.selectOne(Wrappers.<AttendanceArrangement>lambdaQuery().eq(AttendanceArrangement::getId, userGroupListScheduleId)); AttendanceArrangement arrangement = arrangementMapper.selectOne(Wrappers.<AttendanceArrangement>lambdaQuery().eq(AttendanceArrangement::getId, userGroupListScheduleId));
vo.setAttendanceArrangement(arrangement); vo.setAttendanceArrangement(arrangement);
// 根据scheduleId过滤出groupId // 根据scheduleId过滤出groupId
Long groupId = arrangement.getGroupId(); Long groupId = arrangement.getGroupId();
// 根据groupId查询出考勤组的详细信息 // 根据groupId查询出考勤组的详细信息
AttendanceGroup attendanceGroup = groupMapper.selectById(groupId); AttendanceGroup attendanceGroup = groupMapper.selectById(groupId);
vo.setAttendanceGroup(attendanceGroup); vo.setAttendanceGroup(attendanceGroup);
// 判断当前考勤组的班制是固定班制还是排班制
if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.FIXEDSCHEDULE)) {
// 固定班制
// 根据考勤组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);
if (attendanceWeekSet != null) {
// 根据过滤出来的attendanceWeekSet的weekSetId查询出shiftId
Long shiftId = attendanceWeekSet.getShiftId();
// 根据shiftId查询出班次的详细信息
AttendanceShift attendanceShift = shiftMapper.selectById(shiftId);
// 将attendanceShift存到vo中
vo.setAttendanceShift(attendanceShift);
}
} else if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.SHIFTSCHEDULE)) {
// 排班制
// 将startDate作为第一天endDate作为最后一天循环判断当前日期是第几天取出当前天数的班次信息。
LocalDate startDate = vo.getStartDate();
LocalDate endDate = vo.getEndDate();
LocalDate currentDate = bo.getCurrentDate();
// 取出attendanceScheduleCycle表中的天数 //3.根据id查询区域信息
List<Integer> cycleDaysList = scheduleCycleMapper.selectList(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).stream() Long areaId = arrangement.getAreaId();
.map(AttendanceScheduleCycle::getDayNumber) //根据区域id查询出区域的详细信息
.toList(); AttendanceArea attendanceArea = attendanceAreaMapper.selectById(areaId);
vo.setAttendanceArea(attendanceArea);
// 在startDate和endDate之间循环判断当前日期是cycleDays中的第几天 // 判断当前考勤组的班制是固定班制还是排班制
for (LocalDate date = startDate; date.isBefore(endDate) || date.isEqual(endDate); date = date.plusDays(1)) { if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.FIXEDSCHEDULE)) {
if (date.isEqual(currentDate)) { // 固定班制
// 判断当前日期是cycleDays中的第几天 // 根据考勤组id查询出班制信息的dayOfWeek
int dayNumber = (int) (ChronoUnit.DAYS.between(startDate, date) + 1); List<AttendanceWeekSet> weekSetList = weekSetMapper.selectList(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, groupId));
int cycleDay = dayNumber % cycleDaysList.size(); // 将当前日期转换为周几
if (cycleDay == 0) { int weekNumber = bo.getCurrentDate().getDayOfWeek().getValue();
cycleDay = cycleDaysList.size(); // 匹配weekNumber和weekSetList中的dayOfWeek匹配成功则将weekSet存到vo中
} AttendanceWeekSet attendanceWeekSet = weekSetList.stream().filter(weekSet -> weekSet.getDayOfWeek() == weekNumber).findFirst().orElse(null);
// 根据cycleDay查询出当前日期的班次信息 if (attendanceWeekSet != null) {
AttendanceScheduleCycle cycle = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery() // 根据过滤出来的attendanceWeekSet的weekSetId查询出shiftId
.eq(AttendanceScheduleCycle::getGroupId, groupId) Long shiftId = attendanceWeekSet.getShiftId();
.eq(AttendanceScheduleCycle::getDayNumber, cycleDay)); // 根据shiftId查询出班次的详细信息
if (cycle != null) { AttendanceShift attendanceShift = shiftMapper.selectById(shiftId);
// 将cycle存到vo中 // 将attendanceShift存到vo中
vo.setScheduleCycle(cycle); vo.setAttendanceShift(attendanceShift);
// 根据cycleId查询出shiftId }
Long shiftId = cycle.getShiftId(); } else if (Objects.equals(attendanceGroup.getAttendanceType(), StatusConstant.SHIFTSCHEDULE)) {
// 根据shiftId查询出班次的详细信息 // 排班制
AttendanceShift attendanceShift = shiftMapper.selectById(shiftId); // 将startDate作为第一天endDate作为最后一天循环判断当前日期是第几天取出当前天数的班次信息。
// 将shift存到vo中 LocalDate startDate = vo.getStartDate();
vo.setAttendanceShift(attendanceShift); LocalDate endDate = vo.getEndDate();
} LocalDate currentDate = bo.getCurrentDate();
break; // 找到当前日期后跳出循环
// 取出attendanceScheduleCycle表中的天数
List<Integer> cycleDaysList = scheduleCycleMapper.selectList(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).stream()
.map(AttendanceScheduleCycle::getDayNumber)
.toList();
// 在startDate和endDate之间循环判断当前日期是cycleDays中的第几天
for (LocalDate date = startDate; date.isBefore(endDate) || date.isEqual(endDate); date = date.plusDays(1)) {
if (date.isEqual(currentDate)) {
// 判断当前日期是cycleDays中的第几天
int dayNumber = (int) (ChronoUnit.DAYS.between(startDate, date) + 1);
int 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));
if (cycle != null) {
// 将cycle存到vo中
vo.setScheduleCycle(cycle);
// 根据cycleId查询出shiftId
Long shiftId = cycle.getShiftId();
// 根据shiftId查询出班次的详细信息
AttendanceShift attendanceShift = shiftMapper.selectById(shiftId);
// 将shift存到vo中
vo.setAttendanceShift(attendanceShift);
}
break; // 找到当前日期后跳出循环
} }
} }
}
} }
return vo; return vo;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));