feat: add CLI bill risk review

This commit is contained in:
gitea committed 2026-09-05 19:45:21 +08:00
1 parent 85d5f8f13a
commit 6468710730
7 files changed
+140 -3

No files matched your search

+33 -1
View File
@@ -6,6 +6,7 @@ import {
searchAndFormatBills,
getBillByCodeOrId,
getBillFlow,
getBillRisk,
getFieldDictionary,
} from "../../domains/bill/tools.js";
@@ -236,6 +237,37 @@ export async function handleBillCommand(
return { stdout: output, stderr: "", exitCode: 0 };
}
case "risk":
case "review":
case "warnings": {
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
if (!target) throw new Error("请提供要查询风控结果的单号或单据 ID: hose bill risk <单号|ID>");
const report = await getBillRisk(client, corpId, target);
if (!report) {
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
return { stdout: "", stderr: `[NOT FOUND] 未找到单据风控结果: ${target}\n`, exitCode: 1 };
}
if (runtime.jsonMode) {
return { stdout: printJson({ corpId, corpName: corp.name, ...report }, runtime.outputOptions), stderr: "", exitCode: 0 };
}
const warningRows = report.warnings.map((warning) => [
warning.riskLevel || "-",
warning.type || "-",
warning.controlName || warning.title || "-",
warning.messages.join(";") || "-",
]);
const output = [
`====== 单据风控审查 (流程: ${report.flowId}) ======`,
`预算超限: ${report.budgetExceeded ? "是" : "否"}`,
"",
"--- 风险预警 ---",
report.warnings.length ? printTable(["等级", "类型", "规则", "提示"], warningRows) : " (暂无风险预警)",
`发票风险: ${report.invoiceWarnings.length} 条`,
"",
].join("\n");
return { stdout: output, stderr: "", exitCode: 0 };
}
case "link":
case "url": {
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id", "c"]);
@@ -298,6 +330,6 @@ export async function handleBillCommand(
}
default:
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, flow <单号>, schema, link <单号>`);
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, flow <单号>, risk <单号>, schema, link <单号>`);
}
}