feat(bill): resolve archive references in bill details

This commit is contained in:
gitea committed 2026-09-05 20:20:40 +08:00
1 parent 1d1170526b
commit 96d28da862
5 files changed
+34 -3

No files matched your search

+1
View File
@@ -318,6 +318,7 @@ export async function handleBillCommand(
`费用承担部门: ${report.department?.path || report.department?.name || "-"}${report.department?.id ? ` [${report.department.id}]` : ""}`,
`法人实体: ${report.legalEntity ? `${report.legalEntity.name || "未解析"}${report.legalEntity.id ? ` [${report.legalEntity.id}]` : ""}` : "-"}`,
`费用类型: ${report.feeTypes.length ? report.feeTypes.map((item) => `${item.name || "未解析"}${item.code ? ` (${item.code})` : ""} [${item.id}]`).join("、") : "-"}`,
`核算维度: ${report.dimensions.length ? report.dimensions.map((item) => `${item.name || "未解析"}${item.code ? ` (${item.code})` : ""} [${item.id}]`).join("、") : "-"}`,
report.unresolved.length ? `未解析 ID: ${report.unresolved.join("、")}` : "引用均已解析",
"",
].join("\n");
+3
View File
@@ -92,6 +92,9 @@ export async function getRawBillFlow(
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",
+27 -1
View File
@@ -30,6 +30,7 @@ import {
} from "./types.js";
import { CorpContext } from "../../core/config/manager.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { resolveDimension } from "../dimension/tools.js";
// ── 通用内置字段中文 Label 字典 ───────────────────────────────────────────────
@@ -245,7 +246,16 @@ export async function getBillReferences(
if (departmentId && !department?.name) unresolved.push(departmentId);
const legalEntityValue = form.legalEntity;
const legalEntity = toReference(legalEntityValue, "legalEntity", "joined");
const submitterObject = referenceObject(form.submitterId);
const submitterLegalEntity = submitterObject?.defaultDepartment && typeof submitterObject.defaultDepartment === "object"
? referenceObject(submitterObject.defaultDepartment)?.form && typeof referenceObject(submitterObject.defaultDepartment)?.form === "object"
? (referenceObject(submitterObject.defaultDepartment)?.form as Record<string, unknown>).legalEntity
: undefined
: undefined;
const legalEntityId = referenceId(legalEntityValue) || referenceId(submitterLegalEntity);
const legalEntityCatalog = legalEntityId ? await resolveDimension(client, corpId, "FRST") : undefined;
const legalEntityItem = legalEntityCatalog?.items.find((item) => item.id === legalEntityId || item.id.endsWith(`:${legalEntityId}`));
const legalEntity = toReference(legalEntityValue || submitterLegalEntity || legalEntityId, "legalEntity", legalEntityItem ? "catalog" : "joined", legalEntityItem as unknown as Record<string, unknown> | undefined);
if (referenceId(legalEntityValue) && !legalEntity?.name) unresolved.push(referenceId(legalEntityValue)!);
const feeTypes = [...collectFeeTypeIds(form)].map((id) => {
@@ -255,6 +265,21 @@ export async function getBillReferences(
return reference;
}).filter((item): item is BillReference => Boolean(item));
const dimensions: BillReference[] = [];
const dimensionTargets: Array<[RegExp, string]> = [[/project|项目/i, "DA001"], [/cost.?center|成本中心/i, "costCenter"]];
for (const [keyPattern, dimensionCode] of dimensionTargets) {
for (const [key, value] of Object.entries(form)) {
if (!keyPattern.test(key)) continue;
const id = referenceId(value);
if (!id) continue;
const resolved = await resolveDimension(client, corpId, dimensionCode);
const item = resolved?.items.find((entry) => entry.id === id || entry.id.endsWith(`:${id}`));
const reference = toReference(value, "dimension", item ? "catalog" : "raw", item as unknown as Record<string, unknown> | undefined);
if (reference) dimensions.push(reference);
if (!reference?.name) unresolved.push(id);
}
}
return {
target,
billId: typeof raw.id === "string" ? raw.id : undefined,
@@ -265,6 +290,7 @@ export async function getBillReferences(
department,
legalEntity,
feeTypes,
dimensions,
unresolved: [...new Set(unresolved)],
raw: { form },
};
+2 -1
View File
@@ -163,7 +163,7 @@ export interface BillReference {
name?: string;
code?: string;
path?: string;
kind: "staff" | "department" | "feeType" | "legalEntity" | "unknown";
kind: "staff" | "department" | "feeType" | "legalEntity" | "dimension" | "unknown";
source: "joined" | "catalog" | "raw";
}
@@ -177,6 +177,7 @@ export interface BillReferenceReport {
department?: BillReference;
legalEntity?: BillReference;
feeTypes: BillReference[];
dimensions: BillReference[];
unresolved: string[];
raw: Record<string, unknown>;
}