From aead5602277e53ecff63cf3c69a11e2461b23164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Thu, 19 Aug 2021 11:13:59 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=9D=83=E9=99=90=E5=B7=A5=E5=85=B7=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysLoginController.java | 9 +-------- .../controller/system/SysProfileController.java | 17 ++++++++--------- .../controller/system/SysRoleController.java | 3 +-- .../controller/system/SysUserController.java | 9 +-------- .../framework/aspectj/DataScopeAspect.java | 6 ++---- .../com/ruoyi/framework/aspectj/LogAspect.java | 5 ++--- .../web/service/PermissionService.java | 14 +++++--------- 7 files changed, 20 insertions(+), 43 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index a223f0f..dab2bf8 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -12,12 +12,9 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginBody; -import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.framework.web.service.SysLoginService; import com.ruoyi.framework.web.service.SysPermissionService; -import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.service.ISysMenuService; /** @@ -37,9 +34,6 @@ public class SysLoginController @Autowired private SysPermissionService permissionService; - @Autowired - private TokenService tokenService; - /** * 登录方法 * @@ -65,8 +59,7 @@ public class SysLoginController @GetMapping("getInfo") public AjaxResult getInfo() { - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); - SysUser user = loginUser.getUser(); + SysUser user = SecurityUtils.getLoginUser().getUser(); // 角色集合 Set roles = permissionService.getRolePermission(user); // 权限集合 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java index 899c60e..227ac87 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java @@ -19,7 +19,6 @@ import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.framework.web.service.TokenService; @@ -46,7 +45,7 @@ public class SysProfileController extends BaseController @GetMapping public AjaxResult profile() { - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); SysUser user = loginUser.getUser(); AjaxResult ajax = AjaxResult.success(user); ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); @@ -71,17 +70,17 @@ public class SysProfileController extends BaseController { return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); SysUser sysUser = loginUser.getUser(); user.setUserId(sysUser.getUserId()); user.setPassword(null); if (userService.updateUserProfile(user) > 0) { // 更新缓存用户信息 - loginUser.getUser().setNickName(user.getNickName()); - loginUser.getUser().setPhonenumber(user.getPhonenumber()); - loginUser.getUser().setEmail(user.getEmail()); - loginUser.getUser().setSex(user.getSex()); + sysUser.setNickName(user.getNickName()); + sysUser.setPhonenumber(user.getPhonenumber()); + sysUser.setEmail(user.getEmail()); + sysUser.setSex(user.getSex()); tokenService.setLoginUser(loginUser); return AjaxResult.success(); } @@ -95,7 +94,7 @@ public class SysProfileController extends BaseController @PutMapping("/updatePwd") public AjaxResult updatePwd(String oldPassword, String newPassword) { - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); String userName = loginUser.getUsername(); String password = loginUser.getPassword(); if (!SecurityUtils.matchesPassword(oldPassword, password)) @@ -125,7 +124,7 @@ public class SysProfileController extends BaseController { if (!file.isEmpty()) { - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file); if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) { diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java index 4680b67..2870f66 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java @@ -21,7 +21,6 @@ import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.web.service.SysPermissionService; @@ -123,7 +122,7 @@ public class SysRoleController extends BaseController if (roleService.updateRole(role) > 0) { // 更新缓存用户权限 - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) { loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java index 047f2e9..e5469ec 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java @@ -21,14 +21,11 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.service.ISysPostService; import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysUserService; @@ -51,9 +48,6 @@ public class SysUserController extends BaseController @Autowired private ISysPostService postService; - @Autowired - private TokenService tokenService; - /** * 获取用户列表 */ @@ -83,8 +77,7 @@ public class SysUserController extends BaseController { ExcelUtil util = new ExcelUtil(SysUser.class); List userList = util.importExcel(file.getInputStream()); - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); - String operName = loginUser.getUsername(); + String operName = getUsername(); String message = userService.importUser(userList, updateSupport, operName); return AjaxResult.success(message); } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java index e988430..e4340d0 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java @@ -13,10 +13,8 @@ import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.spring.SpringUtils; -import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.common.utils.SecurityUtils; /** * 数据过滤处理 @@ -79,7 +77,7 @@ public class DataScopeAspect return; } // 获取当前的用户 - LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNotNull(loginUser)) { SysUser currentUser = loginUser.getUser(); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java index 18500ab..b7cf17b 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java @@ -27,10 +27,9 @@ import com.ruoyi.common.enums.HttpMethod; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.IpUtils; -import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.framework.manager.AsyncManager; import com.ruoyi.framework.manager.factory.AsyncFactory; -import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.domain.SysOperLog; /** @@ -85,7 +84,7 @@ public class LogAspect } // 获取当前的用户 - LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); // *========数据库日志=========*// SysOperLog operLog = new SysOperLog(); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/PermissionService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/PermissionService.java index 003c794..3881053 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/PermissionService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/PermissionService.java @@ -1,12 +1,11 @@ package com.ruoyi.framework.web.service; import java.util.Set; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; /** @@ -27,9 +26,6 @@ public class PermissionService private static final String PERMISSION_DELIMETER = ","; - @Autowired - private TokenService tokenService; - /** * 验证用户是否具备某权限 * @@ -42,7 +38,7 @@ public class PermissionService { return false; } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) { return false; @@ -73,7 +69,7 @@ public class PermissionService { return false; } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) { return false; @@ -101,7 +97,7 @@ public class PermissionService { return false; } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) { return false; @@ -140,7 +136,7 @@ public class PermissionService { return false; } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) { return false;