feat:资料库内容创建接口
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.shuwen.groot.api.dto.request.library;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Project: groot-data-bank
|
||||
* Description:
|
||||
* Author: Kenn
|
||||
* Create: 2023/7/11 17:21
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class CreateLibraryContentRequest extends CreateLibraryImportTaskRequest {
|
||||
/**
|
||||
* 资料内容
|
||||
*/
|
||||
private String content;
|
||||
}
|
||||
@@ -91,6 +91,14 @@ public interface ILibraryService {
|
||||
*/
|
||||
Object stat(StatLibraryRequest request);
|
||||
|
||||
/**
|
||||
* 创建资料库内容
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 资料内容
|
||||
*/
|
||||
Object createContent(CreateLibraryContentRequest request);
|
||||
|
||||
/**
|
||||
* 获取资料库内容
|
||||
*
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.shuwen.groot.common.utils.MarkdownUtils;
|
||||
import com.shuwen.groot.dao.entity.LibraryImportTask;
|
||||
import com.shuwen.groot.dao.service.ILibraryImportTaskService;
|
||||
import com.shuwen.groot.manager.collected.CollectedDataManager;
|
||||
import com.shuwen.groot.manager.config.base.GssConfig;
|
||||
import com.shuwen.groot.manager.configmap.LibraryRetrievalParamsConfig;
|
||||
import com.shuwen.groot.manager.configmap.QuestionCleanWords;
|
||||
import com.shuwen.groot.manager.configmap.SwitchConfig;
|
||||
@@ -46,6 +47,7 @@ import com.shuwen.mid.sdk.tools.duplicate.vo.CompareResultVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -59,6 +61,7 @@ import xhzy.algo.engine.Term;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -129,6 +132,9 @@ public class LibraryServiceImpl implements ILibraryService {
|
||||
@Resource
|
||||
private Executor libraryConvertExecutor;
|
||||
|
||||
@Resource
|
||||
private GssConfig gssConfig;
|
||||
|
||||
@Override
|
||||
public void update(UpdateLibraryRequest request) {
|
||||
check(request);
|
||||
@@ -584,6 +590,25 @@ public class LibraryServiceImpl implements ILibraryService {
|
||||
return libraryTextSearchHandler.stat(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createContent(CreateLibraryContentRequest request) {
|
||||
check(request);
|
||||
|
||||
//先上传内容到oss
|
||||
String url=null;
|
||||
String key = request.getTenantId() + "/" + request.getUserId() + "/upload/" + System.currentTimeMillis()+".md";
|
||||
try{
|
||||
url = gssHandler.put(key, IOUtils.toInputStream(request.getContent(), StandardCharsets.UTF_8.name()));
|
||||
} catch (Exception e) {
|
||||
throw new DataBankException(InternalErrorCode.OSS_ERROR, "oss上传内容异常", e);
|
||||
}
|
||||
request.setUrl(url);
|
||||
request.setCategory(LibraryCategory.document);
|
||||
|
||||
//再走资料上传流程
|
||||
return libraryTaskService.create(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContent(GetLibraryContentRequest request) {
|
||||
check(request);
|
||||
@@ -742,6 +767,11 @@ public class LibraryServiceImpl implements ILibraryService {
|
||||
checkNotNull(request.getLevel(), InternalErrorCode.EMPTY_PARAMS, "The dataset level is null");
|
||||
}
|
||||
|
||||
private void check(CreateLibraryContentRequest request) {
|
||||
checkNotEmpty(request.getContent(), InternalErrorCode.EMPTY_PARAMS, "The content is empty");
|
||||
checkNotEmpty(request.getName(), InternalErrorCode.EMPTY_PARAMS, "The name is empty");
|
||||
}
|
||||
|
||||
private void check(GetLibraryContentRequest request) {
|
||||
checkNotEmpty(request.getDatasetId(), InternalErrorCode.EMPTY_PARAMS, "The dataset id is empty");
|
||||
}
|
||||
|
||||
@@ -91,6 +91,12 @@ public class LibraryController {
|
||||
return libraryService.stat(request);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/content/create", produces = "application/json", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object createContent(@RequestBody CreateLibraryContentRequest request) {
|
||||
return libraryService.createContent(request);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/content/get", produces = "application/json", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object getContent(@RequestBody GetLibraryContentRequest request) {
|
||||
|
||||
Reference in New Issue
Block a user