From 3d92528179b85141076b6faa1fb6eb0b613b64d6 Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Mon, 25 May 2026 11:14:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(wms/attendance):=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E5=80=92=E7=8F=AD=E6=8E=92=E7=8F=AD=E7=94=9F=E6=88=90=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BA=A4=E6=8E=A5=E7=8F=AD?= =?UTF-8?q?=E6=97=A5=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将排班生成逻辑从基于累计天数切换为基于日期判断,每月1日、11日、21日(非31日)作为交接班日 - 调整交接班处理逻辑,统一班次标识切换方式,避免重复切换错误 - 优化代码注释和变量命名,提升可读性 - 修复批量插入结果判断变量名错误 --- .../WmsAttendanceScheduleServiceImpl.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/klp-wms/src/main/java/com/klp/service/impl/WmsAttendanceScheduleServiceImpl.java b/klp-wms/src/main/java/com/klp/service/impl/WmsAttendanceScheduleServiceImpl.java index 9d2a2b7e..3b88c59d 100644 --- a/klp-wms/src/main/java/com/klp/service/impl/WmsAttendanceScheduleServiceImpl.java +++ b/klp-wms/src/main/java/com/klp/service/impl/WmsAttendanceScheduleServiceImpl.java @@ -186,20 +186,28 @@ public class WmsAttendanceScheduleServiceImpl implements IWmsAttendanceScheduleS /** * 生成倒班排班 + * 根据用户选择的倒班规则和起始日期,生成指定日期范围内的倒班排班表 + * + * @param bo 生成排班业务对象,包含用户ID、规则ID、起始班次等信息 + * @param startDate 排班开始日期 + * @param endDate 排班结束日期 */ private void generateShiftSchedule(GenerateScheduleBo bo, LocalDate startDate, LocalDate endDate) { // 获取倒班规则 + // 通过规则ID查询倒班规则信息 WmsAttendanceShiftRuleVo rule = shiftRuleService.queryById(bo.getRuleId()); if (rule == null) { throw new RuntimeException("倒班规则不存在"); } // 验证班次匹配 + // 检查用户选择的班次是否与规则中的班次匹配 if (!bo.getShiftId().equals(rule.getShiftA()) && !bo.getShiftId().equals(rule.getShiftB())) { throw new RuntimeException("班次ID与倒班规则不匹配"); } // 获取班次信息 + // 查询规则中定义的所有班次信息,包括常规班次和特殊交接班次 WmsAttendanceShiftVo shiftA = shiftService.queryById(rule.getShiftA()); WmsAttendanceShiftVo shiftB = shiftService.queryById(rule.getShiftB()); WmsAttendanceShiftVo changeShiftB = rule.getChangeShiftBId() != null ? @@ -212,26 +220,31 @@ public class WmsAttendanceScheduleServiceImpl implements IWmsAttendanceScheduleS } // 一次查询整个日期范围内已存在的排班 + // 查询用户在指定日期范围内已有的排班日期,避免重复生成 Set existingDates = getExistingScheduleDates(bo.getUserId(), startDate, endDate); List schedules = new ArrayList<>(); LocalDate currentDate = startDate; - long daysFromStart = 0; - - // 确定初始班次 boolean isCurrentShiftA = bo.getShiftId().equals(rule.getShiftA()); - long cycleDays = rule.getCycleDays() != null ? rule.getCycleDays() : 10; + boolean firstDay = true; while (!currentDate.isAfter(endDate)) { + int dayOfMonth = currentDate.getDayOfMonth(); + + // 判断是否为交接班日(每月1日、11日、21日) + boolean isSwapDay = !firstDay + && (dayOfMonth == 1 || dayOfMonth == 11 || dayOfMonth == 21) + && dayOfMonth != 31; + if (!existingDates.contains(currentDate)) { WmsAttendanceSchedule schedule = new WmsAttendanceSchedule(); schedule.setUserId(bo.getUserId()); schedule.setWorkDate(java.sql.Date.valueOf(currentDate)); - boolean isChangeDay = daysFromStart > 0 && daysFromStart % cycleDays == 0; - - if (isChangeDay) { + // 处理交接班日 + if (isSwapDay) { if (isCurrentShiftA) { + // 白班转夜班 if (changeShiftB != null) { schedule.setShiftId(rule.getChangeShiftBId()); schedule.setShiftName(changeShiftB.getShiftName()); @@ -239,7 +252,6 @@ public class WmsAttendanceScheduleServiceImpl implements IWmsAttendanceScheduleS schedule.setShiftId(rule.getShiftB()); schedule.setShiftName(shiftB.getShiftName()); } - isCurrentShiftA = false; } else { // 夜班转白班 if (changeShiftA != null) { @@ -249,8 +261,9 @@ public class WmsAttendanceScheduleServiceImpl implements IWmsAttendanceScheduleS schedule.setShiftId(rule.getShiftA()); schedule.setShiftName(shiftA.getShiftName()); } - isCurrentShiftA = true; } + // 切换班次标识 + isCurrentShiftA = !isCurrentShiftA; } else { // 普通日 if (isCurrentShiftA) { @@ -265,13 +278,12 @@ public class WmsAttendanceScheduleServiceImpl implements IWmsAttendanceScheduleS schedules.add(schedule); } currentDate = currentDate.plusDays(1); - daysFromStart++; + firstDay = false; } - // 批量插入 if (!schedules.isEmpty()) { - boolean i = baseMapper.insertBatch(schedules); - if (!i) { + boolean ok = baseMapper.insertBatch(schedules); + if (!ok) { throw new RuntimeException("批量插入倒班排班失败"); } }