Commit 7098655a2ea78c6867d3b96a2ae5eec5958626a8
1 parent
1aab8aef
feat(mes): 优化排班日历功能,新增假期按日期范围查询逻辑及假期类型枚举
Showing
5 changed files
with
82 additions
and
40 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/calendar/MesCalCalendarController.java
| @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.mes.controller.admin.cal.calendar; | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.mes.controller.admin.cal.calendar; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.date.DatePattern; | 4 | import cn.hutool.core.date.DatePattern; |
| 5 | +import cn.hutool.core.date.LocalDateTimeUtil; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarListReqVO; | 7 | import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarListReqVO; |
| 7 | import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarRespVO; | 8 | import cn.iocoder.yudao.module.mes.controller.admin.cal.calendar.vo.MesCalCalendarRespVO; |
| @@ -12,6 +13,7 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanShiftDO; | @@ -12,6 +13,7 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanShiftDO; | ||
| 12 | import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamDO; | 13 | import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamDO; |
| 13 | import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamMemberDO; | 14 | import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamMemberDO; |
| 14 | import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamShiftDO; | 15 | import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamShiftDO; |
| 16 | +import cn.iocoder.yudao.module.mes.enums.cal.MesCalHolidayTypeEnum; | ||
| 15 | import cn.iocoder.yudao.module.mes.service.cal.holiday.MesCalHolidayService; | 17 | import cn.iocoder.yudao.module.mes.service.cal.holiday.MesCalHolidayService; |
| 16 | import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanService; | 18 | import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanService; |
| 17 | import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanShiftService; | 19 | import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanShiftService; |
| @@ -28,13 +30,12 @@ import org.springframework.web.bind.annotation.GetMapping; | @@ -28,13 +30,12 @@ import org.springframework.web.bind.annotation.GetMapping; | ||
| 28 | import org.springframework.web.bind.annotation.RequestMapping; | 30 | import org.springframework.web.bind.annotation.RequestMapping; |
| 29 | import org.springframework.web.bind.annotation.RestController; | 31 | import org.springframework.web.bind.annotation.RestController; |
| 30 | 32 | ||
| 31 | -import java.time.LocalDate; | ||
| 32 | import java.time.LocalDateTime; | 33 | import java.time.LocalDateTime; |
| 33 | import java.util.*; | 34 | import java.util.*; |
| 34 | import java.util.stream.Collectors; | 35 | import java.util.stream.Collectors; |
| 35 | 36 | ||
| 36 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 37 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 37 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | 38 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 38 | 39 | ||
| 39 | @Tag(name = "管理后台 - MES 排班日历") | 40 | @Tag(name = "管理后台 - MES 排班日历") |
| 40 | @RestController | 41 | @RestController |
| @@ -64,9 +65,8 @@ public class MesCalCalendarController { | @@ -64,9 +65,8 @@ public class MesCalCalendarController { | ||
| 64 | if (CollUtil.isEmpty(teamShifts)) { | 65 | if (CollUtil.isEmpty(teamShifts)) { |
| 65 | return success(Collections.emptyList()); | 66 | return success(Collections.emptyList()); |
| 66 | } | 67 | } |
| 67 | - // 1.2 查询假期列表,构建假期日期集合 | ||
| 68 | - // TODO @AI:是不是按照指定日期查询下,避免加载所有! | ||
| 69 | - Set<String> holidaySet = buildHolidaySet(); | 68 | + // 1.2 按日期范围查询假期,构建节假日日期集合 |
| 69 | + Set<String> holidaySet = buildHolidaySet(reqVO.getStartDay(), reqVO.getEndDay()); | ||
| 70 | // 1.3 批量查询关联数据:班组、班次、排班计划 | 70 | // 1.3 批量查询关联数据:班组、班次、排班计划 |
| 71 | Map<Long, MesCalTeamDO> teamMap = teamService.getTeamMap( | 71 | Map<Long, MesCalTeamDO> teamMap = teamService.getTeamMap( |
| 72 | convertSet(teamShifts, MesCalTeamShiftDO::getTeamId)); | 72 | convertSet(teamShifts, MesCalTeamShiftDO::getTeamId)); |
| @@ -75,24 +75,21 @@ public class MesCalCalendarController { | @@ -75,24 +75,21 @@ public class MesCalCalendarController { | ||
| 75 | Map<Long, MesCalPlanDO> planMap = planService.getPlanMap( | 75 | Map<Long, MesCalPlanDO> planMap = planService.getPlanMap( |
| 76 | convertSet(teamShifts, MesCalTeamShiftDO::getPlanId)); | 76 | convertSet(teamShifts, MesCalTeamShiftDO::getPlanId)); |
| 77 | 77 | ||
| 78 | - // 2. 按 day 分组聚合,过滤假期 | ||
| 79 | - // TODO @AI:使用 MapUtils 里的方法; | ||
| 80 | - Map<String, List<MesCalTeamShiftDO>> dayGroupMap = teamShifts.stream() | ||
| 81 | - .collect(Collectors.groupingBy( | ||
| 82 | - ts -> ts.getDay().toLocalDate().format(DatePattern.NORM_DATE_FORMATTER), | ||
| 83 | - LinkedHashMap::new, | ||
| 84 | - Collectors.toList() | ||
| 85 | - )); | 78 | + // 2. 按 day 分组聚合 |
| 79 | + Map<String, List<MesCalTeamShiftDO>> dayGroupMap = convertMultiMap(teamShifts, | ||
| 80 | + teamShift -> LocalDateTimeUtil.format(teamShift.getDay(), DatePattern.NORM_DATE_PATTERN)); | ||
| 81 | + | ||
| 82 | + // 3. 遍历分组,过滤假期,构建日历响应 | ||
| 86 | List<MesCalCalendarRespVO> result = new ArrayList<>(); | 83 | List<MesCalCalendarRespVO> result = new ArrayList<>(); |
| 87 | for (Map.Entry<String, List<MesCalTeamShiftDO>> entry : dayGroupMap.entrySet()) { | 84 | for (Map.Entry<String, List<MesCalTeamShiftDO>> entry : dayGroupMap.entrySet()) { |
| 88 | String dayStr = entry.getKey(); | 85 | String dayStr = entry.getKey(); |
| 89 | - // 4.1 过滤假期 | 86 | + // 3.1 过滤节假日 |
| 90 | if (holidaySet.contains(dayStr)) { | 87 | if (holidaySet.contains(dayStr)) { |
| 91 | continue; | 88 | continue; |
| 92 | } | 89 | } |
| 93 | List<MesCalTeamShiftDO> dayShifts = entry.getValue(); | 90 | List<MesCalTeamShiftDO> dayShifts = entry.getValue(); |
| 94 | - dayShifts.sort(Comparator.comparing(ts -> ts.getSort() != null ? ts.getSort() : 0)); // 按 sort 升序排列 | ||
| 95 | - // 4.2 获取轮班方式(取第一条记录关联的排班计划) | 91 | + dayShifts.sort(Comparator.comparing(ts -> ts.getSort() != null ? ts.getSort() : 0)); |
| 92 | + // 3.2 获取轮班方式(取第一条记录关联的排班计划) | ||
| 96 | Integer shiftType = null; | 93 | Integer shiftType = null; |
| 97 | MesCalTeamShiftDO first = dayShifts.get(0); | 94 | MesCalTeamShiftDO first = dayShifts.get(0); |
| 98 | if (first.getPlanId() != null) { | 95 | if (first.getPlanId() != null) { |
| @@ -101,19 +98,17 @@ public class MesCalCalendarController { | @@ -101,19 +98,17 @@ public class MesCalCalendarController { | ||
| 101 | shiftType = plan.getShiftType(); | 98 | shiftType = plan.getShiftType(); |
| 102 | } | 99 | } |
| 103 | } | 100 | } |
| 104 | - // 4.3 构建班组排班项列表 | ||
| 105 | - // TODO @AI:convertList? | ||
| 106 | - List<MesCalCalendarRespVO.TeamShiftItem> items = dayShifts.stream() | ||
| 107 | - .map(ts -> buildTeamShiftItem(ts, teamMap, shiftMap)) | ||
| 108 | - .collect(Collectors.toList()); | ||
| 109 | - | ||
| 110 | - // 4.4 构建日历项,添加到结果列表 | ||
| 111 | - // TODO @AI:先构建出一个对象,在 add 到 result 里; | ||
| 112 | - result.add(MesCalCalendarRespVO.builder() | ||
| 113 | - .day(LocalDate.parse(dayStr, DatePattern.NORM_DATE_FORMATTER).atStartOfDay()) | 101 | + // 3.3 构建班组排班项列表 |
| 102 | + List<MesCalCalendarRespVO.TeamShiftItem> items = convertList(dayShifts, | ||
| 103 | + teamShift -> buildTeamShiftItem(teamShift, teamMap, shiftMap)); | ||
| 104 | + | ||
| 105 | + // 3.4 构建日历项,添加到结果列表 | ||
| 106 | + MesCalCalendarRespVO calendarVO = MesCalCalendarRespVO.builder() | ||
| 107 | + .day(LocalDateTimeUtil.parseDate(dayStr, DatePattern.NORM_DATE_FORMATTER).atStartOfDay()) | ||
| 114 | .shiftType(shiftType) | 108 | .shiftType(shiftType) |
| 115 | .teamShifts(items) | 109 | .teamShifts(items) |
| 116 | - .build()); | 110 | + .build(); |
| 111 | + result.add(calendarVO); | ||
| 117 | } | 112 | } |
| 118 | return success(result); | 113 | return success(result); |
| 119 | } | 114 | } |
| @@ -208,20 +203,13 @@ public class MesCalCalendarController { | @@ -208,20 +203,13 @@ public class MesCalCalendarController { | ||
| 208 | } | 203 | } |
| 209 | 204 | ||
| 210 | /** | 205 | /** |
| 211 | - * 构建假期日期集合(yyyy-MM-dd 格式) | 206 | + * 按日期范围查询假期,构建节假日日期集合(yyyy-MM-dd 格式) |
| 212 | */ | 207 | */ |
| 213 | - private Set<String> buildHolidaySet() { | ||
| 214 | - List<MesCalHolidayDO> holidays = holidayService.getHolidayList(); | ||
| 215 | - Set<String> holidaySet = new HashSet<>(); | ||
| 216 | - for (MesCalHolidayDO holiday : holidays) { | ||
| 217 | - // type=2 表示节假日 | ||
| 218 | - // todo @AI:需要搞个枚举类;另外 holiday 那的字段,也要处理下; | ||
| 219 | - if (holiday.getType() != null && holiday.getType() == 2) { | ||
| 220 | - LocalDate day = holiday.getDay().toLocalDate(); | ||
| 221 | - holidaySet.add(day.format(DatePattern.NORM_DATE_FORMATTER)); | ||
| 222 | - } | ||
| 223 | - } | ||
| 224 | - return holidaySet; | 208 | + private Set<String> buildHolidaySet(LocalDateTime startDay, LocalDateTime endDay) { |
| 209 | + List<MesCalHolidayDO> holidays = holidayService.getHolidayList(startDay, endDay); | ||
| 210 | + return convertSet(holidays, | ||
| 211 | + holiday -> LocalDateTimeUtil.format(holiday.getDay(), DatePattern.NORM_DATE_PATTERN), | ||
| 212 | + holiday -> MesCalHolidayTypeEnum.HOLIDAY.getType().equals(holiday.getType())); | ||
| 225 | } | 213 | } |
| 226 | 214 | ||
| 227 | } | 215 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/holiday/MesCalHolidayMapper.java
| @@ -25,4 +25,10 @@ public interface MesCalHolidayMapper extends BaseMapperX<MesCalHolidayDO> { | @@ -25,4 +25,10 @@ public interface MesCalHolidayMapper extends BaseMapperX<MesCalHolidayDO> { | ||
| 25 | .orderByAsc(MesCalHolidayDO::getDay)); | 25 | .orderByAsc(MesCalHolidayDO::getDay)); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | + default List<MesCalHolidayDO> selectListByDayRange(LocalDateTime startDay, LocalDateTime endDay) { | ||
| 29 | + return selectList(new LambdaQueryWrapperX<MesCalHolidayDO>() | ||
| 30 | + .between(MesCalHolidayDO::getDay, startDay, endDay) | ||
| 31 | + .orderByAsc(MesCalHolidayDO::getDay)); | ||
| 32 | + } | ||
| 33 | + | ||
| 28 | } | 34 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalHolidayTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.enums.cal; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.core.ArrayValuable; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Getter; | ||
| 6 | + | ||
| 7 | +import java.util.Arrays; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * MES 假期类型枚举 | ||
| 11 | + * | ||
| 12 | + * 对应字典 mes_cal_holiday_type | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +@Getter | ||
| 17 | +@AllArgsConstructor | ||
| 18 | +public enum MesCalHolidayTypeEnum implements ArrayValuable<Integer> { | ||
| 19 | + | ||
| 20 | + WORKDAY(1, "工作日"), | ||
| 21 | + HOLIDAY(2, "节假日"); | ||
| 22 | + | ||
| 23 | + public static final Integer[] ARRAYS = Arrays.stream(values()) | ||
| 24 | + .map(MesCalHolidayTypeEnum::getType).toArray(Integer[]::new); | ||
| 25 | + | ||
| 26 | + private final Integer type; | ||
| 27 | + private final String name; | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public Integer[] array() { | ||
| 31 | + return ARRAYS; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/holiday/MesCalHolidayService.java
| @@ -30,6 +30,15 @@ public interface MesCalHolidayService { | @@ -30,6 +30,15 @@ public interface MesCalHolidayService { | ||
| 30 | List<MesCalHolidayDO> getHolidayList(); | 30 | List<MesCalHolidayDO> getHolidayList(); |
| 31 | 31 | ||
| 32 | /** | 32 | /** |
| 33 | + * 根据日期范围获得假期设置列表 | ||
| 34 | + * | ||
| 35 | + * @param startDay 开始日期 | ||
| 36 | + * @param endDay 结束日期 | ||
| 37 | + * @return 假期设置列表 | ||
| 38 | + */ | ||
| 39 | + List<MesCalHolidayDO> getHolidayList(LocalDateTime startDay, LocalDateTime endDay); | ||
| 40 | + | ||
| 41 | + /** | ||
| 33 | * 根据日期获得假期设置 | 42 | * 根据日期获得假期设置 |
| 34 | * | 43 | * |
| 35 | * @param day 日期 | 44 | * @param day 日期 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/holiday/MesCalHolidayServiceImpl.java
| @@ -46,6 +46,11 @@ public class MesCalHolidayServiceImpl implements MesCalHolidayService { | @@ -46,6 +46,11 @@ public class MesCalHolidayServiceImpl implements MesCalHolidayService { | ||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | @Override | 48 | @Override |
| 49 | + public List<MesCalHolidayDO> getHolidayList(LocalDateTime startDay, LocalDateTime endDay) { | ||
| 50 | + return holidayMapper.selectListByDayRange(startDay, endDay); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 49 | public MesCalHolidayDO getHolidayByDay(LocalDateTime day) { | 54 | public MesCalHolidayDO getHolidayByDay(LocalDateTime day) { |
| 50 | return holidayMapper.selectByDay(day); | 55 | return holidayMapper.selectByDay(day); |
| 51 | } | 56 | } |