正在显示
7 个修改的文件
包含
107 行增加
和
6 行删除
@@ -89,7 +89,7 @@ public class PermssionController { | @@ -89,7 +89,7 @@ public class PermssionController { | ||
89 | } | 89 | } |
90 | return resultJson; | 90 | return resultJson; |
91 | } | 91 | } |
92 | - @LogAnnotation(moduleName = "权限管理",operate = "权限批量删除") | 92 | + @LogAnnotation(moduleName = "权限管理",operate = "查找权限") |
93 | @GetMapping("/findByRoleId") | 93 | @GetMapping("/findByRoleId") |
94 | public ResultJson findByRoleId(@RequestParam Integer roleId){ | 94 | public ResultJson findByRoleId(@RequestParam Integer roleId){ |
95 | 95 | ||
@@ -101,4 +101,10 @@ public class PermssionController { | @@ -101,4 +101,10 @@ public class PermssionController { | ||
101 | resultJson.setMsg("SUCCESS"); | 101 | resultJson.setMsg("SUCCESS"); |
102 | return resultJson; | 102 | return resultJson; |
103 | } | 103 | } |
104 | + | ||
105 | + @GetMapping("/flushPermCache") | ||
106 | + public ResultJson flushPermCache(){ | ||
107 | + permissionService.flushCache(); | ||
108 | + return new ResultJson("200","清理缓存成功"); | ||
109 | + } | ||
104 | } | 110 | } |
@@ -26,6 +26,13 @@ public interface PERMISSIONMapper { | @@ -26,6 +26,13 @@ public interface PERMISSIONMapper { | ||
26 | 26 | ||
27 | List<PERMISSION> findByUserId(Integer userId); | 27 | List<PERMISSION> findByUserId(Integer userId); |
28 | 28 | ||
29 | + /** | ||
30 | + * 登录验证成功后获取用户权限列表非树形结构 | ||
31 | + * @param userId | ||
32 | + * @return | ||
33 | + */ | ||
34 | + List<PERMISSION> findByUserIdWithLogin(Integer userId); | ||
35 | + | ||
29 | List<PERMISSION> findByRoleId(Integer roleId); | 36 | List<PERMISSION> findByRoleId(Integer roleId); |
30 | 37 | ||
31 | List<String> findRoleListByUrl(String permissionUrl); | 38 | List<String> findRoleListByUrl(String permissionUrl); |
1 | package com.tianbo.warehouse.model; | 1 | package com.tianbo.warehouse.model; |
2 | 2 | ||
3 | +import java.io.Serializable; | ||
3 | import java.util.List; | 4 | import java.util.List; |
4 | 5 | ||
5 | -public class PERMISSION { | 6 | +public class PERMISSION implements Serializable { |
7 | + | ||
8 | + private static final long serialVersionUID = 1L; | ||
9 | + | ||
6 | private Integer permissionId; | 10 | private Integer permissionId; |
7 | 11 | ||
8 | private String name; | 12 | private String name; |
@@ -27,4 +27,16 @@ public interface PermissionService { | @@ -27,4 +27,16 @@ public interface PermissionService { | ||
27 | int updateByPrimaryKeySelective(PERMISSION permission); | 27 | int updateByPrimaryKeySelective(PERMISSION permission); |
28 | 28 | ||
29 | int deleteByPrimaryKey(String companyId); | 29 | int deleteByPrimaryKey(String companyId); |
30 | + | ||
31 | + /** | ||
32 | + * 登录验证成功后获取用户权限列表非树形结构 | ||
33 | + * @param userId | ||
34 | + * @return | ||
35 | + */ | ||
36 | + List<PERMISSION> findByUserIdWithLogin(Integer userId); | ||
37 | + | ||
38 | + /** | ||
39 | + * 清理跟permission相关的所有缓存 | ||
40 | + */ | ||
41 | + void flushCache(); | ||
30 | } | 42 | } |
@@ -3,6 +3,9 @@ package com.tianbo.warehouse.service.imp; | @@ -3,6 +3,9 @@ package com.tianbo.warehouse.service.imp; | ||
3 | import com.github.pagehelper.Page; | 3 | import com.github.pagehelper.Page; |
4 | import com.github.pagehelper.PageHelper; | 4 | import com.github.pagehelper.PageHelper; |
5 | import com.github.pagehelper.PageInfo; | 5 | import com.github.pagehelper.PageInfo; |
6 | +import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheDelTarget; | ||
7 | +import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheEvict; | ||
8 | +import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheable; | ||
6 | import com.tianbo.warehouse.dao.PERMISSIONMapper; | 9 | import com.tianbo.warehouse.dao.PERMISSIONMapper; |
7 | import com.tianbo.warehouse.model.PERMISSION; | 10 | import com.tianbo.warehouse.model.PERMISSION; |
8 | import com.tianbo.warehouse.service.PermissionService; | 11 | import com.tianbo.warehouse.service.PermissionService; |
@@ -21,19 +24,23 @@ public class PermissionServiceImp implements PermissionService { | @@ -21,19 +24,23 @@ public class PermissionServiceImp implements PermissionService { | ||
21 | PERMISSIONMapper permissionMapper; | 24 | PERMISSIONMapper permissionMapper; |
22 | 25 | ||
23 | @Override | 26 | @Override |
27 | + @RedisCacheable(cacheKey = "findAllMenus") | ||
24 | public PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name) { | 28 | public PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name) { |
25 | Page<PERMISSION> page = PageHelper.startPage(pageNum, 0,true,true,true); | 29 | Page<PERMISSION> page = PageHelper.startPage(pageNum, 0,true,true,true); |
26 | List<PERMISSION> list = permissionMapper.findAll(name); | 30 | List<PERMISSION> list = permissionMapper.findAll(name); |
27 | PageInfo<PERMISSION> result = new PageInfo<>(getPermissionList(list, 0)); | 31 | PageInfo<PERMISSION> result = new PageInfo<>(getPermissionList(list, 0)); |
28 | return result; | 32 | return result; |
29 | } | 33 | } |
34 | + | ||
30 | @Override | 35 | @Override |
36 | + @RedisCacheable(cacheKey = "findByRoleId") | ||
31 | public List<PERMISSION> findByRoleId(Integer roleId) { | 37 | public List<PERMISSION> findByRoleId(Integer roleId) { |
32 | List<PERMISSION> list = getPermissionList(permissionMapper.findByRoleId(roleId), 0); | 38 | List<PERMISSION> list = getPermissionList(permissionMapper.findByRoleId(roleId), 0); |
33 | return list; | 39 | return list; |
34 | } | 40 | } |
35 | 41 | ||
36 | @Override | 42 | @Override |
43 | + @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") | ||
37 | public int insertSelective(PERMISSION record) { | 44 | public int insertSelective(PERMISSION record) { |
38 | return permissionMapper.insertSelective(record); | 45 | return permissionMapper.insertSelective(record); |
39 | } | 46 | } |
@@ -50,7 +57,25 @@ public class PermissionServiceImp implements PermissionService { | @@ -50,7 +57,25 @@ public class PermissionServiceImp implements PermissionService { | ||
50 | return permissionList; | 57 | return permissionList; |
51 | } | 58 | } |
52 | 59 | ||
60 | + /** | ||
61 | + * 登录验证成功后获取用户权限列表非树形结构,代表用户所能访问的所有权限。 | ||
62 | + * 最终存储redis,由gateway读取进行权限判定 | ||
63 | + * @param userId | ||
64 | + * @return | ||
65 | + */ | ||
66 | + @Override | ||
67 | + @RedisCacheable(cacheKey = "findByUserIdWithLogin") | ||
68 | + public List<PERMISSION> findByUserIdWithLogin(Integer userId){ | ||
69 | + return permissionMapper.findByUserIdWithLogin(userId); | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * 返回用户权限的树形列表 | ||
74 | + * @param userId | ||
75 | + * @return | ||
76 | + */ | ||
53 | @Override | 77 | @Override |
78 | + @RedisCacheable(cacheKey = "getUserMenusTree")//添加缓存 | ||
54 | public Map<String, Object> getUserMenus(Integer userId) { | 79 | public Map<String, Object> getUserMenus(Integer userId) { |
55 | Map<String, Object> data = new HashMap<String, Object>(); | 80 | Map<String, Object> data = new HashMap<String, Object>(); |
56 | try { | 81 | try { |
@@ -117,11 +142,18 @@ public class PermissionServiceImp implements PermissionService { | @@ -117,11 +142,18 @@ public class PermissionServiceImp implements PermissionService { | ||
117 | 142 | ||
118 | 143 | ||
119 | @Override | 144 | @Override |
145 | + @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") | ||
120 | public int updateByPrimaryKeySelective(PERMISSION permission) { | 146 | public int updateByPrimaryKeySelective(PERMISSION permission) { |
121 | return permissionMapper.updateByPrimaryKeySelective(permission); | 147 | return permissionMapper.updateByPrimaryKeySelective(permission); |
122 | } | 148 | } |
123 | 149 | ||
150 | + /** 批量删除 | ||
151 | + * | ||
152 | + * @param permissionId | ||
153 | + * @return | ||
154 | + */ | ||
124 | @Override | 155 | @Override |
156 | + @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") | ||
125 | public int deleteByPrimaryKey(String permissionId) { | 157 | public int deleteByPrimaryKey(String permissionId) { |
126 | if (permissionId.contains(",")) { | 158 | if (permissionId.contains(",")) { |
127 | try { | 159 | try { |
@@ -140,4 +172,10 @@ public class PermissionServiceImp implements PermissionService { | @@ -140,4 +172,10 @@ public class PermissionServiceImp implements PermissionService { | ||
140 | } | 172 | } |
141 | } | 173 | } |
142 | 174 | ||
175 | + @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") | ||
176 | + @Override | ||
177 | + public void flushCache(){ | ||
178 | + | ||
179 | + } | ||
180 | + | ||
143 | } | 181 | } |
@@ -11,6 +11,7 @@ import com.tianbo.warehouse.model.PERMISSION; | @@ -11,6 +11,7 @@ import com.tianbo.warehouse.model.PERMISSION; | ||
11 | import com.tianbo.warehouse.model.ROLE; | 11 | import com.tianbo.warehouse.model.ROLE; |
12 | import com.tianbo.warehouse.model.USERS; | 12 | import com.tianbo.warehouse.model.USERS; |
13 | import com.tianbo.warehouse.model.UserRole; | 13 | import com.tianbo.warehouse.model.UserRole; |
14 | +import com.tianbo.warehouse.service.PermissionService; | ||
14 | import com.tianbo.warehouse.service.UserService; | 15 | import com.tianbo.warehouse.service.UserService; |
15 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
16 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
@@ -26,15 +27,18 @@ public class UserServiceImpl implements UserService{ | @@ -26,15 +27,18 @@ public class UserServiceImpl implements UserService{ | ||
26 | @Resource | 27 | @Resource |
27 | private USERSMapper usersMapper; | 28 | private USERSMapper usersMapper; |
28 | 29 | ||
29 | - @Autowired | 30 | + @Resource |
30 | private ROLEMapper roleMapper; | 31 | private ROLEMapper roleMapper; |
31 | 32 | ||
32 | - @Autowired | 33 | + @Resource |
33 | private PERMISSIONMapper permissionMapper; | 34 | private PERMISSIONMapper permissionMapper; |
34 | 35 | ||
35 | - @Autowired | 36 | + @Resource |
36 | private UserRoleMapper userRoleMapper; | 37 | private UserRoleMapper userRoleMapper; |
37 | 38 | ||
39 | + @Autowired | ||
40 | + private PermissionService permissionService; | ||
41 | + | ||
38 | @Override | 42 | @Override |
39 | public USERS loadByUsername(String username){ | 43 | public USERS loadByUsername(String username){ |
40 | List<USERS> userList = usersMapper.selectByUsername(username); | 44 | List<USERS> userList = usersMapper.selectByUsername(username); |
@@ -42,7 +46,7 @@ public class UserServiceImpl implements UserService{ | @@ -42,7 +46,7 @@ public class UserServiceImpl implements UserService{ | ||
42 | if (userList != null && userList.size() > 0) { | 46 | if (userList != null && userList.size() > 0) { |
43 | USERS user = userList.get(0); | 47 | USERS user = userList.get(0); |
44 | 48 | ||
45 | - List<PERMISSION> permissionList = permissionMapper.findByUserId(user.getUserId()); | 49 | + List<PERMISSION> permissionList = permissionService.findByUserIdWithLogin(user.getUserId()); |
46 | if (permissionList!=null && permissionList.size()>0){ | 50 | if (permissionList!=null && permissionList.size()>0){ |
47 | user.setPermissions(permissionList); | 51 | user.setPermissions(permissionList); |
48 | } | 52 | } |
@@ -140,6 +140,36 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order | @@ -140,6 +140,36 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order | ||
140 | AND P.parent_id = 0 | 140 | AND P.parent_id = 0 |
141 | ORDER BY permission_order | 141 | ORDER BY permission_order |
142 | </select> | 142 | </select> |
143 | + <select id="findByUserIdWithLogin" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | ||
144 | + SELECT | ||
145 | + P.* | ||
146 | + FROM | ||
147 | + permission P | ||
148 | + WHERE | ||
149 | + P.permission_id IN ( | ||
150 | + SELECT | ||
151 | + RP.permission_id | ||
152 | + FROM | ||
153 | + role_permission RP | ||
154 | + WHERE | ||
155 | + RP.role_id IN ( | ||
156 | + SELECT | ||
157 | + R.role_id | ||
158 | + FROM | ||
159 | + role R | ||
160 | + WHERE | ||
161 | + R.role_id IN ( | ||
162 | + SELECT | ||
163 | + UR.role_id | ||
164 | + FROM | ||
165 | + user_role UR | ||
166 | + WHERE | ||
167 | + UR.user_id = #{userId,jdbcType=INTEGER} | ||
168 | + ) | ||
169 | + ) | ||
170 | + ) | ||
171 | + ORDER BY permission_order | ||
172 | + </select> | ||
143 | <select id="findByRoleId" resultMap="BaseResultMap" parameterType="integer"> | 173 | <select id="findByRoleId" resultMap="BaseResultMap" parameterType="integer"> |
144 | SELECT | 174 | SELECT |
145 | P.* | 175 | P.* |
-
请 注册 或 登录 后发表评论