299 lines
7.4 KiB
TypeScript
299 lines
7.4 KiB
TypeScript
import request from '@/utils/request';
|
||
import type { ApiResult } from '@/api';
|
||
import type { AuditReport } from './model';
|
||
import { MODULES_API_URL } from '@/config/setting';
|
||
|
||
/**
|
||
* 生成审计报告-单一模块
|
||
*/
|
||
export async function generateAuditReport(data: AuditReport) {
|
||
const res = await request.post<ApiResult<unknown>>(
|
||
MODULES_API_URL + '/ai/auditReport/generate',
|
||
data
|
||
);
|
||
if (res.data.code === 0) {
|
||
return res.data.message;
|
||
}
|
||
return Promise.reject(new Error(res.data.message));
|
||
}
|
||
|
||
/**
|
||
* 生成并下载审计报告
|
||
*/
|
||
export async function downloadAuditReport(req: AuditReport) {
|
||
const res = await request.post(
|
||
MODULES_API_URL + '/ai/auditReport/download',
|
||
req,
|
||
{
|
||
responseType: 'blob' // 处理二进制流响应
|
||
}
|
||
);
|
||
|
||
if (res.status === 200) {
|
||
return res.data;
|
||
}
|
||
return Promise.reject(new Error('文件下载失败'));
|
||
}
|
||
|
||
/**
|
||
* 生成审计核查报告 - 重构版
|
||
*/
|
||
export async function generateAuditReport2(
|
||
file: File,
|
||
kbId?: string,
|
||
libraryIds?: string,
|
||
analysisLibrary?: string,
|
||
projectLibrary?: string
|
||
) {
|
||
const formData = new FormData();
|
||
formData.append('file', file);
|
||
|
||
if (kbId) formData.append('kbId', kbId);
|
||
if (libraryIds) formData.append('libraryIds', libraryIds);
|
||
if (analysisLibrary) formData.append('analysisLibrary', analysisLibrary);
|
||
if (projectLibrary) formData.append('projectLibrary', projectLibrary);
|
||
|
||
const res = await request.post<ApiResult<unknown>>(
|
||
MODULES_API_URL + '/ai/auditReport2/generate',
|
||
formData,
|
||
{
|
||
headers: {
|
||
'Content-Type': 'multipart/form-data'
|
||
}
|
||
}
|
||
);
|
||
|
||
if (res.data.code === 0) {
|
||
return res.data.data;
|
||
}
|
||
return Promise.reject(new Error(res.data.message));
|
||
}
|
||
|
||
/**
|
||
* 保存审计报告到数据库
|
||
*/
|
||
export async function saveAuditReport(data: {
|
||
projectId?: number;
|
||
projectName?: string;
|
||
caseIndex?: string;
|
||
auditedTarget?: string;
|
||
reportContent?: string;
|
||
previewHtml?: string;
|
||
sectionCount?: number;
|
||
formCommit?: number;
|
||
}) {
|
||
const res = await request.post<ApiResult<any>>(
|
||
MODULES_API_URL + '/ai/auditReport/save',
|
||
data
|
||
);
|
||
|
||
if (res.data.code === 0) {
|
||
return res.data;
|
||
}
|
||
return Promise.reject(new Error(res.data.message));
|
||
}
|
||
|
||
/**
|
||
* 查询审计报告
|
||
*/
|
||
export async function queryAuditReport(params: {
|
||
projectId: number;
|
||
formCommit: number;
|
||
}) {
|
||
const res = await request.post<ApiResult<any>>(
|
||
MODULES_API_URL + '/ai/auditReport/query',
|
||
null,
|
||
{
|
||
params
|
||
}
|
||
);
|
||
|
||
if (res.data.code === 0) {
|
||
return res.data;
|
||
}
|
||
return Promise.reject(new Error(res.data.message));
|
||
}
|
||
|
||
/**
|
||
* 根据项目 ID 查询审计报告和取证单数据
|
||
* @param projectId 项目 ID
|
||
* @param evidenceIds 勾选的取证单 ID 列表(可选)
|
||
*/
|
||
export async function queryAuditDataByProjectId(projectId: number, evidenceIds?: number[]) {
|
||
console.log('=== 前端发起请求 ===');
|
||
console.log('projectId:', projectId);
|
||
console.log('evidenceIds:', evidenceIds);
|
||
|
||
const res = await request.post<ApiResult<any>>(
|
||
MODULES_API_URL + '/ai/auditReport/queryAuditDataByProjectId',
|
||
evidenceIds ? { evidenceIds } : {},
|
||
{
|
||
params: { projectId },
|
||
headers: {
|
||
'Content-Type': 'application/json;charset=UTF-8'
|
||
}
|
||
}
|
||
);
|
||
|
||
console.log('=== 后端返回响应 ===', res);
|
||
console.log('res.data.code:', res.data.code);
|
||
console.log('res.data.message:', res.data.message);
|
||
console.log('res.data.data:', res.data.data);
|
||
|
||
if (res.data.code === 0) {
|
||
return res.data;
|
||
}
|
||
console.error('API 返回错误 - code:', res.data.code, ', message:', res.data.message);
|
||
return Promise.reject(new Error(res.data.message || '操作失败'));
|
||
}
|
||
|
||
/**
|
||
* 根据项目 ID 生成审计报告并下载
|
||
*/
|
||
export async function generateAuditReportByProjectId(projectId: number) {
|
||
const res = await request.post(
|
||
MODULES_API_URL + '/ai/auditReport/generateByProjectId',
|
||
null,
|
||
{
|
||
params: { projectId },
|
||
responseType: 'blob' // 处理二进制流响应
|
||
}
|
||
);
|
||
|
||
if (res.status === 200) {
|
||
return res.data;
|
||
}
|
||
return Promise.reject(new Error('文件下载失败'));
|
||
}
|
||
|
||
/**
|
||
* 根据项目 ID 和选中的取证单生成审计报告并下载
|
||
*/
|
||
export async function generateAuditReportWithEvidences(projectId: number, evidenceIds: number[]) {
|
||
const res = await request.post(
|
||
MODULES_API_URL + '/ai/auditReport/generateWithEvidences',
|
||
{ evidenceIds },
|
||
{
|
||
params: { projectId },
|
||
responseType: 'blob' // 处理二进制流响应
|
||
}
|
||
);
|
||
|
||
if (res.status === 200) {
|
||
return res.data;
|
||
}
|
||
return Promise.reject(new Error('文件下载失败'));
|
||
}
|
||
|
||
/**
|
||
* 根据项目 ID、选中的取证单和章节内容生成审计报告并下载
|
||
* @param projectId 项目 ID
|
||
* @param evidenceIds 勾选的取证单 ID 列表
|
||
* @param chapters 章节内容数组(包含 formCommit 和 reportContent)
|
||
* @param evaluate 总体评价
|
||
* @param suggestion 审计建议
|
||
*/
|
||
export async function generateAuditReportWithContent(
|
||
projectId: number,
|
||
evidenceIds: number[],
|
||
chapters: Array<{
|
||
formCommit: number;
|
||
reportContent: string;
|
||
}>,
|
||
evaluate?: string,
|
||
suggestion?: string
|
||
) {
|
||
const res = await request.post(
|
||
MODULES_API_URL + '/ai/auditReport/generateWithContent',
|
||
{
|
||
evidenceIds,
|
||
chapters,
|
||
evaluate,
|
||
suggestion
|
||
},
|
||
{
|
||
params: { projectId },
|
||
responseType: 'blob' // 处理二进制流响应
|
||
}
|
||
);
|
||
|
||
if (res.status === 200) {
|
||
return res.data;
|
||
}
|
||
return Promise.reject(new Error('文件下载失败'));
|
||
}
|
||
|
||
/**
|
||
* AI 生成默认话术
|
||
*/
|
||
export async function generateDefaultText(params: {
|
||
projectId?: number;
|
||
formCommit: number;
|
||
chapterTitle?: string;
|
||
evidenceIds?: number[]; // 新增:选中的取证单 ID 列表
|
||
}) {
|
||
const res = await request.post<ApiResult<string>>(
|
||
MODULES_API_URL + '/ai/auditReport/generateDefaultText',
|
||
{
|
||
projectId: params.projectId,
|
||
formCommit: params.formCommit,
|
||
chapterTitle: params.chapterTitle,
|
||
evidenceIds: params.evidenceIds
|
||
}
|
||
);
|
||
|
||
if (res.data.code === 0) {
|
||
// 后端返回的数据在 message 字段中
|
||
return res.data.message || res.data.data;
|
||
}
|
||
return Promise.reject(new Error(res.data.message));
|
||
}
|
||
|
||
/**
|
||
* AI 分析用户自定义输入
|
||
*/
|
||
export async function analyzeUserInput(params: {
|
||
formCommit: number;
|
||
userQuestion: string;
|
||
chapterContent?: string;
|
||
}) {
|
||
const res = await request.post<ApiResult<string>>(
|
||
MODULES_API_URL + '/ai/auditReport/analyzeUserInput',
|
||
null,
|
||
{
|
||
params
|
||
}
|
||
);
|
||
|
||
if (res.data.code === 0) {
|
||
return res.data.data;
|
||
}
|
||
return Promise.reject(new Error(res.data.message));
|
||
}
|
||
|
||
/**
|
||
* 根据取证单生成审计建议
|
||
*/
|
||
export async function generateAuditSuggestion(params: {
|
||
projectId: number;
|
||
evidenceIds: number[];
|
||
}) {
|
||
const res = await request.post<ApiResult<string>>(
|
||
MODULES_API_URL + '/ai/auditReport/generateAuditSuggestion',
|
||
{ evidenceIds: params.evidenceIds },
|
||
{
|
||
params: {
|
||
projectId: params.projectId
|
||
},
|
||
headers: {
|
||
'Content-Type': 'application/json;charset=UTF-8'
|
||
}
|
||
}
|
||
);
|
||
|
||
if (res.data.code === 0) {
|
||
// 后端返回的数据在 message 字段中
|
||
return res.data.message || res.data.data;
|
||
}
|
||
return Promise.reject(new Error(res.data.message));
|
||
} |