feat(bill): trace linked loan and requisition records

This commit is contained in:
gitea committed 2026-09-05 20:04:08 +08:00
1 parent 3df9201a5e
commit 7a8f2f6931
8 files changed
+163 -3

No files matched your search

+35 -1
View File
@@ -8,6 +8,7 @@ import {
getBillFlow,
getBillRisk,
getBillReferences,
getBillRelations,
getFieldDictionary,
} from "../../domains/bill/tools.js";
@@ -297,6 +298,39 @@ export async function handleBillCommand(
return { stdout: output, stderr: "", exitCode: 0 };
}
case "relations":
case "relation":
case "links": {
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
if (!target) throw new Error("请提供要查询关联关系的单号或单据 ID: hose bill relations <单号|ID>");
const report = await getBillRelations(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 rows: string[][] = [];
const visit = (node: typeof report.relations[number], depth = 0) => {
rows.push([
`${" ".repeat(depth)}${node.relation}`,
node.code || node.id || "-",
node.title || "-",
node.amount || "-",
]);
for (const child of node.children) visit(child, depth + 1);
};
for (const node of report.relations) visit(node);
const output = [
`====== 单据关联关系 (单号: ${report.billCode || target}) ======`,
`标题: ${report.title || "-"}`,
rows.length ? printTable(["关系", "关联 ID/单号", "标题/名称", "金额"], rows) : "暂无可识别的前置单据、冲借款或合同关联",
"",
].join("\n");
return { stdout: output, stderr: "", exitCode: 0 };
}
case "link":
case "url": {
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id", "c"]);
@@ -359,6 +393,6 @@ export async function handleBillCommand(
}
default:
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, refs <单号>, flow <单号>, risk <单号>, schema, link <单号>`);
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, refs <单号>, relations <单号>, flow <单号>, risk <单号>, schema, link <单号>`);
}
}