Skip to content

Commit

Permalink
refactor: 重构查询角色字典接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jun 5, 2024
1 parent 1dbb339 commit 1e73d06
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
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 java.io.Serial;
Expand All @@ -30,6 +31,7 @@
* @since 2023/2/8 22:54
*/
@Data
@DictField
@TableName("sys_role")
public class RoleDO extends BaseDO {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
package top.continew.admin.system.service;

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.query.RoleQuery;
import top.continew.admin.system.model.req.RoleReq;
import top.continew.admin.system.model.resp.RoleDetailResp;
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.extension.crud.service.BaseService;

import java.util.List;
import java.util.Set;
Expand All @@ -37,14 +36,6 @@
*/
public interface RoleService extends BaseService<RoleResp, RoleDetailResp, RoleQuery, RoleReq>, IService<RoleDO> {

/**
* 构建字典
*
* @param list 原始列表数据
* @return 字典列表
*/
List<LabelValueResp<Long>> buildDict(List<RoleResp> list);

/**
* 根据 ID 列表查询
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import top.continew.admin.common.constant.SysConstants;
import top.continew.admin.common.enums.DataScopeEnum;
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.model.entity.RoleDO;
import top.continew.admin.system.model.query.RoleQuery;
Expand Down Expand Up @@ -136,14 +135,6 @@ protected void fill(Object obj) {
}
}

@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
@ContainerMethod(namespace = ContainerConstants.USER_ROLE_NAME_LIST, type = MappingType.ORDER_OF_KEYS)
public List<String> listNameByIds(List<Long> ids) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public R<List<Tree<Long>>> listMenuTree(MenuQuery query, SortQuery sortQuery) {
@GetMapping("/dict/role")
public R<List<LabelValueResp<Long>>> listRoleDict(RoleQuery query, SortQuery 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 = "查询字典列表")
Expand Down

0 comments on commit 1e73d06

Please sign in to comment.