From f6ba3e15355e22767e69f8fc14ae22523f8db8dc Mon Sep 17 00:00:00 2001
From: 44323 <443237572@qq.com>
Date: 星期三, 22 十一月 2023 19:33:58 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/PlayPai

---
 cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java |   47 +++++++++++++++++++++++++++++++----------------
 1 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java b/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java
index e0ef0b4..eb205d6 100644
--- a/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java
+++ b/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java
@@ -73,34 +73,36 @@
         props1.setProperty("algorithm-expression", "t_course_package_payment$->{appUserId % 5 + 1}");
         result1.getShardingAlgorithms().put("t_course_package_payment-inline", new AlgorithmConfiguration("INLINE", props1));
         result1.getKeyGenerators().put("t_course_package_payment-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
-        linkedList.add(result1);
 
         //分片规则配置
-        ShardingRuleConfiguration result2 = new ShardingRuleConfiguration();
-        result2.getTables().add(getCoursePackageStudentTableRuleConfiguration());
+        result1.getTables().add(getCoursePackageStudentTableRuleConfiguration());
         Properties props2 = new Properties();
         props2.setProperty("algorithm-expression", "t_course_package_student$->{appUserId % 5 + 1}");
-        result2.getShardingAlgorithms().put("t_course_package_student-inline", new AlgorithmConfiguration("INLINE", props2));
-        result2.getKeyGenerators().put("t_course_package_student-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
-        linkedList.add(result2);
+        result1.getShardingAlgorithms().put("t_course_package_student-inline", new AlgorithmConfiguration("INLINE", props2));
+        result1.getKeyGenerators().put("t_course_package_student-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
 
         //分片规则配置
-        ShardingRuleConfiguration result3 = new ShardingRuleConfiguration();
-        result3.getTables().add(getPostCourseVideoTableRuleConfiguration());
+        result1.getTables().add(getPostCourseVideoTableRuleConfiguration());
         Properties props3 = new Properties();
         props3.setProperty("algorithm-expression", "t_post_course_video$->{coursePackageId % 5 + 1}");
-        result3.getShardingAlgorithms().put("t_post_course_video-inline", new AlgorithmConfiguration("INLINE", props3));
-        result3.getKeyGenerators().put("t_post_course_video-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
-        linkedList.add(result3);
+        result1.getShardingAlgorithms().put("t_post_course_video-inline", new AlgorithmConfiguration("INLINE", props3));
+        result1.getKeyGenerators().put("t_post_course_video-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
 
         //分片规则配置
-        ShardingRuleConfiguration result4 = new ShardingRuleConfiguration();
-        result4.getTables().add(getUserVideoDetailsTableRuleConfiguration());
+        result1.getTables().add(getUserVideoDetailsTableRuleConfiguration());
         Properties props4 = new Properties();
         props4.setProperty("algorithm-expression", "t_user_video_details$->{appUserId % 5 + 1}");
-        result4.getShardingAlgorithms().put("t_user_video_details-inline", new AlgorithmConfiguration("INLINE", props4));
-        result4.getKeyGenerators().put("t_user_video_details-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
-        linkedList.add(result4);
+        result1.getShardingAlgorithms().put("t_user_video_details-inline", new AlgorithmConfiguration("INLINE", props4));
+        result1.getKeyGenerators().put("t_user_video_details-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
+
+        //分片规则配置
+        result1.getTables().add(getCoursePackageSchedulingTableRuleConfiguration());
+        Properties props5 = new Properties();
+        props5.setProperty("algorithm-expression", "t_course_package_scheduling$->{coursePackageId % 5 + 1}");
+        result1.getShardingAlgorithms().put("t_course_package_scheduling-inline", new AlgorithmConfiguration("INLINE", props5));
+        result1.getKeyGenerators().put("t_course_package_scheduling-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
+
+        linkedList.add(result1);
 
         return linkedList;
     }
@@ -131,6 +133,7 @@
 
 
 
+
     /**
      * 分片算法配置
      * @return
@@ -155,4 +158,16 @@
         return result;
     }
 
+
+    /**
+     * 分片算法配置
+     * @return
+     */
+    private ShardingTableRuleConfiguration getCoursePackageSchedulingTableRuleConfiguration() {
+        ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_scheduling", "m_$->{0}.t_course_package_scheduling$->{1..5}");//30
+        result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("coursePackageId", "t_course_package_scheduling-inline"));
+        result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_course_package_scheduling-snowflake"));
+        return result;
+    }
+
 }

--
Gitblit v1.7.1