作者 dong

知识库列表没有进行分页,问题库列表没有及进行分页处理,存入问题库增加重复校验,日志管理增加回答方式,是否存入问题库,五个需要已实现

正在显示 13 个修改的文件 包含 212 行增加35 行删除
@@ -12,8 +12,11 @@ import org.jeecg.common.api.vo.Result; @@ -12,8 +12,11 @@ import org.jeecg.common.api.vo.Result;
12 import org.jeecg.common.aspect.annotation.AutoLog; 12 import org.jeecg.common.aspect.annotation.AutoLog;
13 import org.jeecg.common.system.base.controller.JeecgController; 13 import org.jeecg.common.system.base.controller.JeecgController;
14 import org.jeecg.common.system.query.QueryGenerator; 14 import org.jeecg.common.system.query.QueryGenerator;
  15 +import org.jeecg.modules.airag.app.config.DataSourceConfig;
15 import org.jeecg.modules.airag.app.entity.AiragLog; 16 import org.jeecg.modules.airag.app.entity.AiragLog;
  17 +import org.jeecg.modules.airag.app.entity.QuestionEmbedding;
16 import org.jeecg.modules.airag.app.service.IAiragLogService; 18 import org.jeecg.modules.airag.app.service.IAiragLogService;
  19 +import org.jeecg.modules.airag.app.service.IQuestionEmbeddingService;
