From 03cfb52a9ebb592da67e882ef17b3d27518b9789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8A=9B?= Date: Tue, 29 Mar 2022 10:04:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/pom.xml | 19 +++++++ .../canvas/web/config/ElPermissionConfig.java | 21 -------- .../com/canvas/web/utils/SecurityUtils.java | 8 +++ pom.xml | 1 + .../system/controller/UserController.java | 49 +++++++++---------- .../system/repository/UserRepository.java | 15 ++---- .../system/service/dto/UserQueryCriteria.java | 3 +- 7 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 client/pom.xml delete mode 100644 common/src/main/java/com/canvas/web/config/ElPermissionConfig.java diff --git a/client/pom.xml b/client/pom.xml new file mode 100644 index 0000000..8a917b2 --- /dev/null +++ b/client/pom.xml @@ -0,0 +1,19 @@ + + + + yxk_canvasScreen + com.canvas.web + 1.0-SNAPSHOT + + 4.0.0 + + client + + + 17 + 17 + + + \ No newline at end of file diff --git a/common/src/main/java/com/canvas/web/config/ElPermissionConfig.java b/common/src/main/java/com/canvas/web/config/ElPermissionConfig.java deleted file mode 100644 index f99485a..0000000 --- a/common/src/main/java/com/canvas/web/config/ElPermissionConfig.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.canvas.web.config; - - -import com.canvas.web.utils.SecurityUtils; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -@Service(value = "el") -public class ElPermissionConfig { - - public Boolean check(String... permissions) { - // 获取当前用户的所有权限 - List elPermissions = SecurityUtils.getCurrentUser().getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()); - // 判断当前用户的所有权限是否包含接口上定义的权限 - return elPermissions.contains("admin") || Arrays.stream(permissions).anyMatch(elPermissions::contains); - } -} diff --git a/common/src/main/java/com/canvas/web/utils/SecurityUtils.java b/common/src/main/java/com/canvas/web/utils/SecurityUtils.java index c027d00..f24bd39 100644 --- a/common/src/main/java/com/canvas/web/utils/SecurityUtils.java +++ b/common/src/main/java/com/canvas/web/utils/SecurityUtils.java @@ -52,6 +52,14 @@ public class SecurityUtils { return new JSONObject(new JSONObject(userDetails).get("user")).get("id", Long.class); } + /** + * 获取用户机构id + * */ + public static Long getCurrentOrgId(){ + UserDetails userDetails=getCurrentUser(); + return new JSONObject(new JSONObject(userDetails).get("user")).getJSONObject("org").get("id",Long.class); + } + /** * 获取当前用户的数据权限 diff --git a/pom.xml b/pom.xml index 9839922..3596a33 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ system common + client 多媒体后台管理系统 diff --git a/system/src/main/java/com/canvas/web/modules/system/controller/UserController.java b/system/src/main/java/com/canvas/web/modules/system/controller/UserController.java index abc29ee..96b52ca 100644 --- a/system/src/main/java/com/canvas/web/modules/system/controller/UserController.java +++ b/system/src/main/java/com/canvas/web/modules/system/controller/UserController.java @@ -9,10 +9,12 @@ import com.canvas.web.modules.system.domain.User; import com.canvas.web.modules.system.service.OrgService; import com.canvas.web.modules.system.service.RoleService; import com.canvas.web.modules.system.service.UserService; +import com.canvas.web.modules.system.service.dto.OrgDto; import com.canvas.web.modules.system.service.dto.RoleSmallDto; import com.canvas.web.modules.system.service.dto.UserDto; import com.canvas.web.modules.system.service.dto.UserQueryCriteria; import com.canvas.web.utils.PageUtil; +import com.canvas.web.utils.RedisUtils; import com.canvas.web.utils.Response; import com.canvas.web.utils.SecurityUtils; import io.swagger.annotations.Api; @@ -20,15 +22,14 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.Collections; +import java.util.List; import java.util.stream.Collectors; @Api(tags = "用户管理") @@ -45,7 +46,6 @@ public class UserController { @ApiOperation("新增用户") @PostMapping public Response create(@Validated @RequestBody User resources) { - checkLevel(resources); // 默认密码 123456 resources.setPassword(passwordEncoder.encode("123456")); userService.create(resources); @@ -53,33 +53,32 @@ public class UserController { } - public Response query(UserQueryCriteria criteria, Pageable pageable){ - //判断查询条件是否为空 - if (!ObjectUtils.isEmpty(criteria.getBlurry())){ + @ApiOperation("查询用户") + @GetMapping("list") + public Response query(UserQueryCriteria criteria, Pageable pageable) { + //获取当前登录组织机构id + Long id = SecurityUtils.getCurrentOrgId(); + if (id != null) { + //加入到查询条件 + criteria.getOrgId().add(id); return Response.success(userService.queryAll(criteria,pageable)); } - - return Response.success(PageUtil.toPage(null,0)); - } - - @ApiOperation("测试异常接口") - @AnonymousPostMapping("/test") - public Response test(@Validated @RequestBody User resources){ - if (resources.getPhone()==null){ - throw new BaseException("-1","用户手机号不能为空"); + //判断查询条件是否为空 + if (!ObjectUtils.isEmpty(criteria.getBlurry())) { + return Response.success(userService.queryAll(criteria, pageable)); } - return Response.success(); - } + return Response.success(PageUtil.toPage(null, 0)); + } //如果当前用户角色级别低于创建用户的角色级别,抛出权限不足 - private void checkLevel(User resources){ - Integer currentLevel= Collections.min(roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList())); - Integer optLevel = roleService.findByRoles(resources.getRoles()); - if (currentLevel > optLevel){ - throw new BaseException("权限不足"); - } + private void checkLevel() { + Integer currentLevel = Collections.min(roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList())); + //Integer optLevel = roleService.findByRoles(resources.getRoles()); + // if (currentLevel > optLevel){ + throw new BaseException("权限不足"); + // } } diff --git a/system/src/main/java/com/canvas/web/modules/system/repository/UserRepository.java b/system/src/main/java/com/canvas/web/modules/system/repository/UserRepository.java index cc58fa6..0b5dc7f 100644 --- a/system/src/main/java/com/canvas/web/modules/system/repository/UserRepository.java +++ b/system/src/main/java/com/canvas/web/modules/system/repository/UserRepository.java @@ -41,14 +41,7 @@ public interface UserRepository extends JpaRepository, JpaSpecificat " u.user_id = r.user_id AND r.role_id = ?1", nativeQuery = true) List findByRoleId(Long roleId); - /** - * 根据角色中的部门查询 - * @param id / - * @return / - */ - @Query(value = "SELECT u.* FROM sys_user u, sys_users_roles r, sys_roles_depts d WHERE " + - "u.user_id = r.user_id AND r.role_id = d.role_id AND r.role_id = ?1 group by u.user_id", nativeQuery = true) - List findByDeptRoleId(Long id); + /** * 根据菜单查询 @@ -67,11 +60,11 @@ public interface UserRepository extends JpaRepository, JpaSpecificat /** * 根据部门查询 - * @param deptIds / + * @param orgIds / * @return / */ - @Query(value = "SELECT count(1) FROM sys_user u WHERE u.dept_id IN ?1", nativeQuery = true) - int countByDepts(Set deptIds); + @Query(value = "SELECT count(1) FROM sys_user u WHERE u.org_id IN ?1", nativeQuery = true) + int countByDepts(Set orgIds); /** * 根据角色查询 diff --git a/system/src/main/java/com/canvas/web/modules/system/service/dto/UserQueryCriteria.java b/system/src/main/java/com/canvas/web/modules/system/service/dto/UserQueryCriteria.java index cf56625..e596b8c 100644 --- a/system/src/main/java/com/canvas/web/modules/system/service/dto/UserQueryCriteria.java +++ b/system/src/main/java/com/canvas/web/modules/system/service/dto/UserQueryCriteria.java @@ -22,7 +22,8 @@ public class UserQueryCriteria implements Serializable { @Query private Boolean enabled; - private Long OrgId; + @Query(propName = "id",type = Query.Type.IN,joinName = "org") + private Set OrgId =new HashSet<>(); @Query(type = Query.Type.BETWEEN) private List createTime;