双数据源, 还没配好mapper

pull/5/head
infin_caishuxiao 8 years ago
parent 7a24ec661a
commit 8b73a70c0b

@ -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);
}

@ -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();
}
}

@ -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类的路径加进来就可以了
/**
* DataSourceAutoConfigurationapplication.propertiesspring.datasource.*
* @author caishuxiao
*
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class Application {
public static void main(String[] args) {

@ -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();
}
}

@ -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;
}
}

@ -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;
}
}

@ -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

@ -18,40 +18,22 @@
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="com.infincash.statistics.risk.table" targetProject="src/main/java">
<javaModelGenerator targetPackage="com.infincash.statistics.risk.table.stats" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成映射文件的包名和位置-->
<sqlMapGenerator targetPackage="main.resources.mapping" targetProject="src">
<sqlMapGenerator targetPackage="main.resources.mapping.stats" targetProject="src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.infincash.statistics.risk.mapper" targetProject="src/main/java">
<javaClientGenerator type="XMLMAPPER" targetPackage="com.infincash.statistics.risk.mapper.stats" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<table
tableName="t_user"
domainObjectName="TUser"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table
tableName="t_risk_rule"
domainObjectName="TRiskRule"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table
tableName="t_user_risk"
domainObjectName="TUserRisk"
tableName="t_stats_risk_detail"
domainObjectName="TStatsRiskDetail"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.infincash.statistics.risk.mapper.TRiskRuleMapper">
<select id="countRiskRule" resultType="java.lang.Integer">
select
count(1)
from t_risk_rule
</select>
</mapper>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.infincash.statistics.risk.mapper.TRiskRuleMapper">
<resultMap type="com.infincash.statistics.risk.table.extend.RiskStatsDTO" id="RiskStatsDTOMap">
<id property="id" column="id" />
<result property="userName" column="username" />
<result property="passW ord" column="password" />
</resultMap>
<select id="countRiskRule" resultMap="RiskStatsDTOMap">
select
risk_rule_id, count(1), now()
from t_user_risk
where user_id in (select user_id from t_user where DATE_SUB(NOW(),INTERVAL 1 HOUR) <= register_time)
GROUP by risk_rule_id order by risk_rule_id;
</select>
</mapper>

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.infincash.statistics.risk.mapper.stats.TStatsRiskDetailMapper">
<resultMap id="BaseResultMap" type="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="stats_time" jdbcType="TIMESTAMP" property="statsTime" />
<result column="a_hour_count" jdbcType="INTEGER" property="aHourCount" />
<result column="risk_rule_id" jdbcType="VARCHAR" property="riskRuleId" />
</resultMap>
<sql id="Base_Column_List">
id, stats_time, a_hour_count, risk_rule_id
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_stats_risk_detail
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from t_stats_risk_detail
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
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>
<insert id="insertSelective" parameterType="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
insert into t_stats_risk_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="statsTime != null">
stats_time,
</if>
<if test="aHourCount != null">
a_hour_count,
</if>
<if test="riskRuleId != null">
risk_rule_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="statsTime != null">
#{statsTime,jdbcType=TIMESTAMP},
</if>
<if test="aHourCount != null">
#{aHourCount,jdbcType=INTEGER},
</if>
<if test="riskRuleId != null">
#{riskRuleId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
update t_stats_risk_detail
<set>
<if test="statsTime != null">
stats_time = #{statsTime,jdbcType=TIMESTAMP},
</if>
<if test="aHourCount != null">
a_hour_count = #{aHourCount,jdbcType=INTEGER},
</if>
<if test="riskRuleId != null">
risk_rule_id = #{riskRuleId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
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}
</update>
<resultMap id="BaseResultMap" type="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="stats_time" jdbcType="TIMESTAMP" property="statsTime" />
<result column="a_hour_count" jdbcType="INTEGER" property="aHourCount" />
<result column="risk_rule_id" jdbcType="VARCHAR" property="riskRuleId" />
</resultMap>
<sql id="Base_Column_List">
id, stats_time, a_hour_count, risk_rule_id
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_stats_risk_detail
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from t_stats_risk_detail
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
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>
<insert id="insertSelective" parameterType="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
insert into t_stats_risk_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="statsTime != null">
stats_time,
</if>
<if test="aHourCount != null">
a_hour_count,
</if>
<if test="riskRuleId != null">
risk_rule_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="statsTime != null">
#{statsTime,jdbcType=TIMESTAMP},
</if>
<if test="aHourCount != null">
#{aHourCount,jdbcType=INTEGER},
</if>
<if test="riskRuleId != null">
#{riskRuleId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
update t_stats_risk_detail
<set>
<if test="statsTime != null">
stats_time = #{statsTime,jdbcType=TIMESTAMP},
</if>
<if test="aHourCount != null">
a_hour_count = #{aHourCount,jdbcType=INTEGER},
</if>
<if test="riskRuleId != null">
risk_rule_id = #{riskRuleId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.infincash.statistics.risk.table.stats.TStatsRiskDetail">
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}
</update>
</mapper>
Loading…
Cancel
Save