管道基础大数据平台系统开发-【后端】-Server
13693261870
2022-10-24 403da64eae0a1357d80b6ce44391af1f11b835a3
添加授权功能
已添加7个文件
已修改3个文件
已删除1个文件
636 ■■■■ 文件已修改
data/db_fn.sql 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/db_tab.sql 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/all/FileController.java 119 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/all/PermsController.java 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/all/MenusAuthEntity.java 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/all/PermsAuthEntity.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/all/ResAuthEntity.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/AesHelper.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/all/PermsMapper.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/all/PermsService.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/all/PermsMapper.xml 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/db_fn.sql
@@ -208,13 +208,40 @@
select a.*,b.menuid,c.name from lf.sys_role_menu_auth a inner join lf.sys_menu_auth b on a.menu_auth_id = b.id
inner join lf.sys_auth c on b.authid = c.id where a.roleid = 1 and b.menuid = 1 order by c.id;
----------------------------------------------------------------------------------------------------- 
select * from lf.sys_user;
select gid,gb,name,st_astext(a.geom) from bd.dlg_agnp a;
select * from lf.sys_menu;
-- æ ¹æ®ç”¨æˆ·Uid查询资源
select distinct d.id,d.name,d.server 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 a.uid = 'admin';
-- æ ¹æ®ç”¨æˆ·Uid查询菜单
select distinct e.id,e.pid,e.cn_name,e.en_name,e.url,e.type,e.icon,e.level,e.order_num,e.is_show
from lf.sys_user a inner join lf.sys_role_user b on a.id = b.userid
inner join lf.sys_role_menu_auth c on b.roleid = c.roleid
inner join lf.sys_menu_auth d on c.menu_auth_id = d.id
inner join lf.sys_menu e on d.menuid = e.id
where a.uid = 'admin';
-- æ ¹æ®ç”¨æˆ·Uid查询权限
select distinct f.id,e.cn_name,f.name,e.perms,f.tag
from lf.sys_user a inner join lf.sys_role_user b on a.id = b.userid
inner join lf.sys_role_menu_auth c on b.roleid = c.roleid
inner join lf.sys_menu_auth d on c.menu_auth_id = d.id
inner join lf.sys_menu e on d.menuid = e.id
inner join lf.sys_auth f on d.authid = f.id
where a.uid = 'admin';
-- æ ¹æ®ç”¨æˆ·Uid查询权限2
select distinct e.perms || f.tag as "perms"
from lf.sys_user a inner join lf.sys_role_user b on a.id = b.userid
inner join lf.sys_role_menu_auth c on b.roleid = c.roleid
inner join lf.sys_menu_auth d on c.menu_auth_id = d.id
inner join lf.sys_menu e on d.menuid = e.id
inner join lf.sys_auth f on d.authid = f.id
where a.uid = 'admin';
data/db_tab.sql
@@ -404,13 +404,13 @@
comment on column lf.sys_auth.update_user is '更新人ID';
comment on column lf.sys_auth.update_time is '更新时间';
comment on column lf.sys_auth.bak is '备注';
/* insert into lf.sys_auth (name,tag) values ('查看','select');
insert into lf.sys_auth (name,tag) values ('新增','insert');
insert into lf.sys_auth (name,tag) values ('修改','update');
insert into lf.sys_auth (name,tag) values ('删除','delete');
insert into lf.sys_auth (name,tag) values ('上传','upload');
insert into lf.sys_auth (name,tag) values ('下载','download');
insert into lf.sys_auth (name,tag) values ('统计','count'); */
/* insert into lf.sys_auth (name,tag) values ('查看','/select');
insert into lf.sys_auth (name,tag) values ('新增','/insert');
insert into lf.sys_auth (name,tag) values ('修改','/update');
insert into lf.sys_auth (name,tag) values ('删除','/delete');
insert into lf.sys_auth (name,tag) values ('上传','/upload');
insert into lf.sys_auth (name,tag) values ('下载','/download');
insert into lf.sys_auth (name,tag) values ('统计','/count'); */
select * from lf.sys_auth;
----------------------------------------------------------------------------------------------------- 11.角色表
@@ -508,7 +508,7 @@
--insert into lf.sys_menu_auth (menuid,authid) values (1,1),(1,2),(1,3),(1,4),(1,5);
select * from lf.sys_menu_auth;
----------------------------------------------------------------------------------------------------- 14.角色-菜单-权限表
----------------------------------------------------------------------------------------------------- 15.角色-菜单-权限表
-- DROP TABLE IF EXISTS lf.sys_role_menu_auth;
create table lf.sys_role_menu_auth(
  id serial primary key,
src/main/java/com/lf/server/controller/all/FileController.java
ÎļþÒÑɾ³ý
src/main/java/com/lf/server/controller/all/PermsController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,92 @@
package com.lf.server.controller.all;
import com.lf.server.aspect.SysLog;
import com.lf.server.entity.all.MenusAuthEntity;
import com.lf.server.entity.all.PermsAuthEntity;
import com.lf.server.entity.all.ResAuthEntity;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.service.all.PermsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * æŽˆæƒæŽ§åˆ¶å™¨
 * @author WWW
 */
@Api(tags = "运维管理\\授权管理")
@RestController
@RequestMapping("/file")
public class PermsController extends BaseController {
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询资源授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @GetMapping(value = "/selectRes")
    public ResponseMsg<List<ResAuthEntity>> selectRes(String uid) {
        try {
            List<ResAuthEntity> rs = permsService.selectRes(uid);
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询菜单授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @GetMapping(value = "/selectMenus")
    public ResponseMsg<List<MenusAuthEntity>> selectMenus(String uid) {
        try {
            List<MenusAuthEntity> rs = permsService.selectMenus(uid);
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询权限授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @GetMapping(value = "/selectPerms")
    public ResponseMsg<List<PermsAuthEntity>> selectPerms(String uid) {
        try {
            List<PermsAuthEntity> rs = permsService.selectPerms(uid);
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询权限授权2")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @GetMapping(value = "/selectPerms2")
    public ResponseMsg<List<String>> selectPerms2(String uid) {
        try {
            List<String> rs = permsService.selectPerms2(uid);
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
}
src/main/java/com/lf/server/entity/all/MenusAuthEntity.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,115 @@
package com.lf.server.entity.all;
import java.io.Serializable;
/**
 * èœå•授权
 * @author WWW
 */
public class MenusAuthEntity implements Serializable {
    private static final long serialVersionUID = -944664756113218L;
    private Integer id;
    private Integer pid;
    private String cnName;
    private String enName;
    private String url;
    private Integer type;
    private String icon;
    private Integer level;
    private Integer orderNum;
    private Integer isShow;
    public MenusAuthEntity() {
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getPid() {
        return pid;
    }
    public void setPid(Integer pid) {
        this.pid = pid;
    }
    public String getCnName() {
        return cnName;
    }
    public void setCnName(String cnName) {
        this.cnName = cnName;
    }
    public String getEnName() {
        return enName;
    }
    public void setEnName(String enName) {
        this.enName = enName;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    public String getIcon() {
        return icon;
    }
    public void setIcon(String icon) {
        this.icon = icon;
    }
    public Integer getLevel() {
        return level;
    }
    public void setLevel(Integer level) {
        this.level = level;
    }
    public Integer getOrderNum() {
        return orderNum;
    }
    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }
    public Integer getIsShow() {
        return isShow;
    }
    public void setIsShow(Integer isShow) {
        this.isShow = isShow;
    }
}
src/main/java/com/lf/server/entity/all/PermsAuthEntity.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,65 @@
package com.lf.server.entity.all;
import java.io.Serializable;
/**
 * æƒé™æŽˆæƒ
 * @author WWW
 */
public class PermsAuthEntity implements Serializable {
    private static final long serialVersionUID = -8948994757253139554L;
    private Integer id;
    private String cnName;
    private String name;
    private String perms;
    private String tag;
    public PermsAuthEntity() {
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getCnName() {
        return cnName;
    }
    public void setCnName(String cnName) {
        this.cnName = cnName;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPerms() {
        return perms;
    }
    public void setPerms(String perms) {
        this.perms = perms;
    }
    public String getTag() {
        return tag;
    }
    public void setTag(String tag) {
        this.tag = tag;
    }
}
src/main/java/com/lf/server/entity/all/ResAuthEntity.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,45 @@
package com.lf.server.entity.all;
import java.io.Serializable;
/**
 * èµ„源授权
 * @author WWW
 */
public class ResAuthEntity implements Serializable {
    private static final long serialVersionUID = 7610553267313397837L;
    private Integer id;
    private String name;
    private String server;
    public ResAuthEntity() {
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getServer() {
        return server;
    }
    public void setServer(String server) {
        this.server = server;
    }
}
src/main/java/com/lf/server/helper/AesHelper.java
@@ -75,8 +75,8 @@
     * @throws Exception
     */
    private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception {
        //KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM);
        //kGen.init(128);
        // KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM)
        // kGen.init(128)
        Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), KEY_ALGORITHM));
@@ -117,8 +117,8 @@
     * @throws Exception
     */
    private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception {
        //KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM);
        //kGen.init(128);
        // KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM)
        // kGen.init(128)
        Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), KEY_ALGORITHM));
src/main/java/com/lf/server/mapper/all/PermsMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,49 @@
package com.lf.server.mapper.all;
import com.lf.server.entity.all.MenusAuthEntity;
import com.lf.server.entity.all.PermsAuthEntity;
import com.lf.server.entity.all.ResAuthEntity;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
 * æŽˆæƒç®¡ç†
 * @author WWW
 */
@Mapper
@Repository
public interface PermsMapper {
    /**
     * æ ¹æ®ç”¨æˆ·Uid查询资源授权
     *
     * @param uid
     * @return
     */
    public List<ResAuthEntity> selectRes(String uid);
    /**
     * æ ¹æ®ç”¨æˆ·Uid查询菜单授权
     *
     * @param uid
     * @return
     */
    public List<MenusAuthEntity> selectMenus(String uid);
    /**
     * æ ¹æ®ç”¨æˆ·Uid查询权限授权
     *
     * @param uid
     * @return
     */
    public List<PermsAuthEntity> selectPerms(String uid);
    /**
     * æ ¹æ®ç”¨æˆ·Uid查询权限授权2
     *
     * @param uid
     * @return
     */
    public List<String> selectPerms2(String uid);
}
src/main/java/com/lf/server/service/all/PermsService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,57 @@
package com.lf.server.service.all;
import com.lf.server.entity.all.MenusAuthEntity;
import com.lf.server.entity.all.PermsAuthEntity;
import com.lf.server.entity.all.ResAuthEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.all.PermsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * æŽˆæƒæœåŠ¡
 * @author WWW
 */
@Service
public class PermsService implements PermsMapper {
    @Autowired
    PermsMapper permsMapper;
    @Override
    public List<ResAuthEntity> selectRes(String uid) {
        if (StringHelper.isEmpty(uid)) {
            return null;
        }
        return permsMapper.selectRes(uid);
    }
    @Override
    public List<MenusAuthEntity> selectMenus(String uid) {
        if (StringHelper.isEmpty(uid)) {
            return null;
        }
        return permsMapper.selectMenus(uid);
    }
    @Override
    public List<PermsAuthEntity> selectPerms(String uid) {
        if (StringHelper.isEmpty(uid)) {
            return null;
        }
        return permsMapper.selectPerms(uid);
    }
    @Override
    public List<String> selectPerms2(String uid) {
        if (StringHelper.isEmpty(uid)) {
            return null;
        }
        return permsMapper.selectPerms2(uid);
    }
}
src/main/resources/mapper/all/PermsMapper.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,39 @@
<?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.lf.server.mapper.all.PermsMapper">
    <select id="selectRes" resultType="com.lf.server.entity.all.ResAuthEntity">
        select distinct d.id,d.name,d.server 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 a.uid = #{uid}
    </select>
    <select id="selectMenus" resultType="com.lf.server.entity.all.MenusAuthEntity">
        select distinct e.id,e.pid,e.cn_name,e.en_name,e.url,e.type,e.icon,e.level,e.order_num,e.is_show
        from lf.sys_user a inner join lf.sys_role_user b on a.id = b.userid
        inner join lf.sys_role_menu_auth c on b.roleid = c.roleid
        inner join lf.sys_menu_auth d on c.menu_auth_id = d.id
        inner join lf.sys_menu e on d.menuid = e.id
        where a.uid = #{uid}
    </select>
    <select id="selectPerms" resultType="com.lf.server.entity.all.PermsAuthEntity">
        select distinct f.id,e.cn_name,f.name,e.perms,f.tag
        from lf.sys_user a inner join lf.sys_role_user b on a.id = b.userid
        inner join lf.sys_role_menu_auth c on b.roleid = c.roleid
        inner join lf.sys_menu_auth d on c.menu_auth_id = d.id
        inner join lf.sys_menu e on d.menuid = e.id
        inner join lf.sys_auth f on d.authid = f.id
        where a.uid = #{uid}
    </select>
    <select id="selectPerms2" resultType="java.lang.String">
        select distinct e.perms || f.tag as "perms"
        from lf.sys_user a inner join lf.sys_role_user b on a.id = b.userid
        inner join lf.sys_role_menu_auth c on b.roleid = c.roleid
        inner join lf.sys_menu_auth d on c.menu_auth_id = d.id
        inner join lf.sys_menu e on d.menuid = e.id
        inner join lf.sys_auth f on d.authid = f.id
        where a.uid = #{uid}
    </select>
</mapper>