feat: 增加知识库新类型FAQ知识库
This commit is contained in:
@@ -52,6 +52,17 @@ public class DocumentCollectionController extends BaseCurdController<DocumentCol
|
||||
protected Result<?> onSaveOrUpdateBefore(DocumentCollection entity, boolean isSave) {
|
||||
|
||||
String alias = entity.getAlias();
|
||||
String collectionType = entity.getCollectionType();
|
||||
if (isSave && !StringUtils.hasLength(collectionType)) {
|
||||
entity.setCollectionType(DocumentCollection.TYPE_DOCUMENT);
|
||||
} else if (!DocumentCollection.TYPE_DOCUMENT.equalsIgnoreCase(collectionType)
|
||||
&& !DocumentCollection.TYPE_FAQ.equalsIgnoreCase(collectionType)) {
|
||||
if (StringUtils.hasLength(collectionType)) {
|
||||
throw new BusinessException("知识库类型不正确");
|
||||
}
|
||||
} else {
|
||||
entity.setCollectionType(collectionType.toUpperCase());
|
||||
}
|
||||
|
||||
if (StringUtils.hasLength(alias)){
|
||||
DocumentCollection knowledge = service.getByAlias(alias);
|
||||
@@ -94,7 +105,7 @@ public class DocumentCollectionController extends BaseCurdController<DocumentCol
|
||||
protected Result<Void> onRemoveBefore(Collection<Serializable> ids) {
|
||||
|
||||
QueryWrapper queryWrapper = QueryWrapper.create();
|
||||
queryWrapper.in(BotDocumentCollection::getId, ids);
|
||||
queryWrapper.in(BotDocumentCollection::getDocumentCollectionId, ids);
|
||||
|
||||
boolean exists = botDocumentCollectionService.exists(queryWrapper);
|
||||
if (exists){
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tech.easyflow.ai.entity.Document;
|
||||
@@ -105,13 +104,7 @@ public class DocumentController extends BaseCurdController<DocumentService, Docu
|
||||
throw new BusinessException("知识库id不能为空");
|
||||
}
|
||||
|
||||
DocumentCollection knowledge = StringUtil.isNumeric(kbSlug)
|
||||
? knowledgeService.getById(kbSlug)
|
||||
: knowledgeService.getOne(QueryWrapper.create().eq(DocumentCollection::getSlug, kbSlug));
|
||||
|
||||
if (knowledge == null) {
|
||||
throw new BusinessException("知识库不存在");
|
||||
}
|
||||
DocumentCollection knowledge = getDocumentCollection(kbSlug);
|
||||
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.eq(Document::getCollectionId, knowledge.getId());
|
||||
@@ -128,7 +121,8 @@ public class DocumentController extends BaseCurdController<DocumentService, Docu
|
||||
if (StringUtil.noText(kbSlug)) {
|
||||
throw new BusinessException("知识库id不能为空");
|
||||
}
|
||||
Page<Document> documentList = documentService.getDocumentList(kbSlug, pageSize, pageNumber,fileName);
|
||||
DocumentCollection knowledge = getDocumentCollection(kbSlug);
|
||||
Page<Document> documentList = documentService.getDocumentList(knowledge.getId().toString(), pageSize, pageNumber,fileName);
|
||||
return Result.ok(documentList);
|
||||
}
|
||||
|
||||
@@ -155,6 +149,10 @@ public class DocumentController extends BaseCurdController<DocumentService, Docu
|
||||
@PostMapping(value = {"textSplit", "/saveText"})
|
||||
@SaCheckPermission("/api/v1/documentCollection/save")
|
||||
public Result<?> textSplit(@JsonBody DocumentCollectionSplitParams documentCollectionSplitParams) {
|
||||
if (documentCollectionSplitParams.getKnowledgeId() == null) {
|
||||
throw new BusinessException("知识库id不能为空");
|
||||
}
|
||||
getDocumentCollection(documentCollectionSplitParams.getKnowledgeId().toString());
|
||||
return documentService.textSplit(documentCollectionSplitParams);
|
||||
}
|
||||
|
||||
@@ -221,4 +219,17 @@ public class DocumentController extends BaseCurdController<DocumentService, Docu
|
||||
}
|
||||
}
|
||||
|
||||
private DocumentCollection getDocumentCollection(String idOrSlug) {
|
||||
DocumentCollection knowledge = StringUtil.isNumeric(idOrSlug)
|
||||
? knowledgeService.getById(idOrSlug)
|
||||
: knowledgeService.getOne(QueryWrapper.create().eq(DocumentCollection::getSlug, idOrSlug));
|
||||
if (knowledge == null) {
|
||||
throw new BusinessException("知识库不存在");
|
||||
}
|
||||
if (knowledge.isFaqCollection()) {
|
||||
throw new BusinessException("FAQ知识库不支持文档操作");
|
||||
}
|
||||
return knowledge;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package tech.easyflow.admin.controller.ai;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import tech.easyflow.ai.entity.FaqItem;
|
||||
import tech.easyflow.ai.service.FaqItemService;
|
||||
import tech.easyflow.common.annotation.UsePermission;
|
||||
import tech.easyflow.common.domain.Result;
|
||||
import tech.easyflow.common.web.controller.BaseCurdController;
|
||||
import tech.easyflow.common.web.jsonbody.JsonBody;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/faqItem")
|
||||
@UsePermission(moduleName = "/api/v1/documentCollection")
|
||||
public class FaqItemController extends BaseCurdController<FaqItemService, FaqItem> {
|
||||
|
||||
public FaqItemController(FaqItemService service) {
|
||||
super(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("list")
|
||||
@SaCheckPermission("/api/v1/documentCollection/query")
|
||||
public Result<java.util.List<FaqItem>> list(FaqItem entity, Boolean asTree, String sortKey, String sortType) {
|
||||
return super.list(entity, asTree, sortKey, sortType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("page")
|
||||
@SaCheckPermission("/api/v1/documentCollection/query")
|
||||
public Result<Page<FaqItem>> page(HttpServletRequest request, String sortKey, String sortType, Long pageNumber, Long pageSize) {
|
||||
return super.page(request, sortKey, sortType, pageNumber, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("detail")
|
||||
@SaCheckPermission("/api/v1/documentCollection/query")
|
||||
public Result<FaqItem> detail(String id) {
|
||||
return super.detail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("save")
|
||||
@SaCheckPermission("/api/v1/documentCollection/save")
|
||||
public Result<?> save(@JsonBody FaqItem entity) {
|
||||
return Result.ok(service.saveFaqItem(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("update")
|
||||
@SaCheckPermission("/api/v1/documentCollection/save")
|
||||
public Result<?> update(@JsonBody FaqItem entity) {
|
||||
return Result.ok(service.updateFaqItem(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("remove")
|
||||
@SaCheckPermission("/api/v1/documentCollection/remove")
|
||||
public Result<?> remove(@JsonBody(value = "id", required = true) Serializable id) {
|
||||
return Result.ok(service.removeFaqItem(new java.math.BigInteger(String.valueOf(id))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultOrderBy() {
|
||||
return "order_no asc";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user