Jelajahi Sumber

分库策略国际化

yubin 3 minggu lalu
induk
melakukan
3bf2f28f6d

+ 4 - 2
mall-service/src/main/java/com/txz/mall/configurer/DatabaseShardingAlgorithm.java

@@ -1,6 +1,8 @@
 package com.txz.mall.configurer;
 
+import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Range;
+import com.txz.mall.util.I18nUtil;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
 import org.springframework.util.ObjectUtils;
@@ -356,7 +358,7 @@ public class DatabaseShardingAlgorithm implements ComplexKeysShardingAlgorithm<C
                     Long userId = Long.parseLong(lastFour);
                     result.put(orderId, Arrays.asList(createTime.getTime(), userId));
                 } catch (ParseException | StringIndexOutOfBoundsException e) {
-                    throw new RuntimeException("解析order_id分库条件失败: " + orderId, e);
+                    throw new RuntimeException(I18nUtil.get("failed.to.parse.the.sharding.condition.for.order.id") + JSONObject.toJSONString(shardingValue), e);
                 }
             }
         }
@@ -581,7 +583,7 @@ public class DatabaseShardingAlgorithm implements ComplexKeysShardingAlgorithm<C
         try {
             return SDF.parse(value.toString());
         } catch (ParseException e) {
-            throw new RuntimeException("时间格式错误: " + value, e);
+            throw new RuntimeException(I18nUtil.get("time.format.error") + value, e);
         }
     }
 

+ 4 - 2
mall-service/src/main/java/com/txz/mall/configurer/StoreOrderInfoDatabaseShardingAlgorithm.java

@@ -1,5 +1,7 @@
 package com.txz.mall.configurer;
 
+import com.alibaba.fastjson.JSONObject;
+import com.txz.mall.util.I18nUtil;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
 import org.springframework.util.ObjectUtils;
@@ -201,7 +203,7 @@ private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:
                     Long userId = Long.parseLong(lastFour);
                     result.put(orderId, Arrays.asList(createTime.getTime(), userId));
                 } catch (ParseException | StringIndexOutOfBoundsException e) {
-                    throw new RuntimeException("解析order_no分库条件失败: " + orderId, e);
+                    throw new RuntimeException(I18nUtil.get("failed.to.parse.the.sharding.condition.for.order.id") + JSONObject.toJSONString(shardingValue), e);
                 }
             }
         }
@@ -426,7 +428,7 @@ private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:
         try {
             return SDF.parse(value.toString());
         } catch (ParseException e) {
-            throw new RuntimeException("时间格式错误: " + value, e);
+            throw new RuntimeException(I18nUtil.get("time.format.error") + value, e);
         }
     }
 

+ 4 - 2
mall-service/src/main/java/com/txz/mall/configurer/StoreOrderInfoTableShardingAlgorithm.java

@@ -1,5 +1,7 @@
 package com.txz.mall.configurer;
 
+import com.alibaba.fastjson.JSONObject;
+import com.txz.mall.util.I18nUtil;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
 
@@ -76,7 +78,7 @@ public class StoreOrderInfoTableShardingAlgorithm implements ComplexKeysSharding
         // 1. 获取所有分表键(每个order_id对应一个)
         Collection<Long> shardingKeys = getShardingKeys(shardingValue);
         if (shardingKeys.isEmpty()) {
-            throw new IllegalArgumentException("分表键不能为空(需uid或order_id)");
+            throw new IllegalArgumentException(I18nUtil.get("the.partition.key.cannot.be.empty.must.include.either.uid.or.order.id")+ JSONObject.toJSONString(shardingValue));
         }
 
         // 2. 每个分表键对应一个表,收集所有匹配的表
@@ -95,7 +97,7 @@ public class StoreOrderInfoTableShardingAlgorithm implements ComplexKeysSharding
 
         // 3. 若没有匹配的表,抛出异常
         if (resultTables.isEmpty()) {
-            throw new IllegalArgumentException("未找到匹配的表: " + availableTargets + ", 分表键: " + shardingKeys);
+            throw new IllegalArgumentException(I18nUtil.get("no.matching.table.found") + availableTargets + I18nUtil.get("table.key") + shardingKeys);
         }
 
         return resultTables;

