Files
ln-bi/src/server/routes/asset-assistant/presentation.ts
T
2026-09-23 17:52:33 +08:00

56 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { CATEGORY_LABELS, GROUP_LABELS, type AssistantResult, type QueryPlan } from "../../../shared/assets/assistant.js";
export function resultScope(plan: QueryPlan, subject: string | null): NonNullable<AssistantResult["scope"]> {
const filters = [
plan.kind === "flow" ? "交退换车业务" : CATEGORY_LABELS[plan.category],
...Object.entries(plan.filters).map(([key, values]) => `${GROUP_LABELS[key as keyof typeof GROUP_LABELS]}:${values.join("、")}`),
...Object.entries(plan.excludeFilters || {}).map(([key, values]) => `排除${GROUP_LABELS[key as keyof typeof GROUP_LABELS]}:${values.join("、")}`),
...(plan.vehicleIds ? [`指定 ${plan.vehicleIds.length} 台车辆`] : []),
...(plan.exception ? [{ overdue: "异动已超预计完成时间", dueSoon: "异动未来7天到期", missingDueDate: "异动未填写预计完成时间" }[plan.exception]] : []),
];
const definitions = plan.kind === "flow" ? [
"按运维签章日期统计业务车次,替换交车已计入交车,不能重复相加。",
"按当前账号可见车辆及当前筛选条件查询流转记录;车次差额不代表净增车辆,增减本身不能证明经营改善。",
] : [
"库存含可运营、待运营、异动及待交车;异动、待交车是库存子集,不与总库存相加。",
"待运营是运营状态,待交车是交车流程状态,两者不可替代。",
"运营率 = 当前筛选范围内运营车辆数 ÷ 当前筛选范围内车辆总数。",
"车型按吨位归类;4.5T包含普货和冷链,车型细分可拆开查看,与首页分开展示的口径不同。",
];
if (plan.topN) definitions.push(`仅展示前 ${plan.topN} 个分组,指标总量和占比仍按完整筛选范围计算。`);
return {
company: subject || "全部公司(当前账号可见)",
permission: "仅统计当前账号有权限查看的车辆",
filters,
grouping: plan.kind === "flow" ? "按日" : plan.groupBy === "none" ? "不分组" : `按${GROUP_LABELS[plan.groupBy]}${plan.secondaryGroupBy ? ` × ${GROUP_LABELS[plan.secondaryGroupBy]}` : ""}`,
period: plan.kind === "flow" ? `${plan.start} 至 ${plan.end}(含首尾日期)` : "当前车辆状态(非历史快照)",
definitions,
sourceUpdatedAt: null,
};
}
export function followupSuggestions(result: AssistantResult): string[] {
const p = result.plan;
if (p.kind === "clarify") return [...new Set(result.suggestions || [])].slice(0, 3);
const suggestions: string[] = [];
if (p.kind === "flow") {
if (!p.comparePrevious) suggestions.push("与上一等长周期对比");
if (p.view !== "list") suggestions.push("查看交退换车明细");
if (p.view !== "table") suggestions.push("按天用表格展示");
return suggestions.slice(0, 3);
}
if (!result.rows.length) {
if (Object.keys(p.filters).length || Object.keys(p.excludeFilters || {}).length || p.exception || p.vehicleIds) suggestions.push("取消所有筛选");
if (p.category !== "all") suggestions.push("查看全部资产");
return suggestions;
}
if (p.analysis === "briefing") suggestions.push("按车型细分查看当前库存");
else {
const next = ["vehicleClass", "region", "city", "model", "department"].find(d => d !== p.groupBy && d !== p.secondaryGroupBy && !p.filters[d as keyof typeof p.filters] && (d !== "vehicleClass" || p.groupBy === "type" || p.filters.type?.includes("4.5T")));
if (next) suggestions.push(`保持当前筛选,按${GROUP_LABELS[next as keyof typeof GROUP_LABELS]}拆分`);
}
if (p.view !== "list") suggestions.push("查看当前范围车辆明细");
if (p.category === "inventory" && !p.exception) suggestions.push("当前库存中待交车有多少");
return suggestions.slice(0, 3);
}