feat: 增加RAG知识库与文档基础骨架
This commit is contained in:
11
src/main/java/com/bruce/rag/constant/RagSystemConstants.java
Normal file
11
src/main/java/com/bruce/rag/constant/RagSystemConstants.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.bruce.rag.constant;
|
||||
|
||||
public final class RagSystemConstants {
|
||||
|
||||
public static final String RAG_STORE = "RAG_STORE";
|
||||
|
||||
public static final String RAG_DOCUMENT = "RAG_DOCUMENT";
|
||||
|
||||
private RagSystemConstants() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.bruce.rag.controller;
|
||||
|
||||
import com.bruce.rag.entity.RagDocument;
|
||||
import com.bruce.rag.service.IRagDocumentService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "RAG知识库文档管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/rag/documents")
|
||||
public class RagDocumentController {
|
||||
|
||||
private final IRagDocumentService ragDocumentService;
|
||||
|
||||
public RagDocumentController(IRagDocumentService ragDocumentService) {
|
||||
this.ragDocumentService = ragDocumentService;
|
||||
}
|
||||
|
||||
@Operation(summary = "查询全部知识库文档")
|
||||
@GetMapping
|
||||
public List<RagDocument> list() {
|
||||
return ragDocumentService.list();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.bruce.rag.controller;
|
||||
|
||||
import com.bruce.rag.entity.RagStore;
|
||||
import com.bruce.rag.service.IRagStoreService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "RAG知识库管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/rag/stores")
|
||||
public class RagStoreController {
|
||||
|
||||
private final IRagStoreService ragStoreService;
|
||||
|
||||
public RagStoreController(IRagStoreService ragStoreService) {
|
||||
this.ragStoreService = ragStoreService;
|
||||
}
|
||||
|
||||
@Operation(summary = "查询全部知识库")
|
||||
@GetMapping
|
||||
public List<RagStore> list() {
|
||||
return ragStoreService.list();
|
||||
}
|
||||
}
|
||||
51
src/main/java/com/bruce/rag/entity/RagDocument.java
Normal file
51
src/main/java/com/bruce/rag/entity/RagDocument.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.bruce.rag.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.bruce.common.entity.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("rag_document")
|
||||
@Schema(description = "RAG知识库文档")
|
||||
public class RagDocument extends BaseEntity {
|
||||
|
||||
@Schema(description = "知识库ID")
|
||||
@TableField("store_id")
|
||||
private Long storeId;
|
||||
|
||||
@Schema(description = "附件ID")
|
||||
@TableField("attachment_id")
|
||||
private Long attachmentId;
|
||||
|
||||
@Schema(description = "文档标题")
|
||||
@TableField("document_title")
|
||||
private String documentTitle;
|
||||
|
||||
@Schema(description = "文档摘要")
|
||||
@TableField("document_summary")
|
||||
private String documentSummary;
|
||||
|
||||
@Schema(description = "解析状态")
|
||||
@TableField("parse_status")
|
||||
private String parseStatus;
|
||||
|
||||
@Schema(description = "索引状态")
|
||||
@TableField("index_status")
|
||||
private String indexStatus;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean enabled;
|
||||
|
||||
@Schema(description = "失败原因")
|
||||
@TableField("error_message")
|
||||
private String errorMessage;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
||||
31
src/main/java/com/bruce/rag/entity/RagStore.java
Normal file
31
src/main/java/com/bruce/rag/entity/RagStore.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.bruce.rag.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.bruce.common.entity.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("rag_store")
|
||||
@Schema(description = "RAG知识库")
|
||||
public class RagStore extends BaseEntity {
|
||||
|
||||
@Schema(description = "知识库编码")
|
||||
private String storeCode;
|
||||
|
||||
@Schema(description = "知识库名称")
|
||||
private String storeName;
|
||||
|
||||
@Schema(description = "知识库描述")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "状态")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.bruce.rag.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.bruce.rag.entity.RagDocument;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface RagDocumentMapper extends BaseMapper<RagDocument> {
|
||||
}
|
||||
9
src/main/java/com/bruce/rag/mapper/RagStoreMapper.java
Normal file
9
src/main/java/com/bruce/rag/mapper/RagStoreMapper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.bruce.rag.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.bruce.rag.entity.RagStore;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface RagStoreMapper extends BaseMapper<RagStore> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.bruce.rag.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bruce.rag.entity.RagDocument;
|
||||
|
||||
public interface IRagDocumentService extends IService<RagDocument> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.bruce.rag.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bruce.rag.entity.RagStore;
|
||||
|
||||
public interface IRagStoreService extends IService<RagStore> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.bruce.rag.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bruce.rag.entity.RagDocument;
|
||||
import com.bruce.rag.mapper.RagDocumentMapper;
|
||||
import com.bruce.rag.service.IRagDocumentService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RagDocumentServiceImpl extends ServiceImpl<RagDocumentMapper, RagDocument> implements IRagDocumentService {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.bruce.rag.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bruce.rag.entity.RagStore;
|
||||
import com.bruce.rag.mapper.RagStoreMapper;
|
||||
import com.bruce.rag.service.IRagStoreService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RagStoreServiceImpl extends ServiceImpl<RagStoreMapper, RagStore> implements IRagStoreService {
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.bruce.common.enumconfig;
|
||||
|
||||
import com.bruce.common.enums.BaseDictEnum;
|
||||
import com.bruce.common.enums.EnableStatusEnum;
|
||||
import com.bruce.rag.enums.RagIndexStatusEnum;
|
||||
import com.bruce.rag.enums.RagParseStatusEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class EnumDefinitionTests {
|
||||
|
||||
@Test
|
||||
void enumDefinitionsShouldExist() {
|
||||
assertTrue(BaseDictEnum.class.isAssignableFrom(EnableStatusEnum.class));
|
||||
assertTrue(BaseDictEnum.class.isAssignableFrom(RagParseStatusEnum.class));
|
||||
assertTrue(BaseDictEnum.class.isAssignableFrom(RagIndexStatusEnum.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void enumCodesShouldBeStable() {
|
||||
assertEquals("ENABLED", EnableStatusEnum.ENABLED.getCode());
|
||||
assertEquals("DISABLED", EnableStatusEnum.DISABLED.getCode());
|
||||
assertEquals("UPLOADED", RagParseStatusEnum.UPLOADED.getCode());
|
||||
assertEquals("FAILED", RagParseStatusEnum.FAILED.getCode());
|
||||
assertEquals("PENDING", RagIndexStatusEnum.PENDING.getCode());
|
||||
assertEquals("INDEXED", RagIndexStatusEnum.INDEXED.getCode());
|
||||
}
|
||||
}
|
||||
49
src/test/java/com/bruce/rag/RagComponentStructureTests.java
Normal file
49
src/test/java/com/bruce/rag/RagComponentStructureTests.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.bruce.rag;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bruce.rag.constant.RagSystemConstants;
|
||||
import com.bruce.rag.controller.RagDocumentController;
|
||||
import com.bruce.rag.controller.RagStoreController;
|
||||
import com.bruce.rag.entity.RagDocument;
|
||||
import com.bruce.rag.entity.RagStore;
|
||||
import com.bruce.rag.mapper.RagDocumentMapper;
|
||||
import com.bruce.rag.mapper.RagStoreMapper;
|
||||
import com.bruce.rag.service.IRagDocumentService;
|
||||
import com.bruce.rag.service.IRagStoreService;
|
||||
import com.bruce.rag.service.impl.RagDocumentServiceImpl;
|
||||
import com.bruce.rag.service.impl.RagStoreServiceImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class RagComponentStructureTests {
|
||||
|
||||
@Test
|
||||
void ragComponentsShouldReuseMybatisPlusBaseTypes() {
|
||||
assertTrue(BaseMapper.class.isAssignableFrom(RagStoreMapper.class));
|
||||
assertTrue(BaseMapper.class.isAssignableFrom(RagDocumentMapper.class));
|
||||
assertTrue(IService.class.isAssignableFrom(IRagStoreService.class));
|
||||
assertTrue(IService.class.isAssignableFrom(IRagDocumentService.class));
|
||||
assertTrue(ServiceImpl.class.isAssignableFrom(RagStoreServiceImpl.class));
|
||||
assertTrue(ServiceImpl.class.isAssignableFrom(RagDocumentServiceImpl.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ragSourceTypesAndDocumentRelationShouldExist() throws NoSuchFieldException {
|
||||
Field storeIdField = RagDocument.class.getDeclaredField("storeId");
|
||||
Field attachmentIdField = RagDocument.class.getDeclaredField("attachmentId");
|
||||
|
||||
assertEquals("RAG_STORE", RagSystemConstants.RAG_STORE);
|
||||
assertEquals("RAG_DOCUMENT", RagSystemConstants.RAG_DOCUMENT);
|
||||
assertEquals(Long.class, storeIdField.getType());
|
||||
assertEquals(Long.class, attachmentIdField.getType());
|
||||
assertTrue(RagStore.class.getSimpleName().contains("RagStore"));
|
||||
assertTrue(RagStoreController.class.getSimpleName().contains("RagStoreController"));
|
||||
assertTrue(RagDocumentController.class.getSimpleName().contains("RagDocumentController"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user