+ 4 - 2
mall-service/src/main/java/com/txz/mall/configurer/StoreOrderStatusDatabaseShardingAlgorithm.java

@@ -1,5 +1,7 @@
 package com.txz.mall.configurer;
 
+import com.alibaba.fastjson.JSONObject;
+import com.txz.mall.util.I18nUtil;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
 import org.springframework.util.ObjectUtils;
@@ -202,7 +204,7 @@ public class StoreOrderStatusDatabaseShardingAlgorithm implements ComplexKeysSha
                     Long userId = Long.parseLong(lastFour);
                     result.put(orderId, Arrays.asList(createTime.getTime(), userId));
                 } catch (ParseException | StringIndexOutOfBoundsException e) {
-                    throw new RuntimeException("解析order_id分库条件失败: " + orderId, e);
+                    throw new RuntimeException(I18nUtil.get("failed.to.parse.the.sharding.condition.for.order.id") + JSONObject.toJSONString(shardingValue), e);
                 }
             }
         }
@@ -427,7 +429,7 @@ public class StoreOrderStatusDatabaseShardingAlgorithm implements ComplexKeysSha
         try {
             return SDF.parse(value.toString());
         } catch (ParseException e) {
-            throw new RuntimeException("时间格式错误: " + value, e);
+            throw new RuntimeException(I18nUtil.get("time.format.error") + value, e);
         }
     }
 

+ 4 - 2
mall-service/src/main/java/com/txz/mall/configurer/StoreOrderStatusTableShardingAlgorithm.java

@@ -1,5 +1,7 @@
 package com.txz.mall.configurer;
 
+import com.alibaba.fastjson.JSONObject;
+import com.txz.mall.util.I18nUtil;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
 
@@ -79,7 +81,7 @@ private Collection<Long> getShardingKeys(ComplexKeysShardingValue<Comparable<?>>
         // 1. 获取所有分表键(每个order_id对应一个)
         Collection<Long> shardingKeys = getShardingKeys(shardingValue);
         if (shardingKeys.isEmpty()) {
-            throw new IllegalArgumentException("分表键不能为空(需uid或order_id)");
+            throw new IllegalArgumentException(I18nUtil.get("the.partition.key.cannot.be.empty.must.include.either.uid.or.order.id")+ JSONObject.toJSONString(shardingValue));
         }
 
         // 2. 每个分表键对应一个表,收集所有匹配的表
@@ -98,7 +100,7 @@ private Collection<Long> getShardingKeys(ComplexKeysShardingValue<Comparable<?>>
 
         // 3. 若没有匹配的表,抛出异常
         if (resultTables.isEmpty()) {
-            throw new IllegalArgumentException("未找到匹配的表: " + availableTargets + ", 分表键: " + shardingKeys);
+            throw new IllegalArgumentException(I18nUtil.get("no.matching.table.found") + availableTargets + I18nUtil.get("table.key") + shardingKeys);
         }
 
         return resultTables;

+ 2 - 1
mall-service/src/main/java/com/txz/mall/configurer/StorePinkSummaryTableShardingAlgorithm.java

@@ -1,5 +1,6 @@
 package com.txz.mall.configurer;
 
+import com.txz.mall.util.I18nUtil;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
 
@@ -44,7 +45,7 @@ public class StorePinkSummaryTableShardingAlgorithm implements ComplexKeysShardi
                 return list;
             }
         }
-        throw new IllegalArgumentException("未找到匹配的表: " + availableTargets + ", 分片值: " + userId);
+        throw new IllegalArgumentException(I18nUtil.get("no.matching.table.found") + availableTargets + I18nUtil.get("table.key") + userId);
 
     }
 

+ 4 - 2
mall-service/src/main/java/com/txz/mall/configurer/TableShardingAlgorithm.java

@@ -1,5 +1,7 @@
 package com.txz.mall.configurer;
 
+import com.alibaba.fastjson.JSONObject;
+import com.txz.mall.util.I18nUtil;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
 
