From 1aab8aef43d4d0baa23c5535b0a466e640079767 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 19 Feb 2026 21:25:17 +0800 Subject: [PATCH] feat(mes): 完善排班日历功能,新增假期过滤及班组排班记录查询逻辑 --- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/MesCalCalendarController.java | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarListReqVO.java | 7 +++++-- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarRespVO.java | 7 +++---- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarService.java | 23 ----------------------- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarServiceImpl.java | 251 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java | 24 ++++++++++++++++++++++++ yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java | 16 ++++++++++++++-- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftService.java | 22 ++++++++++++++++++++++ yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftServiceImpl.java | 12 ++++++++++++ yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberService.java | 8 ++++++++ yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberServiceImpl.java | 5 +++++ yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamService.java | 22 ++++++++++++++++++++++ yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamServiceImpl.java | 15 +++++++++++++-- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftService.java | 3 +-- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java | 3 ++- 15 files changed, 325 insertions(+), 292 deletions(-) delete mode 100644 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarService.java delete mode 100644 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarServiceImpl.java diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/MesCalCalendarController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/MesCalCalendarController.java index 244b1a9..647eaba 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/MesCalCalendarController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/MesCalCalendarController.java @@ -1,9 +1,23 @@ package cn.iocoder.yudao.module.mes.controller.admin.cal.calendar; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarListReqVO; import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarRespVO; -import cn.iocoder.yudao.module.mes.service.cal.calendar.MesCalCalendarService; +import cn.iocoder.yudao.module.mes.controller.admin.cal.team.vo.shift.MesCalTeamShiftListReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.holiday.MesCalHolidayDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanShiftDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamMemberDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamShiftDO; +import cn.iocoder.yudao.module.mes.service.cal.holiday.MesCalHolidayService; +import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanService; +import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanShiftService; +import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamMemberService; +import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamService; +import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamShiftService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; @@ -14,9 +28,13 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.List; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - MES 排班日历") @RestController @@ -25,14 +43,185 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; public class MesCalCalendarController { @Resource - private MesCalCalendarService calendarService; + private MesCalTeamShiftService teamShiftService; + @Resource + private MesCalTeamService teamService; + @Resource + private MesCalPlanShiftService planShiftService; + @Resource + private MesCalPlanService planService; + @Resource + private MesCalTeamMemberService teamMemberService; + @Resource + private MesCalHolidayService holidayService; @GetMapping("/list") @Operation(summary = "查询排班日历") @PreAuthorize("@ss.hasPermission('mes:cal-team-shift:query')") public CommonResult> getCalendarList(@Valid MesCalCalendarListReqVO reqVO) { - List list = calendarService.getCalendarList(reqVO); - return success(list); + // 1.1 根据查询类型获取班组排班记录 + List teamShifts = getTeamShifts(reqVO); + if (CollUtil.isEmpty(teamShifts)) { + return success(Collections.emptyList()); + } + // 1.2 查询假期列表,构建假期日期集合 + // TODO @AI:是不是按照指定日期查询下,避免加载所有! + Set holidaySet = buildHolidaySet(); + // 1.3 批量查询关联数据:班组、班次、排班计划 + Map teamMap = teamService.getTeamMap( + convertSet(teamShifts, MesCalTeamShiftDO::getTeamId)); + Map shiftMap = planShiftService.getPlanShiftMap( + convertSet(teamShifts, MesCalTeamShiftDO::getShiftId)); + Map planMap = planService.getPlanMap( + convertSet(teamShifts, MesCalTeamShiftDO::getPlanId)); + + // 2. 按 day 分组聚合,过滤假期 + // TODO @AI:使用 MapUtils 里的方法; + Map> dayGroupMap = teamShifts.stream() + .collect(Collectors.groupingBy( + ts -> ts.getDay().toLocalDate().format(DatePattern.NORM_DATE_FORMATTER), + LinkedHashMap::new, + Collectors.toList() + )); + List result = new ArrayList<>(); + for (Map.Entry> entry : dayGroupMap.entrySet()) { + String dayStr = entry.getKey(); + // 4.1 过滤假期 + if (holidaySet.contains(dayStr)) { + continue; + } + List dayShifts = entry.getValue(); + dayShifts.sort(Comparator.comparing(ts -> ts.getSort() != null ? ts.getSort() : 0)); // 按 sort 升序排列 + // 4.2 获取轮班方式(取第一条记录关联的排班计划) + Integer shiftType = null; + MesCalTeamShiftDO first = dayShifts.get(0); + if (first.getPlanId() != null) { + MesCalPlanDO plan = planMap.get(first.getPlanId()); + if (plan != null) { + shiftType = plan.getShiftType(); + } + } + // 4.3 构建班组排班项列表 + // TODO @AI:convertList? + List items = dayShifts.stream() + .map(ts -> buildTeamShiftItem(ts, teamMap, shiftMap)) + .collect(Collectors.toList()); + + // 4.4 构建日历项,添加到结果列表 + // TODO @AI:先构建出一个对象,在 add 到 result 里; + result.add(MesCalCalendarRespVO.builder() + .day(LocalDate.parse(dayStr, DatePattern.NORM_DATE_FORMATTER).atStartOfDay()) + .shiftType(shiftType) + .teamShifts(items) + .build()); + } + return success(result); + } + + /** + * 根据查询类型获取班组排班记录 + */ + @SuppressWarnings("EnhancedSwitchMigration") + private List getTeamShifts(MesCalCalendarListReqVO reqVO) { + LocalDateTime startDay = reqVO.getStartDay(); + LocalDateTime endDay = reqVO.getEndDay(); + switch (reqVO.getQueryType()) { + case MesCalCalendarListReqVO.QUERY_TYPE_TYPE: + return getTeamShiftsByCalendarType(reqVO.getCalendarType(), startDay, endDay); + case MesCalCalendarListReqVO.QUERY_TYPE_TEAM: + return getTeamShiftsByTeamId(reqVO.getTeamId(), startDay, endDay); + case MesCalCalendarListReqVO.QUERY_TYPE_USER: + return getTeamShiftsByUserId(reqVO.getUserId(), startDay, endDay); + default: + return Collections.emptyList(); + } + } + + /** + * 构建单条 TeamShiftItem + */ + private MesCalCalendarRespVO.TeamShiftItem buildTeamShiftItem(MesCalTeamShiftDO ts, + Map teamMap, + Map shiftMap) { + MesCalTeamDO team = teamMap.get(ts.getTeamId()); + MesCalPlanShiftDO shift = shiftMap.get(ts.getShiftId()); + return MesCalCalendarRespVO.TeamShiftItem.builder() + .teamId(ts.getTeamId()).teamName(team != null ? team.getName() : null) + .shiftId(ts.getShiftId()).shiftName(shift != null ? shift.getName() : null) + .sort(ts.getSort()).build(); + } + + /** + * 按班组类型查询排班记录 + */ + private List getTeamShiftsByCalendarType(Integer calendarType, + LocalDateTime startDay, LocalDateTime endDay) { + if (calendarType == null) { + return Collections.emptyList(); + } + // 1. 查询指定类型的所有班组 + List teams = teamService.getTeamList().stream() + .filter(t -> calendarType.equals(t.getCalendarType())) + .collect(Collectors.toList()); + if (CollUtil.isEmpty(teams)) { + return Collections.emptyList(); + } + // 2. 查询这些班组在日期范围内的排班记录 + List result = new ArrayList<>(teams.size()); + for (MesCalTeamDO team : teams) { + MesCalTeamShiftListReqVO reqVO = new MesCalTeamShiftListReqVO() + .setTeamId(team.getId()).setStartDay(startDay).setEndDay(endDay); + result.addAll(teamShiftService.getTeamShiftList(reqVO)); + } + return result; + } + + /** + * 按班组编号查询排班记录 + */ + private List getTeamShiftsByTeamId(Long teamId, LocalDateTime startDay, LocalDateTime endDay) { + if (teamId == null) { + return Collections.emptyList(); + } + MesCalTeamShiftListReqVO reqVO = new MesCalTeamShiftListReqVO() + .setTeamId(teamId).setStartDay(startDay).setEndDay(endDay); + return teamShiftService.getTeamShiftList(reqVO); + } + + /** + * 按用户编号查询排班记录(先查用户所属班组,再查班组排班) + */ + private List getTeamShiftsByUserId(Long userId, + LocalDateTime startDay, LocalDateTime endDay) { + if (userId == null) { + return Collections.emptyList(); + } + // 1. 查询用户所属的班组(一个用户只属于一个班组) + MesCalTeamMemberDO member = teamMemberService.getTeamMemberByUserId(userId); + if (member == null) { + return Collections.emptyList(); + } + // 2. 查询该班组在日期范围内的排班记录 + MesCalTeamShiftListReqVO reqVO = new MesCalTeamShiftListReqVO() + .setTeamId(member.getTeamId()).setStartDay(startDay).setEndDay(endDay); + return teamShiftService.getTeamShiftList(reqVO); + } + + /** + * 构建假期日期集合(yyyy-MM-dd 格式) + */ + private Set buildHolidaySet() { + List holidays = holidayService.getHolidayList(); + Set holidaySet = new HashSet<>(); + for (MesCalHolidayDO holiday : holidays) { + // type=2 表示节假日 + // todo @AI:需要搞个枚举类;另外 holiday 那的字段,也要处理下; + if (holiday.getType() != null && holiday.getType() == 2) { + LocalDate day = holiday.getDay().toLocalDate(); + holidaySet.add(day.format(DatePattern.NORM_DATE_FORMATTER)); + } + } + return holidaySet; } } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarListReqVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarListReqVO.java index 238a360..ac4774d 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarListReqVO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarListReqVO.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -17,11 +18,13 @@ public class MesCalCalendarListReqVO { public static final String QUERY_TYPE_TEAM = "TEAM"; public static final String QUERY_TYPE_USER = "USER"; - @Schema(description = "开始日期") + @Schema(description = "开始日期", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "开始日期不能为空") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime startDay; - @Schema(description = "结束日期") + @Schema(description = "结束日期", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "结束日期不能为空") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime endDay; diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarRespVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarRespVO.java index 4e6bb37..254857e 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarRespVO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/vo/MesCalCalendarRespVO.java @@ -6,7 +6,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; @Schema(description = "管理后台 - MES 排班日历 Response VO") @@ -16,9 +16,8 @@ import java.util.List; @AllArgsConstructor public class MesCalCalendarRespVO { - // TODO @AI: private LocalDateTime day; 合适点,和 holiday 保持统一; - @Schema(description = "日期,格式 yyyy-MM-dd", requiredMode = Schema.RequiredMode.REQUIRED, example = "2025-01-15") - private String day; + @Schema(description = "日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2025-01-15 00:00:00") + private LocalDateTime day; @Schema(description = "轮班方式", example = "2") private Integer shiftType; // 对应 MesCalShiftTypeEnum 枚举值 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarService.java deleted file mode 100644 index 45773d8..0000000 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarService.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.module.mes.service.cal.calendar; - -import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarListReqVO; -import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarRespVO; - -import java.util.List; - -/** - * MES 排班日历 Service 接口 - * - * @author 芋道源码 - */ -public interface MesCalCalendarService { - - /** - * 查询排班日历列表 - * - * @param reqVO 查询条件 - * @return 排班日历列表 - */ - List getCalendarList(MesCalCalendarListReqVO reqVO); - -} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarServiceImpl.java deleted file mode 100644 index 0191e43..0000000 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/calendar/MesCalCalendarServiceImpl.java +++ /dev/null @@ -1,251 +0,0 @@ -package cn.iocoder.yudao.module.mes.service.cal.calendar; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarListReqVO; -import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarRespVO; -import cn.iocoder.yudao.module.mes.controller.admin.cal.team.vo.shift.MesCalTeamShiftListReqVO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.holiday.MesCalHolidayDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanShiftDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamMemberDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamShiftDO; -import cn.iocoder.yudao.module.mes.dal.mysql.cal.holiday.MesCalHolidayMapper; -import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalPlanMapper; -import cn.iocoder.yudao.module.mes.dal.mysql.cal.team.MesCalTeamMapper; -import cn.iocoder.yudao.module.mes.dal.mysql.cal.team.MesCalTeamMemberMapper; -import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanShiftService; -import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamShiftService; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.stream.Collectors; - -/** - * MES 排班日历 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -public class MesCalCalendarServiceImpl implements MesCalCalendarService { - - // TODO @AI:看看能不能用 hutool 里,已经枚举好的; - private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - - @Resource - private MesCalTeamShiftService teamShiftService; - @Resource - private MesCalPlanShiftService planShiftService; - @Resource - private MesCalTeamMapper teamMapper; - @Resource - private MesCalTeamMemberMapper teamMemberMapper; - @Resource - private MesCalPlanMapper planMapper; - @Resource - private MesCalHolidayMapper holidayMapper; - - @Override - public List getCalendarList(MesCalCalendarListReqVO reqVO) { - // 1. 计算月份范围 - // TODO @AI:参数非空,通过 validator 在 MesCalCalendarListReqVO 里; - LocalDateTime startDay = reqVO.getStartDay(); - LocalDateTime endDay = reqVO.getEndDay(); - if (startDay == null || endDay == null) { - return Collections.emptyList(); - } - - // 2. 根据查询类型查询班组排班记录 - // TODO @AI:抽个小方法去返回; - List teamShifts; - switch (reqVO.getQueryType()) { - case MesCalCalendarListReqVO.QUERY_TYPE_TYPE: - teamShifts = getTeamShiftsByCalendarType(reqVO.getCalendarType(), startDay, endDay); - break; - case MesCalCalendarListReqVO.QUERY_TYPE_TEAM: - teamShifts = getTeamShiftsByTeamId(reqVO.getTeamId(), startDay, endDay); - break; - case MesCalCalendarListReqVO.QUERY_TYPE_USER: - teamShifts = getTeamShiftsByUserId(reqVO.getUserId(), startDay, endDay); - break; - default: - return Collections.emptyList(); - } - if (CollUtil.isEmpty(teamShifts)) { - return Collections.emptyList(); - } - - // 3. 查询假期列表,构建假期日期集合 - Set holidaySet = buildHolidaySet(); - - // 4. 批量查询关联数据:班组名称、班次名称 - // TODO @AI:需要通过 teamService 去查询,并且要 getTeamMap 的方式;不要 Map 这种; - Set teamIds = teamShifts.stream().map(MesCalTeamShiftDO::getTeamId).collect(Collectors.toSet()); - Map teamNameMap = teamMapper.selectBatchIds(teamIds).stream() - .collect(Collectors.toMap(MesCalTeamDO::getId, MesCalTeamDO::getName)); - - // TODO @AI:使用 planShiftService 的 getPlanShiftMap 方法,批量查询并返回 Map;不要 for 循环去查询; - Set shiftIds = teamShifts.stream().map(MesCalTeamShiftDO::getShiftId).collect(Collectors.toSet()); - Map shiftMap = new HashMap<>(); - if (CollUtil.isNotEmpty(shiftIds)) { - for (Long shiftId : shiftIds) { - MesCalPlanShiftDO shift = planShiftService.getPlanShift(shiftId); - if (shift != null) { - shiftMap.put(shiftId, shift); - } - } - } - - // 查询 plan 用于获取 shiftType - // TODO @AI:使用 planService 的 getPlanMap 方法,批量查询并返回 Map;不要 for 循环去查询; - Set planIds = teamShifts.stream().map(MesCalTeamShiftDO::getPlanId) - .filter(Objects::nonNull).collect(Collectors.toSet()); - Map planMap = new HashMap<>(); - if (CollUtil.isNotEmpty(planIds)) { - planMap.putAll(planMapper.selectBatchIds(planIds).stream() - .collect(Collectors.toMap(MesCalPlanDO::getId, p -> p))); - } - - // 5. 按 day 分组聚合,过滤假期 - Map> dayGroupMap = teamShifts.stream() - .collect(Collectors.groupingBy( - ts -> ts.getDay().toLocalDate().format(DAY_FORMATTER), - LinkedHashMap::new, - Collectors.toList() - )); - - List result = new ArrayList<>(); - for (Map.Entry> entry : dayGroupMap.entrySet()) { - String dayStr = entry.getKey(); - // 过滤假期 - if (holidaySet.contains(dayStr)) { - continue; - } - List dayShifts = entry.getValue(); - // 排序 - dayShifts.sort(Comparator.comparing(ts -> ts.getSort() != null ? ts.getSort() : 0)); - - // 获取 shiftType(取第一条记录的 planId 对应的 plan) - Integer shiftType = null; - MesCalTeamShiftDO first = dayShifts.get(0); - if (first.getPlanId() != null) { - MesCalPlanDO plan = planMap.get(first.getPlanId()); - if (plan != null) { - shiftType = plan.getShiftType(); - } - } - - // TODO @AI:看看怎么进一步简化; - List items = dayShifts.stream() - .map(ts -> { - MesCalPlanShiftDO shift = shiftMap.get(ts.getShiftId()); - return MesCalCalendarRespVO.TeamShiftItem.builder() - .teamId(ts.getTeamId()) - .teamName(teamNameMap.get(ts.getTeamId())) - .shiftId(ts.getShiftId()) - .shiftName(shift != null ? shift.getName() : null) - .sort(ts.getSort()) - .build(); - }) - .collect(Collectors.toList()); - - result.add(MesCalCalendarRespVO.builder() - .day(LocalDate.parse(dayStr, DAY_FORMATTER)) - .shiftType(shiftType) - .teamShifts(items) - .build()); - } - return result; - } - - /** - * 按班组类型查询排班记录 - */ - private List getTeamShiftsByCalendarType(Integer calendarType, - LocalDateTime startDay, LocalDateTime endDay) { - if (calendarType == null) { - return Collections.emptyList(); - } - // 1. 查询指定类型的所有班组 - List teams = teamMapper.selectList(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() - .eq(MesCalTeamDO::getCalendarType, calendarType)); - if (CollUtil.isEmpty(teams)) { - return Collections.emptyList(); - } - // 2. 查询这些班组在日期范围内的排班记录 - List result = new ArrayList<>(); - for (MesCalTeamDO team : teams) { - MesCalTeamShiftListReqVO reqVO = new MesCalTeamShiftListReqVO(); - reqVO.setTeamId(team.getId()); - reqVO.setStartDay(startDay); - reqVO.setEndDay(endDay); - result.addAll(teamShiftService.getTeamShiftList(reqVO)); - } - return result; - } - - /** - * 按班组编号查询排班记录 - */ - private List getTeamShiftsByTeamId(Long teamId, - LocalDateTime startDay, LocalDateTime endDay) { - if (teamId == null) { - return Collections.emptyList(); - } - MesCalTeamShiftListReqVO reqVO = new MesCalTeamShiftListReqVO(); - reqVO.setTeamId(teamId); - reqVO.setStartDay(startDay); - reqVO.setEndDay(endDay); - return teamShiftService.getTeamShiftList(reqVO); - } - - /** - * 按用户编号查询排班记录(先查用户所属班组,再查班组排班) - */ - private List getTeamShiftsByUserId(Long userId, - LocalDateTime startDay, LocalDateTime endDay) { - if (userId == null) { - return Collections.emptyList(); - } - // 1. 查询用户所属的班组 - List members = teamMemberMapper.selectList( - new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() - .eq(MesCalTeamMemberDO::getUserId, userId)); - if (CollUtil.isEmpty(members)) { - return Collections.emptyList(); - } - // 2. 查询这些班组在日期范围内的排班记录 - List result = new ArrayList<>(); - for (MesCalTeamMemberDO member : members) { - MesCalTeamShiftListReqVO reqVO = new MesCalTeamShiftListReqVO(); - reqVO.setTeamId(member.getTeamId()); - reqVO.setStartDay(startDay); - reqVO.setEndDay(endDay); - result.addAll(teamShiftService.getTeamShiftList(reqVO)); - } - return result; - } - - /** - * 构建假期日期集合 - */ - private Set buildHolidaySet() { - List holidays = holidayMapper.selectList(); - Set holidaySet = new HashSet<>(); - for (MesCalHolidayDO holiday : holidays) { - // type=2 表示节假日 - if (holiday.getType() != null && holiday.getType() == 2) { - LocalDate day = holiday.getDay().toLocalDate(); - holidaySet.add(day.format(DAY_FORMATTER)); - } - } - return holidaySet; - } - -} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java index 1f97e55..5e141f6 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java @@ -6,6 +6,12 @@ import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanSaveRe import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO; import jakarta.validation.Valid; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; + /** * MES 排班计划 Service 接口 * @@ -59,6 +65,24 @@ public interface MesCalPlanService { MesCalPlanDO getPlan(Long id); /** + * 获得排班计划列表 + * + * @param ids 排班计划编号集合 + * @return 排班计划列表 + */ + List getPlanList(Collection ids); + + /** + * 获得排班计划 Map + * + * @param ids 排班计划编号集合 + * @return 排班计划 Map,key 为编号 + */ + default Map getPlanMap(Collection ids) { + return convertMap(getPlanList(ids), MesCalPlanDO::getId); + } + + /** * 获得排班计划分页 * * @param pageReqVO 分页查询 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java index d28d31b..80f0343 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.mes.service.cal.plan; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanPageReqVO; @@ -16,6 +17,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; @@ -91,8 +96,7 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { planMapper.updateById(updateObj); // 3. 生成班组排班记录 - // TODO @AI:方法名,不要缩写; - teamShiftService.genRecords(id); + teamShiftService.generateTeamShiftRecords(id); } @Override @@ -114,6 +118,14 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { } @Override + public List getPlanList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } + return planMapper.selectByIds(ids); + } + + @Override public PageResult getPlanPage(MesCalPlanPageReqVO pageReqVO) { return planMapper.selectPage(pageReqVO); } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftService.java index 7fa3f39..1fa08a9 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftService.java @@ -6,7 +6,11 @@ import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalPlan import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanShiftDO; import jakarta.validation.Valid; +import java.util.Collection; import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * MES 计划班次 Service 接口 @@ -78,6 +82,24 @@ public interface MesCalPlanShiftService { void addDefaultPlanShift(Long planId, Integer shiftType); /** + * 获得计划班次列表 + * + * @param ids 班次编号集合 + * @return 班次列表 + */ + List getPlanShiftList(Collection ids); + + /** + * 获得计划班次 Map + * + * @param ids 班次编号集合 + * @return 班次 Map,key 为编号 + */ + default Map getPlanShiftMap(Collection ids) { + return convertMap(getPlanShiftList(ids), MesCalPlanShiftDO::getId); + } + + /** * 根据排班计划编号删除所有班次 * * @param planId 排班计划编号 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftServiceImpl.java index 910452e..70d16c5 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftServiceImpl.java @@ -15,6 +15,10 @@ import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import cn.hutool.core.collection.CollUtil; + +import java.util.Collection; +import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -132,6 +136,14 @@ public class MesCalPlanShiftServiceImpl implements MesCalPlanShiftService { } @Override + public List getPlanShiftList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } + return planShiftMapper.selectByIds(ids); + } + + @Override public void deletePlanShiftByPlanId(Long planId) { planShiftMapper.deleteByPlanId(planId); } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberService.java index 24da78f..8713b2c 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberService.java @@ -64,6 +64,14 @@ public interface MesCalTeamMemberService { List getTeamMemberListByTeamIds(Collection teamIds); /** + * 根据用户编号获得班组成员 + * + * @param userId 用户编号 + * @return 班组成员,不存在则返回 null + */ + MesCalTeamMemberDO getTeamMemberByUserId(Long userId); + + /** * 根据班组编号删除所有成员 * * @param teamId 班组编号 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberServiceImpl.java index 76e7fa9..f8c6b32 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamMemberServiceImpl.java @@ -74,6 +74,11 @@ public class MesCalTeamMemberServiceImpl implements MesCalTeamMemberService { } @Override + public MesCalTeamMemberDO getTeamMemberByUserId(Long userId) { + return teamMemberMapper.selectByUserId(userId); + } + + @Override public void deleteByTeamId(Long teamId) { teamMemberMapper.deleteByTeamId(teamId); } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamService.java index ddf9ce9..5251559 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamService.java @@ -6,7 +6,11 @@ import cn.iocoder.yudao.module.mes.controller.admin.cal.team.vo.MesCalTeamSaveRe import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamDO; import jakarta.validation.Valid; +import java.util.Collection; import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * MES 班组 Service 接口 @@ -61,6 +65,24 @@ public interface MesCalTeamService { List getTeamList(); /** + * 获得班组列表 + * + * @param ids 班组编号集合 + * @return 班组列表 + */ + List getTeamList(Collection ids); + + /** + * 获得班组 Map + * + * @param ids 班组编号集合 + * @return 班组 Map,key 为编号 + */ + default Map getTeamMap(Collection ids) { + return convertMap(getTeamList(ids), MesCalTeamDO::getId); + } + + /** * 校验班组存在 * * @param id 编号 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamServiceImpl.java index 8dab282..4f1b055 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamServiceImpl.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.mes.service.cal.team; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.cal.team.vo.MesCalTeamPageReqVO; @@ -12,6 +14,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.util.Collection; +import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -83,6 +87,14 @@ public class MesCalTeamServiceImpl implements MesCalTeamService { } @Override + public List getTeamList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } + return teamMapper.selectByIds(ids); + } + + @Override public MesCalTeamDO validateTeamExists(Long id) { MesCalTeamDO team = teamMapper.selectById(id); if (team == null) { @@ -96,8 +108,7 @@ public class MesCalTeamServiceImpl implements MesCalTeamService { if (team == null) { return; } - // TODO @AI:ObjUtil notEquals - if (id == null || !id.equals(team.getId())) { + if (ObjUtil.notEqual(id, team.getId())) { throw exception(CAL_TEAM_CODE_DUPLICATE); } } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftService.java index 45efa8b..8673765 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftService.java @@ -12,13 +12,12 @@ import java.util.List; */ public interface MesCalTeamShiftService { - // TODO @AI:方法名,优化下; /** * 根据排班计划生成班组排班记录 * * @param planId 排班计划编号 */ - void genRecords(Long planId); + void generateTeamShiftRecords(Long planId); /** * 获得班组排班列表 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java index 718e3fe..6fc8bf6 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java @@ -45,9 +45,10 @@ public class MesCalTeamShiftServiceImpl implements MesCalTeamShiftService { @Lazy private MesCalPlanTeamService planTeamService; + // TODO @芋艿:这块逻辑,可能要想下; @Async @Override - public void genRecords(Long planId) { + public void generateTeamShiftRecords(Long planId) { // 1.1 查询排班计划 MesCalPlanDO plan = planService.getPlan(planId); // 1.2 查询计划中的班次列表 -- libgit2 0.21.4