Skip to content

Commit

Permalink
feat(系统管理): 角色管理接口增加根据id查询用户列表接口
Browse files Browse the repository at this point in the history
  • Loading branch information
houtaroy committed Oct 24, 2023
1 parent 6ef50a1 commit 261c0b3
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package cn.koala.system.apis;
package cn.koala.system;

import cn.koala.openapi.PageableAsQueryParam;
import cn.koala.persist.validator.EditableId;
import cn.koala.system.Role;
import cn.koala.system.apis.request.RoleAuthorizeRequest;
import cn.koala.system.entities.RoleEntity;
import cn.koala.validation.group.Create;
Expand Down Expand Up @@ -157,6 +156,21 @@ Response update(@EditableId(Role.class) @PathVariable("id") Long id,
@PutMapping("{id}/authorize")
Response setRolePermissions(@PathVariable("id") Long id, @RequestBody RoleAuthorizeRequest request);

/**
* 根据id查询角色的用户列表
*
* @param id 角色id
* @return 用户列表
*/
@PreAuthorize("hasAuthority('role.read')")
@Operation(operationId = "listRoleUser", summary = "根据id查询角色的用户列表")
@ApiResponse(responseCode = "200", description = "成功", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = RoleUserListResult.class))
})
@Parameter(in = ParameterIn.PATH, name = "id", description = "角色id", schema = @Schema(type = "integer"))
@GetMapping("{id}/users")
DataResponse<List<User>> listUser(@PathVariable("id") Long id);

class RolePageResult extends DataResponse<Page<RoleEntity>> {

}
Expand All @@ -168,4 +182,8 @@ class RoleResult extends DataResponse<RoleEntity> {
class CheckedPermissionIdsResult extends DataResponse<List<Long>> {

}

class RoleUserListResult extends DataResponse<List<User>> {

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.koala.system.services;
package cn.koala.system;

import cn.koala.persist.CrudService;
import cn.koala.system.Role;

import java.util.List;

Expand All @@ -14,4 +13,6 @@ public interface RoleService extends CrudService<Role, Long> {
List<Long> getCheckedPermissionIds(Long id);

void authorize(Long id, List<Long> checkedIds, List<Long> halfCheckedIds);

List<User> listUser(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.koala.system.repositories;
package cn.koala.system.repository;

import cn.koala.persist.CrudRepository;
import cn.koala.system.Department;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.koala.system.repositories;
package cn.koala.system.repository;

import cn.koala.persist.CrudRepository;
import cn.koala.system.DictionaryItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.koala.system.repositories;
package cn.koala.system.repository;

import cn.koala.persist.CrudRepository;
import cn.koala.system.Dictionary;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.koala.system.repositories;
package cn.koala.system.repository;

import cn.koala.persist.CrudRepository;
import cn.koala.system.Permission;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cn.koala.system.repositories;
package cn.koala.system.repository;

import cn.koala.persist.CrudRepository;
import cn.koala.system.Role;
import cn.koala.system.User;
import org.apache.ibatis.annotations.Param;

import java.util.List;
Expand All @@ -19,4 +20,6 @@ void authorize(
@Param("checkedIds") List<Long> checkedIds,
@Param("halfCheckedIds") List<Long> halfCheckedIds
);

List<User> listUserById(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.koala.system.repositories;
package cn.koala.system.repository;

import cn.koala.persist.CrudRepository;
import cn.koala.system.Setting;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.koala.system.repositories;
package cn.koala.system.repository;

import cn.koala.persist.CrudRepository;
import cn.koala.system.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.koala.mybatis.AbstractMyBatisService;
import cn.koala.system.Department;
import cn.koala.system.repositories.DepartmentRepository;
import cn.koala.system.repository.DepartmentRepository;
import cn.koala.toolkit.tree.TreeHelper;
import cn.koala.toolkit.tree.TreeNode;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.koala.mybatis.AbstractMyBatisService;
import cn.koala.system.DictionaryItem;
import cn.koala.system.repositories.DictionaryItemRepository;
import cn.koala.system.repository.DictionaryItemRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.koala.mybatis.AbstractMyBatisService;
import cn.koala.system.Dictionary;
import cn.koala.system.repositories.DictionaryRepository;
import cn.koala.system.repository.DictionaryRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.koala.mybatis.AbstractMyBatisService;
import cn.koala.system.Permission;
import cn.koala.system.repositories.PermissionRepository;
import cn.koala.system.repository.PermissionRepository;
import cn.koala.toolkit.tree.TreeHelper;
import cn.koala.toolkit.tree.TreeNode;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.koala.mybatis.AbstractMyBatisService;
import cn.koala.system.Setting;
import cn.koala.system.repositories.SettingRepository;
import cn.koala.system.repository.SettingRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.koala.mybatis.AbstractMyBatisService;
import cn.koala.system.User;
import cn.koala.system.repositories.UserRepository;
import cn.koala.system.repository.UserRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import cn.koala.system.User;
import cn.koala.system.UserEntity;
import cn.koala.system.entities.RoleEntity;
import cn.koala.system.repositories.PermissionRepository;
import cn.koala.system.repositories.RoleRepository;
import cn.koala.system.repositories.UserRepository;
import cn.koala.system.repository.PermissionRepository;
import cn.koala.system.repository.RoleRepository;
import cn.koala.system.repository.UserRepository;
import cn.koala.toolkit.DateHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cn.koala.system.apis;
package cn.koala.system.support;

import cn.koala.log.annotations.Log;
import cn.koala.system.Role;
import cn.koala.system.RoleApi;
import cn.koala.system.RoleService;
import cn.koala.system.User;
import cn.koala.system.apis.request.RoleAuthorizeRequest;
import cn.koala.system.entities.RoleEntity;
import cn.koala.system.services.RoleService;
import cn.koala.web.DataResponse;
import cn.koala.web.Response;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,7 +24,7 @@
*/
@RequiredArgsConstructor
@RestController
public class RoleApiImpl implements RoleApi {
public class DefaultRoleApi implements RoleApi {
protected final RoleService roleService;

@Override
Expand Down Expand Up @@ -71,4 +73,9 @@ public Response setRolePermissions(Long id, RoleAuthorizeRequest request) {
roleService.authorize(id, request.getCheckedIds(), request.getHalfCheckedIds());
return Response.SUCCESS;
}

@Override
public DataResponse<List<User>> listUser(Long id) {
return DataResponse.ok(roleService.listUser(id));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cn.koala.system.services;
package cn.koala.system.support;

import cn.koala.mybatis.AbstractMyBatisService;
import cn.koala.persist.support.DomainHelper;
import cn.koala.system.Role;
import cn.koala.system.repositories.RoleRepository;
import cn.koala.system.RoleService;
import cn.koala.system.User;
import cn.koala.system.repository.RoleRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -16,7 +18,7 @@
*/
@RequiredArgsConstructor
@Getter
public class RoleServiceImpl extends AbstractMyBatisService<Role, Long> implements RoleService {
public class DefaultRoleService extends AbstractMyBatisService<Role, Long> implements RoleService {

protected final RoleRepository repository;

Expand All @@ -30,4 +32,9 @@ public void authorize(Long id, List<Long> checkedIds, List<Long> halfCheckedIds)
DomainHelper.assertEditable(repository.load(id));
getRepository().authorize(id, checkedIds, halfCheckedIds);
}

@Override
public List<User> listUser(Long id) {
return repository.listUserById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cn.koala.boot.AbstractApplicationRunner;
import cn.koala.system.Permission;
import cn.koala.system.PermissionRegistrar;
import cn.koala.system.repositories.PermissionRepository;
import cn.koala.system.repository.PermissionRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,19 @@
</foreach>
</if>
</insert>

<select id="listUserById" resultType="cn.koala.system.UserEntity">
select t.id,
t.username,
t.nickname,
t.avatar,
t.email,
t.mobile,
t.remark,
t.sort_index,
t.is_enabled
from k_user t
join k_user_role ur on t.id = ur.user_id and ur.role_id = #{id}
where t.is_deleted = ${@cn.koala.persist.domain.YesNo@NO.value}
</select>
</mapper>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.koala.wechat.miniapp.support;

import cn.koala.system.UserEntity;
import cn.koala.system.repositories.UserRepository;
import cn.koala.system.repository.UserRepository;
import cn.koala.toolkit.DateHelper;
import cn.koala.wechat.miniapp.WechatMiniAppUser;
import cn.koala.wechat.miniapp.WechatMiniAppUserRegistrar;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.koala.system.autoconfigure;

import cn.koala.system.PermissionRegistrar;
import cn.koala.system.RoleService;
import cn.koala.system.UserApi;
import cn.koala.system.UserCreateListener;
import cn.koala.system.apis.DepartmentApi;
Expand All @@ -11,13 +12,12 @@
import cn.koala.system.apis.DictionaryItemApiImpl;
import cn.koala.system.apis.PermissionApi;
import cn.koala.system.apis.PermissionApiImpl;
import cn.koala.system.apis.RoleApiImpl;
import cn.koala.system.repositories.DepartmentRepository;
import cn.koala.system.repositories.DictionaryItemRepository;
import cn.koala.system.repositories.DictionaryRepository;
import cn.koala.system.repositories.PermissionRepository;
import cn.koala.system.repositories.RoleRepository;
import cn.koala.system.repositories.UserRepository;
import cn.koala.system.repository.DepartmentRepository;
import cn.koala.system.repository.DictionaryItemRepository;
import cn.koala.system.repository.DictionaryRepository;
import cn.koala.system.repository.PermissionRepository;
import cn.koala.system.repository.RoleRepository;
import cn.koala.system.repository.UserRepository;
import cn.koala.system.services.DepartmentService;
import cn.koala.system.services.DepartmentServiceImpl;
import cn.koala.system.services.DictionaryItemService;
Expand All @@ -26,11 +26,11 @@
import cn.koala.system.services.DictionaryServiceImpl;
import cn.koala.system.services.PermissionService;
import cn.koala.system.services.PermissionServiceImpl;
import cn.koala.system.services.RoleService;
import cn.koala.system.services.RoleServiceImpl;
import cn.koala.system.services.UserService;
import cn.koala.system.services.UserServiceImpl;
import cn.koala.system.support.AdminRegister;
import cn.koala.system.support.DefaultRoleApi;
import cn.koala.system.support.DefaultRoleService;
import cn.koala.system.support.DefaultUserApi;
import cn.koala.system.support.PermissionRegister;
import cn.koala.system.support.SystemPermissionRegistrar;
Expand All @@ -52,7 +52,7 @@
*/
@Configuration
@EnableConfigurationProperties(SystemProperties.class)
@MapperScan(basePackages = "cn.koala.system.repositories")
@MapperScan(basePackages = "cn.koala.system.repository")
public class SystemAutoConfiguration {
@Bean
@ConditionalOnMissingBean
Expand Down Expand Up @@ -105,13 +105,13 @@ public PermissionApi permissionApi(PermissionService permissionService) {
@Bean
@ConditionalOnMissingBean
public RoleService roleService(RoleRepository roleRepository) {
return new RoleServiceImpl(roleRepository);
return new DefaultRoleService(roleRepository);
}

@Bean
@ConditionalOnMissingBean
public RoleApiImpl roleApi(RoleService roleService) {
return new RoleApiImpl(roleService);
public DefaultRoleApi roleApi(RoleService roleService) {
return new DefaultRoleApi(roleService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.koala.authorization.builder.AuthorizationServerSecurityFilterChainPostProcessor;
import cn.koala.authorization.client.RegisteredClientRegistrar;
import cn.koala.system.repositories.UserRepository;
import cn.koala.system.repository.UserRepository;
import cn.koala.wechat.miniapp.WechatMiniAppUserRegistrar;
import cn.koala.wechat.miniapp.processor.OAuth2WechatMiniAppPostProcessor;
import cn.koala.wechat.miniapp.repository.WechatMiniAppUserRepository;
Expand Down

0 comments on commit 261c0b3

Please sign in to comment.