update 优化 框架代码书写格式
This commit is contained in:
parent
2d7535012e
commit
7c05920e73
|
@ -112,7 +112,7 @@ public class SysRoleController extends BaseController {
|
||||||
// 更新缓存用户权限
|
// 更新缓存用户权限
|
||||||
LoginUser loginUser = getLoginUser();
|
LoginUser loginUser = getLoginUser();
|
||||||
SysUser sysUser = userService.selectUserById(loginUser.getUserId());
|
SysUser sysUser = userService.selectUserById(loginUser.getUserId());
|
||||||
if (ObjectUtil.isNotNull(sysUser) && !sysUser.isAdmin()) {
|
if (ObjectUtil.isNotNull(sysUser) && !LoginHelper.isAdmin()) {
|
||||||
loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser));
|
loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser));
|
||||||
LoginHelper.setLoginUser(loginUser);
|
LoginHelper.setLoginUser(loginUser);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.ruoyi.common.helper;
|
||||||
|
|
||||||
import cn.dev33.satoken.context.SaHolder;
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
|
@ -15,11 +14,11 @@ import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录鉴权助手
|
* 登录鉴权助手
|
||||||
*
|
* <p>
|
||||||
* user_type 为 用户类型 同一个用户表 可以有多种用户类型 例如 pc,app
|
* user_type 为 用户类型 同一个用户表 可以有多种用户类型 例如 pc,app
|
||||||
* deivce 为 设备类型 同一个用户类型 可以有 多种设备类型 例如 web,ios
|
* deivce 为 设备类型 同一个用户类型 可以有 多种设备类型 例如 web,ios
|
||||||
* 可以组成 用户类型与设备类型多对多的 权限灵活控制
|
* 可以组成 用户类型与设备类型多对多的 权限灵活控制
|
||||||
*
|
* <p>
|
||||||
* 多用户体系 针对 多种用户类型 但权限控制不一致
|
* 多用户体系 针对 多种用户类型 但权限控制不一致
|
||||||
* 可以组成 多用户类型表与多设备类型 分别控制权限
|
* 可以组成 多用户类型表与多设备类型 分别控制权限
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ruoyi.system.service;
|
package com.ruoyi.system.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
@ -28,7 +29,7 @@ public class SysPermissionService {
|
||||||
* @return 角色权限信息
|
* @return 角色权限信息
|
||||||
*/
|
*/
|
||||||
public Set<String> getRolePermission(SysUser user) {
|
public Set<String> getRolePermission(SysUser user) {
|
||||||
Set<String> roles = new HashSet<String>();
|
Set<String> roles = new HashSet<>();
|
||||||
// 管理员拥有所有权限
|
// 管理员拥有所有权限
|
||||||
if (user.isAdmin()) {
|
if (user.isAdmin()) {
|
||||||
roles.add("admin");
|
roles.add("admin");
|
||||||
|
@ -45,13 +46,13 @@ public class SysPermissionService {
|
||||||
* @return 菜单权限信息
|
* @return 菜单权限信息
|
||||||
*/
|
*/
|
||||||
public Set<String> getMenuPermission(SysUser user) {
|
public Set<String> getMenuPermission(SysUser user) {
|
||||||
Set<String> perms = new HashSet<String>();
|
Set<String> perms = new HashSet<>();
|
||||||
// 管理员拥有所有权限
|
// 管理员拥有所有权限
|
||||||
if (user.isAdmin()) {
|
if (user.isAdmin()) {
|
||||||
perms.add("*:*:*");
|
perms.add("*:*:*");
|
||||||
} else {
|
} else {
|
||||||
List<SysRole> roles = user.getRoles();
|
List<SysRole> roles = user.getRoles();
|
||||||
if (!roles.isEmpty() && roles.size() > 1) {
|
if (CollUtil.isNotEmpty(roles)) {
|
||||||
// 多角色设置permissions属性,以便数据权限匹配权限
|
// 多角色设置permissions属性,以便数据权限匹配权限
|
||||||
for (SysRole role : roles) {
|
for (SysRole role : roles) {
|
||||||
Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId());
|
Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId());
|
||||||
|
|
|
@ -205,9 +205,9 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String checkConfigKeyUnique(SysConfig config) {
|
public String checkConfigKeyUnique(SysConfig config) {
|
||||||
Long configId = ObjectUtil.isNull(config.getConfigId()) ? -1L : config.getConfigId();
|
long configId = ObjectUtil.isNull(config.getConfigId()) ? -1L : config.getConfigId();
|
||||||
SysConfig info = baseMapper.selectOne(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getConfigKey, config.getConfigKey()));
|
SysConfig info = baseMapper.selectOne(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getConfigKey, config.getConfigKey()));
|
||||||
if (ObjectUtil.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
|
if (ObjectUtil.isNotNull(info) && info.getConfigId() != configId) {
|
||||||
return UserConstants.NOT_UNIQUE;
|
return UserConstants.NOT_UNIQUE;
|
||||||
}
|
}
|
||||||
return UserConstants.UNIQUE;
|
return UserConstants.UNIQUE;
|
||||||
|
|
|
@ -259,7 +259,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||||
dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
||||||
list.add(dept);
|
list.add(dept);
|
||||||
}
|
}
|
||||||
if (list.size() > 0) {
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
baseMapper.updateBatchById(list);
|
baseMapper.updateBatchById(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<RouterVo> buildMenus(List<SysMenu> menus) {
|
public List<RouterVo> buildMenus(List<SysMenu> menus) {
|
||||||
List<RouterVo> routers = new LinkedList<RouterVo>();
|
List<RouterVo> routers = new LinkedList<>();
|
||||||
for (SysMenu menu : menus) {
|
for (SysMenu menu : menus) {
|
||||||
RouterVo router = new RouterVo();
|
RouterVo router = new RouterVo();
|
||||||
router.setHidden("1".equals(menu.getVisible()));
|
router.setHidden("1".equals(menu.getVisible()));
|
||||||
|
@ -169,7 +169,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||||
router.setChildren(buildMenus(cMenus));
|
router.setChildren(buildMenus(cMenus));
|
||||||
} else if (isMenuFrame(menu)) {
|
} else if (isMenuFrame(menu)) {
|
||||||
router.setMeta(null);
|
router.setMeta(null);
|
||||||
List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
List<RouterVo> childrenList = new ArrayList<>();
|
||||||
RouterVo children = new RouterVo();
|
RouterVo children = new RouterVo();
|
||||||
children.setPath(menu.getPath());
|
children.setPath(menu.getPath());
|
||||||
children.setComponent(menu.getComponent());
|
children.setComponent(menu.getComponent());
|
||||||
|
@ -181,7 +181,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||||
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
|
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
|
||||||
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
||||||
router.setPath("/");
|
router.setPath("/");
|
||||||
List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
List<RouterVo> childrenList = new ArrayList<>();
|
||||||
RouterVo children = new RouterVo();
|
RouterVo children = new RouterVo();
|
||||||
String routerPath = innerLinkReplaceEach(menu.getPath());
|
String routerPath = innerLinkReplaceEach(menu.getPath());
|
||||||
children.setPath(routerPath);
|
children.setPath(routerPath);
|
||||||
|
@ -394,7 +394,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) {
|
public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) {
|
||||||
List<SysMenu> returnList = new ArrayList<SysMenu>();
|
List<SysMenu> returnList = new ArrayList<>();
|
||||||
for (SysMenu t : list) {
|
for (SysMenu t : list) {
|
||||||
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
||||||
if (t.getParentId() == parentId) {
|
if (t.getParentId() == parentId) {
|
||||||
|
@ -433,7 +433,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||||
* 判断是否有子节点
|
* 判断是否有子节点
|
||||||
*/
|
*/
|
||||||
private boolean hasChild(List<SysMenu> list, SysMenu t) {
|
private boolean hasChild(List<SysMenu> list, SysMenu t) {
|
||||||
return getChildList(list, t).size() > 0;
|
return CollUtil.isNotEmpty(getChildList(list, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.entity.SysRole;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.helper.LoginHelper;
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
|
import com.ruoyi.common.utils.StreamUtils;
|
||||||
import com.ruoyi.system.domain.SysRoleDept;
|
import com.ruoyi.system.domain.SysRoleDept;
|
||||||
import com.ruoyi.system.domain.SysRoleMenu;
|
import com.ruoyi.system.domain.SysRoleMenu;
|
||||||
import com.ruoyi.system.domain.SysUserRole;
|
import com.ruoyi.system.domain.SysUserRole;
|
||||||
|
@ -397,14 +398,13 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||||
public int insertAuthUsers(Long roleId, Long[] userIds) {
|
public int insertAuthUsers(Long roleId, Long[] userIds) {
|
||||||
// 新增用户与角色管理
|
// 新增用户与角色管理
|
||||||
int rows = 1;
|
int rows = 1;
|
||||||
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
List<SysUserRole> list = StreamUtils.toList(Arrays.asList(userIds), userId -> {
|
||||||
for (Long userId : userIds) {
|
|
||||||
SysUserRole ur = new SysUserRole();
|
SysUserRole ur = new SysUserRole();
|
||||||
ur.setUserId(userId);
|
ur.setUserId(userId);
|
||||||
ur.setRoleId(roleId);
|
ur.setRoleId(roleId);
|
||||||
list.add(ur);
|
return ur;
|
||||||
}
|
});
|
||||||
if (list.size() > 0) {
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
rows = userRoleMapper.insertBatch(list) ? list.size() : 0;
|
rows = userRoleMapper.insertBatch(list) ? list.size() : 0;
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
|
|
|
@ -30,7 +30,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -211,7 +210,6 @@ public class SysUserServiceImpl implements ISysUserService {
|
||||||
* 校验手机号码是否唯一
|
* 校验手机号码是否唯一
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String checkPhoneUnique(SysUser user) {
|
public String checkPhoneUnique(SysUser user) {
|
||||||
|
@ -228,7 +226,6 @@ public class SysUserServiceImpl implements ISysUserService {
|
||||||
* 校验email是否唯一
|
* 校验email是否唯一
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String checkEmailUnique(SysUser user) {
|
public String checkEmailUnique(SysUser user) {
|
||||||
|
@ -417,13 +414,12 @@ public class SysUserServiceImpl implements ISysUserService {
|
||||||
Long[] posts = user.getPostIds();
|
Long[] posts = user.getPostIds();
|
||||||
if (ArrayUtil.isNotEmpty(posts)) {
|
if (ArrayUtil.isNotEmpty(posts)) {
|
||||||
// 新增用户与岗位管理
|
// 新增用户与岗位管理
|
||||||
List<SysUserPost> list = new ArrayList<>(posts.length);
|
List<SysUserPost> list = StreamUtils.toList(Arrays.asList(posts), postId -> {
|
||||||
for (Long postId : posts) {
|
|
||||||
SysUserPost up = new SysUserPost();
|
SysUserPost up = new SysUserPost();
|
||||||
up.setUserId(user.getUserId());
|
up.setUserId(user.getUserId());
|
||||||
up.setPostId(postId);
|
up.setPostId(postId);
|
||||||
list.add(up);
|
return up;
|
||||||
}
|
});
|
||||||
userPostMapper.insertBatch(list);
|
userPostMapper.insertBatch(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -437,13 +433,12 @@ public class SysUserServiceImpl implements ISysUserService {
|
||||||
public void insertUserRole(Long userId, Long[] roleIds) {
|
public void insertUserRole(Long userId, Long[] roleIds) {
|
||||||
if (ArrayUtil.isNotEmpty(roleIds)) {
|
if (ArrayUtil.isNotEmpty(roleIds)) {
|
||||||
// 新增用户与角色管理
|
// 新增用户与角色管理
|
||||||
List<SysUserRole> list = new ArrayList<>(roleIds.length);
|
List<SysUserRole> list = StreamUtils.toList(Arrays.asList(roleIds), roleId -> {
|
||||||
for (Long roleId : roleIds) {
|
|
||||||
SysUserRole ur = new SysUserRole();
|
SysUserRole ur = new SysUserRole();
|
||||||
ur.setUserId(userId);
|
ur.setUserId(userId);
|
||||||
ur.setRoleId(roleId);
|
ur.setRoleId(roleId);
|
||||||
list.add(ur);
|
return ur;
|
||||||
}
|
});
|
||||||
userRoleMapper.insertBatch(list);
|
userRoleMapper.insertBatch(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,17 +86,17 @@
|
||||||
|
|
||||||
<select id="selectPageUserList" resultMap="SysUserResult">
|
<select id="selectPageUserList" resultMap="SysUserResult">
|
||||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex,
|
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex,
|
||||||
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from
|
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader
|
||||||
sys_user u
|
from sys_user u
|
||||||
left join sys_dept d on u.dept_id = d.dept_id
|
left join sys_dept d on u.dept_id = d.dept_id
|
||||||
${ew.getCustomSqlSegment}
|
${ew.getCustomSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectUserList" resultMap="SysUserResult">
|
<select id="selectUserList" resultMap="SysUserResult">
|
||||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex,
|
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex,
|
||||||
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from
|
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader
|
||||||
sys_user u
|
from sys_user u
|
||||||
left join sys_dept d on u.dept_id = d.dept_id
|
left join sys_dept d on u.dept_id = d.dept_id
|
||||||
${ew.getCustomSqlSegment}
|
${ew.getCustomSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue