update 优化 框架代码书写格式

This commit is contained in:
疯狂的狮子li 2023-01-30 18:22:25 +08:00
parent 2d7535012e
commit 7c05920e73
9 changed files with 32 additions and 37 deletions

View File

@ -112,7 +112,7 @@ public class SysRoleController extends BaseController {
// 更新缓存用户权限
LoginUser loginUser = getLoginUser();
SysUser sysUser = userService.selectUserById(loginUser.getUserId());
if (ObjectUtil.isNotNull(sysUser) && !sysUser.isAdmin()) {
if (ObjectUtil.isNotNull(sysUser) && !LoginHelper.isAdmin()) {
loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser));
LoginHelper.setLoginUser(loginUser);
}

View File

@ -2,7 +2,6 @@ package com.ruoyi.common.helper;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.model.LoginUser;
@ -15,11 +14,11 @@ import lombok.NoArgsConstructor;
/**
* 登录鉴权助手
*
* <p>
* user_type 用户类型 同一个用户表 可以有多种用户类型 例如 pc,app
* deivce 设备类型 同一个用户类型 可以有 多种设备类型 例如 web,ios
* 可以组成 用户类型与设备类型多对多的 权限灵活控制
*
* <p>
* 多用户体系 针对 多种用户类型 但权限控制不一致
* 可以组成 多用户类型表与多设备类型 分别控制权限
*

View File

@ -1,5 +1,6 @@
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.SysUser;
import lombok.RequiredArgsConstructor;
@ -28,7 +29,7 @@ public class SysPermissionService {
* @return 角色权限信息
*/
public Set<String> getRolePermission(SysUser user) {
Set<String> roles = new HashSet<String>();
Set<String> roles = new HashSet<>();
// 管理员拥有所有权限
if (user.isAdmin()) {
roles.add("admin");
@ -45,13 +46,13 @@ public class SysPermissionService {
* @return 菜单权限信息
*/
public Set<String> getMenuPermission(SysUser user) {
Set<String> perms = new HashSet<String>();
Set<String> perms = new HashSet<>();
// 管理员拥有所有权限
if (user.isAdmin()) {
perms.add("*:*:*");
} else {
List<SysRole> roles = user.getRoles();
if (!roles.isEmpty() && roles.size() > 1) {
if (CollUtil.isNotEmpty(roles)) {
// 多角色设置permissions属性以便数据权限匹配权限
for (SysRole role : roles) {
Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId());

View File

@ -205,9 +205,9 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
*/
@Override
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()));
if (ObjectUtil.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
if (ObjectUtil.isNotNull(info) && info.getConfigId() != configId) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;

View File

@ -259,7 +259,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
list.add(dept);
}
if (list.size() > 0) {
if (CollUtil.isNotEmpty(list)) {
baseMapper.updateBatchById(list);
}
}

View File

@ -153,7 +153,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/
@Override
public List<RouterVo> buildMenus(List<SysMenu> menus) {
List<RouterVo> routers = new LinkedList<RouterVo>();
List<RouterVo> routers = new LinkedList<>();
for (SysMenu menu : menus) {
RouterVo router = new RouterVo();
router.setHidden("1".equals(menu.getVisible()));
@ -169,7 +169,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
router.setChildren(buildMenus(cMenus));
} else if (isMenuFrame(menu)) {
router.setMeta(null);
List<RouterVo> childrenList = new ArrayList<RouterVo>();
List<RouterVo> childrenList = new ArrayList<>();
RouterVo children = new RouterVo();
children.setPath(menu.getPath());
children.setComponent(menu.getComponent());
@ -181,7 +181,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
router.setPath("/");
List<RouterVo> childrenList = new ArrayList<RouterVo>();
List<RouterVo> childrenList = new ArrayList<>();
RouterVo children = new RouterVo();
String routerPath = innerLinkReplaceEach(menu.getPath());
children.setPath(routerPath);
@ -394,7 +394,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @return String
*/
public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) {
List<SysMenu> returnList = new ArrayList<SysMenu>();
List<SysMenu> returnList = new ArrayList<>();
for (SysMenu t : list) {
// 根据传入的某个父节点ID,遍历该父节点的所有子节点
if (t.getParentId() == parentId) {
@ -433,7 +433,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
* 判断是否有子节点
*/
private boolean hasChild(List<SysMenu> list, SysMenu t) {
return getChildList(list, t).size() > 0;
return CollUtil.isNotEmpty(getChildList(list, t));
}
/**

View File

@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.StreamUtils;
import com.ruoyi.system.domain.SysRoleDept;
import com.ruoyi.system.domain.SysRoleMenu;
import com.ruoyi.system.domain.SysUserRole;
@ -397,14 +398,13 @@ public class SysRoleServiceImpl implements ISysRoleService {
public int insertAuthUsers(Long roleId, Long[] userIds) {
// 新增用户与角色管理
int rows = 1;
List<SysUserRole> list = new ArrayList<SysUserRole>();
for (Long userId : userIds) {
List<SysUserRole> list = StreamUtils.toList(Arrays.asList(userIds), userId -> {
SysUserRole ur = new SysUserRole();
ur.setUserId(userId);
ur.setRoleId(roleId);
list.add(ur);
}
if (list.size() > 0) {
return ur;
});
if (CollUtil.isNotEmpty(list)) {
rows = userRoleMapper.insertBatch(list) ? list.size() : 0;
}
return rows;

View File

@ -30,7 +30,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -211,7 +210,6 @@ public class SysUserServiceImpl implements ISysUserService {
* 校验手机号码是否唯一
*
* @param user 用户信息
* @return
*/
@Override
public String checkPhoneUnique(SysUser user) {
@ -228,7 +226,6 @@ public class SysUserServiceImpl implements ISysUserService {
* 校验email是否唯一
*
* @param user 用户信息
* @return
*/
@Override
public String checkEmailUnique(SysUser user) {
@ -417,13 +414,12 @@ public class SysUserServiceImpl implements ISysUserService {
Long[] posts = user.getPostIds();
if (ArrayUtil.isNotEmpty(posts)) {
// 新增用户与岗位管理
List<SysUserPost> list = new ArrayList<>(posts.length);
for (Long postId : posts) {
List<SysUserPost> list = StreamUtils.toList(Arrays.asList(posts), postId -> {
SysUserPost up = new SysUserPost();
up.setUserId(user.getUserId());
up.setPostId(postId);
list.add(up);
}
return up;
});
userPostMapper.insertBatch(list);
}
}
@ -437,13 +433,12 @@ public class SysUserServiceImpl implements ISysUserService {
public void insertUserRole(Long userId, Long[] roleIds) {
if (ArrayUtil.isNotEmpty(roleIds)) {
// 新增用户与角色管理
List<SysUserRole> list = new ArrayList<>(roleIds.length);
for (Long roleId : roleIds) {
List<SysUserRole> list = StreamUtils.toList(Arrays.asList(roleIds), roleId -> {
SysUserRole ur = new SysUserRole();
ur.setUserId(userId);
ur.setRoleId(roleId);
list.add(ur);
}
return ur;
});
userRoleMapper.insertBatch(list);
}
}

View File

@ -86,16 +86,16 @@
<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,
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
sys_user u
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 sys_user u
left join sys_dept d on u.dept_id = d.dept_id
${ew.getCustomSqlSegment}
</select>
<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,
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
sys_user u
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 sys_user u
left join sys_dept d on u.dept_id = d.dept_id
${ew.getCustomSqlSegment}
</select>