From 6a972c54fe99a186b5885db1b1319643ce9679dd Mon Sep 17 00:00:00 2001
From: shinnosuke <tantao@1hoper.com>
Date: 星期三, 26 八月 2026 18:43:38 +0800
Subject: [PATCH] 又又更新

---
 talent-card-server/src/main/java/com/talentcard/server/business/merchant/BankBranchDirectoryInitializer.java |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/talent-card-server/src/main/java/com/talentcard/server/business/merchant/BankBranchDirectoryInitializer.java b/talent-card-server/src/main/java/com/talentcard/server/business/merchant/BankBranchDirectoryInitializer.java
index c0386ad..f8a7bd5 100644
--- a/talent-card-server/src/main/java/com/talentcard/server/business/merchant/BankBranchDirectoryInitializer.java
+++ b/talent-card-server/src/main/java/com/talentcard/server/business/merchant/BankBranchDirectoryInitializer.java
@@ -34,6 +34,7 @@
     public void run(ApplicationArguments args) {
         try {
             ensureBankCardBranchCodeColumn();
+            ensureBankCardHistoryIndex();
             ensureDirectoryTable();
             importDirectoryIfEmpty();
         } catch (Exception exception) {
@@ -46,6 +47,27 @@
         jdbc.execute("alter table merchant_bank_card add column branch_code varchar(12) default null after branch_name");
     }
 
+    private void ensureBankCardHistoryIndex() {
+        Integer nonUnique = jdbc.query("""
+                select non_unique from information_schema.statistics
+                where table_schema = database() and table_name = 'merchant_bank_card'
+                  and index_name = 'uk_merchant_bank_card_hash'
+                limit 1
+                """, result -> result.next() ? result.getInt("non_unique") : null);
+        if (nonUnique != null && nonUnique == 0) {
+            jdbc.execute("alter table merchant_bank_card drop index uk_merchant_bank_card_hash");
+        }
+        Integer historyIndex = jdbc.query("""
+                select 1 from information_schema.statistics
+                where table_schema = database() and table_name = 'merchant_bank_card'
+                  and index_name = 'idx_merchant_bank_card_hash'
+                limit 1
+                """, result -> result.next() ? 1 : null);
+        if (historyIndex == null) {
+            jdbc.execute("create index idx_merchant_bank_card_hash on merchant_bank_card(merchant_id, card_hash)");
+        }
+    }
+
     private void ensureDirectoryTable() {
         jdbc.execute("""
                 create table if not exists bank_branch_directory (

--
Gitblit v1.7.1