From 3d1c1f9e37f98b46c30b80b1be690a1388206498 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Wed, 21 Oct 2026 07:39:31 +0800 Subject: [PATCH] feat(numbering): unify daily business document numbers (admin) --- .../api/platformContainerCustoms.test.ts | 18 +++++++++++++++++- .../api/platformContainerCustoms.ts | 6 +++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/modules/container-loading/api/platformContainerCustoms.test.ts b/src/modules/container-loading/api/platformContainerCustoms.test.ts index 70397885..9e42d246 100644 --- a/src/modules/container-loading/api/platformContainerCustoms.test.ts +++ b/src/modules/container-loading/api/platformContainerCustoms.test.ts @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { http } from '@/shared/api/http' -import { recordClearanceResult, type DeclarationBatch } from './platformContainerCustoms' +import { createDeclarationBatch, submitDeclarationBatch, recordClearanceResult, type DeclarationBatch } from './platformContainerCustoms' import { completeAllBuyContainerCustoms, downloadContainerCustomsReceipt, downloadContainerCustomsDocument, getContainerCustoms, sendContainerCustomsToBroker, startContainerCustoms, uploadContainerCustomsReceipt } from './platformContainerCustoms' const customs = { @@ -15,6 +15,22 @@ const customs = { describe('platform container customs API', () => { beforeEach(() => vi.restoreAllMocks()) + it('preserves the server batch number when creating and submitting a declaration', async () => { + const batch = { id: '123', customsContainerId: '456', loadingPlanId: '789', batchNo: 'DECL202610200001', sourceVersion: 1, version: 0, results: [] } + const post = vi.spyOn(http, 'post').mockResolvedValue({ code: '200', data: batch }) + const created = await createDeclarationBatch('789', 3) + expect(created.batchNo).toBe('DECL202610200001') + expect(post.mock.calls[0]?.slice(0, 2)).toEqual([ + '/platform/v1/customs/loading-plans/789/declaration-batches', { expectedVersion: 3, remark: null }, + ]) + const submitted = await submitDeclarationBatch(created, ' CUSTOMS-EXTERNAL-1 ') + expect(submitted.batchNo).toBe(created.batchNo) + expect(post.mock.calls[1]?.slice(0, 2)).toEqual([ + '/platform/v1/customs/loading-plans/declaration-batches/123/submit', + { expectedVersion: 0, customsEntryNo: 'CUSTOMS-EXTERNAL-1', remark: null }, + ]) + }) + it('records domestic customs time in Shanghai even when UTC falls on the previous day', async () => { vi.useFakeTimers() try { diff --git a/src/modules/container-loading/api/platformContainerCustoms.ts b/src/modules/container-loading/api/platformContainerCustoms.ts index db2c3cd0..24fc787f 100644 --- a/src/modules/container-loading/api/platformContainerCustoms.ts +++ b/src/modules/container-loading/api/platformContainerCustoms.ts @@ -178,13 +178,13 @@ export async function getDeclarationBatches(loadingPlanId: string) { return (unwrapApiResponse(response) || []).map(normalizeDeclarationBatch) } -export async function createDeclarationBatch(loadingPlanId: string, expectedVersion: number, batchNo?: string) { - const response = await http.post, ApiEnvelope>(`${basePath}/${encodeURIComponent(loadingPlanId)}/declaration-batches`, { expectedVersion, batchNo: batchNo?.trim() || null, remark: null }, { headers: { 'Idempotency-Key': operationId('customs-declaration-batch-create') } }) +export async function createDeclarationBatch(loadingPlanId: string, expectedVersion: number) { + const response = await http.post, ApiEnvelope>(`${basePath}/${encodeURIComponent(loadingPlanId)}/declaration-batches`, { expectedVersion, remark: null }, { headers: { 'Idempotency-Key': operationId('customs-declaration-batch-create') } }) return normalizeDeclarationBatch(unwrapApiResponse(response)) } export async function submitDeclarationBatch(batch: DeclarationBatch, customsEntryNo: string) { - const response = await http.post, ApiEnvelope>(`${basePath}/declaration-batches/${encodeURIComponent(batch.id)}/submit`, { expectedVersion: batch.version, batchNo: batch.batchNo, customsEntryNo: customsEntryNo.trim(), remark: null }, { headers: { 'Idempotency-Key': operationId('customs-declaration-batch-submit') } }) + const response = await http.post, ApiEnvelope>(`${basePath}/declaration-batches/${encodeURIComponent(batch.id)}/submit`, { expectedVersion: batch.version, customsEntryNo: customsEntryNo.trim(), remark: null }, { headers: { 'Idempotency-Key': operationId('customs-declaration-batch-submit') } }) return normalizeDeclarationBatch(unwrapApiResponse(response)) }