Commit 203c639326c4c8b18f9e2691a1a07149abdbbc5e
1 parent
588845ab
refactor(mes-tm): 工具管理模块代码优化
1. 新增独立枚举类 MesTmMaintenTypeEnum、MesTmToolStatusEnum(enums/tm 包) 2. DO Javadoc 从字典引用改为枚举引用 3. ServiceImpl 使用枚举常量替代魔法值 4. Controller 抽取 buildToolRespVOList() 私有方法,复用 page/export 拼接逻辑 5. ServiceImpl 校验方法使用 ObjUtil.notEqual() 替代 Objects.equals + null 判断
Showing
17 changed files
with
268 additions
and
46 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/tm/tool/MesTmToolController.java
| @@ -23,7 +23,11 @@ import org.springframework.security.access.prepost.PreAuthorize; | @@ -23,7 +23,11 @@ import org.springframework.security.access.prepost.PreAuthorize; | ||
| 23 | import org.springframework.validation.annotation.Validated; | 23 | import org.springframework.validation.annotation.Validated; |
| 24 | import org.springframework.web.bind.annotation.*; | 24 | import org.springframework.web.bind.annotation.*; |
| 25 | 25 | ||
| 26 | +import cn.hutool.core.collection.CollUtil; | ||
| 27 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 28 | + | ||
| 26 | import java.io.IOException; | 29 | import java.io.IOException; |
| 30 | +import java.util.Collections; | ||
| 27 | import java.util.List; | 31 | import java.util.List; |
| 28 | import java.util.Map; | 32 | import java.util.Map; |
| 29 | 33 | ||
| @@ -89,17 +93,7 @@ public class MesTmToolController { | @@ -89,17 +93,7 @@ public class MesTmToolController { | ||
| 89 | @PreAuthorize("@ss.hasPermission('mes:tm-tool:query')") | 93 | @PreAuthorize("@ss.hasPermission('mes:tm-tool:query')") |
| 90 | public CommonResult<PageResult<MesTmToolRespVO>> getToolPage(@Valid MesTmToolPageReqVO pageReqVO) { | 94 | public CommonResult<PageResult<MesTmToolRespVO>> getToolPage(@Valid MesTmToolPageReqVO pageReqVO) { |
| 91 | PageResult<MesTmToolDO> pageResult = toolService.getToolPage(pageReqVO); | 95 | PageResult<MesTmToolDO> pageResult = toolService.getToolPage(pageReqVO); |
| 92 | - PageResult<MesTmToolRespVO> voPageResult = BeanUtils.toBean(pageResult, MesTmToolRespVO.class); | ||
| 93 | - // 拼接工具类型名称 | ||
| 94 | - Map<Long, MesTmToolTypeDO> toolTypeMap = toolTypeService.getToolTypeMap( | ||
| 95 | - convertSet(voPageResult.getList(), MesTmToolRespVO::getToolTypeId)); | ||
| 96 | - voPageResult.getList().forEach(vo -> { | ||
| 97 | - MesTmToolTypeDO toolType = toolTypeMap.get(vo.getToolTypeId()); | ||
| 98 | - if (toolType != null) { | ||
| 99 | - vo.setToolTypeName(toolType.getName()); | ||
| 100 | - } | ||
| 101 | - }); | ||
| 102 | - return success(voPageResult); | 96 | + return success(new PageResult<>(buildToolRespVOList(pageResult.getList()), pageResult.getTotal())); |
| 103 | } | 97 | } |
| 104 | 98 | ||
| 105 | @GetMapping("/export-excel") | 99 | @GetMapping("/export-excel") |
| @@ -110,20 +104,26 @@ public class MesTmToolController { | @@ -110,20 +104,26 @@ public class MesTmToolController { | ||
| 110 | HttpServletResponse response) throws IOException { | 104 | HttpServletResponse response) throws IOException { |
| 111 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | 105 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 112 | List<MesTmToolDO> list = toolService.getToolPage(pageReqVO).getList(); | 106 | List<MesTmToolDO> list = toolService.getToolPage(pageReqVO).getList(); |
| 113 | - List<MesTmToolRespVO> voList = BeanUtils.toBean(list, MesTmToolRespVO.class); | ||
| 114 | - // 拼接工具类型名称 | ||
| 115 | - Map<Long, MesTmToolTypeDO> toolTypeMap = toolTypeService.getToolTypeMap( | ||
| 116 | - convertSet(voList, MesTmToolRespVO::getToolTypeId)); | ||
| 117 | - voList.forEach(vo -> { | ||
| 118 | - MesTmToolTypeDO toolType = toolTypeMap.get(vo.getToolTypeId()); | ||
| 119 | - if (toolType != null) { | ||
| 120 | - vo.setToolTypeName(toolType.getName()); | ||
| 121 | - } | ||
| 122 | - }); | 107 | + List<MesTmToolRespVO> voList = buildToolRespVOList(list); |
| 123 | // 导出 Excel | 108 | // 导出 Excel |
| 124 | ExcelUtils.write(response, "工具台账.xls", "数据", MesTmToolRespVO.class, voList); | 109 | ExcelUtils.write(response, "工具台账.xls", "数据", MesTmToolRespVO.class, voList); |
| 125 | } | 110 | } |
| 126 | 111 | ||
| 127 | - // TODO @AI:page、export 都有拼接;可以参考别的模块的出列方式, 抽 build 公用方法; | 112 | + // ==================== 拼接 VO ==================== |
| 113 | + | ||
| 114 | + @SuppressWarnings("CodeBlock2Expr") | ||
| 115 | + private List<MesTmToolRespVO> buildToolRespVOList(List<MesTmToolDO> list) { | ||
| 116 | + if (CollUtil.isEmpty(list)) { | ||
| 117 | + return Collections.emptyList(); | ||
| 118 | + } | ||
| 119 | + // 1. 批量获取工具类型信息 | ||
| 120 | + Map<Long, MesTmToolTypeDO> toolTypeMap = toolTypeService.getToolTypeMap( | ||
| 121 | + convertSet(list, MesTmToolDO::getToolTypeId)); | ||
| 122 | + // 2. 拼接 VO | ||
| 123 | + return BeanUtils.toBean(list, MesTmToolRespVO.class, vo -> { | ||
| 124 | + MapUtils.findAndThen(toolTypeMap, vo.getToolTypeId(), | ||
| 125 | + toolType -> vo.setToolTypeName(toolType.getName())); | ||
| 126 | + }); | ||
| 127 | + } | ||
| 128 | 128 | ||
| 129 | } | 129 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/tm/tool/MesTmToolDO.java
| 1 | package cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool; | 1 | package cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | +import cn.iocoder.yudao.module.mes.enums.tm.MesTmToolStatusEnum; | ||
| 5 | +import cn.iocoder.yudao.module.mes.enums.tm.MesTmMaintenTypeEnum; | ||
| 4 | import com.baomidou.mybatisplus.annotation.KeySequence; | 6 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 8 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -58,11 +60,10 @@ public class MesTmToolDO extends BaseDO { | @@ -58,11 +60,10 @@ public class MesTmToolDO extends BaseDO { | ||
| 58 | * 可用数量 | 60 | * 可用数量 |
| 59 | */ | 61 | */ |
| 60 | private Integer quantityAvailable; | 62 | private Integer quantityAvailable; |
| 61 | - // TODO @AI:枚举类 | ||
| 62 | /** | 63 | /** |
| 63 | * 保养维护类型 | 64 | * 保养维护类型 |
| 64 | * | 65 | * |
| 65 | - * 字典 {@link cn.iocoder.yudao.module.mes.enums.DictTypeConstants#MES_TM_MAINTEN_TYPE} | 66 | + * 枚举 {@link MesTmMaintenTypeEnum} |
| 66 | */ | 67 | */ |
| 67 | private Integer maintenType; | 68 | private Integer maintenType; |
| 68 | /** | 69 | /** |
| @@ -76,7 +77,7 @@ public class MesTmToolDO extends BaseDO { | @@ -76,7 +77,7 @@ public class MesTmToolDO extends BaseDO { | ||
| 76 | /** | 77 | /** |
| 77 | * 状态 | 78 | * 状态 |
| 78 | * | 79 | * |
| 79 | - * 字典 {@link cn.iocoder.yudao.module.mes.enums.DictTypeConstants#MES_TM_TOOL_STATUS} | 80 | + * 枚举 {@link MesTmToolStatusEnum} |
| 80 | */ | 81 | */ |
| 81 | private Integer status; | 82 | private Integer status; |
| 82 | /** | 83 | /** |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/tm/tool/MesTmToolTypeDO.java
| 1 | package cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool; | 1 | package cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | +import cn.iocoder.yudao.module.mes.enums.tm.MesTmMaintenTypeEnum; | ||
| 4 | import com.baomidou.mybatisplus.annotation.KeySequence; | 5 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 6 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 7 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -38,11 +39,10 @@ public class MesTmToolTypeDO extends BaseDO { | @@ -38,11 +39,10 @@ public class MesTmToolTypeDO extends BaseDO { | ||
| 38 | * 是否编码管理 | 39 | * 是否编码管理 |
| 39 | */ | 40 | */ |
| 40 | private Boolean codeFlag; | 41 | private Boolean codeFlag; |
| 41 | - // TODO @AI:枚举类; | ||
| 42 | /** | 42 | /** |
| 43 | * 保养维护类型 | 43 | * 保养维护类型 |
| 44 | * | 44 | * |
| 45 | - * 字典 {@link cn.iocoder.yudao.module.mes.enums.DictTypeConstants#MES_TM_MAINTEN_TYPE} | 45 | + * 枚举 {@link MesTmMaintenTypeEnum} |
| 46 | */ | 46 | */ |
| 47 | private Integer maintenType; | 47 | private Integer maintenType; |
| 48 | /** | 48 | /** |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/DictTypeConstants.java
| @@ -12,5 +12,9 @@ public interface DictTypeConstants { | @@ -12,5 +12,9 @@ public interface DictTypeConstants { | ||
| 12 | String MES_CAL_HOLIDAY_TYPE = "mes_cal_holiday_type"; // MES 假期类型 | 12 | String MES_CAL_HOLIDAY_TYPE = "mes_cal_holiday_type"; // MES 假期类型 |
| 13 | String MES_TM_TOOL_STATUS = "mes_tm_tool_status"; // MES 工具状态 | 13 | String MES_TM_TOOL_STATUS = "mes_tm_tool_status"; // MES 工具状态 |
| 14 | String MES_TM_MAINTEN_TYPE = "mes_tm_mainten_type"; // MES 保养维护类型 | 14 | String MES_TM_MAINTEN_TYPE = "mes_tm_mainten_type"; // MES 保养维护类型 |
| 15 | + String MES_CAL_SHIFT_TYPE = "mes_cal_shift_type"; // MES 轮班方式 | ||
| 16 | + String MES_CAL_SHIFT_METHOD = "mes_cal_shift_method"; // MES 倒班方式 | ||
| 17 | + String MES_CAL_CALENDAR_TYPE = "mes_cal_calendar_type"; // MES 班组类型 | ||
| 18 | + String MES_CAL_PLAN_STATUS = "mes_cal_plan_status"; // MES 排班计划状态 | ||
| 15 | 19 | ||
| 16 | } | 20 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
| @@ -83,12 +83,21 @@ public interface ErrorCodeConstants { | @@ -83,12 +83,21 @@ public interface ErrorCodeConstants { | ||
| 83 | 83 | ||
| 84 | // ========== MES 日历排班-班次(1-040-200-000) ========== | 84 | // ========== MES 日历排班-班次(1-040-200-000) ========== |
| 85 | ErrorCode CAL_SHIFT_NOT_EXISTS = new ErrorCode(1_040_200_000, "班次不存在"); | 85 | ErrorCode CAL_SHIFT_NOT_EXISTS = new ErrorCode(1_040_200_000, "班次不存在"); |
| 86 | + ErrorCode CAL_SHIFT_COUNT_EXCEED_SINGLE = new ErrorCode(1_040_200_001, "轮班方式为白班时只能有一个班次"); | ||
| 87 | + ErrorCode CAL_SHIFT_COUNT_EXCEED_TWO = new ErrorCode(1_040_200_002, "轮班方式为两班倒时只能有两个班次"); | ||
| 88 | + ErrorCode CAL_SHIFT_COUNT_EXCEED_THREE = new ErrorCode(1_040_200_003, "轮班方式为三班倒时只能有三个班次"); | ||
| 86 | 89 | ||
| 87 | // ========== MES 日历排班-班组(1-040-201-000) ========== | 90 | // ========== MES 日历排班-班组(1-040-201-000) ========== |
| 88 | ErrorCode CAL_TEAM_NOT_EXISTS = new ErrorCode(1_040_201_000, "班组不存在"); | 91 | ErrorCode CAL_TEAM_NOT_EXISTS = new ErrorCode(1_040_201_000, "班组不存在"); |
| 89 | 92 | ||
| 90 | // ========== MES 日历排班-排班计划(1-040-202-000) ========== | 93 | // ========== MES 日历排班-排班计划(1-040-202-000) ========== |
| 91 | ErrorCode CAL_PLAN_NOT_EXISTS = new ErrorCode(1_040_202_000, "排班计划不存在"); | 94 | ErrorCode CAL_PLAN_NOT_EXISTS = new ErrorCode(1_040_202_000, "排班计划不存在"); |
| 95 | + ErrorCode CAL_PLAN_CODE_DUPLICATE = new ErrorCode(1_040_202_001, "排班计划编码已存在"); | ||
| 96 | + ErrorCode CAL_PLAN_NOT_PREPARE = new ErrorCode(1_040_202_002, "只能删除草稿状态的排班计划"); | ||
| 97 | + ErrorCode CAL_PLAN_TEAM_COUNT_NOT_MATCH = new ErrorCode(1_040_202_003, "确认排班计划时,分配的班组数量与轮班方式不匹配"); | ||
| 98 | + // ========== MES 日历排班-计划班组关联(1-040-202-100) ========== | ||
| 99 | + ErrorCode CAL_PLAN_TEAM_NOT_EXISTS = new ErrorCode(1_040_202_100, "计划班组关联不存在"); | ||
| 100 | + ErrorCode CAL_PLAN_TEAM_DUPLICATE = new ErrorCode(1_040_202_101, "该班组已分配到此计划"); | ||
| 92 | 101 | ||
| 93 | // ========== MES 日历排班-假期设置(1-040-203-000) ========== | 102 | // ========== MES 日历排班-假期设置(1-040-203-000) ========== |
| 94 | ErrorCode CAL_HOLIDAY_NOT_EXISTS = new ErrorCode(1_040_203_000, "假期设置不存在"); | 103 | ErrorCode CAL_HOLIDAY_NOT_EXISTS = new ErrorCode(1_040_203_000, "假期设置不存在"); |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalPlanStatusEnum.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 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@Getter | ||
| 15 | +@AllArgsConstructor | ||
| 16 | +public enum MesCalPlanStatusEnum implements ArrayValuable<Integer> { | ||
| 17 | + | ||
| 18 | + PREPARE(0, "草稿"), | ||
| 19 | + CONFIRMED(1, "已确认"); | ||
| 20 | + | ||
| 21 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesCalPlanStatusEnum::getStatus).toArray(Integer[]::new); | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 状态值 | ||
| 25 | + */ | ||
| 26 | + private final Integer status; | ||
| 27 | + /** | ||
| 28 | + * 状态名 | ||
| 29 | + */ | ||
| 30 | + private final String name; | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public Integer[] array() { | ||
| 34 | + return ARRAYS; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalShiftMethodEnum.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 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@Getter | ||
| 15 | +@AllArgsConstructor | ||
| 16 | +public enum MesCalShiftMethodEnum implements ArrayValuable<Integer> { | ||
| 17 | + | ||
| 18 | + QUARTER(1, "按季度"), | ||
| 19 | + MONTH(2, "按月"), | ||
| 20 | + WEEK(3, "按周"), | ||
| 21 | + DAY(4, "按天"); | ||
| 22 | + | ||
| 23 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesCalShiftMethodEnum::getMethod).toArray(Integer[]::new); | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 方式值 | ||
| 27 | + */ | ||
| 28 | + private final Integer method; | ||
| 29 | + /** | ||
| 30 | + * 方式名 | ||
| 31 | + */ | ||
| 32 | + private final String name; | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public Integer[] array() { | ||
| 36 | + return ARRAYS; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/cal/MesCalShiftTypeEnum.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 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@Getter | ||
| 15 | +@AllArgsConstructor | ||
| 16 | +public enum MesCalShiftTypeEnum implements ArrayValuable<Integer> { | ||
| 17 | + | ||
| 18 | + SINGLE(1, "单白班"), | ||
| 19 | + TWO(2, "两班倒"), | ||
| 20 | + THREE(3, "三班倒"); | ||
| 21 | + | ||
| 22 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesCalShiftTypeEnum::getType).toArray(Integer[]::new); | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 类型值 | ||
| 26 | + */ | ||
| 27 | + private final Integer type; | ||
| 28 | + /** | ||
| 29 | + * 类型名 | ||
| 30 | + */ | ||
| 31 | + private final String name; | ||
| 32 | + | ||
| 33 | + @Override | ||
| 34 | + public Integer[] array() { | ||
| 35 | + return ARRAYS; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/tm/MesTmMaintenTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.enums.tm; | ||
| 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 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@Getter | ||
| 15 | +@AllArgsConstructor | ||
| 16 | +public enum MesTmMaintenTypeEnum implements ArrayValuable<Integer> { | ||
| 17 | + | ||
| 18 | + REGULAR(1, "定期维护"), | ||
| 19 | + USAGE(2, "按使用次数维护"); | ||
| 20 | + | ||
| 21 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesTmMaintenTypeEnum::getType).toArray(Integer[]::new); | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 类型值 | ||
| 25 | + */ | ||
| 26 | + private final Integer type; | ||
| 27 | + /** | ||
| 28 | + * 类型名 | ||
| 29 | + */ | ||
| 30 | + private final String name; | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public Integer[] array() { | ||
| 34 | + return ARRAYS; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/tm/MesTmToolStatusEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.enums.tm; | ||
| 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 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@Getter | ||
| 15 | +@AllArgsConstructor | ||
| 16 | +public enum MesTmToolStatusEnum implements ArrayValuable<Integer> { | ||
| 17 | + | ||
| 18 | + STORE(1, "在库"), | ||
| 19 | + ISSUE(2, "领用中"), | ||
| 20 | + REPAIR(3, "维修中"), | ||
| 21 | + SCRAP(4, "报废"); | ||
| 22 | + | ||
| 23 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesTmToolStatusEnum::getStatus).toArray(Integer[]::new); | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 状态值 | ||
| 27 | + */ | ||
| 28 | + private final Integer status; | ||
| 29 | + /** | ||
| 30 | + * 状态名 | ||
| 31 | + */ | ||
| 32 | + private final String name; | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public Integer[] array() { | ||
| 36 | + return ARRAYS; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/client/MesMdClientServiceImpl.java
| @@ -19,6 +19,7 @@ import org.springframework.validation.annotation.Validated; | @@ -19,6 +19,7 @@ import org.springframework.validation.annotation.Validated; | ||
| 19 | 19 | ||
| 20 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
| 21 | import java.util.Collection; | 21 | import java.util.Collection; |
| 22 | +import java.util.Collections; | ||
| 22 | import java.util.LinkedHashMap; | 23 | import java.util.LinkedHashMap; |
| 23 | import java.util.List; | 24 | import java.util.List; |
| 24 | import java.util.concurrent.atomic.AtomicInteger; | 25 | import java.util.concurrent.atomic.AtomicInteger; |
| @@ -134,6 +135,9 @@ public class MesMdClientServiceImpl implements MesMdClientService { | @@ -134,6 +135,9 @@ public class MesMdClientServiceImpl implements MesMdClientService { | ||
| 134 | 135 | ||
| 135 | @Override | 136 | @Override |
| 136 | public List<MesMdClientDO> getClientList(Collection<Long> ids) { | 137 | public List<MesMdClientDO> getClientList(Collection<Long> ids) { |
| 138 | + if (CollUtil.isEmpty(ids)) { | ||
| 139 | + return Collections.emptyList(); | ||
| 140 | + } | ||
| 137 | return clientMapper.selectByIds(ids); | 141 | return clientMapper.selectByIds(ids); |
| 138 | } | 142 | } |
| 139 | 143 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java
| 1 | package cn.iocoder.yudao.module.mes.service.md.item; | 1 | package cn.iocoder.yudao.module.mes.service.md.item; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeListReqVO; | 6 | import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeListReqVO; |
| @@ -152,6 +153,9 @@ public class MesMdItemTypeServiceImpl implements MesMdItemTypeService { | @@ -152,6 +153,9 @@ public class MesMdItemTypeServiceImpl implements MesMdItemTypeService { | ||
| 152 | 153 | ||
| 153 | @Override | 154 | @Override |
| 154 | public List<MesMdItemTypeDO> getItemTypeList(Collection<Long> ids) { | 155 | public List<MesMdItemTypeDO> getItemTypeList(Collection<Long> ids) { |
| 156 | + if (CollUtil.isEmpty(ids)) { | ||
| 157 | + return Collections.emptyList(); | ||
| 158 | + } | ||
| 155 | return itemTypeMapper.selectByIds(ids); | 159 | return itemTypeMapper.selectByIds(ids); |
| 156 | } | 160 | } |
| 157 | 161 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/unitmeasure/MesMdUnitMeasureServiceImpl.java
| 1 | package cn.iocoder.yudao.module.mes.service.md.unitmeasure; | 1 | package cn.iocoder.yudao.module.mes.service.md.unitmeasure; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.module.mes.controller.admin.md.unitmeasure.vo.MesMdUnitMeasurePageReqVO; | 6 | import cn.iocoder.yudao.module.mes.controller.admin.md.unitmeasure.vo.MesMdUnitMeasurePageReqVO; |
| @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; | @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; | ||
| 12 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 13 | 14 | ||
| 14 | import java.util.Collection; | 15 | import java.util.Collection; |
| 16 | +import java.util.Collections; | ||
| 15 | import java.util.List; | 17 | import java.util.List; |
| 16 | import java.util.Objects; | 18 | import java.util.Objects; |
| 17 | 19 | ||
| @@ -105,6 +107,9 @@ public class MesMdUnitMeasureServiceImpl implements MesMdUnitMeasureService { | @@ -105,6 +107,9 @@ public class MesMdUnitMeasureServiceImpl implements MesMdUnitMeasureService { | ||
| 105 | 107 | ||
| 106 | @Override | 108 | @Override |
| 107 | public List<MesMdUnitMeasureDO> getUnitMeasureList(Collection<Long> ids) { | 109 | public List<MesMdUnitMeasureDO> getUnitMeasureList(Collection<Long> ids) { |
| 110 | + if (CollUtil.isEmpty(ids)) { | ||
| 111 | + return Collections.emptyList(); | ||
| 112 | + } | ||
| 108 | return unitMeasureMapper.selectByIds(ids); | 113 | return unitMeasureMapper.selectByIds(ids); |
| 109 | } | 114 | } |
| 110 | 115 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/vendor/MesMdVendorServiceImpl.java
| @@ -19,6 +19,7 @@ import org.springframework.validation.annotation.Validated; | @@ -19,6 +19,7 @@ import org.springframework.validation.annotation.Validated; | ||
| 19 | 19 | ||
| 20 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
| 21 | import java.util.Collection; | 21 | import java.util.Collection; |
| 22 | +import java.util.Collections; | ||
| 22 | import java.util.LinkedHashMap; | 23 | import java.util.LinkedHashMap; |
| 23 | import java.util.List; | 24 | import java.util.List; |
| 24 | import java.util.concurrent.atomic.AtomicInteger; | 25 | import java.util.concurrent.atomic.AtomicInteger; |
| @@ -133,6 +134,9 @@ public class MesMdVendorServiceImpl implements MesMdVendorService { | @@ -133,6 +134,9 @@ public class MesMdVendorServiceImpl implements MesMdVendorService { | ||
| 133 | 134 | ||
| 134 | @Override | 135 | @Override |
| 135 | public List<MesMdVendorDO> getVendorList(Collection<Long> ids) { | 136 | public List<MesMdVendorDO> getVendorList(Collection<Long> ids) { |
| 137 | + if (CollUtil.isEmpty(ids)) { | ||
| 138 | + return Collections.emptyList(); | ||
| 139 | + } | ||
| 136 | return vendorMapper.selectByIds(ids); | 140 | return vendorMapper.selectByIds(ids); |
| 137 | } | 141 | } |
| 138 | 142 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/workstation/MesMdWorkshopServiceImpl.java
| 1 | package cn.iocoder.yudao.module.mes.service.md.workstation; | 1 | package cn.iocoder.yudao.module.mes.service.md.workstation; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| @@ -15,6 +16,7 @@ import org.springframework.stereotype.Service; | @@ -15,6 +16,7 @@ import org.springframework.stereotype.Service; | ||
| 15 | import org.springframework.validation.annotation.Validated; | 16 | import org.springframework.validation.annotation.Validated; |
| 16 | 17 | ||
| 17 | import java.util.Collection; | 18 | import java.util.Collection; |
| 19 | +import java.util.Collections; | ||
| 18 | import java.util.List; | 20 | import java.util.List; |
| 19 | 21 | ||
| 20 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -115,6 +117,9 @@ public class MesMdWorkshopServiceImpl implements MesMdWorkshopService { | @@ -115,6 +117,9 @@ public class MesMdWorkshopServiceImpl implements MesMdWorkshopService { | ||
| 115 | 117 | ||
| 116 | @Override | 118 | @Override |
| 117 | public List<MesMdWorkshopDO> getWorkshopList(Collection<Long> ids) { | 119 | public List<MesMdWorkshopDO> getWorkshopList(Collection<Long> ids) { |
| 120 | + if (CollUtil.isEmpty(ids)) { | ||
| 121 | + return Collections.emptyList(); | ||
| 122 | + } | ||
| 118 | return workshopMapper.selectByIds(ids); | 123 | return workshopMapper.selectByIds(ids); |
| 119 | } | 124 | } |
| 120 | 125 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/tm/tool/MesTmToolServiceImpl.java
| @@ -6,11 +6,14 @@ import cn.iocoder.yudao.module.mes.controller.admin.tm.tool.vo.MesTmToolPageReqV | @@ -6,11 +6,14 @@ import cn.iocoder.yudao.module.mes.controller.admin.tm.tool.vo.MesTmToolPageReqV | ||
| 6 | import cn.iocoder.yudao.module.mes.controller.admin.tm.tool.vo.MesTmToolSaveReqVO; | 6 | import cn.iocoder.yudao.module.mes.controller.admin.tm.tool.vo.MesTmToolSaveReqVO; |
| 7 | import cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool.MesTmToolDO; | 7 | import cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool.MesTmToolDO; |
| 8 | import cn.iocoder.yudao.module.mes.dal.mysql.tm.tool.MesTmToolMapper; | 8 | import cn.iocoder.yudao.module.mes.dal.mysql.tm.tool.MesTmToolMapper; |
| 9 | +import cn.iocoder.yudao.module.mes.enums.tm.MesTmMaintenTypeEnum; | ||
| 9 | import jakarta.annotation.Resource; | 10 | import jakarta.annotation.Resource; |
| 10 | import org.springframework.context.annotation.Lazy; | 11 | import org.springframework.context.annotation.Lazy; |
| 11 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 12 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 13 | 14 | ||
| 15 | +import cn.hutool.core.util.ObjUtil; | ||
| 16 | + | ||
| 14 | import java.util.Objects; | 17 | import java.util.Objects; |
| 15 | 18 | ||
| 16 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 19 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -55,10 +58,9 @@ public class MesTmToolServiceImpl implements MesTmToolService { | @@ -55,10 +58,9 @@ public class MesTmToolServiceImpl implements MesTmToolService { | ||
| 55 | validateToolCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); | 58 | validateToolCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); |
| 56 | 59 | ||
| 57 | // 更新 | 60 | // 更新 |
| 58 | - // TODO @AI:枚举类维护类型,避免使用魔法值 | ||
| 59 | - if (Objects.equals(updateReqVO.getMaintenType(), 1)) { // 定期维护 | 61 | + if (Objects.equals(updateReqVO.getMaintenType(), MesTmMaintenTypeEnum.REGULAR.getType())) { |
| 60 | updateReqVO.setNextMaintenPeriod(null); | 62 | updateReqVO.setNextMaintenPeriod(null); |
| 61 | - } else if (Objects.equals(updateReqVO.getMaintenType(), 2)) { // 按使用次数维护 | 63 | + } else if (Objects.equals(updateReqVO.getMaintenType(), MesTmMaintenTypeEnum.USAGE.getType())) { |
| 62 | updateReqVO.setNextMaintenDate(null); | 64 | updateReqVO.setNextMaintenDate(null); |
| 63 | } | 65 | } |
| 64 | MesTmToolDO updateObj = BeanUtils.toBean(updateReqVO, MesTmToolDO.class); | 66 | MesTmToolDO updateObj = BeanUtils.toBean(updateReqVO, MesTmToolDO.class); |
| @@ -87,11 +89,7 @@ public class MesTmToolServiceImpl implements MesTmToolService { | @@ -87,11 +89,7 @@ public class MesTmToolServiceImpl implements MesTmToolService { | ||
| 87 | if (tool == null) { | 89 | if (tool == null) { |
| 88 | return; | 90 | return; |
| 89 | } | 91 | } |
| 90 | - // TODO @AI:ObjUtil notEquals | ||
| 91 | - if (id == null) { | ||
| 92 | - throw exception(TM_TOOL_CODE_DUPLICATE); | ||
| 93 | - } | ||
| 94 | - if (!Objects.equals(tool.getId(), id)) { | 92 | + if (ObjUtil.notEqual(tool.getId(), id)) { |
| 95 | throw exception(TM_TOOL_CODE_DUPLICATE); | 93 | throw exception(TM_TOOL_CODE_DUPLICATE); |
| 96 | } | 94 | } |
| 97 | } | 95 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/tm/tool/MesTmToolTypeServiceImpl.java
| 1 | package cn.iocoder.yudao.module.mes.service.tm.tool; | 1 | package cn.iocoder.yudao.module.mes.service.tm.tool; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.module.mes.controller.admin.tm.tool.vo.type.MesTmToolTypePageReqVO; | 6 | import cn.iocoder.yudao.module.mes.controller.admin.tm.tool.vo.type.MesTmToolTypePageReqVO; |
| @@ -11,9 +12,11 @@ import jakarta.annotation.Resource; | @@ -11,9 +12,11 @@ import jakarta.annotation.Resource; | ||
| 11 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 12 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 13 | 14 | ||
| 15 | +import cn.hutool.core.util.ObjUtil; | ||
| 16 | + | ||
| 14 | import java.util.Collection; | 17 | import java.util.Collection; |
| 18 | +import java.util.Collections; | ||
| 15 | import java.util.List; | 19 | import java.util.List; |
| 16 | -import java.util.Objects; | ||
| 17 | 20 | ||
| 18 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 21 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 19 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; | 22 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| @@ -84,11 +87,7 @@ public class MesTmToolTypeServiceImpl implements MesTmToolTypeService { | @@ -84,11 +87,7 @@ public class MesTmToolTypeServiceImpl implements MesTmToolTypeService { | ||
| 84 | if (toolType == null) { | 87 | if (toolType == null) { |
| 85 | return; | 88 | return; |
| 86 | } | 89 | } |
| 87 | - // TODO @AI:ObjUtil notEquals | ||
| 88 | - if (id == null) { | ||
| 89 | - throw exception(TM_TOOL_TYPE_CODE_DUPLICATE); | ||
| 90 | - } | ||
| 91 | - if (!Objects.equals(toolType.getId(), id)) { | 90 | + if (ObjUtil.notEqual(toolType.getId(), id)) { |
| 92 | throw exception(TM_TOOL_TYPE_CODE_DUPLICATE); | 91 | throw exception(TM_TOOL_TYPE_CODE_DUPLICATE); |
| 93 | } | 92 | } |
| 94 | } | 93 | } |
| @@ -98,11 +97,7 @@ public class MesTmToolTypeServiceImpl implements MesTmToolTypeService { | @@ -98,11 +97,7 @@ public class MesTmToolTypeServiceImpl implements MesTmToolTypeService { | ||
| 98 | if (toolType == null) { | 97 | if (toolType == null) { |
| 99 | return; | 98 | return; |
| 100 | } | 99 | } |
| 101 | - // TODO @AI:ObjUtil notEquals | ||
| 102 | - if (id == null) { | ||
| 103 | - throw exception(TM_TOOL_TYPE_NAME_DUPLICATE); | ||
| 104 | - } | ||
| 105 | - if (!Objects.equals(toolType.getId(), id)) { | 100 | + if (ObjUtil.notEqual(toolType.getId(), id)) { |
| 106 | throw exception(TM_TOOL_TYPE_NAME_DUPLICATE); | 101 | throw exception(TM_TOOL_TYPE_NAME_DUPLICATE); |
| 107 | } | 102 | } |
| 108 | } | 103 | } |
| @@ -124,6 +119,9 @@ public class MesTmToolTypeServiceImpl implements MesTmToolTypeService { | @@ -124,6 +119,9 @@ public class MesTmToolTypeServiceImpl implements MesTmToolTypeService { | ||
| 124 | 119 | ||
| 125 | @Override | 120 | @Override |
| 126 | public List<MesTmToolTypeDO> getToolTypeList(Collection<Long> ids) { | 121 | public List<MesTmToolTypeDO> getToolTypeList(Collection<Long> ids) { |
| 122 | + if (CollUtil.isEmpty(ids)) { | ||
| 123 | + return Collections.emptyList(); | ||
| 124 | + } | ||
| 127 | return toolTypeMapper.selectByIds(ids); | 125 | return toolTypeMapper.selectByIds(ids); |
| 128 | } | 126 | } |
| 129 | 127 |