feat: add CLI bill approval flow timeline

This commit is contained in:
gitea committed 2026-09-05 19:40:45 +08:00
1 parent 155f179fcd
commit a8bdb67293
7 files changed
+234 -5

No files matched your search

+42 -1
View File
@@ -5,6 +5,7 @@ import { createEkbClient } from "../../core/auth/ekb.js";
import {
searchAndFormatBills,
getBillByCodeOrId,
getBillFlow,
getFieldDictionary,
} from "../../domains/bill/tools.js";
@@ -195,6 +196,46 @@ export async function handleBillCommand(
};
}
case "flow":
case "records":
case "timeline": {
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
if (!target) throw new Error("请提供要查询流程的单号或单据 ID: hose bill flow <单号|ID>");
const flow = await getBillFlow(client, corpId, target);
if (!flow) {
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, ...flow }, runtime.outputOptions), stderr: "", exitCode: 0 };
}
const historyRows = flow.history.map((entry) => [
entry.time ? new Date(entry.time).toLocaleString("zh-CN") : "-",
entry.nodeName || "-",
entry.action || "-",
entry.operator?.name || (entry.automatic ? "系统" : "-"),
entry.comment || "-",
]);
const pendingRows = flow.pending.map((node) => [
node.state || "-",
node.name || "-",
node.type || "-",
node.approver?.name || node.approvers?.map((person) => person.name).filter(Boolean).join(", ") || "-",
]);
const output = [
`====== 审批流程 (单号: ${flow.billCode || target} | 状态: ${flow.state || "-"}) ======`,
`流程 ID: ${flow.flowId || "-"} 当前节点: ${flow.currentNode || "-"}`,
"",
"--- 历史流转 ---",
flow.history.length ? printTable(["时间", "节点", "动作", "处理人", "意见"], historyRows) : " (暂无历史记录)",
"",
"--- 后续节点 ---",
flow.pending.length ? printTable(["状态", "节点", "类型", "审批人"], pendingRows) : " (暂无后续节点)",
"",
].join("\n");
return { stdout: output, stderr: "", exitCode: 0 };
}
case "link":
case "url": {
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id", "c"]);
@@ -257,6 +298,6 @@ export async function handleBillCommand(
}
default:
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, schema, link <单号>`);
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, flow <单号>, schema, link <单号>`);
}
}