加强产品编码管理的完整性校验
在产品编码管理模块中,新增了对MFC、批次和规则下是否存在产品的校验。此更新确保在尝试修改或删除MFC、批次和规则时,如果这些实体下存在关联产品,系统将阻止操作并返回错误信息。该功能提升了数据一致性和操作的可靠性,避免了可能的数据完整性问题。
This commit is contained in:
parent
dbb08b4d9b
commit
778ea6a1f1
|
@ -53,6 +53,10 @@ public class BatchesService extends BaseService<BatchesMapper, Batches> {
|
|||
@Lazy
|
||||
private AttributeValueBackupService attributeValueBackupService;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private CodeService codeService;
|
||||
|
||||
public Result addBatches(BatchesVo vo) {
|
||||
Long count = this.getBaseMapper().selectCount(new QueryWrapper<Batches>()
|
||||
.lambda()
|
||||
|
@ -78,6 +82,13 @@ public class BatchesService extends BaseService<BatchesMapper, Batches> {
|
|||
if (ObjUtil.isNull(obj)) {
|
||||
return Result.fail("数据不存在");
|
||||
}
|
||||
count = codeService.count(new QueryWrapper<Code>()
|
||||
.lambda()
|
||||
.eq(Code::getBatchesId, id)
|
||||
);
|
||||
if (count > 0) {
|
||||
return Result.fail("该批次下有产品,无法修改");
|
||||
}
|
||||
obj.setBatchesName(vo.getBatchesName());
|
||||
obj.setBatchesDescription(vo.getBatchesDescription());
|
||||
return this.saveOrUpdate(obj) ? Result.success("操作成功") : Result.fail("操作失败");
|
||||
|
@ -87,6 +98,13 @@ public class BatchesService extends BaseService<BatchesMapper, Batches> {
|
|||
if (ObjUtil.isNull(this.getById(id))) {
|
||||
return Result.fail("数据不存在");
|
||||
}
|
||||
Long count = codeService.count(new QueryWrapper<Code>()
|
||||
.lambda()
|
||||
.eq(Code::getBatchesId, id)
|
||||
);
|
||||
if (count > 0) {
|
||||
return Result.fail("该批次下有产品,无法删除");
|
||||
}
|
||||
return this.removeById(id) ? Result.success("操作成功") : Result.fail("操作失败");
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,7 @@ import cn.workde.core.base.BaseService;
|
|||
import cn.workde.core.data.dto.Result;
|
||||
import cn.workde.module.drone.coding.dto.AttributeClassificationDto;
|
||||
import cn.workde.module.drone.coding.dto.AttributeValueDto;
|
||||
import cn.workde.module.drone.coding.entity.Attribute;
|
||||
import cn.workde.module.drone.coding.entity.AttributeClassification;
|
||||
import cn.workde.module.drone.coding.entity.AttributeValue;
|
||||
import cn.workde.module.drone.coding.entity.Mfc;
|
||||
import cn.workde.module.drone.coding.entity.*;
|
||||
import cn.workde.module.drone.coding.mapper.MfcMapper;
|
||||
import cn.workde.module.drone.coding.vo.AttributeValueVo;
|
||||
import cn.workde.module.drone.coding.vo.AttributeValueVo2;
|
||||
|
@ -46,6 +43,10 @@ public class MfcService extends BaseService<MfcMapper, Mfc> {
|
|||
@Lazy
|
||||
private AttributeValueService attributeValueService;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private CodeService codeService;
|
||||
|
||||
|
||||
private String check(String id, MfcVo vo) {
|
||||
String message = "";
|
||||
|
@ -87,6 +88,13 @@ public class MfcService extends BaseService<MfcMapper, Mfc> {
|
|||
if (ObjUtil.isNull(obj)) {
|
||||
return Result.fail("数据不存在");
|
||||
}
|
||||
long count = codeService.count(new QueryWrapper<Code>()
|
||||
.lambda()
|
||||
.eq(Code::getMfcId, id)
|
||||
);
|
||||
if (count > 0) {
|
||||
return Result.fail("该MFC下有产品,不允许修改");
|
||||
}
|
||||
obj.setMfcName(vo.getMfcName());
|
||||
obj.setMfcDescription(vo.getMfcDescription());
|
||||
return this.saveOrUpdate(obj) ? Result.success("操作成功") : Result.fail("操作失败");
|
||||
|
@ -96,6 +104,13 @@ public class MfcService extends BaseService<MfcMapper, Mfc> {
|
|||
if (ObjUtil.isNull(this.getById(id))) {
|
||||
return Result.fail("数据不存在");
|
||||
}
|
||||
long count = codeService.count(new QueryWrapper<Code>()
|
||||
.lambda()
|
||||
.eq(Code::getMfcId, id)
|
||||
);
|
||||
if (count > 0) {
|
||||
return Result.fail("该MFC下有产品,不允许删除");
|
||||
}
|
||||
return this.removeById(id) ? Result.success("操作成功") : Result.fail("操作失败");
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,14 @@ import cn.hutool.core.util.ObjUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.workde.core.base.BaseService;
|
||||
import cn.workde.core.data.dto.Result;
|
||||
import cn.workde.module.drone.coding.entity.Code;
|
||||
import cn.workde.module.drone.coding.entity.Rule;
|
||||
import cn.workde.module.drone.coding.mapper.RuleMapper;
|
||||
import cn.workde.module.drone.coding.vo.RuleVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -26,6 +29,11 @@ public class RuleService extends BaseService<RuleMapper, Rule> {
|
|||
|
||||
private final List<String> codeList = CollUtil.newArrayList("001", "002", "003");
|
||||
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private CodeService codeService;
|
||||
|
||||
private String check(String id, RuleVo vo) {
|
||||
vo.setRuleCode(StrUtil.trim(vo.getRuleCode()));
|
||||
//判断编码唯一性
|
||||
|
@ -69,6 +77,13 @@ public class RuleService extends BaseService<RuleMapper, Rule> {
|
|||
return Result.fail("数据不存在");
|
||||
}
|
||||
|
||||
long count = codeService.count(new QueryWrapper<Code>()
|
||||
.lambda()
|
||||
.eq(Code::getRuleId, id)
|
||||
);
|
||||
if (count > 0) {
|
||||
return Result.fail("该规则下有产品,不允许修改");
|
||||
}
|
||||
if (!codeList.contains(rule.getRuleCode())) {
|
||||
rule.setRuleCode(vo.getRuleCode());
|
||||
}
|
||||
|
@ -84,6 +99,13 @@ public class RuleService extends BaseService<RuleMapper, Rule> {
|
|||
if (codeList.contains(rule.getRuleCode())) {
|
||||
return Result.fail("内置规则,不允许删除");
|
||||
}
|
||||
long count = codeService.count(new QueryWrapper<Code>()
|
||||
.lambda()
|
||||
.eq(Code::getRuleId, id)
|
||||
);
|
||||
if (count > 0) {
|
||||
return Result.fail("该规则下有产品,不允许删除");
|
||||
}
|
||||
return this.removeById(id) ? Result.success("操作成功") : Result.fail("操作失败");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue