fix(bill): resolve bills outside the caller's own flow list
根因:flows/my 按当前凭证身份返回“我发起”的单据,系统或其他员工创建的单据不在其中, 导致 bill get 返回 NOT FOUND(测试企业 B26000012/B26000017 复现)。 修复:新增企业级通道 POST /api/flow/v2/flows/searchByCode 兜底, 命中后再拉一次完整详情,保证表头字段齐全。
This commit is contained in:
1 parent
782466ad80
commit
258b347d4d
2 files changed
+79
-49
No files matched your search
@@ -172,6 +172,36 @@ export async function getRawBillFlow(
|
||||
}
|
||||
}
|
||||
|
||||
// 通道 0.5: 企业级按单号索引(跨身份,不依赖 flows/my 的“我发起”范围)
|
||||
// 部分单据由系统或其他员工创建,当前凭证身份在 flows/my 中不可见,但 searchByCode 可查。
|
||||
try {
|
||||
const res = await client.post("api/flow/v2/flows/searchByCode", {
|
||||
searchParams: { corpId },
|
||||
json: {},
|
||||
});
|
||||
const json = (await res.json()) as { items?: Record<string, unknown>[] };
|
||||
const item = (json.items ?? []).find((it) => {
|
||||
const form = (it.form && typeof it.form === "object" ? it.form : {}) as Record<string, unknown>;
|
||||
return it.id === cleanTarget || form.code === cleanTarget;
|
||||
});
|
||||
if (item) {
|
||||
const flowId = typeof item.id === "string" ? item.id : undefined;
|
||||
// searchByCode 返回的是精简表单(可能缺收款信息/部门等表头字段),
|
||||
// 命中后统一再拉一次完整详情,保证 bill get / bill validate 拿到的字段齐全。
|
||||
if (flowId) {
|
||||
const detail = await client.post(`api/flow/v1/flows/flowId/$${flowId}`, {
|
||||
searchParams: { id: flowId, corpId },
|
||||
json: { filterBy: `(id==${quoted(flowId)})`, select: "id,state,form,logs" },
|
||||
});
|
||||
const detailJson = (await detail.json()) as { value?: Record<string, unknown> };
|
||||
if (detailJson.value) return { flowId: detailJson.value };
|
||||
}
|
||||
return { flowId: item };
|
||||
}
|
||||
} catch {
|
||||
// 通道 0.5 失败时继续走既有回溯通道
|
||||
}
|
||||
|
||||
const backlogId = typeof match?.id === "string" ? match.id : cleanTarget;
|
||||
const flowIdFromMatch = match?.flowId && typeof match.flowId === "object" && typeof (match.flowId as any).id === "string"
|
||||
? (match.flowId as any).id
|
||||
|
||||
Reference in new issue
Block a user