feat: add approval flow dwell time metadata
This commit is contained in:
1 parent
a2d078aafe
commit
9ddbd0390d
5 files changed
+33
-5
No files matched your search
@@ -58,7 +58,7 @@ hose bill get S26000001 --risk --json
|
||||
|
||||
## 3. 单据审批流程 (`bill flow`)
|
||||
|
||||
读取单据右侧审批流程面板的真实业务接口,输出历史流转日志、处理人、审批意见、当前节点和后续节点;使用 `--json` 可获得结构化时间线。
|
||||
读取单据右侧审批流程面板的真实业务接口,输出历史流转日志、处理人、审批意见、节点停留时长、自动跳过标记、当前节点和后续节点;使用 `--json` 可获得结构化时间线。
|
||||
|
||||
```bash
|
||||
hose-use bill flow CL20260903001
|
||||
|
||||
@@ -243,6 +243,8 @@ export async function handleBillCommand(
|
||||
entry.nodeName || "-",
|
||||
entry.action || "-",
|
||||
entry.operator?.name || (entry.automatic ? "系统" : "-"),
|
||||
entry.durationMs !== undefined ? `${Math.round(entry.durationMs / 1000)} 秒` : "-",
|
||||
entry.skipped ? "自动跳过" : entry.automatic ? "自动" : "",
|
||||
entry.comment || "-",
|
||||
]);
|
||||
const pendingRows = flow.pending.map((node) => [
|
||||
@@ -256,7 +258,7 @@ export async function handleBillCommand(
|
||||
`流程 ID: ${flow.flowId || "-"} 当前节点: ${flow.currentNode || "-"}`,
|
||||
"",
|
||||
"--- 历史流转 ---",
|
||||
flow.history.length ? printTable(["时间", "节点", "动作", "处理人", "意见"], historyRows) : " (暂无历史记录)",
|
||||
flow.history.length ? printTable(["时间", "节点", "动作", "处理人", "停留时长", "标记", "意见"], historyRows) : " (暂无历史记录)",
|
||||
"",
|
||||
"--- 后续节点 ---",
|
||||
flow.pending.length ? printTable(["状态", "节点", "类型", "审批人"], pendingRows) : " (暂无后续节点)",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from "bun:test";
|
||||
import { formatSingleBill, getBillReferences, getBillRelations, getBillAttachments, getBillRisk } from "./tools.js";
|
||||
import { formatSingleBill, getBillReferences, getBillRelations, getBillAttachments, getBillRisk, getBillFlow } from "./tools.js";
|
||||
import { RawBillItemSchema, EntitySchema } from "./types.js";
|
||||
|
||||
describe("Bill Domain", () => {
|
||||
@@ -191,4 +191,22 @@ describe("Bill Domain", () => {
|
||||
expect(result?.warnings[0]?.controlName).toBe("重复报销");
|
||||
expect(result?.invoiceWarnings).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("calculates approval-node dwell time and automatic skip markers", async () => {
|
||||
const client = {
|
||||
post: async (path: string) => {
|
||||
if (path.includes("backlogs/search")) {
|
||||
return new Response(JSON.stringify({ items: [{ id: "backlog-flow", flowId: { id: "flow-flow", form: { code: "S26000005", title: "流程时长" } } }] }));
|
||||
}
|
||||
return new Response(JSON.stringify({ value: { id: "backlog-flow", state: "APPROVING", nodeName: "财务审批", flowId: { id: "flow-flow", form: { code: "S26000005", title: "流程时长" }, logs: [
|
||||
{ id: "log-1", time: 1000, operatorId: "staff-1", attributes: { nodeName: "提交" } },
|
||||
{ id: "log-2", time: 2500, operatorId: null, state: "SKIPPED", attributes: { nodeName: "自动校验", isAuto: true, isSkip: true } },
|
||||
], plan: { nodes: [] } } } }));
|
||||
},
|
||||
} as any;
|
||||
const result = await getBillFlow(client, "corp-flow", "S26000005");
|
||||
expect(result?.history[0]?.durationMs).toBe(1500);
|
||||
expect(result?.history[1]?.automatic).toBe(true);
|
||||
expect(result?.history[1]?.skipped).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -709,20 +709,26 @@ export async function getBillFlow(
|
||||
const form = flow.form && typeof flow.form === "object" ? flow.form as Record<string, unknown> : {};
|
||||
const nodeState = raw.nodeState && typeof raw.nodeState === "object" ? raw.nodeState as Record<string, unknown> : {};
|
||||
const logs = Array.isArray(flow.logs) ? flow.logs : [];
|
||||
const history: BillFlowEntry[] = logs.map((value) => {
|
||||
const history: BillFlowEntry[] = logs.map((value, index) => {
|
||||
const log = value && typeof value === "object" ? value as Record<string, unknown> : {};
|
||||
const attributes = log.attributes && typeof log.attributes === "object" ? log.attributes as Record<string, unknown> : {};
|
||||
const currentTime = typeof log.time === "number" ? log.time : undefined;
|
||||
const nextLog = logs[index + 1] && typeof logs[index + 1] === "object" ? logs[index + 1] as Record<string, unknown> : undefined;
|
||||
const nextTime = typeof nextLog?.time === "number" ? nextLog.time : undefined;
|
||||
const durationMs = currentTime !== undefined && nextTime !== undefined && nextTime >= currentTime ? nextTime - currentTime : undefined;
|
||||
const nextOperators = Array.isArray(log.nextOperatorIds)
|
||||
? log.nextOperatorIds.map(flowPerson).filter((person): person is NonNullable<typeof person> => Boolean(person))
|
||||
: [];
|
||||
return {
|
||||
id: typeof log.id === "string" ? log.id : undefined,
|
||||
time: typeof log.time === "number" ? log.time : undefined,
|
||||
time: currentTime,
|
||||
durationMs,
|
||||
state: typeof log.state === "string" ? log.state : undefined,
|
||||
action: typeof log.action === "string" ? log.action : undefined,
|
||||
nodeName: typeof attributes.nodeName === "string" ? attributes.nodeName : typeof attributes.nextName === "string" ? attributes.nextName : undefined,
|
||||
comment: typeof attributes.comment === "string" && attributes.comment ? attributes.comment : undefined,
|
||||
automatic: attributes.isEbotNode === true || attributes.isAuto === true || !log.operatorId,
|
||||
skipped: attributes.isSkip === true || attributes.skipped === true || log.state === "SKIPPED",
|
||||
operator: flowPerson(log.operatorId),
|
||||
nextOperators,
|
||||
};
|
||||
|
||||
@@ -107,11 +107,13 @@ export interface BillQueryParams {
|
||||
export interface BillFlowEntry {
|
||||
id?: string;
|
||||
time?: number;
|
||||
durationMs?: number;
|
||||
state?: string;
|
||||
action?: string;
|
||||
nodeName?: string;
|
||||
comment?: string;
|
||||
automatic?: boolean;
|
||||
skipped?: boolean;
|
||||
operator?: { id?: string; name?: string; code?: string };
|
||||
nextOperators?: Array<{ id?: string; name?: string; code?: string }>;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user