From dd2f95dab824307ed39f88fe855cf6ee130281d9 Mon Sep 17 00:00:00 2001 From: Parker Date: Sun, 29 Nov 2020 23:47:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=89=B9=E6=AE=8A=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=88=A4=E6=96=AD=E7=A7=9F=E6=88=B7=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E5=94=AF=E4=B8=80=E9=AA=8C=E8=AF=81=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=8D=95=E7=8B=AC=E6=8F=90=E5=8F=96=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/role/mapper/RoleMapper.java | 3 +- .../system/role/mapper/xml/RoleMapper.xml | 7 +--- .../role/service/impl/RoleServiceImpl.java | 40 +++++++++++++------ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMapper.java index 83ddc5e..f7ac43c 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMapper.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMapper.java @@ -34,10 +34,9 @@ public interface RoleMapper extends BaseMapper { /** * 唯一验证 - * @param entity * @param wrapper * @return */ - Integer uniqueVerificationByCode(@Param("entity") SysRole entity, @Param("ew") Wrapper wrapper); + Integer uniqueVerificationByCode(@Param("ew") Wrapper wrapper); } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMapper.xml index 91fc299..b4cf97d 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMapper.xml +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMapper.xml @@ -26,14 +26,9 @@ select count(0) from - sys_role a + sys_role ${ew.sqlSegment} - and a.role_code = #{entity.roleCode} - and a.deleted = 0 - - and a.id != #{entity.id} - diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java index 6cdbf9e..bde903f 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java @@ -16,11 +16,11 @@ package org.opsli.modulars.system.role.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.commons.lang3.StringUtils; import org.opsli.api.wrapper.system.role.RoleModel; +import org.opsli.common.constants.MyBatisConstants; import org.opsli.common.exception.ServiceException; import org.opsli.core.base.service.impl.CrudServiceImpl; -import org.opsli.core.persistence.querybuilder.GenQueryBuilder; -import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.chain.TenantHandler; import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.role.entity.SysRole; @@ -51,11 +51,7 @@ public class RoleServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); - // 多租户处理 - TenantHandler tenantHandler = new TenantHandler(); - QueryWrapper qWrapper = tenantHandler.handler(entityClazz, queryBuilder.build()); - Integer count = mapper.uniqueVerificationByCode(entity,qWrapper); + Integer count = this.uniqueVerificationByCode(entity); if(count != null && count > 0){ // 重复 throw new ServiceException(SystemMsg.EXCEPTION_ROLE_UNIQUE); @@ -71,11 +67,7 @@ public class RoleServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); - // 多租户处理 - TenantHandler tenantHandler = new TenantHandler(); - QueryWrapper qWrapper = tenantHandler.handler(entityClazz, queryBuilder.build()); - Integer count = mapper.uniqueVerificationByCode(entity,qWrapper); + Integer count = this.uniqueVerificationByCode(entity); if(count != null && count > 0){ // 重复 throw new ServiceException(SystemMsg.EXCEPTION_ROLE_UNIQUE); @@ -85,6 +77,30 @@ public class RoleServiceImpl extends CrudServiceImpl wrapper = new QueryWrapper<>(); + + // code 唯一 + wrapper.eq("role_code", entity.getRoleCode()) + .eq(MyBatisConstants.FIELD_DELETE_LOGIC, "0"); + + // 如果为修改 则跳过当前数据 + if(StringUtils.isNotBlank(entity.getId())){ + wrapper.notIn(MyBatisConstants.FIELD_ID, entity.getId()); + } + + // 租户检测 + wrapper = new TenantHandler().handler(super.entityClazz, wrapper); + + return mapper.uniqueVerificationByCode(wrapper); + } + }