接口调整
This commit is contained in:
1 parent
c5328e6a35
commit
40d06b781a
2 files changed
+17
-10
No files matched your search
@@ -8,7 +8,7 @@ VITE_USE_REAL_DATA=true
|
||||
VITE_MOCK_COP_TASK_DETAIL=true
|
||||
|
||||
# 研判情报报告(大屏绘制智能体深链 selectSqReport)数据源:true 走本地样例假数据(真实接口未就绪时调试用);联调通过后置 false。
|
||||
VITE_MOCK_SQ_REPORT=true
|
||||
VITE_MOCK_SQ_REPORT=false
|
||||
|
||||
# 深链任务详情(cop-task-detail:任务名称/描述)数据源:true 走本地假数据(真实接口未就绪时调试用);联调通过后置 false。
|
||||
VITE_MOCK_COP_TASK_DETAIL=true
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 大屏绘制智能体的任务输入适配层。
|
||||
*
|
||||
* 报告详情由 Gateway 的 `/api/task-reports/by-task/{taskId}` 提供,返回格式
|
||||
* 与原 `selectSqReport` 一致:`{state, msg, data}`。每条 `contentJson` 是
|
||||
* 报告详情由 Consumer 的 `/cop/selectSqReport?taskId=` 提供,返回格式为
|
||||
* `{state, msg, data}`。每条 `contentJson` 是
|
||||
* JSON 字符串,本模块将其按 `categoryType` 解析为智能体和大屏页面可直接使用的
|
||||
* 结构化输入。
|
||||
*/
|
||||
|
||||
import { getTaskReport } from "@/strategy-components/api/task-reports";
|
||||
import { readRuntimeFlag } from "@/env";
|
||||
import { readRuntimeEnv, readRuntimeFlag } from "@/env";
|
||||
import { requestCrudService } from "@/service/request-axios-service";
|
||||
import { SQ_REPORT_MOCK_RESPONSE } from "@/strategy-components/components/task-components/sq-report-mock-data";
|
||||
|
||||
/** 保留给既有调用方的 sessionStorage key;报告本身不再使用 mock 缓存。 */
|
||||
@@ -32,9 +32,15 @@ function categoryKey(categoryType: unknown, index: number): string {
|
||||
return cleaned || `分类${index + 1}`;
|
||||
}
|
||||
|
||||
/** Consumer 研判情报报告接口完整地址。 */
|
||||
function sqReportUrl(): string {
|
||||
const base = readRuntimeEnv("VITE_AIPI_CONSUMER_URL")?.replace(/\/+$/, "") ?? "";
|
||||
return base ? `${base}/cop/selectSqReport` : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 将接口 envelope 提取为 `{ taskId, source, categories }`。
|
||||
* 返回 null 表示该任务尚未保存可用的报告内容。
|
||||
* 返回 null 表示接口没有返回可用的报告内容。
|
||||
*/
|
||||
export function extractSqReport(body: unknown, taskId: string): unknown | null {
|
||||
const data = (body && typeof body === "object" ? (body as { data?: unknown }).data : null) as
|
||||
@@ -51,7 +57,7 @@ export function extractSqReport(body: unknown, taskId: string): unknown | null {
|
||||
categories[key] = content;
|
||||
});
|
||||
if (Object.keys(categories).length === 0) return null;
|
||||
return { taskId, source: "api/task-reports", categories };
|
||||
return { taskId, source: "cop/selectSqReport", categories };
|
||||
}
|
||||
|
||||
/** 兼容旧调用方:报告由接口实时读取,不再在浏览器中缓存。 */
|
||||
@@ -70,8 +76,7 @@ export async function fetchDashboardInputJson(
|
||||
_opts?: { forceRefresh?: boolean },
|
||||
): Promise<unknown | null> {
|
||||
if (!taskId) return null;
|
||||
// 开发演示模式使用与 Gateway 接口同形的本地样例;这样不依赖报告库是否已为
|
||||
// 当前深链 taskId 写入数据,同时真实/生产环境仍始终从 Gateway 读取。
|
||||
// 开发演示模式不发外部请求,直接返回与 Consumer 接口同形的本地样例。
|
||||
if (readRuntimeFlag("VITE_MOCK_SQ_REPORT")) {
|
||||
return extractSqReport(
|
||||
{
|
||||
@@ -81,7 +86,9 @@ export async function fetchDashboardInputJson(
|
||||
taskId,
|
||||
);
|
||||
}
|
||||
const body = await getTaskReport(taskId);
|
||||
const url = sqReportUrl();
|
||||
if (!url) return null;
|
||||
const body = await requestCrudService.get(url, { taskId });
|
||||
return extractSqReport(body, taskId);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user