Merge remote-tracking branch 'origin/master'
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
commit
b7fa3cd788
@ -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-已生效
|
||||
|
@ -42,7 +42,7 @@ public class AttendanceScheduleCycle extends TenantEntity {
|
||||
*/
|
||||
private Long isRest;
|
||||
|
||||
private Long scheduleId;
|
||||
private Long shiftId;
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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-已生效
|
||||
|
@ -61,5 +61,9 @@ public class AttendanceGroupVo implements Serializable {
|
||||
|
||||
List<AttendanceClockDate> clockDateList;
|
||||
|
||||
List<AttendanceScheduleCycle> scheduleCycleList;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,7 +174,16 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
|
||||
@Override
|
||||
public List<AttendanceArrangementVo> queryList(AttendanceArrangementBo bo) {
|
||||
|
||||
//1.根据开始时间和结束时间查询所有的排班信息
|
||||
Date startDate = bo.getStartDate();
|
||||
Date endDate = bo.getEndDate();
|
||||
Date calendarStartDate = bo.getCalendarStartDate();
|
||||
Date calendarEndTimeDate = bo.getCalendarEndTimeDate();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//1.根据日历的开始时间和日历的结束时间查询所有的排班信息
|
||||
List<AttendanceArrangement> arrangementList = baseMapper.selectList(Wrappers.<AttendanceArrangement>lambdaQuery().ge(AttendanceArrangement::getStartDate, bo.getCalendarStartDate()).le(AttendanceArrangement::getEndDate, bo.getCalendarEndTimeDate()));
|
||||
//2.查询人员组的信息
|
||||
//根据开始时间查询排班的id
|
||||
@ -244,6 +261,10 @@ public class AttendanceArrangementServiceImpl implements IAttendanceArrangementS
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
|
||||
judgeDate(bo, add);
|
||||
|
||||
|
||||
//取出当前新增的排班的id
|
||||
Long ArrangementId = add.getId();
|
||||
//用获取到的排班id向attendanceUserGroup表中插入数据
|
||||
@ -257,6 +278,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 +306,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表中更新数据
|
||||
|
@ -78,18 +78,22 @@ public class AttendanceGroupServiceImpl implements IAttendanceGroupService {
|
||||
vo.setWeekList(weekSets);
|
||||
} else if (Objects.equals(attendanceType, SHIFTSCHEDULE)) {
|
||||
//2.排班制
|
||||
//2.1根据id参数查询考勤周期表
|
||||
List<AttendanceWeekSet> weekSets = weekSetMapper.selectList(Wrappers.<AttendanceWeekSet>lambdaQuery().eq(AttendanceWeekSet::getGroupId, id));
|
||||
//2.1根据id参数查询考勤天数表
|
||||
List<AttendanceScheduleCycle> scheduleCycles = attendanceScheduleCycleMapper.selectList(Wrappers.<AttendanceScheduleCycle>lambdaQuery().eq(AttendanceScheduleCycle::getGroupId, id));
|
||||
//2.2根据id参数取出所有考勤天数id
|
||||
List<Long> weekSetIds = weekSets.stream().map(AttendanceWeekSet::getId).toList();
|
||||
//2.3根据天数id查询出中间表
|
||||
List<AttendanceScheduleCycle> scheduleCycles = attendanceScheduleCycleMapper.selectList(Wrappers.<AttendanceScheduleCycle>lambdaQuery().in(AttendanceScheduleCycle::getGroupId, weekSetIds));
|
||||
//2.4根据中间表的班次id查询出班次表id
|
||||
List<Long> scheduleCycleIds = scheduleCycles.stream().map(AttendanceScheduleCycle::getId).toList();
|
||||
//2.5根据班次id查询出班次表
|
||||
List<AttendanceShift> shifts = attendanceShiftMapper.selectList(Wrappers.<AttendanceShift>lambdaQuery().in(AttendanceShift::getId, scheduleCycleIds));
|
||||
//2.3根据天数id查询出中间表
|
||||
List<AttendanceWeeksetShift> weeksetShifts = attendanceWeeksetShiftMapper.selectList(Wrappers.<AttendanceWeeksetShift>lambdaQuery().in(AttendanceWeeksetShift::getWeekSetId, scheduleCycleIds));
|
||||
//2.4根据中间表的班次id查询出班次表id
|
||||
List<Long> weeksetShiftIds = weeksetShifts.stream().map(AttendanceWeeksetShift::getId).toList();
|
||||
//根据id查询出shiftId
|
||||
List<Long> shiftIds = weeksetShifts.stream().map(AttendanceWeeksetShift::getShiftId).toList();
|
||||
//2.5根据shiftId查询出班次表
|
||||
List<AttendanceShift> shifts = attendanceShiftMapper.selectList(Wrappers.<AttendanceShift>lambdaQuery().in(AttendanceShift::getId, shiftIds));
|
||||
//2.6将查询后的数据封装到attendanceGroupVo中
|
||||
vo.setAttendanceList(shifts);
|
||||
vo.setScheduleCycleList(scheduleCycles);
|
||||
|
||||
}
|
||||
|
||||
//根据id查询attendance_clock_date表
|
||||
@ -203,20 +207,21 @@ public class AttendanceGroupServiceImpl implements IAttendanceGroupService {
|
||||
|
||||
//3.排班制
|
||||
if (Objects.equals(add.getAttendanceType(), StatusConstant.SHIFTSCHEDULE)) {
|
||||
//2.2排班制,向天数表中插入数据
|
||||
AttendanceScheduleCycle attendanceScheduleCycle = new AttendanceScheduleCycle();
|
||||
//循环向周期表中插入数据
|
||||
bo.getNumList().forEach(
|
||||
num -> {
|
||||
//2.2排班制,向天数表中插入数据
|
||||
AttendanceScheduleCycle attendanceScheduleCycle = new AttendanceScheduleCycle();
|
||||
attendanceScheduleCycle.setGroupId(add.getId());
|
||||
attendanceScheduleCycle.setDayNumber(num.getDayNumber());
|
||||
attendanceScheduleCycle.setShiftId(num.getShiftId());
|
||||
attendanceScheduleCycleMapper.insert(attendanceScheduleCycle);
|
||||
//获取周期表的id
|
||||
Long scheduleId = attendanceScheduleCycle.getId();
|
||||
//向中间表插入周期的id
|
||||
AttendanceWeeksetShift attendanceWeeksetShift = new AttendanceWeeksetShift();
|
||||
attendanceWeeksetShift.setWeekSetId(scheduleId);
|
||||
attendanceWeeksetShift.setShiftId(num.getScheduleId());
|
||||
attendanceWeeksetShift.setShiftId(num.getShiftId());
|
||||
attendanceWeeksetShiftMapper.insert(attendanceWeeksetShift);
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user