feat: (REQ-3846) 根据code批量查询indexNode接口-加上fileKey/fileUrl

This commit is contained in:
xudawei 2025-04-14 11:03:57 +08:00
parent 3cf2f063d0
commit 6ca353c221
7 changed files with 142 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package cn.axzo.nanopart.doc.api.anonymous;
import javax.validation.Valid;
import cn.axzo.nanopart.doc.api.domain.IndexNodeInfo;
import cn.axzo.nanopart.doc.api.index.request.BatchGetNodeInfoRequest;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -13,6 +15,8 @@ import cn.axzo.nanopart.doc.api.anonymous.request.AnonymousUploadFileRequest;
import cn.axzo.nanopart.doc.api.index.request.CopyNodeRequest;
import cn.azxo.framework.common.model.CommonResponse;
import java.util.Map;
/**
* @author yanglin
*/
@ -51,4 +55,10 @@ public interface DocAnonymousDatabaseApi {
@PostMapping("/api/anonymous/copy")
CommonResponse<String> copy(@RequestBody @Valid CopyNodeRequest request);
/**
* 批量获取节点信息集合
*/
@PostMapping("/api/anonymous/batchGetNodeInfo")
CommonResponse<Map<String, IndexNodeInfo>> batchGetNodeInfo(@RequestBody @Valid BatchGetNodeInfoRequest request);
}

View File

@ -125,6 +125,10 @@ public class IndexNodeInfo implements NodeValue, ValueContainer<IndexNodeInfo> {
private IndexNodeAttributes attributes;
private String ossFileKey;
private String ossFileUrl;
public Path path() {
return Path.wrap(path);
}
@ -145,6 +149,12 @@ public class IndexNodeInfo implements NodeValue, ValueContainer<IndexNodeInfo> {
return fileTemplateNodeInfo;
}
@JsonIgnore
@JSONField(serialize = false, deserialize = false)
public FileAttributes getOrCreateFileAttributes() {
return getOrCreateAttributes().getOrCreateFileAttributes();
}
@Override
public Long id() {
return id;

View File

@ -0,0 +1,32 @@
package cn.axzo.nanopart.doc.api.index.request;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty;
import java.util.List;
/**
* @author xudawei@axzo.cn
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BatchGetNodeInfoRequest {
/**
* 节点编码集合
*/
@NotEmpty(message = "节点编码集合不能为空")
private List<String> codes;
/**
* 是否需要fileUrltrue:需要,false:不需要
* 默认false
*/
private Boolean needFileUrl = false;
}

View File

@ -5,6 +5,8 @@ import java.util.List;
import java.util.stream.Collectors;
import cn.axzo.nanopart.doc.api.enums.DatabaseScope;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
@ -53,6 +55,15 @@ public class IndexNodeDao extends ServiceImpl<IndexNodeMapper, IndexNode> {
.one();
}
public List<IndexNode> findByCodes(List<String> codes) {
if (CollectionUtils.isEmpty(codes)) {
return Lists.newArrayList();
}
return lambdaQuery() //
.in(IndexNode::getCode, codes) //
.list();
}
public void updatePath(String code, String path) {
lambdaUpdate() //
.eq(IndexNode::getCode, code) //

View File

@ -1,8 +1,22 @@
package cn.axzo.nanopart.doc.file.anonymous;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.function.Function;
import java.util.stream.Collectors;
import cn.axzo.nanopart.doc.api.domain.IndexNodeInfo;
import cn.axzo.nanopart.doc.api.index.request.BatchGetNodeInfoRequest;
import cn.axzo.nanopart.doc.integration.OssClient;
import cn.axzo.oss.http.model.ApiSignUrlDownloadResponse;
import cn.hutool.core.bean.BeanUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;
import cn.axzo.nanopart.doc.api.anonymous.DocAnonymousDatabaseApi;
@ -28,6 +42,7 @@ public class DocAnonymousDatabaseApiController implements DocAnonymousDatabaseAp
private final IndexManager indexManager;
private final AsyncUtils asyncUtils;
private final OssClient ossClient;
@Override
public CommonResponse<String> createDir(AnonymousCreateDirRequest request) {
@ -56,4 +71,46 @@ public class DocAnonymousDatabaseApiController implements DocAnonymousDatabaseAp
return CommonResponse.success(asyncUtils.getOrTimeout(future, 60, "克隆").getCode());
}
/**
* 批量获取节点信息集合
*/
@Override
public CommonResponse<Map<String, IndexNodeInfo>> batchGetNodeInfo(BatchGetNodeInfoRequest request) {
if (Objects.isNull(request) || CollectionUtils.isEmpty(request.getCodes())) {
return CommonResponse.success(Collections.emptyMap());
}
List<IndexNode> indexNodes = indexManager.findByCodes(request.getCodes());
if (CollectionUtils.isEmpty(indexNodes)) {
return CommonResponse.success(Collections.emptyMap());
}
List<IndexNodeInfo> indexNodeInfos = BeanUtil.copyToList(indexNodes, IndexNodeInfo.class);
//填充对象中的fileKey/fileUrl
this.fillFileKeyUrl(request, indexNodeInfos);
Map<String, IndexNodeInfo> nodeInfoMap = indexNodeInfos.stream()
.collect(Collectors.toMap(item -> item.getCode(), Function.identity(), (x, y) -> x));
return CommonResponse.success(nodeInfoMap);
}
/**
* 填充对象中的fileKey/fileUrl
*/
private void fillFileKeyUrl(BatchGetNodeInfoRequest request, List<IndexNodeInfo> indexNodeInfos) {
if (request.getNeedFileUrl()) {
Set<String> fileKeys = indexNodeInfos.stream().filter(item -> StringUtils.hasText(item.getOrCreateFileAttributes().getOssFileKey()))
.map(item -> item.getOrCreateFileAttributes().getOssFileKey())
.collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(fileKeys)) {
List<ApiSignUrlDownloadResponse> urlResponses = ossClient.batchGetOssUrl(fileKeys);
Map<String, String> fileKeyAndUrlMap = urlResponses.stream().collect(Collectors.toMap(key -> key.getFileKey(), value -> value.getSignUrl(), (x, y) -> x));
indexNodeInfos.stream().filter(item -> StringUtils.hasText(item.getOrCreateFileAttributes().getOssFileKey()))
.forEach(item -> {
item.setOssFileKey(item.getOrCreateFileAttributes().getOssFileKey());
item.setOssFileUrl(fileKeyAndUrlMap.get(item.getOssFileKey()));
});
}
}
}
}

