Skip to content

Commit

Permalink
refactor: 使用 Crane4j 优化部分数据填充处理
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Mar 23, 2024
1 parent df0c0dd commit c05584b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package top.charles7c.continew.admin.system.model.resp;

import cn.crane4j.annotation.Assemble;
import cn.crane4j.annotation.Mapping;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.charles7c.continew.admin.common.constant.ContainerConstants;
import top.charles7c.continew.admin.common.enums.DataScopeEnum;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
Expand All @@ -37,6 +40,7 @@
@Data
@ExcelIgnoreUnannotated
@Schema(description = "角色详情信息")
@Assemble(container = ContainerConstants.ROLE_DEPT_ID_LIST, key = "id", props = @Mapping(ref = "deptIds"))
public class RoleDetailResp extends BaseDetailResp {

@Serial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package top.charles7c.continew.admin.system.model.resp;

import cn.crane4j.annotation.Assemble;
import cn.crane4j.annotation.AssembleMethod;
import cn.crane4j.annotation.ContainerMethod;
import cn.crane4j.annotation.Mapping;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.charles7c.continew.admin.common.constant.ContainerConstants;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.admin.common.enums.GenderEnum;
import top.charles7c.continew.admin.common.util.helper.LoginHelper;
Expand All @@ -44,6 +46,7 @@
@Data
@ExcelIgnoreUnannotated
@Schema(description = "用户详情信息")
@Assemble(container = ContainerConstants.USER_ROLE_ID_LIST, key = "id", props = @Mapping(ref = "roleIds"))
public class UserDetailResp extends BaseDetailResp {

@Serial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ protected void fill(Object obj) {
super.fill(obj);
if (obj instanceof RoleDetailResp detail) {
Long roleId = detail.getId();
List<Long> deptIdList = roleDeptService.listDeptIdByRoleId(roleId);
detail.setDeptIds(deptIdList);
if (SysConstants.ADMIN_ROLE_CODE.equals(detail.getCode())) {
List<MenuResp> list = menuService.listAll();
List<Long> menuIds = list.stream().map(MenuResp::getId).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ public void delete(List<Long> ids) {
protected void fill(Object obj) {
super.fill(obj);
if (obj instanceof UserDetailResp detail) {
List<Long> roleIdList = userRoleService.listRoleIdByUserId(detail.getId());
detail.setRoleIds(roleIdList);
List<Long> roleIdList = detail.getRoleIds();
if (CollUtil.isNotEmpty(roleIdList)) {
detail.setRoleNames(String.join(StringConstants.CHINESE_COMMA, roleService.listNameByIds(roleIdList)));
}
Expand Down

0 comments on commit c05584b

Please sign in to comment.