diff --git a/README.md b/README.md index c8feef6..ba16447 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@

- Downloads + Downloads Build Status Build Status Coverage Status - Downloads + Downloads Downloads @@ -186,6 +186,3 @@ Apache Licence也是对商业应用友好的许可。使用者也可以在需要 - -## 关注我们 -![](https://images.gitee.com/uploads/images/2019/0330/065148_f0ada806_410595.jpeg) \ No newline at end of file diff --git a/blade-auth/pom.xml b/blade-auth/pom.xml index c3467fe..cd348d3 100644 --- a/blade-auth/pom.xml +++ b/blade-auth/pom.xml @@ -8,7 +8,7 @@ SpringBlade org.springblade - 3.1.0 + 3.2.0 blade-auth diff --git a/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java b/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java index 912a1a8..5de8370 100644 --- a/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java +++ b/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java @@ -61,6 +61,7 @@ public class TokenUtil { param.put(TokenConstant.OAUTH_ID, userInfo.getOauthId()); param.put(TokenConstant.USER_ID, Func.toStr(user.getId())); param.put(TokenConstant.ROLE_ID, user.getRoleId()); + param.put(TokenConstant.DEPT_ID, user.getDeptId()); param.put(TokenConstant.ACCOUNT, user.getAccount()); param.put(TokenConstant.USER_NAME, user.getAccount()); param.put(TokenConstant.ROLE_NAME, Func.join(userInfo.getRoles())); diff --git a/blade-common/pom.xml b/blade-common/pom.xml index a167f87..2ff4b64 100644 --- a/blade-common/pom.xml +++ b/blade-common/pom.xml @@ -5,7 +5,7 @@ SpringBlade org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-gateway/pom.xml b/blade-gateway/pom.xml index b5ec77e..49f2049 100644 --- a/blade-gateway/pom.xml +++ b/blade-gateway/pom.xml @@ -5,7 +5,7 @@ SpringBlade org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java b/blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java index 1e29459..0e5a7f0 100644 --- a/blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java +++ b/blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java @@ -61,7 +61,7 @@ public class AuthFilter implements GlobalFilter, Ordered { ServerHttpResponse resp = exchange.getResponse(); String headerToken = exchange.getRequest().getHeaders().getFirst(AuthProvider.AUTH_KEY); String paramToken = exchange.getRequest().getQueryParams().getFirst(AuthProvider.AUTH_KEY); - if (StringUtils.isAllBlank(headerToken, paramToken)) { + if (StringUtils.isBlank(headerToken) && StringUtils.isBlank(paramToken)) { return unAuth(resp, "缺失令牌,鉴权失败"); } String auth = StringUtils.isBlank(headerToken) ? paramToken : headerToken; diff --git a/blade-ops/blade-admin/pom.xml b/blade-ops/blade-admin/pom.xml index cce71b3..f1d835c 100644 --- a/blade-ops/blade-admin/pom.xml +++ b/blade-ops/blade-admin/pom.xml @@ -5,7 +5,7 @@ blade-ops org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-ops/blade-develop/pom.xml b/blade-ops/blade-develop/pom.xml index aecc99b..350af89 100644 --- a/blade-ops/blade-develop/pom.xml +++ b/blade-ops/blade-develop/pom.xml @@ -6,7 +6,7 @@ org.springblade blade-ops - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-ops/blade-report/pom.xml b/blade-ops/blade-report/pom.xml index 933269a..99ed51d 100644 --- a/blade-ops/blade-report/pom.xml +++ b/blade-ops/blade-report/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-ops - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-ops/blade-resource/pom.xml b/blade-ops/blade-resource/pom.xml index 377a0bb..6d2f36a 100644 --- a/blade-ops/blade-resource/pom.xml +++ b/blade-ops/blade-resource/pom.xml @@ -5,7 +5,7 @@ blade-ops org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-ops/blade-seata-order/pom.xml b/blade-ops/blade-seata-order/pom.xml index 0ce4b87..0a7e5e3 100644 --- a/blade-ops/blade-seata-order/pom.xml +++ b/blade-ops/blade-seata-order/pom.xml @@ -5,7 +5,7 @@ blade-ops org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-ops/blade-seata-storage/pom.xml b/blade-ops/blade-seata-storage/pom.xml index d8cffc4..97c0ef1 100644 --- a/blade-ops/blade-seata-storage/pom.xml +++ b/blade-ops/blade-seata-storage/pom.xml @@ -5,7 +5,7 @@ blade-ops org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-ops/blade-swagger/pom.xml b/blade-ops/blade-swagger/pom.xml index 7435ff0..695223e 100644 --- a/blade-ops/blade-swagger/pom.xml +++ b/blade-ops/blade-swagger/pom.xml @@ -5,7 +5,7 @@ blade-ops org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-ops/pom.xml b/blade-ops/pom.xml index 06e2d85..2c8ddc0 100644 --- a/blade-ops/pom.xml +++ b/blade-ops/pom.xml @@ -5,13 +5,13 @@ SpringBlade org.springblade - 3.1.0 + 3.2.0 4.0.0 blade-ops ${project.artifactId} - 3.1.0 + 3.2.0 pom blade-admin diff --git a/blade-service-api/blade-demo-api/pom.xml b/blade-service-api/blade-demo-api/pom.xml index b183541..2fca853 100644 --- a/blade-service-api/blade-demo-api/pom.xml +++ b/blade-service-api/blade-demo-api/pom.xml @@ -5,7 +5,7 @@ blade-service-api org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service-api/blade-desk-api/pom.xml b/blade-service-api/blade-desk-api/pom.xml index 240136b..9258727 100644 --- a/blade-service-api/blade-desk-api/pom.xml +++ b/blade-service-api/blade-desk-api/pom.xml @@ -5,7 +5,7 @@ blade-service-api org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service-api/blade-dict-api/pom.xml b/blade-service-api/blade-dict-api/pom.xml index 2652398..bde6b39 100644 --- a/blade-service-api/blade-dict-api/pom.xml +++ b/blade-service-api/blade-dict-api/pom.xml @@ -5,7 +5,7 @@ blade-service-api org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service-api/blade-scope-api/pom.xml b/blade-service-api/blade-scope-api/pom.xml new file mode 100644 index 0000000..43487bd --- /dev/null +++ b/blade-service-api/blade-scope-api/pom.xml @@ -0,0 +1,30 @@ + + + + blade-service-api + org.springblade + 3.2.0 + + 4.0.0 + + blade-scope-api + ${project.artifactId} + ${blade.project.version} + jar + + + + org.springblade + blade-core-secure + ${blade.tool.version} + + + org.springblade + blade-core-datascope + ${blade.tool.version} + + + + diff --git a/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/cache/DataScopeCache.java b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/cache/DataScopeCache.java new file mode 100644 index 0000000..a55a156 --- /dev/null +++ b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/cache/DataScopeCache.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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 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; + } +} diff --git a/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/config/ScopeConfiguration.java b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/config/ScopeConfiguration.java new file mode 100644 index 0000000..365d5e7 --- /dev/null +++ b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/config/ScopeConfiguration.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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(); + } + +} diff --git a/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/feign/IDataScopeClient.java b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/feign/IDataScopeClient.java new file mode 100644 index 0000000..6dc5b16 --- /dev/null +++ b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/feign/IDataScopeClient.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.feign; + +import org.springblade.core.datascope.model.DataScopeModel; +import org.springblade.core.launch.constant.AppConstant; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; + +/** + * 数据权限Feign接口类 + * + * @author Chill + */ +@FeignClient( + value = AppConstant.APPLICATION_SYSTEM_NAME, + fallback = IDataScopeClientFallback.class +) +public interface IDataScopeClient { + + String API_PREFIX = "/client/data-scope"; + String GET_DATA_SCOPE_BY_MAPPER = API_PREFIX + "/by-mapper"; + String GET_DATA_SCOPE_BY_CODE = API_PREFIX + "/by-code"; + String GET_DEPT_ANCESTORS = API_PREFIX + "/dept-ancestors"; + + /** + * 获取数据权限 + * + * @param mapperId 数据权限mapperId + * @param roleId 用户角色集合 + * @return DataScopeModel + */ + @GetMapping(GET_DATA_SCOPE_BY_MAPPER) + DataScopeModel getDataScopeByMapper(@RequestParam("mapperId") String mapperId, @RequestParam("roleId") String roleId); + + /** + * 获取数据权限 + * + * @param code 数据权限资源编号 + * @return DataScopeModel + */ + @GetMapping(GET_DATA_SCOPE_BY_CODE) + DataScopeModel getDataScopeByCode(@RequestParam("code") String code); + + /** + * 获取部门子级 + * + * @param deptId 部门id + * @return deptIds + */ + @GetMapping(GET_DEPT_ANCESTORS) + List getDeptAncestors(@RequestParam("deptId") Long deptId); + + +} diff --git a/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/feign/IDataScopeClientFallback.java b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/feign/IDataScopeClientFallback.java new file mode 100644 index 0000000..abcd35a --- /dev/null +++ b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/feign/IDataScopeClientFallback.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.feign; + +import org.springblade.core.datascope.model.DataScopeModel; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * IDataScopeClientFallback + * + * @author Chill + */ +@Component +public class IDataScopeClientFallback implements IDataScopeClient { + @Override + public DataScopeModel getDataScopeByMapper(String mapperId, String roleId) { + return null; + } + + @Override + public DataScopeModel getDataScopeByCode(String code) { + return null; + } + + @Override + public List getDeptAncestors(Long deptId) { + return null; + } +} diff --git a/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/handler/DataScopeModelHandler.java b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/handler/DataScopeModelHandler.java new file mode 100644 index 0000000..2e7cb67 --- /dev/null +++ b/blade-service-api/blade-scope-api/src/main/java/org/springblade/system/handler/DataScopeModelHandler.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.handler; + +import org.springblade.core.datascope.handler.ScopeModelHandler; +import org.springblade.core.datascope.model.DataScopeModel; +import org.springblade.system.cache.DataScopeCache; + +import java.util.List; + +/** + * 通用数据权限规则 + * + * @author Chill + */ +public class DataScopeModelHandler implements ScopeModelHandler { + + /** + * 获取数据权限 + * + * @param mapperId 数据权限mapperId + * @param roleId 用户角色集合 + * @return DataScopeModel + */ + @Override + public DataScopeModel getDataScopeByMapper(String mapperId, String roleId) { + return DataScopeCache.getDataScopeByMapper(mapperId, roleId); + } + + /** + * 获取数据权限 + * + * @param code 数据权限资源编号 + * @return DataScopeModel + */ + @Override + public DataScopeModel getDataScopeByCode(String code) { + return DataScopeCache.getDataScopeByCode(code); + } + + /** + * 获取部门子级 + * + * @param deptId 部门id + * @return deptIds + */ + @Override + public List getDeptAncestors(Long deptId) { + return DataScopeCache.getDeptAncestors(deptId); + } +} diff --git a/blade-service-api/blade-system-api/pom.xml b/blade-service-api/blade-system-api/pom.xml index 0fe4c24..c788723 100644 --- a/blade-service-api/blade-system-api/pom.xml +++ b/blade-service-api/blade-system-api/pom.xml @@ -5,7 +5,7 @@ blade-service-api org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/DataScope.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/DataScope.java new file mode 100644 index 0000000..486763d --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/DataScope.java @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +/** + * 实体类 + * + * @author BladeX + */ +@Data +@TableName("blade_scope_data") +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "DataScope对象", description = "DataScope对象") +public class DataScope extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @ApiModelProperty(value = "主键") + @TableId(value = "id", type = IdType.ASSIGN_ID) + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + /** + * 菜单主键 + */ + @ApiModelProperty(value = "菜单主键") + private Long menuId; + /** + * 资源编号 + */ + @ApiModelProperty(value = "资源编号") + private String resourceCode; + /** + * 数据权限名称 + */ + @ApiModelProperty(value = "数据权限名称") + private String scopeName; + /** + * 数据权限可见字段 + */ + @ApiModelProperty(value = "数据权限可见字段") + private String scopeField; + /** + * 数据权限类名 + */ + @ApiModelProperty(value = "数据权限类名") + private String scopeClass; + /** + * 数据权限字段 + */ + @ApiModelProperty(value = "数据权限字段") + private String scopeColumn; + /** + * 数据权限类型 + */ + @ApiModelProperty(value = "数据权限类型") + private Integer scopeType; + /** + * 数据权限值域 + */ + @ApiModelProperty(value = "数据权限值域") + private String scopeValue; + /** + * 数据权限备注 + */ + @ApiModelProperty(value = "数据权限备注") + private String remark; + + +} diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Dept.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Dept.java index 9350877..367daec 100644 --- a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Dept.java +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Dept.java @@ -60,6 +60,12 @@ public class Dept implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long parentId; + /** + * 祖级机构主键 + */ + @ApiModelProperty(value = "祖级机构主键") + private String ancestors; + /** * 部门名 */ diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/RoleScope.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/RoleScope.java new file mode 100644 index 0000000..756a015 --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/RoleScope.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 实体类 + * + * @author Chill + */ +@Data +@TableName("blade_role_scope") +@ApiModel(value = "RoleScope对象", description = "RoleScope对象") +public class RoleScope implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @JsonSerialize(using = ToStringSerializer.class) + @ApiModelProperty(value = "主键") + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 权限id + */ + @JsonSerialize(using = ToStringSerializer.class) + @ApiModelProperty(value = "权限id") + private Long scopeId; + + /** + * 角色id + */ + @JsonSerialize(using = ToStringSerializer.class) + @ApiModelProperty(value = "角色id") + private Long roleId; + + +} diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/CheckedTreeVO.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/CheckedTreeVO.java new file mode 100644 index 0000000..7156c7a --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/CheckedTreeVO.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.vo; + +import lombok.Data; + +import java.util.List; + +/** + * CheckedTreeVO + * + * @author Chill + */ +@Data +public class CheckedTreeVO { + + private List menu; + + private List dataScope; + +} diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DataScopeVO.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DataScopeVO.java new file mode 100644 index 0000000..59c8d40 --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DataScopeVO.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.vo; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.system.entity.DataScope; + +/** + * 视图实体类 + * + * @author Chill + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "DataScopeVO对象", description = "DataScopeVO对象") +public class DataScopeVO extends DataScope { + private static final long serialVersionUID = 1L; + + /** + * 规则类型名 + */ + private String scopeTypeName; +} diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantTreeVO.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantTreeVO.java new file mode 100644 index 0000000..4d9c144 --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantTreeVO.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.vo; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * GrantTreeVO + * + * @author Chill + */ +@Data +public class GrantTreeVO implements Serializable { + private static final long serialVersionUID = 1L; + + private List menu; + + private List dataScope; + +} diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantVO.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantVO.java index 79797f1..31cbc80 100644 --- a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantVO.java +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantVO.java @@ -36,4 +36,7 @@ public class GrantVO implements Serializable { @ApiModelProperty(value = "menuIds集合") private List menuIds; + @ApiModelProperty(value = "dataScopeIds集合") + private List dataScopeIds; + } diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/MenuVO.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/MenuVO.java index b27071f..60a76ae 100644 --- a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/MenuVO.java +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/MenuVO.java @@ -56,6 +56,12 @@ public class MenuVO extends Menu implements INode { @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children; + /** + * 是否有子孙节点 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private Boolean hasChildren; + @Override public List getChildren() { if (this.children == null) { diff --git a/blade-service-api/blade-user-api/pom.xml b/blade-service-api/blade-user-api/pom.xml index be91de0..b7a50bb 100644 --- a/blade-service-api/blade-user-api/pom.xml +++ b/blade-service-api/blade-user-api/pom.xml @@ -5,7 +5,7 @@ blade-service-api org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service-api/pom.xml b/blade-service-api/pom.xml index 0c47684..617c26e 100644 --- a/blade-service-api/pom.xml +++ b/blade-service-api/pom.xml @@ -5,13 +5,13 @@ SpringBlade org.springblade - 3.1.0 + 3.2.0 4.0.0 blade-service-api ${project.artifactId} - 3.1.0 + 3.2.0 pom SpringBlade 微服务API集合 @@ -20,6 +20,7 @@ blade-dict-api blade-system-api blade-user-api + blade-scope-api blade-demo-api diff --git a/blade-service/blade-demo/pom.xml b/blade-service/blade-demo/pom.xml index c9b6d2e..8c52f70 100644 --- a/blade-service/blade-demo/pom.xml +++ b/blade-service/blade-demo/pom.xml @@ -5,7 +5,7 @@ blade-service org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service/blade-desk/pom.xml b/blade-service/blade-desk/pom.xml index 3fd8813..f7304c9 100644 --- a/blade-service/blade-desk/pom.xml +++ b/blade-service/blade-desk/pom.xml @@ -6,7 +6,7 @@ org.springblade blade-service - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service/blade-desk/src/test/java/BladeDemoTest.java b/blade-service/blade-desk/src/test/java/BladeDemoTest.java index 86ed5a3..66e31da 100644 --- a/blade-service/blade-desk/src/test/java/BladeDemoTest.java +++ b/blade-service/blade-desk/src/test/java/BladeDemoTest.java @@ -22,7 +22,7 @@ public class BladeDemoTest { @Test public void contextLoads() { - int count = noticeService.count(); + Long count = noticeService.count(); System.out.println("notice数量:[" + count + "] 个"); } diff --git a/blade-service/blade-log/pom.xml b/blade-service/blade-log/pom.xml index 22cc540..67e8c3b 100644 --- a/blade-service/blade-log/pom.xml +++ b/blade-service/blade-log/pom.xml @@ -5,7 +5,7 @@ blade-service org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service/blade-system/pom.xml b/blade-service/blade-system/pom.xml index 548fb4c..201430b 100644 --- a/blade-service/blade-system/pom.xml +++ b/blade-service/blade-system/pom.xml @@ -5,7 +5,7 @@ blade-service org.springblade - 3.1.0 + 3.2.0 4.0.0 diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/DataScopeController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/DataScopeController.java new file mode 100644 index 0000000..214055e --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/DataScopeController.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CacheUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.system.entity.DataScope; +import org.springblade.system.service.IDataScopeService; +import org.springblade.system.vo.DataScopeVO; +import org.springblade.system.wrapper.DataScopeWrapper; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import static org.springblade.core.tool.utils.CacheUtil.SYS_CACHE; + +/** + * 数据权限控制器 + * + * @author BladeX + */ +@RestController +@AllArgsConstructor +@RequestMapping("/data-scope") +@Api(value = "数据权限", tags = "数据权限") +public class DataScopeController extends BladeController { + + private final IDataScopeService dataScopeService; + + /** + * 详情 + */ + @GetMapping("/detail") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "详情", notes = "传入dataScope") + public R detail(DataScope dataScope) { + DataScope detail = dataScopeService.getOne(Condition.getQueryWrapper(dataScope)); + return R.data(detail); + } + + /** + * 分页 + */ + @GetMapping("/list") + @ApiOperationSupport(order = 2) + @ApiOperation(value = "分页", notes = "传入dataScope") + public R> list(DataScope dataScope, Query query) { + IPage pages = dataScopeService.page(Condition.getPage(query), Condition.getQueryWrapper(dataScope)); + return R.data(DataScopeWrapper.build().pageVO(pages)); + } + + /** + * 新增 + */ + @PostMapping("/save") + @ApiOperationSupport(order = 3) + @ApiOperation(value = "新增", notes = "传入dataScope") + public R save(@Valid @RequestBody DataScope dataScope) { + CacheUtil.clear(SYS_CACHE); + return R.status(dataScopeService.save(dataScope)); + } + + /** + * 修改 + */ + @PostMapping("/update") + @ApiOperationSupport(order = 4) + @ApiOperation(value = "修改", notes = "传入dataScope") + public R update(@Valid @RequestBody DataScope dataScope) { + CacheUtil.clear(SYS_CACHE); + return R.status(dataScopeService.updateById(dataScope)); + } + + /** + * 新增或修改 + */ + @PostMapping("/submit") + @ApiOperationSupport(order = 5) + @ApiOperation(value = "新增或修改", notes = "传入dataScope") + public R submit(@Valid @RequestBody DataScope dataScope) { + CacheUtil.clear(SYS_CACHE); + return R.status(dataScopeService.saveOrUpdate(dataScope)); + } + + + /** + * 删除 + */ + @PostMapping("/remove") + @ApiOperationSupport(order = 6) + @ApiOperation(value = "逻辑删除", notes = "传入ids") + public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { + CacheUtil.clear(SYS_CACHE); + return R.status(dataScopeService.deleteLogic(Func.toLongList(ids))); + } + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java index 5e161cc..8800e96 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java @@ -96,11 +96,8 @@ public class DeptController extends BladeController { @PostMapping("/submit") @ApiOperationSupport(order = 4) @ApiOperation(value = "新增或修改", notes = "传入dept") - public R submit(@Valid @RequestBody Dept dept, BladeUser user) { - if (Func.isEmpty(dept.getId())) { - dept.setTenantId(user.getTenantId()); - } - return R.status(deptService.saveOrUpdate(dept)); + public R submit(@Valid @RequestBody Dept dept) { + return R.status(deptService.submit(dept)); } /** diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java index aa19580..30836e8 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java @@ -28,6 +28,8 @@ import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.Func; import org.springblade.system.entity.Menu; import org.springblade.system.service.IMenuService; +import org.springblade.system.vo.CheckedTreeVO; +import org.springblade.system.vo.GrantTreeVO; import org.springblade.system.vo.MenuVO; import org.springblade.system.wrapper.MenuWrapper; import org.springframework.web.bind.annotation.*; @@ -74,17 +76,48 @@ public class MenuController extends BladeController { @ApiOperationSupport(order = 2) @ApiOperation(value = "列表", notes = "传入menu") public R> list(@ApiIgnore @RequestParam Map menu) { - @SuppressWarnings("unchecked") List

