将审计方案的AI分析和审计报告分开
This commit is contained in:
@@ -55,7 +55,6 @@ import com.gxwebsoft.ai.enums.AuditReportEnum;
|
||||
import com.gxwebsoft.ai.service.AuditReportService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.util.AuditReportUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
@@ -94,6 +93,8 @@ public class AuditReportController extends BaseController {
|
||||
|
||||
private final static String AUDIT_REPORT_TOKEN = "Bearer app-PlYMOvcUQrW7tromrqCNcX9M";
|
||||
|
||||
private final static String AUDIT_SCHEMA_TOKEN = "Bearer app-d7Ok9FECVZG2Ybw9wpg7tGu9";
|
||||
|
||||
// private final AiCloudFileService aiCloudFileService;
|
||||
//
|
||||
// private final AiCloudDocService aiCloudDocService;
|
||||
@@ -133,10 +134,9 @@ public class AuditReportController extends BaseController {
|
||||
/**
|
||||
* 生成审计报告-单一模块
|
||||
*/
|
||||
@Deprecated
|
||||
@Operation(summary = "生成审计报告-单一模块")
|
||||
@Operation(summary = "生成审计方案")
|
||||
@PostMapping("/generate")
|
||||
public ApiResult<?> generateAuditReport(@RequestBody AuditReportRequest req) {
|
||||
public ApiResult<?> generateAuditSchema(@RequestBody AuditReportRequest req) {
|
||||
final User loginUser = getLoginUser();
|
||||
|
||||
Set<String> kbIdSet = new HashSet<>();
|
||||
@@ -155,7 +155,7 @@ public class AuditReportController extends BaseController {
|
||||
// String ret = this.invok(query, knowledge, AuditReportUtil.generateReportContent(req), req.getSuggestion(), loginUser.getUsername());
|
||||
// String ret = this.invok(query, knowledge, AuditReportUtil.generateReportContentByFormCommit(req), req.getSuggestion(), req.getFrom00(), loginUser.getUsername());
|
||||
|
||||
return success(invokeAIAnalysis(query, knowledge, loginUser.getUsername()));
|
||||
return success(invokeSchemaAIAnalysis(query, knowledge, loginUser.getUsername()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1622,7 +1622,7 @@ public class AuditReportController extends BaseController {
|
||||
log.info("生成审计报告标题:{},AI 提示词:{}", request.getChapterTitle(), prompt);
|
||||
|
||||
// TODO 调用 AI 接口
|
||||
String result = invokeAIAnalysis(prompt, kbId, loginUser.getUsername());
|
||||
String result = invokeReportAIAnalysis(prompt, kbId, loginUser.getUsername());
|
||||
|
||||
// 保存历史记录到数据库
|
||||
try {
|
||||
@@ -1691,12 +1691,12 @@ public class AuditReportController extends BaseController {
|
||||
|
||||
PwlProject project = pwlProjectService.getById(projectId);
|
||||
// TODO 调用 AI 接口
|
||||
String result = invokeAIAnalysis(promptBuilder.toString(), project.getKbId(), loginUser.getUsername());
|
||||
String result = invokeSchemaAIAnalysis(promptBuilder.toString(), project.getKbId(), loginUser.getUsername());
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("AI 分析用户自定义输入异常", e);
|
||||
return fail("AI 分析用户自定义输入异常:" + e.getMessage(), null);
|
||||
return fail("AI 分析用户自定义输入异常:" + e.getMessage(), AUDIT_SCHEMA_TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1777,7 +1777,7 @@ public class AuditReportController extends BaseController {
|
||||
/**
|
||||
* 调用 AI 分析用户输入
|
||||
*/
|
||||
private String invokeAIAnalysis(String prompt, String kbId, String userName) {
|
||||
private String invokeReportAIAnalysis(String prompt, String kbId, String userName) {
|
||||
// 构建请求体
|
||||
JSONObject requestBody = new JSONObject();
|
||||
JSONObject inputs = new JSONObject();
|
||||
@@ -1855,6 +1855,69 @@ public class AuditReportController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
private String invokeSchemaAIAnalysis(String prompt, String kbId, String userName) {
|
||||
// 构建请求体
|
||||
JSONObject requestBody = new JSONObject();
|
||||
JSONObject inputs = new JSONObject();
|
||||
if(StrUtil.isNotBlank(kbId)){
|
||||
prompt += "\n\n只能在以下知识库中读取数据,标签编号:" + kbId;
|
||||
}
|
||||
inputs.put("query", prompt);
|
||||
inputs.put("title", "审计方案 AI 分析");
|
||||
|
||||
requestBody.put("inputs", inputs);
|
||||
requestBody.put("response_mode", "blocking");
|
||||
requestBody.put("user", userName);
|
||||
|
||||
try {
|
||||
// 发送 POST 请求
|
||||
String result = HttpUtil.createPost("http://1.14.159.185:8180/v1/workflows/run")
|
||||
.header("Authorization", AUDIT_SCHEMA_TOKEN)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(requestBody.toString())
|
||||
.timeout(600000)
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
log.info("AI 工作流返回结果:{}", result);
|
||||
|
||||
// 解析返回的 JSON 字符串
|
||||
JSONObject jsonResponse = JSONObject.parseObject(result);
|
||||
|
||||
// 检查是否有错误
|
||||
if (jsonResponse.containsKey("error")) {
|
||||
JSONObject error = jsonResponse.getJSONObject("error");
|
||||
String errorMsg = error != null ? error.getString("message") : "未知错误";
|
||||
throw new RuntimeException("AI 服务返回错误:" + errorMsg);
|
||||
|
||||
}
|
||||
|
||||
JSONObject data = jsonResponse.getJSONObject("data");
|
||||
if (data == null) {
|
||||
log.error("AI 响应中缺少 data 字段,完整响应:{}", result);
|
||||
throw new RuntimeException("AI 服务响应格式异常,缺少 data 字段");
|
||||
}
|
||||
|
||||
JSONObject outputs = data.getJSONObject("outputs");
|
||||
if (outputs == null) {
|
||||
log.error("AI 响应中缺少 outputs 字段,完整响应:{}", result);
|
||||
throw new RuntimeException("AI 服务响应格式异常,缺少 outputs 字段");
|
||||
}
|
||||
|
||||
/*JSONObject resultJSON = outputs.getJSONObject("result");
|
||||
|
||||
if (resultJSON == null) {
|
||||
log.warn("AI 返回的结果为空,完整响应:{}", result);
|
||||
return "";
|
||||
}*/
|
||||
|
||||
return outputs.getString("result");
|
||||
} catch (Exception e) {
|
||||
log.error("调用 AI 工作流失败", e);
|
||||
throw new RuntimeException("调用 AI 工作流失败:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据取证单生成审计建议
|
||||
*/
|
||||
@@ -1915,12 +1978,12 @@ public class AuditReportController extends BaseController {
|
||||
);
|
||||
|
||||
// TODO 调用 AI 接口
|
||||
String result = invokeAIAnalysis(prompt, project.getKbId(), loginUser.getUsername());
|
||||
String result = invokeSchemaAIAnalysis(prompt, project.getKbId(), loginUser.getUsername());
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("根据取证单生成审计建议异常", e);
|
||||
return fail("根据取证单生成审计建议异常:" + e.getMessage(), null);
|
||||
return fail("根据取证单生成审计建议异常:" + e.getMessage(), AUDIT_SCHEMA_TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user