feat(bill,flow): add unified bill trace and flow get diagnostic engine (Phase 2)
This commit is contained in:
1 parent
7891959853
commit
ffec604ed9
10 files changed
+970
-32
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createBillActionContext } from "./context.js";
|
||||
import { handleApprove, handleReject, handleTransfer, handleAddNode, handleComment } from "./approve.js";
|
||||
import { handleList, handleGet } from "./search.js";
|
||||
import { handleList, handleGet, handleTrace } from "./search.js";
|
||||
import { handleFlow, handleRisk, handleBudget } from "./flow.js";
|
||||
import { handleRefs, handleRelations, handleAttachments, handleDownload } from "./related.js";
|
||||
import { handleSchema, handleLink, handleSpec } from "./meta.js";
|
||||
@@ -53,6 +53,11 @@ export async function handleBillCommand(
|
||||
case "find":
|
||||
return handleGet(ctx);
|
||||
|
||||
case "trace":
|
||||
case "inspect":
|
||||
case "diagnose":
|
||||
return handleTrace(ctx);
|
||||
|
||||
case "schema":
|
||||
case "schemas":
|
||||
case "entities":
|
||||
@@ -100,6 +105,6 @@ export async function handleBillCommand(
|
||||
return handleSpec(ctx);
|
||||
|
||||
default:
|
||||
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号> [--risk], spec <specificationId>, refs <单号>, relations <单号>, attachments <单号>, download <单号>, flow <单号>, risk <单号>, budget <单号>, schema, link <单号>`);
|
||||
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号> [--risk], trace <单号|ID>, spec <specificationId>, refs <单号>, relations <单号>, attachments <单号>, download <单号>, flow <单号>, risk <单号>, budget <单号>, schema, link <单号>`);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getBillByCodeOrId, getBillRisk, searchAndFormatBills } from "../../../domains/bill/tools.js";
|
||||
import { getBillByCodeOrId, getBillRisk, searchAndFormatBills, traceBillFlowDetail } from "../../../domains/bill/tools.js";
|
||||
import { booleanOption, numberOption, stringOption } from "../../parser.js";
|
||||
import { printJson, printTable } from "../../printer.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import type { CliResult } from "../../types.js";
|
||||
import type { BillActionContext } from "./context.js";
|
||||
|
||||
@@ -198,3 +198,102 @@ export async function handleGet(ctx: BillActionContext): Promise<CliResult> {
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
export async function handleTrace(ctx: BillActionContext): Promise<CliResult> {
|
||||
const { parsed, runtime, corp, corpId } = ctx;
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id", "target", "flowId"]);
|
||||
if (!target) {
|
||||
throw new Error("请提供要穿透诊断的单号或单据/流程 ID: hose-use bill trace <单号|ID> 或 hose-use flow get <单号|ID>");
|
||||
}
|
||||
|
||||
const client = await ctx.getClient();
|
||||
const report = await traceBillFlowDetail(client, corpId, target);
|
||||
|
||||
if (!report.found) {
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(report, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `[NOT FOUND] 在企业 [${corp.name}] 下未找到匹配 [${target}] 的单据或审批流实例\n 诊断提示: ${report.diagnostic.advice}\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(
|
||||
{
|
||||
corpId,
|
||||
corpName: corp.name,
|
||||
...report,
|
||||
},
|
||||
runtime.outputOptions
|
||||
),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const approverNames = report.pendingApprovers
|
||||
.map((p) => (p.name ? `${p.name}${p.code ? ` (${p.code})` : ""}` : p.id))
|
||||
.filter(Boolean)
|
||||
.join("、");
|
||||
|
||||
const lines: string[] = [
|
||||
`====== 单据全域穿透诊断 [${report.billCode || report.target}] ======`,
|
||||
printKeyValue({
|
||||
"单据编号": report.billCode || "-",
|
||||
"单据 ID": report.billId || "-",
|
||||
"流程实例 (flowId)": report.flowId || "-",
|
||||
"单据类型": report.specificationName
|
||||
? `${report.specificationName}${report.specificationId ? ` (${report.specificationId})` : ""}`
|
||||
: "-",
|
||||
"单据标题": report.title || "-",
|
||||
"提报人员": report.submitter
|
||||
? `${report.submitter.name || "-"}${report.submitter.id ? ` (${report.submitter.id})` : ""}`
|
||||
: "-",
|
||||
"归属部门": report.department || "-",
|
||||
"提报时间": report.submitDate || "-",
|
||||
"单据金额": report.amount || "-",
|
||||
"全局流转状态": `${report.state || "-"} (${report.rawState || "-"})`,
|
||||
}),
|
||||
"",
|
||||
"── 🩺 待办与审批诊断 ──",
|
||||
` 阶段判定 : ${report.diagnostic.stageLabel}`,
|
||||
` 当前驻留节点: ${report.currentNode?.name || "-"}${report.currentNode?.id ? ` (${report.currentNode.id})` : ""}`,
|
||||
` 待办处理人: ${approverNames || "(当前无待办审批人)"}`,
|
||||
` 是否可审批: ${report.diagnostic.canApprove ? "✅ 是 (支持执行同意/驳回)" : "❌ 否 (当前不可审批)"}`,
|
||||
` 诊断结论 : ${report.diagnostic.summary}`,
|
||||
` 排障建议 : ${report.diagnostic.advice}`,
|
||||
];
|
||||
|
||||
if (report.timeline.length > 0) {
|
||||
lines.push("");
|
||||
lines.push("── ⏱️ 审批流转历史轨迹 (Timeline) ──");
|
||||
const timelineRows = report.timeline.map((item) => [
|
||||
`#${item.index}`,
|
||||
item.time || "-",
|
||||
item.nodeName || "-",
|
||||
item.operator?.name || item.operator?.id || (item.automatic ? "自动执行" : "-"),
|
||||
item.action || item.state || "-",
|
||||
item.comment ? (item.comment.length > 30 ? item.comment.slice(0, 30) + "..." : item.comment) : "-",
|
||||
]);
|
||||
lines.push(
|
||||
printTable(
|
||||
["#", "时间", "节点名称", "操作人", "动作", "审批意见"],
|
||||
timelineRows
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `${lines.join("\n")}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user