@@ -83,7 +85,7 @@ public class TableShardingAlgorithm implements ComplexKeysShardingAlgorithm<Comp
         // 1. 获取所有分表键(每个order_id对应一个)
         Collection<Long> shardingKeys = getShardingKeys(shardingValue);
         if (shardingKeys.isEmpty()) {
-            throw new IllegalArgumentException("分表键不能为空(需uid或order_id)");
+            throw new IllegalArgumentException(I18nUtil.get("the.partition.key.cannot.be.empty.must.include.either.uid.or.order.id")+ JSONObject.toJSONString(shardingValue));
         }
 
         // 2. 每个分表键对应一个表,收集所有匹配的表
@@ -102,7 +104,7 @@ public class TableShardingAlgorithm implements ComplexKeysShardingAlgorithm<Comp
 
         // 3. 若没有匹配的表,抛出异常
         if (resultTables.isEmpty()) {
-            throw new IllegalArgumentException("未找到匹配的表: " + availableTargets + ", 分表键: " + shardingKeys);
+            throw new IllegalArgumentException(I18nUtil.get("no.matching.table.found") + availableTargets + I18nUtil.get("table.key") + shardingKeys);
         }
 
         return resultTables;

+ 2 - 1
mall-service/src/main/java/com/txz/mall/configurer/UserSignTableShardingAlgorithm.java

@@ -1,5 +1,6 @@
 package com.txz.mall.configurer;
 
+import com.txz.mall.util.I18nUtil;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
 
@@ -37,7 +38,7 @@ public class UserSignTableShardingAlgorithm implements ComplexKeysShardingAlgori
                 return list;
             }
         }
-        throw new IllegalArgumentException("未找到匹配的表: " + availableTargets + ", 分片值: " + userId);
+        throw new IllegalArgumentException(I18nUtil.get("no.matching.table.found") + availableTargets + I18nUtil.get("table.key") + userId);
 
     }
 

+ 7 - 1
mall-service/src/main/resources/i18n/messages_en_US.properties

@@ -172,4 +172,10 @@ the.group.buying.summary.data.does.not.exist=the group buying summary data does
 store.pink.summary.order.no.set.not.exist=store pink summary order no set not exist
 order.code.is.empty=order code is empty
 cid.store.pink.summary.order.no.set.not.exist=cid store pink summary order no set not exist
-the.order.number.cannot.be.empty=the order number cannot be empty
+the.order.number.cannot.be.empty=the order number cannot be empty
+
+failed.to.parse.the.sharding.condition.for.order.id=failed to parse the sharding condition for order id
+time.format.error=time format error
+the.partition.key.cannot.be.empty.must.include.either.uid.or.order.id=the partition key cannot be empty must include either uid or order id
+no.matching.table.found=no matching table found:
+table.key=, table key:

+ 5 - 0
mall-service/src/main/resources/i18n/messages_zh_CN.properties

@@ -170,4 +170,9 @@ order.code.is.empty=\u8BA2\u5355\u7F16\u7801\u4E3A\u7A7A
 cid.store.pink.summary.order.no.set.not.exist=\u4F7F\u7528cid\u7684\u67E5\u8BE2pinksummary\u83B7\u53D6\u5230\u5230orderNoSet\u5168\u4E3A\u7A7A
 
 the.order.number.cannot.be.empty=\u8BA2\u5355\u53F7\u4E0D\u80FD\u4E3A\u7A7A
+failed.to.parse.the.sharding.condition.for.order.id=\u89E3\u6790order_id\u5206\u5E93\u6761\u4EF6\u5931\u8D25
+time.format.error=\u65F6\u95F4\u683C\u5F0F\u9519\u8BEF:
+the.partition.key.cannot.be.empty.must.include.either.uid.or.order.id=\u5206\u8868\u952E\u4E0D\u80FD\u4E3A\u7A7A\uFF08\u9700uid\u6216order_id\uFF09
+no.matching.table.found=\u672A\u627E\u5230\u5339\u914D\u7684\u8868:
+table.key=, \u5206\u8868\u952E: