|
@@ -1,6 +1,8 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.common.annotation.DataScope;
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
@@ -9,6 +11,7 @@ import com.ruoyi.common.exception.CustomException;
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
import com.ruoyi.system.domain.SysRoleDept;
|
|
|
import com.ruoyi.system.domain.SysRoleMenu;
|
|
|
+import com.ruoyi.system.domain.SysUserRole;
|
|
|
import com.ruoyi.system.mapper.SysRoleDeptMapper;
|
|
|
import com.ruoyi.system.mapper.SysRoleMapper;
|
|
|
import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
|
@@ -27,8 +30,6 @@ import java.util.*;
|
|
|
*/
|
|
|
@Service
|
|
|
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
|
|
|
- @Autowired
|
|
|
- private SysRoleMapper roleMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SysRoleMenuMapper roleMenuMapper;
|
|
@@ -48,7 +49,20 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
@Override
|
|
|
@DataScope(deptAlias = "d")
|
|
|
public List<SysRole> selectRoleList(SysRole role) {
|
|
|
- return roleMapper.selectRoleList(role);
|
|
|
+ Map<String, Object> params = role.getParams();
|
|
|
+ Object dataScope = params.get("dataScope");
|
|
|
+ return list(new LambdaQueryWrapper<SysRole>()
|
|
|
+ .like(StrUtil.isNotBlank(role.getRoleName()), SysRole::getRoleName, role.getRoleName())
|
|
|
+ .eq(StrUtil.isNotBlank(role.getStatus()), SysRole::getStatus, role.getStatus())
|
|
|
+ .like(StrUtil.isNotBlank(role.getRoleKey()), SysRole::getRoleKey, role.getRoleKey())
|
|
|
+ .apply(Validator.isNotEmpty(params.get("beginTime")),
|
|
|
+ "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')",
|
|
|
+ params.get("beginTime"))
|
|
|
+ .apply(Validator.isNotEmpty(params.get("endTime")),
|
|
|
+ "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')",
|
|
|
+ params.get("endTime"))
|
|
|
+ .apply(dataScope != null, dataScope != null ? dataScope.toString() : null)
|
|
|
+ .orderByAsc(SysRole::getRoleSort));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -59,7 +73,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public Set<String> selectRolePermissionByUserId(Long userId) {
|
|
|
- List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
|
|
|
+ List<SysRole> perms = baseMapper.selectRolePermissionByUserId(userId);
|
|
|
Set<String> permsSet = new HashSet<>();
|
|
|
for (SysRole perm : perms) {
|
|
|
if (Validator.isNotNull(perm)) {
|
|
@@ -87,7 +101,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public List<Integer> selectRoleListByUserId(Long userId) {
|
|
|
- return roleMapper.selectRoleListByUserId(userId);
|
|
|
+ return baseMapper.selectRoleListByUserId(userId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -98,7 +112,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public SysRole selectRoleById(Long roleId) {
|
|
|
- return roleMapper.selectRoleById(roleId);
|
|
|
+ return getById(roleId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -110,7 +124,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
@Override
|
|
|
public String checkRoleNameUnique(SysRole role) {
|
|
|
Long roleId = Validator.isNull(role.getRoleId()) ? -1L : role.getRoleId();
|
|
|
- SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
|
|
|
+ SysRole info = getOne(new LambdaQueryWrapper<SysRole>()
|
|
|
+ .eq(SysRole::getRoleName, role.getRoleName()).last("limit 1"));
|
|
|
if (Validator.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
}
|
|
@@ -126,7 +141,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
@Override
|
|
|
public String checkRoleKeyUnique(SysRole role) {
|
|
|
Long roleId = Validator.isNull(role.getRoleId()) ? -1L : role.getRoleId();
|
|
|
- SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey());
|
|
|
+ SysRole info = getOne(new LambdaQueryWrapper<SysRole>()
|
|
|
+ .eq(SysRole::getRoleKey, role.getRoleKey()).last("limit 1"));
|
|
|
if (Validator.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
}
|
|
@@ -153,7 +169,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public int countUserRoleByRoleId(Long roleId) {
|
|
|
- return userRoleMapper.countUserRoleByRoleId(roleId);
|
|
|
+ return userRoleMapper.selectCount(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getRoleId, roleId));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -166,7 +182,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
@Transactional
|
|
|
public int insertRole(SysRole role) {
|
|
|
// 新增角色信息
|
|
|
- roleMapper.insertRole(role);
|
|
|
+ baseMapper.insert(role);
|
|
|
return insertRoleMenu(role);
|
|
|
}
|
|
|
|
|
@@ -180,9 +196,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
@Transactional
|
|
|
public int updateRole(SysRole role) {
|
|
|
// 修改角色信息
|
|
|
- roleMapper.updateRole(role);
|
|
|
+ baseMapper.updateById(role);
|
|
|
// 删除角色与菜单关联
|
|
|
- roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId());
|
|
|
+ roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, role.getRoleId()));
|
|
|
return insertRoleMenu(role);
|
|
|
}
|
|
|
|
|
@@ -194,7 +210,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public int updateRoleStatus(SysRole role) {
|
|
|
- return roleMapper.updateRole(role);
|
|
|
+ return baseMapper.updateById(role);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -207,9 +223,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
@Transactional
|
|
|
public int authDataScope(SysRole role) {
|
|
|
// 修改角色信息
|
|
|
- roleMapper.updateRole(role);
|
|
|
+ baseMapper.updateById(role);
|
|
|
// 删除角色与部门关联
|
|
|
- roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId());
|
|
|
+ roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().eq(SysRoleDept::getRoleId, role.getRoleId()));
|
|
|
// 新增角色和部门信息(数据权限)
|
|
|
return insertRoleDept(role);
|
|
|
}
|
|
@@ -220,7 +236,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
* @param role 角色对象
|
|
|
*/
|
|
|
public int insertRoleMenu(SysRole role) {
|
|
|
- int rows = 1;
|
|
|
+ int rows = 0;
|
|
|
// 新增用户与角色管理
|
|
|
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
|
|
|
for (Long menuId : role.getMenuIds()) {
|
|
@@ -230,7 +246,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
list.add(rm);
|
|
|
}
|
|
|
if (list.size() > 0) {
|
|
|
- rows = roleMenuMapper.batchRoleMenu(list);
|
|
|
+ for (SysRoleMenu sysRoleMenu : list) {
|
|
|
+ rows += roleMenuMapper.insert(sysRoleMenu);
|
|
|
+ }
|
|
|
}
|
|
|
return rows;
|
|
|
}
|
|
@@ -241,7 +259,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
* @param role 角色对象
|
|
|
*/
|
|
|
public int insertRoleDept(SysRole role) {
|
|
|
- int rows = 1;
|
|
|
+ int rows = 0;
|
|
|
// 新增角色与部门(数据权限)管理
|
|
|
List<SysRoleDept> list = new ArrayList<SysRoleDept>();
|
|
|
for (Long deptId : role.getDeptIds()) {
|
|
@@ -251,7 +269,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
list.add(rd);
|
|
|
}
|
|
|
if (list.size() > 0) {
|
|
|
- rows = roleDeptMapper.batchRoleDept(list);
|
|
|
+ for (SysRoleDept sysRoleDept : list) {
|
|
|
+ rows += roleDeptMapper.insert(sysRoleDept);
|
|
|
+ }
|
|
|
}
|
|
|
return rows;
|
|
|
}
|
|
@@ -266,10 +286,10 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
@Transactional
|
|
|
public int deleteRoleById(Long roleId) {
|
|
|
// 删除角色与菜单关联
|
|
|
- roleMenuMapper.deleteRoleMenuByRoleId(roleId);
|
|
|
+ roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, roleId));
|
|
|
// 删除角色与部门关联
|
|
|
- roleDeptMapper.deleteRoleDeptByRoleId(roleId);
|
|
|
- return roleMapper.deleteRoleById(roleId);
|
|
|
+ roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().eq(SysRoleDept::getRoleId, roleId));
|
|
|
+ return baseMapper.deleteById(roleId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -288,10 +308,11 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|
|
throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName()));
|
|
|
}
|
|
|
}
|
|
|
+ List<Long> ids = Arrays.asList(roleIds);
|
|
|
// 删除角色与菜单关联
|
|
|
- roleMenuMapper.deleteRoleMenu(roleIds);
|
|
|
+ roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, ids));
|
|
|
// 删除角色与部门关联
|
|
|
- roleDeptMapper.deleteRoleDept(roleIds);
|
|
|
- return roleMapper.deleteRoleByIds(roleIds);
|
|
|
+ roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().in(SysRoleDept::getRoleId, ids));
|
|
|
+ return baseMapper.deleteBatchIds(ids);
|
|
|
}
|
|
|
}
|