优化特殊需要判断租户状态表,唯一验证需要单独提取判断

v1.4.1
Parker 4 years ago
parent 090991f823
commit dd2f95dab8

@ -34,10 +34,9 @@ public interface RoleMapper extends BaseMapper<SysRole> {
/**
*
* @param entity
* @param wrapper
* @return
*/
Integer uniqueVerificationByCode(@Param("entity") SysRole entity, @Param("ew") Wrapper<SysRole> wrapper);
Integer uniqueVerificationByCode(@Param("ew") Wrapper<SysRole> wrapper);
}

@ -26,14 +26,9 @@
select
count(0)
from
sys_role a
sys_role
<where>
${ew.sqlSegment}
and a.role_code = #{entity.roleCode}
and a.deleted = 0
<if test="entity != null and entity.id != null and entity.id != ''">
and a.id != #{entity.id}
</if>
</where>
</select>

@ -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<RoleMapper, SysRole, RoleMo
SysRole entity = super.transformM2T(model);
// 唯一验证
QueryBuilder<SysRole> queryBuilder = new GenQueryBuilder<>();
// 多租户处理
TenantHandler tenantHandler = new TenantHandler();
QueryWrapper<SysRole> 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<RoleMapper, SysRole, RoleMo
SysRole entity = super.transformM2T(model);
// 唯一验证
QueryBuilder<SysRole> queryBuilder = new GenQueryBuilder<>();
// 多租户处理
TenantHandler tenantHandler = new TenantHandler();
QueryWrapper<SysRole> 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<RoleMapper, SysRole, RoleMo
}
/**
*
* @param entity
* @return
*/
@Transactional(readOnly = true)
public Integer uniqueVerificationByCode(SysRole entity){
QueryWrapper<SysRole> 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);
}
}

Loading…
Cancel
Save