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