正在显示
7 个修改的文件
包含
126 行增加
和
21 行删除
| @@ -156,7 +156,7 @@ public class RedisCacheableAspect { | @@ -156,7 +156,7 @@ public class RedisCacheableAspect { | ||
| 156 | if(allEntries){ | 156 | if(allEntries){ |
| 157 | if(cacheKey!=null){ | 157 | if(cacheKey!=null){ |
| 158 | Long result = redisTemplate.delete(redisTemplate.keys(cacheKey+"*")); | 158 | Long result = redisTemplate.delete(redisTemplate.keys(cacheKey+"*")); |
| 159 | - log.info("已删除{}个缓存",result); | 159 | + log.info("已删除{}个缓存->{}*<-",result,cacheKey); |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | }catch (Exception e){ | 162 | }catch (Exception e){ |
| @@ -107,4 +107,11 @@ public class PermssionController { | @@ -107,4 +107,11 @@ public class PermssionController { | ||
| 107 | permissionService.flushCache(); | 107 | permissionService.flushCache(); |
| 108 | return new ResultJson("200","清理缓存成功"); | 108 | return new ResultJson("200","清理缓存成功"); |
| 109 | } | 109 | } |
| 110 | + | ||
| 111 | + @GetMapping("/userMenu") | ||
| 112 | + public ResultJson<List<PERMISSION>> userMenu( | ||
| 113 | + @RequestParam(value = "userId", required = true) Integer userId){ | ||
| 114 | + return new ResultJson<List<PERMISSION>>("200","success",permissionService.getUserMenuTreeByUserId(userId)); | ||
| 115 | + | ||
| 116 | + } | ||
| 110 | } | 117 | } |
| @@ -38,4 +38,8 @@ public interface PERMISSIONMapper { | @@ -38,4 +38,8 @@ public interface PERMISSIONMapper { | ||
| 38 | List<String> findRoleListByUrl(String permissionUrl); | 38 | List<String> findRoleListByUrl(String permissionUrl); |
| 39 | 39 | ||
| 40 | List<PERMISSION> getRolePermisson(Integer roleId); | 40 | List<PERMISSION> getRolePermisson(Integer roleId); |
| 41 | + | ||
| 42 | + List<PERMISSION> getUserMenuTreeByUserId(Integer userId); | ||
| 43 | + | ||
| 44 | + List<PERMISSION> getChildMenu(Integer parentId); | ||
| 41 | } | 45 | } |
| @@ -31,6 +31,10 @@ public class PERMISSION implements Serializable { | @@ -31,6 +31,10 @@ public class PERMISSION implements Serializable { | ||
| 31 | 31 | ||
| 32 | private String component; | 32 | private String component; |
| 33 | 33 | ||
| 34 | + private boolean hasChild; | ||
| 35 | + | ||
| 36 | + private boolean leaf; | ||
| 37 | + | ||
| 34 | private List<PERMISSION> children; | 38 | private List<PERMISSION> children; |
| 35 | 39 | ||
| 36 | public Integer getPermissionId() { | 40 | public Integer getPermissionId() { |
| @@ -65,10 +69,6 @@ public class PERMISSION implements Serializable { | @@ -65,10 +69,6 @@ public class PERMISSION implements Serializable { | ||
| 65 | return ismenu; | 69 | return ismenu; |
| 66 | } | 70 | } |
| 67 | 71 | ||
| 68 | - public void setIsmenu(String ismenu) { | ||
| 69 | - this.ismenu = "0".equals(ismenu)?false:true ; | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | public Integer getParentId() { | 72 | public Integer getParentId() { |
| 73 | return parentId; | 73 | return parentId; |
| 74 | } | 74 | } |
| @@ -122,6 +122,45 @@ public class PERMISSION implements Serializable { | @@ -122,6 +122,45 @@ public class PERMISSION implements Serializable { | ||
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | public void setChildren(List<PERMISSION> children) { | 124 | public void setChildren(List<PERMISSION> children) { |
| 125 | + if (children.isEmpty()){ | ||
| 126 | + this.leaf = true; | ||
| 127 | + this.hasChild = false; | ||
| 128 | + }else { | ||
| 129 | + this.leaf = false; | ||
| 130 | + this.hasChild = true; | ||
| 131 | + } | ||
| 125 | this.children = children; | 132 | this.children = children; |
| 126 | } | 133 | } |
| 127 | -} | ||
| 134 | + | ||
| 135 | + public void setPermissionId(Integer permissionId) { | ||
| 136 | + this.permissionId = permissionId; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + public void setIsmenu(Boolean ismenu) { | ||
| 140 | + this.ismenu = ismenu; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + public Boolean getHidden() { | ||
| 144 | + return hidden; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + public void setHidden(Boolean hidden) { | ||
| 148 | + this.hidden = hidden; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + public boolean isHasChild() { | ||
| 152 | + return hasChild; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + public void setHasChild(boolean hasChild) { | ||
| 156 | + this.hasChild = hasChild; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + public boolean isLeaf() { | ||
| 160 | + return leaf; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + public void setLeaf(boolean leaf) { | ||
| 164 | + this.leaf = leaf; | ||
| 165 | + } | ||
| 166 | +} |
| @@ -39,4 +39,11 @@ public interface PermissionService { | @@ -39,4 +39,11 @@ public interface PermissionService { | ||
| 39 | * 清理跟permission相关的所有缓存 | 39 | * 清理跟permission相关的所有缓存 |
| 40 | */ | 40 | */ |
| 41 | void flushCache(); | 41 | void flushCache(); |
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 用户菜单树形 | ||
| 45 | + * @param userId | ||
| 46 | + * @return | ||
| 47 | + */ | ||
| 48 | + List<PERMISSION> getUserMenuTreeByUserId(Integer userId); | ||
| 42 | } | 49 | } |
| @@ -9,6 +9,7 @@ import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheable; | @@ -9,6 +9,7 @@ import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheable; | ||
| 9 | import com.tianbo.warehouse.dao.PERMISSIONMapper; | 9 | import com.tianbo.warehouse.dao.PERMISSIONMapper; |
| 10 | import com.tianbo.warehouse.model.PERMISSION; | 10 | import com.tianbo.warehouse.model.PERMISSION; |
| 11 | import com.tianbo.warehouse.service.PermissionService; | 11 | import com.tianbo.warehouse.service.PermissionService; |
| 12 | +import lombok.extern.slf4j.Slf4j; | ||
| 12 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 13 | 14 | ||
| 14 | import javax.annotation.Resource; | 15 | import javax.annotation.Resource; |
| @@ -17,6 +18,7 @@ import java.util.HashMap; | @@ -17,6 +18,7 @@ import java.util.HashMap; | ||
| 17 | import java.util.List; | 18 | import java.util.List; |
| 18 | import java.util.Map; | 19 | import java.util.Map; |
| 19 | 20 | ||
| 21 | +@Slf4j | ||
| 20 | @Service("PermissionService") | 22 | @Service("PermissionService") |
| 21 | public class PermissionServiceImp implements PermissionService { | 23 | public class PermissionServiceImp implements PermissionService { |
| 22 | 24 | ||
| @@ -39,8 +41,8 @@ public class PermissionServiceImp implements PermissionService { | @@ -39,8 +41,8 @@ public class PermissionServiceImp implements PermissionService { | ||
| 39 | return list; | 41 | return list; |
| 40 | } | 42 | } |
| 41 | 43 | ||
| 42 | - @Override | ||
| 43 | @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") | 44 | @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") |
| 45 | + @Override | ||
| 44 | public int insertSelective(PERMISSION record) { | 46 | public int insertSelective(PERMISSION record) { |
| 45 | return permissionMapper.insertSelective(record); | 47 | return permissionMapper.insertSelective(record); |
| 46 | } | 48 | } |
| @@ -152,8 +154,8 @@ public class PermissionServiceImp implements PermissionService { | @@ -152,8 +154,8 @@ public class PermissionServiceImp implements PermissionService { | ||
| 152 | * @param permissionId | 154 | * @param permissionId |
| 153 | * @return | 155 | * @return |
| 154 | */ | 156 | */ |
| 155 | - @Override | ||
| 156 | @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") | 157 | @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") |
| 158 | + @Override | ||
| 157 | public int deleteByPrimaryKey(String permissionId) { | 159 | public int deleteByPrimaryKey(String permissionId) { |
| 158 | if (permissionId.contains(",")) { | 160 | if (permissionId.contains(",")) { |
| 159 | try { | 161 | try { |
| @@ -175,7 +177,13 @@ public class PermissionServiceImp implements PermissionService { | @@ -175,7 +177,13 @@ public class PermissionServiceImp implements PermissionService { | ||
| 175 | @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") | 177 | @RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp") |
| 176 | @Override | 178 | @Override |
| 177 | public void flushCache(){ | 179 | public void flushCache(){ |
| 180 | + log.info("删除缓存"); | ||
| 181 | + } | ||
| 178 | 182 | ||
| 183 | + @Override | ||
| 184 | + @RedisCacheable(cacheKey = "getUserMenuTreeByUserId") | ||
| 185 | + public List<PERMISSION> getUserMenuTreeByUserId(Integer userId) { | ||
| 186 | + return permissionMapper.getUserMenuTreeByUserId(userId); | ||
| 179 | } | 187 | } |
| 180 | 188 | ||
| 181 | } | 189 | } |
| @@ -15,22 +15,14 @@ | @@ -15,22 +15,14 @@ | ||
| 15 | <result column="iconCls" property="iconCls" jdbcType="VARCHAR" /> | 15 | <result column="iconCls" property="iconCls" jdbcType="VARCHAR" /> |
| 16 | <result column="component" property="component" jdbcType="VARCHAR" /> | 16 | <result column="component" property="component" jdbcType="VARCHAR" /> |
| 17 | </resultMap> | 17 | </resultMap> |
| 18 | - <resultMap id="treeResultMap" type="com.tianbo.warehouse.model.PERMISSION" > | ||
| 19 | - <id column="permission_id" property="permissionId" jdbcType="INTEGER" /> | ||
| 20 | - <result column="name" property="name" jdbcType="VARCHAR" /> | ||
| 21 | - <result column="permission_order" property="permissionOrder" jdbcType="VARCHAR" /> | ||
| 22 | - <result column="description" property="description" jdbcType="VARCHAR" /> | ||
| 23 | - <result column="ismenu" property="ismenu" jdbcType="BOOLEAN" /> | ||
| 24 | - <result column="hidden" property="hidden" jdbcType="BOOLEAN" /> | ||
| 25 | - <result column="parent_id" property="parentId" jdbcType="INTEGER" /> | ||
| 26 | - <result column="path" property="path" jdbcType="VARCHAR" /> | ||
| 27 | - <result column="url" property="url" jdbcType="VARCHAR" /> | ||
| 28 | - <result column="method" property="method" jdbcType="VARCHAR" /> | ||
| 29 | - <result column="iconCls" property="iconCls" jdbcType="VARCHAR" /> | ||
| 30 | - <result column="component" property="component" jdbcType="VARCHAR" /> | 18 | + <resultMap id="treeResultMap" type="com.tianbo.warehouse.model.PERMISSION" extends="BaseResultMap"> |
| 31 | <collection property="children" column="permission_id" javaType="java.util.ArrayList" ofType="com.tianbo.warehouse.model.PERMISSION" select="selectByParentId"> | 19 | <collection property="children" column="permission_id" javaType="java.util.ArrayList" ofType="com.tianbo.warehouse.model.PERMISSION" select="selectByParentId"> |
| 32 | </collection> | 20 | </collection> |
| 33 | </resultMap> | 21 | </resultMap> |
| 22 | + <resultMap id="treeMap" type="com.tianbo.warehouse.model.PERMISSION" extends="BaseResultMap"> | ||
| 23 | + <collection property="children" column="permission_id" javaType="java.util.ArrayList" ofType="com.tianbo.warehouse.model.PERMISSION" select="getChildMenu"> | ||
| 24 | + </collection> | ||
| 25 | + </resultMap> | ||
| 34 | <sql id="Base_Column_List" > | 26 | <sql id="Base_Column_List" > |
| 35 | permission_id, name, permission_order, description, ismenu,hidden,parent_id, | 27 | permission_id, name, permission_order, description, ismenu,hidden,parent_id, |
| 36 | path, url, method, iconCls, component | 28 | path, url, method, iconCls, component |
| @@ -332,4 +324,52 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order | @@ -332,4 +324,52 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order | ||
| 332 | component = #{component,jdbcType=VARCHAR} | 324 | component = #{component,jdbcType=VARCHAR} |
| 333 | where permission_id = #{permissionId,jdbcType=INTEGER} | 325 | where permission_id = #{permissionId,jdbcType=INTEGER} |
| 334 | </update> | 326 | </update> |
| 327 | + | ||
| 328 | + <select id="getUserMenuTreeByUserId" parameterType="java.lang.Integer" resultMap="treeMap"> | ||
| 329 | + SELECT | ||
| 330 | + P.* | ||
| 331 | + FROM | ||
| 332 | + permission P | ||
| 333 | + WHERE | ||
| 334 | + parent_id = 0 | ||
| 335 | + AND | ||
| 336 | + ismenu = 1 | ||
| 337 | + AND | ||
| 338 | + P.permission_id IN ( | ||
| 339 | + SELECT | ||
| 340 | + RP.permission_id | ||
| 341 | + FROM | ||
| 342 | + role_permission RP | ||
| 343 | + WHERE | ||
| 344 | + RP.role_id IN ( | ||
| 345 | + SELECT | ||
| 346 | + R.role_id | ||
| 347 | + FROM | ||
| 348 | + role R | ||
| 349 | + WHERE | ||
| 350 | + R.role_id IN ( | ||
| 351 | + SELECT | ||
| 352 | + UR.role_id | ||
| 353 | + FROM | ||
| 354 | + user_role UR | ||
| 355 | + WHERE | ||
| 356 | + UR.user_id = #{userId,jdbcType=INTEGER} | ||
| 357 | + ) | ||
| 358 | + ) | ||
| 359 | + ) | ||
| 360 | + ORDER BY | ||
| 361 | + permission_order | ||
| 362 | + </select> | ||
| 363 | + <select id="getChildMenu" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | ||
| 364 | + SELECT | ||
| 365 | + * | ||
| 366 | + FROM | ||
| 367 | + permission | ||
| 368 | + WHERE | ||
| 369 | + ismenu = 1 | ||
| 370 | + AND | ||
| 371 | + parent_id = #{parentId,jdbcType=INTEGER} | ||
| 372 | + ORDER BY | ||
| 373 | + permission_order | ||
| 374 | + </select> | ||
| 335 | </mapper> | 375 | </mapper> |
-
请 注册 或 登录 后发表评论