feat(bill,flow): add unified bill trace and flow get diagnostic engine (Phase 2)
This commit is contained in:
1 parent
7891959853
commit
ffec604ed9
10 files changed
+970
-32
No files matched your search
+73
-27
@@ -63,12 +63,16 @@ export async function getRawBillFlow(
|
||||
corpId: string,
|
||||
target: string
|
||||
): Promise<Record<string, unknown> | undefined> {
|
||||
const cleanTarget = target.trim();
|
||||
let match: Record<string, unknown> | undefined;
|
||||
const filters = [
|
||||
`(id==${quoted(target)})||((flowId.id==${quoted(target)})||(flowId.form.code==${quoted(target)}))`,
|
||||
|
||||
// 通道 1: api/flow/v2/backlogs/search 精准单号与 ID 匹配
|
||||
const searchFilters = [
|
||||
`(id==${quoted(cleanTarget)})||((flowId.id==${quoted(cleanTarget)})||(flowId.form.code==${quoted(cleanTarget)}))`,
|
||||
`(flowId.form.code==${quoted(cleanTarget)})`,
|
||||
`(state.in("APPROVING","PROCESSED","REJECTED","DRAFT"))`,
|
||||
];
|
||||
for (const filterBy of filters) {
|
||||
for (const filterBy of searchFilters) {
|
||||
try {
|
||||
const lookup = await client.post("api/flow/v2/backlogs/search", {
|
||||
searchParams: { corpId },
|
||||
@@ -82,36 +86,78 @@ export async function getRawBillFlow(
|
||||
match = (lookupJson.items ?? []).find((item) => {
|
||||
const flow = item.flowId && typeof item.flowId === "object" ? item.flowId as Record<string, unknown> : {};
|
||||
const form = flow.form && typeof flow.form === "object" ? flow.form as Record<string, unknown> : {};
|
||||
return item.id === target || flow.id === target || form.code === target;
|
||||
return item.id === cleanTarget || flow.id === cleanTarget || form.code === cleanTarget;
|
||||
});
|
||||
if (match) break;
|
||||
} catch {
|
||||
// Fall through to the broad status lookup or direct detail request.
|
||||
// 继续尝试其他检索
|
||||
}
|
||||
}
|
||||
const backlogId = typeof match?.id === "string" ? match.id : target;
|
||||
|
||||
const detail = await client.post("api/flow/v2/backlogs/id", {
|
||||
searchParams: (() => {
|
||||
const params = new URLSearchParams({ corpId });
|
||||
for (const join of [
|
||||
"flowId.form.submitterId,submitterId,/v1/organization/staffs?join=defaultDepartment,defaultDepartment,/v1/organization/departments",
|
||||
"flowId.form.ownerId,ownerId,/v1/organization/staffs?select=id,name,code",
|
||||
"flowId.form.expenseDepartment,expenseDepartment,/v1/organization/departments",
|
||||
"flowId.logs.operatorId,operatorId,/v1/organization/staffs?select=id,name,code",
|
||||
"flowId.logs.nextOperatorId,nextOperatorId,/v1/organization/staffs?select=id,name,code",
|
||||
"flowId.plan.nodes.approverId,approverId,/v1/organization/staffs?select=id,name,code",
|
||||
"flowId.plan.nodes.counterSigners.signerId,signerId,/v1/organization/staffs?select=id,name,code",
|
||||
]) params.append("join", join);
|
||||
return params;
|
||||
})(),
|
||||
json: {
|
||||
filterBy: `(id==${quoted(backlogId)})`,
|
||||
select: flowDetailSelect(),
|
||||
},
|
||||
});
|
||||
const json = (await detail.json()) as { value?: Record<string, unknown>; items?: Record<string, unknown>[] };
|
||||
return json.value ?? json.items?.[0];
|
||||
// 通道 2: 尝试从我发起的流程与已审批单据中检索 (flows/my & flows/approved)
|
||||
if (!match) {
|
||||
const endpoints = ["api/flow/v1/flows/my", "api/flow/v1/flows/approved", "api/flow/v2/carbonCopy/search"];
|
||||
for (const ep of endpoints) {
|
||||
try {
|
||||
const res = await client.post(ep, {
|
||||
searchParams: { corpId },
|
||||
json: {
|
||||
limit: { start: 0, count: 50 },
|
||||
filterBy: `(form.code==${quoted(cleanTarget)})||(flowId.form.code==${quoted(cleanTarget)})`,
|
||||
},
|
||||
});
|
||||
const json = (await res.json()) as { items?: Record<string, unknown>[] };
|
||||
const found = (json.items ?? []).find((item) => {
|
||||
const flow = item.flowId && typeof item.flowId === "object" ? item.flowId as Record<string, unknown> : {};
|
||||
const form = (flow.form ?? item.form) as Record<string, unknown> | undefined;
|
||||
return item.id === cleanTarget || flow.id === cleanTarget || form?.code === cleanTarget;
|
||||
});
|
||||
if (found) {
|
||||
match = found;
|
||||
break;
|
||||
}
|
||||
} catch {
|
||||
// 忽略通道异常
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
: undefined;
|
||||
|
||||
// 通道 3: 调用 api/flow/v2/backlogs/id 获取完整结构化详情
|
||||
try {
|
||||
const filterByCond = flowIdFromMatch
|
||||
? `(id==${quoted(backlogId)})||(flowId.id==${quoted(flowIdFromMatch)})`
|
||||
: `(id==${quoted(backlogId)})||((flowId.id==${quoted(cleanTarget)})||(flowId.form.code==${quoted(cleanTarget)}))`;
|
||||
|
||||
const detail = await client.post("api/flow/v2/backlogs/id", {
|
||||
searchParams: (() => {
|
||||
const params = new URLSearchParams({ corpId });
|
||||
for (const join of [
|
||||
"flowId.form.submitterId,submitterId,/v1/organization/staffs?join=defaultDepartment,defaultDepartment,/v1/organization/departments",
|
||||
"flowId.form.ownerId,ownerId,/v1/organization/staffs?select=id,name,code",
|
||||
"flowId.form.expenseDepartment,expenseDepartment,/v1/organization/departments",
|
||||
"flowId.logs.operatorId,operatorId,/v1/organization/staffs?select=id,name,code",
|
||||
"flowId.logs.nextOperatorId,nextOperatorId,/v1/organization/staffs?select=id,name,code",
|
||||
"flowId.plan.nodes.approverId,approverId,/v1/organization/staffs?select=id,name,code",
|
||||
"flowId.plan.nodes.counterSigners.signerId,signerId,/v1/organization/staffs?select=id,name,code",
|
||||
]) params.append("join", join);
|
||||
return params;
|
||||
})(),
|
||||
json: {
|
||||
filterBy: filterByCond,
|
||||
select: flowDetailSelect(),
|
||||
},
|
||||
});
|
||||
const json = (await detail.json()) as { value?: Record<string, unknown>; items?: Record<string, unknown>[] };
|
||||
return json.value ?? json.items?.[0] ?? match;
|
||||
} catch (err) {
|
||||
if (match) return match;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export interface BillActionTarget {
|
||||
|
||||
Reference in new issue
Block a user