Compare commits

...

2 Commits

Author SHA1 Message Date
dy
da0ba9aa0a 抽取公共方法
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2025-07-29 11:08:59 +08:00
dy
bff00b7b4a 新增排班问题处理 2025-07-29 11:06:29 +08:00
5 changed files with 106 additions and 60 deletions

View File

@ -55,12 +55,12 @@ public class AttendanceArrangement extends TenantEntity {
/**
* 开始日期
*/
private LocalDate startDate;
private Date startDate;
/**
* 结束日期(仅date_type=3时有效)
*/
private LocalDate endDate;
private Date endDate;
/**
* 状态0-未生效1-已生效

View File

@ -9,6 +9,7 @@ import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import org.dromara.property.domain.AttendanceScheduleCycle;
import org.dromara.property.domain.AttendanceUserGroup;
import org.springframework.format.annotation.DateTimeFormat;
@ -52,7 +53,7 @@ public class AttendanceArrangementBo extends BaseEntity {
/**
* 日期类型1-单个日期2-长期有效3-期间有效
*/
private Long dateType;
private Integer dateType;
/**
* 开始日期
@ -69,8 +70,8 @@ public class AttendanceArrangementBo extends BaseEntity {
/**
* 前端传日历的开始时间和结束时间
*/
private LocalDate calendarStartDate;
private LocalDate calendarEndTimeDate;
private Date calendarStartDate;
private Date calendarEndTimeDate;
/**
* 前端传某天的当前日期
@ -83,7 +84,15 @@ public class AttendanceArrangementBo extends BaseEntity {
*/
private Long status;
/**
*
* 排班用户组
*/
private List<AttendanceUserGroup> userGroupList;
/**
* 排班日期列表
*/
private List<AttendanceScheduleCycle> scheduleCycleList;
}

View File

@ -28,5 +28,11 @@ public class StatusConstant {
public static final Integer NORMAL = 1;
//日期类型1-单个日期2-长期有效3-期间有效
public static final Integer SINGLE = 1;
public static final Integer LONGTIME = 2;
public static final Integer SHORTTIME = 3;
}

View File

