fix(cost-center): 修复接单模板改价 SQL 参数类型推断冲突
同一个 $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,并补源码级回归测试。
This commit is contained in:
@@ -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',
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -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`,
|
||||
|
||||
Reference in New Issue
Block a user