Fix time-windowed rejection scoping, revert synthetic mapping on system fields, and make E columns strictly opt-in via --with-flow

This commit is contained in:
gitea committed 2026-09-15 09:23:06 +08:00
1 parent de79e9735b
commit 577ad0415c
4 files changed
+141 -39

No files matched your search

+2 -1
View File
@@ -147,7 +147,8 @@ seal-use analytics performance --corp <corpId> [--start-date <ISO|ms>] [--end-da
seal-use analytics analyze <recordId> --corp <corpId>
seal-use analytics export --corp <corpId> [--downloads] [--out <file>] [--start-date <ISO>] [--end-date <ISO>] [--force]
seal-use approval-runs count --corp <corpId> [--status APPROVED] [--start <YYYY-MM-DD|ms>] [--end <YYYY-MM-DD|ms>]
seal-use approval-runs export --corp <corpId> [--start <YYYY-MM-DD|ms>] [--end <YYYY-MM-DD|ms>] [--force] [--status <status>] [--manual-status <status>] [--completed-only] [--limit <n>] [--downloads] [--out <file>]
seal-use approval-runs export --corp <corpId> [--start <YYYY-MM-DD|ms>] [--end <YYYY-MM-DD|ms>] [--force] [--status <status>] [--manual-status <status>] [--completed-only] [--limit <n>] [--downloads] [--out <file>] [--with-flow]
# --with-flow: 启用合思原生审批流对齐,输出 E人工行为 / E人工意见 两列(默认关闭以节省合思 API 调用)
seal-use approval-runs search --corp <corpId> [--query text] [--limit 20] [--includeBridge true]
seal-use approval-runs get <recordId> --corp <corpId> [--fields metadata|document.fields,result.summary] [--output-file file.json]
seal-use approval-runs attachments <recordId> --corp <corpId>
+26 -17
View File
@@ -1137,17 +1137,18 @@ export function alignApprovalRunsWithHoseFlow(
: "-";
}
} else {
// Latest run for this document
if (
rejectEvent ||
isFlowRejected ||
(flow && flow.rejections && flow.rejections.length > 0) ||
(!flow && isRunRejectedInSeal)
) {
// Latest run for this document.
// Rule: rejectEvent is scoped to THIS run's time window — if it exists, this run was
// definitively rejected regardless of what the overall flow state is now (the flow may
// have been paid via a subsequent re-submission).
// flow.rejections.length alone is NOT reliable — it can contain rejections from earlier
// rounds. Only use it as a fallback when isFlowRejected (current state) is also true.
if (rejectEvent) {
// A rejection event occurred inside this run's time window → this run was rejected.
eHumanAction = "审批驳回";
auditDrift = false;
auditDriftReason = undefined;
const rejInfo = formatRejectionComment(rejectEvent, flow?.rejections?.[0], mar, history);
const rejInfo = formatRejectionComment(rejectEvent, undefined, mar, history);
eHumanComment = rejInfo.comment;
operator = rejInfo.operator;
} else if (isFlowCompleted || (!flow && isRunApprovedInSeal)) {
@@ -1173,6 +1174,15 @@ export function alignApprovalRunsWithHoseFlow(
eHumanComment = lastHumanApproval?.comment ? `1. ${lastHumanApproval.comment}` : "-";
if (!operator) operator = lastHumanApproval?.operator;
}
} else if (isFlowPaying) {
eHumanAction = "⏳ 支付中";
const opinionLines = formatHumanOpinionLines(subsequentHumanEvents);
for (const ev of subsequentHumanEvents) {
if (!operator && ev.operator) operator = ev.operator;
}
const pendingLines = extractPendingLines(flow);
eHumanComment = formatNumberedHumanOpinions(opinionLines, pendingLines, "reverse");
} else if (isFlowRetractedOrCancelled || (retractEvent && !hasPostAiResubmit) || isRunCancelledInSeal) {
eHumanAction = "已撤回";
operator = retractEvent?.operator;
@@ -1189,15 +1199,14 @@ export function alignApprovalRunsWithHoseFlow(
: opinionLines.length === 1
? opinionLines[0]!
: "单据已撤回";
} else if (isFlowPaying) {
eHumanAction = "⏳ 支付中";
const opinionLines = formatHumanOpinionLines(subsequentHumanEvents);
for (const ev of subsequentHumanEvents) {
if (!operator && ev.operator) operator = ev.operator;
}
const pendingLines = extractPendingLines(flow);
eHumanComment = formatNumberedHumanOpinions(opinionLines, pendingLines, "reverse");
} else if (isFlowRejected || (!flow && isRunRejectedInSeal)) {
// No rejectEvent in this run's window, but the current Hose flow state is rejected.
eHumanAction = "审批驳回";
auditDrift = false;
auditDriftReason = undefined;
const rejInfo = formatRejectionComment(undefined, flow?.rejections?.[0], mar, history);
eHumanComment = rejInfo.comment;
operator = rejInfo.operator;
} else {
// Flow is actively approving
eHumanAction = "⏳ 审批中";
+72 -7
View File
@@ -267,7 +267,7 @@ describe("exportApprovalRunsToExcel integration", () => {
expect(result.rejectReasonCount).toBe(1);
expect(existsSync(tmpOut)).toBe(true);
// Verify Excel contents with ExcelJS
// Verify Excel contents with ExcelJS: default export does NOT include E columns (Hose resource optimization)
const wb = new ExcelJS.Workbook();
await wb.xlsx.readFile(tmpOut);
const ws = wb.worksheets[0]!;
@@ -275,20 +275,85 @@ describe("exportApprovalRunsToExcel integration", () => {
expect(ws.getRow(1).getCell(1).value).toBe("单据编号");
expect(ws.getRow(1).getCell(9).value).toBe("人工审核");
expect(ws.getRow(1).getCell(10).value).toBe("人工驳回原因");
expect(ws.getRow(1).getCell(11).value).toBe("E人工行为");
expect(ws.getRow(1).getCell(12).value).toBe("E人工意见");
expect(ws.getRow(1).getCell(11).value).toBe("创建时间");
expect(ws.getRow(1).getCell(12).value).toBe("任务耗时");
expect(ws.getRow(2).getCell(1).value).toBe("B26001");
expect(ws.getRow(2).getCell(9).value).toBe("已支付/审批完成");
expect(ws.getRow(2).getCell(10).value).toBe("-");
expect(ws.getRow(2).getCell(11).value).toBe("-");
expect(ws.getRow(2).getCell(12).value).toBe("-");
expect(ws.getRow(3).getCell(1).value).toBe("B26002");
expect(ws.getRow(3).getCell(9).value).toBe("被驳回");
expect(ws.getRow(3).getCell(10).value).toBe("请上传正确的行程单凭据");
expect(ws.getRow(3).getCell(11).value).toBe("-");
expect(ws.getRow(3).getCell(12).value).toBe("-");
} finally {
if (existsSync(tmpOut)) {
rmSync(tmpOut, { force: true });
}
}
});
test("generates excel workbook with E columns when withFlow is true for hose corp", async () => {
const hoseCorp: CorpConfig = {
...testCorp,
source: { type: "hose", corpId: "corp-hose-1" } as any
};
const mockClient = {
get: (url: string) => {
if (url.includes("api/v1/rules")) {
return {
json: async () => ({
rules: [{ id: "r1", code: 0, description: "发票真实性核验", scope: "全局", strictness: "SHOULD_FOLLOW" }]
})
};
}
if (url.includes("api/v1/approvals")) {
return {
json: async () => ({
total: 1,
records: [
{
id: "run-h1",
sourceDocumentSN: "B26001",
status: "completed",
taskMode: "assisted",
sourceSystem: "hosecloud",
document: { fields: [] },
result: { decision: "APPROVE", rulesResult: [] },
manualApprovalRecord: {
status: { label: "已通过", type: "APPROVED" }
},
createdAt: 1788760000000,
updatedAt: 1788760030000
}
]
})
};
}
throw new Error(`Unexpected url: ${url}`);
}
} as any;
const tmpOut = join(tmpdir(), `test-export-flow-${Date.now()}.xlsx`);
try {
const result = await exportApprovalRunsToExcel(mockClient, hoseCorp, {
outputFile: tmpOut,
limit: 10,
pageDelayMs: 0,
withFlow: true
});
expect(result.recordCount).toBe(1);
const wb = new ExcelJS.Workbook();
await wb.xlsx.readFile(tmpOut);
const ws = wb.worksheets[0]!;
expect(ws.getRow(1).getCell(1).value).toBe("单据编号");
expect(ws.getRow(1).getCell(9).value).toBe("人工审核");
expect(ws.getRow(1).getCell(10).value).toBe("人工驳回原因");
expect(ws.getRow(1).getCell(11).value).toBe("E人工行为");
expect(ws.getRow(1).getCell(12).value).toBe("E人工意见");
expect(ws.getRow(1).getCell(13).value).toBe("创建时间");
} finally {
if (existsSync(tmpOut)) {
rmSync(tmpOut, { force: true });
+41 -14
View File
@@ -482,6 +482,8 @@ export async function exportApprovalRunsToExcel(
views: [{ state: "frozen", ySplit: 1, xSplit: 2 }]
});
const withFlow = options.withFlow === true && corp.source.type === "hose";
const baseColumns: Array<{ header: string; key: string; width: number }> = [
{ header: "单据编号", key: "sn", width: 16 },
{ header: "单据模板名称", key: "templateName", width: 26 },
@@ -493,8 +495,12 @@ export async function exportApprovalRunsToExcel(
{ header: "思考深度", key: "thinkingDepth", width: 12 },
{ header: "人工审核", key: "manualStatus", width: 16 },
{ header: "人工驳回原因", key: "humanRejectReason", width: 36 },
{ header: "E人工行为", key: "eHumanAction", width: 18 },
{ header: "E人工意见", key: "eHumanComment", width: 36 },
...(withFlow
? [
{ header: "E人工行为", key: "eHumanAction", width: 18 },
{ header: "E人工意见", key: "eHumanComment", width: 36 }
]
: []),
{ header: "创建时间", key: "createdAt", width: 20 },
{ header: "任务耗时", key: "duration", width: 12 },
{ header: "关联规则数", key: "hitRuleCount", width: 12 },
@@ -705,9 +711,7 @@ export async function exportApprovalRunsToExcel(
const mar = (record as any).manualApprovalRecord || {};
const marSourceStatus = String(mar.status?.sourceStatus || "");
let manualStatus = "-";
if (marSourceStatus === "已支付回调补偿驳回" || marSourceStatus.includes("补偿驳回")) {
manualStatus = "已撤回";
} else if (mar.status?.label) {
if (mar.status?.label) {
manualStatus = String(mar.status.label);
} else if (mar.status?.type) {
const t = String(mar.status.type);
@@ -769,8 +773,12 @@ export async function exportApprovalRunsToExcel(
thinkingDepth: "标准",
manualStatus,
humanRejectReason,
eHumanAction,
eHumanComment,
...(withFlow
? {
eHumanAction,
eHumanComment
}
: {}),
createdAt: createdAtStr,
duration: durationStr,
hitRuleCount: hitRuleIds.length,
@@ -804,14 +812,33 @@ export async function exportApprovalRunsToExcel(
};
if (colNumber <= baseColumns.length) {
const colDef = baseColumns[colNumber - 1];
const colKey = colDef?.key || "";
const isLeftAligned = [
"sn",
"templateName",
"humanRejectReason",
"eHumanComment",
"hitRulesSummary",
"aiSummary"
].includes(colKey);
const isWrapText = [
"humanRejectReason",
"eHumanComment",
"hitRulesSummary",
"aiSummary"
].includes(colKey);
cell.alignment = {
vertical: "middle",
horizontal: [1, 2, 10, 12, 16, 17].includes(colNumber) ? "left" : "center",
wrapText: [10, 12, 16, 17].includes(colNumber)
horizontal: isLeftAligned ? "left" : "center",
wrapText: isWrapText
};
// AI 决策颜色区分
if (colNumber === 7) {
if (colKey === "aiDecision") {
if (val === "通过" || val === "备注通过") cell.font = { color: { argb: "FF16A34A" }, bold: true };
else if (val === "转交复核") cell.font = { color: { argb: "FFD97706" }, bold: true };
else if (val === "驳回") cell.font = { color: { argb: "FFDC2626" }, bold: true };
@@ -819,7 +846,7 @@ export async function exportApprovalRunsToExcel(
}
// 人工审核高亮
if (colNumber === 9) {
if (colKey === "manualStatus") {
if (val.includes("驳回")) {
cell.font = { name: "Microsoft YaHei", size: 10, color: { argb: "FFDC2626" }, bold: true };
cell.fill = { type: "pattern", pattern: "solid", fgColor: { argb: "FFFEE2E2" } };
@@ -836,12 +863,12 @@ export async function exportApprovalRunsToExcel(
}
// 人工驳回原因字体
if (colNumber === 10 && val !== "-") {
if (colKey === "humanRejectReason" && val !== "-") {
cell.font = { name: "Microsoft YaHei", size: 9, color: { argb: "FF991B1B" } };
}
// E人工行为高亮
if (colNumber === 11) {
if (colKey === "eHumanAction") {
if (val.includes("⚠️") || val.includes("修改")) {
cell.font = { name: "Microsoft YaHei", size: 10, color: { argb: "FFD97706" }, bold: true };
cell.fill = { type: "pattern", pattern: "solid", fgColor: { argb: "FFFEF3C7" } };
@@ -869,7 +896,7 @@ export async function exportApprovalRunsToExcel(
}
// E人工意见字体
if (colNumber === 12 && val !== "-") {
if (colKey === "eHumanComment" && val !== "-") {
cell.font = { name: "Microsoft YaHei", size: 9, color: { argb: "FF334155" } };
}
} else {