Commit a297b060098a8183971d1d8b77dc9d3e8eb4df77
1 parent
aab84802
feat(mes): 新增物料批次属性配置(md_item_batch_config)
1. 新增独立表 mes_md_item_batch_config,与 mes_md_item 保持 1:1 关系(UNIQUE KEY) 2. 新增 DO/Mapper/Service/Controller/VO,采用 upsert 模式(GET by itemId + POST save) 3. 复用物料权限 mes:md-item:query / mes:md-item:update,无需独立菜单 4. MesMdItemServiceImpl:级联删除批次配置 + 启用时校验至少一个 flag 为 true 5. 修复 simple-list 接口未返回 itemOrProduct 字段的 BUG 6. 代码规范:变量/方法名统一加 Item 前缀(itemBatchConfigService / getItemBatchConfigByItemId 等)
Showing
10 changed files
with
443 additions
and
1 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/MesMdItemBatchConfigController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.md.item; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | +import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.batchconfig.MesMdItemBatchConfigRespVO; | |
| 6 | +import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.batchconfig.MesMdItemBatchConfigSaveReqVO; | |
| 7 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemBatchConfigDO; | |
| 8 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemBatchConfigService; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | +import jakarta.annotation.Resource; | |
| 13 | +import jakarta.validation.Valid; | |
| 14 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | +import org.springframework.validation.annotation.Validated; | |
| 16 | +import org.springframework.web.bind.annotation.*; | |
| 17 | + | |
| 18 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 19 | + | |
| 20 | +@Tag(name = "管理后台 - MES 物料批次属性配置") | |
| 21 | +@RestController | |
| 22 | +@RequestMapping("/mes/md/item-batch-config") | |
| 23 | +@Validated | |
| 24 | +public class MesMdItemBatchConfigController { | |
| 25 | + | |
| 26 | + @Resource | |
| 27 | + private MesMdItemBatchConfigService itemBatchConfigService; | |
| 28 | + | |
| 29 | + @GetMapping("/get-by-item-id") | |
| 30 | + @Operation(summary = "根据物料编号获取批次属性配置") | |
| 31 | + @Parameter(name = "itemId", description = "物料编号", required = true, example = "69") | |
| 32 | + @PreAuthorize("@ss.hasPermission('mes:md-item:query')") | |
| 33 | + public CommonResult<MesMdItemBatchConfigRespVO> getItemBatchConfigByItemId( | |
| 34 | + @RequestParam("itemId") Long itemId) { | |
| 35 | + MesMdItemBatchConfigDO config = itemBatchConfigService.getItemBatchConfigByItemId(itemId); | |
| 36 | + return success(BeanUtils.toBean(config, MesMdItemBatchConfigRespVO.class)); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @PostMapping("/save") | |
| 40 | + @Operation(summary = "保存批次属性配置(新增或更新)") | |
| 41 | + @PreAuthorize("@ss.hasPermission('mes:md-item:update')") | |
| 42 | + public CommonResult<Long> saveItemBatchConfig(@Valid @RequestBody MesMdItemBatchConfigSaveReqVO saveReqVO) { | |
| 43 | + return success(itemBatchConfigService.saveItemBatchConfig(saveReqVO)); | |
| 44 | + } | |
| 45 | + | |
| 46 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/MesMdItemTypeController.java
| ... | ... | @@ -78,7 +78,8 @@ public class MesMdItemTypeController { |
| 78 | 78 | List<MesMdItemTypeDO> list = itemTypeService.getItemTypeList( |
| 79 | 79 | new MesMdItemTypeListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); |
| 80 | 80 | return success(convertList(list, itemType -> new MesMdItemTypeRespVO() |
| 81 | - .setId(itemType.getId()).setName(itemType.getName()).setParentId(itemType.getParentId()))); | |
| 81 | + .setId(itemType.getId()).setName(itemType.getName()).setParentId(itemType.getParentId()) | |
| 82 | + .setItemOrProduct(itemType.getItemOrProduct()))); | |
| 82 | 83 | } |
| 83 | 84 | |
| 84 | 85 | } | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/vo/batchconfig/MesMdItemBatchConfigRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.batchconfig; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - MES 物料批次属性配置 Response VO") | |
| 9 | +@Data | |
| 10 | +public class MesMdItemBatchConfigRespVO { | |
| 11 | + | |
| 12 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 13 | + private Long id; | |
| 14 | + | |
| 15 | + @Schema(description = "物料编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "69") | |
| 16 | + private Long itemId; | |
| 17 | + | |
| 18 | + @Schema(description = "批次属性-生产日期", example = "true") | |
| 19 | + private Boolean produceDateFlag; | |
| 20 | + | |
| 21 | + @Schema(description = "批次属性-有效期", example = "true") | |
| 22 | + private Boolean expireDateFlag; | |
| 23 | + | |
| 24 | + @Schema(description = "批次属性-入库日期", example = "false") | |
| 25 | + private Boolean receiptDateFlag; | |
| 26 | + | |
| 27 | + @Schema(description = "批次属性-供应商", example = "false") | |
| 28 | + private Boolean vendorFlag; | |
| 29 | + | |
| 30 | + @Schema(description = "批次属性-客户", example = "false") | |
| 31 | + private Boolean clientFlag; | |
| 32 | + | |
| 33 | + @Schema(description = "批次属性-销售订单编号", example = "false") | |
| 34 | + private Boolean salesOrderCodeFlag; | |
| 35 | + | |
| 36 | + @Schema(description = "批次属性-采购订单编号", example = "false") | |
| 37 | + private Boolean purchaseOrderCodeFlag; | |
| 38 | + | |
| 39 | + @Schema(description = "批次属性-生产工单", example = "false") | |
| 40 | + private Boolean workorderFlag; | |
| 41 | + | |
| 42 | + @Schema(description = "批次属性-生产任务", example = "false") | |
| 43 | + private Boolean taskFlag; | |
| 44 | + | |
| 45 | + @Schema(description = "批次属性-工位", example = "false") | |
| 46 | + private Boolean workstationFlag; | |
| 47 | + | |
| 48 | + @Schema(description = "批次属性-工具", example = "false") | |
| 49 | + private Boolean toolFlag; | |
| 50 | + | |
| 51 | + @Schema(description = "批次属性-模具", example = "false") | |
| 52 | + private Boolean moldFlag; | |
| 53 | + | |
| 54 | + @Schema(description = "批次属性-生产批号", example = "true") | |
| 55 | + private Boolean lotNumberFlag; | |
| 56 | + | |
| 57 | + @Schema(description = "批次属性-质量状态", example = "false") | |
| 58 | + private Boolean qualityStatusFlag; | |
| 59 | + | |
| 60 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 61 | + private LocalDateTime createTime; | |
| 62 | + | |
| 63 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/vo/batchconfig/MesMdItemBatchConfigSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.batchconfig; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotNull; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +@Schema(description = "管理后台 - MES 物料批次属性配置新增/修改 Request VO") | |
| 8 | +@Data | |
| 9 | +public class MesMdItemBatchConfigSaveReqVO { | |
| 10 | + | |
| 11 | + @Schema(description = "编号", example = "1024") | |
| 12 | + private Long id; | |
| 13 | + | |
| 14 | + @Schema(description = "物料编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "69") | |
| 15 | + @NotNull(message = "物料编号不能为空") | |
| 16 | + private Long itemId; | |
| 17 | + | |
| 18 | + @Schema(description = "批次属性-生产日期", example = "true") | |
| 19 | + private Boolean produceDateFlag; | |
| 20 | + | |
| 21 | + @Schema(description = "批次属性-有效期", example = "true") | |
| 22 | + private Boolean expireDateFlag; | |
| 23 | + | |
| 24 | + @Schema(description = "批次属性-入库日期", example = "false") | |
| 25 | + private Boolean receiptDateFlag; | |
| 26 | + | |
| 27 | + @Schema(description = "批次属性-供应商", example = "false") | |
| 28 | + private Boolean vendorFlag; | |
| 29 | + | |
| 30 | + @Schema(description = "批次属性-客户", example = "false") | |
| 31 | + private Boolean clientFlag; | |
| 32 | + | |
| 33 | + @Schema(description = "批次属性-销售订单编号", example = "false") | |
| 34 | + private Boolean salesOrderCodeFlag; | |
| 35 | + | |
| 36 | + @Schema(description = "批次属性-采购订单编号", example = "false") | |
| 37 | + private Boolean purchaseOrderCodeFlag; | |
| 38 | + | |
| 39 | + @Schema(description = "批次属性-生产工单", example = "false") | |
| 40 | + private Boolean workorderFlag; | |
| 41 | + | |
| 42 | + @Schema(description = "批次属性-生产任务", example = "false") | |
| 43 | + private Boolean taskFlag; | |
| 44 | + | |
| 45 | + @Schema(description = "批次属性-工位", example = "false") | |
| 46 | + private Boolean workstationFlag; | |
| 47 | + | |
| 48 | + @Schema(description = "批次属性-工具", example = "false") | |
| 49 | + private Boolean toolFlag; | |
| 50 | + | |
| 51 | + @Schema(description = "批次属性-模具", example = "false") | |
| 52 | + private Boolean moldFlag; | |
| 53 | + | |
| 54 | + @Schema(description = "批次属性-生产批号", example = "true") | |
| 55 | + private Boolean lotNumberFlag; | |
| 56 | + | |
| 57 | + @Schema(description = "批次属性-质量状态", example = "false") | |
| 58 | + private Boolean qualityStatusFlag; | |
| 59 | + | |
| 60 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/md/item/MesMdItemBatchConfigDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.dal.dataobject.md.item; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import lombok.*; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * MES 物料批次属性配置 DO | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@TableName("mes_md_item_batch_config") | |
| 15 | +@KeySequence("mes_md_item_batch_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 16 | +@Data | |
| 17 | +@EqualsAndHashCode(callSuper = true) | |
| 18 | +@ToString(callSuper = true) | |
| 19 | +@Builder | |
| 20 | +@NoArgsConstructor | |
| 21 | +@AllArgsConstructor | |
| 22 | +public class MesMdItemBatchConfigDO extends BaseDO { | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 编号 | |
| 26 | + */ | |
| 27 | + @TableId | |
| 28 | + private Long id; | |
| 29 | + /** | |
| 30 | + * 物料编号 | |
| 31 | + * | |
| 32 | + * 关联 {@link MesMdItemDO#getId()} | |
| 33 | + */ | |
| 34 | + private Long itemId; | |
| 35 | + /** | |
| 36 | + * 批次属性-生产日期 | |
| 37 | + */ | |
| 38 | + private Boolean produceDateFlag; | |
| 39 | + /** | |
| 40 | + * 批次属性-有效期 | |
| 41 | + */ | |
| 42 | + private Boolean expireDateFlag; | |
| 43 | + /** | |
| 44 | + * 批次属性-入库日期 | |
| 45 | + */ | |
| 46 | + private Boolean receiptDateFlag; | |
| 47 | + /** | |
| 48 | + * 批次属性-供应商 | |
| 49 | + */ | |
| 50 | + private Boolean vendorFlag; | |
| 51 | + /** | |
| 52 | + * 批次属性-客户 | |
| 53 | + */ | |
| 54 | + private Boolean clientFlag; | |
| 55 | + /** | |
| 56 | + * 批次属性-销售订单编号 | |
| 57 | + */ | |
| 58 | + private Boolean salesOrderCodeFlag; | |
| 59 | + /** | |
| 60 | + * 批次属性-采购订单编号 | |
| 61 | + */ | |
| 62 | + private Boolean purchaseOrderCodeFlag; | |
| 63 | + /** | |
| 64 | + * 批次属性-生产工单 | |
| 65 | + */ | |
| 66 | + private Boolean workorderFlag; | |
| 67 | + /** | |
| 68 | + * 批次属性-生产任务 | |
| 69 | + */ | |
| 70 | + private Boolean taskFlag; | |
| 71 | + /** | |
| 72 | + * 批次属性-工位 | |
| 73 | + */ | |
| 74 | + private Boolean workstationFlag; | |
| 75 | + /** | |
| 76 | + * 批次属性-工具 | |
| 77 | + */ | |
| 78 | + private Boolean toolFlag; | |
| 79 | + /** | |
| 80 | + * 批次属性-模具 | |
| 81 | + */ | |
| 82 | + private Boolean moldFlag; | |
| 83 | + /** | |
| 84 | + * 批次属性-生产批号 | |
| 85 | + */ | |
| 86 | + private Boolean lotNumberFlag; | |
| 87 | + /** | |
| 88 | + * 批次属性-质量状态 | |
| 89 | + */ | |
| 90 | + private Boolean qualityStatusFlag; | |
| 91 | + | |
| 92 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/md/item/MesMdItemBatchConfigMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.dal.mysql.md.item; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemBatchConfigDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +@Mapper | |
| 8 | +public interface MesMdItemBatchConfigMapper extends BaseMapperX<MesMdItemBatchConfigDO> { | |
| 9 | + | |
| 10 | + default MesMdItemBatchConfigDO selectByItemId(Long itemId) { | |
| 11 | + return selectOne(MesMdItemBatchConfigDO::getItemId, itemId); | |
| 12 | + } | |
| 13 | + | |
| 14 | + default int deleteByItemId(Long itemId) { | |
| 15 | + return delete(MesMdItemBatchConfigDO::getItemId, itemId); | |
| 16 | + } | |
| 17 | + | |
| 18 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
| ... | ... | @@ -30,6 +30,10 @@ public interface ErrorCodeConstants { |
| 30 | 30 | ErrorCode MD_ITEM_NAME_DUPLICATE = new ErrorCode(1_040_102_002, "物料名称已存在"); |
| 31 | 31 | ErrorCode MD_ITEM_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_040_102_003, "导入物料数据不能为空"); |
| 32 | 32 | |
| 33 | + // ========== MES 基础数据-物料批次属性配置(1-040-102-100) ========== | |
| 34 | + ErrorCode MD_ITEM_BATCH_CONFIG_NOT_EXISTS = new ErrorCode(1_040_102_100, "物料批次属性配置不存在"); | |
| 35 | + ErrorCode MD_ITEM_BATCH_CONFIG_AT_LEAST_ONE_FLAG = new ErrorCode(1_040_102_101, "批次管理已启用,至少需要配置一个批次属性"); | |
| 36 | + | |
| 33 | 37 | // ========== MES 基础数据-客户(1-040-103-000) ========== |
| 34 | 38 | ErrorCode MD_CLIENT_NOT_EXISTS = new ErrorCode(1_040_103_000, "客户不存在"); |
| 35 | 39 | ErrorCode MD_CLIENT_CODE_DUPLICATE = new ErrorCode(1_040_103_001, "客户编码已存在"); |
| ... | ... | @@ -46,9 +50,23 @@ public interface ErrorCodeConstants { |
| 46 | 50 | |
| 47 | 51 | // ========== MES 基础数据-车间(1-040-105-000) ========== |
| 48 | 52 | ErrorCode MD_WORKSHOP_NOT_EXISTS = new ErrorCode(1_040_105_000, "车间不存在"); |
| 53 | + ErrorCode MD_WORKSHOP_CODE_DUPLICATE = new ErrorCode(1_040_105_001, "车间编码已存在"); | |
| 54 | + ErrorCode MD_WORKSHOP_NAME_DUPLICATE = new ErrorCode(1_040_105_002, "车间名称已存在"); | |
| 55 | + ErrorCode MD_WORKSHOP_HAS_WORKSTATION = new ErrorCode(1_040_105_003, "车间下存在工位,无法删除"); | |
| 49 | 56 | |
| 50 | 57 | // ========== MES 基础数据-工位(1-040-106-000) ========== |
| 51 | 58 | ErrorCode MD_WORKSTATION_NOT_EXISTS = new ErrorCode(1_040_106_000, "工位不存在"); |
| 59 | + ErrorCode MD_WORKSTATION_CODE_DUPLICATE = new ErrorCode(1_040_106_001, "工位编码已存在"); | |
| 60 | + ErrorCode MD_WORKSTATION_NAME_DUPLICATE = new ErrorCode(1_040_106_002, "工位名称已存在"); | |
| 61 | + // ========== MES 基础数据-工位设备(1-040-106-100) ========== | |
| 62 | + ErrorCode MD_WORKSTATION_MACHINE_NOT_EXISTS = new ErrorCode(1_040_106_100, "工位设备记录不存在"); | |
| 63 | + ErrorCode MD_WORKSTATION_MACHINE_EXISTS = new ErrorCode(1_040_106_101, "该设备已分配到其他工位"); | |
| 64 | + // ========== MES 基础数据-工位工具(1-040-106-200) ========== | |
| 65 | + ErrorCode MD_WORKSTATION_TOOL_NOT_EXISTS = new ErrorCode(1_040_106_200, "工位工具记录不存在"); | |
| 66 | + ErrorCode MD_WORKSTATION_TOOL_TYPE_EXISTS = new ErrorCode(1_040_106_201, "该工具类型已在此工位中存在"); | |
| 67 | + // ========== MES 基础数据-工位人员(1-040-106-300) ========== | |
| 68 | + ErrorCode MD_WORKSTATION_WORKER_NOT_EXISTS = new ErrorCode(1_040_106_300, "工位人员记录不存在"); | |
| 69 | + ErrorCode MD_WORKSTATION_WORKER_POST_EXISTS = new ErrorCode(1_040_106_301, "该岗位已在此工位中存在"); | |
| 52 | 70 | |
| 53 | 71 | // ========== MES 基础数据-产品BOM(1-040-107-000) ========== |
| 54 | 72 | ErrorCode MD_PRODUCT_BOM_NOT_EXISTS = new ErrorCode(1_040_107_000, "产品BOM不存在"); | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemBatchConfigService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.service.md.item; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.batchconfig.MesMdItemBatchConfigSaveReqVO; | |
| 4 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemBatchConfigDO; | |
| 5 | +import jakarta.validation.Valid; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * MES 物料批次属性配置 Service 接口 | |
| 9 | + * | |
| 10 | + * @author 芋道源码 | |
| 11 | + */ | |
| 12 | +public interface MesMdItemBatchConfigService { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 根据物料编号获取批次属性配置 | |
| 16 | + * | |
| 17 | + * @param itemId 物料编号 | |
| 18 | + * @return 批次属性配置,不存在则返回 null | |
| 19 | + */ | |
| 20 | + MesMdItemBatchConfigDO getItemBatchConfigByItemId(Long itemId); | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 保存批次属性配置(新增或更新) | |
| 24 | + * | |
| 25 | + * @param saveReqVO 保存信息 | |
| 26 | + * @return 配置编号 | |
| 27 | + */ | |
| 28 | + Long saveItemBatchConfig(@Valid MesMdItemBatchConfigSaveReqVO saveReqVO); | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * 根据物料编号删除批次属性配置 | |
| 32 | + * | |
| 33 | + * @param itemId 物料编号 | |
| 34 | + */ | |
| 35 | + void deleteItemBatchConfigByItemId(Long itemId); | |
| 36 | + | |
| 37 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemBatchConfigServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.service.md.item; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 4 | +import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.batchconfig.MesMdItemBatchConfigSaveReqVO; | |
| 5 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemBatchConfigDO; | |
| 6 | +import cn.iocoder.yudao.module.mes.dal.mysql.md.item.MesMdItemBatchConfigMapper; | |
| 7 | +import jakarta.annotation.Resource; | |
| 8 | +import org.springframework.context.annotation.Lazy; | |
| 9 | +import org.springframework.stereotype.Service; | |
| 10 | +import org.springframework.validation.annotation.Validated; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 13 | +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.MD_ITEM_NOT_EXISTS; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * MES 物料批次属性配置 Service 实现类 | |
| 17 | + * | |
| 18 | + * @author 芋道源码 | |
| 19 | + */ | |
| 20 | +@Service | |
| 21 | +@Validated | |
| 22 | +public class MesMdItemBatchConfigServiceImpl implements MesMdItemBatchConfigService { | |
| 23 | + | |
| 24 | + @Resource | |
| 25 | + private MesMdItemBatchConfigMapper itemBatchConfigMapper; | |
| 26 | + | |
| 27 | + @Resource | |
| 28 | + @Lazy // 避免循环依赖(MesMdItemServiceImpl 也会注入本 Service) | |
| 29 | + private MesMdItemService itemService; | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public MesMdItemBatchConfigDO getItemBatchConfigByItemId(Long itemId) { | |
| 33 | + return itemBatchConfigMapper.selectByItemId(itemId); | |
| 34 | + } | |
| 35 | + | |
| 36 | + @Override | |
| 37 | + public Long saveItemBatchConfig(MesMdItemBatchConfigSaveReqVO saveReqVO) { | |
| 38 | + // 1. 校验物料存在 | |
| 39 | + if (itemService.getItem(saveReqVO.getItemId()) == null) { | |
| 40 | + throw exception(MD_ITEM_NOT_EXISTS); | |
| 41 | + } | |
| 42 | + | |
| 43 | + // 2. 查询已有配置,决定新增还是更新 | |
| 44 | + MesMdItemBatchConfigDO existing = itemBatchConfigMapper.selectByItemId(saveReqVO.getItemId()); | |
| 45 | + if (existing != null) { | |
| 46 | + // 更新 | |
| 47 | + MesMdItemBatchConfigDO updateObj = BeanUtils.toBean(saveReqVO, MesMdItemBatchConfigDO.class); | |
| 48 | + updateObj.setId(existing.getId()); | |
| 49 | + itemBatchConfigMapper.updateById(updateObj); | |
| 50 | + return existing.getId(); | |
| 51 | + } | |
| 52 | + | |
| 53 | + // 新增 | |
| 54 | + MesMdItemBatchConfigDO insertObj = BeanUtils.toBean(saveReqVO, MesMdItemBatchConfigDO.class); | |
| 55 | + itemBatchConfigMapper.insert(insertObj); | |
| 56 | + return insertObj.getId(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public void deleteItemBatchConfigByItemId(Long itemId) { | |
| 61 | + itemBatchConfigMapper.deleteByItemId(itemId); | |
| 62 | + } | |
| 63 | + | |
| 64 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemServiceImpl.java
| ... | ... | @@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.MesMdItemImportEx |
| 9 | 9 | import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.MesMdItemImportRespVO; |
| 10 | 10 | import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.MesMdItemPageReqVO; |
| 11 | 11 | import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.MesMdItemSaveReqVO; |
| 12 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 13 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemBatchConfigDO; | |
| 12 | 14 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; |
| 13 | 15 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemTypeDO; |
| 14 | 16 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; |
| ... | ... | @@ -45,6 +47,9 @@ public class MesMdItemServiceImpl implements MesMdItemService { |
| 45 | 47 | @Resource |
| 46 | 48 | private MesMdUnitMeasureService unitMeasureService; |
| 47 | 49 | |
| 50 | + @Resource | |
| 51 | + private MesMdItemBatchConfigService itemBatchConfigService; | |
| 52 | + | |
| 48 | 53 | @Override |
| 49 | 54 | public Long createItem(MesMdItemSaveReqVO createReqVO) { |
| 50 | 55 | // 校验物料编码的唯一性 |
| ... | ... | @@ -76,6 +81,9 @@ public class MesMdItemServiceImpl implements MesMdItemService { |
| 76 | 81 | // 校验计量单位存在 |
| 77 | 82 | validateUnitMeasureExists(updateReqVO.getUnitMeasureId()); |
| 78 | 83 | |
| 84 | + // 如果启用了批次管理且状态为开启,校验批次属性配置 | |
| 85 | + validateBatchConfigIfNeeded(updateReqVO); | |
| 86 | + | |
| 79 | 87 | // 更新 |
| 80 | 88 | MesMdItemDO updateObj = BeanUtils.toBean(updateReqVO, MesMdItemDO.class); |
| 81 | 89 | clearStockIfNotSafe(updateObj); // 如果未启用安全库存,清零库存上下限 |
| ... | ... | @@ -86,6 +94,8 @@ public class MesMdItemServiceImpl implements MesMdItemService { |
| 86 | 94 | public void deleteItem(Long id) { |
| 87 | 95 | // 校验存在 |
| 88 | 96 | validateItemExists(id); |
| 97 | + // 级联删除批次属性配置 | |
| 98 | + itemBatchConfigService.deleteItemBatchConfigByItemId(id); | |
| 89 | 99 | // 删除 |
| 90 | 100 | itemMapper.deleteById(id); |
| 91 | 101 | } |
| ... | ... | @@ -144,6 +154,39 @@ public class MesMdItemServiceImpl implements MesMdItemService { |
| 144 | 154 | item.setMinStock(BigDecimal.ZERO).setMaxStock(BigDecimal.ZERO); |
| 145 | 155 | } |
| 146 | 156 | |
| 157 | + /** | |
| 158 | + * 如果启用了批次管理且状态为开启,校验批次属性配置是否存在且至少一个属性为 true | |
| 159 | + */ | |
| 160 | + private void validateBatchConfigIfNeeded(MesMdItemSaveReqVO reqVO) { | |
| 161 | + if (!Boolean.TRUE.equals(reqVO.getBatchFlag())) { | |
| 162 | + return; | |
| 163 | + } | |
| 164 | + if (!CommonStatusEnum.ENABLE.getStatus().equals(reqVO.getStatus())) { | |
| 165 | + return; | |
| 166 | + } | |
| 167 | + MesMdItemBatchConfigDO config = itemBatchConfigService.getItemBatchConfigByItemId(reqVO.getId()); | |
| 168 | + if (config == null) { | |
| 169 | + throw exception(MD_ITEM_BATCH_CONFIG_NOT_EXISTS); | |
| 170 | + } | |
| 171 | + boolean hasAnyFlag = Boolean.TRUE.equals(config.getProduceDateFlag()) | |
| 172 | + || Boolean.TRUE.equals(config.getExpireDateFlag()) | |
| 173 | + || Boolean.TRUE.equals(config.getReceiptDateFlag()) | |
| 174 | + || Boolean.TRUE.equals(config.getVendorFlag()) | |
| 175 | + || Boolean.TRUE.equals(config.getClientFlag()) | |
| 176 | + || Boolean.TRUE.equals(config.getSalesOrderCodeFlag()) | |
| 177 | + || Boolean.TRUE.equals(config.getPurchaseOrderCodeFlag()) | |
| 178 | + || Boolean.TRUE.equals(config.getWorkorderFlag()) | |
| 179 | + || Boolean.TRUE.equals(config.getTaskFlag()) | |
| 180 | + || Boolean.TRUE.equals(config.getWorkstationFlag()) | |
| 181 | + || Boolean.TRUE.equals(config.getToolFlag()) | |
| 182 | + || Boolean.TRUE.equals(config.getMoldFlag()) | |
| 183 | + || Boolean.TRUE.equals(config.getLotNumberFlag()) | |
| 184 | + || Boolean.TRUE.equals(config.getQualityStatusFlag()); | |
| 185 | + if (!hasAnyFlag) { | |
| 186 | + throw exception(MD_ITEM_BATCH_CONFIG_AT_LEAST_ONE_FLAG); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + | |
| 147 | 190 | @Override |
| 148 | 191 | public MesMdItemDO getItem(Long id) { |
| 149 | 192 | return itemMapper.selectById(id); | ... | ... |