| | |
| | | |
| | | |
| | | @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() { |
| | |
| | | props3.setProperty("algorithm-expression", "t_user_benefits_videos$->{appUserId % 5 + 1}"); |
| | | result1.getShardingAlgorithms().put("t_user_benefits_videos-inline", new AlgorithmConfiguration("INLINE", props3)); |
| | | result1.getKeyGenerators().put("t_user_benefits_videos-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); |
| | | linkedList.add(result1); |
| | | |
| | | result1.getTables().add(getUserCouponTableRulePaymentConfiguration()); |
| | | Properties props4 = new Properties(); |
| | | props4.setProperty("algorithm-expression", "t_user_coupon_payment$->{userId % 5 + 1}"); |
| | | result1.getShardingAlgorithms().put("t_user_coupon_payment-inline", new AlgorithmConfiguration("INLINE", props4)); |
| | | result1.getKeyGenerators().put("t_user_coupon_payment-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); |
| | | linkedList.add(result1); |
| | | return linkedList; |
| | | } |
| | | |
| | | /** |
| | | * 分片算法配置 |
| | | * |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration getUserCouponTableRuleConfiguration() { |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 分片算法配置 |
| | | * |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration getUserPointsMerchandiseTableRuleConfiguration() { |
| | |
| | | |
| | | /** |
| | | * 分片算法配置 |
| | | * |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration getUserBenefitsVideosTableRuleConfiguration() { |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 分片算法配置 |
| | | * |
| | | * @return |
| | | */ |
| | | private ShardingTableRuleConfiguration getUserCouponTableRulePaymentConfiguration() { |
| | | ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_user_coupon_payment", "m_$->{0}.t_user_coupon_payment$->{1..5}");//50 |
| | | result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("userId", "t_user_coupon_payment-inline")); |
| | | result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_user_coupon_payment-snowflake")); |
| | | return result; |
| | | } |
| | | |
| | | } |