李进 2 år sedan
förälder
incheckning
ee3be374d3

+ 6 - 0
authorize-api-service/pom.xml

@@ -23,6 +23,12 @@
             <artifactId>authorize-api</artifactId>
             <version>1.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>authorize-sdk</artifactId>
+            <version>1.0</version>
+        </dependency>
+
 
         <dependency>
             <groupId>com.xy</groupId>

+ 0 - 20
authorize-api-service/src/main/java/com/xy/annotation/CheckSysId.java

@@ -1,20 +0,0 @@
-package com.xy.annotation;
-
-import java.lang.annotation.*;
-
-/**
- * 检查系统是否属于当前登录人
- *
- * @author lijin
- */
-@Target({ElementType.METHOD})
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-public @interface CheckSysId {
-
-    /**
-     * 系统id属性名
-     */
-    String value() default "systemId,sysId";
-
-}

+ 0 - 40
authorize-api-service/src/main/java/com/xy/annotation/aspet/CommAset.java

@@ -1,40 +0,0 @@
-package com.xy.annotation.aspet;
-
-import com.xy.annotation.CheckSysId;
-import com.xy.redis.RedisCache;
-import com.xy.utils.Reflect;
-import com.xy.utils.Tuple;
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.springframework.stereotype.Component;
-
-import java.util.Arrays;
-import java.util.List;
-
-@Aspect
-@Component
-public class CommAset {
-
-    @Around("@annotation(checkSysId)")
-    public Object checkSysId(ProceedingJoinPoint joinPoint, CheckSysId checkSysId) throws Throwable {
-        Object[] args = joinPoint.getArgs();
-        Object result;
-        String value = checkSysId.value();
-        try {
-            String[] split = value.split(",");
-            for (String s : split) {
-                Tuple.Tuple3<String, Object, Class<?>> property = Reflect.PropertyReflect.getProperty(args[0], s);
-                if (property.getV2() != null) {
-                    List list = property.getV3().equals(List.class) ? (List) property.getV2() : Arrays.asList(property.getV2());
-                    list.forEach(o -> RedisCache.checkSystemIdByException(Long.parseLong(o.toString())));
-                    break;
-                }
-            }
-            result = joinPoint.proceed(args);
-        } catch (Exception e) {
-            throw e;
-        }
-        return result;
-    }
-}

+ 0 - 32
authorize-api-service/src/main/java/com/xy/entity/join/SysMenuJoinSysRoleMenu.java

@@ -1,32 +0,0 @@
-package com.xy.entity.join;
-
-import com.xy.entity.SysMenu;
-import lombok.Data;
-import lombok.experimental.Accessors;
-
-import java.io.Serializable;
-import java.util.List;
-
-/**
- * 菜单表和角色菜单表关联实体
- */
-@Data
-@Accessors(chain = true)
-public class SysMenuJoinSysRoleMenu extends SysMenu implements Serializable {
-
-    /**
-     * 角色id
-     */
-    private Long roleId;
-
-    /**
-     * 管理员数据查询权限
-     */
-    private Boolean selectIsAdmin;
-
-    /**
-     * 子级集合
-     */
-    private List<SysMenuJoinSysRoleMenu> sonSysMenu;
-
-}

+ 4 - 300
authorize-api-service/src/main/java/com/xy/redis/RedisCache.java

@@ -5,18 +5,13 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 import com.xy.collections.list.JArrayList;
 import com.xy.collections.list.JList;
 import com.xy.collections.map.JMap;
-import com.xy.consts.CommConsts;
 import com.xy.entity.*;
-import com.xy.entity.join.SysMenuJoinSysRoleMenu;
-import com.xy.error.CommRuntimeException;
 import com.xy.mapper.SysDeptMapper;
 import com.xy.mapper.SysMenuMapper;
 import com.xy.mapper.SysRoleMapper;
 import com.xy.mapper.SysSystemMapper;
 import com.xy.utils.*;
 import icu.mhb.mybatisplus.plugln.core.JoinLambdaWrapper;
-import lombok.Data;
-import lombok.experimental.Accessors;
 import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
