|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Bean | 
|---|
|  |  |  | public DataSource getDataSource(){ | 
|---|
|  |  |  | public DataSource getDataSource() { | 
|---|
|  |  |  | DataSource dataSource = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Properties properties = new Properties(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 配置多数据源 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Map<String, DataSource> createDataSourceMap() { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分片配置 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Collection<RuleConfiguration> createShardingRuleConfiguration() { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //分片规则配置 | 
|---|
|  |  |  | ShardingRuleConfiguration result1 = new ShardingRuleConfiguration(); | 
|---|
|  |  |  | result1.getTables().add(gettCoursePackagePaymentTableRuleConfiguration()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | result1.getTables().add(getCoursePackagePaymentTableRuleConfiguration()); | 
|---|
|  |  |  | Properties props1 = new Properties(); | 
|---|
|  |  |  | props1.setProperty("algorithm-expression", "t_course_package_payment$->{appUserId % 5 + 1}"); | 
|---|
|  |  |  | result1.getShardingAlgorithms().put("t_course_package_payment-inline", new AlgorithmConfiguration("INLINE", props1)); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //分片规则配置 | 
|---|
|  |  |  | result1.getTables().add(getPostCourseVideoTableRuleConfiguration()); | 
|---|
|  |  |  | Properties props3 = new Properties(); | 
|---|
|  |  |  | props3.setProperty("algorithm-expression", "t_post_course_video$->{coursePackageId % 5 + 1}"); | 
|---|
|  |  |  | 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())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //分片规则配置 | 
|---|
|  |  |  | result1.getTables().add(getUserVideoDetailsTableRuleConfiguration()); | 
|---|
|  |  |  | Properties props4 = new Properties(); | 
|---|
|  |  |  | props4.setProperty("algorithm-expression", "t_user_video_details$->{appUserId % 5 + 1}"); | 
|---|
|  |  |  | 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())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //分片规则配置 | 
|---|
|  |  |  | result1.getTables().add(getCoursePackageOrderTableRuleConfiguration()); | 
|---|
|  |  |  | Properties props6 = new Properties(); | 
|---|
|  |  |  | props6.setProperty("algorithm-expression", "t_course_package_order$->{appUserId % 5 + 1}"); | 
|---|
|  |  |  | result1.getShardingAlgorithms().put("t_course_package_order-inline", new AlgorithmConfiguration("INLINE", props6)); | 
|---|
|  |  |  | result1.getKeyGenerators().put("t_course_package_order-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | linkedList.add(result1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return linkedList; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分片算法配置 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private ShardingTableRuleConfiguration gettCoursePackagePaymentTableRuleConfiguration() { | 
|---|
|  |  |  | ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_payment", "m$->{0}.t_course_package_payment$->{1..5}");//50 | 
|---|
|  |  |  | private ShardingTableRuleConfiguration getCoursePackagePaymentTableRuleConfiguration() { | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分片算法配置 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分片算法配置 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private ShardingTableRuleConfiguration getPostCourseVideoTableRuleConfiguration() { | 
|---|
|  |  |  | ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_post_course_video", "m_$->{0}.t_post_course_video$->{1..5}");//30 | 
|---|
|  |  |  | result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("coursePackageId", "t_post_course_video-inline")); | 
|---|
|  |  |  | result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_post_course_video-snowflake")); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分片算法配置 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private ShardingTableRuleConfiguration getUserVideoDetailsTableRuleConfiguration() { | 
|---|
|  |  |  | ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_user_video_details", "m_$->{0}.t_user_video_details$->{1..5}");//30 | 
|---|
|  |  |  | result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("appUserId", "t_user_video_details-inline")); | 
|---|
|  |  |  | result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_user_video_details-snowflake")); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分片算法配置 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private ShardingTableRuleConfiguration getCoursePackageOrderTableRuleConfiguration() { | 
|---|
|  |  |  | ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_order", "m_$->{0}.t_course_package_order$->{1..5}");//30 | 
|---|
|  |  |  | result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("appUserId", "t_course_package_order-inline")); | 
|---|
|  |  |  | result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_course_package_order-snowflake")); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|