From f7d336cfc46bd184769a6c24fce263b59c660143 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Thu, 7 Nov 2024 18:18:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E8=B5=84=E6=8E=A5=E5=8F=A3=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/bonus/material/ma/mapper/TypeMapper.java | 2 +- .../bonus/material/ma/service/impl/TypeServiceImpl.java | 8 ++++---- .../src/main/resources/mapper/material/ma/TypeMapper.xml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java index e9e4b029..ba21ca7f 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java @@ -127,7 +127,7 @@ public interface TypeMapper { */ int logicDeleteTypeByTypeIds(Long[] typeIds); - Type queryByName(String typeName); + Type queryByNameAndParentId(@Param("typeName") String typeName, @Param("parentId") Long parentId); /** * 根据ID查询 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java index d7b3cbfb..f442b6f3 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java @@ -290,8 +290,8 @@ public class TypeServiceImpl implements ITypeService { @Override public int insertType(Type type) { //根据类型名称判断,去重 - Type maType = typeMapper.queryByName(type.getTypeName()); - if (maType != null && maType.getParentId().equals(type.getParentId())) { + Type maType = typeMapper.queryByNameAndParentId(type.getTypeName(), type.getParentId()); + if (maType != null) { throw new RuntimeException("同级下类型名称存在重复!"); } type.setLevel(String.valueOf(Integer.parseInt(type.getLevel()) + 1)); @@ -318,8 +318,8 @@ public class TypeServiceImpl implements ITypeService { @Override public int updateType(Type type) { //根据类型名称判断,去重 - Type maType = typeMapper.queryByName(type.getTypeName()); - if (maType != null && !maType.getTypeId().equals(type.getTypeId()) && maType.getParentId().equals(type.getParentId())) { + Type maType = typeMapper.queryByNameAndParentId(type.getTypeName(), type.getParentId()); + if (maType != null && !maType.getTypeId().equals(type.getTypeId())) { throw new RuntimeException("同级下类型名称存在重复!"); } type.setUpdateTime(DateUtils.getNowDate()); diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml index 79f672e5..3905f4a1 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml @@ -513,11 +513,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ) - select type_id as typeId, parent_id as parentId, type_name as typeName, level as level from ma_type - where type_name = #{typeName} and del_flag = '0' + where type_name = #{typeName} and parent_id = #{parentId} and del_flag = '0'