From 16b62a8e6d674a95122fdabd386f9a5a3b441615 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Thu, 29 Oct 2026 14:38:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(cost-center):=20=E4=BF=AE=E5=A4=8D=E6=8E=A5?= =?UTF-8?q?=E5=8D=95=E6=A8=A1=E6=9D=BF=E6=94=B9=E4=BB=B7=20SQL=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=B1=BB=E5=9E=8B=E6=8E=A8=E6=96=AD=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 同一个 $1 在 reward_amount 处按 bigint 推断,在 CASE ... THEN $1 ELSE 0 处 因字面量 0 被推断成 integer,node-pg 不发送参数类型时 PostgreSQL 直接报 inconsistent types deduced for parameter $1,导致改价 500。 显式写成 $1::bigint / 0::bigint,并补源码级回归测试。 --- .../services/cost-center/cost-center.test.ts | 17 +++++++++++++++++ .../cost-center/product-catalog-service.ts | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/services/cost-center/cost-center.test.ts b/apps/backend/src/services/cost-center/cost-center.test.ts index 728cdbaa..832575d7 100644 --- a/apps/backend/src/services/cost-center/cost-center.test.ts +++ b/apps/backend/src/services/cost-center/cost-center.test.ts @@ -272,3 +272,20 @@ test('mapping lookup follows specificity and concrete-shop priority', () => { 50, ) }) + +/** + * 2026-10-29 生产:改「接单模板」商品价格 500。 + * + * PostgreSQL 报 `inconsistent types deduced for parameter $1`(integer versus bigint): + * 同一个 $1 在 `reward_amount = $1` 处按 bigint 推断,在 `CASE ... THEN $1 ELSE 0` + * 处又因为 `0` 是 integer 被推断成 integer。node-pg 不发送参数类型,必须显式转换。 + */ +test('接单模板改价 SQL 的参数必须显式指定 bigint', async () => { + const { readFile } = await import('node:fs/promises') + const source = await readFile(new URL('./product-catalog-service.ts', import.meta.url), 'utf8') + assert.ok( + source.includes( + 'unit_price_fen = CASE WHEN unit_price_fen > 0 THEN $1::bigint ELSE 0::bigint END', + ), + ) +}) diff --git a/apps/backend/src/services/cost-center/product-catalog-service.ts b/apps/backend/src/services/cost-center/product-catalog-service.ts index 1f8e5577..cca1d79f 100644 --- a/apps/backend/src/services/cost-center/product-catalog-service.ts +++ b/apps/backend/src/services/cost-center/product-catalog-service.ts @@ -1471,8 +1471,8 @@ export async function setAdminProductPrice( if (rule) { await query( `UPDATE work_product_rules - SET reward_amount = $1, - unit_price_fen = CASE WHEN unit_price_fen > 0 THEN $1 ELSE 0 END, + SET reward_amount = $1::bigint, + unit_price_fen = CASE WHEN unit_price_fen > 0 THEN $1::bigint ELSE 0::bigint END, cost_item_id = $2, updated_at = $3 WHERE id = $4`,