From 5b101a3023713250404616482cd1e4b536d59b8f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 27 Oct 2026 21:28:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=BA=93=E5=AD=98=E6=8A=B5=E6=89=A3):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=B9=E6=89=B9=E6=AC=A1=E6=88=90=E6=9C=AC?= =?UTF-8?q?=E9=87=8D=E7=AE=97=20SQL=20=E6=8B=AC=E5=8F=B7/=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=B1=BB=E5=9E=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UPDATE cover_qty 子查询多一个右括号;补记账本 INSERT 的 / 显式 text 转换,避免 inconsistent types deduced。已在本地同事务重放通过。 --- .../src/services/inventoryBatchCostService.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/src/services/inventoryBatchCostService.ts b/server/src/services/inventoryBatchCostService.ts index 0260aef..c0efead 100644 --- a/server/src/services/inventoryBatchCostService.ts +++ b/server/src/services/inventoryBatchCostService.ts @@ -361,9 +361,9 @@ export async function recalcCoverLedgerForBatchCostChange( SET amount = $3::numeric, allocated_amount = $3::numeric, cover_qty = ( SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) - FROM order_items WHERE order_code = $1 AND sku_code = $2 - )) - WHERE order_code = $1 AND sku_code = $2 AND cost_source = 'inventory_cover'`, + FROM order_items WHERE order_code = $1::text AND sku_code = $2::text + ) + WHERE order_code = $1::text AND sku_code = $2::text AND cost_source = 'inventory_cover'`, [row.order_code, row.sku_code, row.after_amount] ); if ((updated.rowCount || 0) === 0 && Number(row.after_amount) > 0) { @@ -377,8 +377,8 @@ export async function recalcCoverLedgerForBatchCostChange( `INSERT INTO cost_details ( cycle_code, order_code, cost_type, cost_subtype, amount, allocated_amount, status, branch_code, sku_code, cost_source, remark, cover_qty - ) VALUES ($1, $2, 'purchase', 'stock_cover', $3, $3, 20, $4, $5, 'inventory_cover', 'stock_cover', - (SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2 AND sku_code = $5))`, + ) VALUES ($1, $2::text, 'purchase', 'stock_cover', $3, $3, 20, $4, $5::text, 'inventory_cover', 'stock_cover', + (SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2::text AND sku_code = $5::text))`, [cycleCode, row.order_code, row.after_amount, branch, row.sku_code] ); } @@ -471,8 +471,8 @@ export async function repairMissingCoverLedger(input: { SET amount = $2::numeric, allocated_amount = $2::numeric, cover_qty = ( SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) - FROM order_items WHERE order_code = $3 AND sku_code = $4 - )) + FROM order_items WHERE order_code = $3::text AND sku_code = $4::text + ) WHERE id = $1`, [existing.rows[0].id, amount, code, sku] ); @@ -489,8 +489,8 @@ export async function repairMissingCoverLedger(input: { `INSERT INTO cost_details ( cycle_code, order_code, cost_type, cost_subtype, amount, allocated_amount, status, branch_code, sku_code, cost_source, remark, cover_qty - ) VALUES ($1, $2, 'purchase', 'stock_cover', $3, $3, 20, $4, $5, 'inventory_cover', 'stock_cover', - (SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2 AND sku_code = $5))`, + ) VALUES ($1, $2::text, 'purchase', 'stock_cover', $3, $3, 20, $4, $5::text, 'inventory_cover', 'stock_cover', + (SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2::text AND sku_code = $5::text))`, [ trim(meta.rows[0]?.cycle_code) || '0000', code,