100 lines
3.7 KiB
TypeScript
100 lines
3.7 KiB
TypeScript
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
|
import { createBillActionContext } from "./bill/context.js";
|
|
import { handleTrace, handleList } from "./bill/search.js";
|
|
import { handleFlow, handleRisk } from "./bill/flow.js";
|
|
import { handleApprove, handleReject } from "./bill/approve.js";
|
|
|
|
function printFlowHelp(): string {
|
|
return [
|
|
"hose-use flow - 审批流全域透视与穿透诊断命令族",
|
|
"",
|
|
"用法:",
|
|
" hose-use flow <单号|ID> 等价于 flow get/trace,快速透视单据流转与诊断待办",
|
|
" hose-use flow get <单号|ID> 深度穿透单据全貌、当前驻留节点与 400 待办根因诊断",
|
|
" hose-use flow trace <单号|ID> (别名) 同 flow get",
|
|
" hose-use flow history <单号|ID> 查看审批历史流转时间线与后续节点",
|
|
" hose-use flow risk <单号|ID> 查看费控与合规风控诊断",
|
|
" hose-use flow list [options] 列出当前待审批/已审批单据流",
|
|
" hose-use flow approve <单号|ID> 执行审批同意 (受 --dry-run 与 --yes 约束)",
|
|
" hose-use flow reject <单号|ID> 执行审批驳回 (受 --dry-run 与 --yes 约束)",
|
|
"",
|
|
"选项:",
|
|
" --corp=<id> 指定操作企业 (默认激活企业)",
|
|
" --json 以 JSON 结构化格式输出诊断数据",
|
|
" --verbose 显示完整调试信息",
|
|
" -h, --help 显示帮助信息",
|
|
].join("\n");
|
|
}
|
|
|
|
export async function handleFlowCommand(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime
|
|
): Promise<CliResult> {
|
|
if (parsed.options.help || parsed.action === "help") {
|
|
return {
|
|
stdout: printFlowHelp() + "\n",
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const corp = runtime.selectedCorp;
|
|
if (!corp) {
|
|
return {
|
|
stdout: "",
|
|
stderr: "未选中企业,请先通过 hose-use corps switch 或 --corp 指定企业\n",
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
const action = parsed.action?.toLowerCase();
|
|
const args = [...parsed.args];
|
|
|
|
// 1. 无动作无参数且无 --code/--id 选项时,默认展示列表
|
|
if (!action && args.length === 0 && !parsed.options.code && !parsed.options.id) {
|
|
const ctx = createBillActionContext(parsed, runtime);
|
|
return handleList(ctx);
|
|
}
|
|
|
|
// 2. 识别透视与穿透类动词
|
|
const flowTraceActions = new Set(["get", "trace", "inspect", "diagnose", "show", "find"]);
|
|
if (action && flowTraceActions.has(action)) {
|
|
const ctx = createBillActionContext(parsed, runtime);
|
|
return handleTrace(ctx);
|
|
}
|
|
|
|
// 3. 识别其他常用审批流动作
|
|
const flowOtherActions = new Set(["history", "records", "timeline", "risk", "list", "search", "approve", "agree", "reject", "deny"]);
|
|
if (action && flowOtherActions.has(action)) {
|
|
const ctx = createBillActionContext(parsed, runtime);
|
|
switch (action) {
|
|
case "history":
|
|
case "records":
|
|
case "timeline":
|
|
return handleFlow(ctx);
|
|
case "risk":
|
|
return handleRisk(ctx);
|
|
case "list":
|
|
case "search":
|
|
return handleList(ctx);
|
|
case "approve":
|
|
case "agree":
|
|
return handleApprove(ctx);
|
|
case "reject":
|
|
case "deny":
|
|
return handleReject(ctx);
|
|
}
|
|
}
|
|
|
|
// 4. 用户直接输入单号:hose-use flow <单号|ID>
|
|
// 从原始 positional[1] 获取未经 lowercase 转换的原始单号/ID
|
|
const rawTarget = parsed.positional?.[1] || parsed.action;
|
|
const rewrittenParsed: CliParsedArgs = {
|
|
...parsed,
|
|
action: "trace",
|
|
args: [rawTarget!, ...args],
|
|
};
|
|
const ctx = createBillActionContext(rewrittenParsed, runtime);
|
|
return handleTrace(ctx);
|
|
}
|