合并账户库为单表

This commit is contained in:
wkc
2026-04-17 10:18:13 +08:00
parent cc1a4538af
commit 4c6ca52e7e
24 changed files with 1285 additions and 377 deletions

View File

@@ -11,6 +11,15 @@ INSERT INTO ccdi_account_info (
bank,
bank_code,
currency,
is_self_account,
monthly_avg_trans_count,
monthly_avg_trans_amount,
trans_freq_type,
dr_max_single_amount,
cr_max_single_amount,
dr_max_daily_amount,
cr_max_daily_amount,
trans_risk_level,
status,
effective_date,
invalid_date,
@@ -28,32 +37,6 @@ SELECT
'HZLH001',
'CNY',
1,
'2026-04-13',
NULL,
'system',
'system'
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM ccdi_account_info WHERE account_no = '622202440000010001'
);
INSERT INTO ccdi_account_result (
account_no,
is_self_account,
monthly_avg_trans_count,
monthly_avg_trans_amount,
trans_freq_type,
dr_max_single_amount,
cr_max_single_amount,
dr_max_daily_amount,
cr_max_daily_amount,
trans_risk_level,
create_by,
update_by
)
SELECT
'622202440000010001',
1,
12,
28600.00,
'MEDIUM',
@@ -62,11 +45,14 @@ SELECT
16000.00,
22000.00,
'MEDIUM',
1,
'2026-04-13',
NULL,
'system',
'system'
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM ccdi_account_result WHERE account_no = '622202440000010001'
SELECT 1 FROM ccdi_account_info WHERE account_no = '622202440000010001'
);
INSERT INTO ccdi_account_info (
@@ -79,6 +65,15 @@ INSERT INTO ccdi_account_info (
bank,
bank_code,
currency,
is_self_account,
monthly_avg_trans_count,
monthly_avg_trans_amount,
trans_freq_type,
dr_max_single_amount,
cr_max_single_amount,
dr_max_daily_amount,
cr_max_daily_amount,
trans_risk_level,
status,
effective_date,
invalid_date,
@@ -95,32 +90,6 @@ SELECT
'国泰君安杭州营业部',
'GTJAHZ01',
'CNY',
1,
'2026-04-13',
NULL,
'system',
'system'
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM ccdi_account_info WHERE account_no = 'ZQ330101199104010101'
);
INSERT INTO ccdi_account_result (
account_no,
is_self_account,
monthly_avg_trans_count,
monthly_avg_trans_amount,
trans_freq_type,
dr_max_single_amount,
cr_max_single_amount,
dr_max_daily_amount,
cr_max_daily_amount,
trans_risk_level,
create_by,
update_by
)
SELECT
'ZQ330101199104010101',
0,
6,
152000.00,
@@ -130,11 +99,14 @@ SELECT
98000.00,
116000.00,
'HIGH',
1,
'2026-04-13',
NULL,
'system',
'system'
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM ccdi_account_result WHERE account_no = 'ZQ330101199104010101'
SELECT 1 FROM ccdi_account_info WHERE account_no = 'ZQ330101199104010101'
);
INSERT INTO ccdi_account_info (
@@ -147,6 +119,15 @@ INSERT INTO ccdi_account_info (
bank,
bank_code,
currency,
is_self_account,
monthly_avg_trans_count,
monthly_avg_trans_amount,
trans_freq_type,
dr_max_single_amount,
cr_max_single_amount,
dr_max_daily_amount,
cr_max_daily_amount,
trans_risk_level,
status,
effective_date,
invalid_date,
@@ -163,32 +144,6 @@ SELECT
'支付宝',
'ALIPAY',
'CNY',
1,
'2026-04-13',
NULL,
'system',
'system'
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM ccdi_account_info WHERE account_no = '13700000035'
);
INSERT INTO ccdi_account_result (
account_no,
is_self_account,
monthly_avg_trans_count,
monthly_avg_trans_amount,
trans_freq_type,
dr_max_single_amount,
cr_max_single_amount,
dr_max_daily_amount,
cr_max_daily_amount,
trans_risk_level,
create_by,
update_by
)
SELECT
'13700000035',
0,
18,
46800.00,
@@ -198,11 +153,14 @@ SELECT
18800.00,
21600.00,
'LOW',
1,
'2026-04-13',
NULL,
'system',
'system'
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM ccdi_account_result WHERE account_no = '13700000035'
SELECT 1 FROM ccdi_account_info WHERE account_no = '13700000035'
);
INSERT INTO ccdi_account_info (
@@ -215,6 +173,15 @@ INSERT INTO ccdi_account_info (
bank,
bank_code,
currency,
is_self_account,
monthly_avg_trans_count,
monthly_avg_trans_amount,
trans_freq_type,
dr_max_single_amount,
cr_max_single_amount,
dr_max_daily_amount,
cr_max_daily_amount,
trans_risk_level,
status,
effective_date,
invalid_date,
@@ -231,32 +198,6 @@ SELECT
'微信支付',
'WXPAY',
'CNY',
1,
'2026-04-13',
NULL,
'system',
'system'
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM ccdi_account_info WHERE account_no = 'wx-ext-20260413-001'
);
INSERT INTO ccdi_account_result (
account_no,
is_self_account,
monthly_avg_trans_count,
monthly_avg_trans_amount,
trans_freq_type,
dr_max_single_amount,
cr_max_single_amount,
dr_max_daily_amount,
cr_max_daily_amount,
trans_risk_level,
create_by,
update_by
)
SELECT
'wx-ext-20260413-001',
0,
9,
9800.00,
@@ -266,9 +207,12 @@ SELECT
5600.00,
7000.00,
'LOW',
1,
'2026-04-13',
NULL,
'system',
'system'
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM ccdi_account_result WHERE account_no = 'wx-ext-20260413-001'
SELECT 1 FROM ccdi_account_info WHERE account_no = 'wx-ext-20260413-001'
);

