feat(bill): support full invoice validation details, datalink cards, and department paths (v0.7.3)
This commit is contained in:
1 parent
5e06429d6c
commit
a8e32cff32
12 files changed
+313
-56
No files matched your search
+117
-8
@@ -18,6 +18,8 @@ import {
|
||||
transferBillAction,
|
||||
addNodeBillAction,
|
||||
commentBillAction,
|
||||
getInvoiceValidationDetail,
|
||||
getDatalinkCard,
|
||||
type BillActionOptions,
|
||||
type BillActionTarget,
|
||||
} from "./api.js";
|
||||
@@ -1274,13 +1276,15 @@ export const billTools = [
|
||||
|
||||
export async function getTranslatorContext(
|
||||
client: KyInstance,
|
||||
corpId: string
|
||||
corpId: string,
|
||||
rawFlow?: Record<string, unknown>
|
||||
): Promise<TranslatorOptions> {
|
||||
const [feeTypeTree, catalog, dimEntity, dimBiz] = await Promise.allSettled([
|
||||
const [feeTypeTree, catalog, dimEntity, dimBiz, dimBool] = await Promise.allSettled([
|
||||
getFeeTypeTree(client, corpId),
|
||||
getReferenceCatalog(client, corpId),
|
||||
resolveDimension(client, corpId, "法人实体"),
|
||||
resolveDimension(client, corpId, "业务类型"),
|
||||
resolveDimension(client, corpId, "是否"),
|
||||
]);
|
||||
|
||||
const feeTypeMap = new Map<string, { name?: string; path?: string }>();
|
||||
@@ -1295,15 +1299,118 @@ export async function getTranslatorContext(
|
||||
const departmentMap = catalog.status === "fulfilled" ? catalog.value.departments : undefined;
|
||||
|
||||
const dimensionItemMap = new Map<string, { name?: string; code?: string; label?: string }>();
|
||||
if (dimEntity.status === "fulfilled" && dimEntity.value?.items) {
|
||||
for (const item of dimEntity.value.items) {
|
||||
dimensionItemMap.set(item.id, { name: item.name, code: item.code });
|
||||
for (const dimRes of [dimEntity, dimBiz, dimBool]) {
|
||||
if (dimRes.status === "fulfilled" && dimRes.value?.items) {
|
||||
for (const item of dimRes.value.items) {
|
||||
dimensionItemMap.set(item.id, { name: item.name, code: item.code });
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimBiz.status === "fulfilled" && dimBiz.value?.items) {
|
||||
for (const item of dimBiz.value.items) {
|
||||
dimensionItemMap.set(item.id, { name: item.name, code: item.code });
|
||||
|
||||
const invoiceDetailMap = new Map<string, Record<string, unknown>>();
|
||||
const datalinkCardMap = new Map<string, string>();
|
||||
|
||||
if (rawFlow) {
|
||||
const flowIdObj = (rawFlow.flowId && typeof rawFlow.flowId === "object" ? rawFlow.flowId : rawFlow) as Record<string, any>;
|
||||
const form = (flowIdObj.form && typeof flowIdObj.form === "object" ? flowIdObj.form : {}) as Record<string, any>;
|
||||
|
||||
// 1. 扫描所有发票 invoiceId
|
||||
const invoiceIds = new Set<string>();
|
||||
const details = Array.isArray(form.details) ? form.details : [];
|
||||
for (const d of details) {
|
||||
const ftf = d?.feeTypeForm || d || {};
|
||||
const invs = ftf.invoiceForm?.invoices || ftf.invoices || [];
|
||||
if (Array.isArray(invs)) {
|
||||
for (const inv of invs) {
|
||||
const id = inv.invoiceId || inv.id;
|
||||
if (typeof id === "string" && id) invoiceIds.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const invoiceFetches = Array.from(invoiceIds).map(async (id) => {
|
||||
const detail = await getInvoiceValidationDetail(client, corpId, id);
|
||||
if (detail) invoiceDetailMap.set(id, detail);
|
||||
});
|
||||
|
||||
// 2. 扫描数据连接/卡片 ID (例如供应商 ID01...,payeeId 等)
|
||||
const cardCandidateIds = new Set<string>();
|
||||
for (const [_, v] of Object.entries(form)) {
|
||||
if (typeof v === "string" && v.startsWith("ID01")) {
|
||||
if (!dimensionItemMap.has(v)) {
|
||||
cardCandidateIds.add(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const cardFetches = Array.from(cardCandidateIds).map(async (cardId) => {
|
||||
const cardVal = await getDatalinkCard(client, corpId, cardId);
|
||||
const cardObj = (cardVal?.data as any)?.dataLink || (cardVal?.data as any)?.form || cardVal?.data;
|
||||
if (cardObj && typeof cardObj === "object") {
|
||||
const parts: string[] = [];
|
||||
let suppName = "";
|
||||
let suppCode = "";
|
||||
let bankCard = "";
|
||||
let payeeInfoStr = "";
|
||||
let payeeInfoDirect = "";
|
||||
|
||||
for (const [fieldKey, fieldVal] of Object.entries(cardObj)) {
|
||||
if (fieldKey.endsWith("_name") || fieldKey.includes("供应商名称")) {
|
||||
suppName = String(fieldVal);
|
||||
} else if (fieldKey.endsWith("_code") || fieldKey.includes("供应商编码")) {
|
||||
suppCode = String(fieldVal);
|
||||
} else if (fieldKey.includes("银行卡号") || fieldKey.includes("卡号")) {
|
||||
bankCard = String(fieldVal);
|
||||
} else if (fieldKey.includes("收款信息") && typeof fieldVal === "object" && fieldVal !== null) {
|
||||
const pi = fieldVal as Record<string, any>;
|
||||
const piParts: string[] = [];
|
||||
const directParts: string[] = [];
|
||||
const accountName = pi.name || pi.accountName || pi.accountOwner;
|
||||
const accountNo = pi.cardNo || pi.account;
|
||||
const accountType = (pi.type || pi.accountType) === "PUBLIC" ? "对公账户" : (pi.type || pi.accountType);
|
||||
const accountSort = pi.sort || pi.accountCategory || pi.accountClass;
|
||||
const bankName = pi.bank || pi.bankName;
|
||||
const branchName = pi.branch || pi.openBankName;
|
||||
|
||||
if (accountName) piParts.push(`开户名=${accountName}`);
|
||||
if (accountNo) piParts.push(`账号=${accountNo}`);
|
||||
if (accountType) piParts.push(`账户类型=${accountType}`);
|
||||
if (accountSort) piParts.push(`账户类别=${accountSort}`);
|
||||
if (bankName) piParts.push(`银行=${bankName}`);
|
||||
if (branchName) piParts.push(`开户网点=${branchName}`);
|
||||
if (piParts.length > 0) {
|
||||
payeeInfoStr = piParts.join(";");
|
||||
}
|
||||
|
||||
if (accountNo) directParts.push(`账号=${accountNo}`);
|
||||
if (bankName) directParts.push(`银行=${bankName}`);
|
||||
if (accountName) directParts.push(`开户名=${accountName}`);
|
||||
if (branchName) directParts.push(`开户网点=${branchName}`);
|
||||
if (accountType) directParts.push(`账户类型=${accountType}`);
|
||||
if (accountSort) directParts.push(`账户类别=${accountSort}`);
|
||||
if (directParts.length > 0) {
|
||||
payeeInfoDirect = directParts.join(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (suppName) parts.push(`供应商名称=${suppName}`);
|
||||
if (suppCode) parts.push(`供应商编码=${suppCode}`);
|
||||
if (bankCard) parts.push(`银行卡号=${bankCard}`);
|
||||
if (payeeInfoStr) parts.push(`收款信息=${payeeInfoStr}`);
|
||||
|
||||
if (parts.length > 0) {
|
||||
datalinkCardMap.set(cardId, parts.join(";"));
|
||||
}
|
||||
if (payeeInfoDirect || payeeInfoStr) {
|
||||
const valToSet = payeeInfoDirect || payeeInfoStr;
|
||||
datalinkCardMap.set(`payeeInfo:${cardId}`, valToSet);
|
||||
if (suppCode) datalinkCardMap.set(suppCode, valToSet);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.allSettled([...invoiceFetches, ...cardFetches]);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -1311,6 +1418,8 @@ export async function getTranslatorContext(
|
||||
staffMap,
|
||||
departmentMap,
|
||||
dimensionItemMap,
|
||||
invoiceDetailMap,
|
||||
datalinkCardMap,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user