list = menuService.list(Condition.getQueryWrapper(menu, Menu.class).lambda().orderByAsc(Menu::getSort)); return R.data(MenuWrapper.build().listNodeVO(list)); } + /** + * 菜单列表 + */ + @GetMapping("/menu-list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "菜单编号", paramType = "query", dataType = "string"), + @ApiImplicitParam(name = "name", value = "菜单名称", paramType = "query", dataType = "string") + }) + @PreAuth(RoleConstant.HAS_ROLE_ADMIN) + @ApiOperationSupport(order = 3) + @ApiOperation(value = "菜单列表", notes = "传入menu") + public R> menuList(@ApiIgnore @RequestParam Map menu) { + List list = menuService.list(Condition.getQueryWrapper(menu, Menu.class).lambda().eq(Menu::getCategory, 1).orderByAsc(Menu::getSort)); + return R.data(MenuWrapper.build().listNodeVO(list)); + } + + /** + * 懒加载菜单列表 + */ + @GetMapping("/lazy-menu-list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "菜单编号", paramType = "query", dataType = "string"), + @ApiImplicitParam(name = "name", value = "菜单名称", paramType = "query", dataType = "string") + }) + @PreAuth(RoleConstant.HAS_ROLE_ADMIN) + @ApiOperationSupport(order = 4) + @ApiOperation(value = "懒加载菜单列表", notes = "传入menu") + public R> lazyMenuList(Long parentId, @ApiIgnore @RequestParam Map menu) { + List list = menuService.lazyMenuList(parentId, menu); + return R.data(MenuWrapper.build().listNodeLazyVO(list)); + } + /** * 新增或修改 */ @PostMapping("/submit") @PreAuth(RoleConstant.HAS_ROLE_ADMIN) - @ApiOperationSupport(order = 3) + @ApiOperationSupport(order = 5) @ApiOperation(value = "新增或修改", notes = "传入menu") public R submit(@Valid @RequestBody Menu menu) { return R.status(menuService.saveOrUpdate(menu)); @@ -96,7 +129,7 @@ public class MenuController extends BladeController { */ @PostMapping("/remove") @PreAuth(RoleConstant.HAS_ROLE_ADMIN) - @ApiOperationSupport(order = 4) + @ApiOperationSupport(order = 6) @ApiOperation(value = "删除", notes = "传入ids") public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { return R.status(menuService.removeByIds(Func.toLongList(ids))); @@ -106,7 +139,7 @@ public class MenuController extends BladeController { * 前端菜单数据 */ @GetMapping("/routes") - @ApiOperationSupport(order = 5) + @ApiOperationSupport(order = 7) @ApiOperation(value = "前端菜单数据", notes = "前端菜单数据") public R> routes(BladeUser user) { List list = menuService.routes((user == null || user.getUserId() == 0L) ? null : user.getRoleId()); @@ -117,7 +150,7 @@ public class MenuController extends BladeController { * 前端按钮数据 */ @GetMapping("/buttons") - @ApiOperationSupport(order = 6) + @ApiOperationSupport(order = 8) @ApiOperation(value = "前端按钮数据", notes = "前端按钮数据") public R> buttons(BladeUser user) { List list = menuService.buttons(user.getRoleId()); @@ -128,7 +161,7 @@ public class MenuController extends BladeController { * 获取菜单树形结构 */ @GetMapping("/tree") - @ApiOperationSupport(order = 7) + @ApiOperationSupport(order = 9) @ApiOperation(value = "树形结构", notes = "树形结构") public R> tree() { List tree = menuService.tree(); @@ -139,27 +172,33 @@ public class MenuController extends BladeController { * 获取权限分配树形结构 */ @GetMapping("/grant-tree") - @ApiOperationSupport(order = 8) + @ApiOperationSupport(order = 10) @ApiOperation(value = "权限分配树形结构", notes = "权限分配树形结构") - public R> grantTree(BladeUser user) { - return R.data(menuService.grantTree(user)); + public R grantTree(BladeUser user) { + GrantTreeVO vo = new GrantTreeVO(); + vo.setMenu(menuService.grantTree(user)); + vo.setDataScope(menuService.grantDataScopeTree(user)); + return R.data(vo); } /** * 获取权限分配树形结构 */ @GetMapping("/role-tree-keys") - @ApiOperationSupport(order = 9) + @ApiOperationSupport(order = 11) @ApiOperation(value = "角色所分配的树", notes = "角色所分配的树") - public R> roleTreeKeys(String roleIds) { - return R.data(menuService.roleTreeKeys(roleIds)); + public R roleTreeKeys(String roleIds) { + CheckedTreeVO vo = new CheckedTreeVO(); + vo.setMenu(menuService.roleTreeKeys(roleIds)); + vo.setDataScope(menuService.dataScopeTreeKeys(roleIds)); + return R.data(vo); } /** * 获取配置的角色权限 */ @GetMapping("auth-routes") - @ApiOperationSupport(order = 10) + @ApiOperationSupport(order = 12) @ApiOperation(value = "菜单的角色权限") public R> authRoutes(BladeUser user) { if (Func.isEmpty(user) || user.getUserId() == 0L) { diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java index f9d1f71..ef365de 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java @@ -25,6 +25,7 @@ import org.springblade.core.secure.BladeUser; import org.springblade.core.tool.api.R; import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.node.INode; +import org.springblade.core.tool.utils.CacheUtil; import org.springblade.core.tool.utils.Func; import org.springblade.system.entity.Role; import org.springblade.system.service.IRoleService; @@ -38,6 +39,8 @@ import javax.validation.Valid; import java.util.List; import java.util.Map; +import static org.springblade.core.tool.utils.CacheUtil.SYS_CACHE; + /** * 控制器 * @@ -89,27 +92,41 @@ public class RoleController extends BladeController { return R.data(tree); } + + /** + * 获取指定角色树形结构 + */ + @GetMapping("/tree-by-id") + @ApiOperationSupport(order = 4) + @ApiOperation(value = "树形结构", notes = "树形结构") + public R> treeById(Long roleId, BladeUser bladeUser) { + Role role = roleService.getById(roleId); + List tree = roleService.tree(Func.notNull(role) ? role.getTenantId() : bladeUser.getTenantId()); + return R.data(tree); + } + /** * 新增或修改 */ @PostMapping("/submit") - @ApiOperationSupport(order = 4) + @ApiOperationSupport(order = 5) @ApiOperation(value = "新增或修改", notes = "传入role") public R submit(@Valid @RequestBody Role role, BladeUser user) { + CacheUtil.clear(SYS_CACHE); if (Func.isEmpty(role.getId())) { role.setTenantId(user.getTenantId()); } return R.status(roleService.saveOrUpdate(role)); } - /** * 删除 */ @PostMapping("/remove") - @ApiOperationSupport(order = 5) + @ApiOperationSupport(order = 6) @ApiOperation(value = "删除", notes = "传入ids") public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { + CacheUtil.clear(SYS_CACHE); return R.status(roleService.removeByIds(Func.toLongList(ids))); } @@ -117,11 +134,11 @@ public class RoleController extends BladeController { * 设置菜单权限 */ @PostMapping("/grant") - @ApiOperationSupport(order = 6) + @ApiOperationSupport(order = 7) @ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合") public R grant(@RequestBody GrantVO grantVO) { - boolean temp = roleService.grant(grantVO.getRoleIds(), grantVO.getMenuIds()); + CacheUtil.clear(SYS_CACHE); + boolean temp = roleService.grant(grantVO.getRoleIds(), grantVO.getMenuIds(), grantVO.getDataScopeIds()); return R.status(temp); } - } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/feign/DataScopeClient.java b/blade-service/blade-system/src/main/java/org/springblade/system/feign/DataScopeClient.java new file mode 100644 index 0000000..9167bc4 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/feign/DataScopeClient.java @@ -0,0 +1,106 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.feign; + +import lombok.RequiredArgsConstructor; +import org.springblade.core.datascope.constant.DataScopeConstant; +import org.springblade.core.datascope.model.DataScopeModel; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * 数据权限Feign实现类 + * + * @author Chill + */ +@ApiIgnore +@RestController +@RequiredArgsConstructor +public class DataScopeClient implements IDataScopeClient { + + private static final DataScopeModel SEARCHED_DATA_SCOPE_MODEL = new DataScopeModel(Boolean.TRUE); + + private final JdbcTemplate jdbcTemplate; + + /** + * 获取数据权限 + * + * @param mapperId 数据权限mapperId + * @param roleId 用户角色集合 + * @return DataScopeModel + */ + @Override + @GetMapping(GET_DATA_SCOPE_BY_MAPPER) + public DataScopeModel getDataScopeByMapper(String mapperId, String roleId) { + List args = new ArrayList<>(Collections.singletonList(mapperId)); + List roleIds = Func.toLongList(roleId); + args.addAll(roleIds); + // 增加searched字段防止未配置的参数重复读库导致缓存击穿 + // 后续若有新增配置则会清空缓存重新加载 + DataScopeModel dataScope; + List list = jdbcTemplate.query(DataScopeConstant.dataByMapper(roleIds.size()), args.toArray(), new BeanPropertyRowMapper<>(DataScopeModel.class)); + if (CollectionUtil.isNotEmpty(list)) { + dataScope = list.iterator().next(); + dataScope.setSearched(Boolean.TRUE); + } else { + dataScope = SEARCHED_DATA_SCOPE_MODEL; + } + return dataScope; + } + + /** + * 获取数据权限 + * + * @param code 数据权限资源编号 + * @return DataScopeModel + */ + @Override + @GetMapping(GET_DATA_SCOPE_BY_CODE) + public DataScopeModel getDataScopeByCode(String code) { + // 增加searched字段防止未配置的参数重复读库导致缓存击穿 + // 后续若有新增配置则会清空缓存重新加载 + DataScopeModel dataScope; + List list = jdbcTemplate.query(DataScopeConstant.DATA_BY_CODE, new Object[]{code}, new BeanPropertyRowMapper<>(DataScopeModel.class)); + if (CollectionUtil.isNotEmpty(list)) { + dataScope = list.iterator().next(); + dataScope.setSearched(Boolean.TRUE); + } else { + dataScope = SEARCHED_DATA_SCOPE_MODEL; + } + return dataScope; + } + + /** + * 获取部门子级 + * + * @param deptId 部门id + * @return deptIds + */ + @Override + @GetMapping(GET_DEPT_ANCESTORS) + public List getDeptAncestors(Long deptId) { + return jdbcTemplate.queryForList(DataScopeConstant.DATA_BY_DEPT, new Object[]{deptId}, Long.class); + } +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DataScopeMapper.java b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DataScopeMapper.java new file mode 100644 index 0000000..88f0578 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DataScopeMapper.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springblade.system.entity.DataScope; + +/** + * Mapper 接口 + * + * @author BladeX + */ +public interface DataScopeMapper extends BaseMapper { + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DataScopeMapper.xml b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DataScopeMapper.xml new file mode 100644 index 0000000..cbb4659 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DataScopeMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java index 771bfae..b5320ab 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java @@ -22,6 +22,7 @@ import org.springblade.system.entity.Menu; import org.springblade.system.vo.MenuVO; import java.util.List; +import java.util.Map; /** * Mapper 接口 @@ -39,6 +40,15 @@ public interface MenuMapper extends BaseMapper

{ */ List selectMenuPage(IPage page, MenuVO menu); + /** + * 懒加载菜单列表 + * + * @param parentId + * @param param + * @return + */ + List lazyMenuList(Long parentId, Map param); + /** * 树形结构 * @@ -61,6 +71,21 @@ public interface MenuMapper extends BaseMapper { */ List grantTreeByRole(List roleId); + /** + * 数据权限授权树形结构 + * + * @return + */ + List grantDataScopeTree(); + + /** + * 数据权限授权树形结构 + * + * @param roleId + * @return + */ + List grantDataScopeTreeByRole(List roleId); + /** * 所有菜单 * diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml index 260c931..e36edfe 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml @@ -19,6 +19,23 @@ + + + + + + + + + + + + + + + + + @@ -37,6 +54,35 @@ select * from blade_menu where is_deleted = 0 + + @@ -127,6 +173,104 @@ ) + + + +