22 changed files with 407 additions and 69 deletions
-
3common/src/main/java/com/canvas/web/enums/ResponseEnum.java
-
2common/src/main/java/com/canvas/web/utils/CacheKey.java
-
34system/src/main/java/com/canvas/web/modules/security/controller/AuthorizationController.java
-
6system/src/main/java/com/canvas/web/modules/security/service/OnlineUserService.java
-
7system/src/main/java/com/canvas/web/modules/security/service/dto/OnlineUserDto.java
-
12system/src/main/java/com/canvas/web/modules/system/controller/MenuController.java
-
71system/src/main/java/com/canvas/web/modules/system/controller/RoleController.java
-
1system/src/main/java/com/canvas/web/modules/system/domain/Role.java
-
18system/src/main/java/com/canvas/web/modules/system/domain/vo/MenuMetaVo.java
-
28system/src/main/java/com/canvas/web/modules/system/domain/vo/MenuVo.java
-
4system/src/main/java/com/canvas/web/modules/system/repository/MenuRepository.java
-
7system/src/main/java/com/canvas/web/modules/system/repository/RoleRepository.java
-
2system/src/main/java/com/canvas/web/modules/system/service/MenuService.java
-
5system/src/main/java/com/canvas/web/modules/system/service/RoleService.java
-
46system/src/main/java/com/canvas/web/modules/system/service/dto/DeptDto.java
-
18system/src/main/java/com/canvas/web/modules/system/service/dto/MenuDto.java
-
2system/src/main/java/com/canvas/web/modules/system/service/dto/OrgSmallDto.java
-
7system/src/main/java/com/canvas/web/modules/system/service/dto/RoleDto.java
-
6system/src/main/java/com/canvas/web/modules/system/service/dto/UserDto.java
-
106system/src/main/java/com/canvas/web/modules/system/service/impl/MenuServiceImpl.java
-
89system/src/main/java/com/canvas/web/modules/system/service/impl/RoleServiceImpl.java
-
2system/src/main/java/com/canvas/web/modules/system/service/impl/UserServiceImpl.java
@ -0,0 +1,71 @@ |
|||
package com.canvas.web.modules.system.controller; |
|||
|
|||
import com.canvas.web.annotation.rest.AnonymousGetMapping; |
|||
import com.canvas.web.annotation.rest.AnonymousPostMapping; |
|||
import com.canvas.web.enums.ResponseEnum; |
|||
import com.canvas.web.exception.BaseException; |
|||
import com.canvas.web.modules.system.service.RoleService; |
|||
import com.canvas.web.modules.system.service.dto.RoleDto; |
|||
import com.canvas.web.modules.system.service.dto.RoleQueryCriteria; |
|||
import com.canvas.web.modules.system.service.dto.RoleSmallDto; |
|||
import com.canvas.web.modules.system.service.mapstruct.RoleMapper; |
|||
import com.canvas.web.utils.Response; |
|||
import com.canvas.web.utils.SecurityUtils; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@RestController |
|||
@RequiredArgsConstructor |
|||
@Api(tags = "角色管理") |
|||
@RequestMapping("/api/roles") |
|||
public class RoleController { |
|||
|
|||
private final RoleService roleService; |
|||
|
|||
private static final String ENTITY_NAME="role"; |
|||
|
|||
private final RoleMapper roleMapper; |
|||
|
|||
@ApiOperation("新增角色") |
|||
@AnonymousPostMapping("/create") |
|||
public Response<Object> create(@Validated @RequestBody RoleDto roleDto){ |
|||
if (roleDto.getId() !=null){ |
|||
throw new BaseException("A new cannot already have an ID", ResponseEnum.ROLE_ADD_ERROR_EXIST_ID.getMessage()); |
|||
} |
|||
//TODO:权限测试 |
|||
// getLevels(roleDto.getLevel()); |
|||
roleService.create(roleMapper.toEntity(roleDto)); |
|||
return Response.success(ResponseEnum.ADD_SUCCESS); |
|||
|
|||
} |
|||
|
|||
|
|||
@ApiOperation("查询角色") |
|||
@AnonymousGetMapping("/list") |
|||
public Response<Object> queryAllRole(RoleQueryCriteria criteria, Pageable pageable){ |
|||
return new Response<>(roleService.queryAll(criteria,pageable)); |
|||
} |
|||
|
|||
|
|||
|
|||
private int getLevels(Integer level){ |
|||
List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()); |
|||
int min = Collections.min(levels); |
|||
if(level != null){ |
|||
if(level < min){ |
|||
throw new BaseException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level); |
|||
} |
|||
} |
|||
return min; |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
package com.canvas.web.modules.system.domain.vo; |
|||
|
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
public class MenuMetaVo implements Serializable { |
|||
|
|||
private String title; |
|||
|
|||
private String icon; |
|||
|
|||
private Boolean noCache; |
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.canvas.web.modules.system.domain.vo; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_EMPTY) |
|||
public class MenuVo implements Serializable { |
|||
|
|||
private String name; |
|||
|
|||
private String path; |
|||
|
|||
private Boolean hidden; |
|||
|
|||
private String redirect; |
|||
|
|||
private String component; |
|||
|
|||
private Boolean alwaysShow; |
|||
|
|||
private MenuMetaVo meta; |
|||
|
|||
private List<MenuVo> children; |
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.canvas.web.modules.system.service.dto; |
|||
|
|||
import com.canvas.web.base.BaseDTO; |
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Objects; |
|||
|
|||
public class DeptDto extends BaseDTO implements Serializable { |
|||
|
|||
private Long id; |
|||
|
|||
private String name; |
|||
|
|||
private Boolean enabled; |
|||
|
|||
private Integer deptSort; |
|||
|
|||
public Boolean getLeaf() { |
|||
return subCount <= 0; |
|||
} |
|||
|
|||
public String getLabel() { |
|||
return name; |
|||
} |
|||
|
|||
private Integer subCount; |
|||
|
|||
@Override |
|||
public boolean equals(Object o) { |
|||
if (this == o) { |
|||
return true; |
|||
} |
|||
if (o == null || getClass() != o.getClass()) { |
|||
return false; |
|||
} |
|||
DeptDto deptDto = (DeptDto) o; |
|||
return Objects.equals(id, deptDto.id) && |
|||
Objects.equals(name, deptDto.name); |
|||
} |
|||
|
|||
@Override |
|||
public int hashCode() { |
|||
return Objects.hash(id, name); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue