Files
qnc-server-v3/deploy/sql/sync_agent_product_config.sql
2025-12-13 17:44:18 +08:00

112 lines
2.5 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================
-- 同步产品表数据到代理产品配置表
-- 说明:为现有产品创建对应的代理产品配置记录
-- 执行时间2025-01-XX
-- ============================================
-- 方式1使用 INSERT IGNORE如果记录已存在则忽略
-- 注意product_name 字段已移除,改为通过 product_id 关联查询 product 表获取
INSERT IGNORE INTO
`agent_product_config` (
`product_id`,
`base_price`,
`system_max_price`,
`price_threshold`,
`price_fee_rate`,
`del_state`,
`version`
)
VALUES (
1,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
2,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
3,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
4,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
5,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
6,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
7,
0.00,
9999.99,
NULL,
NULL,
0,
0
);
-- ============================================
-- 方式2使用 INSERT ... ON DUPLICATE KEY UPDATE如果记录已存在则忽略
-- 注意product_name 字段已移除,不再需要更新
-- ============================================
/*
INSERT INTO `agent_product_config`
(`product_id`, `base_price`, `system_max_price`, `price_threshold`, `price_fee_rate`, `del_state`, `version`)
VALUES
(1, 0.00, 9999.99, NULL, NULL, 0, 0),
(2, 0.00, 9999.99, NULL, NULL, 0, 0),
(3, 0.00, 9999.99, NULL, NULL, 0, 0),
(4, 0.00, 9999.99, NULL, NULL, 0, 0),
(5, 0.00, 9999.99, NULL, NULL, 0, 0),
(6, 0.00, 9999.99, NULL, NULL, 0, 0),
(7, 0.00, 9999.99, NULL, NULL, 0, 0)
ON DUPLICATE KEY UPDATE
`product_id` = VALUES(`product_id`);
*/
-- ============================================
-- 验证查询:检查同步结果
-- ============================================
SELECT apc.id, apc.product_id, p.product_name, apc.base_price, apc.system_max_price, apc.price_threshold, apc.price_fee_rate, apc.del_state, apc.create_time
FROM
`agent_product_config` apc
LEFT JOIN `product` p ON apc.product_id = p.id
AND p.del_state = 0
WHERE
apc.del_state = 0
ORDER BY apc.product_id;