Browse Source

登出功能添加清空用户缓存逻辑

macro 11 months ago
parent
commit
215bc0e4fd

+ 2 - 1
mall-admin/src/main/java/com/macro/mall/controller/UmsAdminController.java

@@ -108,7 +108,8 @@ public class UmsAdminController {
     @ApiOperation(value = "登出功能")
     @RequestMapping(value = "/logout", method = RequestMethod.POST)
     @ResponseBody
-    public CommonResult logout() {
+    public CommonResult logout(Principal principal) {
+        adminService.logout(principal.getName());
         return CommonResult.success(null);
     }
 

+ 6 - 0
mall-admin/src/main/java/com/macro/mall/service/UmsAdminService.java

@@ -89,4 +89,10 @@ public interface UmsAdminService {
      * 获取缓存服务
      */
     UmsAdminCacheService getCacheService();
+
+    /**
+     * 登出功能
+     * @param username 用户名
+     */
+    void logout(String username);
 }

+ 8 - 0
mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java

@@ -276,4 +276,12 @@ public class UmsAdminServiceImpl implements UmsAdminService {
     public UmsAdminCacheService getCacheService() {
         return SpringUtil.getBean(UmsAdminCacheService.class);
     }
+
+    @Override
+    public void logout(String username) {
+        //清空缓存中的用户相关数据
+        UmsAdmin admin = getCacheService().getAdmin(username);
+        getCacheService().delAdmin(admin.getId());
+        getCacheService().delResourceList(admin.getId());
+    }
 }