From e2909a88fb69f5adb2dc0d8ef072a768e70ccc07 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 20 Oct 2026 22:19:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BA=93=E5=AD=98):=20=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=8F=96=E8=AF=A5=E6=89=B9=E6=AC=A1=E6=9C=80?= =?UTF-8?q?=E6=97=A9=E4=B8=80=E6=AC=A1=E5=85=A5=E5=BA=93=E6=B5=81=E6=B0=B4?= =?UTF-8?q?(stock=5Fin/inspection=5Fin)=EF=BC=8C=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=20inbound=5Fat=EF=BC=9B=E6=92=A4=E9=94=80?= =?UTF-8?q?=E7=94=A8=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/services/inventoryQueryService.ts | 13 +++++++++++-- src/components/inventory/BatchReportUploadModal.tsx | 5 +++-- src/utils/workflowApi.ts | 2 ++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/server/src/services/inventoryQueryService.ts b/server/src/services/inventoryQueryService.ts index a8c5451..d1ba5be 100644 --- a/server/src/services/inventoryQueryService.ts +++ b/server/src/services/inventoryQueryService.ts @@ -161,6 +161,13 @@ export async function listInventoryForManagement( LEFT JOIN skus sk ON sk.sku_code = inv.sku_code LEFT JOIN categories cat ON cat.category_code = sk.category_code LEFT JOIN suppliers sup ON sup.supplier_code = inv.supplier_code + LEFT JOIN LATERAL ( + SELECT to_char(min(l.created_at), 'YYYY-MM-DD') AS inbound_at + FROM inventory_logs l + WHERE l.branch_code = inv.branch_code + AND l.batch_no = inv.batch_no + AND l.operation_type IN ('stock_in', 'inspection_in') + ) inb ON TRUE `; const statsParams: unknown[] = []; @@ -218,7 +225,7 @@ export async function listInventoryForManagement( const listParams = [...params, pageSize, offset]; const listResult = await pool.query( - `SELECT inv.*, + `SELECT inv.*, inb.inbound_at AS inbound_at, -- 批次产地(2026-10-21 批次级产地):批次优先,空则前端按商品档案默认值展示; -- 返回固定键名 batch_origin(弹窗回显读 (item as any).batch_origin) COALESCE(inv.origin, '') AS batch_origin, @@ -229,7 +236,7 @@ export async function listInventoryForManagement( sk.origin, cat.category_name, sup.company_name AS supplier_name, - EXISTS ( + ( SELECT count(*)::int FROM inventory_batch_report_matches m WHERE m.inventory_id = inv.id ) AS batch_report_count ${fromSql} @@ -342,6 +349,8 @@ export async function listInventoryForManagement( shelf_life: item.shelf_life == null ? null : String(item.shelf_life), /** 是否存在已确认的入库批次报告关联(供列表标注「缺少批次报告」) */ has_batch_report: Number(item.batch_report_count || 0) > 0, + /** 入库时间 = 该批次**最早一次**入库流水(stock_in / inspection_in)的日期;无流水则 null */ + inbound_at: item.inbound_at ? String(item.inbound_at) : null, batch_report_count: Number(item.batch_report_count || 0), /** 批次级产地(空串 = 未设置;前端弹窗回显与「留空走商品默认」共用该键) */ batch_origin: item.batch_origin == null ? '' : String(item.batch_origin), diff --git a/src/components/inventory/BatchReportUploadModal.tsx b/src/components/inventory/BatchReportUploadModal.tsx index 59ea369..8784a73 100644 --- a/src/components/inventory/BatchReportUploadModal.tsx +++ b/src/components/inventory/BatchReportUploadModal.tsx @@ -287,6 +287,7 @@ type ManualPickRow = { sku_name?: string; production_date?: string; inbound_at?: string | null; + created_at?: string | null; available_qty?: number; unit?: string; storage_zone?: string; @@ -375,7 +376,7 @@ const ManualBatchPicker: React.FC<{ {t('inventory.batchReport.candidateBatch')}: {r.batch_no || '—'} - {r.inbound_at ? `${t('inventory.batchReport.inboundAt')} ${r.inbound_at}` : '—'}{r.production_date ? ` · ${t('inventory.col.prodDate')} ${String(r.production_date).slice(0, 10)}` : ''} + {r.inbound_at ? `${t('inventory.batchReport.inboundAt')} ${r.inbound_at}${r.production_date ? ` · ` : ''}` : ''}{r.production_date ? `${t('inventory.col.prodDate')} ${String(r.production_date).slice(0, 10)}` : (r.inbound_at ? '' : '—')} {r.available_qty ?? '—'} {r.unit || ''} @@ -475,7 +476,7 @@ const ReportCard: React.FC<{ {t('inventory.batchReport.candidateBatch')}: {c.batch_no || '—'} - {c.inbound_at ? `${t('inventory.batchReport.inboundAt')} ${c.inbound_at}` : '—'}{c.production_date ? ` · ${t('inventory.col.prodDate')} ${String(c.production_date).slice(0, 10)}` : ''} + {c.inbound_at ? `${t('inventory.batchReport.inboundAt')} ${c.inbound_at}${c.production_date ? ` · ` : ''}` : ''}{c.production_date ? `${t('inventory.col.prodDate')} ${String(c.production_date).slice(0, 10)}` : (c.inbound_at ? '' : '—')} {c.available_qty ?? '—'} {c.unit || ''} diff --git a/src/utils/workflowApi.ts b/src/utils/workflowApi.ts index 34e33bd..aa32b7e 100644 --- a/src/utils/workflowApi.ts +++ b/src/utils/workflowApi.ts @@ -3932,6 +3932,8 @@ export interface InventoryBatchReportCandidate { production_date: string | null; /** 入库时间(列表展示用;2026-10-20 起展示入库时间而非生产日期) */ inbound_at?: string | null; + /** 批次落库时间(解析链路只返回这个字段,前端用它兜底显示"入库时间") */ + created_at?: string | null; available_qty: number | null; unit: string | null; spec: string | null;