mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 22:57:17 +08:00 
			
		
		
		
	refactor: 重构查询角色字典接口
This commit is contained in:
		| @@ -19,6 +19,7 @@ package top.continew.admin.system.model.entity; | |||||||
| import com.baomidou.mybatisplus.annotation.TableName; | import com.baomidou.mybatisplus.annotation.TableName; | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
| import top.continew.admin.common.enums.DataScopeEnum; | import top.continew.admin.common.enums.DataScopeEnum; | ||||||
|  | import top.continew.starter.extension.crud.annotation.DictField; | ||||||
| import top.continew.starter.extension.crud.model.entity.BaseDO; | import top.continew.starter.extension.crud.model.entity.BaseDO; | ||||||
|  |  | ||||||
| import java.io.Serial; | import java.io.Serial; | ||||||
| @@ -30,6 +31,7 @@ import java.io.Serial; | |||||||
|  * @since 2023/2/8 22:54 |  * @since 2023/2/8 22:54 | ||||||
|  */ |  */ | ||||||
| @Data | @Data | ||||||
|  | @DictField | ||||||
| @TableName("sys_role") | @TableName("sys_role") | ||||||
| public class RoleDO extends BaseDO { | public class RoleDO extends BaseDO { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,14 +17,13 @@ | |||||||
| package top.continew.admin.system.service; | package top.continew.admin.system.service; | ||||||
|  |  | ||||||
| import top.continew.admin.common.model.dto.RoleDTO; | import top.continew.admin.common.model.dto.RoleDTO; | ||||||
| import top.continew.admin.common.model.resp.LabelValueResp; |  | ||||||
| import top.continew.admin.system.model.entity.RoleDO; | import top.continew.admin.system.model.entity.RoleDO; | ||||||
| import top.continew.admin.system.model.query.RoleQuery; | import top.continew.admin.system.model.query.RoleQuery; | ||||||
| import top.continew.admin.system.model.req.RoleReq; | import top.continew.admin.system.model.req.RoleReq; | ||||||
| import top.continew.admin.system.model.resp.RoleDetailResp; | import top.continew.admin.system.model.resp.RoleDetailResp; | ||||||
| import top.continew.admin.system.model.resp.RoleResp; | import top.continew.admin.system.model.resp.RoleResp; | ||||||
| import top.continew.starter.extension.crud.service.BaseService; |  | ||||||
| import top.continew.starter.data.mybatis.plus.service.IService; | import top.continew.starter.data.mybatis.plus.service.IService; | ||||||
|  | import top.continew.starter.extension.crud.service.BaseService; | ||||||
|  |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Set; | import java.util.Set; | ||||||
| @@ -37,14 +36,6 @@ import java.util.Set; | |||||||
|  */ |  */ | ||||||
| public interface RoleService extends BaseService<RoleResp, RoleDetailResp, RoleQuery, RoleReq>, IService<RoleDO> { | public interface RoleService extends BaseService<RoleResp, RoleDetailResp, RoleQuery, RoleReq>, IService<RoleDO> { | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 构建字典 |  | ||||||
|      * |  | ||||||
|      * @param list 原始列表数据 |  | ||||||
|      * @return 字典列表 |  | ||||||
|      */ |  | ||||||
|     List<LabelValueResp<Long>> buildDict(List<RoleResp> list); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 根据 ID 列表查询 |      * 根据 ID 列表查询 | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -31,7 +31,6 @@ import top.continew.admin.common.constant.ContainerConstants; | |||||||
| import top.continew.admin.common.constant.SysConstants; | import top.continew.admin.common.constant.SysConstants; | ||||||
| import top.continew.admin.common.enums.DataScopeEnum; | import top.continew.admin.common.enums.DataScopeEnum; | ||||||
| import top.continew.admin.common.model.dto.RoleDTO; | import top.continew.admin.common.model.dto.RoleDTO; | ||||||
| import top.continew.admin.common.model.resp.LabelValueResp; |  | ||||||
| import top.continew.admin.system.mapper.RoleMapper; | import top.continew.admin.system.mapper.RoleMapper; | ||||||
| import top.continew.admin.system.model.entity.RoleDO; | import top.continew.admin.system.model.entity.RoleDO; | ||||||
| import top.continew.admin.system.model.query.RoleQuery; | import top.continew.admin.system.model.query.RoleQuery; | ||||||
| @@ -136,14 +135,6 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public List<LabelValueResp<Long>> buildDict(List<RoleResp> list) { |  | ||||||
|         if (CollUtil.isEmpty(list)) { |  | ||||||
|             return new ArrayList<>(0); |  | ||||||
|         } |  | ||||||
|         return list.stream().map(r -> new LabelValueResp<>(r.getName(), r.getId())).toList(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @ContainerMethod(namespace = ContainerConstants.USER_ROLE_NAME_LIST, type = MappingType.ORDER_OF_KEYS) |     @ContainerMethod(namespace = ContainerConstants.USER_ROLE_NAME_LIST, type = MappingType.ORDER_OF_KEYS) | ||||||
|     public List<String> listNameByIds(List<Long> ids) { |     public List<String> listNameByIds(List<Long> ids) { | ||||||
|   | |||||||
| @@ -97,6 +97,8 @@ public class CommonController { | |||||||
|     @GetMapping("/dict/role") |     @GetMapping("/dict/role") | ||||||
|     public R<List<LabelValueResp<Long>>> listRoleDict(RoleQuery query, SortQuery sortQuery) { |     public R<List<LabelValueResp<Long>>> listRoleDict(RoleQuery query, SortQuery sortQuery) { | ||||||
|         return R.ok(roleService.buildDict(roleService.list(query, sortQuery))); |         return R.ok(roleService.buildDict(roleService.list(query, sortQuery))); | ||||||
|  |     public R<List<LabelValueResp>> listRoleDict(RoleQuery query, SortQuery sortQuery) { | ||||||
|  |         return R.ok(roleService.listDict(query, sortQuery)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Operation(summary = "查询字典", description = "查询字典列表") |     @Operation(summary = "查询字典", description = "查询字典列表") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user