|
@@ -1,9 +1,12 @@
|
|
package com.simuwang.manage.service.impl.system;
|
|
package com.simuwang.manage.service.impl.system;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.simuwang.base.common.exception.APIException;
|
|
import com.simuwang.base.common.support.MybatisPage;
|
|
import com.simuwang.base.common.support.MybatisPage;
|
|
import com.simuwang.base.common.support.command.BaseAddCmd;
|
|
import com.simuwang.base.common.support.command.BaseAddCmd;
|
|
import com.simuwang.base.common.support.command.BaseEditCmd;
|
|
import com.simuwang.base.common.support.command.BaseEditCmd;
|
|
@@ -28,6 +31,7 @@ import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.function.Consumer;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -49,7 +53,7 @@ public class SysRoleServiceImpl implements SysRoleService {
|
|
@Override
|
|
@Override
|
|
public <Q extends PageQuery> void wrapQuery(QueryWrapper<SysRoleDO> wrapper, Q query) {
|
|
public <Q extends PageQuery> void wrapQuery(QueryWrapper<SysRoleDO> wrapper, Q query) {
|
|
// 排除超级管理员
|
|
// 排除超级管理员
|
|
- wrapper.ne("role_id", 1).notIn("role_key", "SYSTEM", "ADMIN");
|
|
|
|
|
|
+ wrapper.ne("role_id", 1).notIn("role_key", "SYSTEM", "ADMIN", "system", "admin");
|
|
RoleQuery params = (RoleQuery) query;
|
|
RoleQuery params = (RoleQuery) query;
|
|
String keyword = params.getKeyword();
|
|
String keyword = params.getKeyword();
|
|
if (StrUtil.isNotBlank(keyword)) {
|
|
if (StrUtil.isNotBlank(keyword)) {
|
|
@@ -70,6 +74,10 @@ public class SysRoleServiceImpl implements SysRoleService {
|
|
public <C extends BaseAddCmd<SysRoleDO>> void insert(C command) {
|
|
public <C extends BaseAddCmd<SysRoleDO>> void insert(C command) {
|
|
RoleAddCmd cmd = (RoleAddCmd) command;
|
|
RoleAddCmd cmd = (RoleAddCmd) command;
|
|
SysRoleDO entity = cmd.toEntity();
|
|
SysRoleDO entity = cmd.toEntity();
|
|
|
|
+ SysRoleDO role = this.getRole(entity);
|
|
|
|
+ if (role != null) {
|
|
|
|
+ throw new APIException("角色名称或权限字符已存在");
|
|
|
|
+ }
|
|
this.mapper.insert(entity);
|
|
this.mapper.insert(entity);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -77,6 +85,10 @@ public class SysRoleServiceImpl implements SysRoleService {
|
|
public <C extends BaseEditCmd<SysRoleDO>> void update(C command) {
|
|
public <C extends BaseEditCmd<SysRoleDO>> void update(C command) {
|
|
RoleEditCmd cmd = (RoleEditCmd) command;
|
|
RoleEditCmd cmd = (RoleEditCmd) command;
|
|
SysRoleDO entity = cmd.toEntity();
|
|
SysRoleDO entity = cmd.toEntity();
|
|
|
|
+ SysRoleDO role = this.getRole(entity);
|
|
|
|
+ if (role != null) {
|
|
|
|
+ throw new APIException("角色名称或权限字符已存在");
|
|
|
|
+ }
|
|
this.mapper.updateById(entity);
|
|
this.mapper.updateById(entity);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -109,4 +121,15 @@ public class SysRoleServiceImpl implements SysRoleService {
|
|
List<OnlyIdNameDO> dataList = this.userAuthService.roleAssignPerms(query.getId());
|
|
List<OnlyIdNameDO> dataList = this.userAuthService.roleAssignPerms(query.getId());
|
|
return dataList.stream().map(OnlyIdNameDO::toVo).collect(Collectors.toList());
|
|
return dataList.stream().map(OnlyIdNameDO::toVo).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private SysRoleDO getRole(SysRoleDO entity) {
|
|
|
|
+ Consumer<LambdaQueryWrapper<SysRoleDO>> consumer = w -> w
|
|
|
|
+ .eq(SysRoleDO::getRoleName, entity.getRoleName())
|
|
|
|
+ .or()
|
|
|
|
+ .eq(SysRoleDO::getRoleKey, entity.getRoleKey());
|
|
|
|
+ LambdaQueryWrapper<SysRoleDO> wrapper = Wrappers.lambdaQuery(SysRoleDO.class)
|
|
|
|
+ .eq(entity.getRoleId() != null, SysRoleDO::getRoleId, entity.getRoleId())
|
|
|
|
+ .and(consumer);
|
|
|
|
+ return this.mapper.selectOne(wrapper);
|
|
|
|
+ }
|
|
}
|
|
}
|