17 import org.jeecg.modules.airag.llm.entity.AiragKnowledge; 20 import org.jeecg.modules.airag.llm.entity.AiragKnowledge;
18 import org.jeecg.modules.airag.llm.entity.AiragModel; 21 import org.jeecg.modules.airag.llm.entity.AiragModel;
19 import org.jeecg.modules.airag.llm.service.IAiragModelService; 22 import org.jeecg.modules.airag.llm.service.IAiragModelService;
@@ -24,10 +27,7 @@ import org.springframework.web.servlet.ModelAndView; @@ -24,10 +27,7 @@ import org.springframework.web.servlet.ModelAndView;
24 import javax.servlet.http.HttpServletRequest; 27 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse; 28 import javax.servlet.http.HttpServletResponse;
26 import java.sql.SQLException; 29 import java.sql.SQLException;
27 -import java.util.Arrays;  
28 -import java.util.HashMap;  
29 -import java.util.List;  
30 -import java.util.Map; 30 +import java.util.*;
31 31
32 /** 32 /**
33 * @Description: 日志管理 33 * @Description: 日志管理
@@ -45,7 +45,13 @@ public class AiragLogController extends JeecgController<AiragLog, IAiragLogServi @@ -45,7 +45,13 @@ public class AiragLogController extends JeecgController<AiragLog, IAiragLogServi
45 45
46 @Autowired 46 @Autowired
47 private IAiragModelService airagModelService; 47 private IAiragModelService airagModelService;
48 - /** 48 + @Autowired
  49 + private DataSourceConfig dataSourceConfig;
  50 +
  51 + @Autowired
  52 + private IQuestionEmbeddingService questionEmbeddingService;
  53 +
  54 + /**
49 * 分页列表查询 55 * 分页列表查询
50 * 56 *
51 * @param airagLog 57 * @param airagLog
@@ -61,6 +67,8 @@ public class AiragLogController extends JeecgController<AiragLog, IAiragLogServi @@ -61,6 +67,8 @@ public class AiragLogController extends JeecgController<AiragLog, IAiragLogServi
61 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, 67 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
62 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, 68 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
63 HttpServletRequest req) { 69 HttpServletRequest req) {
  70 +
  71 +
64 QueryWrapper<AiragLog> queryWrapper = QueryGenerator.initQueryWrapper(airagLog, req.getParameterMap()); 72 QueryWrapper<AiragLog> queryWrapper = QueryGenerator.initQueryWrapper(airagLog, req.getParameterMap());
65 Page<AiragLog> page = new Page<AiragLog>(pageNo, pageSize); 73 Page<AiragLog> page = new Page<AiragLog>(pageNo, pageSize);
66 // IPage<AiragLog> pageList = airagLogService.page(page, queryWrapper); 74 // IPage<AiragLog> pageList = airagLogService.page(page, queryWrapper);
@@ -127,6 +135,15 @@ public class AiragLogController extends JeecgController<AiragLog, IAiragLogServi @@ -127,6 +135,15 @@ public class AiragLogController extends JeecgController<AiragLog, IAiragLogServi
127 @RequiresPermissions("airaglog:airag_log:saveToQuestionLibrary") 135 @RequiresPermissions("airaglog:airag_log:saveToQuestionLibrary")
128 @PostMapping(value = "/saveToQuestionLibrary") 136 @PostMapping(value = "/saveToQuestionLibrary")
129 public Result<String> saveToQuestionLibrary(@RequestBody AiragLog airagLog) { 137 public Result<String> saveToQuestionLibrary(@RequestBody AiragLog airagLog) {
  138 + QuestionEmbedding questionEmbedding = new QuestionEmbedding();
  139 + questionEmbedding.setQuestion(airagLog.getQuestion());
  140 + List<QuestionEmbedding> list = questionEmbeddingService.findQuestion(questionEmbedding);
  141 + for (QuestionEmbedding questionEmbedding1 : list){
  142 + if(questionEmbedding1.getQuestion().equals(airagLog.getQuestion())){
  143 + return Result.error("问题库已有相同问题,不可存入");
  144 + }
  145 + }
  146 + airagLog.setIsStorage(1);
130 airagLogService.saveToQuestionLibrary(airagLog); 147 airagLogService.saveToQuestionLibrary(airagLog);
131 return Result.OK("存入问题库成功!"); 148 return Result.OK("存入问题库成功!");
132 } 149 }
@@ -59,19 +59,14 @@ public class EmbeddingsController { @@ -59,19 +59,14 @@ public class EmbeddingsController {
59 //@AutoLog(value = "Embeddings-分页列表查询") 59 //@AutoLog(value = "Embeddings-分页列表查询")
60 @Operation(summary = "Embeddings-分页列表查询") 60 @Operation(summary = "Embeddings-分页列表查询")
61 @GetMapping(value = "/list") 61 @GetMapping(value = "/list")
62 - public Result<IPage<Embeddings>> queryPageList(Embeddings embeddings, 62 + public Result<Page<Embeddings>> queryPageList(Embeddings embeddings,
63 @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, 63 @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
64 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, 64 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
65 HttpServletRequest req) throws NoSuchFieldException, IllegalAccessException, SQLException { 65 HttpServletRequest req) throws NoSuchFieldException, IllegalAccessException, SQLException {
66 //Response<Embedding> embedding = aiModelUtils.getEmbedding("1925730210204721154", "33333"); 66 //Response<Embedding> embedding = aiModelUtils.getEmbedding("1925730210204721154", "33333");
67 67
68 - List<Embeddings> records = embeddingsService.findAll(embeddings);  
69 - for (Embeddings record : records) {  
70 - System.out.println("record = " + record);  
71 - }  
72 - Page<Embeddings> page = new Page<Embeddings>(pageNo, pageSize);  
73 - page.setRecords(records);  
74 - return Result.OK(page); 68 + Page<Embeddings> records = embeddingsService.findAll(embeddings,pageNo,pageSize);
  69 + return Result.OK(records);
75 } 70 }
76 /** 71 /**
77 * 查询知识库ID 72 * 查询知识库ID
1 package org.jeecg.modules.airag.app.controller; 1 package org.jeecg.modules.airag.app.controller;
2 2
  3 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 import dev.langchain4j.internal.Json; 4 import dev.langchain4j.internal.Json;
4 import lombok.extern.slf4j.Slf4j; 5 import lombok.extern.slf4j.Slf4j;
5 import org.apache.commons.lang3.StringUtils; 6 import org.apache.commons.lang3.StringUtils;
6 import org.jeecg.common.api.vo.Result; 7 import org.jeecg.common.api.vo.Result;
7 -import org.jeecg.modules.airag.app.entity.AiragLog;  
8 import org.jeecg.modules.airag.app.entity.QuestionEmbedding; 8 import org.jeecg.modules.airag.app.entity.QuestionEmbedding;
9 import org.jeecg.modules.airag.app.service.IQuestionEmbeddingService; 9 import org.jeecg.modules.airag.app.service.IQuestionEmbeddingService;
10 import org.jeecg.modules.airag.app.utils.JsonUtils; 10 import org.jeecg.modules.airag.app.utils.JsonUtils;
11 import org.jeecg.modules.airag.llm.entity.AiragKnowledge; 11 import org.jeecg.modules.airag.llm.entity.AiragKnowledge;
12 -import org.jeecg.modules.airag.llm.entity.AiragModel;  
13 import org.jeecg.modules.airag.llm.service.IAiragKnowledgeService; 12 import org.jeecg.modules.airag.llm.service.IAiragKnowledgeService;
14 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.transaction.annotation.Transactional; 14 import org.springframework.transaction.annotation.Transactional;
@@ -17,7 +16,6 @@ import org.springframework.web.bind.annotation.*; @@ -17,7 +16,6 @@ import org.springframework.web.bind.annotation.*;
17 import org.springframework.web.multipart.MultipartFile; 16 import org.springframework.web.multipart.MultipartFile;
18 17
19 import java.util.HashMap; 18 import java.util.HashMap;
20 -import java.util.List;  
21 import java.util.Map; 19 import java.util.Map;
22 import java.util.stream.Collectors; 20 import java.util.stream.Collectors;
23 21
@@ -31,13 +29,13 @@ public class QuestionEmbeddingController { @@ -31,13 +29,13 @@ public class QuestionEmbeddingController {
31 private IAiragKnowledgeService airagKnowledgeService; 29 private IAiragKnowledgeService airagKnowledgeService;
32 30
33 @GetMapping("/list") 31 @GetMapping("/list")
34 - public Result<List<QuestionEmbedding>> findAll(QuestionEmbedding questionEmbedding) {  
35 - List<QuestionEmbedding> list = questionEmbeddingService.findAll(questionEmbedding); 32 + public Result<Page<QuestionEmbedding>> findAll(QuestionEmbedding questionEmbedding, @RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize) {
  33 + Page<QuestionEmbedding> page = questionEmbeddingService.findAll(questionEmbedding,pageNo,pageSize);
36 Map<String, String> airagKnowledgeMap = airagKnowledgeService.list() 34 Map<String, String> airagKnowledgeMap = airagKnowledgeService.list()
37 .stream() 35 .stream()
38 .collect(Collectors.toMap(AiragKnowledge::getId, AiragKnowledge::getName)); 36 .collect(Collectors.toMap(AiragKnowledge::getId, AiragKnowledge::getName));
39 37
40 - list.forEach(item -> { 38 + page.getRecords().forEach(item -> {
41 String metadata = item.getMetadata(); 39 String metadata = item.getMetadata();
42 if (StringUtils.isNotBlank(metadata)) { 40 if (StringUtils.isNotBlank(metadata)) {
43 Map<String, String> jsonMap = JsonUtils.jsonUtils(metadata); 41 Map<String, String> jsonMap = JsonUtils.jsonUtils(metadata);
@@ -48,8 +46,7 @@ public class QuestionEmbeddingController { @@ -48,8 +46,7 @@ public class QuestionEmbeddingController {
48 } 46 }
49 47
50 }); 48 });
51 -  
52 - return Result.OK(list); 49 + return Result.OK(page);
53 } 50 }
54 51
55 @GetMapping("/queryById") 52 @GetMapping("/queryById")
@@ -77,8 +77,32 @@ public class AiragLog implements Serializable { @@ -77,8 +77,32 @@ public class AiragLog implements Serializable {
77 @Excel(name = "模型ID", width = 15) 77 @Excel(name = "模型ID", width = 15)
78 @Schema(description = "模型ID") 78 @Schema(description = "模型ID")
79 private String modelId; 79 private String modelId;
  80 + /**
  81 + * 回答方式
  82 + */
  83 + @Excel(name = "回答方式", width = 15)
  84 + @TableField("answer_type")
  85 + @Schema(description = "回答方式:1:问题库回答 2:模型回答 3:未命中")
  86 + private int answerType;
  87 + /**
  88 + * 回答方式
  89 + */
  90 + @Excel(name = "是否存入问题库", width = 15)
  91 + @TableField("is_storage")
  92 + @Schema(description = "是否存入问题库 0:否 1:是")
  93 + private int isStorage;
