删除标签添加约束条件

This commit is contained in:
yangsb
2024-04-07 17:00:30 +08:00
parent 7ae23bdf87
commit 33597959e2
2 changed files with 14 additions and 0 deletions
@@ -189,6 +189,7 @@ public interface ErrorCodeConstants {
ErrorCode LABEL_TEMPLATE_NOT_EXISTS = new ErrorCode(1_002_300_000, "标签模板不存在");
ErrorCode LABEL_NOT_EXISTS = new ErrorCode(1_002_300_001, "标签不存在");
ErrorCode DEFAULT_LABEL_NOT_EXISTS = new ErrorCode(1_002_300_002, "该类型标签默认模板不存在");
ErrorCode MACHINE_USE_LABEL = new ErrorCode(1_002_300_003, "无法删除已有机台使用标签");
// ========== 系统数据源 1_002_301_000 ==========
ErrorCode DATA_SOURCE_NOT_EXISTS = new ErrorCode(1_002_301_000, "系统数据源不存在");
@@ -1,11 +1,14 @@
package com.cf.imes.module.system.service.lable;
import cn.hutool.core.collection.CollectionUtil;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.system.controller.admin.label.vo.*;
import com.cf.imes.module.system.dal.dataobject.lable.LabelDO;
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
import com.cf.imes.module.system.dal.mysql.label.LabelMapper;
import com.cf.imes.module.system.dal.mysql.machine.MachineMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -15,6 +18,7 @@ import java.util.*;
import java.util.stream.Collectors;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.LABEL_NOT_EXISTS;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.MACHINE_USE_LABEL;
/**
* 标签模板 Service 实现类
@@ -29,6 +33,8 @@ public class LabelServiceImpl implements LabelService {
@Resource
private LabelMapper labelMapper;
@Resource
private MachineMapper machineMapper;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -58,6 +64,13 @@ public class LabelServiceImpl implements LabelService {
if (LabelDO == null) {
throw exception(LABEL_NOT_EXISTS);
}
List<MachineDO> machineDOS = machineMapper.selectList(new LambdaQueryWrapperX<MachineDO>()
.select(MachineDO::getId)
.eq(MachineDO::getLabelId, id)
);
if(CollectionUtil.isNotEmpty(machineDOS)) {
throw exception(MACHINE_USE_LABEL);
}
// 删除标签模板表
labelMapper.deleteById(id);