Support paid flow states, freeflow pay actions, and clean pending nodes
This commit is contained in:
1 parent
d5f68ea2f3
commit
6c6b3034a0
3 files changed
+239
-81
No files matched your search
+140
-77
@@ -250,13 +250,24 @@ export function parseHoseOpenPending(
|
||||
allLogs: HoseOpenAllLogsItem[],
|
||||
staffMap?: Map<string, HoseOpenStaffItem>
|
||||
): HoseFlowPendingNode[] {
|
||||
const pendingItems = allLogs.filter(
|
||||
(item) =>
|
||||
const pendingItems = allLogs.filter((item) => {
|
||||
const stateUpper = String(item.state || "").toUpperCase();
|
||||
if (
|
||||
stateUpper === "CANCELED" ||
|
||||
stateUpper === "CANCELLED" ||
|
||||
stateUpper === "PROCESSED" ||
|
||||
stateUpper === "COMPLETED" ||
|
||||
stateUpper === "PAID"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
item.logId === -1 ||
|
||||
item.state === "APPROVING" ||
|
||||
item.state === "PROCESSING" ||
|
||||
item.state === "PAYING"
|
||||
);
|
||||
stateUpper === "APPROVING" ||
|
||||
stateUpper === "PROCESSING" ||
|
||||
stateUpper === "PAYING"
|
||||
);
|
||||
});
|
||||
|
||||
return pendingItems.map((item, index) => {
|
||||
let approver = extractFlowPerson(item.ownerId);
|
||||
@@ -450,7 +461,19 @@ export function parseHoseOpenComposite(
|
||||
|
||||
const form = (flowDetails.form || {}) as Record<string, unknown>;
|
||||
const history = parseHoseTimeline(flowDetails.logs || [], staffMap);
|
||||
const pending = parseHoseOpenPending(allLogs, staffMap);
|
||||
const rawState = flowDetails.state;
|
||||
const state = translateFlowState(rawState);
|
||||
const rawStateUpper = String(rawState || "").toUpperCase();
|
||||
const isFlowInEndState = [
|
||||
"COMPLETED",
|
||||
"APPROVED",
|
||||
"PAID",
|
||||
"REVOKED",
|
||||
"CANCELED",
|
||||
"CANCELLED",
|
||||
"REJECTED"
|
||||
].includes(rawStateUpper);
|
||||
const pending = isFlowInEndState ? [] : parseHoseOpenPending(allLogs, staffMap);
|
||||
|
||||
const currentNode = pending.find((p) => p.isCurrent)?.name;
|
||||
const metrics = calculateFlowMetrics(
|
||||
@@ -462,9 +485,6 @@ export function parseHoseOpenComposite(
|
||||
const staffOpinions = extractStaffOpinions(history);
|
||||
const rejections = extractRejections(history);
|
||||
|
||||
const rawState = flowDetails.state;
|
||||
const state = translateFlowState(rawState);
|
||||
|
||||
let specification: { id?: string; name?: string; code?: string } | undefined;
|
||||
if (form.specificationId && typeof form.specificationId === "object") {
|
||||
const specObj = form.specificationId as Record<string, unknown>;
|
||||
@@ -542,11 +562,6 @@ export function parseHoseFlow(
|
||||
? nodeState.nodeId
|
||||
: undefined;
|
||||
|
||||
const pending = parseHosePending(plan, currentNode, currentNodeId);
|
||||
const metrics = calculateFlowMetrics(flow, history, raw);
|
||||
const staffOpinions = extractStaffOpinions(history);
|
||||
const rejections = extractRejections(history);
|
||||
|
||||
const rawState =
|
||||
typeof raw.state === "string"
|
||||
? raw.state
|
||||
@@ -554,6 +569,20 @@ export function parseHoseFlow(
|
||||
? flow.state
|
||||
: undefined;
|
||||
const state = translateFlowState(rawState);
|
||||
const rawStateUpper = String(rawState || "").toUpperCase();
|
||||
const isFlowInEndState = [
|
||||
"COMPLETED",
|
||||
"APPROVED",
|
||||
"PAID",
|
||||
"REVOKED",
|
||||
"CANCELED",
|
||||
"CANCELLED",
|
||||
"REJECTED"
|
||||
].includes(rawStateUpper);
|
||||
const pending = isFlowInEndState ? [] : parseHosePending(plan, currentNode, currentNodeId);
|
||||
const metrics = calculateFlowMetrics(flow, history, raw);
|
||||
const staffOpinions = extractStaffOpinions(history);
|
||||
const rejections = extractRejections(history);
|
||||
|
||||
const lastAttributes =
|
||||
history.at(-1)?.nodeName ??
|
||||
@@ -648,6 +677,60 @@ export async function getHoseFlow(
|
||||
return getHoseOpenFlow(client, flowId, staffCache);
|
||||
}
|
||||
|
||||
export function formatAiDecision(decision?: string): string {
|
||||
if (!decision) return "-";
|
||||
const norm = decision.toUpperCase();
|
||||
if (norm === "APPROVE" || norm === "通过") return "通过";
|
||||
if (norm === "EXEMPT_APPROVE" || norm === "免审通过" || norm === "备注通过") return "备注通过";
|
||||
if (norm === "REVIEW" || norm === "转交复核") return "转交复核";
|
||||
if (norm === "REJECT" || norm === "驳回") return "驳回";
|
||||
if (norm === "ERROR" || norm === "错误") return "错误";
|
||||
return decision;
|
||||
}
|
||||
|
||||
export function formatHumanOpinionLines(events: HoseFlowTimelineEntry[]): string[] {
|
||||
const lines: string[] = [];
|
||||
for (const ev of events) {
|
||||
if (
|
||||
(ev.rawAction === "freeflow.carbonCopy" ||
|
||||
ev.rawAction === "freeflow.cc" ||
|
||||
ev.rawAction === "freeflow.print" ||
|
||||
ev.action === "打印提醒" ||
|
||||
ev.action === "抄送通知") &&
|
||||
!ev.comment
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const opName = ev.operator?.name || ev.operator?.id || "未知";
|
||||
const nodePrefix = ev.nodeName?.trim() ? `${ev.nodeName.trim()}(${opName})` : opName;
|
||||
let comment = ev.comment;
|
||||
if (!comment) {
|
||||
if (ev.rawAction === "freeflow.agree" || ev.action === "审批同意") {
|
||||
comment = "同意";
|
||||
} else if (ev.rawAction === "freeflow.autoAgree") {
|
||||
comment = "自动同意";
|
||||
} else if (ev.rawAction === "freeflow.pay" || ev.action === "支付完成") {
|
||||
comment = "支付完成";
|
||||
} else if (ev.rawAction === "freeflow.paying" || ev.action === "支付中") {
|
||||
comment = "支付中";
|
||||
} else if (ev.rawAction === "freeflow.reject" || ev.action === "审批驳回") {
|
||||
comment = "驳回";
|
||||
} else if (ev.rawAction === "freeflow.retract" || ev.action === "单据撤回") {
|
||||
comment = "单据撤回";
|
||||
} else {
|
||||
comment = ev.action || "-";
|
||||
}
|
||||
}
|
||||
|
||||
const line = `${nodePrefix}: ${comment}`;
|
||||
if (lines.length === 0 || lines[lines.length - 1] !== line) {
|
||||
lines.push(line);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
export function alignApprovalRunsWithHoseFlow(
|
||||
runs: ApprovalRun[],
|
||||
flow?: HoseFlowDetail
|
||||
@@ -663,7 +746,7 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
recordId: run.id,
|
||||
sourceDocumentSN: run.sourceDocumentSN,
|
||||
taskMode: run.taskMode,
|
||||
aiDecision: typeof aiDecision === "string" ? aiDecision : "-",
|
||||
aiDecision: formatAiDecision(typeof aiDecision === "string" ? aiDecision : "-"),
|
||||
aiAction: "-",
|
||||
eHumanAction: "-",
|
||||
eHumanComment: "-",
|
||||
@@ -678,11 +761,17 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
);
|
||||
|
||||
const history = flow.history || [];
|
||||
const rawStateUpper = String(flow.rawState || "").toUpperCase();
|
||||
const stateUpper = String(flow.state || "").toUpperCase();
|
||||
const isFlowCompleted =
|
||||
flow.rawState === "COMPLETED" ||
|
||||
flow.rawState === "APPROVED" ||
|
||||
flow.state === "已完成" ||
|
||||
flow.state === "审批通过";
|
||||
rawStateUpper === "COMPLETED" ||
|
||||
rawStateUpper === "APPROVED" ||
|
||||
rawStateUpper === "PAID" ||
|
||||
rawStateUpper === "PAYING" ||
|
||||
stateUpper === "已完成" ||
|
||||
stateUpper === "审批通过" ||
|
||||
stateUpper === "已支付" ||
|
||||
stateUpper === "支付中";
|
||||
|
||||
for (let i = 0; i < sortedRuns.length; i++) {
|
||||
const run = sortedRuns[i];
|
||||
@@ -728,6 +817,12 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
normManual === "已取消" ||
|
||||
normManual === "已撤回" ||
|
||||
normManual === "REVOKED";
|
||||
const isRunApprovedInSeal =
|
||||
normManual === "APPROVED" ||
|
||||
normManual === "已支付/审批完成" ||
|
||||
normManual === "已通过" ||
|
||||
normManual === "已完成" ||
|
||||
normManual === "已支付";
|
||||
|
||||
// 5-second clock skew tolerance window [runTime - 5000, nextRunTime)
|
||||
const windowEvents = history.filter((e) => {
|
||||
@@ -769,9 +864,9 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
!e.isEbot &&
|
||||
e.rawAction !== "freeflow.submit" &&
|
||||
e.action !== "提交送审" &&
|
||||
e.rawAction !== "freeflow.print" &&
|
||||
e.action !== "打印提醒" &&
|
||||
e.rawAction !== "freeflow.comment"
|
||||
!((e.rawAction === "freeflow.comment" || e.action === "发表评论") && !e.comment) &&
|
||||
!((e.rawAction === "freeflow.print" || e.action === "打印提醒") && !e.comment) &&
|
||||
!(e.rawAction === "freeflow.carbonCopy" || e.rawAction === "freeflow.cc" || e.action === "抄送通知")
|
||||
);
|
||||
|
||||
const retractEvent = subsequentHumanEvents.find(
|
||||
@@ -782,19 +877,19 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
);
|
||||
|
||||
const isFlowRetractedOrCancelled =
|
||||
flow.rawState === "DRAFT" ||
|
||||
flow.rawState === "REVOKED" ||
|
||||
flow.rawState === "CANCELED" ||
|
||||
flow.rawState === "CANCELLED" ||
|
||||
flow.state === "草稿" ||
|
||||
flow.state === "已撤回" ||
|
||||
flow.state === "已取消";
|
||||
rawStateUpper === "DRAFT" ||
|
||||
rawStateUpper === "REVOKED" ||
|
||||
rawStateUpper === "CANCELED" ||
|
||||
rawStateUpper === "CANCELLED" ||
|
||||
stateUpper === "草稿" ||
|
||||
stateUpper === "已撤回" ||
|
||||
stateUpper === "已取消";
|
||||
|
||||
const isFlowRejected =
|
||||
flow.rawState === "REJECTED" ||
|
||||
flow.rawState === "TERMINATED" ||
|
||||
flow.state === "审批驳回" ||
|
||||
flow.state === "已驳回";
|
||||
rawStateUpper === "REJECTED" ||
|
||||
rawStateUpper === "TERMINATED" ||
|
||||
stateUpper === "审批驳回" ||
|
||||
stateUpper === "已驳回";
|
||||
|
||||
if (!isLatestRun) {
|
||||
// Historical run that has been superseded by a newer run
|
||||
@@ -810,23 +905,15 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
eHumanComment = rejectEvent.comment || "驳回";
|
||||
} else {
|
||||
eHumanAction = "已修改重提";
|
||||
const opinionLines: string[] = [];
|
||||
const opinionLines = formatHumanOpinionLines(subsequentHumanEvents);
|
||||
for (const ev of subsequentHumanEvents) {
|
||||
const opName = ev.operator?.name || ev.operator?.id || "未知";
|
||||
const nodePrefix = ev.nodeName?.trim() ? `${ev.nodeName.trim()}(${opName})` : opName;
|
||||
const comment =
|
||||
ev.comment ||
|
||||
(ev.rawAction === "freeflow.agree" || ev.action === "审批同意"
|
||||
? "同意"
|
||||
: ev.action || "-");
|
||||
opinionLines.push(`${nodePrefix}: ${comment}`);
|
||||
if (!operator) operator = ev.operator;
|
||||
if (!operator && ev.operator) operator = ev.operator;
|
||||
}
|
||||
eHumanComment = opinionLines.length > 0 ? opinionLines.join("\n") : "-";
|
||||
}
|
||||
} else {
|
||||
// Latest run for this document
|
||||
if (isFlowCompleted) {
|
||||
if (isFlowCompleted || isRunApprovedInSeal) {
|
||||
const hasRetract = subsequentHumanEvents.some(
|
||||
(e) => e.rawAction === "freeflow.retract" || e.action === "单据撤回"
|
||||
);
|
||||
@@ -845,17 +932,9 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
eHumanComment = rejectEvent.comment || "驳回";
|
||||
operator = rejectEvent.operator;
|
||||
} else {
|
||||
const opinionLines: string[] = [];
|
||||
const opinionLines = formatHumanOpinionLines(subsequentHumanEvents);
|
||||
for (const ev of subsequentHumanEvents) {
|
||||
const opName = ev.operator?.name || ev.operator?.id || "未知";
|
||||
const nodePrefix = ev.nodeName?.trim() ? `${ev.nodeName.trim()}(${opName})` : opName;
|
||||
const comment =
|
||||
ev.comment ||
|
||||
(ev.rawAction === "freeflow.agree" || ev.action === "审批同意"
|
||||
? "同意"
|
||||
: ev.action || "-");
|
||||
opinionLines.push(`${nodePrefix}: ${comment}`);
|
||||
if (!operator) operator = ev.operator;
|
||||
if (!operator && ev.operator) operator = ev.operator;
|
||||
}
|
||||
|
||||
if (opinionLines.length > 0) {
|
||||
@@ -866,7 +945,7 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
.find(
|
||||
(e) =>
|
||||
!e.isEbot &&
|
||||
(e.rawAction === "freeflow.agree" || e.action === "审批同意")
|
||||
(e.rawAction === "freeflow.agree" || e.action === "审批同意" || e.rawAction === "freeflow.pay")
|
||||
);
|
||||
eHumanComment = lastHumanApproval?.comment || "-";
|
||||
if (!operator) operator = lastHumanApproval?.operator;
|
||||
@@ -875,17 +954,9 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
} else if (isFlowRetractedOrCancelled || (retractEvent && !hasPostAiResubmit) || isRunCancelledInSeal) {
|
||||
eHumanAction = "已撤回";
|
||||
operator = retractEvent?.operator;
|
||||
const opinionLines: string[] = [];
|
||||
const opinionLines = formatHumanOpinionLines(subsequentHumanEvents);
|
||||
for (const ev of subsequentHumanEvents) {
|
||||
const opName = ev.operator?.name || ev.operator?.id || "未知";
|
||||
const nodePrefix = ev.nodeName?.trim() ? `${ev.nodeName.trim()}(${opName})` : opName;
|
||||
const comment =
|
||||
ev.comment ||
|
||||
(ev.rawAction === "freeflow.agree" || ev.action === "审批同意"
|
||||
? "同意"
|
||||
: ev.action || "-");
|
||||
opinionLines.push(`${nodePrefix}: ${comment}`);
|
||||
if (!operator) operator = ev.operator;
|
||||
if (!operator && ev.operator) operator = ev.operator;
|
||||
}
|
||||
if (retractEvent && opinionLines.length === 0) {
|
||||
opinionLines.push(`${retractEvent.operator?.name || "提交人"}: 单据撤回`);
|
||||
@@ -900,17 +971,9 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
// Flow is still actively approving
|
||||
eHumanAction = auditDrift ? "审核中 (⚠️ AI通过后被修改重提)" : "审核中";
|
||||
|
||||
const opinionLines: string[] = [];
|
||||
const opinionLines = formatHumanOpinionLines(subsequentHumanEvents);
|
||||
for (const ev of subsequentHumanEvents) {
|
||||
const opName = ev.operator?.name || ev.operator?.id || "未知";
|
||||
const nodePrefix = ev.nodeName?.trim() ? `${ev.nodeName.trim()}(${opName})` : opName;
|
||||
const comment =
|
||||
ev.comment ||
|
||||
(ev.rawAction === "freeflow.agree" || ev.action === "审批同意"
|
||||
? "同意"
|
||||
: ev.action || "-");
|
||||
opinionLines.push(`${nodePrefix}: ${comment}`);
|
||||
if (!operator) operator = ev.operator;
|
||||
if (!operator && ev.operator) operator = ev.operator;
|
||||
}
|
||||
|
||||
const pendingNodes = flow.pending || [];
|
||||
@@ -934,7 +997,7 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
recordId: run.id,
|
||||
sourceDocumentSN: run.sourceDocumentSN,
|
||||
taskMode: run.taskMode,
|
||||
aiDecision: aiDecisionStr,
|
||||
aiDecision: formatAiDecision(aiDecisionStr),
|
||||
aiAction,
|
||||
eHumanAction,
|
||||
eHumanComment,
|
||||
|
||||
Reference in new issue
Block a user