80 94
81 // 新增:临时字段(非数据库字段) 95 // 新增:临时字段(非数据库字段)
82 @TableField(exist = false) // MyBatis-Plus 标记该字段不存在于数据库表中 96 @TableField(exist = false) // MyBatis-Plus 标记该字段不存在于数据库表中
83 private String name; 97 private String name;
  98 +
  99 + // 新增:临时字段(非数据库字段)
  100 + @TableField(exist = false) // MyBatis-Plus 标记该字段不存在于数据库表中
  101 + private String createTime_begin;
  102 + // 新增:临时字段(非数据库字段)
  103 + @TableField(exist = false) // MyBatis-Plus 标记该字段不存在于数据库表中
  104 + private String createTime_end;
  105 +
  106 + @TableField(exist = false) // MyBatis-Plus 标记该字段不存在于数据库表中
  107 + private String createTimeStr;
84 } 108 }
@@ -18,4 +18,7 @@ public interface AiragLogMapper extends BaseMapper<AiragLog> { @@ -18,4 +18,7 @@ public interface AiragLogMapper extends BaseMapper<AiragLog> {
18 IPage<AiragLog> list1(@Param("param1")AiragLog airagLog, Page<AiragLog> page); 18 IPage<AiragLog> list1(@Param("param1")AiragLog airagLog, Page<AiragLog> page);
19 19
20 IPage<AiragLog> pageList(@Param("param1") AiragLog airagLog, Page<AiragLog> page); 20 IPage<AiragLog> pageList(@Param("param1") AiragLog airagLog, Page<AiragLog> page);
  21 +
  22 + int updataIsStorage(@Param("param1") int isStorage);
  23 +
21 } 24 }
@@ -3,6 +3,7 @@ package org.jeecg.modules.airag.app.mapper; @@ -3,6 +3,7 @@ package org.jeecg.modules.airag.app.mapper;
3 import ch.qos.logback.core.net.SyslogOutputStream; 3 import ch.qos.logback.core.net.SyslogOutputStream;
4 import cn.hutool.core.lang.generator.SnowflakeGenerator; 4 import cn.hutool.core.lang.generator.SnowflakeGenerator;
5 import com.alibaba.fastjson2.JSONObject; 5 import com.alibaba.fastjson2.JSONObject;
  6 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 import com.fasterxml.jackson.core.JsonProcessingException; 7 import com.fasterxml.jackson.core.JsonProcessingException;
