mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 02:46:50 +08:00
修正编译错误;
增加临时接口
This commit is contained in:
@@ -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<Boolean> 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<String> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -200,9 +200,9 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
|
||||
// 2. 根据案例ID查询最新一条CaseDocumentLog数据
|
||||
List<CaseDocumentLog> 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<CaseDocumentLog> 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<CaseDocumentLog> 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();
|
||||
|
||||
Reference in New Issue
Block a user