Commit 521c5380dfac4db15957bd21cae00daa05536172

Authored by YunaiV
1 parent da07eebb

✨ feat(service): 添加工具删除时的批次引用校验

yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/tm/tool/MesTmToolServiceImpl.java
1 1 package cn.iocoder.yudao.module.mes.service.tm.tool;
2 2  
3   -import java.util.Collections;
4 3 import cn.hutool.core.util.ObjUtil;
5 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
... ... @@ -11,18 +10,19 @@ import cn.iocoder.yudao.module.mes.dal.mysql.tm.tool.MesTmToolMapper;
11 10 import cn.iocoder.yudao.module.mes.enums.tm.MesTmMaintenTypeEnum;
12 11 import cn.iocoder.yudao.module.mes.enums.wm.BarcodeBizTypeEnum;
13 12 import cn.iocoder.yudao.module.mes.service.wm.barcode.MesWmBarcodeService;
  13 +import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService;
14 14 import jakarta.annotation.Resource;
15 15 import org.springframework.context.annotation.Lazy;
16 16 import org.springframework.stereotype.Service;
17 17 import org.springframework.validation.annotation.Validated;
18 18  
19 19 import java.util.Collection;
  20 +import java.util.Collections;
20 21 import java.util.List;
21 22 import java.util.Objects;
22 23  
23 24 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
24   -import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.TM_TOOL_CODE_DUPLICATE;
25   -import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.TM_TOOL_NOT_EXISTS;
  25 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
26 26  
27 27 /**
28 28 * MES 工具台账 Service 实现类
... ... @@ -41,6 +41,9 @@ public class MesTmToolServiceImpl implements MesTmToolService {
41 41 private MesTmToolTypeService toolTypeService;
42 42 @Resource
43 43 private MesWmBarcodeService barcodeService;
  44 + @Resource
  45 + @Lazy
  46 + private MesWmBatchService batchService;
44 47  
45 48 @Override
46 49 public Long createTool(MesTmToolSaveReqVO createReqVO) {
... ... @@ -86,6 +89,11 @@ public class MesTmToolServiceImpl implements MesTmToolService {
86 89 public void deleteTool(Long id) {
87 90 // 校验存在
88 91 validateToolExists(id);
  92 + // 校验是否被批次引用
  93 + if (batchService.getBatchCountByToolId(id) > 0) {
  94 + throw exception(TM_TOOL_HAS_BATCH);
  95 + }
  96 +
89 97 // 删除
90 98 toolMapper.deleteById(id);
91 99 }
... ...