feat: 查询命令分组.
This commit is contained in:
@@ -7,6 +7,7 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 命令片段分组 视图响应对象
|
||||
@@ -30,4 +31,7 @@ public class CommandSnippetGroupVO implements Serializable {
|
||||
@Schema(description = "分组名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "命令片段列表")
|
||||
private List<CommandSnippetVO> items;
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class CommandSnippetWrapperVO implements Serializable {
|
||||
@Schema(description = "分组")
|
||||
private List<CommandSnippetGroupVO> groups;
|
||||
|
||||
@Schema(description = "命令片段")
|
||||
private List<CommandSnippetVO> items;
|
||||
@Schema(description = "未分组的命令片段")
|
||||
private List<CommandSnippetVO> ungroupedItems;
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.orion.ops.module.asset.service.impl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
@@ -25,7 +26,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -92,9 +96,22 @@ public class CommandSnippetServiceImpl implements CommandSnippetService {
|
||||
List<CommandSnippetGroupVO> groups = commandSnippetGroupService.getCommandSnippetGroupList();
|
||||
// 查询命令片段
|
||||
List<CommandSnippetVO> items = this.getCommandSnippetList();
|
||||
// 设置组内数据
|
||||
Map<Long, CommandSnippetGroupVO> groupMap = groups.stream()
|
||||
.collect(Collectors.toMap(CommandSnippetGroupVO::getId, Function.identity()));
|
||||
groupMap.forEach((groupId, group) -> {
|
||||
List<CommandSnippetVO> groupedItems = items.stream()
|
||||
.filter(s -> groupId.equals(s.getGroupId()))
|
||||
.collect(Collectors.toList());
|
||||
group.setItems(groupedItems);
|
||||
});
|
||||
// 未分组数据
|
||||
List<CommandSnippetVO> ungroupedItems = items.stream()
|
||||
.filter(s -> s.getGroupId() == null)
|
||||
.collect(Collectors.toList());
|
||||
return CommandSnippetWrapperVO.builder()
|
||||
.groups(groups)
|
||||
.items(items)
|
||||
.ungroupedItems(ungroupedItems)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user