From be080e15003102850228cd6e952ac18bfe4fa8b8 Mon Sep 17 00:00:00 2001 From: Christ Date: Tue, 18 Aug 2026 16:19:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E9=93=BA=E8=B4=A7=E5=8F=91=E5=B8=83=E5=BC=BA=E5=88=B6=E9=97=B4?= =?UTF-8?q?=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/features/apiAdapters.test.ts | 4 + frontend/app/features/items/api.ts | 3 + frontend/app/features/items/hooks.ts | 10 ++- .../app/features/items/pages/ItemList.tsx | 13 ++- frontend/app/features/items/types.ts | 6 ++ frontend/shared/api-contract/index.ts | 2 + internal/adapter/item_batch_publish.go | 3 +- internal/adapter/item_batch_publish_test.go | 6 +- internal/adapter/item_batch_repository.go | 14 +++- .../items/batch_preview_persistence.go | 2 + internal/application/items/batch_publish.go | 82 ++++++++++++++----- .../application/items/batch_publish_test.go | 10 ++- .../items/batch_worker_coordinator_test.go | 6 +- internal/db/item_publish_batches.go | 56 +++++++++---- internal/db/migrate_test.go | 10 +-- .../mysql/00033_publish_interval.sql | 11 +++ .../postgres/00033_publish_interval.sql | 11 +++ .../sqlite/00033_publish_interval.sql | 11 +++ internal/db/publish_batches_test.go | 47 +++++++++++ .../server/item_publish_batch_handlers.go | 33 +++++++- internal/server/publish_batch_run_test.go | 2 +- internal/server/publish_batch_test.go | 40 ++++++++- internal/server/success_contract.go | 2 + ...st-i39PcoQv.js => AccountList-CW56xo40.js} | 2 +- ...dList-z1WELq_d.js => CardList-DXFjEouq.js} | 2 +- .../{Chat-BfnRPAOt.js => Chat-o8zU9itw.js} | 2 +- ...oard-3YjsHK0L.js => Dashboard-xJlcwTaJ.js} | 2 +- .../webui/static/assets/ItemList-CnEIHIcF.js | 2 + .../webui/static/assets/ItemList-DDiNaq3H.js | 2 - ...-DcqcaoDO.js => Notifications-Cgc4sSHL.js} | 2 +- ...List-CljaoSLa.js => OrderList-BY2V4t6y.js} | 2 +- .../{Rules-BiND-23Q.js => Rules-BeCst9X9.js} | 2 +- ...tings-BIhrQYtY.js => Settings-CbEKYyJY.js} | 2 +- .../webui/static/assets/index-BgG-QVY7.css | 1 - .../{index-k6Tc6ww6.js => index-CCqtUiU5.js} | 4 +- .../webui/static/assets/index-fhlAsi4b.css | 1 + internal/webui/static/index.html | 4 +- internal/xianyu/mtop/publish.go | 8 ++ internal/xianyu/mtop/publish_extra_test.go | 15 ++++ 39 files changed, 362 insertions(+), 75 deletions(-) create mode 100644 internal/db/migrations/mysql/00033_publish_interval.sql create mode 100644 internal/db/migrations/postgres/00033_publish_interval.sql create mode 100644 internal/db/migrations/sqlite/00033_publish_interval.sql rename internal/webui/static/assets/{AccountList-i39PcoQv.js => AccountList-CW56xo40.js} (99%) rename internal/webui/static/assets/{CardList-z1WELq_d.js => CardList-DXFjEouq.js} (99%) rename internal/webui/static/assets/{Chat-BfnRPAOt.js => Chat-o8zU9itw.js} (99%) rename internal/webui/static/assets/{Dashboard-3YjsHK0L.js => Dashboard-xJlcwTaJ.js} (99%) create mode 100644 internal/webui/static/assets/ItemList-CnEIHIcF.js delete mode 100644 internal/webui/static/assets/ItemList-DDiNaq3H.js rename internal/webui/static/assets/{Notifications-DcqcaoDO.js => Notifications-Cgc4sSHL.js} (99%) rename internal/webui/static/assets/{OrderList-CljaoSLa.js => OrderList-BY2V4t6y.js} (99%) rename internal/webui/static/assets/{Rules-BiND-23Q.js => Rules-BeCst9X9.js} (99%) rename internal/webui/static/assets/{Settings-BIhrQYtY.js => Settings-CbEKYyJY.js} (99%) delete mode 100644 internal/webui/static/assets/index-BgG-QVY7.css rename internal/webui/static/assets/{index-k6Tc6ww6.js => index-CCqtUiU5.js} (95%) create mode 100644 internal/webui/static/assets/index-fhlAsi4b.css diff --git a/frontend/app/features/apiAdapters.test.ts b/frontend/app/features/apiAdapters.test.ts index f6979eb..2640b7f 100644 --- a/frontend/app/features/apiAdapters.test.ts +++ b/frontend/app/features/apiAdapters.test.ts @@ -1243,6 +1243,7 @@ const runVersionedItemBatchAPITest = async () => { defaultCookieId: 'acc1', fallbackCategory: { catId: 'cat-1', catName: '资料', channelCatId: 'channel-1', tbCatId: 'tb-1' }, location: { area: '区域', city: '城市', division_id: '1', longitude: 120, latitude: 30, poi_id: 'poi-1', poi_name: '地点', province: '省' }, + publishIntervalSeconds: 12, }); await startItemPublishBatch('preview-1'); await getItemPublishBatches(10); @@ -1254,6 +1255,9 @@ const runVersionedItemBatchAPITest = async () => { expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/items/get-all-from-account', expect.objectContaining({ method: 'POST' })); expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/items/publish-categories/recommend', expect.objectContaining({ method: 'POST' })); expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/items/publish-batches/preview', expect.objectContaining({ method: 'POST', body: expect.any(FormData) })); + // previewBody 保存批量预检表单,确保用户设置的间隔进入后端持久化边界。 + const previewBody = fetchMock.mock.calls[2][1].body as FormData; + expect(previewBody.get('publish_interval_seconds')).toBe('12'); expect(fetchMock).toHaveBeenNthCalledWith(4, '/api/v1/items/publish-batches', expect.objectContaining({ method: 'POST' })); expect(fetchMock).toHaveBeenNthCalledWith(5, '/api/v1/items/publish-batches?limit=10', expect.objectContaining({ method: 'GET' })); expect(fetchMock).toHaveBeenNthCalledWith(6, '/api/v1/items/publish-batches/batch-1', expect.objectContaining({ method: 'GET' })); diff --git a/frontend/app/features/items/api.ts b/frontend/app/features/items/api.ts index cc425ff..cdb4187 100644 --- a/frontend/app/features/items/api.ts +++ b/frontend/app/features/items/api.ts @@ -109,6 +109,8 @@ export const previewItemPublishBatch = async (form: { /** tbCatId 表示淘宝分类标识。 */ tbCatId?: string; }; /** location 表示地址。 */ location?: PublishLocation; + /** publishIntervalSeconds 表示最终商品发布之间的最小间隔秒数。 */ + publishIntervalSeconds?: number; }, options?: RequestControlOptions): Promise => { // body 请求体,用于当前 API 处理流程。 const body = new FormData(); @@ -120,6 +122,7 @@ export const previewItemPublishBatch = async (form: { body.set('fallback_channel_category_id', form.fallbackCategory.channelCatId || ''); body.set('fallback_tb_category_id', form.fallbackCategory.tbCatId || ''); if (form.location) body.set('location', JSON.stringify(form.location)); + body.set('publish_interval_seconds', String(form.publishIntervalSeconds ?? 5)); return postForm('/api/v1/items/publish-batches/preview', body, options); } diff --git a/frontend/app/features/items/hooks.ts b/frontend/app/features/items/hooks.ts index 811fe3e..8c91dc6 100644 --- a/frontend/app/features/items/hooks.ts +++ b/frontend/app/features/items/hooks.ts @@ -45,6 +45,8 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli const [batchLocations, setBatchLocations] = useState>([]); // batchLocation 保存批量任务当前选中的发货地。 const [batchLocation, setBatchLocation] = useState(null); + // batchPublishIntervalSeconds 保存当前批量任务的最终发布最小间隔,默认五秒。 + const [batchPublishIntervalSeconds, setBatchPublishIntervalSeconds] = useState(5); // batchLoading 表示批量任务请求是否正在执行。 const [batchLoading, setBatchLoading] = useState(false); // batchPollInFlight 防止同一批次的轮询请求重叠。 @@ -97,6 +99,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli setBatchFallbackCategory({ catId: '', catName: '', channelCatId: '', tbCatId: '' }); setBatchLocations([]); setBatchLocation(null); + setBatchPublishIntervalSeconds(5); setShowBatchModal(true); setBatchLoading(true); try { @@ -111,6 +114,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli if (!isCurrentBatchOperation(request.requestGeneration, request.controller)) return; setRecentBatch(detail); setBatchDetail(detail); + setBatchPublishIntervalSeconds(detail.publish_interval_seconds || 5); setBatchPhase(['running', 'canceling'].includes(detail.status) ? 'running' : 'done'); } } catch (error /* 恢复任务错误 */) { @@ -177,6 +181,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli const detail = await getItemPublishBatch(recentBatch.id, { signal: request.controller.signal }); if (!isCurrentBatchOperation(request.requestGeneration, request.controller)) return; setBatchDetail(detail); + setBatchPublishIntervalSeconds(detail.publish_interval_seconds || 5); setBatchPhase(['running', 'canceling'].includes(detail.status) ? 'running' : 'done'); } catch (error /* 最近结果读取错误 */) { if (!isCurrentBatchOperation(request.requestGeneration, request.controller)) return; @@ -211,6 +216,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli defaultCookieId: options.selectedAccount, fallbackCategory: batchFallbackCategory, location: batchLocation || undefined, + publishIntervalSeconds: batchPublishIntervalSeconds, }, { signal: request.controller.signal }); if (!isCurrentBatchOperation(request.requestGeneration, request.controller)) return; setBatchPreview(result); @@ -224,7 +230,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli if (isCurrentBatchOperation(request.requestGeneration, request.controller)) setBatchLoading(false); } }, - [batchFallbackCategory, batchFile, batchImagesZip, batchLocation, beginBatchRequest, isCurrentBatchOperation, options.selectedAccount], + [batchFallbackCategory, batchFile, batchImagesZip, batchLocation, batchPublishIntervalSeconds, beginBatchRequest, isCurrentBatchOperation, options.selectedAccount], ); // handleStartBatch 启动预检通过的批量任务并读取首个详情。 @@ -429,6 +435,8 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli batchLocation, setBatchLocations, setBatchLocation, + batchPublishIntervalSeconds, + setBatchPublishIntervalSeconds, openBatchModal, handleRecommendBatchCategory, openRecentBatchResult, diff --git a/frontend/app/features/items/pages/ItemList.tsx b/frontend/app/features/items/pages/ItemList.tsx index 6f9c81f..cedc5bc 100644 --- a/frontend/app/features/items/pages/ItemList.tsx +++ b/frontend/app/features/items/pages/ItemList.tsx @@ -79,6 +79,8 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { setRecentBatch, batchLocations, batchLocation, + batchPublishIntervalSeconds, + setBatchPublishIntervalSeconds, setBatchLocations, setBatchLocation, openBatchModal, @@ -657,9 +659,16 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { {batchLocations.length > 0 && } - + -
+
+ +
+ +