diff --git a/chat-server/src/main/java/com/bjtds/brichat/service/dify/constants/DifyConstants.java b/chat-server/src/main/java/com/bjtds/brichat/service/dify/constants/DifyConstants.java index 63d6435..b087d3e 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/service/dify/constants/DifyConstants.java +++ b/chat-server/src/main/java/com/bjtds/brichat/service/dify/constants/DifyConstants.java @@ -15,7 +15,7 @@ public final class DifyConstants { public static final String PDF_TASK_REDIS_KEY = "pdf:conversion:tasks"; public static final String PDF_TASK_LIST_SUFFIX = ":list"; public static final int REDIS_EXPIRE_HOURS = 24; - public static final int PDF_TASK_EXPIRE_MINUTES = 10; // PDF转换任务10分钟超时 + public static final int PDF_TASK_EXPIRE_MINUTES = 120; // PDF转换任务2小时超时(Redis存储时间) // ======== 文件类型常量 ======== public static final String FILE_TYPE_DOC = "doc"; diff --git a/chat-server/src/main/java/com/bjtds/brichat/service/dify/impl/PdfConversionServiceImpl.java b/chat-server/src/main/java/com/bjtds/brichat/service/dify/impl/PdfConversionServiceImpl.java index 1665166..b0f89a0 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/service/dify/impl/PdfConversionServiceImpl.java +++ b/chat-server/src/main/java/com/bjtds/brichat/service/dify/impl/PdfConversionServiceImpl.java @@ -77,6 +77,7 @@ public class PdfConversionServiceImpl implements PdfConversionService { logger.info("PDF转换任务已提交,任务ID: {}, 文件名: {}", taskId, file.getOriginalFilename()); // 构建响应 + //id a4a21249410643f0bc31bdeb2de5dc92 } catch (Exception e) { @@ -121,7 +122,7 @@ public class PdfConversionServiceImpl implements PdfConversionService { logger.info("PDF转换服务调用成功: taskId {}", taskId); } catch (Exception e) { - logger.error("调用PDF转换服务失败: {}", e.getMessage(), e); + logger.error("调用PDF转换服务失败: {} 文件名:{}", e.getMessage(),file.getOriginalFilename()); throw new DifyServiceException("调用PDF转换服务失败: " + e.getMessage(), e); } return taskId; @@ -132,18 +133,26 @@ public class PdfConversionServiceImpl implements PdfConversionService { try { // 使用Hash结构存储,key为任务ID,value为任务信息 String hashKey = DifyConstants.PDF_TASK_REDIS_KEY + ":" + pdfTask.getTaskId(); + logger.info("开始存储PDF任务到Redis,key: {}, 任务ID: {}", hashKey, pdfTask.getTaskId()); + redisTemplate.opsForHash().put(hashKey, "taskInfo", pdfTask); - // 设置过期时间(10分钟) - redisTemplate.expire(hashKey, DifyConstants.PDF_TASK_EXPIRE_MINUTES, TimeUnit.MINUTES); + // 设置过期时间(2小时) + Boolean expireResult = redisTemplate.expire(hashKey, DifyConstants.PDF_TASK_EXPIRE_MINUTES, TimeUnit.MINUTES); + logger.info("设置Redis key过期时间: {} 分钟,结果: {}", DifyConstants.PDF_TASK_EXPIRE_MINUTES, expireResult); // 同时将任务ID加入到任务列表中,便于定时任务扫描 - redisTemplate.opsForList().rightPush( - DifyConstants.PDF_TASK_REDIS_KEY + DifyConstants.PDF_TASK_LIST_SUFFIX, - pdfTask.getTaskId() - ); + String listKey = DifyConstants.PDF_TASK_REDIS_KEY + DifyConstants.PDF_TASK_LIST_SUFFIX; + Long listSize = redisTemplate.opsForList().rightPush(listKey, pdfTask.getTaskId()); + logger.info("任务ID已加入列表,列表key: {}, 当前列表大小: {}", listKey, listSize); - logger.info("PDF任务信息已存储到Redis: {}", pdfTask); + // 验证存储是否成功 + Boolean keyExists = redisTemplate.hasKey(hashKey); + Long ttl = redisTemplate.getExpire(hashKey); + logger.info("存储验证 - key存在: {}, TTL: {} 秒", keyExists, ttl); + + logger.info("PDF任务信息已成功存储到Redis: taskId={}, fileName={}", + pdfTask.getTaskId(), pdfTask.getName()); } catch (Exception e) { logger.error("存储PDF任务信息到Redis失败: {}", e.getMessage(), e); diff --git a/chat-server/src/main/java/com/bjtds/brichat/service/task/PdfConversionResultListener.java b/chat-server/src/main/java/com/bjtds/brichat/service/task/PdfConversionResultListener.java index 34c27a0..decd5d2 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/service/task/PdfConversionResultListener.java +++ b/chat-server/src/main/java/com/bjtds/brichat/service/task/PdfConversionResultListener.java @@ -47,10 +47,29 @@ public class PdfConversionResultListener implements MessageListener { // 从Redis获取任务信息 String hashKey = PDF_TASK_REDIS_KEY + ":" + taskId; + logger.debug("正在查询Redis key: {}", hashKey); + + // 先检查key是否存在 + Boolean keyExists = redisTemplate.hasKey(hashKey); + logger.debug("Redis key {} 是否存在: {}", hashKey, keyExists); + + if (keyExists) { + // 检查key的TTL + Long ttl = redisTemplate.getExpire(hashKey); + logger.debug("Redis key {} 的TTL: {} 秒", hashKey, ttl); + } + PdfTaskDto taskInfo = (PdfTaskDto) redisTemplate.opsForHash().get(hashKey, "taskInfo"); if (taskInfo == null) { - logger.warn("任务{}的信息在Redis中不存在,可能已被清理", taskId); + logger.warn("任务{}的信息在Redis中不存在,可能已被清理。Redis key: {}, key存在: {}", + taskId, hashKey, keyExists); + + // 检查任务列表中是否还有这个任务ID + String listKey = PDF_TASK_REDIS_KEY + ":list"; + //Long position = redisTemplate.opsForList().indexOf(listKey, taskId); + //logger.warn("任务{}在任务列表{}中的位置", taskId, listKey); + return; } diff --git a/chat-server/src/main/java/com/bjtds/brichat/service/task/PdfConversionTaskService.java b/chat-server/src/main/java/com/bjtds/brichat/service/task/PdfConversionTaskService.java index fd79ec5..9937d2a 100644 --- a/chat-server/src/main/java/com/bjtds/brichat/service/task/PdfConversionTaskService.java +++ b/chat-server/src/main/java/com/bjtds/brichat/service/task/PdfConversionTaskService.java @@ -65,7 +65,7 @@ public class PdfConversionTaskService { private static final String DEEP_ANALYSIS_PROCESSING = "deep_analysis:processing"; // PDF任务超时时间(毫秒) - private static final long PDF_TASK_TIMEOUT_MS = 1 * 60 * 60 * 1000; // 1小时 + private static final long PDF_TASK_TIMEOUT_MS = 2 * 60 * 60 * 1000; // 2小时,与Redis过期时间保持一致 /** * 处理成功完成的任务