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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hose-use",
|
"name": "hose-use",
|
||||||
"version": "0.7.2",
|
"version": "0.7.3",
|
||||||
"description": "合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号登录、企业租户切换、单据明细检索、工作流管理、内置 HTTP 服务与常驻守护进程。",
|
"description": "合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号登录、企业租户切换、单据明细检索、工作流管理、内置 HTTP 服务与常驻守护进程。",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "yingqing"
|
"name": "yingqing"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# hose-use (v0.7.2)
|
# hose-use (v0.7.3)
|
||||||
|
|
||||||
合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。
|
合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"openapi": "3.1.0",
|
"openapi": "3.1.0",
|
||||||
"info": {
|
"info": {
|
||||||
"title": "hose-use API & MCP Tools Specification",
|
"title": "hose-use API & MCP Tools Specification",
|
||||||
"version": "0.7.2",
|
"version": "0.7.3",
|
||||||
"description": "Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows."
|
"description": "Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows."
|
||||||
},
|
},
|
||||||
"servers": [
|
"servers": [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
openapi: 3.1.0
|
openapi: 3.1.0
|
||||||
info:
|
info:
|
||||||
title: hose-use API & MCP Tools Specification
|
title: hose-use API & MCP Tools Specification
|
||||||
version: 0.7.2
|
version: 0.7.3
|
||||||
description: >-
|
description: >-
|
||||||
Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows.
|
Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows.
|
||||||
servers:
|
servers:
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hose-use",
|
"name": "hose-use",
|
||||||
"version": "0.7.2",
|
"version": "0.7.3",
|
||||||
"module": "src/server.ts",
|
"module": "src/server.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ console.log("✓ Updated README.md");
|
|||||||
const skillPath = join(ROOT, "skills", "hose-use", "SKILL.md");
|
const skillPath = join(ROOT, "skills", "hose-use", "SKILL.md");
|
||||||
let skillContent = readFileSync(skillPath, "utf-8");
|
let skillContent = readFileSync(skillPath, "utf-8");
|
||||||
skillContent = skillContent.replace(/# hose-use \(v[\d.]+\)/g, `# hose-use (v${nextVersion})`);
|
skillContent = skillContent.replace(/# hose-use \(v[\d.]+\)/g, `# hose-use (v${nextVersion})`);
|
||||||
|
skillContent = skillContent.replace(/v[\d.]+: 合思/g, `v${nextVersion}: 合思`);
|
||||||
|
skillContent = skillContent.replace(/version: [\d.]+/g, `version: ${nextVersion}`);
|
||||||
|
skillContent = skillContent.replace(/\(v[\d.]+\)/g, `(v${nextVersion})`);
|
||||||
writeFileSync(skillPath, skillContent);
|
writeFileSync(skillPath, skillContent);
|
||||||
console.log("✓ Updated skills/hose-use/SKILL.md");
|
console.log("✓ Updated skills/hose-use/SKILL.md");
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
name: hose-use
|
name: hose-use
|
||||||
description: "v0.7.2: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。"
|
description: "v0.7.3: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。"
|
||||||
metadata:
|
metadata:
|
||||||
version: 0.7.2
|
version: 0.7.3
|
||||||
short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.7.2)
|
short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.7.3)
|
||||||
---
|
---
|
||||||
|
|
||||||
# hose-use (v0.7.2)
|
# hose-use (v0.7.3)
|
||||||
|
|
||||||
在具备 MCP 的 AI 智能体环境中,**优先使用 `hose_cli` 单工具网关**,传入 `command: string` 执行;在终端或自动化脚本中,直接调用全局 `hose` 或 `hose-use` 命令行。
|
在具备 MCP 的 AI 智能体环境中,**优先使用 `hose_cli` 单工具网关**,传入 `command: string` 执行;在终端或自动化脚本中,直接调用全局 `hose` 或 `hose-use` 命令行。
|
||||||
本 Skill 是智能体的路由分发层:保持主文档简明,遇到复杂业务时深入查阅对应的专属参考文档(`references/*.md`)。
|
本 Skill 是智能体的路由分发层:保持主文档简明,遇到复杂业务时深入查阅对应的专属参考文档(`references/*.md`)。
|
||||||
|
|||||||
+2
-2
@@ -164,7 +164,7 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
|||||||
const flowIdObj = (raw.flowId && typeof raw.flowId === "object" ? raw.flowId : raw) as Record<string, any>;
|
const flowIdObj = (raw.flowId && typeof raw.flowId === "object" ? raw.flowId : raw) as Record<string, any>;
|
||||||
const form = (flowIdObj.form && typeof flowIdObj.form === "object" ? flowIdObj.form : {}) as Record<string, any>;
|
const form = (flowIdObj.form && typeof flowIdObj.form === "object" ? flowIdObj.form : {}) as Record<string, any>;
|
||||||
const title = form.title || flowIdObj.title || "<无标题>";
|
const title = form.title || flowIdObj.title || "<无标题>";
|
||||||
const translatorContext = await getTranslatorContext(context.client, context.corpId).catch(() => undefined);
|
const translatorContext = await getTranslatorContext(context.client, context.corpId, raw).catch(() => undefined);
|
||||||
const snapshot = translateBillFlowToMarkdown(raw, translatorContext);
|
const snapshot = translateBillFlowToMarkdown(raw, translatorContext);
|
||||||
|
|
||||||
// 创建全新独立运行实例 (永久长 ID + 6 位短 ID, 6 小时有效期)
|
// 创建全新独立运行实例 (永久长 ID + 6 位短 ID, 6 小时有效期)
|
||||||
@@ -299,7 +299,7 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
|||||||
if (!raw) {
|
if (!raw) {
|
||||||
throw new Error(`在当前企业下未找到单号或 ID 为 [${targetSn}] 的单据`);
|
throw new Error(`在当前企业下未找到单号或 ID 为 [${targetSn}] 的单据`);
|
||||||
}
|
}
|
||||||
const translatorContext = await getTranslatorContext(context.client, context.corpId).catch(() => undefined);
|
const translatorContext = await getTranslatorContext(context.client, context.corpId, raw).catch(() => undefined);
|
||||||
const markdown = translateBillFlowToMarkdown(raw, translatorContext);
|
const markdown = translateBillFlowToMarkdown(raw, translatorContext);
|
||||||
|
|
||||||
repo.logAiProAction({
|
repo.logAiProAction({
|
||||||
|
|||||||
+42
-1
@@ -18,7 +18,7 @@ function flowLookupSelect(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function flowDetailSelect(): string {
|
function flowDetailSelect(): string {
|
||||||
return "flowId(form(`...`),logs(operatorId,nextOperatorId,`...`),plan(`...`),`...`),`...`";
|
return "flowId(form(specificationId(id,name,code),`...`),logs(operatorId,nextOperatorId,`...`),plan(`...`),`...`),`...`";
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listActiveStaffCatalog(
|
export async function listActiveStaffCatalog(
|
||||||
@@ -396,3 +396,44 @@ export async function listEntitySchemas(
|
|||||||
const parsed = EntityListResponseSchema.parse(json);
|
const parsed = EntityListResponseSchema.parse(json);
|
||||||
return parsed.items;
|
return parsed.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 发票票面查验详情与商品明细 API ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
export async function getInvoiceValidationDetail(
|
||||||
|
client: KyInstance,
|
||||||
|
corpId: string,
|
||||||
|
invoiceId: string
|
||||||
|
): Promise<Record<string, unknown> | undefined> {
|
||||||
|
try {
|
||||||
|
const response = await client.get(`api/v2/invoice/validation/$${encodeURIComponent(invoiceId)}`, {
|
||||||
|
searchParams: { masterId: invoiceId, corpId }
|
||||||
|
});
|
||||||
|
return (await response.json()) as Record<string, unknown>;
|
||||||
|
} catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 数据连接业务对象与卡片详情 API ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
export async function getDatalinkCard(
|
||||||
|
client: KyInstance,
|
||||||
|
corpId: string,
|
||||||
|
entityId: string,
|
||||||
|
type = "CARD"
|
||||||
|
): Promise<Record<string, unknown> | undefined> {
|
||||||
|
try {
|
||||||
|
const response = await client.get(`api/v2/datalink/detail/$${encodeURIComponent(entityId)}/$${encodeURIComponent(type)}`, {
|
||||||
|
searchParams: {
|
||||||
|
entityId,
|
||||||
|
type,
|
||||||
|
join: "data.dataLink.entityId,entity,/v2/datalink/entity",
|
||||||
|
corpId,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const json = (await response.json()) as { value?: Record<string, unknown> };
|
||||||
|
return json?.value ?? undefined;
|
||||||
|
} catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
+117
-8
@@ -18,6 +18,8 @@ import {
|
|||||||
transferBillAction,
|
transferBillAction,
|
||||||
addNodeBillAction,
|
addNodeBillAction,
|
||||||
commentBillAction,
|
commentBillAction,
|
||||||
|
getInvoiceValidationDetail,
|
||||||
|
getDatalinkCard,
|
||||||
type BillActionOptions,
|
type BillActionOptions,
|
||||||
type BillActionTarget,
|
type BillActionTarget,
|
||||||
} from "./api.js";
|
} from "./api.js";
|
||||||
@@ -1274,13 +1276,15 @@ export const billTools = [
|
|||||||
|
|
||||||
export async function getTranslatorContext(
|
export async function getTranslatorContext(
|
||||||
client: KyInstance,
|
client: KyInstance,
|
||||||
corpId: string
|
corpId: string,
|
||||||
|
rawFlow?: Record<string, unknown>
|
||||||
): Promise<TranslatorOptions> {
|
): Promise<TranslatorOptions> {
|
||||||
const [feeTypeTree, catalog, dimEntity, dimBiz] = await Promise.allSettled([
|
const [feeTypeTree, catalog, dimEntity, dimBiz, dimBool] = await Promise.allSettled([
|
||||||
getFeeTypeTree(client, corpId),
|
getFeeTypeTree(client, corpId),
|
||||||
getReferenceCatalog(client, corpId),
|
getReferenceCatalog(client, corpId),
|
||||||
resolveDimension(client, corpId, "法人实体"),
|
resolveDimension(client, corpId, "法人实体"),
|
||||||
resolveDimension(client, corpId, "业务类型"),
|
resolveDimension(client, corpId, "业务类型"),
|
||||||
|
resolveDimension(client, corpId, "是否"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const feeTypeMap = new Map<string, { name?: string; path?: string }>();
|
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 departmentMap = catalog.status === "fulfilled" ? catalog.value.departments : undefined;
|
||||||
|
|
||||||
const dimensionItemMap = new Map<string, { name?: string; code?: string; label?: string }>();
|
const dimensionItemMap = new Map<string, { name?: string; code?: string; label?: string }>();
|
||||||
if (dimEntity.status === "fulfilled" && dimEntity.value?.items) {
|
for (const dimRes of [dimEntity, dimBiz, dimBool]) {
|
||||||
for (const item of dimEntity.value.items) {
|
if (dimRes.status === "fulfilled" && dimRes.value?.items) {
|
||||||
dimensionItemMap.set(item.id, { name: item.name, code: item.code });
|
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) {
|
const invoiceDetailMap = new Map<string, Record<string, unknown>>();
|
||||||
dimensionItemMap.set(item.id, { name: item.name, code: item.code });
|
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 {
|
return {
|
||||||
@@ -1311,6 +1418,8 @@ export async function getTranslatorContext(
|
|||||||
staffMap,
|
staffMap,
|
||||||
departmentMap,
|
departmentMap,
|
||||||
dimensionItemMap,
|
dimensionItemMap,
|
||||||
|
invoiceDetailMap,
|
||||||
|
datalinkCardMap,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+139
-35
@@ -120,6 +120,16 @@ export function formatPersonValue(
|
|||||||
return String(val);
|
return String(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TranslatorOptions {
|
||||||
|
corpName?: string;
|
||||||
|
feeTypeMap?: Map<string, { name?: string; path?: string }>;
|
||||||
|
staffMap?: Map<string, Record<string, unknown>>;
|
||||||
|
departmentMap?: Map<string, { path?: string; item?: Record<string, unknown> }>;
|
||||||
|
dimensionItemMap?: Map<string, { name?: string; code?: string; label?: string; path?: string }>;
|
||||||
|
invoiceDetailMap?: Map<string, Record<string, unknown>>;
|
||||||
|
datalinkCardMap?: Map<string, string>;
|
||||||
|
}
|
||||||
|
|
||||||
// ── 5. 部门全路径格式化 ───────────────────────────────────────────────────────
|
// ── 5. 部门全路径格式化 ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
export function formatDepartmentValue(
|
export function formatDepartmentValue(
|
||||||
@@ -140,6 +150,12 @@ export function formatDepartmentValue(
|
|||||||
}
|
}
|
||||||
if (typeof val === "object") {
|
if (typeof val === "object") {
|
||||||
const obj = val as Record<string, unknown>;
|
const obj = val as Record<string, unknown>;
|
||||||
|
const id = (obj.id || obj.deptId || obj.departmentId || "") as string;
|
||||||
|
if (id) {
|
||||||
|
const match = departmentMap?.get(id) ?? departmentMap?.get(id.split(":").at(-1) ?? id);
|
||||||
|
if (match?.path) return match.path;
|
||||||
|
if (match?.item?.name) return match.item.name as string;
|
||||||
|
}
|
||||||
return (obj.fullPath || obj.path || obj.name || "") as string;
|
return (obj.fullPath || obj.path || obj.name || "") as string;
|
||||||
}
|
}
|
||||||
return String(val);
|
return String(val);
|
||||||
@@ -149,7 +165,8 @@ export function formatDepartmentValue(
|
|||||||
|
|
||||||
export function formatReferenceOrObject(
|
export function formatReferenceOrObject(
|
||||||
val: unknown,
|
val: unknown,
|
||||||
dimensionMap?: Map<string, { name?: string; code?: string; label?: string; path?: string }>
|
dimensionMap?: Map<string, { name?: string; code?: string; label?: string; path?: string }>,
|
||||||
|
datalinkCardMap?: Map<string, string>
|
||||||
): string {
|
): string {
|
||||||
if (val === null || val === undefined) return "";
|
if (val === null || val === undefined) return "";
|
||||||
if (typeof val === "boolean") return val ? "是" : "否";
|
if (typeof val === "boolean") return val ? "是" : "否";
|
||||||
@@ -157,6 +174,9 @@ export function formatReferenceOrObject(
|
|||||||
|
|
||||||
if (typeof val === "string") {
|
if (typeof val === "string") {
|
||||||
const trimmed = val.trim();
|
const trimmed = val.trim();
|
||||||
|
if (datalinkCardMap?.has(trimmed)) {
|
||||||
|
return datalinkCardMap.get(trimmed)!;
|
||||||
|
}
|
||||||
if (dimensionMap?.has(trimmed)) {
|
if (dimensionMap?.has(trimmed)) {
|
||||||
const match = dimensionMap.get(trimmed)!;
|
const match = dimensionMap.get(trimmed)!;
|
||||||
const title = match.name || match.label || match.path || trimmed;
|
const title = match.name || match.label || match.path || trimmed;
|
||||||
@@ -168,7 +188,7 @@ export function formatReferenceOrObject(
|
|||||||
if (Array.isArray(val)) {
|
if (Array.isArray(val)) {
|
||||||
const city = parseCityValue(val);
|
const city = parseCityValue(val);
|
||||||
if (city && city !== String(val)) return city;
|
if (city && city !== String(val)) return city;
|
||||||
return val.map((item) => formatReferenceOrObject(item, dimensionMap)).join(";");
|
return val.map((item) => formatReferenceOrObject(item, dimensionMap, datalinkCardMap)).join(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof val === "object") {
|
if (typeof val === "object") {
|
||||||
@@ -242,7 +262,10 @@ export function formatApportionSplits(
|
|||||||
|
|
||||||
// ── 8. 明细发票列表行内格式化 ─────────────────────────────────────────────────
|
// ── 8. 明细发票列表行内格式化 ─────────────────────────────────────────────────
|
||||||
|
|
||||||
export function formatInlineInvoices(invoices: unknown[]): string[] {
|
export function formatInlineInvoices(
|
||||||
|
invoices: unknown[],
|
||||||
|
invoiceDetailMap?: Map<string, Record<string, unknown>>
|
||||||
|
): string[] {
|
||||||
if (!Array.isArray(invoices) || invoices.length === 0) return [];
|
if (!Array.isArray(invoices) || invoices.length === 0) return [];
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
lines.push(`- **发票列表**(${invoices.length}):`);
|
lines.push(`- **发票列表**(${invoices.length}):`);
|
||||||
@@ -250,21 +273,51 @@ export function formatInlineInvoices(invoices: unknown[]): string[] {
|
|||||||
invoices.forEach((invItem: any, idx: number) => {
|
invoices.forEach((invItem: any, idx: number) => {
|
||||||
const num = idx + 1;
|
const num = idx + 1;
|
||||||
const inv = invItem.invoice || invItem;
|
const inv = invItem.invoice || invItem;
|
||||||
|
const rawInvoiceId = String(inv.invoiceId || inv.id || "");
|
||||||
|
const detailFromMap = (rawInvoiceId && invoiceDetailMap?.get(rawInvoiceId)) || undefined;
|
||||||
|
const master = detailFromMap?.master as Record<string, unknown> | undefined;
|
||||||
|
const masterForm = (master?.form as Record<string, unknown>) || {};
|
||||||
|
const goodsDetails = Array.isArray(detailFromMap?.details) ? detailFromMap.details : [];
|
||||||
|
|
||||||
const verify = inv.verifyResult || inv;
|
const verify = inv.verifyResult || inv;
|
||||||
const fileInfo = inv.fileInfo || {};
|
const fileInfo = inv.fileInfo || {};
|
||||||
const code = inv.invoiceCode || inv.invoiceNo || inv.invoiceNumber || verify.invoiceNo || inv.invoiceId || `发票-${num}`;
|
let code = inv.invoiceCode || inv.invoiceNo || inv.invoiceNumber || verify.invoiceNo || (masterForm["E_system_发票主体_发票号码"] as string) || inv.invoiceId || `发票-${num}`;
|
||||||
|
if (typeof code === "string" && code.includes("::")) {
|
||||||
|
code = code.split("::").at(-1) || code;
|
||||||
|
}
|
||||||
|
|
||||||
const fileId = fileInfo.fileId || inv.fileId || inv.invoiceId || "";
|
const fileId = fileInfo.fileId || inv.fileId || inv.invoiceId || "";
|
||||||
const fileName = fileInfo.fileName || inv.fileName || "";
|
let fileName = fileInfo.fileName || inv.fileName || "";
|
||||||
|
if (!fileName && masterForm["E_system_发票主体_图片"]) {
|
||||||
|
try {
|
||||||
|
fileName = decodeURIComponent(String(masterForm["E_system_发票主体_图片"]));
|
||||||
|
} catch {
|
||||||
|
fileName = String(masterForm["E_system_发票主体_图片"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
const fileType = fileInfo.fileType || inv.fileType || "invoice";
|
const fileType = fileInfo.fileType || inv.fileType || "invoice";
|
||||||
const invoiceDate = formatDateValue(inv.invoiceDate || verify.invoiceDate);
|
const rawDate = inv.invoiceDate || verify.invoiceDate || masterForm["E_system_发票主体_发票日期"];
|
||||||
const verifyStatus = inv.verifyState || verify.verifyStatus || "verified";
|
const invoiceDate = formatDateValue(rawDate);
|
||||||
const buyer = verify.buyer || inv.buyer || "";
|
const verifyStatus = inv.verifyState || verify.verifyStatus || (masterForm["E_system_发票主体_验真"] ? "verified" : undefined) || "verified";
|
||||||
const buyerTax = verify.buyerTaxNo || inv.buyerTaxNo || "";
|
const buyer = verify.buyer || inv.buyer || masterForm["E_system_发票主体_购买方名称"] || "";
|
||||||
const seller = verify.seller || inv.seller || "";
|
const buyerTax = verify.buyerTaxNo || inv.buyerTaxNo || masterForm["E_system_发票主体_购买方纳税人识别号"] || "";
|
||||||
const sellerTax = verify.sellerTaxNo || inv.sellerTaxNo || "";
|
const seller = verify.seller || inv.seller || masterForm["E_system_发票主体_销售方名称"] || "";
|
||||||
const invoiceType = inv.invoiceType || verify.invoiceType || "电子发票";
|
const sellerTax = verify.sellerTaxNo || inv.sellerTaxNo || masterForm["E_system_发票主体_销售方纳税人识别号"] || "";
|
||||||
const totalAmount = formatAmountValue(inv.approveAmount || inv.totalAmount || verify.amount || inv.amount);
|
|
||||||
const taxAmount = formatAmountValue(inv.taxAmount || verify.taxAmount);
|
let invoiceType = inv.invoiceType || verify.invoiceType;
|
||||||
|
if (!invoiceType && masterForm["E_system_发票主体_发票类别"]) {
|
||||||
|
const cat = String(masterForm["E_system_发票主体_发票类别"]);
|
||||||
|
if (cat.includes("SPECIAL") || cat.includes("专票")) {
|
||||||
|
invoiceType = "电子发票(增值税专用发票)";
|
||||||
|
} else {
|
||||||
|
invoiceType = "电子发票";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
invoiceType = invoiceType || "电子发票";
|
||||||
|
|
||||||
|
const remark = (masterForm["E_system_发票主体_备注"] as string) || inv.remark || "";
|
||||||
|
const totalAmount = formatAmountValue(inv.approveAmount || inv.totalAmount || verify.amount || inv.amount || masterForm["E_system_发票主体_价税合计"]);
|
||||||
|
const taxAmount = formatAmountValue(inv.taxAmount || verify.taxAmount || masterForm["E_system_发票主体_税额"]);
|
||||||
|
|
||||||
lines.push(` ${num}. **发票号码: ${code}**`);
|
lines.push(` ${num}. **发票号码: ${code}**`);
|
||||||
if (fileId) lines.push(` 原始文件fileId: ${fileId}`);
|
if (fileId) lines.push(` 原始文件fileId: ${fileId}`);
|
||||||
@@ -275,16 +328,55 @@ export function formatInlineInvoices(invoices: unknown[]): string[] {
|
|||||||
if (buyer) lines.push(` 购方: ${buyer}${buyerTax ? `,税号: ${buyerTax}` : ""}`);
|
if (buyer) lines.push(` 购方: ${buyer}${buyerTax ? `,税号: ${buyerTax}` : ""}`);
|
||||||
if (seller) lines.push(` 销方: ${seller}${sellerTax ? `,税号: ${sellerTax}` : ""}`);
|
if (seller) lines.push(` 销方: ${seller}${sellerTax ? `,税号: ${sellerTax}` : ""}`);
|
||||||
if (invoiceType) lines.push(` 发票类型: ${invoiceType}`);
|
if (invoiceType) lines.push(` 发票类型: ${invoiceType}`);
|
||||||
|
if (remark) lines.push(` 备注: ${remark}`);
|
||||||
lines.push(` 价税合计: ${totalAmount}`);
|
lines.push(` 价税合计: ${totalAmount}`);
|
||||||
if (taxAmount !== "CNY 0.00") lines.push(` 税额: ${taxAmount}`);
|
if (taxAmount && taxAmount !== "CNY 0.00") lines.push(` 税额: ${taxAmount}`);
|
||||||
|
|
||||||
|
const items = verify.items || inv.items || (goodsDetails.length > 0 ? goodsDetails.map((gd: any) => {
|
||||||
|
const f = gd.form || {};
|
||||||
|
return {
|
||||||
|
名称: gd.name || f["E_system_发票明细_name"] || "",
|
||||||
|
单位: f["E_system_发票明细_单位"] || "",
|
||||||
|
数量: String(f["E_system_发票明细_数量"] || ""),
|
||||||
|
单价: formatAmountValue(f["E_system_发票明细_单价"]),
|
||||||
|
金额: formatAmountValue(f["E_system_发票明细_金额"]),
|
||||||
|
税率: f["E_system_发票明细_税率"] || "",
|
||||||
|
税额: formatAmountValue(f["E_system_发票明细_税额"]),
|
||||||
|
};
|
||||||
|
}) : undefined);
|
||||||
|
|
||||||
const items = verify.items || inv.items;
|
|
||||||
if (Array.isArray(items) && items.length > 0) {
|
if (Array.isArray(items) && items.length > 0) {
|
||||||
lines.push(` 发票明细(${items.length}):`);
|
lines.push(` 发票明细(${items.length}):`);
|
||||||
for (const it of items) {
|
for (const it of items) {
|
||||||
lines.push(` - ${JSON.stringify(it)}`);
|
lines.push(` - ${JSON.stringify(it)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (master && Object.keys(masterForm).length > 0) {
|
||||||
|
const invInfoObj = {
|
||||||
|
销售方地址电话: masterForm["E_system_发票主体_销售方地址电话"] || "",
|
||||||
|
是否有发票原件: masterForm["E_system_发票主体_是否有发票原件"] ? "是" : "否",
|
||||||
|
收票状态: masterForm["E_system_收票状态"] || "NORECEIVE",
|
||||||
|
可抵扣税额: formatAmountValue(masterForm["E_税额"] || masterForm["E_system_发票主体_税额"]),
|
||||||
|
名称: masterForm["E_system_发票主体_name"] || code,
|
||||||
|
发票号码: code,
|
||||||
|
发票日期: invoiceDate,
|
||||||
|
购买方名称: buyer,
|
||||||
|
购买方纳税人识别号: buyerTax,
|
||||||
|
发票金额: formatAmountValue(masterForm["E_不计税金额"] || masterForm["E_system_发票主体_发票金额"]),
|
||||||
|
税额: taxAmount,
|
||||||
|
价税合计: totalAmount,
|
||||||
|
销售方名称: seller,
|
||||||
|
销售方纳税人识别号: sellerTax,
|
||||||
|
销售方开户行及账号: masterForm["E_system_发票主体_销售方开户行及账号"] || "",
|
||||||
|
备注: remark,
|
||||||
|
发票类别: invoiceType,
|
||||||
|
不计税金额: formatAmountValue(masterForm["E_不计税金额"] || masterForm["E_system_发票主体_发票金额"]),
|
||||||
|
发票状态: masterForm["E_system_发票主体_发票状态"] || "NORMAL_BLUE",
|
||||||
|
是否电子票: masterForm["E_system_发票主体_是否电子票"] ? "是" : "否",
|
||||||
|
};
|
||||||
|
lines.push(` 发票信息: ${JSON.stringify(invInfoObj)}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
@@ -311,7 +403,13 @@ export function formatInlineAttachments(attachments: unknown[]): string[] {
|
|||||||
// ── 10. 模板名称标准化 ────────────────────────────────────────────────────────
|
// ── 10. 模板名称标准化 ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export function resolveSpecificationName(specId: unknown): string {
|
export function resolveSpecificationName(specId: unknown): string {
|
||||||
if (!specId || typeof specId !== "string") return "未知模板";
|
if (!specId) return "未知模板";
|
||||||
|
if (typeof specId === "object") {
|
||||||
|
const obj = specId as Record<string, unknown>;
|
||||||
|
if (typeof obj.name === "string" && obj.name) return obj.name;
|
||||||
|
if (typeof obj.id === "string") return resolveSpecificationName(obj.id);
|
||||||
|
}
|
||||||
|
if (typeof specId !== "string") return "未知模板";
|
||||||
if (specId.includes("REQUISITION_TRIP") || specId.includes("trip")) return "差旅申请单";
|
if (specId.includes("REQUISITION_TRIP") || specId.includes("trip")) return "差旅申请单";
|
||||||
if (specId.includes("REIMBURSEMENT") || specId.includes("expense")) return "报销单";
|
if (specId.includes("REIMBURSEMENT") || specId.includes("expense")) return "报销单";
|
||||||
if (specId.includes("LOAN") || specId.includes("loan")) return "借款单";
|
if (specId.includes("LOAN") || specId.includes("loan")) return "借款单";
|
||||||
@@ -341,7 +439,7 @@ export function formatDynamicField(
|
|||||||
if (BUILTIN_SYSTEM_KEYS.has(key)) return undefined;
|
if (BUILTIN_SYSTEM_KEYS.has(key)) return undefined;
|
||||||
if (val === null || val === undefined || val === "") return undefined;
|
if (val === null || val === undefined || val === "") return undefined;
|
||||||
|
|
||||||
let label = options?.dictionary?.get(key)?.label || key.replace(/^u_/, "");
|
let label = (options as any)?.dictionary?.get(key)?.label || key.replace(/^u_/, "");
|
||||||
const lowerKey = key.toLowerCase();
|
const lowerKey = key.toLowerCase();
|
||||||
|
|
||||||
let text: string;
|
let text: string;
|
||||||
@@ -354,7 +452,7 @@ export function formatDynamicField(
|
|||||||
} else if (lowerKey.includes("person") || lowerKey.includes("staff") || lowerKey.includes("submitter")) {
|
} else if (lowerKey.includes("person") || lowerKey.includes("staff") || lowerKey.includes("submitter")) {
|
||||||
text = formatPersonValue(val, options?.staffMap);
|
text = formatPersonValue(val, options?.staffMap);
|
||||||
} else {
|
} else {
|
||||||
text = formatReferenceOrObject(val, options?.dimensionItemMap);
|
text = formatReferenceOrObject(val, options?.dimensionItemMap, options?.datalinkCardMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!text) return undefined;
|
if (!text) return undefined;
|
||||||
@@ -403,7 +501,7 @@ export function translateBillFlowToMarkdown(
|
|||||||
// 法人实体
|
// 法人实体
|
||||||
const legalEntityVal = form.法人实体 ?? form.legalEntity;
|
const legalEntityVal = form.法人实体 ?? form.legalEntity;
|
||||||
if (legalEntityVal) {
|
if (legalEntityVal) {
|
||||||
const formattedEntity = formatReferenceOrObject(legalEntityVal, options?.dimensionItemMap);
|
const formattedEntity = formatReferenceOrObject(legalEntityVal, options?.dimensionItemMap, options?.datalinkCardMap);
|
||||||
lines.push(`- **法人实体**: ${formattedEntity}`);
|
lines.push(`- **法人实体**: ${formattedEntity}`);
|
||||||
} else if (options?.corpName) {
|
} else if (options?.corpName) {
|
||||||
lines.push(`- **法人实体**: ${options.corpName}`);
|
lines.push(`- **法人实体**: ${options.corpName}`);
|
||||||
@@ -428,19 +526,21 @@ export function translateBillFlowToMarkdown(
|
|||||||
// 是否有纸质票据
|
// 是否有纸质票据
|
||||||
const paperInvoice = form.u_是否有纸质票据;
|
const paperInvoice = form.u_是否有纸质票据;
|
||||||
if (paperInvoice !== undefined && paperInvoice !== null && paperInvoice !== "") {
|
if (paperInvoice !== undefined && paperInvoice !== null && paperInvoice !== "") {
|
||||||
lines.push(`- **是否有纸质票据**: ${formatReferenceOrObject(paperInvoice, options?.dimensionItemMap)}`);
|
lines.push(`- **是否有纸质票据**: ${formatReferenceOrObject(paperInvoice, options?.dimensionItemMap, options?.datalinkCardMap)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 经常交易供应商
|
// 经常交易供应商
|
||||||
const vendor = form.u_经常交易供应商 ?? form.payeeId;
|
const vendor = form.u_经常交易供应商 ?? form.payeeId;
|
||||||
if (vendor) {
|
if (vendor) {
|
||||||
lines.push(`- **经常交易供应商**: ${formatReferenceOrObject(vendor, options?.dimensionItemMap)}`);
|
lines.push(`- **经常交易供应商**: ${formatReferenceOrObject(vendor, options?.dimensionItemMap, options?.datalinkCardMap)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收款信息
|
// 收款信息
|
||||||
const payeeAccount = form.payeeAccountId ?? form.payeeInfo;
|
const payeeAccount = form.payeeAccountId ?? form.payeeInfo;
|
||||||
if (payeeAccount) {
|
if (payeeAccount) {
|
||||||
lines.push(`- **收款信息**: ${formatReferenceOrObject(payeeAccount, options?.dimensionItemMap)}`);
|
lines.push(`- **收款信息**: ${formatReferenceOrObject(payeeAccount, options?.dimensionItemMap, options?.datalinkCardMap)}`);
|
||||||
|
} else if (vendor && typeof vendor === "string" && options?.datalinkCardMap?.has(`payeeInfo:${vendor}`)) {
|
||||||
|
lines.push(`- **收款信息**: ${options.datalinkCardMap.get(`payeeInfo:${vendor}`)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发票金额-总、税额、不含税
|
// 发票金额-总、税额、不含税
|
||||||
@@ -468,11 +568,15 @@ export function translateBillFlowToMarkdown(
|
|||||||
}
|
}
|
||||||
lines.push(`- **提交日期**: ${submitTime}`);
|
lines.push(`- **提交日期**: ${submitTime}`);
|
||||||
|
|
||||||
const mainAmount = form.requisitionMoney || form.amount || form.expenseMoney;
|
if (form.requisitionMoney) {
|
||||||
lines.push(`- **申请金额**: ${formatAmountValue(mainAmount)}`);
|
lines.push(`- **申请金额**: ${formatAmountValue(form.requisitionMoney)}`);
|
||||||
if (form.expenseMoney && form.payMoney) {
|
|
||||||
lines.push(`- **报销金额**: ${formatAmountValue(form.expenseMoney)}`);
|
|
||||||
}
|
}
|
||||||
|
if (form.expenseMoney) {
|
||||||
|
lines.push(`- **报销金额**: ${formatAmountValue(form.expenseMoney)}`);
|
||||||
|
} else if (!form.requisitionMoney && (form.amount || form.payMoney)) {
|
||||||
|
lines.push(`- **申请金额**: ${formatAmountValue(form.amount || form.payMoney)}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (form.companyRealPay !== undefined) {
|
if (form.companyRealPay !== undefined) {
|
||||||
lines.push(`- **公司实付金额**: ${formatAmountValue(form.companyRealPay)}`);
|
lines.push(`- **公司实付金额**: ${formatAmountValue(form.companyRealPay)}`);
|
||||||
}
|
}
|
||||||
@@ -483,16 +587,16 @@ export function translateBillFlowToMarkdown(
|
|||||||
|
|
||||||
// 关联申请
|
// 关联申请
|
||||||
const requisitions = Array.isArray(form.requisitionIds) ? form.requisitionIds : [];
|
const requisitions = Array.isArray(form.requisitionIds) ? form.requisitionIds : [];
|
||||||
if (requisitions.length > 0) {
|
lines.push(`### 关联申请(共 ${requisitions.length} 条)`);
|
||||||
lines.push(`### 关联申请(共 ${requisitions.length} 条)`);
|
lines.push("");
|
||||||
|
|
||||||
|
// 行程规划 (仅在有行程时输出)
|
||||||
|
const itineraries = Array.isArray(form.itineraries) ? form.itineraries : [];
|
||||||
|
if (itineraries.length > 0) {
|
||||||
|
lines.push(`### 行程规划(共 ${itineraries.length} 条)`);
|
||||||
lines.push("");
|
lines.push("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 行程规划
|
|
||||||
const itineraries = Array.isArray(form.itineraries) ? form.itineraries : [];
|
|
||||||
lines.push(`### 行程规划(共 ${itineraries.length} 条)`);
|
|
||||||
lines.push("");
|
|
||||||
|
|
||||||
// 费用明细
|
// 费用明细
|
||||||
const details = Array.isArray(form.details) ? form.details : [];
|
const details = Array.isArray(form.details) ? form.details : [];
|
||||||
lines.push(`### 费用明细(共 ${details.length} 条)`);
|
lines.push(`### 费用明细(共 ${details.length} 条)`);
|
||||||
@@ -537,7 +641,7 @@ export function translateBillFlowToMarkdown(
|
|||||||
// 明细发票列表(内嵌相对位置)
|
// 明细发票列表(内嵌相对位置)
|
||||||
const invoiceList = feeForm.invoiceForm?.invoices || feeForm.invoices;
|
const invoiceList = feeForm.invoiceForm?.invoices || feeForm.invoices;
|
||||||
if (Array.isArray(invoiceList) && invoiceList.length > 0) {
|
if (Array.isArray(invoiceList) && invoiceList.length > 0) {
|
||||||
lines.push(...formatInlineInvoices(invoiceList));
|
lines.push(...formatInlineInvoices(invoiceList, options?.invoiceDetailMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
const city = parseCityValue(feeForm.city);
|
const city = parseCityValue(feeForm.city);
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
export const VERSION = "0.7.2";
|
export const VERSION = "0.7.3";
|
||||||
Reference in new issue
Block a user