7 import com.fasterxml.jackson.core.type.TypeReference; 8 import com.fasterxml.jackson.core.type.TypeReference;
8 import com.fasterxml.jackson.databind.ObjectMapper; 9 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -31,22 +32,32 @@ public class PgVectorMapper { @@ -31,22 +32,32 @@ public class PgVectorMapper {
31 } 32 }
32 33
33 // 查询所有向量记录 34 // 查询所有向量记录
34 - public List<Embeddings> findAll(Embeddings embeddings) { 35 + public Page<Embeddings> findAll(Embeddings embeddings,int pageNo,int pageSize) {
35 List<Embeddings> results = new ArrayList<>(); 36 List<Embeddings> results = new ArrayList<>();
36 StringBuilder sql = new StringBuilder("SELECT * FROM embeddings WHERE 1=1"); 37 StringBuilder sql = new StringBuilder("SELECT * FROM embeddings WHERE 1=1");
  38 + StringBuilder countSql = new StringBuilder("SELECT COUNT(1) FROM embeddings WHERE 1=1");
37 List<Object> params = new ArrayList<>(); // 存储参数值 39 List<Object> params = new ArrayList<>(); // 存储参数值
  40 + List<Object> countParams = new ArrayList<>(); // 存储参数值
38 41
39 // 动态构建查询条件 42 // 动态构建查询条件
40 if (StringUtils.isNotBlank(embeddings.getKnowledgeId())) { 43 if (StringUtils.isNotBlank(embeddings.getKnowledgeId())) {
41 sql.append(" AND metadata ->> 'knowledgeId' = ?"); 44 sql.append(" AND metadata ->> 'knowledgeId' = ?");
  45 + countSql.append(" AND metadata ->> 'knowledgeId' = ?");
42 params.add(embeddings.getKnowledgeId()); 46 params.add(embeddings.getKnowledgeId());
  47 + countParams.add(embeddings.getKnowledgeId());
43 } 48 }
44 49
45 if (StringUtils.isNotBlank(embeddings.getText())) { 50 if (StringUtils.isNotBlank(embeddings.getText())) {
46 sql.append(" AND text ILIKE ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配 51 sql.append(" AND text ILIKE ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配
  52 + countSql.append(" AND text ILIKE ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配
47 params.add("%" + embeddings.getText() + "%"); 53 params.add("%" + embeddings.getText() + "%");
  54 + countParams.add("%" + embeddings.getText() + "%");
48 } 55 }
49 56
  57 + // 添加分页
  58 + sql.append(" LIMIT ? OFFSET ?");
  59 + params.add(pageSize);
  60 + params.add((pageNo - 1) * pageSize);
50 61
51 System.out.println("SQL: " + sql.toString()); 62 System.out.println("SQL: " + sql.toString());
52 63
@@ -67,7 +78,31 @@ public class PgVectorMapper { @@ -67,7 +78,31 @@ public class PgVectorMapper {
67 log.error("查询所有向量记录失败", e); 78 log.error("查询所有向量记录失败", e);
68 throw new RuntimeException("查询向量数据时发生数据库错误", e); 79 throw new RuntimeException("查询向量数据时发生数据库错误", e);
69 } 80 }
70 - return results; 81 +
  82 +
  83 + // 执行计数查询
  84 + int total = 0;
  85 + try(Connection conn = getConnection();
  86 + PreparedStatement stmt = conn.prepareStatement(countSql.toString())){
  87 + // 设置参数值
  88 + for (int i = 0; i < countParams.size(); i++) {
  89 + stmt.setObject(i + 1, countParams.get(i));
  90 + }
  91 +
  92 + try (ResultSet rs = stmt.executeQuery()) {
  93 + if (rs.next()) {
  94 + total = rs.getInt(1); // 直接获取count值
  95 + }
  96 + }
  97 + } catch (SQLException e) {
  98 + log.error("查询记录总数失败", e);
  99 + throw new RuntimeException("查询记录总数时发生数据库错误", e);
  100 + }
  101 +
  102 + Page<Embeddings> page = new Page<>();
  103 + page.setRecords(results);
  104 + page.setTotal(total);
  105 + return page;
71 } 106 }
72 107
73 // 根据ID查询单个向量记录 108 // 根据ID查询单个向量记录
@@ -2,6 +2,7 @@ package org.jeecg.modules.airag.app.mapper; @@ -2,6 +2,7 @@ package org.jeecg.modules.airag.app.mapper;
2 2
3 import cn.hutool.core.lang.generator.SnowflakeGenerator; 3 import cn.hutool.core.lang.generator.SnowflakeGenerator;
4 import com.alibaba.fastjson2.JSONObject; 4 import com.alibaba.fastjson2.JSONObject;
  5 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5 import com.fasterxml.jackson.core.JsonProcessingException; 6 import com.fasterxml.jackson.core.JsonProcessingException;
6 import com.fasterxml.jackson.core.type.TypeReference; 7 import com.fasterxml.jackson.core.type.TypeReference;
7 import com.fasterxml.jackson.databind.ObjectMapper; 8 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -38,22 +39,93 @@ public class QuestionEmbeddingMapper { @@ -38,22 +39,93 @@ public class QuestionEmbeddingMapper {
38 } 39 }
39 40
40 // 查询所有记录 41 // 查询所有记录
41 - public List<QuestionEmbedding> findAll(QuestionEmbedding questionEmbedding) { 42 + public Page<QuestionEmbedding> findAll(QuestionEmbedding questionEmbedding, int pageNo, int pageSize) {
42 List<QuestionEmbedding> results = new ArrayList<>(); 43 List<QuestionEmbedding> results = new ArrayList<>();
43 StringBuilder sql = new StringBuilder("select * from question_embedding where 1 = 1"); 44 StringBuilder sql = new StringBuilder("select * from question_embedding where 1 = 1");
  45 + StringBuilder countSql = new StringBuilder("select count(1) from question_embedding where 1 = 1");
44 List<Object> params = new ArrayList<>(); 46 List<Object> params = new ArrayList<>();
  47 + List<Object> countParams = new ArrayList<>();
45 48
46 if (StringUtils.isNotBlank(questionEmbedding.getKnowledgeId())) { 49 if (StringUtils.isNotBlank(questionEmbedding.getKnowledgeId())) {
47 sql.append(" AND metadata ->> 'knowledgeId' = ?"); 50 sql.append(" AND metadata ->> 'knowledgeId' = ?");
  51 + countSql.append(" AND metadata ->> 'knowledgeId' = ?");
48 params.add(questionEmbedding.getKnowledgeId()); 52 params.add(questionEmbedding.getKnowledgeId());
  53 + countParams.add(questionEmbedding.getKnowledgeId());
49 } 54 }
50 if(StringUtils.isNotBlank(questionEmbedding.getQuestion())){ 55 if(StringUtils.isNotBlank(questionEmbedding.getQuestion())){
51 - sql.append(" and question like '%").append(questionEmbedding.getQuestion()).append("%'"); 56 + sql.append(" AND question ILIKE ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配
  57 + countSql.append(" AND question ILIKE ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配
  58 + params.add("%" + questionEmbedding.getQuestion() + "%");
  59 + countParams.add("%" + questionEmbedding.getQuestion() + "%");
52 } 60 }
53 61
54 if(StringUtils.isNotBlank(questionEmbedding.getAnswer())){ 62 if(StringUtils.isNotBlank(questionEmbedding.getAnswer())){
55 - sql.append(" and answer like '%").append(questionEmbedding.getAnswer()).append("%'"); 63 + sql.append(" AND answer ILIKE ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配
  64 + countSql.append(" AND answer ILIKE ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配
  65 + params.add("%" + questionEmbedding.getAnswer() + "%");
  66 + countParams.add("%" + questionEmbedding.getAnswer() + "%");
56 } 67 }
  68 +
  69 + // 添加分页
  70 + sql.append(" LIMIT ? OFFSET ?");
  71 + params.add(pageSize);
  72 + params.add((pageNo - 1) * pageSize);
  73 +
  74 +
  75 + try(Connection conn = getConnection();
  76 + PreparedStatement stmt = conn.prepareStatement(sql.toString())){
  77 + // 设置参数值
  78 + for (int i = 0; i < params.size(); i++) {
  79 + stmt.setObject(i + 1, params.get(i));
  80 + }
  81 +
  82 + try (ResultSet rs = stmt.executeQuery()) {
  83 + while (rs.next()) {
  84 + results.add(mapRowToQuestionEmbedding(rs));
  85 + }
  86 + }
  87 + } catch (SQLException e) {
  88 + log.error("查询所有记录失败", e);
  89 + throw new RuntimeException("查询数据时发生数据库错误", e);
  90 + }
  91 +
  92 + // 执行计数查询
  93 + long total = 0;
  94 + try(Connection conn = getConnection();
  95 + PreparedStatement stmt = conn.prepareStatement(countSql.toString())){
  96 + // 设置参数值
  97 + for (int i = 0; i < countParams.size(); i++) {
  98 + stmt.setObject(i + 1, countParams.get(i));
  99 + }
  100 +
  101 + try (ResultSet rs = stmt.executeQuery()) {
  102 + if (rs.next()) {
  103 + total = rs.getLong(1); // 直接获取count值
  104 + }
  105 + }
  106 + } catch (SQLException e) {
  107 + log.error("查询记录总数失败", e);
  108 + throw new RuntimeException("查询记录总数时发生数据库错误", e);
  109 + }
  110 +
  111 + Page<QuestionEmbedding> page = new Page<>();
  112 + page.setRecords(results);
  113 + page.setTotal(total);
  114 + return page;
  115 + }
  116 +
  117 + // 查询所有记录
  118 + public List<QuestionEmbedding> findQuestion(QuestionEmbedding questionEmbedding) {
  119 + List<QuestionEmbedding> results = new ArrayList<>();
  120 + StringBuilder sql = new StringBuilder("select * from question_embedding where 1 = 1");
  121 + List<Object> params = new ArrayList<>();
  122 +
  123 + if(StringUtils.isNotBlank(questionEmbedding.getQuestion())){
  124 + sql.append(" AND question = ?"); // 使用 ILIKE 进行不区分大小写的模糊匹配
  125 + params.add(questionEmbedding.getQuestion());
  126 + }
  127 +
  128 +
57 try(Connection conn = getConnection(); 129 try(Connection conn = getConnection();
58 PreparedStatement stmt = conn.prepareStatement(sql.toString())){ 130 PreparedStatement stmt = conn.prepareStatement(sql.toString())){
59 // 设置参数值 131 // 设置参数值
@@ -70,6 +142,8 @@ public class QuestionEmbeddingMapper { @@ -70,6 +142,8 @@ public class QuestionEmbeddingMapper {
70 log.error("查询所有记录失败", e); 142 log.error("查询所有记录失败", e);
71 throw new RuntimeException("查询数据时发生数据库错误", e); 143 throw new RuntimeException("查询数据时发生数据库错误", e);
72 } 144 }
  145 +
  146 +
73 return results; 147 return results;
74 } 148 }
75 149
@@ -9,13 +9,35 @@ @@ -9,13 +9,35 @@
9 </select> 9 </select>
10 10
11 <select id="pageList" resultType="org.jeecg.modules.airag.app.entity.AiragLog"> 11 <select id="pageList" resultType="org.jeecg.modules.airag.app.entity.AiragLog">
12 - select * from airag_log 12 + select
  13 + id, create_by, create_time,
  14 + update_by, update_time, question,
  15 + answer, model_id, answer_type, is_storage
  16 + from airag_log
13 where 1=1 17 where 1=1
  18 + <if test="param1.isStorage != null and param1.isStorage != -1">
  19 + and is_storage = #{param1.isStorage}
  20 + </if>
14 <if test="param1.name != '' and param1.name != null"> 21 <if test="param1.name != '' and param1.name != null">
15 and model_id = #{param1.name} 22 and model_id = #{param1.name}
16 </if> 23 </if>
17 <if test="param1.question != '' and param1.question != null"> 24 <if test="param1.question != '' and param1.question != null">
18 and question LIKE CONCAT('%', #{param1.question}, '%') 25 and question LIKE CONCAT('%', #{param1.question}, '%')
19 </if> 26 </if>
  27 + <if test="param1.answerType != '' and param1.answerType != null">
  28 + and answer_type = #{param1.answerType}
  29 + </if>
  30 + <if test="param1.createTime_begin != '' and param1.createTime_begin != null and param1.createTime_end != null and param1.createTime_end != null">
  31 + and create_time between #{param1.createTime_begin} and #{param1.createTime_end}
  32 + </if>
  33 +
  34 +
  35 +
  36 +
20 </select> 37 </select>
  38 +
  39 + <update id="updataIsStorage">
  40 + update airag_log
  41 + set is_storage = #{isStorage}
  42 + </update>
21 </mapper> 43 </mapper>
@@ -2,6 +2,7 @@ package org.jeecg.modules.airag.app.service; @@ -2,6 +2,7 @@ package org.jeecg.modules.airag.app.service;
2 2
3 //import org.jeecg.modules.demo.test.entity.Test; 3 //import org.jeecg.modules.demo.test.entity.Test;
4 4
  5 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5 import org.jeecg.modules.airag.app.entity.Embeddings; 6 import org.jeecg.modules.airag.app.entity.Embeddings;
6 7
7 import java.util.List; 8 import java.util.List;
@@ -14,7 +15,7 @@ import java.util.List; @@ -14,7 +15,7 @@ import java.util.List;
14 */ 15 */
15 public interface IEmbeddingsService { 16 public interface IEmbeddingsService {
16 17
17 - List<Embeddings> findAll(Embeddings embeddings); 18 + Page<Embeddings> findAll(Embeddings embeddings,int pageNo,int pageSize);
18 int deleteById(String id); 19 int deleteById(String id);
19 int insert(Embeddings record); 20 int insert(Embeddings record);
20 int update(Embeddings record); 21 int update(Embeddings record);
1 package org.jeecg.modules.airag.app.service; 1 package org.jeecg.modules.airag.app.service;
2 2
  3 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 import org.jeecg.common.api.vo.Result; 4 import org.jeecg.common.api.vo.Result;
4 import org.jeecg.modules.airag.app.entity.QuestionEmbedding; 5 import org.jeecg.modules.airag.app.entity.QuestionEmbedding;
5 import org.springframework.web.multipart.MultipartFile; 6 import org.springframework.web.multipart.MultipartFile;
@@ -7,7 +8,8 @@ import org.springframework.web.multipart.MultipartFile; @@ -7,7 +8,8 @@ import org.springframework.web.multipart.MultipartFile;
7 import java.util.List; 8 import java.util.List;
8 9
9 public interface IQuestionEmbeddingService { 10 public interface IQuestionEmbeddingService {
10 - List<QuestionEmbedding> findAll(QuestionEmbedding questionEmbedding); 11 + Page<QuestionEmbedding> findAll(QuestionEmbedding questionEmbedding, Integer pageNo, Integer pageSize);
  12 + List<QuestionEmbedding> findQuestion(QuestionEmbedding questionEmbedding);
11 QuestionEmbedding findById(String id); 13 QuestionEmbedding findById(String id);
12 int insert(QuestionEmbedding record); 14 int insert(QuestionEmbedding record);
13 int update(QuestionEmbedding record); 15 int update(QuestionEmbedding record);
@@ -56,9 +56,9 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i @@ -56,9 +56,9 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i
56 QuestionEmbedding questionEmbedding = new QuestionEmbedding(); 56 QuestionEmbedding questionEmbedding = new QuestionEmbedding();
57 questionEmbedding.setQuestion(log.getQuestion()); 57 questionEmbedding.setQuestion(log.getQuestion());
58 questionEmbedding.setAnswer(log.getAnswer()); 58 questionEmbedding.setAnswer(log.getAnswer());
59 -  
60 -  
61 questionEmbeddingMapper.insert(questionEmbedding); 59 questionEmbeddingMapper.insert(questionEmbedding);
  60 + airagLogMapper.updataIsStorage(log.getIsStorage());
  61 +
62 } 62 }
63 63
64 @Override 64 @Override
1 package org.jeecg.modules.airag.app.service.impl; 1 package org.jeecg.modules.airag.app.service.impl;
2 2
  3 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 import org.jeecg.modules.airag.app.entity.Embeddings; 4 import org.jeecg.modules.airag.app.entity.Embeddings;
4 import org.jeecg.modules.airag.app.mapper.PgVectorMapper; 5 import org.jeecg.modules.airag.app.mapper.PgVectorMapper;
5 import org.jeecg.modules.airag.app.service.IEmbeddingsService; 6 import org.jeecg.modules.airag.app.service.IEmbeddingsService;
@@ -20,8 +21,8 @@ public class IEmbeddingsServiceImpl implements IEmbeddingsService { @@ -20,8 +21,8 @@ public class IEmbeddingsServiceImpl implements IEmbeddingsService {
20 private PgVectorMapper pgVectorMapper; 21 private PgVectorMapper pgVectorMapper;
21 22
22 @Override 23 @Override
23 - public List<Embeddings> findAll(Embeddings embeddings) {  
24 - return pgVectorMapper.findAll(embeddings); 24 + public Page<Embeddings> findAll(Embeddings embeddings, int pageNo, int pageSize) {
  25 + return pgVectorMapper.findAll(embeddings,pageNo,pageSize);
25 } 26 }
26 27
27 public int deleteById(String id) { 28 public int deleteById(String id) {
1 package org.jeecg.modules.airag.app.service.impl; 1 package org.jeecg.modules.airag.app.service.impl;
2 2
  3 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 import org.apache.poi.hwpf.usermodel.CharacterRun; 4 import org.apache.poi.hwpf.usermodel.CharacterRun;
4 import org.apache.poi.hwpf.HWPFDocument; 5 import org.apache.poi.hwpf.HWPFDocument;
5 import org.apache.poi.hwpf.usermodel.Paragraph; 6 import org.apache.poi.hwpf.usermodel.Paragraph;
@@ -64,8 +65,13 @@ public class QuestionEmbeddingServiceImpl implements IQuestionEmbeddingService { @@ -64,8 +65,13 @@ public class QuestionEmbeddingServiceImpl implements IQuestionEmbeddingService {
64 private static final Pattern UUID_PATTERN = Pattern.compile("_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"); 65 private static final Pattern UUID_PATTERN = Pattern.compile("_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
65 66
66 @Override 67 @Override
67 - public List<QuestionEmbedding> findAll(QuestionEmbedding questionEmbedding) {  
68 - return questionEmbeddingMapper.findAll(questionEmbedding); 68 + public Page<QuestionEmbedding> findAll(QuestionEmbedding questionEmbedding, Integer pageNo, Integer pageSize) {
  69 + return questionEmbeddingMapper.findAll(questionEmbedding,pageNo,pageSize);
  70 + }
  71 +
  72 + @Override
  73 + public List<QuestionEmbedding> findQuestion(QuestionEmbedding questionEmbedding) {
  74 + return questionEmbeddingMapper.findQuestion(questionEmbedding);
69 } 75 }
70 76
71 @Override 77 @Override