diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalShiftController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalPlanShiftController.java index f17660e..4e0c905 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalShiftController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalPlanShiftController.java @@ -6,11 +6,11 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalShiftPageReqVO; -import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalShiftRespVO; -import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalShiftSaveReqVO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalShiftDO; -import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalShiftService; +import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalPlanShiftPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalPlanShiftRespVO; +import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalPlanShiftSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalPlanShiftDO; +import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanShiftService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -27,77 +27,77 @@ import java.util.List; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -// TODO @AI:它是不是改成 MesCalPlanShiftController 更好?毕竟它是排班计划的班次,而不是单纯的班次 @Tag(name = "管理后台 - MES 计划班次") @RestController -@RequestMapping("/mes/cal/shift") +@RequestMapping("/mes/cal/plan-shift") @Validated -public class MesCalShiftController { +public class MesCalPlanShiftController { @Resource - private MesCalShiftService shiftService; + private MesCalPlanShiftService planShiftService; @PostMapping("/create") @Operation(summary = "创建计划班次") - @PreAuthorize("@ss.hasPermission('mes:cal-shift:create')") - public CommonResult createShift(@Valid @RequestBody MesCalShiftSaveReqVO createReqVO) { - return success(shiftService.createShift(createReqVO)); + @PreAuthorize("@ss.hasPermission('mes:cal-plan:update')") + public CommonResult createPlanShift(@Valid @RequestBody MesCalPlanShiftSaveReqVO createReqVO) { + return success(planShiftService.createPlanShift(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新计划班次") - @PreAuthorize("@ss.hasPermission('mes:cal-shift:update')") - public CommonResult updateShift(@Valid @RequestBody MesCalShiftSaveReqVO updateReqVO) { - shiftService.updateShift(updateReqVO); + @PreAuthorize("@ss.hasPermission('mes:cal-plan:update')") + public CommonResult updatePlanShift(@Valid @RequestBody MesCalPlanShiftSaveReqVO updateReqVO) { + planShiftService.updatePlanShift(updateReqVO); return success(true); } @DeleteMapping("/delete") @Operation(summary = "删除计划班次") @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('mes:cal-shift:delete')") - public CommonResult deleteShift(@RequestParam("id") Long id) { - shiftService.deleteShift(id); + @PreAuthorize("@ss.hasPermission('mes:cal-plan:update')") + public CommonResult deletePlanShift(@RequestParam("id") Long id) { + planShiftService.deletePlanShift(id); return success(true); } @GetMapping("/get") @Operation(summary = "获得计划班次") @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('mes:cal-shift:query')") - public CommonResult getShift(@RequestParam("id") Long id) { - MesCalShiftDO shift = shiftService.getShift(id); - return success(BeanUtils.toBean(shift, MesCalShiftRespVO.class)); + @PreAuthorize("@ss.hasPermission('mes:cal-plan:query')") + public CommonResult getPlanShift(@RequestParam("id") Long id) { + MesCalPlanShiftDO planShift = planShiftService.getPlanShift(id); + return success(BeanUtils.toBean(planShift, MesCalPlanShiftRespVO.class)); } @GetMapping("/page") @Operation(summary = "获得计划班次分页") - @PreAuthorize("@ss.hasPermission('mes:cal-shift:query')") - public CommonResult> getShiftPage(@Valid MesCalShiftPageReqVO pageReqVO) { - PageResult pageResult = shiftService.getShiftPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, MesCalShiftRespVO.class)); + @PreAuthorize("@ss.hasPermission('mes:cal-plan:query')") + public CommonResult> getPlanShiftPage(@Valid MesCalPlanShiftPageReqVO pageReqVO) { + PageResult pageResult = planShiftService.getPlanShiftPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, MesCalPlanShiftRespVO.class)); } @GetMapping("/list-by-plan") @Operation(summary = "获得指定排班计划的班次列表") @Parameter(name = "planId", description = "排班计划编号", required = true) - @PreAuthorize("@ss.hasPermission('mes:cal-shift:query')") - public CommonResult> getShiftListByPlan(@RequestParam("planId") Long planId) { - List list = shiftService.getShiftListByPlanId(planId); - return success(BeanUtils.toBean(list, MesCalShiftRespVO.class)); + @PreAuthorize("@ss.hasPermission('mes:cal-plan:query')") + public CommonResult> getPlanShiftListByPlan(@RequestParam("planId") Long planId) { + List list = planShiftService.getPlanShiftListByPlanId(planId); + return success(BeanUtils.toBean(list, MesCalPlanShiftRespVO.class)); } +// TODO @AI:是不是不要导出 @GetMapping("/export-excel") @Operation(summary = "导出计划班次 Excel") - @PreAuthorize("@ss.hasPermission('mes:cal-shift:export')") + @PreAuthorize("@ss.hasPermission('mes:cal-plan:export')") @ApiAccessLog(operateType = EXPORT) - public void exportShiftExcel(@Valid MesCalShiftPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { + public void exportPlanShiftExcel(@Valid MesCalPlanShiftPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = shiftService.getShiftPage(pageReqVO).getList(); + List list = planShiftService.getPlanShiftPage(pageReqVO).getList(); // 导出 Excel - ExcelUtils.write(response, "计划班次.xls", "数据", MesCalShiftRespVO.class, - BeanUtils.toBean(list, MesCalShiftRespVO.class)); + ExcelUtils.write(response, "计划班次.xls", "数据", MesCalPlanShiftRespVO.class, + BeanUtils.toBean(list, MesCalPlanShiftRespVO.class)); } } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalShiftPageReqVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalPlanShiftPageReqVO.java index d37a934..525e168 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalShiftPageReqVO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalPlanShiftPageReqVO.java @@ -10,7 +10,7 @@ import lombok.ToString; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MesCalShiftPageReqVO extends PageParam { +public class MesCalPlanShiftPageReqVO extends PageParam { @Schema(description = "排班计划编号", example = "1") private Long planId; diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalShiftRespVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalPlanShiftRespVO.java index d8abf28..5be873a 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalShiftRespVO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalPlanShiftRespVO.java @@ -7,10 +7,11 @@ import lombok.Data; import java.time.LocalDateTime; +// TODO @AI:是不是不要导出 @Schema(description = "管理后台 - MES 计划班次 Response VO") @Data @ExcelIgnoreUnannotated -public class MesCalShiftRespVO { +public class MesCalPlanShiftRespVO { @Schema(description = "班次编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @ExcelProperty("班次编号") diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalShiftSaveReqVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalPlanShiftSaveReqVO.java index 1ed9abb..fd60e99 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalShiftSaveReqVO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/vo/shift/MesCalPlanShiftSaveReqVO.java @@ -7,7 +7,7 @@ import lombok.Data; @Schema(description = "管理后台 - MES 计划班次新增/修改 Request VO") @Data -public class MesCalShiftSaveReqVO { +public class MesCalPlanShiftSaveReqVO { @Schema(description = "班次编号", example = "1024") private Long id; diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/MesCalPlanDO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/MesCalPlanDO.java index fb0c2f6..6e88aab 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/MesCalPlanDO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/MesCalPlanDO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.mes.dal.dataobject.cal; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.mes.enums.cal.MesCalCalendarTypeEnum; import cn.iocoder.yudao.module.mes.enums.cal.MesCalPlanStatusEnum; import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftMethodEnum; import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum; @@ -39,11 +40,10 @@ public class MesCalPlanDO extends BaseDO { * 计划名称 */ private String name; - // TODO @AI:增加一个枚举值(类),好一点; /** * 班组类型 * - * 枚举 mes_cal_calendar_type(1=分组轮班, 2=固定班组) + * 枚举 {@link MesCalCalendarTypeEnum} */ private Integer calendarType; /** diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/MesCalShiftDO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/MesCalPlanShiftDO.java index dc028df..2165f9c 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/MesCalShiftDO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/MesCalPlanShiftDO.java @@ -11,15 +11,15 @@ import lombok.*; * * @author 芋道源码 */ -@TableName("mes_cal_shift") -@KeySequence("mes_cal_shift_seq") +@TableName("mes_cal_plan_shift") +@KeySequence("mes_cal_plan_shift_seq") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @Builder @NoArgsConstructor @AllArgsConstructor -public class MesCalShiftDO extends BaseDO { +public class MesCalPlanShiftDO extends BaseDO { /** * 班次编号 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/plan/MesCalShiftMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/plan/MesCalPlanShiftMapper.java index 41c0f84..ce87857 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/plan/MesCalShiftMapper.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/plan/MesCalPlanShiftMapper.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.mes.dal.mysql.cal.plan; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalShiftPageReqVO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalShiftDO; +import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalPlanShiftPageReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalPlanShiftDO; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -15,28 +15,28 @@ import java.util.List; * @author 芋道源码 */ @Mapper -public interface MesCalShiftMapper extends BaseMapperX { +public interface MesCalPlanShiftMapper extends BaseMapperX { - default PageResult selectPage(MesCalShiftPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(MesCalShiftDO::getPlanId, reqVO.getPlanId()) - .likeIfPresent(MesCalShiftDO::getName, reqVO.getName()) - .orderByAsc(MesCalShiftDO::getSort)); + default PageResult selectPage(MesCalPlanShiftPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(MesCalPlanShiftDO::getPlanId, reqVO.getPlanId()) + .likeIfPresent(MesCalPlanShiftDO::getName, reqVO.getName()) + .orderByAsc(MesCalPlanShiftDO::getSort)); } - default List selectListByPlanId(Long planId) { - return selectList(new LambdaQueryWrapperX() - .eq(MesCalShiftDO::getPlanId, planId) - .orderByAsc(MesCalShiftDO::getSort)); + default List selectListByPlanId(Long planId) { + return selectList(new LambdaQueryWrapperX() + .eq(MesCalPlanShiftDO::getPlanId, planId) + .orderByAsc(MesCalPlanShiftDO::getSort)); } default Long selectCountByPlanId(Long planId) { - return selectCount(MesCalShiftDO::getPlanId, planId); + return selectCount(MesCalPlanShiftDO::getPlanId, planId); } default void deleteByPlanId(Long planId) { - delete(new LambdaQueryWrapperX() - .eq(MesCalShiftDO::getPlanId, planId)); + delete(new LambdaQueryWrapperX() + .eq(MesCalPlanShiftDO::getPlanId, planId)); } } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/DictTypeConstants.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/DictTypeConstants.java index 64de731..456c08f 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/DictTypeConstants.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/DictTypeConstants.java @@ -19,5 +19,8 @@ public interface DictTypeConstants { String MES_DV_MACHINERY_STATUS = "mes_dv_machinery_status"; // MES 设备状态 String MES_INDEX_TYPE = "mes_index_type"; // MES 检测项类型 String MES_DEFECT_LEVEL = "mes_defect_level"; // MES 缺陷等级 + String MES_PRO_WORKORDER_STATUS = "mes_pro_workorder_status"; // MES 生产工单状态 + String MES_PRO_WORKORDER_SOURCE_TYPE = "mes_pro_workorder_source_type"; // MES 工单来源类型 + String MES_PRO_WORKORDER_TYPE = "mes_pro_workorder_type"; // MES 工单类型 } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index 274ec06..ae99e75 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -81,11 +81,9 @@ public interface ErrorCodeConstants { ErrorCode MD_PRODUCT_SIP_NOT_EXISTS = new ErrorCode(1_040_109_000, "产品SIP不存在"); ErrorCode MD_PRODUCT_SIP_SORT_DUPLICATE = new ErrorCode(1_040_109_001, "该展示序号已存在"); - // ========== MES 日历排班-班次(1-040-200-000) ========== - ErrorCode CAL_SHIFT_NOT_EXISTS = new ErrorCode(1_040_200_000, "班次不存在"); - ErrorCode CAL_SHIFT_COUNT_EXCEED_SINGLE = new ErrorCode(1_040_200_001, "轮班方式为白班时只能有一个班次"); - ErrorCode CAL_SHIFT_COUNT_EXCEED_TWO = new ErrorCode(1_040_200_002, "轮班方式为两班倒时只能有两个班次"); - ErrorCode CAL_SHIFT_COUNT_EXCEED_THREE = new ErrorCode(1_040_200_003, "轮班方式为三班倒时只能有三个班次"); + // ========== MES 日历排班-计划班次(1-040-200-000) ========== + ErrorCode CAL_PLAN_SHIFT_NOT_EXISTS = new ErrorCode(1_040_200_000, "计划班次不存在"); + ErrorCode CAL_PLAN_SHIFT_COUNT_EXCEED = new ErrorCode(1_040_200_001, "班次数量已达到轮班方式的上限"); // ========== MES 日历排班-班组(1-040-201-000) ========== ErrorCode CAL_TEAM_NOT_EXISTS = new ErrorCode(1_040_201_000, "班组不存在"); @@ -140,6 +138,9 @@ public interface ErrorCodeConstants { // ========== MES 生产管理-生产工单(1-040-502-000) ========== ErrorCode PRO_WORKORDER_NOT_EXISTS = new ErrorCode(1_040_502_000, "生产工单不存在"); + ErrorCode PRO_WORKORDER_CODE_DUPLICATE = new ErrorCode(1_040_502_001, "生产工单编码已存在"); + ErrorCode PRO_WORKORDER_NOT_PREPARE = new ErrorCode(1_040_502_002, "只能删除草稿状态的工单"); + ErrorCode PRO_WORKORDER_BOM_NOT_EXISTS = new ErrorCode(1_040_502_100, "生产工单BOM不存在"); // ========== MES 生产管理-生产任务(1-040-503-000) ========== ErrorCode PRO_TASK_NOT_EXISTS = new ErrorCode(1_040_503_000, "生产任务不存在"); diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/CalConstants.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/CalConstants.java deleted file mode 100644 index 02cd03a..0000000 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/CalConstants.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.mes.enums.cal; - -// TODO @AI:参考别的类,生成枚举类 -/** - * MES 日历排班常量 - * - * @author 芋道源码 - */ -public interface CalConstants { - - /** 白班 */ - String SHIFT_NAME_DAY = "白班"; - /** 夜班 */ - String SHIFT_NAME_NIGHT = "夜班"; - /** 中班 */ - String SHIFT_NAME_MID = "中班"; - -} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalCalendarTypeEnum.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalCalendarTypeEnum.java new file mode 100644 index 0000000..e9f6867 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalCalendarTypeEnum.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.mes.enums.cal; + +import cn.iocoder.yudao.framework.common.core.ArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * MES 班组类型(日历类型)枚举 + * + * @author 芋道源码 + */ +@Getter +@AllArgsConstructor +public enum MesCalCalendarTypeEnum implements ArrayValuable { + + GROUP_ROTATION(1, "分组轮班"), + FIXED_TEAM(2, "固定班组"); + + public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesCalCalendarTypeEnum::getType).toArray(Integer[]::new); + + /** + * 类型值 + */ + private final Integer type; + /** + * 类型名 + */ + private final String name; + + @Override + public Integer[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalShiftTypeEnum.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalShiftTypeEnum.java index 9679cc3..f801e10 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalShiftTypeEnum.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalShiftTypeEnum.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.mes.enums.cal; +import cn.hutool.core.lang.Pair; import cn.iocoder.yudao.framework.common.core.ArrayValuable; import lombok.AllArgsConstructor; import lombok.Getter; import java.util.Arrays; +import java.util.List; /** * MES 轮班方式枚举 @@ -15,9 +17,18 @@ import java.util.Arrays; @AllArgsConstructor public enum MesCalShiftTypeEnum implements ArrayValuable { - SINGLE(1, "单白班"), - TWO(2, "两班倒"), - THREE(3, "三班倒"); + SINGLE(1, "单白班", List.of( + Pair.of("白班", new String[]{"08:00", "17:00"}) + )), + TWO(2, "两班倒", List.of( + Pair.of("白班", new String[]{"08:00", "20:00"}), + Pair.of("夜班", new String[]{"20:00", "08:00"}) + )), + THREE(3, "三班倒", List.of( + Pair.of("白班", new String[]{"08:00", "16:00"}), + Pair.of("中班", new String[]{"16:00", "00:00"}), + Pair.of("夜班", new String[]{"00:00", "08:00"}) + )); public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesCalShiftTypeEnum::getType).toArray(Integer[]::new); @@ -29,6 +40,39 @@ public enum MesCalShiftTypeEnum implements ArrayValuable { * 类型名 */ private final String name; + /** + * 班次配置列表 + * + * key: 班次名称(如 "白班", "夜班", "中班") + * value: [startTime, endTime](如 ["08:00", "17:00"]) + */ + private final List> shifts; + + /** + * 获取班次数量上限 + */ + public int getShiftCount() { + return shifts.size(); + } + + /** + * 获取所需的最少班组数量 + */ + public int getRequiredTeamCount() { + return shifts.size(); + } + + /** + * 根据类型值获取枚举 + */ + public static MesCalShiftTypeEnum valueOf(Integer type) { + for (MesCalShiftTypeEnum value : values()) { + if (value.getType().equals(type)) { + return value; + } + } + throw new IllegalArgumentException("不支持的轮班方式: " + type); + } @Override public Integer[] array() { 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 cd81180..5ce96b9 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 @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalPlanDO; import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalPlanMapper; import cn.iocoder.yudao.module.mes.enums.cal.MesCalPlanStatusEnum; import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum; +import cn.hutool.core.util.ObjUtil; import jakarta.annotation.Resource; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -30,7 +31,7 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { private MesCalPlanMapper planMapper; @Resource @Lazy - private MesCalShiftService shiftService; + private MesCalPlanShiftService planShiftService; @Resource @Lazy private MesCalPlanTeamService planTeamService; @@ -48,7 +49,7 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { // 3. 自动生成默认班次 if (plan.getShiftType() != null) { - shiftService.addDefaultShift(plan.getId(), plan.getShiftType()); + planShiftService.addDefaultPlanShift(plan.getId(), plan.getShiftType()); } return plan.getId(); } @@ -56,6 +57,7 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { @Override @Transactional(rollbackFor = Exception.class) public void updatePlan(MesCalPlanSaveReqVO updateReqVO) { + // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑) // 1.1 校验存在 MesCalPlanDO existPlan = validatePlanExists(updateReqVO.getId()); // 1.2 校验编码唯一 @@ -79,13 +81,13 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { // 1.1 校验存在 MesCalPlanDO plan = validatePlanExists(id); // 1.2 校验状态为草稿 - // TODO @AI:notEquals 更好一点; - if (!MesCalPlanStatusEnum.PREPARE.getStatus().equals(plan.getStatus())) { + // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑)【最好抽成一个方法,各个地方可以调用】 + if (ObjUtil.notEqual(MesCalPlanStatusEnum.PREPARE.getStatus(), plan.getStatus())) { throw exception(CAL_PLAN_NOT_PREPARE); } // 2.1 级联删除班次 + 班组关联 - shiftService.deleteShiftByPlanId(id); + planShiftService.deletePlanShiftByPlanId(id); planTeamService.deleteByPlanId(id); // 2.2 删除计划 planMapper.deleteById(id); @@ -124,13 +126,10 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { */ private void validateTeamCountForConfirm(Long planId, Integer shiftType) { Long teamCount = planTeamService.getPlanTeamCountByPlanId(planId); - // TODO @AI:startTime、endTime 可以放到枚举类里么?List;这样就可以判断数量; - if (MesCalShiftTypeEnum.TWO.getType().equals(shiftType) && teamCount < 2) { - throw exception(CAL_PLAN_TEAM_COUNT_NOT_MATCH); - } else if (MesCalShiftTypeEnum.THREE.getType().equals(shiftType) && teamCount < 3) { + MesCalShiftTypeEnum shiftTypeEnum = MesCalShiftTypeEnum.valueOf(shiftType); + if (teamCount < shiftTypeEnum.getRequiredTeamCount()) { throw exception(CAL_PLAN_TEAM_COUNT_NOT_MATCH); } - // TODO @AI:兜底下,其它,则抛出异常参数 IllegalArgumentException,提示不支持的轮班方式; } } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalShiftService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftService.java index 046220e..c014a48 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalShiftService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftService.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.mes.service.cal.plan; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalShiftPageReqVO; -import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalShiftSaveReqVO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalShiftDO; +import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalPlanShiftPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalPlanShiftSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalPlanShiftDO; import jakarta.validation.Valid; import java.util.List; @@ -13,7 +13,7 @@ import java.util.List; * * @author 芋道源码 */ -public interface MesCalShiftService { +public interface MesCalPlanShiftService { /** * 创建计划班次 @@ -21,21 +21,21 @@ public interface MesCalShiftService { * @param createReqVO 创建信息 * @return 编号 */ - Long createShift(@Valid MesCalShiftSaveReqVO createReqVO); + Long createPlanShift(@Valid MesCalPlanShiftSaveReqVO createReqVO); /** * 更新计划班次 * * @param updateReqVO 更新信息 */ - void updateShift(@Valid MesCalShiftSaveReqVO updateReqVO); + void updatePlanShift(@Valid MesCalPlanShiftSaveReqVO updateReqVO); /** * 删除计划班次 * * @param id 编号 */ - void deleteShift(Long id); + void deletePlanShift(Long id); /** * 获得计划班次 @@ -43,7 +43,7 @@ public interface MesCalShiftService { * @param id 编号 * @return 计划班次 */ - MesCalShiftDO getShift(Long id); + MesCalPlanShiftDO getPlanShift(Long id); /** * 获得计划班次分页 @@ -51,7 +51,7 @@ public interface MesCalShiftService { * @param pageReqVO 分页查询 * @return 计划班次分页 */ - PageResult getShiftPage(MesCalShiftPageReqVO pageReqVO); + PageResult getPlanShiftPage(MesCalPlanShiftPageReqVO pageReqVO); /** * 获得指定排班计划的班次列表 @@ -59,7 +59,7 @@ public interface MesCalShiftService { * @param planId 排班计划编号 * @return 班次列表 */ - List getShiftListByPlanId(Long planId); + List getPlanShiftListByPlanId(Long planId); /** * 获得指定排班计划的班次数量 @@ -67,7 +67,7 @@ public interface MesCalShiftService { * @param planId 排班计划编号 * @return 班次数量 */ - Long getShiftCountByPlanId(Long planId); + Long getPlanShiftCountByPlanId(Long planId); /** * 根据轮班方式添加默认班次 @@ -75,13 +75,13 @@ public interface MesCalShiftService { * @param planId 排班计划编号 * @param shiftType 轮班方式 */ - void addDefaultShift(Long planId, Integer shiftType); + void addDefaultPlanShift(Long planId, Integer shiftType); /** * 根据排班计划编号删除所有班次 * * @param planId 排班计划编号 */ - void deleteShiftByPlanId(Long planId); + void deletePlanShiftByPlanId(Long 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 new file mode 100644 index 0000000..a189026 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanShiftServiceImpl.java @@ -0,0 +1,130 @@ +package cn.iocoder.yudao.module.mes.service.cal.plan; + +import cn.hutool.core.lang.Pair; +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.shift.MesCalPlanShiftPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalPlanShiftSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalPlanDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalPlanShiftDO; +import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalPlanMapper; +import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalPlanShiftMapper; +import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; + +/** + * MES 计划班次 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class MesCalPlanShiftServiceImpl implements MesCalPlanShiftService { + + @Resource + private MesCalPlanShiftMapper planShiftMapper; + @Resource + private MesCalPlanMapper planMapper; + + @Override + public Long createPlanShift(MesCalPlanShiftSaveReqVO createReqVO) { + // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑) + // 校验班次数量限制 + validatePlanShiftCount(createReqVO.getPlanId()); + + // 插入 + MesCalPlanShiftDO planShift = BeanUtils.toBean(createReqVO, MesCalPlanShiftDO.class); + planShiftMapper.insert(planShift); + return planShift.getId(); + } + + @Override + public void updatePlanShift(MesCalPlanShiftSaveReqVO updateReqVO) { + // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑) + // 校验存在 + validatePlanShiftExists(updateReqVO.getId()); + // 更新 + MesCalPlanShiftDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanShiftDO.class); + planShiftMapper.updateById(updateObj); + } + + @Override + public void deletePlanShift(Long id) { + // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑) + // 校验存在 + validatePlanShiftExists(id); + // 删除 + planShiftMapper.deleteById(id); + } + + private void validatePlanShiftExists(Long id) { + if (planShiftMapper.selectById(id) == null) { + throw exception(CAL_PLAN_SHIFT_NOT_EXISTS); + } + } + + /** + * 校验班次数量是否超限 + *