View File

@@ -0,0 +1,31 @@
SET @ccdi_account_info_is_self_account_sql = IF(
EXISTS(
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'is_self_account'
),
'SELECT 1',
'ALTER TABLE `ccdi_account_info` ADD COLUMN `is_self_account` TINYINT NOT NULL DEFAULT 1 COMMENT ''是否本人账户'' AFTER `currency`'
);
PREPARE ccdi_account_info_is_self_account_stmt FROM @ccdi_account_info_is_self_account_sql;
EXECUTE ccdi_account_info_is_self_account_stmt;
DEALLOCATE PREPARE ccdi_account_info_is_self_account_stmt;
SET @ccdi_account_info_trans_risk_level_sql = IF(
EXISTS(
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'trans_risk_level'
),
'SELECT 1',
'ALTER TABLE `ccdi_account_info` ADD COLUMN `trans_risk_level` VARCHAR(32) DEFAULT NULL COMMENT ''交易风险等级'' AFTER `is_self_account`'
);
PREPARE ccdi_account_info_trans_risk_level_stmt FROM @ccdi_account_info_trans_risk_level_sql;
EXECUTE ccdi_account_info_trans_risk_level_stmt;
DEALLOCATE PREPARE ccdi_account_info_trans_risk_level_stmt;

View File

@@ -0,0 +1,156 @@
-- 合并账户库双表:将 ccdi_account_result 分析字段并回 ccdi_account_info并删除旧表。
-- 执行说明:涉及中文内容时请使用 bin/mysql_utf8_exec.sh 执行,确保会话字符集为 utf8mb4。
DELIMITER //
DROP PROCEDURE IF EXISTS `merge_ccdi_account_result_into_info`//
CREATE PROCEDURE `merge_ccdi_account_result_into_info`()
BEGIN
DECLARE duplicate_count INT DEFAULT 0;
DECLARE result_table_exists INT DEFAULT 0;
SELECT COUNT(*)
INTO duplicate_count
FROM (
SELECT account_no
FROM ccdi_account_info
WHERE account_no IS NOT NULL
AND account_no <> ''
GROUP BY account_no
HAVING COUNT(*) > 1
) duplicated_accounts;
IF duplicate_count > 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'ccdi_account_info.account_no 存在重复数据,禁止执行账户库合表迁移。';
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'is_self_account'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `is_self_account` TINYINT NOT NULL DEFAULT 1 COMMENT '是否本人账户' AFTER `currency`;
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'monthly_avg_trans_count'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `monthly_avg_trans_count` INT DEFAULT NULL COMMENT '月均交易笔数' AFTER `is_self_account`;
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'monthly_avg_trans_amount'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `monthly_avg_trans_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '月均交易金额' AFTER `monthly_avg_trans_count`;
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'trans_freq_type'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `trans_freq_type` VARCHAR(32) DEFAULT NULL COMMENT '交易频率类型' AFTER `monthly_avg_trans_amount`;
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'dr_max_single_amount'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `dr_max_single_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '最大单笔支出金额' AFTER `trans_freq_type`;
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'cr_max_single_amount'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `cr_max_single_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '最大单笔收入金额' AFTER `dr_max_single_amount`;
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'dr_max_daily_amount'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `dr_max_daily_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '最大单日支出金额' AFTER `cr_max_single_amount`;
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'cr_max_daily_amount'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `cr_max_daily_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '最大单日收入金额' AFTER `dr_max_daily_amount`;
END IF;
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_info'
AND column_name = 'trans_risk_level'
) THEN
ALTER TABLE `ccdi_account_info`
ADD COLUMN `trans_risk_level` VARCHAR(32) DEFAULT NULL COMMENT '交易风险等级' AFTER `cr_max_daily_amount`;
END IF;
SELECT COUNT(*)
INTO result_table_exists
FROM information_schema.tables
WHERE table_schema = DATABASE()
AND table_name = 'ccdi_account_result';
IF result_table_exists > 0 THEN
UPDATE `ccdi_account_info` ai
JOIN `ccdi_account_result` ar
ON ai.account_no = ar.account_no
SET ai.is_self_account = ar.is_self_account,
ai.monthly_avg_trans_count = ar.monthly_avg_trans_count,
ai.monthly_avg_trans_amount = ar.monthly_avg_trans_amount,
ai.trans_freq_type = ar.trans_freq_type,
ai.dr_max_single_amount = ar.dr_max_single_amount,
ai.cr_max_single_amount = ar.cr_max_single_amount,
ai.dr_max_daily_amount = ar.dr_max_daily_amount,
ai.cr_max_daily_amount = ar.cr_max_daily_amount,
ai.trans_risk_level = ar.trans_risk_level,
ai.update_by = COALESCE(ar.update_by, ai.update_by),
ai.update_time = COALESCE(ar.update_time, ai.update_time);
DROP TABLE `ccdi_account_result`;
END IF;
END//
CALL `merge_ccdi_account_result_into_info`()//
DROP PROCEDURE IF EXISTS `merge_ccdi_account_result_into_info`//
DELIMITER ;