| | |
| | | package com.moon.server.controller.all; |
| | | |
| | | import com.moon.server.annotation.SysLog; |
| | | import com.moon.server.entity.sys.LayerEntity; |
| | | import com.moon.server.entity.sys.MenuEntity; |
| | | import com.moon.server.entity.sys.ResEntity; |
| | | import com.moon.server.entity.sys.UserEntity; |
| | |
| | | |
| | | @Autowired |
| | | LayerService layerService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询当前用户的资源授权") |
| | | @GetMapping(value = "/selectLayers") |
| | | public ResponseMsg<Object> selectLayers(HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("用户未登录", null); |
| | | } |
| | | |
| | | String uid = StaticData.ADMIN.equals(ue.getUid()) ? null : ue.getUid(); |
| | | List<LayerEntity> rs = layerService.selectLayers(uid); |
| | | |
| | | return success(rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询当前用户的资源授权") |
| | |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | /*@SysLog() |
| | | @ApiOperation(value = "查询所有图层") |
| | | @GetMapping(value = "/selectLayers") |
| | | public ResponseMsg<Object> selectLayers(HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("用户未登录", null); |
| | | } |
| | | |
| | | List<LayerEntity> list = layerService.selectAll(); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | }*/ |
| | | } |
| | |
| | | PermsService permsService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据角色ID查询资源") |
| | | @ApiOperation(value = "根据角色ID查询图层") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "roleid", value = "角色ID", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | |
| | | package com.moon.server.entity.sys; |
| | | |
| | | import io.swagger.models.auth.In; |
| | | |
| | | import java.io.Serializable; |
| | | import java.sql.Timestamp; |
| | | |
| | |
| | | public class RoleLayerEntity implements Serializable { |
| | | private static final long serialVersionUID = -773018130926889472L; |
| | | |
| | | private int id; |
| | | private Integer id; |
| | | |
| | | private int roleid; |
| | | |
| | |
| | | |
| | | private String enName; |
| | | |
| | | private Integer type; |
| | | private Integer isLayer; |
| | | |
| | | private Integer pid; |
| | | |
| | |
| | | public RoleLayerEntity() { |
| | | } |
| | | |
| | | public int getId() { |
| | | public Integer getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(int id) { |
| | | public void setId(Integer id) { |
| | | this.id = id; |
| | | } |
| | | |
| | |
| | | this.enName = enName; |
| | | } |
| | | |
| | | public Integer getType() { |
| | | return type; |
| | | public Integer getIsLayer() { |
| | | return isLayer; |
| | | } |
| | | |
| | | public void setType(Integer type) { |
| | | this.type = type; |
| | | public void setIsLayer(Integer isLayer) { |
| | | this.isLayer = isLayer; |
| | | } |
| | | |
| | | public Integer getPid() { |
| | |
| | | @Repository |
| | | public interface LayerMapper { |
| | | /** |
| | | * 根据用户ID查询图层列表 |
| | | * |
| | | * @param uid 用户ID |
| | | * @return 图层列表 |
| | | */ |
| | | public List<LayerEntity> selectLayers(String uid); |
| | | |
| | | /** |
| | | * 查询记录数 |
| | | * |
| | | * @param name 名称 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 清除权限缓存 |
| | | * 清除授权缓存 |
| | | */ |
| | | public void clearPermsCache() { |
| | | redisService.clearKeys(RedisCacheKey.permsRootKey()); |
| | |
| | | package com.moon.server.service.sys; |
| | | |
| | | import com.moon.server.entity.all.RedisCacheKey; |
| | | import com.moon.server.entity.all.SettingData; |
| | | import com.moon.server.entity.sys.LayerEntity; |
| | | import com.moon.server.entity.sys.ResEntity; |
| | | import com.moon.server.helper.StringHelper; |
| | | import com.moon.server.mapper.sys.LayerMapper; |
| | | import com.moon.server.service.all.RedisService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 图层 |
| | |
| | | */ |
| | | @Service |
| | | public class LayerService implements LayerMapper { |
| | | @Autowired |
| | | @Resource |
| | | LayerMapper layerMapper; |
| | | |
| | | @Resource |
| | | RedisService redisService; |
| | | |
| | | @Override |
| | | public List<LayerEntity> selectLayers(String uid) { |
| | | String key = RedisCacheKey.permsLayerKey(uid); |
| | | Object obj = redisService.get(key); |
| | | if (obj instanceof List<?>) { |
| | | return (List<LayerEntity>) obj; |
| | | } |
| | | |
| | | List<LayerEntity> list = layerMapper.selectLayers(uid); |
| | | if (list != null && list.size() > 0) { |
| | | redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public Integer selectCount(String name) { |
| | | name = StringHelper.getLikeUpperStr(name); |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moon.server.mapper.sys.LayerMapper"> |
| | | <select id="selectLayers" resultType="com.moon.server.entity.sys.LayerEntity"> |
| | | select distinct d.* |
| | | from lf.sys_user a |
| | | inner join lf.sys_role_user b on a.id = b.userid |
| | | inner join lf.sys_role_res c on b.roleid = c.roleid |
| | | inner join lf.sys_res d on c.resid = d.id |
| | | <where> |
| | | d.status = 1 |
| | | <if test="uid != null"> |
| | | and a.uid = #{uid} |
| | | </if> |
| | | </where> |
| | | order by d.id; |
| | | </select> |
| | | |
| | | <select id="selectCount" resultType="java.lang.Integer"> |
| | | select count(*) from lf.sys_layer |
| | | <where> |
| | |
| | | <mapper namespace="com.moon.server.mapper.sys.RoleLayerMapper"> |
| | | <select id="selectLayersByRole" resultType="com.moon.server.entity.sys.RoleLayerEntity"> |
| | | with rs as (select id, layerid from lf.sys_role_layer where roleid = #{roleid}) |
| | | select (select id from rs b where b.layerid = a.id) "id", a.id "layerid", a.cn_name, a.en_name, a.type, a.pid, a.level, a.order_num |
| | | select (select id from rs b where b.layerid = a.id) "id", a.id "layerid", a.cn_name, a.en_name, a.is_layer, a.pid, a.level, a.order_num |
| | | from lf.sys_layer a |
| | | order by a.id; |
| | | </select> |