From 058941367e6ded8cc6af572bafcb6f119183470a Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 8 Dec 2019 19:43:16 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B7=A6=E6=A0=91=E5=8F=B3=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springblade/system/cache/SysCache.java | 41 +++++++ .../springblade/system/feign/ISysClient.java | 10 ++ .../system/feign/ISysClientFallback.java | 5 + .../system/user/entity/UserDept.java | 64 ++++++++++ .../springblade/system/feign/SysClient.java | 7 ++ .../system/service/impl/RoleServiceImpl.java | 4 +- .../user/controller/UserController.java | 17 +++ .../system/user/mapper/UserDeptMapper.java | 30 +++++ .../system/user/mapper/UserDeptMapper.xml | 5 + .../system/user/mapper/UserMapper.java | 29 +---- .../system/user/mapper/UserMapper.xml | 25 ++++ .../system/user/service/IUserDeptService.java | 30 +++++ .../system/user/service/IUserService.java | 2 +- .../service/impl/UserDeptServiceImpl.java | 34 ++++++ .../user/service/impl/UserServiceImpl.java | 32 ++++- doc/sql/mysql/bladex-saber-mysql.sql | 21 ++++ doc/sql/mysql/bladex-sword-mysql.sql | 21 ++++ doc/sql/oracle/bladex-saber-oracle.sql | 83 ++++++++++++- doc/sql/oracle/bladex-sword-oracle.sql | 113 +++++++++++++++--- .../postgresql/bladex-saber-postgresql.sql | 32 ++++- .../postgresql/bladex-sword-postgresql.sql | 32 ++++- doc/sql/update/mysql-update-2.2.1~2.2.2.sql | 18 +++ doc/sql/update/oracle-update-2.2.1~2.2.2.sql | 22 ++++ .../update/postgresql-update-2.2.1~2.2.2.sql | 22 ++++ 24 files changed, 648 insertions(+), 51 deletions(-) create mode 100644 blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/entity/UserDept.java create mode 100644 blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserDeptMapper.java create mode 100644 blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserDeptMapper.xml create mode 100644 blade-service/blade-user/src/main/java/org/springblade/system/user/service/IUserDeptService.java create mode 100644 blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserDeptServiceImpl.java diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/SysCache.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/SysCache.java index dc603688..ced82465 100644 --- a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/SysCache.java +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/SysCache.java @@ -25,7 +25,9 @@ import org.springblade.system.entity.Role; import org.springblade.system.entity.Tenant; import org.springblade.system.feign.ISysClient; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE; @@ -39,6 +41,8 @@ public class SysCache { private static final String DEPT_ID = "dept:id:"; private static final String DEPT_NAME_ID = "deptName:id:"; private static final String DEPT_NAMES_ID = "deptNames:id:"; + private static final String DEPT_CHILD_ID = "deptChild:id:"; + private static final String DEPT_CHILDIDS_ID = "deptChildIds:id:"; private static final String ROLE_ID = "role:id:"; private static final String ROLE_NAME_ID = "roleName:id:"; private static final String ROLE_NAMES_ID = "roleNames:id:"; @@ -147,6 +151,43 @@ public class SysCache { }); } + /** + * 获取子部门集合 + * + * @param deptId 主键 + * @return 子部门 + */ + public static List getDeptChild(Long deptId) { + return CacheUtil.get(SYS_CACHE, DEPT_CHILD_ID, deptId, () -> { + R> result = getSysClient().getDeptChild(deptId); + return result.getData(); + }); + } + + /** + * 获取子部门ID集合 + * + * @param deptId 主键 + * @return 子部门ID + */ + public static List getDeptChildIds(Long deptId) { + if (deptId == null) { + return null; + } + List deptIdList = CacheUtil.get(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, List.class); + if (deptIdList == null) { + deptIdList = new ArrayList<>(); + List deptChild = getDeptChild(deptId); + if (deptChild != null) { + List collect = deptChild.stream().map(Dept::getId).collect(Collectors.toList()); + deptIdList.addAll(collect); + } + deptIdList.add(deptId); + CacheUtil.put(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, deptIdList); + } + return deptIdList; + } + /** * 获取角色名集合 * diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java index b9ddea2b..d5cd5aea 100644 --- a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java @@ -44,6 +44,7 @@ public interface ISysClient { String DEPT = API_PREFIX + "/dept"; String DEPT_NAME = API_PREFIX + "/dept-name"; String DEPT_NAMES = API_PREFIX + "/dept-names"; + String DEPT_CHILD = API_PREFIX + "/dept-child"; String ROLE = API_PREFIX + "/role"; String ROLE_NAME = API_PREFIX + "/role-name"; String ROLE_NAMES = API_PREFIX + "/role-names"; @@ -114,6 +115,15 @@ public interface ISysClient { @GetMapping(DEPT_NAMES) R> getDeptNames(@RequestParam("deptIds") String deptIds); + /** + * 获取子部门ID + * + * @param deptId + * @return + */ + @GetMapping(DEPT_CHILD) + R> getDeptChild(@RequestParam("deptId") Long deptId); + /** * 获取角色名 * diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java index 0198fc62..357de13d 100644 --- a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java @@ -68,6 +68,11 @@ public class ISysClientFallback implements ISysClient { return R.fail("获取数据失败"); } + @Override + public R> getDeptChild(Long deptId) { + return R.fail("获取数据失败"); + } + @Override public R> getRoleNames(String roleIds) { return R.fail("获取数据失败"); diff --git a/blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/entity/UserDept.java b/blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/entity/UserDept.java new file mode 100644 index 00000000..e64e8507 --- /dev/null +++ b/blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/entity/UserDept.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springblade.system.user.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_user_dept") +@ApiModel(value = "UserDept对象", description = "UserDept对象") +public class UserDept implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @JsonSerialize(using = ToStringSerializer.class) + @ApiModelProperty(value = "主键") + @TableId(value = "id", type = IdType.ID_WORKER) + private Long id; + + /** + * 用户ID + */ + @JsonSerialize(using = ToStringSerializer.class) + @ApiModelProperty(value = "用户ID") + private Long userId; + + /** + * 部门ID + */ + @JsonSerialize(using = ToStringSerializer.class) + @ApiModelProperty(value = "部门ID") + private Long deptId; + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java b/blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java index b6f29a39..b7f703b6 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java @@ -16,6 +16,7 @@ */ package org.springblade.system.feign; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springblade.system.entity.Dept; @@ -92,6 +93,12 @@ public class SysClient implements ISysClient { return R.data(deptService.getDeptNames(deptIds)); } + @Override + @GetMapping(DEPT_CHILD) + public R> getDeptChild(Long deptId) { + return R.data(deptService.list(Wrappers.query().lambda().like(Dept::getAncestors, deptId))); + } + @Override @GetMapping(ROLE_NAMES) public R> getRoleNames(String roleIds) { diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java index 4f2a835c..de9335a9 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java @@ -91,7 +91,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR roleMenuService.saveBatch(roleMenus); // 删除角色配置的数据权限集合 - roleScopeService.remove(Wrappers.update().lambda().in(RoleScope::getRoleId, roleIds)); + roleScopeService.remove(Wrappers.update().lambda().eq(RoleScope::getScopeCategory, DATA_SCOPE_CATEGORY).in(RoleScope::getRoleId, roleIds)); // 组装配置 List roleDataScopes = new ArrayList<>(); roleIds.forEach(roleId -> dataScopeIds.forEach(scopeId -> { @@ -104,7 +104,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR // 新增配置 roleScopeService.saveBatch(roleDataScopes); - // 删除角色配置的数据权限集合 + // 删除角色配置的接口权限集合 roleScopeService.remove(Wrappers.update().lambda().eq(RoleScope::getScopeCategory, API_SCOPE_CATEGORY).in(RoleScope::getRoleId, roleIds)); // 组装配置 List roleApiScopes = new ArrayList<>(); diff --git a/blade-service/blade-user/src/main/java/org/springblade/system/user/controller/UserController.java b/blade-service/blade-user/src/main/java/org/springblade/system/user/controller/UserController.java index 2e7b384c..74264fcb 100644 --- a/blade-service/blade-user/src/main/java/org/springblade/system/user/controller/UserController.java +++ b/blade-service/blade-user/src/main/java/org/springblade/system/user/controller/UserController.java @@ -28,6 +28,7 @@ import org.springblade.core.secure.annotation.PreAuth; import org.springblade.core.tool.api.R; import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.constant.RoleConstant; +import org.springblade.core.tool.utils.StringPool; import org.springblade.system.user.entity.User; import org.springblade.system.user.service.IUserService; import org.springblade.system.user.vo.UserVO; @@ -94,6 +95,22 @@ public class UserController { return R.data(UserWrapper.build().pageVO(pages)); } + /** + * 自定义用户列表 + */ + @GetMapping("/page") + @ApiImplicitParams({ + @ApiImplicitParam(name = "account", value = "账号名", paramType = "query", dataType = "string"), + @ApiImplicitParam(name = "realName", value = "姓名", paramType = "query", dataType = "string") + }) + @ApiOperationSupport(order = 3) + @ApiOperation(value = "列表", notes = "传入account和realName") + @PreAuth(RoleConstant.HAS_ROLE_ADMIN) + public R> page(@ApiIgnore User user, Query query, Long deptId, BladeUser bladeUser) { + IPage pages = userService.selectUserPage(Condition.getPage(query), user, deptId, (bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? StringPool.EMPTY : bladeUser.getTenantId())); + return R.data(UserWrapper.build().pageVO(pages)); + } + /** * 新增或修改 */ diff --git a/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserDeptMapper.java b/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserDeptMapper.java new file mode 100644 index 00000000..a8bf6bdc --- /dev/null +++ b/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserDeptMapper.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springblade.system.user.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springblade.system.user.entity.UserDept; + +/** + * Mapper 接口 + * + * @author Chill + */ +public interface UserDeptMapper extends BaseMapper { + + +} diff --git a/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserDeptMapper.xml b/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserDeptMapper.xml new file mode 100644 index 00000000..e5b4723a --- /dev/null +++ b/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserDeptMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.java b/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.java index 4e695192..107cd733 100644 --- a/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.java +++ b/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.java @@ -18,6 +18,7 @@ package org.springblade.system.user.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import org.apache.ibatis.annotations.Param; import org.springblade.system.user.entity.User; import java.util.List; @@ -34,9 +35,11 @@ public interface UserMapper extends BaseMapper { * * @param page * @param user + * @param deptIdList + * @param tenantId * @return */ - List selectUserPage(IPage page, User user); + List selectUserPage(IPage page, User user, @Param("deptIdList") List deptIdList, @Param("tenantId") String tenantId); /** * 获取用户 @@ -47,28 +50,4 @@ public interface UserMapper extends BaseMapper { */ User getUser(String tenantId, String account); - /** - * 获取角色名 - * - * @param ids - * @return - */ - List getRoleName(String[] ids); - - /** - * 获取角色别名 - * - * @param ids - * @return - */ - List getRoleAlias(String[] ids); - - /** - * 获取部门名 - * - * @param ids - * @return - */ - List getDeptName(String[] ids); - } diff --git a/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.xml b/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.xml index 81f71d27..70417c14 100644 --- a/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.xml +++ b/blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.xml @@ -38,6 +38,31 @@