From 16bd124cac92b7dcc4d323307f724ee596257bd0 Mon Sep 17 00:00:00 2001 From: luogw <3132758203@qq.com> Date: Tue, 21 Jul 2026 15:07:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81=E7=BA=BF=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UpdateProductLineDomainServiceImpl.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/project/information/domain/service/impl/UpdateProductLineDomainServiceImpl.java b/src/main/java/com/project/information/domain/service/impl/UpdateProductLineDomainServiceImpl.java index f8e23ec..499ae82 100644 --- a/src/main/java/com/project/information/domain/service/impl/UpdateProductLineDomainServiceImpl.java +++ b/src/main/java/com/project/information/domain/service/impl/UpdateProductLineDomainServiceImpl.java @@ -1,6 +1,5 @@ package com.project.information.domain.service.impl; -import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.project.base.domain.exception.BusinessErrorException; @@ -28,16 +27,26 @@ public class UpdateProductLineDomainServiceImpl implements UpdateProductLineDoma throw new BusinessErrorException("名称不能为空"); } ProductLineEntity entity = productLineBaseService.getById(dto.getId()); + if (entity == null) { + throw new BusinessErrorException("产品线不存在"); + } LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(ProductLineEntity::getBusiness , entity.getBusiness()); - queryWrapper.eq(ProductLineEntity::getLeaf , entity.getLeaf()); + queryWrapper.eq(ProductLineEntity::getBusiness, entity.getBusiness()); + if (Boolean.TRUE.equals(entity.getLeaf())) { + // 子产品线:同一父级下名称不能重复 + queryWrapper.eq(ProductLineEntity::getParentId, entity.getParentId()); + } else { + // 产品线:同一 BG 下名称不能重复 + queryWrapper.eq(ProductLineEntity::getLeaf, false); + } queryWrapper.eq(ProductLineEntity::getName , dto.getName()); - ProductLineEntity existOne = productLineBaseService.getOne(queryWrapper); - if (Objects.nonNull(existOne)) { - if (BooleanUtil.isFalse(entity.getLeaf())) { - throw new BusinessErrorException("同一 BG 下产品线名称不能重复"); - } else { + queryWrapper.ne(ProductLineEntity::getId , dto.getId()); + long count = productLineBaseService.count(queryWrapper); + if (count > 0) { + if (Boolean.TRUE.equals(entity.getLeaf())) { throw new BusinessErrorException("同一产品线下子产品线名称不能重复"); + } else { + throw new BusinessErrorException("同一 BG 下产品线名称不能重复"); } } entity.setName(dto.getName());