@ -8,7 +8,7 @@ import org.dromara.property.domain.*;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@ -60,13 +60,13 @@ public class AttendanceArrangementVo implements Serializable {
* 开始日期
*/
@ExcelProperty(value = "开始日期")
private LocalDate startDate;
private Date startDate;
/**
* 结束日期(仅date_type=3时有效)
*/
@ExcelProperty(value = "结束日期(仅date_type=3时有效)")
private LocalDate endDate;
private Date endDate;
/**
* 状态0-未生效1-已生效

View File

@ -19,6 +19,8 @@ import org.dromara.property.service.IAttendanceArrangementService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@ -75,63 +77,69 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
LambdaQueryWrapper<AttendanceArrangement> lqw = buildQueryWrapper(bo);
Page<AttendanceArrangementVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
//1.在2号到10号有固定班制和排班制根据当前日期查询出所有的考勤组id
//查询指定日期在哪些排班中
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设置到考勤组中
//循环groupIds循环和AttendanceGroup中的id做对比如果有相同的则取出attendanceGroup中的所有数据
groupIds.forEach(
groupId -> {
//从数据库查询出当前考勤组的所有数据
AttendanceGroup group = attendanceGroupMapper.selectOne(Wrappers.<AttendanceGroup>lambdaQuery().eq(AttendanceGroup::getId, groupId));
Page<AttendanceArrangementVo> attendanceArrangementVoPage = result.setRecords(result.getRecords().stream().peek(vo -> {
// 3.查询出当前考勤组的所有数据从考勤组判断当前id是固定班制还是排班制
if (group.getAttendanceType().equals(StatusConstant.FIXEDSCHEDULE)) {
// 3.1固定班制将当前的日期转为周几然后与数据库中的班次周数作对比取出当前日期的班次信息
//将传来的日期参数转为周几
int week = DateUtil.dayOfWeek(bo.getCurrentDate());
//取出当前日期的周数与数据库中的班次周数作对比取出当前日期的班次信息
AttendanceWeekSet weekSet = weekSetMapper.selectOne(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, groupId).eq(AttendanceWeekSet::getDayOfWeek, week));
//将weekSet存到结果中
AttendanceArrangementVo arrangementVo = new AttendanceArrangementVo();
arrangementVo.setWeekSet(weekSet);
//根据weekSet取出id根据id查询出attendanceWeekSetShift表中的shiftId
Long shiftId = weekSet.getId();
//根据shiftId查询attendanceShift表中对应的id的数据
AttendanceShift shift = attendanceShiftMapper.selectById(shiftId);
//将shift存到结果中
arrangementVo.setShift(shift);
//1.在2号到10号有固定班制和排班制根据当前日期查询出所有的考勤组id
//查询指定日期在哪些排班中
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 (group.getAttendanceType().equals(StatusConstant.SHIFTSCHEDULE)) {
// 3.2排班制判断第一天是从几号开始循环判断判断当前是循环中的第几天取出当前天数的班次信息
//取出排班中的开始时间和结束时间
Date startDate = bo.getStartDate();
Date endDate = bo.getEndDate();
Date currentDate = bo.getCurrentDate();
//取出attendanceScheduleCycle表中的天数
Integer cycleDays = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).getDayNumber();
//在startDate和endDate之间循环判端当前日期是cycleDays中的第几天
int cycleDay = 0;
while (startDate.before(currentDate) || endDate.after(currentDate)) {
cycleDay++;
startDate = DateUtil.offsetDay(startDate, 1);
//判断当前日期是clcleDays中的第几天
if (cycleDay > cycleDays) {
cycleDay = 1;
// 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());
//取出当前日期的周数与数据库中的班次周数作对比取出当前日期的班次信息
AttendanceWeekSet weekSet = weekSetMapper.selectOne(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, groupId).eq(AttendanceWeekSet::getDayOfWeek, week));
//将weekSet存到结果中
AttendanceArrangementVo arrangementVo = new AttendanceArrangementVo();
arrangementVo.setWeekSet(weekSet);
//根据weekSet取出id根据id查询出attendanceWeekSetShift表中的shiftId
Long shiftId = weekSet.getId();
//根据shiftId查询attendanceShift表中对应的id的数据
AttendanceShift shift = attendanceShiftMapper.selectById(shiftId);
//将shift存到结果中
arrangementVo.setShift(shift);
} else if (group.getAttendanceType().equals(StatusConstant.SHIFTSCHEDULE)) {
// 3.2排班制判断第一天是从几号开始循环判断判断当前是循环中的第几天取出当前天数的班次信息
//取出排班中的开始时间和结束时间
Date startDate = bo.getStartDate();
Date endDate = bo.getEndDate();
Date currentDate = bo.getCurrentDate();
//取出attendanceScheduleCycle表中的天数
Integer cycleDays = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId)).getDayNumber();
//在startDate和endDate之间循环判端当前日期是cycleDays中的第几天
int cycleDay = 0;
while (startDate.before(currentDate) || endDate.after(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存到结果中
AttendanceArrangementVo arrangementVo = new AttendanceArrangementVo();
arrangementVo.setCycle(cycle);
//根据cycleDay查询出当前日期的班次信息
AttendanceScheduleCycle cycle = scheduleCycleMapper.selectOne(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, groupId).eq(AttendanceScheduleCycle::getDayNumber, cycleDay));
//将cycle存到结果中
AttendanceArrangementVo arrangementVo = new AttendanceArrangementVo();
arrangementVo.setCycle(cycle);
}
}
}
);
);
}).collect(Collectors.toList()));
// //1.根据当前日期查询出排班信息
@ -154,7 +162,7 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
// }
return TableDataInfo.build(result);
return TableDataInfo.build(attendanceArrangementVoPage);
}
/**
@ -244,6 +252,10 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
if (flag) {
bo.setId(add.getId());
}
judgeDate(bo, add);
//取出当前新增的排班的id
Long ArrangementId = add.getId();
//用获取到的排班id向attendanceUserGroup表中插入数据
@ -257,6 +269,23 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
return flag;
}
private static void judgeDate(AttendanceArrangementBo bo, AttendanceArrangement add) {
//判断排班日期是单个日期还是从此日期开始循环有效还是从此日期开始有效
//1.单个日期
if (bo.getDateType().equals(StatusConstant.SINGLE)) {
add.setEndDate(null);
}
//2.从此日期开始长期有效
if (bo.getDateType().equals(StatusConstant.LONGTIME)) {
//设置长期时间为2099年12月31日
LocalDate longTimeEndDate = LocalDate.of(2099, 12, 31);
add.setEndDate(Date.from(longTimeEndDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
}
if (bo.getDateType().equals(StatusConstant.SHORTTIME)){
add.setEndDate(bo.getEndDate());
}
}
/**
* 修改排班
*
@ -268,6 +297,8 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
AttendanceArrangement update = MapstructUtils.convert(bo, AttendanceArrangement.class);
validEntityBeforeSave(update);
judgeDate(bo, update);
//取出当前排班的id
Long ArrangementId = update.getId();
//用获取到的排班id向attendanceUserGroup表中更新数据