+ * 通过 planId 查询已有班次数量,根据排班计划的轮班方式校验 + */ + private void validatePlanShiftCount(Long planId) { + MesCalPlanDO plan = planMapper.selectById(planId); + if (plan == null) { + return; + } + Long count = planShiftMapper.selectCountByPlanId(planId); + MesCalShiftTypeEnum shiftTypeEnum = MesCalShiftTypeEnum.valueOf(plan.getShiftType()); + if (count >= shiftTypeEnum.getShiftCount()) { + throw exception(CAL_PLAN_SHIFT_COUNT_EXCEED); + } + } + + @Override + public MesCalPlanShiftDO getPlanShift(Long id) { + return planShiftMapper.selectById(id); + } + + @Override + public PageResult getPlanShiftPage(MesCalPlanShiftPageReqVO pageReqVO) { + return planShiftMapper.selectPage(pageReqVO); + } + + @Override + public List getPlanShiftListByPlanId(Long planId) { + return planShiftMapper.selectListByPlanId(planId); + } + + @Override + public Long getPlanShiftCountByPlanId(Long planId) { + return planShiftMapper.selectCountByPlanId(planId); + } + + @Override + public void addDefaultPlanShift(Long planId, Integer shiftType) { + // 根据轮班方式,通过枚举配置生成默认班次 + MesCalShiftTypeEnum shiftTypeEnum = MesCalShiftTypeEnum.valueOf(shiftType); + List> shifts = shiftTypeEnum.getShifts(); + for (int i = 0; i < shifts.size(); i++) { + Pair shift = shifts.get(i); + MesCalPlanShiftDO planShiftDO = MesCalPlanShiftDO.builder() + .planId(planId).sort(i + 1).name(shift.getKey()) + .startTime(shift.getValue()[0]).endTime(shift.getValue()[1]) + .build(); + planShiftMapper.insert(planShiftDO); + } + } + + @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/plan/MesCalPlanTeamServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanTeamServiceImpl.java index 3a20842..e7f66f1 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanTeamServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanTeamServiceImpl.java @@ -27,6 +27,7 @@ public class MesCalPlanTeamServiceImpl implements MesCalPlanTeamService { @Override public Long createPlanTeam(MesCalPlanTeamSaveReqVO createReqVO) { + // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑) // 校验排班计划存在 validatePlanTeamDuplicate(createReqVO.getPlanId(), createReqVO.getTeamId()); @@ -38,6 +39,7 @@ public class MesCalPlanTeamServiceImpl implements MesCalPlanTeamService { @Override public void deletePlanTeam(Long id) { + // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑) // 校验存在 validatePlanTeamExists(id); // 删除 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalShiftServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalShiftServiceImpl.java deleted file mode 100644 index 1135282..0000000 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalShiftServiceImpl.java +++ /dev/null @@ -1,147 +0,0 @@ -package cn.iocoder.yudao.module.mes.service.cal.plan; - -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.shift.MesCalShiftPageReqVO; -import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.shift.MesCalShiftSaveReqVO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalPlanDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.cal.MesCalShiftDO; -import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalPlanMapper; -import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalShiftMapper; -import cn.iocoder.yudao.module.mes.enums.cal.CalConstants; -import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.List; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; - -/** - * MES 计划班次 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -public class MesCalShiftServiceImpl implements MesCalShiftService { - - @Resource - private MesCalShiftMapper shiftMapper; - @Resource - private MesCalPlanMapper planMapper; - - @Override - public Long createShift(MesCalShiftSaveReqVO createReqVO) { - // 校验班次数量限制 - validateShiftCount(createReqVO.getPlanId()); - - // 插入 - MesCalShiftDO shift = BeanUtils.toBean(createReqVO, MesCalShiftDO.class); - shiftMapper.insert(shift); - return shift.getId(); - } - - @Override - public void updateShift(MesCalShiftSaveReqVO updateReqVO) { - // 校验存在 - validateShiftExists(updateReqVO.getId()); - // 更新 - MesCalShiftDO updateObj = BeanUtils.toBean(updateReqVO, MesCalShiftDO.class); - shiftMapper.updateById(updateObj); - } - - @Override - public void deleteShift(Long id) { - // 校验存在 - validateShiftExists(id); - // 删除 - shiftMapper.deleteById(id); - } - - private void validateShiftExists(Long id) { - if (shiftMapper.selectById(id) == null) { - throw exception(CAL_SHIFT_NOT_EXISTS); - } - } - - /** - * 校验班次数量是否超限 - *

- * 通过 planId 查询已有班次数量,根据排班计划的轮班方式校验 - */ - private void validateShiftCount(Long planId) { - MesCalPlanDO plan = planMapper.selectById(planId); - if (plan == null) { - return; - } - Long count = shiftMapper.selectCountByPlanId(planId); - Integer shiftType = plan.getShiftType(); - // TODO @AI:startTime、endTime 可以放到枚举类里么?List;这样可以 count 来判断。更简洁; - if (MesCalShiftTypeEnum.SINGLE.getType().equals(shiftType) && count >= 1) { - throw exception(CAL_SHIFT_COUNT_EXCEED_SINGLE); - } else if (MesCalShiftTypeEnum.TWO.getType().equals(shiftType) && count >= 2) { - throw exception(CAL_SHIFT_COUNT_EXCEED_TWO); - } else if (MesCalShiftTypeEnum.THREE.getType().equals(shiftType) && count >= 3) { - throw exception(CAL_SHIFT_COUNT_EXCEED_THREE); - } - } - - @Override - public MesCalShiftDO getShift(Long id) { - return shiftMapper.selectById(id); - } - - @Override - public PageResult getShiftPage(MesCalShiftPageReqVO pageReqVO) { - return shiftMapper.selectPage(pageReqVO); - } - - @Override - public List getShiftListByPlanId(Long planId) { - return shiftMapper.selectListByPlanId(planId); - } - - @Override - public Long getShiftCountByPlanId(Long planId) { - return shiftMapper.selectCountByPlanId(planId); - } - - @Override - public void addDefaultShift(Long planId, Integer shiftType) { - // 根据轮班方式,添加默认班次 - // TODO @AI:startTime、endTime 可以放到枚举类里么?List;这样就可以 for 循环; - if (MesCalShiftTypeEnum.SINGLE.getType().equals(shiftType)) { - // 单白班:1 个班次 - insertShift(planId, 1, CalConstants.SHIFT_NAME_DAY, "08:00", "17:00"); - } else if (MesCalShiftTypeEnum.TWO.getType().equals(shiftType)) { - // 两班倒:2 个班次 - insertShift(planId, 1, CalConstants.SHIFT_NAME_DAY, "08:00", "20:00"); - insertShift(planId, 2, CalConstants.SHIFT_NAME_NIGHT, "20:00", "08:00"); - } else if (MesCalShiftTypeEnum.THREE.getType().equals(shiftType)) { - // 三班倒:3 个班次 - insertShift(planId, 1, CalConstants.SHIFT_NAME_DAY, "08:00", "16:00"); - insertShift(planId, 2, CalConstants.SHIFT_NAME_MID, "16:00", "00:00"); - insertShift(planId, 3, CalConstants.SHIFT_NAME_NIGHT, "00:00", "08:00"); - } - } - - private void insertShift(Long planId, Integer sort, String name, String startTime, String endTime) { - // TODO @AI:链式 set,想通放在一样; - MesCalShiftDO shift = new MesCalShiftDO(); - shift.setPlanId(planId); - shift.setSort(sort); - shift.setName(name); - shift.setStartTime(startTime); - shift.setEndTime(endTime); - shiftMapper.insert(shift); - } - - @Override - public void deleteShiftByPlanId(Long planId) { - shiftMapper.deleteByPlanId(planId); - } - -}