@@ -24,22 +19,12 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * 权限系统redis工具类
  */
 @Component
-public class RedisCache {
-
-    private static RedisService<List<CacheEntity>> getRedisService() {
-        return SpringBeanUtils.getBean(RedisService.class);
-    }
-
-    private static String getKey(Long loginId) {
-        return String.format("%s:%d", "menu", loginId);
-    }
+public class RedisCache extends AuthorizeUtils {
 
     /**
      * 缓存业务系统权限到redis
@@ -51,7 +36,7 @@ public class RedisCache {
         SysRoleMapper sysRoleMapper = SpringBeanUtils.getBean(SysRoleMapper.class);
         SysDeptMapper sysDeptMapper = SpringBeanUtils.getBean(SysDeptMapper.class);
         SysMenuMapper sysMenuMapper = SpringBeanUtils.getBean(SysMenuMapper.class);
-        RedisService<List<RedisCache.CacheEntity>> roleMenuRedisService = getRedisService();
+        RedisService<List<AuthorizeUtils.CacheEntity>> roleMenuRedisService = getRedisService();
         //获取登录人所有系统
         JoinLambdaWrapper<SysSystem> sysSystemsJoinLambdaWrapper = new JoinLambdaWrapper<>(SysSystem.class)
                 .eq(SysSystem::getStatus, true)
@@ -109,9 +94,9 @@ public class RedisCache {
         List<SysMenuJoinSysRoleMenu> sysMenus = sysMenuMapper.joinSelectList(sysMenuJoinLambdaWrapper, SysMenuJoinSysRoleMenu.class);
         JMap<Long, List<SysMenuJoinSysRoleMenu>> sysMenuMaps = new JArrayList<>(sysMenus).toMap(SysMenuJoinSysRoleMenu::getRoleId).group();
         sysSystems.forEach(sysSystem -> {
-            List<RedisCache.CacheEntity> cacheEntitys = new ArrayList<>();
+            List<AuthorizeUtils.CacheEntity> cacheEntitys = new ArrayList<>();
             sysRoles.forEach(sysRole -> {
-                RedisCache.CacheEntity cacheEntity = new RedisCache.CacheEntity()
+                AuthorizeUtils.CacheEntity cacheEntity = new AuthorizeUtils.CacheEntity()
                         .setRoleId(sysRole.getId())
                         .setRoleCode(sysRole.getCode())
                         .setList(sysMenuMaps.get(sysRole.getId()));
@@ -121,105 +106,6 @@ public class RedisCache {
         });
     }
 
-    /**
-     * 获取菜单
-     *
-     * @param loginId  登录id
-     * @param systemId 系统id
-     * @return
-     */
-    public static List<SysMenuJoinSysRoleMenu> getMenu(Long loginId, Long systemId) {
-        JList<SysMenuJoinSysRoleMenu> sysMenuJoinSysRoleMenus = new JArrayList<>();
-        //获取redis缓存
-        List<RedisCache.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
-        if (!Emptys.check(cacheEntities)) {
-            return sysMenuJoinSysRoleMenus;
-        }
-        //角色菜单累加
-        cacheEntities.forEach(cacheEntity -> sysMenuJoinSysRoleMenus.addAll(cacheEntity.getList()));
-        //去重
-        sysMenuJoinSysRoleMenus.comparing(SysMenuJoinSysRoleMenu::getId);
-        return sysMenuJoinSysRoleMenus;
-    }
-
-    /**
-     * 获取菜单
-     *
-     * @param systemId 系统id
-     * @return
-     */
-    public static List<SysMenuJoinSysRoleMenu> getMenu(Long systemId) {
-        return getMenu(SaTokenUtils.getId(Long.class), systemId);
-    }
-
-    /**
-     * 获取菜单树
-     *
-     * @param loginId  登录id
-     * @param systemId 系统id
-     * @return
-     */
-    public static List<SysMenuJoinSysRoleMenu> getMenuTree(Long loginId, Long systemId) {
-        //获取菜单
-        JList<SysMenuJoinSysRoleMenu> sysMenuJoinSysRoleMenus = new JArrayList<>(getMenu(loginId, systemId));
-        //生成树
-        JList<SysMenuJoinSysRoleMenu> tops = sysMenuJoinSysRoleMenus.filter().isNull(SysMenuJoinSysRoleMenu::getPaterId).list();
-        for (SysMenuJoinSysRoleMenu top : tops) {
-            List<SysMenuJoinSysRoleMenu> tree = Beans.tree(top, sysMenuJoinSysRoleMenus, SysMenuJoinSysRoleMenu::getId, SysMenuJoinSysRoleMenu::getPaterId, SysMenuJoinSysRoleMenu::getSonSysMenu);
-            top.setSonSysMenu(tree);
-        }
-        return tops;
-    }
-
-    /**
-     * 获取菜单树
-     *
-     * @param systemId 系统id
-     * @return
-     */
-    public static List<SysMenuJoinSysRoleMenu> getMenuTree(Long systemId) {
-        return getMenuTree(SaTokenUtils.getId(Long.class), systemId);
-    }
-
-    /**
-     * 判断数据查询权限
-     *
-     * @param loginId  登录id
-     * @param systemId 系统id
-     * @param systemId 接口uri
-     * @return true=管理员数据查询权限 false=普通查询权限
-     */
-    public static boolean getDataAuth(Long loginId, Long systemId, String uri) {
-        //获取redis缓存
-        List<CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
-        if (!Emptys.check(cacheEntities)) {
-            return false;
-        }
-        //遍历角色
-        for (CacheEntity cacheEntity : cacheEntities) {
-            //根据 接口uri和管理员数据查询权限=true 查找角色菜单,找到则有管理员数据查询权限,反之普通查询权限
-            SysMenuJoinSysRoleMenu sysMenuJoinSysRoleMenu = new JArrayList<>(cacheEntity.getList()).filter()
-                    .eq(SysMenuJoinSysRoleMenu::getInterfaceUri, uri)
-                    .eq(SysMenuJoinSysRoleMenu::getSelectIsAdmin, true)
-                    .object();
-            if (sysMenuJoinSysRoleMenu != null) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * 判断数据查询权限
-     *
-     * @param systemId 系统id
-     * @param systemId 接口uri
-     * @return true=管理员数据查询权限 false=普通查询权限
-     */
-    public static boolean getDataAuth(Long systemId, String uri) {
-        return getDataAuth(SaTokenUtils.getId(Long.class), systemId, uri);
-    }
-
     /**
      * 判断数据查询权限
      *
@@ -248,186 +134,4 @@ public class RedisCache {
         return getDataAuth(SaTokenUtils.getId(Long.class), systemId, lambdaQueryWrapper, function);
     }
 
-    /**
-     * 获取所有系统ID
-     *
-     * @param loginId 登录id
-     * @return
-     */
-    public static List<Long> getSystemIds(Long loginId) {
-        Map<String, List<CacheEntity>> map = getRedisService().getMap(getKey(loginId));
-        if (!Emptys.check(map)) {
-            return new ArrayList<>();
-        }
-        List<Long> list = new ArrayList<>(map.size());
-        map.forEach((s, cacheEntities) -> list.add(Long.parseLong(s)));
-        return list;
-    }
-
-    /**
-     * 获取所有系统ID
-     *
-     * @return
-     */
-    public static List<Long> getSystemIds() {
-        return getSystemIds(SaTokenUtils.getId(Long.class));
-    }
-
-    /**
-     * 检验系统ID是否属于当前登录人
-     *
-     * @param loginId  登录id
-     * @param systemId 系统id
-     * @return
-     */
-    public static Boolean checkSystemId(Long loginId, Long systemId) {
-        Map<String, List<CacheEntity>> map = getRedisService().getMap(getKey(loginId));
-        return map.containsKey(systemId.toString());
-    }
-
-    /**
-     * 检验系统ID是否属于当前登录人
-     *
-     * @param systemId 系统id
-     * @return
-     */
-    public static Boolean checkSystemId(Long systemId) {
-        return checkSystemId(SaTokenUtils.getId(Long.class), systemId);
-    }
-
-    /**
-     * 检验系统ID是否属于当前登录人并抛出异常
-     *
-     * @param loginId  登录id
-     * @param systemId 系统id
-     * @return
-     */
-    public static void checkSystemIdByException(Long loginId, Long systemId) {
-        Boolean aBoolean = checkSystemId(loginId, systemId);
-        if (!aBoolean) {
-            throw new CommRuntimeException("系统不存在");
-        }
-    }
-
-    /**
-     * 检验系统ID是否属于当前登录人并抛出异常
-     *
-     * @param systemId 系统id
-     * @return
-     */
-    public static void checkSystemIdByException(Long systemId) {
-        checkSystemIdByException(SaTokenUtils.getId(Long.class), systemId);
-    }
-
-    /**
-     * 获取所有角色ID
-     *
-     * @param loginId  登录id
-     * @param systemId 系统id
-     * @return
-     */
-    public static List<Long> getRoleIds(Long loginId, Long systemId) {
-        List<CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
-        if (!Emptys.check(cacheEntities)) {
-            return new ArrayList<>();
-        }
-        List<Long> list = new ArrayList<>(cacheEntities.size());
-        cacheEntities.forEach(cacheEntity -> list.add(Long.parseLong(cacheEntity.getRoleId().toString())));
-        return list;
-    }
-
-    /**
-     * 获取所有角色ID
-     *
-     * @param systemId 系统id
-     * @return
-     */
-    public static List<Long> getRoleIds(Long systemId) {
-        return getRoleIds(SaTokenUtils.getId(Long.class), systemId);
-    }
-
-    /**
-     * 是否是管理员
-     *
-     * @param loginId 登录id
-     * @return
-     */
-    public static Boolean isAdmin(Long loginId, Long systemId) {
-        List<CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
-        if (!Emptys.check(cacheEntities)) {
-            return false;
-        }
-        for (CacheEntity cacheEntity : cacheEntities) {
-            if (CommConsts.ADMIN_ROLE_CODE.equals(cacheEntity.getRoleCode())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * 是否是管理员
-     *
-     * @return
-     */
-    public static Boolean isAdmin(Long systemId) {
-        return isAdmin(SaTokenUtils.getId(Long.class), systemId);
-    }
-
-    /**
-     * 获取所有菜单接口uri
-     *
-     * @param loginId  登录id
-     * @param systemId 系统id
-     * @return
-     */
-    public static List<String> getMenuInterfaceUri(Long loginId, Long systemId) {
-        JList<String> list = new JArrayList<>();
-        //获取redis缓存
-        List<CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
-        if (!Emptys.check(cacheEntities)) {
-            return list;
-        }
-        //遍历角色
-        for (CacheEntity cacheEntity : cacheEntities) {
-            List<SysMenuJoinSysRoleMenu> sysMenuJoinSysRoleMenus = cacheEntity.getList();
-            list.addAll(new JArrayList<>(sysMenuJoinSysRoleMenus).filter()
-                    .isNotNull(SysMenuJoinSysRoleMenu::getInterfaceUri).list()
-                    .getProperty(SysMenuJoinSysRoleMenu::getInterfaceUri)
-            );
-        }
-        return list.comparing();
-    }
-
-    /**
-     * 获取所有菜单接口uri
-     *
-     * @param systemId 系统id
-     * @return
-     */
-    public static List<String> getMenuInterfaceUri(Long systemId) {
-        return getMenuInterfaceUri(SaTokenUtils.getId(Long.class), systemId);
-    }
-
-    @Data
-    @Accessors(chain = true)
-    public static class CacheEntity {
-
-        /**
-         * 角色id
-         */
-        private Long roleId;
-
-        /**
-         * 角色标识
-         */
-        private String roleCode;
-
-        /**
-         * 菜单集合
-         */
-        private List<SysMenuJoinSysRoleMenu> list;
-
-    }
-
 }

+ 1 - 3
authorize-api-service/src/main/java/com/xy/service/impl/SysMenuServiceImpl.java

@@ -2,15 +2,14 @@ package com.xy.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.xy.annotation.CheckSysId;
 import com.xy.collections.list.JArrayList;
 import com.xy.collections.list.JList;
 import com.xy.consts.CommConsts;
 import com.xy.dto.SysMenuDto;
 import com.xy.entity.SysMenu;
+import com.xy.entity.SysMenuJoinSysRoleMenu;
 import com.xy.entity.SysRole;
 import com.xy.entity.SysRoleMenu;
-import com.xy.entity.join.SysMenuJoinSysRoleMenu;
 import com.xy.mapper.SysMenuMapper;
 import com.xy.mapper.SysRoleMapper;
 import com.xy.mapper.SysRoleMenuMapper;
@@ -47,7 +46,6 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
     private SysRoleMapper sysRoleMapper;
 
     @Override
-    @CheckSysId
     @ApiOperation("用户菜单树")
     public R<List<SysMenuDto.Vo>> workMenu(SysMenuDto.WorkMenu workMenu) {
         List<SysMenuDto.Vo> list = new ArrayList<>();

+ 6 - 0
authorize-api-service/src/main/java/com/xy/service/impl/SysWorkUserServiceImpl.java

@@ -223,6 +223,12 @@ public class SysWorkUserServiceImpl extends ServiceImpl<SysWorkUserMapper, SysWo
 
     @Override
     public R<Boolean> authByData(AuthByInterface authByInterface) {
+        //登录鉴权
+        Boolean data = authByLogin().getData();
+        if (!data) {
+            return R.ok(false);
+        }
+        //数据鉴权
         long longId = Long.parseLong(SaTokenUtils.getId().toString());
         boolean dataAuth = RedisCache.getDataAuth(longId, authByInterface.getSystemId(), authByInterface.getUri());
         return R.ok(dataAuth);

+ 37 - 0
authorize-sdk/pom.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>xy-authorize</artifactId>
+        <groupId>com.xy</groupId>
+        <version>1.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>authorize-sdk</artifactId>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>xy-common</artifactId>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>xy-redis</artifactId>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>xy-satoken</artifactId>
+            <version>1.0</version>
+        </dependency>
+    </dependencies>
+</project>

+ 0 - 0
authorize-api-service/src/main/java/com/xy/consts/CommConsts.java → authorize-sdk/src/main/java/com/xy/consts/CommConsts.java


+ 90 - 0
authorize-sdk/src/main/java/com/xy/entity/SysMenuJoinSysRoleMenu.java

@@ -0,0 +1,90 @@
+package com.xy.entity;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * 菜单表和角色菜单表关联实体
+ */
+@Data
+@Accessors(chain = true)
+public class SysMenuJoinSysRoleMenu implements Serializable {
+
+    /**
+     * 角色id
+     */
+    private Long roleId;
+
+    /**
+     * 管理员数据查询权限
+     */
+    private Boolean selectIsAdmin;
+
+    /**
+     * 子级集合
+     */
+    private List<SysMenuJoinSysRoleMenu> sonSysMenu;
+
+    /**
+     * 父id
+     */
+    private Long paterId;
+
+    /**
+     * 系统id
+     */
+    private Long sysId;
+
+    /**
+     * 标识
+     */
+    private String code;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    /**
+     * 类型;1=导航列 2=数据页 3=数据接口
+     */
+    private Integer type;
+
+    /**
+     * 数据接口uri
+     */
+    private String interfaceUri;
+
+    /**
+     * 前端参数
+     */
+    private String webJson;
+
+    /**
+     * 状态
+     */
+    private Boolean status;
+
+    private Long id;
+
+    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
+    @JsonSerialize(using = LocalDateTimeSerializer.class)
+    private LocalDateTime createTime;
+
+    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
+    @JsonSerialize(using = LocalDateTimeSerializer.class)
+    private LocalDateTime updateTime;
+
+    private Long createUser;
+
+    private Long updateUser;
+}

+ 383 - 0
authorize-sdk/src/main/java/com/xy/utils/AuthorizeUtils.java

@@ -0,0 +1,383 @@
+package com.xy.utils;
+
+import cn.dev33.satoken.stp.StpUtil;
+import com.xy.collections.list.JArrayList;
+import com.xy.collections.list.JList;
+import com.xy.consts.CommConsts;
+import com.xy.entity.SysMenuJoinSysRoleMenu;
+import com.xy.error.CommRuntimeException;
+import lombok.Data;
+import lombok.experimental.Accessors;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class AuthorizeUtils {
+
+    protected static RedisService<List<CacheEntity>> getRedisService() {
+        return SpringBeanUtils.getBean(RedisService.class);
+    }
+
+    protected static String getKey(Long loginId) {
+        return String.format("%s:%d", "menu", loginId);
+    }
+
+    /**
+     * 获取菜单
+     *
+     * @param loginId  登录id
+     * @param systemId 系统id
+     * @return
+     */
+    public static List<SysMenuJoinSysRoleMenu> getMenu(Long loginId, Long systemId) {
+        JList<SysMenuJoinSysRoleMenu> sysMenuJoinSysRoleMenus = new JArrayList<>();
+        //获取redis缓存
+        List<AuthorizeUtils.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
+        if (!Emptys.check(cacheEntities)) {
+            return sysMenuJoinSysRoleMenus;
+        }
+        //角色菜单累加
+        cacheEntities.forEach(cacheEntity -> {
+            if (Emptys.check(cacheEntity.getList())) {
+                sysMenuJoinSysRoleMenus.addAll(cacheEntity.getList());
+            }
+        });
+        //去重
+        sysMenuJoinSysRoleMenus.comparing(SysMenuJoinSysRoleMenu::getId);
+        return sysMenuJoinSysRoleMenus;
+    }
+
+    /**
+     * 获取菜单
+     *
+     * @param systemId 系统id
+     * @return
+     */
+    public static List<SysMenuJoinSysRoleMenu> getMenu(String token, Long systemId) {
+        return getMenu(getLoginId(token, Long.class), systemId);
+    }
+
+    /**
+     * 获取菜单树
+     *
+     * @param loginId  登录id
+     * @param systemId 系统id
+     * @return
+     */
+    public static List<SysMenuJoinSysRoleMenu> getMenuTree(Long loginId, Long systemId) {
+        //获取菜单
+        JList<SysMenuJoinSysRoleMenu> sysMenuJoinSysRoleMenus = new JArrayList<>(getMenu(loginId, systemId));
+        //生成树
+        JList<SysMenuJoinSysRoleMenu> tops = sysMenuJoinSysRoleMenus.filter().isNull(SysMenuJoinSysRoleMenu::getPaterId).list();
+        for (SysMenuJoinSysRoleMenu top : tops) {
+            List<SysMenuJoinSysRoleMenu> tree = Beans.tree(top, sysMenuJoinSysRoleMenus, SysMenuJoinSysRoleMenu::getId, SysMenuJoinSysRoleMenu::getPaterId, SysMenuJoinSysRoleMenu::getSonSysMenu);
+            top.setSonSysMenu(tree);
+        }
+        return tops;
+    }
+
+    /**
+     * 获取菜单树
+     *
+     * @param systemId 系统id
+     * @return
+     */
+    public static List<SysMenuJoinSysRoleMenu> getMenuTree(String token, Long systemId) {
+        return getMenuTree(getLoginId(token, Long.class), systemId);
+    }
+
+    /**
+     * 判断数据查询权限
+     *
+     * @param loginId  登录id
+     * @param systemId 系统id
+     * @param systemId 接口uri
+     * @return true=管理员数据查询权限 false=普通查询权限
+     */
+    public static boolean getDataAuth(Long loginId, Long systemId, String uri) {
+        //获取redis缓存
+        List<AuthorizeUtils.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
+        if (!Emptys.check(cacheEntities)) {
+            return false;
+        }
+        //遍历角色
+        for (AuthorizeUtils.CacheEntity cacheEntity : cacheEntities) {
+            //根据 接口uri和管理员数据查询权限=true 查找角色菜单,找到则有管理员数据查询权限,反之普通查询权限
+            SysMenuJoinSysRoleMenu sysMenuJoinSysRoleMenu = new JArrayList<>(cacheEntity.getList()).filter()
+                    .eq(SysMenuJoinSysRoleMenu::getInterfaceUri, uri)
+                    .eq(SysMenuJoinSysRoleMenu::getSelectIsAdmin, true)
+                    .object();
+            if (sysMenuJoinSysRoleMenu != null) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 判断数据查询权限
+     *
+     * @param systemId 系统id
+     * @param systemId 接口uri
+     * @return true=管理员数据查询权限 false=普通查询权限
+     */
+    public static boolean getDataAuth(String token, Long systemId, String uri) {
+        return getDataAuth(getLoginId(token, Long.class), systemId, uri);
+    }
+
+    /**
+     * 获取所有系统ID
+     *
+     * @param loginId 登录id
+     * @return
+     */
+    public static List<Long> getSystemIds(Long loginId) {
+        Map<String, List<CacheEntity>> map = getRedisService().getMap(getKey(loginId));
+        if (!Emptys.check(map)) {
+            return new ArrayList<>();
+        }
+        List<Long> list = new ArrayList<>(map.size());
+        map.forEach((s, cacheEntities) -> list.add(Long.parseLong(s)));
+        return list;
+    }
+
+    /**
+     * 获取所有系统ID
+     *
+     * @return
+     */
+    public static List<Long> getSystemIds(String token) {
+        return getSystemIds(getLoginId(token, Long.class));
+    }
+
+    /**
+     * 检验系统ID是否属于当前登录人
+     *
+     * @param loginId  登录id
+     * @param systemId 系统id
+     * @return
+     */
+    public static Boolean checkSystemId(Long loginId, Long systemId) {
+        Map<String, List<AuthorizeUtils.CacheEntity>> map = getRedisService().getMap(getKey(loginId));
+        return map.containsKey(systemId.toString());
+    }
+
+    /**
+     * 检验系统ID是否属于当前登录人
+     *
+     * @param systemId 系统id
+     * @return
+     */
+    public static Boolean checkSystemId(String token, Long systemId) {
+        return checkSystemId(getLoginId(token, Long.class), systemId);
+    }
+
+    /**
+     * 检验系统ID是否属于当前登录人并抛出异常
+     *
+     * @param loginId  登录id
+     * @param systemId 系统id
+     * @return
+     */
+    public static void checkSystemIdByException(Long loginId, Long systemId) {
+        Boolean aBoolean = checkSystemId(loginId, systemId);
+        if (!aBoolean) {
+            throw new CommRuntimeException("系统不存在");
+        }
+    }
+
+    /**
+     * 检验系统ID是否属于当前登录人并抛出异常
+     *
+     * @param systemId 系统id
+     * @return
+     */
+    public static void checkSystemIdByException(String token, Long systemId) {
+        checkSystemIdByException(getLoginId(token, Long.class), systemId);
+    }
+
+    /**
+     * 获取所有角色ID
+     *
+     * @param loginId  登录id
+     * @param systemId 系统id
+     * @return
+     */
+    public static List<Long> getRoleIds(Long loginId, Long systemId) {
+        List<AuthorizeUtils.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
+        if (!Emptys.check(cacheEntities)) {
+            return new ArrayList<>();
+        }
+        List<Long> list = new ArrayList<>(cacheEntities.size());
+        cacheEntities.forEach(cacheEntity -> list.add(Long.parseLong(cacheEntity.getRoleId().toString())));
+        return list;
+    }
+
+    /**
+     * 获取所有角色ID
+     *
+     * @param systemId 系统id
+     * @return
+     */
+    public static List<Long> getRoleIds(String token, Long systemId) {
+        return getRoleIds(getLoginId(token, Long.class), systemId);
+    }
+
+    /**
+     * 是否是管理员
+     *
+     * @param loginId 登录id
+     * @return
+     */
+    public static Boolean isAdmin(Long loginId, Long systemId) {
+        List<AuthorizeUtils.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
+        if (!Emptys.check(cacheEntities)) {
+            return false;
+        }
+        for (AuthorizeUtils.CacheEntity cacheEntity : cacheEntities) {
+            if (CommConsts.ADMIN_ROLE_CODE.equals(cacheEntity.getRoleCode())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 是否是管理员
+     *
+     * @return
+     */
+    public static Boolean isAdmin(String token, Long systemId) {
+        return isAdmin(getLoginId(token, Long.class), systemId);
+    }
+
+    /**
+     * 获取所有菜单接口uri
+     *
+     * @param loginId  登录id
+     * @param systemId 系统id
+     * @return
+     */
+    public static List<String> getMenuInterfaceUri(Long loginId, Long systemId) {
+        JList<String> list = new JArrayList<>();
+        //获取redis缓存
+        List<AuthorizeUtils.CacheEntity> cacheEntities = getRedisService().getMap(getKey(loginId), systemId.toString());
+        if (!Emptys.check(cacheEntities)) {
+            return list;
+        }
+        //遍历角色
+        for (AuthorizeUtils.CacheEntity cacheEntity : cacheEntities) {
+            List<SysMenuJoinSysRoleMenu> sysMenuJoinSysRoleMenus = cacheEntity.getList();
+            list.addAll(new JArrayList<>(sysMenuJoinSysRoleMenus).filter()
+                    .isNotNull(SysMenuJoinSysRoleMenu::getInterfaceUri).list()
+                    .getProperty(SysMenuJoinSysRoleMenu::getInterfaceUri)
+            );
+        }
+        return list.comparing();
+    }
+
+    /**
+     * 获取所有菜单接口uri
+     *
+     * @param systemId 系统id
+     * @return
+     */
+    public static List<String> getMenuInterfaceUri(String token, Long systemId) {
+        return getMenuInterfaceUri(getLoginId(token, Long.class), systemId);
+    }
+
+    /**
+     * 登录鉴权
+     *
+     * @return
+     */
+    public static boolean authByLogin(String token) {
+        if (!Emptys.check(token)) {
+            return false;
+        }
+        Object loginIdByToken = StpUtil.getLoginIdByToken(token);
+        if (loginIdByToken == null) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 接口鉴权
+     *
+     * @param systemId 系统id
+     * @return
+     */
+    public static boolean authByInterface(String token, Long systemId, String uri) {
+        //登录鉴权
+        Boolean data = authByLogin(token);
+        if (!data) {
+            return false;
+        }
+        //接口鉴权
+        List<String> menuInterfaceUri = getMenuInterfaceUri(getLoginId(token, Long.class), systemId);
+        if (!menuInterfaceUri.contains(uri)) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 数据鉴权
+     *
+     * @param systemId 系统id
+     * @return
+     */
+    public static boolean authByData(String token, Long systemId, String uri) {
+        //登录鉴权
+        Boolean data = authByLogin(token);
+        if (!data) {
+            return false;
+        }
+        //数据鉴权
+        long longId = getLoginId(token, Long.class);
+        return getDataAuth(longId, systemId, uri);
+    }
+
+    /**
+     * 获取登录id
+     *
+     * @param token
+     * @param tClass
+     * @param <T>
+     * @return
+     */
+    public static <T> T getLoginId(String token, Class<T> tClass) {
+        Object id = StpUtil.getLoginIdByToken(token);
+        String idStr = id.toString();
+        return tClass.equals(Long.class) ? (T) Long.valueOf(idStr)
+                : tClass.equals(Integer.class) ? (T) Integer.valueOf(idStr)
+                : tClass.equals(String.class) ? (T) idStr
+                : (T) id;
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class CacheEntity implements Serializable {
+
+        /**
+         * 角色id
+         */
+        private Long roleId;
+
+        /**
+         * 角色标识
+         */
+        private String roleCode;
+
+        /**
+         * 菜单集合
+         */
+        private List<SysMenuJoinSysRoleMenu> list;
+
+    }
+}

+ 1 - 0
pom.xml

@@ -12,6 +12,7 @@
         <module>authorize-api-cloud</module>
         <module>authorize-api-service</module>
         <module>authorize-start</module>
+        <module>authorize-sdk</module>
     </modules>
     <packaging>pom</packaging>