diff --git a/skills/hose-use/references/bill.md b/skills/hose-use/references/bill.md index 5848014..49de610 100644 --- a/skills/hose-use/references/bill.md +++ b/skills/hose-use/references/bill.md @@ -70,7 +70,7 @@ hose bill refs S26000001 hose bill refs S26000001 --json ``` -JSON 输出包含 `submitter`、`owner`、`department`、`legalEntity`、`feeTypes` 和 `unresolved`。目录在当前进程内按企业缓存 10 分钟,避免对同一企业重复拉取。 +JSON 输出包含 `submitter`、`owner`、`department`、`legalEntity`、`feeTypes`、`dimensions` 和 `unresolved`。单据里出现法人实体、项目或成本中心 ID 时,会联动 `dimension` 目录补充名称与编码;目录在当前进程内按企业缓存 10 分钟。 ### 单据关联链 (`bill relations`) diff --git a/src/cli/commands/bill.ts b/src/cli/commands/bill.ts index 84036e1..9ff35e3 100644 --- a/src/cli/commands/bill.ts +++ b/src/cli/commands/bill.ts @@ -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"); diff --git a/src/domains/bill/api.ts b/src/domains/bill/api.ts index 5ceb099..27f2d09 100644 --- a/src/domains/bill/api.ts +++ b/src/domains/bill/api.ts @@ -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", diff --git a/src/domains/bill/tools.ts b/src/domains/bill/tools.ts index 9935401..d94e326 100644 --- a/src/domains/bill/tools.ts +++ b/src/domains/bill/tools.ts @@ -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).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 | 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 | 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 }, }; diff --git a/src/domains/bill/types.ts b/src/domains/bill/types.ts index fe7d734..151bb7d 100644 --- a/src/domains/bill/types.ts +++ b/src/domains/bill/types.ts @@ -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; }