forked from chillzhuang/SpringBlade
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
smallchill
committed
Nov 4, 2021
1 parent
d15f223
commit 5914f6c
Showing
75 changed files
with
1,826 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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>blade-service-api</artifactId> | ||
<groupId>org.springblade</groupId> | ||
<version>3.2.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>blade-scope-api</artifactId> | ||
<name>${project.artifactId}</name> | ||
<version>${blade.project.version}</version> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springblade</groupId> | ||
<artifactId>blade-core-secure</artifactId> | ||
<version>${blade.tool.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springblade</groupId> | ||
<artifactId>blade-core-datascope</artifactId> | ||
<version>${blade.tool.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
92 changes: 92 additions & 0 deletions
92
...ervice-api/blade-scope-api/src/main/java/org/springblade/system/cache/DataScopeCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 ([email protected]). | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springblade.system.cache; | ||
|
||
import org.springblade.core.datascope.model.DataScopeModel; | ||
import org.springblade.core.tool.utils.*; | ||
import org.springblade.system.feign.IDataScopeClient; | ||
|
||
import java.util.List; | ||
|
||
import static org.springblade.core.tool.utils.CacheUtil.SYS_CACHE; | ||
|
||
|
||
/** | ||
* 数据权限缓存 | ||
* | ||
* @author Chill | ||
*/ | ||
public class DataScopeCache { | ||
|
||
private static final String SCOPE_CACHE_CODE = "dataScope:code:"; | ||
private static final String SCOPE_CACHE_CLASS = "dataScope:class:"; | ||
private static final String DEPT_CACHE_ANCESTORS = "dept:ancestors:"; | ||
|
||
private static IDataScopeClient dataScopeClient; | ||
|
||
private static IDataScopeClient getDataScopeClient() { | ||
if (dataScopeClient == null) { | ||
dataScopeClient = SpringUtil.getBean(IDataScopeClient.class); | ||
} | ||
return dataScopeClient; | ||
} | ||
|
||
/** | ||
* 获取数据权限 | ||
* | ||
* @param mapperId 数据权限mapperId | ||
* @param roleId 用户角色集合 | ||
* @return DataScopeModel | ||
*/ | ||
public static DataScopeModel getDataScopeByMapper(String mapperId, String roleId) { | ||
DataScopeModel dataScope = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_CLASS, mapperId + StringPool.COLON + roleId, DataScopeModel.class); | ||
if (dataScope == null || !dataScope.getSearched()) { | ||
dataScope = getDataScopeClient().getDataScopeByMapper(mapperId, roleId); | ||
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_CLASS, mapperId + StringPool.COLON + roleId, dataScope); | ||
} | ||
return StringUtil.isNotBlank(dataScope.getResourceCode()) ? dataScope : null; | ||
} | ||
|
||
/** | ||
* 获取数据权限 | ||
* | ||
* @param code 数据权限资源编号 | ||
* @return DataScopeModel | ||
*/ | ||
public static DataScopeModel getDataScopeByCode(String code) { | ||
DataScopeModel dataScope = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_CODE, code, DataScopeModel.class); | ||
if (dataScope == null || !dataScope.getSearched()) { | ||
dataScope = getDataScopeClient().getDataScopeByCode(code); | ||
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_CODE, code, dataScope); | ||
} | ||
return StringUtil.isNotBlank(dataScope.getResourceCode()) ? dataScope : null; | ||
} | ||
|
||
/** | ||
* 获取部门子级 | ||
* | ||
* @param deptId 部门id | ||
* @return deptIds | ||
*/ | ||
public static List<Long> getDeptAncestors(Long deptId) { | ||
List ancestors = CacheUtil.get(SYS_CACHE, DEPT_CACHE_ANCESTORS, deptId, List.class); | ||
if (CollectionUtil.isEmpty(ancestors)) { | ||
ancestors = getDataScopeClient().getDeptAncestors(deptId); | ||
CacheUtil.put(SYS_CACHE, DEPT_CACHE_ANCESTORS, deptId, ancestors); | ||
} | ||
return ancestors; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...e-api/blade-scope-api/src/main/java/org/springblade/system/config/ScopeConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 ([email protected]). | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springblade.system.config; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import org.springblade.core.datascope.handler.ScopeModelHandler; | ||
import org.springblade.core.secure.config.RegistryConfiguration; | ||
import org.springblade.system.handler.DataScopeModelHandler; | ||
import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* 公共封装包配置类 | ||
* | ||
* @author Chill | ||
*/ | ||
@Configuration | ||
@AllArgsConstructor | ||
@AutoConfigureBefore(RegistryConfiguration.class) | ||
public class ScopeConfiguration { | ||
|
||
@Bean | ||
public ScopeModelHandler scopeModelHandler() { | ||
return new DataScopeModelHandler(); | ||
} | ||
|
||
} |
Oops, something went wrong.