lisy
2023-07-10 a6ef8f0dd977a30abd878f8e6106630b97d6e5b0
cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java
@@ -73,15 +73,16 @@
        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);
        //分片规则配置
        result1.getTables().add(getCoursePackageStudentTableRuleConfiguration());
        ShardingRuleConfiguration result2 = new ShardingRuleConfiguration();
        result2.getTables().add(getCoursePackageStudentTableRuleConfiguration());
        Properties props2 = new Properties();
        props2.setProperty("algorithm-expression", "t_course_package_student$->{appUserId % 5 + 1}");
        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()));
        linkedList.add(result1);
        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);
        return linkedList;
    }
@@ -91,7 +92,7 @@
     * @return
     */
    private ShardingTableRuleConfiguration getCoursePackagePaymentTableRuleConfiguration() {
        ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_payment", "m$->{0}.t_course_package_payment$->{1..5}");//50
        ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_payment", "m_$->{0}.t_course_package_payment$->{1..5}");//50
        result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("appUserId", "t_course_package_payment-inline"));
        result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_course_package_payment-snowflake"));
        return result;
@@ -104,7 +105,7 @@
     * @return
     */
    private ShardingTableRuleConfiguration getCoursePackageStudentTableRuleConfiguration() {
        ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_student", "m$->{0}.t_course_package_student$->{1..5}");//30
        ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_student", "m_$->{0}.t_course_package_student$->{1..5}");//30
        result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("appUserId", "t_course_package_student-inline"));
        result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_course_package_student-snowflake"));
        return result;