From ece950fddc25737df490acd12caa6396ddde8a36 Mon Sep 17 00:00:00 2001 From: "liu.zixi" Date: Wed, 24 Sep 2025 10:04:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=BC=96=E8=AF=91=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=9B=20=E5=A2=9E=E5=8A=A0=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boecase/api/CaseDocumentLogApi.java | 139 +++++++++++++++++- .../service/ICaseDocumentLogService.java | 9 ++ .../impl/CaseDocumentLogServiceImpl.java | 11 ++ .../impl/CaseKnowledgeServiceImpl.java | 50 +++---- 4 files changed, 176 insertions(+), 33 deletions(-) diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CaseDocumentLogApi.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CaseDocumentLogApi.java index 826a59cc..342457f0 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CaseDocumentLogApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CaseDocumentLogApi.java @@ -7,6 +7,12 @@ import com.xboe.core.log.AutoLog; import com.xboe.module.boecase.dto.CaseDocumentLogQueryDto; import com.xboe.module.boecase.service.ICaseDocumentLogService; import com.xboe.module.boecase.service.ICaseKnowledgeService; +import com.xboe.module.boecase.service.ICasesService; +import com.xboe.module.boecase.entity.Cases; +import com.xboe.module.boecase.entity.CaseDocumentLog; +import com.xboe.common.utils.IDGenerator; +import com.xboe.common.utils.StringUtil; +import java.time.LocalDateTime; import com.xboe.module.boecase.vo.CaseDocumentLogVo; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -27,6 +33,9 @@ public class CaseDocumentLogApi extends ApiBaseController { @Resource private ICaseKnowledgeService caseKnowledgeService; + @Resource + private ICasesService casesService; + /** * AI调用日志分页查询 * @@ -86,17 +95,101 @@ public class CaseDocumentLogApi extends ApiBaseController { } /** - * 重试请求参数 + * 根据案例ID上传案例文档到知识库 + * + * @param request 上传请求参数 + * @return 上传结果 */ - public static class RetryRequest { - private String logId; - - public String getLogId() { - return logId; + @PostMapping("/uploadCaseByID") + @AutoLog(module = "案例文档管理", action = "根据案例ID上传文档", info = "根据案例ID查询案例信息并上传文档到知识库") + public JsonResponse uploadCaseById(@RequestBody UploadCaseRequest request) { + try { + String caseId = request.getCaseId(); + if (StringUtil.isBlank(caseId)) { + return badRequest("案例ID不能为空"); + } + + // 查询案例信息 + Cases caseInfo = casesService.selectById(caseId, false); + if (caseInfo == null || caseInfo.getDeleted()) { + return badRequest("案例不存在或已删除"); + } + + log.info("开始上传案例文档到知识库,案例ID: {}, 案例标题: {}", caseId, caseInfo.getTitle()); + + // 调用ICaseKnowledgeService的uploadCaseDocument方法 + boolean result = caseKnowledgeService.uploadCaseDocument(caseId); + + if (result) { + log.info("案例文档上传成功,案例ID: {}", caseId); + return success(result, "案例文档上传成功"); + } else { + log.warn("案例文档上传失败,案例ID: {}", caseId); + return success(result, "案例文档上传失败"); + } + + } catch (Exception e) { + log.error("根据案例ID上传文档失败", e); + return error("上传失败", e.getMessage()); } + } - public void setLogId(String logId) { - this.logId = logId; + /** + * 直接创建CaseDocumentLog数据 + * + * @param logData 日志数据 + * @return 创建结果 + */ + @PostMapping("/createLog") + @AutoLog(module = "案例文档日志", action = "创建日志记录", info = "直接创建一条CaseDocumentLog数据") + public JsonResponse createLog(@RequestBody CaseDocumentLog logData) { + try { + // 参数校验 + if (StringUtil.isBlank(logData.getCaseId())) { + return badRequest("案例ID不能为空"); + } + if (StringUtil.isBlank(logData.getOptType())) { + return badRequest("操作类型不能为空"); + } + + // 设置必要的默认值 + if (StringUtil.isBlank(logData.getId())) { + logData.setId(IDGenerator.generate()); + } + if (logData.getOptTime() == null) { + logData.setOptTime(LocalDateTime.now()); + } + if (logData.getOptStatus() == null) { + logData.setOptStatus(0); // 默认为调用中 + } + if (logData.getDeleted() == null) { + logData.setDeleted(false); + } + + // 如果提供了案例ID但没有案例标题,尝试查询案例信息补充标题 + if (StringUtil.isBlank(logData.getCaseTitle()) && StringUtil.isNotBlank(logData.getCaseId())) { + try { + Cases caseInfo = casesService.selectById(logData.getCaseId(), false); + if (caseInfo != null) { + logData.setCaseTitle(caseInfo.getTitle()); + } + } catch (Exception e) { + log.warn("查询案例标题失败,案例ID: {}", logData.getCaseId(), e); + } + } + + log.info("创建CaseDocumentLog记录,案例ID: {}, 操作类型: {}", + logData.getCaseId(), logData.getOptType()); + + // 保存日志记录 + caseDocumentLogService.save(logData); + + log.info("CaseDocumentLog记录创建成功,日志ID: {}", logData.getId()); + return success(logData.getId(), "日志记录创建成功"); + + } catch (Exception e) { + log.error("创建CaseDocumentLog记录失败", e); + return error("创建失败", e.getMessage()); } } @@ -203,4 +296,34 @@ public class CaseDocumentLogApi extends ApiBaseController { } } + /** + * 上传案例请求参数 + */ + public static class UploadCaseRequest { + private String caseId; + + public String getCaseId() { + return caseId; + } + + public void setCaseId(String caseId) { + this.caseId = caseId; + } + } + + /** + * 重试请求参数 + */ + public static class RetryRequest { + private String logId; + + public String getLogId() { + return logId; + } + + public void setLogId(String logId) { + this.logId = logId; + } + } + } \ No newline at end of file diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/ICaseDocumentLogService.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/ICaseDocumentLogService.java index 58cfa45b..66cb9d5c 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/ICaseDocumentLogService.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/ICaseDocumentLogService.java @@ -2,6 +2,7 @@ package com.xboe.module.boecase.service; import com.xboe.common.PageList; import com.xboe.module.boecase.dto.CaseDocumentLogQueryDto; +import com.xboe.module.boecase.entity.CaseDocumentLog; import com.xboe.module.boecase.vo.CaseDocumentLogVo; /** @@ -37,4 +38,12 @@ public interface ICaseDocumentLogService { */ boolean retryByLogId(String logId); + /** + * 保存日志记录 + * + * @param log 日志对象 + * @return 是否成功 + */ + boolean save(CaseDocumentLog log); + } \ No newline at end of file diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CaseDocumentLogServiceImpl.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CaseDocumentLogServiceImpl.java index edeae343..f5679657 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CaseDocumentLogServiceImpl.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CaseDocumentLogServiceImpl.java @@ -222,6 +222,17 @@ public class CaseDocumentLogServiceImpl implements ICaseDocumentLogService { return retrySuccess; } + @Override + public boolean save(CaseDocumentLog caseDocumentLog) { + try { + caseDocumentLogDao.save(caseDocumentLog); + return true; + } catch (Exception e) { + log.error("保存CaseDocumentLog失败", e); + return false; + } + } + /** * 实体转换为VO */ diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CaseKnowledgeServiceImpl.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CaseKnowledgeServiceImpl.java index f1520ba0..7af1c6f0 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CaseKnowledgeServiceImpl.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CaseKnowledgeServiceImpl.java @@ -200,9 +200,9 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService { // 2. 根据案例ID查询最新一条CaseDocumentLog数据 List logList = caseDocumentLogDao.getGenericDao() - .findList(CaseDocumentLog.class, - FieldFilters.eq("caseId", caseId), - OrderCondition.desc("sysCreateTime")); + .findList(CaseDocumentLog.class, 1, + OrderCondition.desc("sysCreateTime"), + FieldFilters.eq("caseId", caseId)); if (logList.isEmpty()) { log.error("删除案例文档失败,未找到相关的日志记录,caseId: {}", caseId); @@ -231,18 +231,18 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService { log.info("删除案例文档第{}次尝试,caseId: {}, taskId: {}", attempt, caseId, taskId); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpDelete httpDelete = new HttpDelete(deleteUrl); + // 构建请求参数 + String params = "kId=" + URLEncoder.encode(caseAiProperties.getCaseKnowledgeId(), StandardCharsets.UTF_8.name()) + + "&taskIds=" + URLEncoder.encode(taskId, StandardCharsets.UTF_8.name()); + HttpDelete httpDelete = new HttpDelete(deleteUrl + "?" + params); httpDelete.setHeader("X-AI-ApiCode", caseAiProperties.getAiApiCode()); httpDelete.setHeader("access_token", accessToken); httpDelete.setHeader("Content-Type", "application/x-www-form-urlencoded"); + - // 构建请求参数 - String params = "kId=" + URLEncoder.encode(caseAiProperties.getCaseKnowledgeId(), StandardCharsets.UTF_8.name()) + - "&taskIds=" + URLEncoder.encode(taskId, StandardCharsets.UTF_8.name()); - - StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8); - entity.setContentType("application/x-www-form-urlencoded"); - httpDelete.setEntity(entity); +// StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8); +// entity.setContentType("application/x-www-form-urlencoded"); +// httpDelete.setEntity(entity); try (CloseableHttpResponse response = httpClient.execute(httpDelete)) { int statusCode = response.getStatusLine().getStatusCode(); @@ -385,9 +385,9 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService { try { // 1. 根据taskId查询最新一条CaseDocumentLog数据 List logList = caseDocumentLogDao.getGenericDao() - .findList(CaseDocumentLog.class, - FieldFilters.eq("taskId", taskId), - OrderCondition.desc("sysCreateTime")); + .findList(CaseDocumentLog.class, 1, + OrderCondition.desc("sysCreateTime"), + FieldFilters.eq("taskId", taskId)); if (logList.isEmpty()) { log.error("处理上传回调失败,未找到对应的日志记录,taskId: {}", taskId); @@ -483,9 +483,9 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService { private boolean callDeleteInterface(String caseId, Cases caseEntity, String accessToken) { // 1. 根据案例ID查询最新一条CaseDocumentLog数据 List logList = caseDocumentLogDao.getGenericDao() - .findList(CaseDocumentLog.class, - FieldFilters.eq("caseId", caseId), - OrderCondition.desc("sysCreateTime")); + .findList(CaseDocumentLog.class, 1, + OrderCondition.desc("sysCreateTime"), + FieldFilters.eq("caseId", caseId)); if (logList.isEmpty()) { log.warn("调用删除接口时未找到相关的日志记录,caseId: {}", caseId); @@ -507,18 +507,18 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService { log.info("调用删除接口第{}次尝试,caseId: {}, taskId: {}", attempt, caseId, taskId); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpDelete httpDelete = new HttpDelete(deleteUrl); + // 构建请求参数 + String params = "kId=" + URLEncoder.encode(caseAiProperties.getCaseKnowledgeId(), StandardCharsets.UTF_8.name()) + + "&taskIds=" + URLEncoder.encode(taskId, StandardCharsets.UTF_8.name()); + HttpDelete httpDelete = new HttpDelete(deleteUrl + "?" + params); httpDelete.setHeader("X-AI-ApiCode", caseAiProperties.getAiApiCode()); httpDelete.setHeader("access_token", accessToken); httpDelete.setHeader("Content-Type", "application/x-www-form-urlencoded"); + - // 构建请求参数 - String params = "kId=" + URLEncoder.encode(caseAiProperties.getCaseKnowledgeId(), StandardCharsets.UTF_8.name()) + - "&taskIds=" + URLEncoder.encode(taskId, StandardCharsets.UTF_8.name()); - - StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8); - entity.setContentType("application/x-www-form-urlencoded"); - httpDelete.setEntity(entity); +// StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8); +// entity.setContentType("application/x-www-form-urlencoded"); +// httpDelete.setEntity(entity); try (CloseableHttpResponse response = httpClient.execute(httpDelete)) { int statusCode = response.getStatusLine().getStatusCode();