View File

@ -254,6 +254,10 @@ public class IndexManager {
return indexNodeDao.getOrThrow(code);
}
public List<IndexNode> findByCodes(List<String> codes) {
return indexNodeDao.findByCodes(codes);
}
public void updateBizInfo(String code, String bizCode, String description, String icon) {
if (StringUtils.isBlank(bizCode) && StringUtils.isBlank(description) && StringUtils.isBlank(icon))
return;

View File

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;
@ -152,4 +153,21 @@ public class OssClient {
docLogDao.log(context, subject, logContents);
}
public List<ApiSignUrlDownloadResponse> batchGetOssUrl(Set<String> ossFileKeys) {
if (CollectionUtils.isEmpty(ossFileKeys)) {
return Collections.emptyList();
}
ApiSignUrlDownloadRequest request = new ApiSignUrlDownloadRequest();
request.setFileKeys(Lists.newArrayList(ossFileKeys));
try {
log.info("OssClient-batchGetOssUrl params:{}", JSON.toJSONString(ossFileKeys));
CommonResponse<List<ApiSignUrlDownloadResponse>> response = serverFileServiceApi.signUrlFetchDownload(request);
log.info("OssClient-batchGetOssUrl params:{},result:{}", JSON.toJSONString(ossFileKeys), JSON.toJSONString(response));
return response.getData();
} catch (Exception e) {
log.warn("OssClient-batchGetOssUrl exception, fileKeys:{}", JSON.toJSONString(ossFileKeys), e);
throw new RuntimeException(e);
}
}
}