Browse Source

提交项目

master
刘力 3 years ago
parent
commit
03cfb52a9e
  1. 19
      client/pom.xml
  2. 21
      common/src/main/java/com/canvas/web/config/ElPermissionConfig.java
  3. 8
      common/src/main/java/com/canvas/web/utils/SecurityUtils.java
  4. 1
      pom.xml
  5. 37
      system/src/main/java/com/canvas/web/modules/system/controller/UserController.java
  6. 15
      system/src/main/java/com/canvas/web/modules/system/repository/UserRepository.java
  7. 3
      system/src/main/java/com/canvas/web/modules/system/service/dto/UserQueryCriteria.java

19
client/pom.xml

@ -0,0 +1,19 @@
<?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>yxk_canvasScreen</artifactId>
<groupId>com.canvas.web</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>

21
common/src/main/java/com/canvas/web/config/ElPermissionConfig.java

@ -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<String> elPermissions = SecurityUtils.getCurrentUser().getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
// 判断当前用户的所有权限是否包含接口上定义的权限
return elPermissions.contains("admin") || Arrays.stream(permissions).anyMatch(elPermissions::contains);
}
}

8
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);
}
/**
* 获取当前用户的数据权限

1
pom.xml

@ -12,6 +12,7 @@
<modules>
<module>system</module>
<module>common</module>
<module>client</module>
</modules>
<name>多媒体后台管理系统</name>

37
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<Object> create(@Validated @RequestBody User resources) {
checkLevel(resources);
// 默认密码 123456
resources.setPassword(passwordEncoder.encode("123456"));
userService.create(resources);
@ -53,7 +53,16 @@ public class UserController {
}
@ApiOperation("查询用户")
@GetMapping("list")
public Response<Object> query(UserQueryCriteria criteria, Pageable pageable) {
//获取当前登录组织机构id
Long id = SecurityUtils.getCurrentOrgId();
if (id != null) {
//加入到查询条件
criteria.getOrgId().add(id);
return Response.success(userService.queryAll(criteria,pageable));
}
//判断查询条件是否为空
if (!ObjectUtils.isEmpty(criteria.getBlurry())) {
return Response.success(userService.queryAll(criteria, pageable));
@ -62,24 +71,14 @@ public class UserController {
return Response.success(PageUtil.toPage(null, 0));
}
@ApiOperation("测试异常接口")
@AnonymousPostMapping("/test")
public Response<Object> test(@Validated @RequestBody User resources){
if (resources.getPhone()==null){
throw new BaseException("-1","用户手机号不能为空");
}
return Response.success();
}
//如果当前用户角色级别低于创建用户的角色级别抛出权限不足
private void checkLevel(User resources){
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){
//Integer optLevel = roleService.findByRoles(resources.getRoles());
// if (currentLevel > optLevel){
throw new BaseException("权限不足");
}
// }
}

15
system/src/main/java/com/canvas/web/modules/system/repository/UserRepository.java

@ -41,14 +41,7 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
" u.user_id = r.user_id AND r.role_id = ?1", nativeQuery = true)
List<User> 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<User> findByDeptRoleId(Long id);
/**
* 根据菜单查询
@ -67,11 +60,11 @@ public interface UserRepository extends JpaRepository<User, Long>, 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<Long> deptIds);
@Query(value = "SELECT count(1) FROM sys_user u WHERE u.org_id IN ?1", nativeQuery = true)
int countByDepts(Set<Long> orgIds);
/**
* 根据角色查询

3
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<Long> OrgId =new HashSet<>();
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> createTime;

Loading…
Cancel
Save