From 8b73a70c0bb29dd8bd075ccd0dff3fc957f43dfc Mon Sep 17 00:00:00 2001 From: infin_caishuxiao Date: Thu, 22 Feb 2018 18:27:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8C=E6=95=B0=E6=8D=AE=E6=BA=90,=20?= =?UTF-8?q?=E8=BF=98=E6=B2=A1=E9=85=8D=E5=A5=BDmapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/stats/TStatsRiskDetailMapper.java | 17 ++ .../risk/table/stats/TStatsRiskDetail.java | 45 +++++ .../com/xxl/job/executor/Application.java | 9 +- .../core/config/DataSourceConfig.java | 25 +++ .../job/executor/core/config/PrdDbConfig.java | 37 ++++ .../executor/core/config/StatsDbConfig.java | 36 ++++ .../src/main/resources/application.properties | 16 +- .../resources/generator/generatorConfig.xml | 28 +-- .../resources/mapping/TRiskRuleMapper.xml | 9 - .../resources/mapping/prd/TRiskRuleMapper.xml | 17 ++ .../mapping/stats/TStatsRiskDetailMapper.xml | 160 ++++++++++++++++++ 11 files changed, 361 insertions(+), 38 deletions(-) create mode 100644 xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/infincash/statistics/risk/mapper/stats/TStatsRiskDetailMapper.java create mode 100644 xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/infincash/statistics/risk/table/stats/TStatsRiskDetail.java create mode 100644 xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/DataSourceConfig.java create mode 100644 xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/PrdDbConfig.java create mode 100644 xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/StatsDbConfig.java delete mode 100644 xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/TRiskRuleMapper.xml create mode 100644 xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/prd/TRiskRuleMapper.xml create mode 100644 xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/stats/TStatsRiskDetailMapper.xml diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/infincash/statistics/risk/mapper/stats/TStatsRiskDetailMapper.java b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/infincash/statistics/risk/mapper/stats/TStatsRiskDetailMapper.java new file mode 100644 index 00000000..70fd7cff --- /dev/null +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/infincash/statistics/risk/mapper/stats/TStatsRiskDetailMapper.java @@ -0,0 +1,17 @@ +package com.infincash.statistics.risk.mapper.stats; + +import com.infincash.statistics.risk.table.stats.TStatsRiskDetail; + +public interface TStatsRiskDetailMapper { + int deleteByPrimaryKey(Long id); + + int insert(TStatsRiskDetail record); + + int insertSelective(TStatsRiskDetail record); + + TStatsRiskDetail selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(TStatsRiskDetail record); + + int updateByPrimaryKey(TStatsRiskDetail record); +} \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/infincash/statistics/risk/table/stats/TStatsRiskDetail.java b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/infincash/statistics/risk/table/stats/TStatsRiskDetail.java new file mode 100644 index 00000000..123b69f8 --- /dev/null +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/infincash/statistics/risk/table/stats/TStatsRiskDetail.java @@ -0,0 +1,45 @@ +package com.infincash.statistics.risk.table.stats; + +import java.util.Date; + +public class TStatsRiskDetail { + private Long id; + + private Date statsTime; + + private Integer aHourCount; + + private String riskRuleId; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getStatsTime() { + return statsTime; + } + + public void setStatsTime(Date statsTime) { + this.statsTime = statsTime; + } + + public Integer getaHourCount() { + return aHourCount; + } + + public void setaHourCount(Integer aHourCount) { + this.aHourCount = aHourCount; + } + + public String getRiskRuleId() { + return riskRuleId; + } + + public void setRiskRuleId(String riskRuleId) { + this.riskRuleId = riskRuleId == null ? null : riskRuleId.trim(); + } +} \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/Application.java b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/Application.java index 6f32d7fd..9b28bd4b 100644 --- a/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/Application.java +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/Application.java @@ -3,9 +3,14 @@ package com.xxl.job.executor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -@SpringBootApplication -@MapperScan("com.infincash.statistics.risk.mapper")//将项目中对应的mapper类的路径加进来就可以了 +/** + * 禁掉DataSourceAutoConfiguration,因为它会读取application.properties文件的spring.datasource.*属性并自动配置单数据源 + * @author caishuxiao + * + */ +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class Application { public static void main(String[] args) { diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/DataSourceConfig.java b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/DataSourceConfig.java new file mode 100644 index 00000000..b5411e32 --- /dev/null +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/DataSourceConfig.java @@ -0,0 +1,25 @@ +package com.xxl.job.executor.core.config; + +import javax.sql.DataSource; + +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class DataSourceConfig { + + @Bean(name = "prd") + @ConfigurationProperties(prefix = "spring.datasource.prd") // application.properteis中对应属性的前缀 + public DataSource dataSource1() { + return DataSourceBuilder.create().build(); + } + + @Bean(name = "stats") + @ConfigurationProperties(prefix = "spring.datasource.stats") // application.properteis中对应属性的前缀 + public DataSource dataSource2() { + return DataSourceBuilder.create().build(); + } + +} \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/PrdDbConfig.java b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/PrdDbConfig.java new file mode 100644 index 00000000..6d876970 --- /dev/null +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/PrdDbConfig.java @@ -0,0 +1,37 @@ +package com.xxl.job.executor.core.config; + +import javax.sql.DataSource; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@MapperScan(basePackages = {"titan.mapper"}, sqlSessionFactoryRef = "sqlSessionFactory1") +public class PrdDbConfig { + + @Autowired + @Qualifier("titanMasterDS") + private DataSource ds1; + + + @Bean + public SqlSessionFactory sqlSessionFactory1() throws Exception { + SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); + factoryBean.setDataSource(ds1); // 使用titan数据源, 连接titan库 + + return factoryBean.getObject(); + + } + + @Bean + public SqlSessionTemplate sqlSessionTemplate1() throws Exception { + SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactory1()); // 使用上面配置的Factory + return template; + } +} \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/StatsDbConfig.java b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/StatsDbConfig.java new file mode 100644 index 00000000..6781296a --- /dev/null +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/java/com/xxl/job/executor/core/config/StatsDbConfig.java @@ -0,0 +1,36 @@ +package com.xxl.job.executor.core.config; + +import javax.sql.DataSource; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@MapperScan(basePackages = {"other.mapper"}, sqlSessionFactoryRef = "sqlSessionFactory2") +public class StatsDbConfig { + @Autowired + @Qualifier("ds2") + private DataSource ds2; + + @Bean + public SqlSessionFactory sqlSessionFactory2() throws Exception { + SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); + factoryBean.setDataSource(ds2); + + + return factoryBean.getObject(); + + } + + @Bean + public SqlSessionTemplate sqlSessionTemplate2() throws Exception { + SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactory2()); + return template; + } +} \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/application.properties b/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/application.properties index 144c6e91..3dbbf114 100644 --- a/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/application.properties +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/application.properties @@ -1,7 +1,15 @@ -spring.datasource.url=jdbc:mysql://172.16.16.98:3306/microfinance?useUnicode=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false -spring.datasource.username=jobopr -spring.datasource.password=jobopr666 -spring.datasource.driver-class-name=com.mysql.jdbc.Driver +spring.datasource.prd.url=jdbc:mysql://172.16.16.98:3306/microfinance?useUnicode=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false +spring.datasource.prd.username=jobopr +spring.datasource.prd.password=jobopr666 +spring.datasource.prd.driver-class-name=com.mysql.jdbc.Driver + +spring.datasource.stats.url=jdbc:mysql://172.16.16.99:3306/microfinance1?useUnicode=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false +spring.datasource.stats.username=jobopr +spring.datasource.stats.password=jobopr666 +spring.datasource.stats.driver-class-name=com.mysql.jdbc.Driver + + + mybatis.mapper-locations=classpath:mapping/*.xml mybatis.type-aliases-package=com.infincash.statistics.risk.table # web port diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/generator/generatorConfig.xml b/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/generator/generatorConfig.xml index d15527aa..2e14bde5 100644 --- a/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/generator/generatorConfig.xml +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/generator/generatorConfig.xml @@ -18,40 +18,22 @@ - + - + - + -
- -
- - - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/prd/TRiskRuleMapper.xml b/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/prd/TRiskRuleMapper.xml new file mode 100644 index 00000000..8a732410 --- /dev/null +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/prd/TRiskRuleMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/stats/TStatsRiskDetailMapper.xml b/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/stats/TStatsRiskDetailMapper.xml new file mode 100644 index 00000000..12df531b --- /dev/null +++ b/xxl-job-executor-samples/xxl-job-executor-db/src/main/resources/mapping/stats/TStatsRiskDetailMapper.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + id, stats_time, a_hour_count, risk_rule_id + + + + delete from t_stats_risk_detail + where id = #{id,jdbcType=BIGINT} + + + insert into t_stats_risk_detail (id, stats_time, a_hour_count, + risk_rule_id) + values (#{id,jdbcType=BIGINT}, #{statsTime,jdbcType=TIMESTAMP}, #{aHourCount,jdbcType=INTEGER}, + #{riskRuleId,jdbcType=VARCHAR}) + + + insert into t_stats_risk_detail + + + id, + + + stats_time, + + + a_hour_count, + + + risk_rule_id, + + + + + #{id,jdbcType=BIGINT}, + + + #{statsTime,jdbcType=TIMESTAMP}, + + + #{aHourCount,jdbcType=INTEGER}, + + + #{riskRuleId,jdbcType=VARCHAR}, + + + + + update t_stats_risk_detail + + + stats_time = #{statsTime,jdbcType=TIMESTAMP}, + + + a_hour_count = #{aHourCount,jdbcType=INTEGER}, + + + risk_rule_id = #{riskRuleId,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + update t_stats_risk_detail + set stats_time = #{statsTime,jdbcType=TIMESTAMP}, + a_hour_count = #{aHourCount,jdbcType=INTEGER}, + risk_rule_id = #{riskRuleId,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + + + + + + + + id, stats_time, a_hour_count, risk_rule_id + + + + delete from t_stats_risk_detail + where id = #{id,jdbcType=BIGINT} + + + insert into t_stats_risk_detail (id, stats_time, a_hour_count, + risk_rule_id) + values (#{id,jdbcType=BIGINT}, #{statsTime,jdbcType=TIMESTAMP}, #{aHourCount,jdbcType=INTEGER}, + #{riskRuleId,jdbcType=VARCHAR}) + + + insert into t_stats_risk_detail + + + id, + + + stats_time, + + + a_hour_count, + + + risk_rule_id, + + + + + #{id,jdbcType=BIGINT}, + + + #{statsTime,jdbcType=TIMESTAMP}, + + + #{aHourCount,jdbcType=INTEGER}, + + + #{riskRuleId,jdbcType=VARCHAR}, + + + + + update t_stats_risk_detail + + + stats_time = #{statsTime,jdbcType=TIMESTAMP}, + + + a_hour_count = #{aHourCount,jdbcType=INTEGER}, + + + risk_rule_id = #{riskRuleId,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + update t_stats_risk_detail + set stats_time = #{statsTime,jdbcType=TIMESTAMP}, + a_hour_count = #{aHourCount,jdbcType=INTEGER}, + risk_rule_id = #{riskRuleId,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file