Fix retracted run status and eliminate synthetic node leakage
This commit is contained in:
1 parent
86ac075c48
commit
047c877c1f
3 files changed
+140
-21
No files matched your search
@@ -1148,6 +1148,72 @@ describe("Hose Flow Domain", () => {
|
||||
} as any
|
||||
);
|
||||
expect(res2.comment).toBe("财务经理(周晚容): 单据超标缺少说明");
|
||||
|
||||
const res3 = formatRejectionComment(
|
||||
undefined,
|
||||
undefined,
|
||||
{ nodeName: "合思审批节点", rejectComment: "超额报销" }
|
||||
);
|
||||
expect(res3.comment).toBe("超额报销");
|
||||
expect(res3.comment).not.toContain("合思审批节点");
|
||||
});
|
||||
|
||||
test("handles historical retracted run superseded by paid run (B26002100 case)", () => {
|
||||
const runs = [
|
||||
{
|
||||
id: "run-round-1",
|
||||
sourceDocumentSN: "B26002100",
|
||||
taskMode: "assisted",
|
||||
createdAt: 100000,
|
||||
manualApprovalRecord: {
|
||||
nodeName: "合思审批节点",
|
||||
status: { type: "TERMINATED", label: "已驳回", sourceStatus: "已支付回调补偿驳回" }
|
||||
},
|
||||
result: { decision: "APPROVE" }
|
||||
},
|
||||
{
|
||||
id: "run-round-2",
|
||||
sourceDocumentSN: "B26002100",
|
||||
taskMode: "assisted",
|
||||
createdAt: 200000,
|
||||
manualApprovalRecord: {
|
||||
status: { type: "APPROVED", label: "已支付/审批完成", sourceStatus: "已支付/审批完成" }
|
||||
},
|
||||
result: { decision: "APPROVE" }
|
||||
}
|
||||
] as any[];
|
||||
|
||||
const flow = {
|
||||
state: "已支付",
|
||||
rawState: "paid",
|
||||
history: [
|
||||
{ time: 99000, action: "提交送审", rawAction: "freeflow.submit", operator: { name: "袁锦" } },
|
||||
{ time: 101000, action: "审批同意", rawAction: "freeflow.agree", isEbot: true, operator: { name: "Ebot" } },
|
||||
{ time: 105000, action: "审批同意", rawAction: "freeflow.agree", nodeName: "费用类型是研发费", operator: { name: "宁艳楠" }, comment: "同意" },
|
||||
{ time: 150000, action: "单据撤回", rawAction: "freeflow.retract", operator: { name: "袁锦" } },
|
||||
{ time: 199000, action: "提交送审", rawAction: "freeflow.submit", operator: { name: "袁锦" } },
|
||||
{ time: 201000, action: "审批同意", rawAction: "freeflow.agree", isEbot: true, operator: { name: "Ebot" } },
|
||||
{ time: 205000, action: "审批同意", rawAction: "freeflow.agree", nodeName: "费用类型是研发费", operator: { name: "宁艳楠" }, comment: "同意" },
|
||||
{ time: 210000, action: "审批同意", rawAction: "freeflow.agree", nodeName: "财务经理", operator: { name: "周晚容" }, comment: "同意" },
|
||||
{ time: 220000, action: "支付成功", rawAction: "freeflow.pay", operator: { name: "高思琦" } }
|
||||
]
|
||||
} as any;
|
||||
|
||||
const aligned = alignApprovalRunsWithHoseFlow(runs, flow);
|
||||
|
||||
const r1 = aligned.get("run-round-1")!;
|
||||
expect(r1.eHumanAction).toBe("已撤回");
|
||||
expect(r1.eHumanComment).toBe(
|
||||
"1. 费用类型是研发费(宁艳楠): 同意\n2. 袁锦: 单据撤回"
|
||||
);
|
||||
expect(r1.eHumanComment).not.toContain("合思审批节点");
|
||||
expect(r1.eHumanComment).not.toContain("审批驳回");
|
||||
|
||||
const r2 = aligned.get("run-round-2")!;
|
||||
expect(r2.eHumanAction).toBe("已支付");
|
||||
expect(r2.eHumanComment).toBe(
|
||||
"1. 费用类型是研发费(宁艳楠): 同意\n2. 财务经理(周晚容): 同意\n3. 高思琦: 支付成功"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
+70
-20
@@ -786,6 +786,16 @@ export function formatRejectionComment(
|
||||
""
|
||||
).trim();
|
||||
|
||||
// Strip Seal's synthetic wrapper node names (never output "合思审批节点" to user)
|
||||
if (
|
||||
rawNodeName === "合思审批节点" ||
|
||||
rawNodeName === "外部审批节点" ||
|
||||
rawNodeName.includes("合思审批") ||
|
||||
rawNodeName.includes("外部审批")
|
||||
) {
|
||||
rawNodeName = "";
|
||||
}
|
||||
|
||||
// In Hose, freeflow.reject often records target node "提交人" (meaning rejected back to submitter)
|
||||
// If we have an operator name, lookup their actual approval nodeName in history
|
||||
if ((!rawNodeName || rawNodeName === "提交人") && opName && history) {
|
||||
@@ -986,6 +996,10 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
typeof mar.status === "object" && mar.status !== null
|
||||
? String((mar.status as Record<string, unknown>).type || (mar.status as Record<string, unknown>).label || "").toUpperCase()
|
||||
: "";
|
||||
const marSourceStatus =
|
||||
typeof mar.status === "object" && mar.status !== null
|
||||
? String((mar.status as Record<string, unknown>).sourceStatus || "")
|
||||
: "";
|
||||
const rawManual =
|
||||
(doc.manualApprovalStatus as string | undefined) ||
|
||||
(res.manualApprovalStatus as string | undefined) ||
|
||||
@@ -996,7 +1010,11 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
normManual === "CANCELED" ||
|
||||
normManual === "已取消" ||
|
||||
normManual === "已撤回" ||
|
||||
normManual === "REVOKED";
|
||||
normManual === "REVOKED" ||
|
||||
marStatus === "CANCELLED" ||
|
||||
marStatus === "CANCELED" ||
|
||||
marSourceStatus.includes("撤回") ||
|
||||
marSourceStatus.includes("取消");
|
||||
const isRunApprovedInSeal =
|
||||
normManual === "APPROVED" ||
|
||||
normManual === "已支付/审批完成" ||
|
||||
@@ -1004,16 +1022,19 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
normManual === "已完成" ||
|
||||
normManual === "已支付" ||
|
||||
marStatus === "APPROVED";
|
||||
const isRunCompensation =
|
||||
marSourceStatus.includes("补偿") || marSourceStatus.includes("已支付");
|
||||
const isRunRejectedInSeal =
|
||||
normManual === "TERMINATED" ||
|
||||
normManual === "REJECTED" ||
|
||||
normManual === "REJECT" ||
|
||||
normManual === "已驳回" ||
|
||||
normManual === "被驳回" ||
|
||||
marStatus === "TERMINATED" ||
|
||||
marStatus === "REJECTED" ||
|
||||
marStatus === "已驳回" ||
|
||||
marStatus === "被驳回";
|
||||
!isRunCompensation &&
|
||||
(normManual === "TERMINATED" ||
|
||||
normManual === "REJECTED" ||
|
||||
normManual === "REJECT" ||
|
||||
normManual === "已驳回" ||
|
||||
normManual === "被驳回" ||
|
||||
marStatus === "TERMINATED" ||
|
||||
marStatus === "REJECTED" ||
|
||||
marStatus === "已驳回" ||
|
||||
marStatus === "被驳回");
|
||||
|
||||
// 5-second clock skew tolerance window [runTime - 5000, nextRunTime)
|
||||
const windowEvents = history.filter((e) => {
|
||||
@@ -1069,37 +1090,61 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
|
||||
if (!isLatestRun) {
|
||||
// Historical run that has been superseded by a newer run
|
||||
if (rejectEvent || isRunRejectedInSeal) {
|
||||
if (rejectEvent || (!flow && isRunRejectedInSeal)) {
|
||||
eHumanAction = "审批驳回";
|
||||
auditDrift = false;
|
||||
auditDriftReason = undefined;
|
||||
const rejInfo = formatRejectionComment(rejectEvent, undefined, mar, history);
|
||||
eHumanComment = rejInfo.comment;
|
||||
operator = rejInfo.operator;
|
||||
} else if (retractEvent || isRunCancelledInSeal) {
|
||||
} else if (retractEvent || isRunCancelledInSeal || (!rejectEvent && marSourceStatus.includes("单据撤回"))) {
|
||||
eHumanAction = "已撤回";
|
||||
operator = retractEvent?.operator;
|
||||
// Events belonging to this run only occur up to the retract event
|
||||
const runEvents = retractEvent
|
||||
? subsequentHumanEvents.filter((e) => (e.time ?? 0) <= (retractEvent.time ?? Infinity))
|
||||
: subsequentHumanEvents;
|
||||
const opinionLines = formatHumanOpinionLines(runEvents);
|
||||
for (const ev of runEvents) {
|
||||
if (!operator && ev.operator) operator = ev.operator;
|
||||
}
|
||||
if (retractEvent && !opinionLines.some((l) => l.includes("单据撤回"))) {
|
||||
opinionLines.push(`${retractEvent.operator?.name || "提交人"}: 单据撤回`);
|
||||
}
|
||||
eHumanComment =
|
||||
retractEvent?.comment ||
|
||||
(retractEvent ? `${retractEvent.operator?.name || "提交人"}: 单据撤回` : "单据已撤回/取消");
|
||||
opinionLines.length > 1
|
||||
? formatNumberedHumanOpinions(opinionLines, [], "forward")
|
||||
: opinionLines.length === 1
|
||||
? opinionLines[0]!
|
||||
: (retractEvent ? `${retractEvent.operator?.name || "提交人"}: 单据撤回` : "单据已撤回");
|
||||
} else {
|
||||
eHumanAction = "已修改重提";
|
||||
const opinionLines = formatHumanOpinionLines(subsequentHumanEvents);
|
||||
for (const ev of subsequentHumanEvents) {
|
||||
if (!operator && ev.operator) operator = ev.operator;
|
||||
}
|
||||
eHumanComment = formatNumberedHumanOpinions(opinionLines, [], "forward");
|
||||
eHumanComment =
|
||||
opinionLines.length > 1
|
||||
? formatNumberedHumanOpinions(opinionLines, [], "forward")
|
||||
: opinionLines.length === 1
|
||||
? opinionLines[0]!
|
||||
: "-";
|
||||
}
|
||||
} else {
|
||||
// Latest run for this document
|
||||
if (rejectEvent || isRunRejectedInSeal || isFlowRejected) {
|
||||
if (
|
||||
rejectEvent ||
|
||||
isFlowRejected ||
|
||||
(flow && flow.rejections && flow.rejections.length > 0) ||
|
||||
(!flow && isRunRejectedInSeal)
|
||||
) {
|
||||
eHumanAction = "审批驳回";
|
||||
auditDrift = false;
|
||||
auditDriftReason = undefined;
|
||||
const rejInfo = formatRejectionComment(rejectEvent, flow.rejections?.[0], mar, history);
|
||||
const rejInfo = formatRejectionComment(rejectEvent, flow?.rejections?.[0], mar, history);
|
||||
eHumanComment = rejInfo.comment;
|
||||
operator = rejInfo.operator;
|
||||
} else if (isFlowCompleted || isRunApprovedInSeal) {
|
||||
} else if (isFlowCompleted || (!flow && isRunApprovedInSeal)) {
|
||||
eHumanAction = isFlowPaid ? "已支付" : "审批通过";
|
||||
|
||||
const opinionLines = formatHumanOpinionLines(subsequentHumanEvents);
|
||||
@@ -1129,10 +1174,15 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
for (const ev of subsequentHumanEvents) {
|
||||
if (!operator && ev.operator) operator = ev.operator;
|
||||
}
|
||||
if (retractEvent && opinionLines.length === 0) {
|
||||
if (retractEvent && !opinionLines.some((l) => l.includes("单据撤回"))) {
|
||||
opinionLines.push(`${retractEvent.operator?.name || "提交人"}: 单据撤回`);
|
||||
}
|
||||
eHumanComment = opinionLines.length > 0 ? opinionLines.join("\n") : "单据已撤回";
|
||||
eHumanComment =
|
||||
opinionLines.length > 1
|
||||
? formatNumberedHumanOpinions(opinionLines, [], "forward")
|
||||
: opinionLines.length === 1
|
||||
? opinionLines[0]!
|
||||
: "单据已撤回";
|
||||
} else if (isFlowPaying) {
|
||||
eHumanAction = "⏳ 支付中";
|
||||
|
||||
|
||||
@@ -703,8 +703,11 @@ export async function exportApprovalRunsToExcel(
|
||||
|
||||
// 6. 人工审核状态与驳回原因
|
||||
const mar = (record as any).manualApprovalRecord || {};
|
||||
const marSourceStatus = String(mar.status?.sourceStatus || "");
|
||||
let manualStatus = "-";
|
||||
if (mar.status?.label) {
|
||||
if (marSourceStatus === "已支付回调补偿驳回" || marSourceStatus.includes("补偿驳回")) {
|
||||
manualStatus = "已撤回";
|
||||
} else if (mar.status?.label) {
|
||||
manualStatus = String(mar.status.label);
|
||||
} else if (mar.status?.type) {
|
||||
const t = String(mar.status.type);
|
||||
|
||||
Reference in new issue
Block a user