主系统 2026-10-13 单边把「我方送过去的单位载体」改成**走待审**(其提交 a0afc585): 单位变了 ⇒ 回 pending(他们的行先不变,审核通过后才写并推 price_qty_decided); 该行已有待审 ⇒ 回 409 pending_exists(原话「再等一轮即可,别重试轰炸」); 补单位(当前为空)仍免审。我方协议不用改,但有两处必须跟上: 1) 409 被我们误记成"提交失败":http.ts 把未分类 4xx 判 rejected ⇒ submitPriceQtyRequest 落 failed ⇒ 设计文 §11.8 的定向补发每轮计 1 次尝试,5 轮(约 50 分钟)后判 abandoned。 修法:api/priceQty.ts 把 409 映射为机器可读的 conflict='pending_exists' 并一路透传; 补发遇到它时保持 waiting 且**把尝试次数退回**(不计重试预算),等那条待审落定后自然补发。 2) 单位载体被审核人驳回时,落定钩子会再发一次同一单位(可能被反复驳回)。 修法:落定钩子把"刚落定的台账行"传给补发;若它是**单位载体**(kind='qty' 且 proposed_qty === before_qty)且结论 rejected ⇒ 意图标 noop、不重发(尊重审核结论; 操作员若仍要改,重新改一次单位即可 = 新的显式意图)。 不误伤(含反证用例):真失败仍按 5 次上限收敛;被驳回的是改量(proposed ≠ before)时单位照常补发。 测试:unitDeferredResend.test.ts 扩到 15 例(新增 ⑪/⑪b/⑫/⑫b/⑬); 服务端 tsc 0 错;全量 26 failed / 2653 passed 与基线持平(唯一差异仍是对方 WIP 的 pickingZoneOrder); 门禁 8 通过 / 1 既定红 / 1 未执行(与改前一致)。 文档:设计文 §11.10(新语义 + 两处追赶 + 补单位/他们的理由/已知边界); 对接清单 §4.5.24 七(我方回执:追赶明细 + 误发待审的处置结果 + 对其 六之补 的确认)。 另:误发待审那条(其请求驳回"成本价 6.5 → 10")——我方镜像价从未跟成 10; 代为驳回时其侧已查不到该 request_id(not_found),我方台账保持待审不变, 按既有 Q6 对账口径宽限期后自动关成 failed(已在回执里写清)。
432 lines
19 KiB
TypeScript
432 lines
19 KiB
TypeScript
import { pool } from '../db';
|
||
import { runWithTenantDataAccess } from './tenantSchemaService';
|
||
import { isEnabled, submitPriceQtyRequest } from './mainSystemPriceQtyRequest';
|
||
import { listActiveBranchCodes } from './platformBranch';
|
||
|
||
/**
|
||
* 单位变更「跳过」的定向补发(2026-10-13,开发者选 A)。
|
||
*
|
||
* 场景(主系统回执 §10.2-3 /= 对接清单 §4.5.23 二-4):
|
||
* 某行有**待审的改量申请**时,我方**不上报单位**(否则会顶掉那条待审改量,见
|
||
* `submitPriceQtyRequest` 的跳过分支)。但「跳过」≠「排队」—— 那条待审若最终被**驳回**,
|
||
* 这次单位变更就**永久丢失**。
|
||
*
|
||
* 本模块把"被跳过的意图"落成一条 `waiting` 记录,等该行改量审核**落定**后**定向补发一次**:
|
||
* ① 记录点:`submitPriceQtyRequest` 跳过分支(`recordDeferredUnitResend`);
|
||
* ② 触发点:`handlePriceQtyDecidedEvent` 尾部(webhook 与 Q6 对账共用该处理器)
|
||
* + 15 分钟清扫 `sweepDeferredUnitResends()`(无决策事件的情形)。
|
||
*
|
||
* 补发形态 = 既有载体(零协议改动):`proposed_qty` = 该行**当前数量(不变)**、`unit` = 该行**当前单位**,
|
||
* `client_request_id = unit-deferred-<意图行 id>`(确定性幂等键 ⇒ 重复触发不会重复上报)。
|
||
*
|
||
* **明确不做**:不在 decided 时"比对双方单位后回推"(主系统管理端改单位不通知我方 ⇒ 会覆盖他们的改动,
|
||
* 见设计文 §11.4-3 / 其 §10.4);不新增 `kind='unit'`;不改我方本地值。
|
||
*
|
||
* 设计文档:docs/design/20261011-跨系统改价改量审核.md §11.8
|
||
*/
|
||
|
||
/** 实际发起补发的次数上限:连试这么多次仍发不出去就放弃并留日志(不无限重试) */
|
||
const MAX_RESEND_ATTEMPTS = 5;
|
||
|
||
export type DeferredUnitIntentStatus = 'waiting' | 'sent' | 'noop' | 'abandoned';
|
||
|
||
export type DeferredUnitIntentRow = {
|
||
id: string;
|
||
branch_code: string;
|
||
prep_id: string;
|
||
main_order_code: string | null;
|
||
our_order_code: string;
|
||
our_order_item_id: string | null;
|
||
before_unit: string;
|
||
target_unit: string;
|
||
status: DeferredUnitIntentStatus;
|
||
attempts: number;
|
||
last_error: string | null;
|
||
deferred_at: string;
|
||
resolved_at: string | null;
|
||
updated_at: string;
|
||
payload: unknown;
|
||
};
|
||
|
||
function trimUnit(value: unknown): string {
|
||
return String(value ?? '').trim();
|
||
}
|
||
|
||
function errText(error: unknown): string {
|
||
return (error as Error)?.message || String(error);
|
||
}
|
||
|
||
/**
|
||
* 记一条"待补发意图"(**跳过单位上报时**调用)。
|
||
*
|
||
* 同一 `(branch_code, prep_id)` 只保留**最新**一条 `waiting`:再次跳过就地刷新 `before_unit`/`target_unit`
|
||
* 并把尝试计数归零(那是一次新的"被跳过的变更"),不会攒出一串过期意图。
|
||
*
|
||
* ⚠️ **绝不抛错**:调用方是订单明细保存链路,"跳过"这个业务结论不能因为留痕失败而变形。
|
||
*/
|
||
export async function recordDeferredUnitResend(params: {
|
||
branchCode: string;
|
||
prepId: string;
|
||
mainOrderCode?: string | null;
|
||
ourOrderCode: string;
|
||
ourOrderItemId?: string | null;
|
||
beforeUnit: string;
|
||
targetUnit: string;
|
||
}): Promise<{ kind: 'recorded' | 'skipped' | 'failed'; reason?: string }> {
|
||
const branchCode = String(params.branchCode || '').trim();
|
||
const prepId = String(params.prepId || '').trim();
|
||
const beforeUnit = trimUnit(params.beforeUnit);
|
||
const targetUnit = trimUnit(params.targetUnit);
|
||
if (!branchCode || !prepId || !params.ourOrderCode) {
|
||
return { kind: 'skipped', reason: '缺少分公司/备货行/本系统单号,无法记录补发意图' };
|
||
}
|
||
if (!targetUnit || targetUnit === beforeUnit) {
|
||
return { kind: 'skipped', reason: '单位没变(或新单位为空),无需补发' };
|
||
}
|
||
try {
|
||
await pool.query(
|
||
`INSERT INTO public.main_system_price_qty_unit_deferred
|
||
(branch_code, prep_id, main_order_code, our_order_code, our_order_item_id,
|
||
before_unit, target_unit, status, payload)
|
||
VALUES ($1,$2,$3,$4,$5::uuid,$6,$7,'waiting',$8::jsonb)
|
||
ON CONFLICT (branch_code, prep_id) WHERE status = 'waiting'
|
||
DO UPDATE SET before_unit = EXCLUDED.before_unit,
|
||
target_unit = EXCLUDED.target_unit,
|
||
main_order_code = COALESCE(EXCLUDED.main_order_code, public.main_system_price_qty_unit_deferred.main_order_code),
|
||
our_order_code = EXCLUDED.our_order_code,
|
||
our_order_item_id = COALESCE(EXCLUDED.our_order_item_id, public.main_system_price_qty_unit_deferred.our_order_item_id),
|
||
attempts = 0,
|
||
last_error = NULL,
|
||
deferred_at = NOW(),
|
||
resolved_at = NULL,
|
||
payload = COALESCE(public.main_system_price_qty_unit_deferred.payload, '{}'::jsonb) || EXCLUDED.payload,
|
||
updated_at = NOW()`,
|
||
[
|
||
branchCode,
|
||
prepId,
|
||
params.mainOrderCode ?? null,
|
||
String(params.ourOrderCode),
|
||
params.ourOrderItemId ?? null,
|
||
beforeUnit,
|
||
targetUnit,
|
||
JSON.stringify({
|
||
deferred: { at: new Date().toISOString(), before_unit: beforeUnit, target_unit: targetUnit },
|
||
}),
|
||
]
|
||
);
|
||
return { kind: 'recorded' };
|
||
} catch (error: unknown) {
|
||
console.error('[unit-deferred] 记录补发意图失败(跳过结论不受影响):', errText(error));
|
||
return { kind: 'failed', reason: errText(error) };
|
||
}
|
||
}
|
||
|
||
async function markIntent(
|
||
id: string,
|
||
status: DeferredUnitIntentStatus,
|
||
fields: { lastError?: string | null; targetUnit?: string | null; attempts?: number } = {}
|
||
): Promise<void> {
|
||
await pool.query(
|
||
`UPDATE public.main_system_price_qty_unit_deferred
|
||
SET status = $2::varchar,
|
||
last_error = $3,
|
||
target_unit = COALESCE($4, target_unit),
|
||
attempts = COALESCE($5, attempts),
|
||
resolved_at = CASE WHEN $2::varchar = 'waiting' THEN NULL ELSE NOW() END,
|
||
updated_at = NOW()
|
||
WHERE id = $1::uuid`,
|
||
[id, status, fields.lastError ?? null, fields.targetUnit ?? null, fields.attempts ?? null]
|
||
);
|
||
}
|
||
|
||
/** 终局(sent/noop/abandoned)留一条操作日志;失败不阻断 */
|
||
async function logResend(params: {
|
||
branchCode: string;
|
||
intent: DeferredUnitIntentRow;
|
||
status: DeferredUnitIntentStatus;
|
||
targetUnit: string | null;
|
||
detail: string;
|
||
trigger: 'decided' | 'sweep';
|
||
}): Promise<void> {
|
||
try {
|
||
const { writeAuditLog } = await import('./auditService');
|
||
await writeAuditLog({
|
||
operatorId: null,
|
||
operatorRole: 'system',
|
||
operationType: 'main_system_price_qty_unit_deferred_resend',
|
||
targetTable: 'order_items',
|
||
targetId: params.intent.our_order_item_id ?? undefined,
|
||
branchCode: params.branchCode,
|
||
actionCategory: 'order',
|
||
ipAddress: null,
|
||
oldValue: { unit: params.intent.before_unit },
|
||
newValue: {
|
||
unit: params.targetUnit,
|
||
status: params.status,
|
||
trigger: params.trigger,
|
||
detail: params.detail,
|
||
intent_row_id: params.intent.id,
|
||
prep_id: params.intent.prep_id,
|
||
our_order_code: params.intent.our_order_code,
|
||
attempts: params.intent.attempts,
|
||
},
|
||
});
|
||
} catch (error: unknown) {
|
||
console.error('[unit-deferred] 写操作日志失败:', errText(error));
|
||
}
|
||
}
|
||
|
||
export type DeferredFlushOutcome = {
|
||
kind: 'none' | 'blocked' | 'noop' | 'sent' | 'waiting' | 'abandoned';
|
||
reason: string;
|
||
/** 补发成功时对应的台账行 id(排障/验收用) */
|
||
requestRowId?: string | null;
|
||
/** 补发成功时台账最终状态(applied/pending/…) */
|
||
requestStatus?: string | null;
|
||
};
|
||
|
||
/**
|
||
* 尝试补发某备货行的单位变更(**幂等**:同一意图重复调用只上报一次)。
|
||
*
|
||
* 三个前提(缺一不补):
|
||
* ① 该行**没有任何 pending 台账行**(**任何 kind**)—— 比原跳过判据更严:不仅防顶掉待审改量,
|
||
* 也防在别人的待审期间制造第二条待审(主系统 pending 分支的 upsert 覆盖风险);
|
||
* ② 我方订单行仍存在,且**当前单位 ≠ 意图的旧单位**(改回/清空 ⇒ `noop`,不必补);
|
||
* ③ 跨系统开关仍是开的。
|
||
*/
|
||
export async function flushDeferredUnitResendForPrep(params: {
|
||
branchCode: string;
|
||
prepId: string;
|
||
trigger: 'decided' | 'sweep';
|
||
/**
|
||
* 刚落定的那条台账行(仅 `trigger='decided'` 时给)。
|
||
*
|
||
* 用途(2026-10-13 追加):主系统已把「子系统改我方单位」改成**走待审** ——
|
||
* 若他们的审核人**驳回**了我们送的单位载体(`kind='qty'` 且 `proposed_qty === before_qty`),
|
||
* 那就是"这条单位变更他们不接受":**不再自动补发**(否则每落定一次就重发一次、被反复驳回)。
|
||
* 尊重审核结论;操作员若仍要改,重新改一次单位即可(那是一次新的显式意图)。
|
||
*/
|
||
justDecided?: {
|
||
status: string;
|
||
kind: string;
|
||
proposedQty: number | string | null;
|
||
beforeQty: number | string | null;
|
||
};
|
||
}): Promise<DeferredFlushOutcome> {
|
||
const branchCode = String(params.branchCode || '').trim();
|
||
const prepId = String(params.prepId || '').trim();
|
||
if (!branchCode || !prepId) return { kind: 'none', reason: '缺少分公司/备货行' };
|
||
if (!isEnabled()) return { kind: 'blocked', reason: '跨系统改价改量未开启,暂不补发' };
|
||
|
||
const found = await pool.query<DeferredUnitIntentRow>(
|
||
`SELECT * FROM public.main_system_price_qty_unit_deferred
|
||
WHERE branch_code = $1 AND prep_id = $2 AND status = 'waiting'
|
||
ORDER BY updated_at DESC LIMIT 1`,
|
||
[branchCode, prepId]
|
||
);
|
||
const intent = found.rows[0];
|
||
if (!intent) return { kind: 'none', reason: '没有待补发意图' };
|
||
|
||
/**
|
||
* 前提⓪(2026-10-13):**刚落定的那条就是"单位载体"且被驳回** ⇒ 不再补发。
|
||
* 判定"单位载体":`kind='qty'` 且 `proposed_qty === before_qty`(数量不变的载体,见设计文 §11.2)。
|
||
*/
|
||
const decided = params.justDecided;
|
||
if (decided && String(decided.status) === 'rejected' && String(decided.kind) === 'qty') {
|
||
const proposed = Number(decided.proposedQty);
|
||
const before = Number(decided.beforeQty);
|
||
const isUnitCarrier =
|
||
Number.isFinite(proposed) &&
|
||
Number.isFinite(before) &&
|
||
Math.abs(proposed - before) < 1e-9;
|
||
if (isUnitCarrier) {
|
||
const reason = '主系统驳回了这次单位变更(审核结论:不予变更)⇒ 不再自动补发';
|
||
await markIntent(intent.id, 'noop', { lastError: reason });
|
||
await logResend({
|
||
branchCode,
|
||
intent,
|
||
status: 'noop',
|
||
targetUnit: null,
|
||
detail: reason,
|
||
trigger: params.trigger,
|
||
});
|
||
return { kind: 'noop', reason };
|
||
}
|
||
}
|
||
|
||
// 前提①:任何 kind 的 pending 都不补(保守;宁可等下一轮清扫)
|
||
const pending = await pool.query(
|
||
`SELECT 1 FROM public.main_system_price_qty_requests
|
||
WHERE branch_code = $1 AND prep_id = $2 AND status = 'pending' LIMIT 1`,
|
||
[branchCode, prepId]
|
||
);
|
||
if (pending.rowCount) {
|
||
return { kind: 'blocked', reason: '该行仍有待审申请(任何 kind),本次不补发' };
|
||
}
|
||
if (!intent.our_order_item_id) {
|
||
await markIntent(intent.id, 'abandoned', { lastError: '意图缺我方订单行 id,无法补发' });
|
||
return { kind: 'abandoned', reason: '意图缺我方订单行 id,无法补发' };
|
||
}
|
||
|
||
// 前提②:读本行当前单位(tenant 隔离:必须走 runWithTenantDataAccess)
|
||
let current: { unit: string | null; quantity: string | number | null } | null = null;
|
||
try {
|
||
const rows = await runWithTenantDataAccess(branchCode, (client) =>
|
||
client.query<{ unit: string | null; quantity: string | number | null }>(
|
||
`SELECT unit, quantity FROM order_items WHERE order_code = $1 AND id = $2::uuid LIMIT 1`,
|
||
[intent.our_order_code, intent.our_order_item_id]
|
||
)
|
||
);
|
||
current = rows.rows[0] ?? null;
|
||
} catch (error: unknown) {
|
||
return { kind: 'blocked', reason: `读取本行失败(下次清扫再试):${errText(error)}` };
|
||
}
|
||
if (!current) {
|
||
await markIntent(intent.id, 'abandoned', { lastError: '我方订单行已不存在' });
|
||
return { kind: 'abandoned', reason: '我方订单行已不存在' };
|
||
}
|
||
const unitNow = trimUnit(current.unit);
|
||
if (!unitNow || unitNow === trimUnit(intent.before_unit)) {
|
||
const reason = unitNow
|
||
? `单位已改回 ${unitNow},无需补发`
|
||
: '本行当前单位为空,无需补发';
|
||
await markIntent(intent.id, 'noop', { lastError: reason });
|
||
await logResend({ branchCode, intent, status: 'noop', targetUnit: unitNow || null, detail: reason, trigger: params.trigger });
|
||
return { kind: 'noop', reason };
|
||
}
|
||
|
||
const attempts = Number(intent.attempts || 0) + 1;
|
||
if (attempts > MAX_RESEND_ATTEMPTS) {
|
||
const reason = `补发连续失败 ${MAX_RESEND_ATTEMPTS} 次,停止自动补发,需人工处理`;
|
||
await markIntent(intent.id, 'abandoned', { lastError: intent.last_error || reason });
|
||
await logResend({ branchCode, intent, status: 'abandoned', targetUnit: unitNow, detail: reason, trigger: params.trigger });
|
||
return { kind: 'abandoned', reason };
|
||
}
|
||
// 先记一次尝试(崩溃/异常也不会无限重试),并顺手把目标单位刷成最新
|
||
await markIntent(intent.id, 'waiting', { attempts, targetUnit: unitNow, lastError: intent.last_error ?? null });
|
||
|
||
const outcome = await submitPriceQtyRequest({
|
||
branchCode,
|
||
ourOrderCode: intent.our_order_code,
|
||
ourOrderItemId: intent.our_order_item_id,
|
||
// 只报"单位":数量维度都不传 ⇒ 判为"只改单位" ⇒ 自动带"数量不变"的载体
|
||
proposedUnit: unitNow,
|
||
beforeUnit: intent.before_unit,
|
||
reason: `单位变更补报(改量审核已落定):${intent.before_unit || '—'} → ${unitNow}`,
|
||
actor: { userId: null, roles: 'system', requestedBy: 'system:unit-deferred-resend' },
|
||
// 确定性幂等键:重复触发命中台账唯一键 ⇒ 返回既有申请,不重复上报
|
||
clientRequestId: `unit-deferred-${intent.id}`,
|
||
});
|
||
const detail =
|
||
outcome.kind === 'ok'
|
||
? `${outcome.message || '已补报主系统'}(台账 ${outcome.status})`
|
||
: (outcome as { reason?: string }).reason || outcome.kind;
|
||
|
||
if (outcome.kind === 'ok') {
|
||
await markIntent(intent.id, 'sent', { lastError: null });
|
||
await logResend({ branchCode, intent, status: 'sent', targetUnit: unitNow, detail, trigger: params.trigger });
|
||
return { kind: 'sent', reason: detail, requestRowId: outcome.row?.id ?? null, requestStatus: outcome.status ?? null };
|
||
}
|
||
if (outcome.kind === 'invalid' || outcome.kind === 'not_main_system_order') {
|
||
// 结构性失败:重试也不会变好 ⇒ 放弃并留痕
|
||
await markIntent(intent.id, 'abandoned', { lastError: detail });
|
||
await logResend({ branchCode, intent, status: 'abandoned', targetUnit: unitNow, detail, trigger: params.trigger });
|
||
return { kind: 'abandoned', reason: detail };
|
||
}
|
||
/**
|
||
* 409 `pending_exists`(2026-10-13):该行**已有别的待审** ⇒ 对方明确要求"再等一轮,别重试轰炸"。
|
||
* ⇒ 保持 `waiting` 但**把这次尝试次数退回去**(不进重试预算),否则 5 轮(约 50 分钟)就会被判放弃、
|
||
* 单位变更被静默丢弃。等那条待审落定后下一轮自然补发。
|
||
*/
|
||
const conflict = (outcome as { conflict?: string }).conflict;
|
||
if (conflict === 'pending_exists' || /pending_exists/i.test(detail)) {
|
||
await markIntent(intent.id, 'waiting', {
|
||
attempts: Number(intent.attempts || 0), // 退回:不计入重试预算
|
||
lastError: detail,
|
||
targetUnit: unitNow,
|
||
});
|
||
return { kind: 'waiting', reason: `该行仍有别的待审(pending_exists),等一轮再补发:${detail}` };
|
||
}
|
||
if (outcome.kind === 'no_change' && !/待审核的改量/.test(detail)) {
|
||
// 既不是"又被待审挡住",也不是真的没变(单位刚被改回去) ⇒ 视为不必补发
|
||
await markIntent(intent.id, 'noop', { lastError: detail });
|
||
await logResend({ branchCode, intent, status: 'noop', targetUnit: unitNow, detail, trigger: params.trigger });
|
||
return { kind: 'noop', reason: detail };
|
||
}
|
||
// 其余(又被待审挡住 / 主系统暂不可用 / 提交失败 / 被驳回)⇒ 保持 waiting,等下一轮
|
||
await markIntent(intent.id, 'waiting', { attempts, lastError: detail, targetUnit: unitNow });
|
||
if (attempts >= MAX_RESEND_ATTEMPTS) {
|
||
const reason = `补发连续失败 ${attempts} 次,停止自动补发,需人工处理:${detail}`;
|
||
await markIntent(intent.id, 'abandoned', { lastError: reason, attempts });
|
||
await logResend({ branchCode, intent, status: 'abandoned', targetUnit: unitNow, detail: reason, trigger: params.trigger });
|
||
return { kind: 'abandoned', reason };
|
||
}
|
||
return { kind: 'waiting', reason: detail };
|
||
}
|
||
|
||
export type DeferredResendSweepResult = {
|
||
branches: number;
|
||
scanned: number;
|
||
sent: number;
|
||
blocked: number;
|
||
noop: number;
|
||
abandoned: number;
|
||
waiting: number;
|
||
};
|
||
|
||
/**
|
||
* 15 分钟清扫:把所有 `waiting` 意图里"已无阻塞"的补发掉。
|
||
*
|
||
* 覆盖"没有决策事件"的情形:待审行被对账判 `failed` 关闭(主系统侧已无此申请)、
|
||
* 我方台账由 qty 之外的路径落定、或落定事件漏推(Q6 对账之外仍失败)等。
|
||
*/
|
||
export async function sweepDeferredUnitResends(params?: { limit?: number }): Promise<DeferredResendSweepResult> {
|
||
const result: DeferredResendSweepResult = {
|
||
branches: 0,
|
||
scanned: 0,
|
||
sent: 0,
|
||
blocked: 0,
|
||
noop: 0,
|
||
abandoned: 0,
|
||
waiting: 0,
|
||
};
|
||
if (!isEnabled()) return result;
|
||
const limit = Math.max(1, Math.min(500, Number(params?.limit ?? 200)));
|
||
let branches: string[] = [];
|
||
try {
|
||
branches = await listActiveBranchCodes();
|
||
} catch (error: unknown) {
|
||
console.error('[unit-deferred] 清扫取分公司失败:', errText(error));
|
||
return result;
|
||
}
|
||
result.branches = branches.length;
|
||
for (const branchCode of branches) {
|
||
try {
|
||
const rows = await pool.query<{ prep_id: string }>(
|
||
`SELECT prep_id FROM public.main_system_price_qty_unit_deferred
|
||
WHERE branch_code = $1 AND status = 'waiting'
|
||
ORDER BY updated_at ASC LIMIT $2`,
|
||
[branchCode, limit]
|
||
);
|
||
for (const row of rows.rows) {
|
||
const prepId = String(row.prep_id || '');
|
||
if (!prepId) continue;
|
||
result.scanned += 1;
|
||
try {
|
||
const outcome = await flushDeferredUnitResendForPrep({ branchCode, prepId, trigger: 'sweep' });
|
||
if (outcome.kind === 'sent') result.sent += 1;
|
||
else if (outcome.kind === 'noop') result.noop += 1;
|
||
else if (outcome.kind === 'abandoned') result.abandoned += 1;
|
||
else if (outcome.kind === 'blocked') result.blocked += 1;
|
||
else if (outcome.kind === 'waiting') result.waiting += 1;
|
||
} catch (error: unknown) {
|
||
console.error(`[unit-deferred] 补发失败(${branchCode}/${prepId}):`, errText(error));
|
||
}
|
||
}
|
||
} catch (error: unknown) {
|
||
console.error(`[unit-deferred] 清扫失败(${branchCode}):`, errText(error));
|
||
}
|
||
}
|
||
return result;
|
||
}
|