Route material pack batches to their own create endpoint

Material pack simulation uses POST /api/v1/simulation/create-material-pack-batch
with approvalCode/nodeId/runMode in the request body; keep the shared
create-batch payload for hosecloud single-number mode.

Verification: material pack create on xiezihao staging returns 200 and
ingests records (HY001/HY002, taskMode=simulation); 116 tests pass.
This commit is contained in:
gitea committed 2026-08-24 18:27:55 +08:00
1 parent 997f1f60ac
commit baab26bcda
9 files changed
+138 -31

No files matched your search

+1 -2
View File
@@ -740,7 +740,6 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
disableAttachmentCache: booleanOption(args.options.disableAttachmentCache) ?? booleanOption(args.options["disable-attachment-cache"]),
signKey: stringOption(args.options.signKey) ?? stringOption(args.options["sign-key"]),
packageIds: splitOption(args.options.packageIds) ?? splitOption(args.options["package-ids"]),
packageLabel: stringOption(args.options.packageLabel) ?? stringOption(args.options["package-label"]),
templateId: stringOption(args.options.templateId) ?? stringOption(args.options["template-id"]),
schemaConfig,
rawParams: jsonObject(args.json)
@@ -1621,7 +1620,7 @@ Usage:
seal-home approval-runs bridge [--sourceDocumentSN B26001887] [--corp <corpId>]
seal-home simulation batch-records <batchId> [--corp <corpId>]
seal-home simulation create --mode hosecloud --flow-ids "B26017701,B26022501" [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-invoice-generation|--skip-invoice-generation false] [--corp <corpId>]
seal-home simulation create --mode material_pack --package-ids <materialPackageId> [--package-label 名称] [--template-id conference_reimbursement_v1] [--schema-config file.json] [--corp <corpId>]
seal-home simulation create --mode material_pack --package-ids <materialPackageId> [--template-id conference_reimbursement_v1] [--schema-config file.json] [--corp <corpId>]
seal-home simulation list [--limit 50] [--corp <corpId>]
seal-home simulation get <batchId> [--corp <corpId>]
seal-home simulation templates [--corp <corpId>]
+10
View File
@@ -599,6 +599,16 @@ export async function createSimulationBatch(
);
}
export async function createMaterialPackBatch(
client: KyInstance,
params: Record<string, unknown>
): Promise<SimulationCreateResult> {
return unwrap(
await client.post("api/v1/simulation/create-material-pack-batch", { json: params }),
SimulationCreateResultSchema
);
}
export async function listSimulationBatches(
client: KyInstance,
opts: { limit?: number } = {}
+41 -7
View File
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";
import { KyInstance } from "ky";
import { CorpConfig } from "../../core/config/types.js";
import {
createMaterialPackBatch,
createSimulationBatch,
getSimulationBatch,
getSimulationIntegrationStatus,
@@ -212,7 +213,6 @@ describe("buildSimulationBatchParams", () => {
const params = buildSimulationBatchParams({
mode: "material_pack",
packageIds: ["019fd15c-13a6-748f-8cdd-73e2da60252a"],
packageLabel: "Hilton测试材料包3-ready-v2-20260805-c6fcc0db",
templateId: "conference_reimbursement_v1",
skipInvoiceGeneration: true,
skipExpenseExtraction: true,
@@ -231,11 +231,14 @@ describe("buildSimulationBatchParams", () => {
});
expect(params).toMatchObject({
sourceSystem: "material_pack",
packageIds: ["019fd15c-13a6-748f-8cdd-73e2da60252a"],
packageLabel: "Hilton测试材料包3-ready-v2-20260805-c6fcc0db",
templateId: "conference_reimbursement_v1",
packageIds: ["019fd15c-13a6-748f-8cdd-73e2da60252a"],
approvalCode: "material_pack",
nodeId: "material_pack",
runMode: "import_and_simulate",
skipInvoiceGeneration: true,
skipExpenseExtraction: true,
disableAttachmentCache: false,
thinkingDepthOverride: "default",
schemaConfig: {
id: "conference_reimbursement_v1",
@@ -243,11 +246,26 @@ describe("buildSimulationBatchParams", () => {
attachmentFieldKey: "supporting_files"
}
});
// 合思专属字段不随材料包模式发送; approvalCode/nodeId 由服务端推导
expect(params).not.toHaveProperty("approvalCode");
expect(params).not.toHaveProperty("disableAttachmentCache");
// 材料包走独立端点, 请求体不带合思专属字段和服务端推导字段
expect(params).not.toHaveProperty("sourceSystem");
expect(params).not.toHaveProperty("flowIds");
expect(params).not.toHaveProperty("dataCollectionMode");
expect(params).not.toHaveProperty("rejectNodeName");
expect(params).not.toHaveProperty("limit");
expect(params).not.toHaveProperty("packageLabel");
});
test("derives templateId from schemaConfig.id when omitted", () => {
const params = buildSimulationBatchParams({
mode: "material_pack",
packageIds: ["019fd15c-13a6-748f-8cdd-73e2da60252a"],
schemaConfig: { id: "conference_reimbursement_v1", mainSheetName: "Sheet1" }
});
expect(params).toMatchObject({
templateId: "conference_reimbursement_v1",
packageIds: ["019fd15c-13a6-748f-8cdd-73e2da60252a"],
approvalCode: "material_pack"
});
});
test("rawParams can introduce reserved time-range fields", () => {
@@ -294,6 +312,22 @@ describe("simulation API client", () => {
expect(result.batchId).toBe("01a032f6-9798-7021-a632-f9fffb48f463");
});
test("creates a material pack batch via its own endpoint", async () => {
let postedUrl = "";
const client = {
post: (url: string, options: { json: Record<string, unknown> }) => {
postedUrl = url;
expect(options.json).toMatchObject({ templateId: "conference_reimbursement_v1" });
return { json: async () => ({ data: { batchId: "material-batch-1" } }) };
}
} as unknown as KyInstance;
const result = await createMaterialPackBatch(client, { templateId: "conference_reimbursement_v1" });
expect(postedUrl).toBe("api/v1/simulation/create-material-pack-batch");
expect(result.batchId).toBe("material-batch-1");
});
test("lists batches with a limit query", async () => {
let requestedUrl = "";
let requestedParams: Record<string, string> | undefined;
+15 -9
View File
@@ -1081,8 +1081,7 @@ export const sealTools = [
disableAttachmentCache: z.boolean().optional().describe("不使用附件缓存, 默认 false"),
signKey: z.string().optional().describe("合思集成标识; 缺省时自动取第一个合思集成"),
packageIds: z.array(z.string()).optional().describe("材料包模式: 材料包 id 列表(来自 material-packages upload 响应)"),
packageLabel: z.string().optional().describe("材料包标签, 展示用"),
templateId: z.string().optional().describe("材料包模板 id, 例如 conference_reimbursement_v1"),
templateId: z.string().optional().describe("材料包模板 id, 例如 conference_reimbursement_v1; 缺省取 schemaConfig.id"),
schemaConfig: z.record(z.string(), z.unknown()).optional().describe("材料包字段映射(确认参数), 建议使用 material-packages upload 返回的 schemaConfig"),
rawParams: z.record(z.string(), z.unknown()).optional().describe("预留: 其他取数模式(如时间范围 startTime/endTime)透传参数, 覆盖上述构建结果")
}),
@@ -1098,7 +1097,6 @@ export const sealTools = [
disableAttachmentCache?: boolean;
signKey?: string;
packageIds?: string[];
packageLabel?: string;
templateId?: string;
schemaConfig?: Record<string, unknown>;
rawParams?: Record<string, unknown>;
@@ -1124,13 +1122,15 @@ export const sealTools = [
disableAttachmentCache: params.disableAttachmentCache,
signKey,
packageIds: params.packageIds,
packageLabel: params.packageLabel,
templateId: params.templateId,
schemaConfig: params.schemaConfig,
rawParams: params.rawParams
});
const result = await api.createSimulationBatch(client, payload);
const result = mode === "material_pack"
? await api.createMaterialPackBatch(client, payload)
: await api.createSimulationBatch(client, payload);
return {
...result,
created: true,
@@ -1552,7 +1552,6 @@ export type SimulationBatchCreateInput = {
disableAttachmentCache?: boolean;
signKey?: string;
packageIds?: string[];
packageLabel?: string;
templateId?: string;
schemaConfig?: Record<string, unknown>;
// 预留:其他取数模式(如合思时间范围)透传参数,覆盖构建结果
@@ -1587,16 +1586,23 @@ export function buildSimulationBatchParams(input: SimulationBatchCreateInput): R
if (!input.packageIds?.length) {
throw new Error("material_pack 模式需要提供 packageIds(材料包 id)");
}
const templateId = input.templateId ?? (input.schemaConfig as { id?: string } | undefined)?.id;
if (!templateId) {
throw new Error("material_pack 模式需要提供 templateId(或 schemaConfig.id)");
}
// 材料包模式走独立端点 /api/v1/simulation/create-material-pack-batch:
// 请求直接携带 approvalCode/nodeId/runMode, 不带 sourceSystem/时间范围等字段。
Object.assign(params, {
sourceSystem: "material_pack",
templateId,
packageIds: input.packageIds,
approvalCode: "material_pack",
nodeId: "material_pack",
runMode: "import_and_simulate",
skipInvoiceGeneration: input.skipInvoiceGeneration ?? true,
skipExpenseExtraction: input.skipExpenseExtraction ?? true,
disableAttachmentCache: input.disableAttachmentCache ?? false,
thinkingDepthOverride: input.thinkingDepthOverride ?? "default"
});
if (input.templateId) params.templateId = input.templateId;
if (input.packageLabel) params.packageLabel = input.packageLabel;
if (input.schemaConfig !== undefined) params.schemaConfig = input.schemaConfig;
}