You've already forked FrameTour-BE
- 移除 ClickHouseStatsMapper 接口及 XML 映射文件 - 使用 NamedParameterJdbcTemplate 替代 MyBatis 实现数据查询 - 添加日期格式化工具类处理 ClickHouse 时间格式 - 重构所有统计查询方法使用原生 SQL 字符串构建 - 添加 MySQL 主数据源配置确保多数据源正确配置 - 升级 ClickHouse JDBC 驱动版本到 0.8.5 - 解决 0.6.x 版本参数绑定问题通过手动 SQL 构建 - 保持原有查询逻辑不变仅改变实现方式
42 lines
1.3 KiB
Java
42 lines
1.3 KiB
Java
package com.ycwl.basic.config;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
/**
|
|
* MySQL 主数据源配置
|
|
*
|
|
* 当 ClickHouse 启用时,需要显式配置 MySQL 数据源并标记为 @Primary,
|
|
* 以确保 MyBatis-Plus 和其他组件使用正确的数据源
|
|
*/
|
|
@Configuration
|
|
@ConditionalOnProperty(prefix = "clickhouse", name = "enabled", havingValue = "true")
|
|
public class MySqlPrimaryDataSourceConfig {
|
|
|
|
/**
|
|
* MySQL 数据源属性
|
|
*/
|
|
@Primary
|
|
@Bean
|
|
@ConfigurationProperties(prefix = "spring.datasource")
|
|
public DataSourceProperties mysqlDataSourceProperties() {
|
|
return new DataSourceProperties();
|
|
}
|
|
|
|
/**
|
|
* MySQL 主数据源
|
|
* 使用 @Primary 确保这是默认数据源
|
|
*/
|
|
@Primary
|
|
@Bean(name = "dataSource")
|
|
public DataSource mysqlDataSource(DataSourceProperties properties) {
|
|
return properties.initializeDataSourceBuilder().build();
|
|
}
|
|
}
|