管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-25 4ddfd502023662f6d25c4be416d88751e206d91a
1
已修改19个文件
440 ■■■■ 文件已修改
data/db_fn.sql 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/all/PermsController.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/AuthController.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/MenuAuthController.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/MenuController.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/ResController.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/RoleController.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/RoleMenuAuthController.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/RoleResController.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/RoleUserController.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/all/RedisCacheKey.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/interceptor/AuthInterceptor.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/all/PermsMapper.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/all/PermsService.java 84 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/all/ScheduleService.java 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/sys/TokenService.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/all/PermsMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/sys/LoginMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/sys/OperateMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/db_fn.sql
@@ -207,6 +207,12 @@
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;
-----------------------------------------------------------------------------------------------------
update lf.sys_operate set modular1='运维管理',modular2='菜单管理' where position('/Menu/select' in url)>0 and (modular1 is null or modular2 is null);
update lf.sys_operate set modular1='运维管理',modular2='用户管理' where position('/user/select' in url)>0 and (modular1 is null or modular2 is null);
update lf.sys_operate set modular1='运维管理',modular2='资源管理' where position('/res/select' in url)>0 and (modular1 is null or modular2 is null);
delete from lf.sys_operate where modular1 is null or modular2 is null;
----------------------------------------------------------------------------------------------------- 
select gid,gb,name,st_astext(a.geom) from bd.dlg_agnp a;
select * from lf.sys_menu;
@@ -243,7 +249,10 @@
inner join lf.sys_auth f on d.authid = f.id
where a.uid = 'admin';
select modular2,count(*) from lf.sys_operate group by modular2;
select to_char(optime,'yyyy-mm-dd') as optime,count(*) from lf.sys_login where optime between (select optime - interval '30 day')
and optime group by to_char(optime, 'yyyy-mm-dd') order by to_char(optime, 'yyyy-mm-dd') asc;
src/main/java/com/lf/server/controller/all/PermsController.java
@@ -64,9 +64,9 @@
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @GetMapping(value = "/selectPerms")
    public ResponseMsg<List<PermsAuthEntity>> selectPerms(String uid) {
    public ResponseMsg<List<String>> selectPerms(String uid) {
        try {
            List<PermsAuthEntity> rs = permsService.selectPerms(uid);
            List<String> rs = permsService.selectPerms(uid);
            return success(rs);
        } catch (Exception ex) {
@@ -75,14 +75,14 @@
    }
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询权限授权2")
    @ApiOperation(value = "根据用户Uid查询权限授权实体集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @GetMapping(value = "/selectPerms2")
    public ResponseMsg<List<String>> selectPerms2(String uid) {
    @GetMapping(value = "/selectPermsEntity")
    public ResponseMsg<List<PermsAuthEntity>> selectPermsEntity(String uid) {
        try {
            List<String> rs = permsService.selectPerms2(uid);
            List<PermsAuthEntity> rs = permsService.selectPermsEntity(uid);
            return success(rs);
        } catch (Exception ex) {
src/main/java/com/lf/server/controller/sys/AuthController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.AuthEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.AuthService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -31,6 +32,9 @@
    @Autowired
    TokenService tokenService;
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -136,6 +140,9 @@
            }
            int count = authService.insertAuth(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -159,6 +166,9 @@
            }
            int count = authService.insertAuths(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -175,6 +185,9 @@
    public ResponseMsg<Integer> deleteAuth(int id) {
        try {
            int count = authService.deleteAuth(id);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -193,7 +206,12 @@
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
            int count = authService.deleteAuths(ids);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
@@ -215,6 +233,9 @@
            }
            int count = authService.updateAuth(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
src/main/java/com/lf/server/controller/sys/MenuAuthController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.MenuAuthEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.MenuAuthService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -30,6 +31,9 @@
    @Autowired
    TokenService tokenService;
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -165,6 +169,9 @@
            }
            int count = menuAuthService.insert(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -188,6 +195,9 @@
            }
            int count = menuAuthService.inserts(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -204,6 +214,9 @@
    public ResponseMsg<Integer> delete(int id) {
        try {
            int count = menuAuthService.delete(id);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -224,6 +237,9 @@
            }
            int count = menuAuthService.deletes(ids);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -246,6 +262,9 @@
            }
            int count = menuAuthService.update(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -270,6 +289,9 @@
            }
            int count = menuAuthService.updates(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
src/main/java/com/lf/server/controller/sys/MenuController.java
@@ -7,6 +7,7 @@
import com.lf.server.entity.sys.MenuEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.MenuService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -34,6 +35,9 @@
    @Autowired
    TokenService tokenService;
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "插入一条")
    @ApiImplicitParams({
@@ -48,6 +52,9 @@
            }
            int count = menuService.insertMenu(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -71,6 +78,9 @@
            }
            int count = menuService.insertMenus(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -87,6 +97,9 @@
    public ResponseMsg<Integer> deleteMenu(int id) {
        try {
            int count = menuService.deleteMenu(id);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -107,6 +120,9 @@
            }
            int count = menuService.deleteMenus(ids);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -129,6 +145,9 @@
            }
            int count = menuService.updateMenu(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -153,6 +172,9 @@
            }
            int count = menuService.updateMenus(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
src/main/java/com/lf/server/controller/sys/ResController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.ResEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.all.UploadService;
import com.lf.server.service.sys.ResService;
import com.lf.server.service.sys.TokenService;
@@ -37,6 +38,9 @@
    @Autowired
    UploadService uploadService;
    @Autowired
    PermsService permsService;
    private final static String TAB_NAME = "sys_res";
@@ -144,6 +148,9 @@
            }
            int count = resService.insertRes(entity);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -167,6 +174,9 @@
            }
            int count = resService.insertRess(list);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -183,6 +193,9 @@
    public ResponseMsg<Integer> deleteRes(int id) {
        try {
            int count = resService.deleteRes(id);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -201,7 +214,12 @@
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
            int count = resService.deleteRess(ids);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
@@ -223,6 +241,9 @@
            }
            int count = resService.updateRes(entity);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
src/main/java/com/lf/server/controller/sys/RoleController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.RoleEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.RoleService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -31,6 +32,9 @@
    @Autowired
    TokenService tokenService;
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -114,6 +118,9 @@
            }
            int count = roleService.insertRole(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -137,6 +144,9 @@
            }
            int count = roleService.insertRoles(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -153,6 +163,9 @@
    public ResponseMsg<Integer> deleteRole(int id) {
        try {
            int count = roleService.deleteRole(id);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -173,6 +186,9 @@
            }
            int count = roleService.deleteRoles(ids);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -195,6 +211,9 @@
            }
            int count = roleService.updateRole(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
src/main/java/com/lf/server/controller/sys/RoleMenuAuthController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.RoleMenuAuthEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.RoleMenuAuthService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -30,6 +31,9 @@
    @Autowired
    TokenService tokenService;
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -165,6 +169,9 @@
            }
            int count = roleMenuAuthService.insert(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -188,6 +195,9 @@
            }
            int count = roleMenuAuthService.inserts(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -204,6 +214,9 @@
    public ResponseMsg<Integer> delete(int id) {
        try {
            int count = roleMenuAuthService.delete(id);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -224,6 +237,9 @@
            }
            int count = roleMenuAuthService.deletes(ids);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -246,6 +262,9 @@
            }
            int count = roleMenuAuthService.update(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -270,6 +289,9 @@
            }
            int count = roleMenuAuthService.updates(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
src/main/java/com/lf/server/controller/sys/RoleResController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.RoleResEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.RoleResService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -30,6 +31,9 @@
    @Autowired
    TokenService tokenService;
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -137,6 +141,9 @@
            }
            int count = roleResService.insert(entity);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -160,6 +167,9 @@
            }
            int count = roleResService.inserts(list);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -176,6 +186,9 @@
    public ResponseMsg<Integer> delete(int id) {
        try {
            int count = roleResService.delete(id);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -196,6 +209,9 @@
            }
            int count = roleResService.deletes(ids);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -218,6 +234,9 @@
            }
            int count = roleResService.update(entity);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -242,6 +261,9 @@
            }
            int count = roleResService.updates(list);
            if (count > 0) {
                permsService.clearResCache();
            }
            return success(count);
        } catch (Exception ex) {
src/main/java/com/lf/server/controller/sys/RoleUserController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.RoleUserEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.RoleUserService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -30,6 +31,9 @@
    @Autowired
    TokenService tokenService;
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -137,6 +141,9 @@
            }
            int count = roleUserService.insert(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -160,6 +167,9 @@
            }
            int count = roleUserService.inserts(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -176,6 +186,9 @@
    public ResponseMsg<Integer> delete(int id) {
        try {
            int count = roleUserService.delete(id);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -196,6 +209,9 @@
            }
            int count = roleUserService.deletes(ids);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -218,6 +234,9 @@
            }
            int count = roleUserService.update(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -242,6 +261,9 @@
            }
            int count = roleUserService.updates(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
src/main/java/com/lf/server/entity/all/RedisCacheKey.java
@@ -7,9 +7,6 @@
public class RedisCacheKey {
    /**
     * 登录令牌键
     *
     * @param key
     * @return
     */
    public static String signTokenKey(String key) {
        return "sign:token:" + key;
@@ -17,9 +14,6 @@
    /**
     * 登录用户键
     *
     * @param key
     * @return
     */
    public static String signUserKey(String key) {
        return "sign:user:" + key;
@@ -27,21 +21,43 @@
    /**
     * 密码错误键
     *
     * @param key
     * @return
     */
    public static String signPwdError(String key) {
        return "sign:pwdError:" + key;
    }
    /**
     * 锁定用户键
     *
     * @param key
     * @return
     * 授权根键
     */
    public static String signLockUser(String key) {
        return "sso:lockUser:" + key;
    public static String permsRootKey() {
        return "sso:";
    }
    /**
     * 资源授权键
     */
    public static String permsResKey(String key) {
        return "perms:res:" + key;
    }
    /**
     * 菜单授权键
     */
    public static String permsMenusKey(String key) {
        return "perms:menus:" + key;
    }
    /**
     * 权限授权键
     */
    public static String permsPermsKey(String key) {
        return "perms:perms:" + key;
    }
    /**
     * 权限授权实体键
     */
    public static String permsPermsEntityKey(String key) {
        return "perms:permsEntity:" + key;
    }
}
src/main/java/com/lf/server/interceptor/AuthInterceptor.java
@@ -14,6 +14,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * 身份认证拦截器
@@ -31,22 +32,19 @@
    private static final String USER_LOCK = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.USER_LOCK_ERROR, "用户ID已禁用"));
    private static final String NO_AUTH = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.NO_AUTH_ERROR, "无权限访问"));
    public AuthInterceptor(TokenService tokenService) {
        this.tokenService = tokenService;
    }
    /**
     * Controller执行之前执行,如果返回值是true则代表放行,返回false则拦截
     *
     * @param request
     * @param response
     * @param handler
     * @return
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        // noinspection AlibabaRemoveCommentedCode
        try {
            System.out.println(request.getRequestURI().toLowerCase() + ", " + (handler instanceof HandlerMethod));
            // 非方法 或 无需授权,无需拦截
            if (!(handler instanceof HandlerMethod) || noNeedAuth(request)) {
                return true;
@@ -66,8 +64,10 @@
                return WebHelper.write2Page(response, USER_LOCK);
            }
            // noinspection AlibabaRemoveCommentedCode
            // 权限校验
            //if (!checkPerms(ue, request)) {
            //    return WebHelper.write2Page(response, NO_AUTH);
            //}
            return true;
        } catch (Exception ex) {
@@ -78,9 +78,6 @@
    /**
     * 无需授权
     *
     * @param request
     * @return
     */
    private static boolean noNeedAuth(HttpServletRequest request) {
        String uri = request.getRequestURI().toLowerCase();
@@ -92,4 +89,23 @@
        return false;
    }
    /**
     * 检查权限
     */
    private boolean checkPerms(UserEntity ue, HttpServletRequest request) {
        List<String> list = tokenService.permsService.selectPerms(ue.getUid());
        if (list == null || list.size() == 0) {
            return false;
        }
        String url = request.getRequestURI();
        for (String perm : list) {
            if (url.startsWith(perm)) {
                return true;
            }
        }
        return false;
    }
}
src/main/java/com/lf/server/mapper/all/PermsMapper.java
@@ -37,13 +37,13 @@
     * @param uid
     * @return
     */
    public List<PermsAuthEntity> selectPerms(String uid);
    public List<String> selectPerms(String uid);
    /**
     * 根据用户Uid查询权限授权2
     * 根据用户Uid查询权限授权实体集合
     *
     * @param uid
     * @return
     */
    public List<String> selectPerms2(String uid);
    public List<PermsAuthEntity> selectPermsEntity(String uid);
}
src/main/java/com/lf/server/service/all/PermsService.java
@@ -1,14 +1,13 @@
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.entity.all.*;
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;
import java.util.concurrent.TimeUnit;
/**
 * 授权服务
@@ -19,13 +18,27 @@
    @Autowired
    PermsMapper permsMapper;
    @Autowired
    RedisService redisService;
    @Override
    public List<ResAuthEntity> selectRes(String uid) {
        if (StringHelper.isEmpty(uid)) {
            return null;
        }
        return permsMapper.selectRes(uid);
        String key = RedisCacheKey.permsResKey(uid);
        Object obj = redisService.get(key);
        if (obj instanceof List<?>) {
            return (List<ResAuthEntity>) obj;
        }
        List<ResAuthEntity> list = permsMapper.selectRes(uid);
        if (list != null && list.size() > 0) {
            redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES);
        }
        return list;
    }
    @Override
@@ -34,24 +47,77 @@
            return null;
        }
        return permsMapper.selectMenus(uid);
        String key = RedisCacheKey.permsMenusKey(uid);
        Object obj = redisService.get(key);
        if (obj instanceof List<?>) {
            return (List<MenusAuthEntity>) obj;
        }
        List<MenusAuthEntity> list = permsMapper.selectMenus(uid);
        if (list != null && list.size() > 0) {
            redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES);
        }
        return list;
    }
    @Override
    public List<PermsAuthEntity> selectPerms(String uid) {
    public List<String> selectPerms(String uid) {
        if (StringHelper.isEmpty(uid)) {
            return null;
        }
        return permsMapper.selectPerms(uid);
        String key = RedisCacheKey.permsPermsKey(uid);
        Object obj = redisService.get(key);
        if (obj instanceof List<?>) {
            return (List<String>) obj;
        }
        List<String> list = permsMapper.selectPerms(uid);
        if (list != null && list.size() > 0) {
            redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES);
        }
        return list;
    }
    @Override
    public List<String> selectPerms2(String uid) {
    public List<PermsAuthEntity> selectPermsEntity(String uid) {
        if (StringHelper.isEmpty(uid)) {
            return null;
        }
        return permsMapper.selectPerms2(uid);
        String key = RedisCacheKey.permsPermsEntityKey(uid);
        Object obj = redisService.get(key);
        if (obj instanceof List<?>) {
            return (List<PermsAuthEntity>) obj;
        }
        List<PermsAuthEntity> list = permsMapper.selectPermsEntity(uid);
        if (list != null && list.size() > 0) {
            redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES);
        }
        return list;
    }
    public void clearResCache() {
        clearCache(RedisCacheKey.permsResKey(""));
    }
    public void clearPermsCache() {
        clearCache(RedisCacheKey.permsMenusKey(""));
        clearCache(RedisCacheKey.permsPermsKey(""));
        clearCache(RedisCacheKey.permsPermsEntityKey(""));
    }
    public void clearAllCache() {
        clearCache(RedisCacheKey.permsRootKey());
    }
    protected void clearCache(String key) {
        if (redisService.hasKey(key)) {
            redisService.clearKeys(key);
        }
    }
}
src/main/java/com/lf/server/service/all/ScheduleService.java
@@ -53,9 +53,6 @@
    /**
     * 查询服务器状态
     *
     * @return
     * @throws InterruptedException
     */
    public JSONObject selectServerStatus() throws InterruptedException {
        JSONObject json = new JSONObject();
@@ -67,9 +64,6 @@
    /**
     * 查询Cpu信息
     *
     * @return
     * @throws InterruptedException
     */
    public JSONObject selectCpuInfo() throws InterruptedException {
        SystemInfo systemInfo = new SystemInfo();
@@ -101,8 +95,6 @@
    /**
     * 查询内存信息
     *
     * @return
     */
    public JSONObject selectMemInfo() {
        JSONObject map = new JSONObject();
@@ -124,8 +116,6 @@
    /**
     * 查询在线用户
     *
     * @return
     */
    public List<JSONObject> selectOnlineUsers() {
        List<JSONObject> list = new ArrayList<JSONObject>();
@@ -133,7 +123,7 @@
        Set<String> keys = redisTemplate.keys(RedisCacheKey.signUserKey("*"));
        for (String key : keys) {
            Object obj = redisTemplate.opsForValue().get(key);
            if (obj != null && obj instanceof UserEntity) {
            if (obj instanceof UserEntity) {
                UserEntity ue = (UserEntity) obj;
                JSONObject map = new JSONObject();
@@ -150,8 +140,6 @@
    /**
     * 查询服务资源状态
     *
     * @return
     */
    public List<ResEntity> selectResStatus() {
        List<ResEntity> resList = resService.selectResAll();
@@ -191,8 +179,6 @@
    /**
     * 统计服务资源状态
     *
     * @return
     */
    public JSONObject countResStatus() {
        List<ResEntity> resList = resService.selectResAll();
@@ -210,10 +196,7 @@
    /**
     * 资源操作状态
     *
     * @return
     */
    public JSONObject operateCount() {
        List<OperateEntity> list = operateService.operateCount();
        JSONObject jsonObject = new JSONObject();
@@ -234,26 +217,23 @@
    /**
     * 用户登录状态
     *
     * @return
     */
    public JSONObject userLoginCount() {
        List<LoginEntity> list = loginService.selectLoginCounts();
        JSONObject jsonObject = new JSONObject();
        if (list.isEmpty()) {
        if (list == null || list.isEmpty()) {
            return null;
        } else {
            List<JSONObject> lister = new ArrayList<JSONObject>();
            for (LoginEntity key : list) {
                JSONObject map = new JSONObject();
                map.put("count", key.getCount());
                map.put("optime", key.getOptime());
                lister.add(map);
            }
            jsonObject.put("userLoginCount", lister);
            return jsonObject;
        }
    }
        JSONObject jsonObject = new JSONObject();
        List<JSONObject> lister = new ArrayList<JSONObject>();
        for (LoginEntity key : list) {
            JSONObject map = new JSONObject();
            map.put("count", key.getCount());
            map.put("optime", key.getOptime());
            lister.add(map);
        }
        jsonObject.put("userLoginCount", lister);
        return jsonObject;
    }
}
src/main/java/com/lf/server/service/sys/TokenService.java
@@ -8,6 +8,7 @@
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.WebHelper;
import com.lf.server.mapper.sys.TokenMapper;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.all.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -27,9 +28,6 @@
@Service
public class TokenService implements TokenMapper {
    @Autowired
    public RedisService redisService;
    @Autowired
    TokenMapper tokenMapper;
    @Autowired
@@ -37,6 +35,12 @@
    @Autowired
    LoginService loginService;
    @Autowired
    public RedisService redisService;
    @Autowired
    public  PermsService permsService;
    @Override
    public Integer selectCount(String name, Integer type) {
@@ -187,7 +191,7 @@
        // redis
        Object obj = redisService.get(tokenKey);
        if (obj != null && obj instanceof TokenEntity) {
        if (obj instanceof TokenEntity) {
            return (TokenEntity) obj;
        }
@@ -229,7 +233,7 @@
        // redis
        Object obj = redisService.get(userKey);
        if (obj != null && obj instanceof UserEntity) {
        if (obj instanceof UserEntity) {
            return (UserEntity) obj;
        }
src/main/resources/mapper/all/PermsMapper.xml
@@ -17,8 +17,8 @@
        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
    <select id="selectPerms" 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
@@ -27,8 +27,8 @@
        where a.uid = #{uid}
    </select>
    <select id="selectPerms2" resultType="java.lang.String">
        select distinct e.perms || f.tag as "perms"
    <select id="selectPermsEntity" 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
src/main/resources/mapper/sys/LoginMapper.xml
@@ -85,7 +85,7 @@
    </update>
    <select id="selectLoginCounts" resultType="com.lf.server.entity.sys.LoginEntity">
       select to_char(optime,'yyyy-mm-dd') as optime ,count(*) from lf.sys_login where optime between (select optime - interval '30 day')
       and optime group by to_char(optime,'yyyy-mm-dd') order by to_char(optime,'yyyy-mm-dd') desc;
        select to_char(optime,'yyyy-mm-dd') as optime,count(*) from lf.sys_login where optime between (select optime - interval '30 day')
        and optime group by to_char(optime, 'yyyy-mm-dd') order by to_char(optime, 'yyyy-mm-dd') asc
    </select>
</mapper>
src/main/resources/mapper/sys/OperateMapper.xml
@@ -80,6 +80,6 @@
    </update>
    <select id="operateCount" resultType="com.lf.server.entity.sys.OperateEntity">
        select  modular2, count(*) from lf.sys_operate group by modular2 ;
        select modular2,count(*) from lf.sys_operate group by modular2
    </select>
</mapper>