一,数据源配置
1.1,pom.xml配置
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 2 <modelVersion>4.0.0</modelVersion> 3 <groupId>bhz.uts</groupId> 4 <artifactId>uts-consumer</artifactId> 5 <version>0.0.1-SNAPSHOT</version> 6 7 <parent> 8 <groupId>org.springframework.boot</groupId> 9 <artifactId>spring-boot-starter-parent</artifactId> 10 <version>1.5.6.RELEASE</version> 11 <relativePath/> <!-- lookup parent from repository --> 12 </parent> 13 14 <properties> 15 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 16 <java.version>1.8</java.version> 17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 18 <java.version>1.8</java.version> 19 <commons-fileupload.version>1.2.2</commons-fileupload.version> 20 <commons-lang3.version>3.3.1</commons-lang3.version> 21 <commons-io.version>2.4</commons-io.version> 22 <commons-collections.version>3.2.2</commons-collections.version> 23 <fastjson.version>1.1.26</fastjson.version> 24 <mybatis.version>3.4.1</mybatis.version> 25 <mybatis-spring.version>1.3.0</mybatis-spring.version> 26 <druid.version>1.0.24</druid.version> 27 <activiti.version>5.21.0</activiti.version> 28 <cxf.version>3.0.0</cxf.version> 29 <cxf-rt.version>3.1.6</cxf-rt.version> 30 <oracle.version>7</oracle.version> 31 <fasterxml.uuid.version>3.1.4</fasterxml.uuid.version> 32 <github.miemiedev.version>1.2.17</github.miemiedev.version> 33 <common.codec.version>1.10</common.codec.version> 34 <servlet-api.version>3.1.0</servlet-api.version> 35 <kaptcha.version>2.3.2</kaptcha.version> 36 <org.codehaus.jackson.version>1.9.13</org.codehaus.jackson.version> 37 <poi-ooxml.version>3.9</poi-ooxml.version> 38 <commons-beanutils.version>1.9.3</commons-beanutils.version> 39 <pinyin4j.version>2.5.1</pinyin4j.version> 40 </properties> 41 42 <dependencies> 43 <!-- 添加SpringMvc、Web[TOMCAT] jar provided排除tomcat, 使用独立容器运行(非内嵌,当) --> 44 <dependency> 45 <groupId>org.springframework.boot</groupId> 46 <artifactId>spring-boot-starter-web</artifactId> 47 </dependency> 48 <dependency> 49 <groupId>org.springframework.boot</groupId> 50 <artifactId>spring-boot-starter-test</artifactId> 51 <scope>test</scope> 52 </dependency> 53 <dependency> 54 <groupId>org.springframework.boot</groupId> 55 <artifactId>spring-boot-starter-aop</artifactId> 56 </dependency> 57 <dependency> 58 <groupId>org.springframework.boot</groupId> 59 <artifactId>spring-boot-autoconfigure</artifactId> 60 </dependency> 61 <dependency> 62 <groupId>commons-fileupload</groupId> 63 <artifactId>commons-fileupload</artifactId> 64 <version>${commons-fileupload.version}</version> 65 </dependency> 66 <dependency> 67 <groupId>org.apache.commons</groupId> 68 <artifactId>commons-lang3</artifactId> 69 <version>${commons-lang3.version}</version> 70 </dependency> 71 <dependency> 72 <groupId>commons-io</groupId> 73 <artifactId>commons-io</artifactId> 74 <version>${commons-io.version}</version> 75 </dependency> 76 <dependency> 77 <groupId>commons-collections</groupId> 78 <artifactId>commons-collections</artifactId> 79 <version>${commons-collections.version}</version> 80 </dependency> 81 <dependency> 82 <groupId>commons-codec</groupId> 83 <artifactId>commons-codec</artifactId> 84 <version>${common.codec.version}</version> 85 </dependency> 86 <dependency> 87 <groupId>commons-beanutils</groupId> 88 <artifactId>commons-beanutils</artifactId> 89 <version>${commons-beanutils.version}</version> 90 </dependency> 91 <dependency> 92 <groupId>com.alibaba</groupId> 93 <artifactId>fastjson</artifactId> 94 <version>${fastjson.version}</version> 95 </dependency> 96 <!--对json格式的支持 --> 97 <dependency> 98 <groupId>org.codehaus.jackson</groupId> 99 <artifactId>jackson-mapper-asl</artifactId> 100 <version>${org.codehaus.jackson.version}</version> 101 </dependency> 102 <dependency> 103 <groupId>com.fasterxml.jackson.core</groupId> 104 <artifactId>jackson-databind</artifactId> 105 </dependency> 106 <dependency> 107 <groupId>com.fasterxml.uuid</groupId> 108 <artifactId>java-uuid-generator</artifactId> 109 <version>${fasterxml.uuid.version}</version> 110 </dependency> 111 <!-- 添加JDBC jar --> 112 <dependency> 113 <groupId>org.springframework.boot</groupId> 114 <artifactId>spring-boot-starter-jdbc</artifactId> 115 </dependency> 116 <dependency> 117 <groupId>org.mybatis.spring.boot</groupId> 118 <artifactId>mybatis-spring-boot-starter</artifactId> 119 <version>1.1.1</version> 120 </dependency> 121 <dependency> 122 <groupId>tk.mybatis</groupId> 123 <artifactId>mapper-spring-boot-starter</artifactId> 124 <version>1.1.0</version> 125 </dependency> 126 <dependency> 127 <groupId>com.alibaba</groupId> 128 <artifactId>druid</artifactId> 129 <version>${druid.version}</version> 130 </dependency> 131 <dependency> 132 <groupId>mysql</groupId> 133 <artifactId>mysql-connector-java</artifactId> 134 </dependency> 135 <dependency> 136 <groupId>com.github.pagehelper</groupId> 137 <artifactId>pagehelper-spring-boot-starter</artifactId> 138 <version>1.1.0</version> 139 <exclusions> 140 <exclusion> 141 <artifactId>mybatis-spring-boot-starter</artifactId> 142 <groupId>org.mybatis.spring.boot</groupId> 143 </exclusion> 144 </exclusions> 145 </dependency> 146 <!-- netty --> 147 <dependency> 148 <groupId>io.netty</groupId> 149 <artifactId>netty-all</artifactId> 150 <version>4.1.12.Final</version> 151 </dependency> 152 <!-- 序列化框架marshalling --> 153 <dependency> 154 <groupId>org.jboss.marshalling</groupId> 155 <artifactId>jboss-marshalling</artifactId> 156 <version>1.3.0.CR9</version> 157 </dependency> 158 <dependency> 159 <groupId>org.jboss.marshalling</groupId> 160 <artifactId>jboss-marshalling-serial</artifactId> 161 <version>1.3.0.CR9</version> 162 </dependency> 163 <!-- netty end --> 164 </dependencies> 165 166 <build> 167 <finalName>uts-consumer</finalName> 168 <!-- 打包时包含properties、xml --> 169 <resources> 170 <resource> 171 <directory>src/main/java</directory> 172 <includes> 173 <include>**/*.properties</include> 174 <include>**/*.xml</include> 175 </includes> 176 <!-- 是否替换资源中的属性--> 177 <filtering>true</filtering> 178 </resource> 179 <resource> 180 <directory>src/main/resources</directory> 181 </resource> 182 </resources> 183 <plugins> 184 <plugin> 185 <groupId>org.apache.maven.plugins</groupId> 186 <artifactId>maven-war-plugin</artifactId> 187 </plugin> 188 <!-- 解解决maven update project 后版本降低为1.5的bug --> 189 <plugin> 190 <groupId>org.apache.maven.plugins</groupId> 191 <artifactId>maven-compiler-plugin</artifactId> 192 <configuration> 193 <source>1.8</source> 194 <target>1.8</target> 195 </configuration> 196 </plugin> 197 <!-- 单元测试 --> 198 <plugin> 199 <groupId>org.apache.maven.plugins</groupId> 200 <artifactId>maven-surefire-plugin</artifactId> 201 <configuration> 202 <skip>true</skip> 203 <includes> 204 <include>**/*Test*.java</include> 205 </includes> 206 <testFailureIgnore>true</testFailureIgnore> 207 </configuration> 208 </plugin> 209 <plugin> 210 <groupId>org.apache.maven.plugins</groupId> 211 <artifactId>maven-source-plugin</artifactId> 212 <executions> 213 <!-- 绑定到特定的生命周期之后,运行maven-source-pluin 运行目标为jar-no-fork --> 214 <execution> 215 <phase>package</phase> 216 <goals> 217 <goal>jar-no-fork</goal> 218 </goals> 219 </execution> 220 </executions> 221 </plugin> 222 </plugins> 223 </build> 224 225 </project>
1.2,application.yml配置
1 server: 2 context-path: / 3 port: 8002 4 5 6 transfer: 7 host: 127.0.0.1 8 port: 8765 9 10 ## Spring配置: 11 spring: 12 http: 13 encoding: 14 charset: UTF-8 15 jackson: 16 date-format: yyyy-MM-dd HH:mm:ss 17 time-zone: GMT+8 18 default-property-inclusion: NON_NULL 19 ##DATASOURCE CONFIGURATION -- see druid.yml 20 21 druid: 22 type: com.alibaba.druid.pool.DruidDataSource 23 uts1: 24 url: jdbc:mysql://localhost:3306/uts1?characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useUnicode=true 25 username: root 26 password: root 27 initialSize: 5 28 minIdle: 10 29 maxIdle: 10 30 maxActive: 100 31 maxWait: 60000 32 timeBetweenEvictionRunsMillis: 60000 33 minEvictableIdleTimeMillis: 300000 34 validationQuery: SELECT 1 FROM DUAL 35 testWhileIdle: true 36 testOnBorrow: false 37 testOnReturn: false 38 poolPreparedStatements: true 39 maxPoolPreparedStatementPerConnectionSize: 20 40 filters: stat,wall,log4j 41 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 42 suseGlobalDataSourceStat: true 43 44 45 uts2: 46 url: jdbc:mysql://localhost:3306/uts2?characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useUnicode=true 47 username: root 48 password: root 49 initialSize: 5 50 minIdle: 10 51 maxIdle: 10 52 maxActive: 100 53 maxWait: 60000 54 timeBetweenEvictionRunsMillis: 60000 55 minEvictableIdleTimeMillis: 300000 56 validationQuery: SELECT 1 FROM DUAL 57 testWhileIdle: true 58 testOnBorrow: false 59 testOnReturn: false 60 poolPreparedStatements: true 61 maxPoolPreparedStatementPerConnectionSize: 20 62 filters: stat,wall,log4j 63 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 64 suseGlobalDataSourceStat: true 65 66 uts3: 67 url: jdbc:mysql://localhost:3306/uts3?characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useUnicode=true 68 username: root 69 password: root 70 initialSize: 5 71 minIdle: 10 72 maxIdle: 10 73 maxActive: 100 74 maxWait: 60000 75 timeBetweenEvictionRunsMillis: 60000 76 minEvictableIdleTimeMillis: 300000 77 validationQuery: SELECT 1 FROM DUAL 78 testWhileIdle: true 79 testOnBorrow: false 80 testOnReturn: false 81 poolPreparedStatements: true 82 maxPoolPreparedStatementPerConnectionSize: 20 83 filters: stat,wall,log4j 84 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 85 suseGlobalDataSourceStat: true 86 87 88 uts4: 89 url: jdbc:mysql://localhost:3306/uts4?characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useUnicode=true 90 username: root 91 password: root 92 initialSize: 5 93 minIdle: 10 94 maxIdle: 10 95 maxActive: 100 96 maxWait: 60000 97 timeBetweenEvictionRunsMillis: 60000 98 minEvictableIdleTimeMillis: 300000 99 validationQuery: SELECT 1 FROM DUAL 100 testWhileIdle: true 101 testOnBorrow: false 102 testOnReturn: false 103 poolPreparedStatements: true 104 maxPoolPreparedStatementPerConnectionSize: 20 105 filters: stat,wall,log4j 106 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 107 suseGlobalDataSourceStat: true 108 109 110 111 112 113 mybatis: 114 type-aliases-package: bhz.uts 115 mapper-locations: classpath:bhz/uts/mapping/*.xml 116 117 logging: 118 level: 119 tk.mybatis: TRACE 120 121 122 pagehelper: 123 helperDialect: mysql 124 reasonable: true 125 supportMethodsArguments: true 126 params: count=countSql 127 128 129 130
1.3,数据库sql语句
1 CREATE TABLE IF NOT EXISTS `trade_detail_0` ( 2 `ID` varchar(128) NOT NULL, 3 `SERIALNO` varchar(128) NOT NULL, 4 `TRADE_DATE` timestamp NULL DEFAULT NULL, 5 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 6 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 7 `BUSINESS_TYPE` varchar(40) NOT NULL, 8 `BALANCE` decimal(20,2) NOT NULL, 9 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 10 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 11 `ACCOUNT_NAME` varchar(40) NOT NULL, 12 `ACCOUNT_NO` varchar(40) NOT NULL, 13 `DIGEST` varchar(400) DEFAULT NULL, 14 `STATUS` varchar(1) NOT NULL, 15 `CREATE_BY` varchar(40) NOT NULL, 16 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 17 `UPDATE_BY` varchar(40) NOT NULL, 18 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 19 PRIMARY KEY (`ID`) 20 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 21 22 CREATE TABLE IF NOT EXISTS `trade_detail_1` ( 23 `ID` varchar(128) NOT NULL, 24 `SERIALNO` varchar(128) NOT NULL, 25 `TRADE_DATE` timestamp NULL DEFAULT NULL, 26 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 27 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 28 `BUSINESS_TYPE` varchar(40) NOT NULL, 29 `BALANCE` decimal(20,2) NOT NULL, 30 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 31 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 32 `ACCOUNT_NAME` varchar(40) NOT NULL, 33 `ACCOUNT_NO` varchar(40) NOT NULL, 34 `DIGEST` varchar(400) DEFAULT NULL, 35 `STATUS` varchar(1) NOT NULL, 36 `CREATE_BY` varchar(40) NOT NULL, 37 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 38 `UPDATE_BY` varchar(40) NOT NULL, 39 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 40 PRIMARY KEY (`ID`) 41 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 42 43 CREATE TABLE IF NOT EXISTS `trade_detail_2` ( 44 `ID` varchar(128) NOT NULL, 45 `SERIALNO` varchar(128) NOT NULL, 46 `TRADE_DATE` timestamp NULL DEFAULT NULL, 47 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 48 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 49 `BUSINESS_TYPE` varchar(40) NOT NULL, 50 `BALANCE` decimal(20,2) NOT NULL, 51 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 52 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 53 `ACCOUNT_NAME` varchar(40) NOT NULL, 54 `ACCOUNT_NO` varchar(40) NOT NULL, 55 `DIGEST` varchar(400) DEFAULT NULL, 56 `STATUS` varchar(1) NOT NULL, 57 `CREATE_BY` varchar(40) NOT NULL, 58 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 59 `UPDATE_BY` varchar(40) NOT NULL, 60 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 61 PRIMARY KEY (`ID`) 62 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 63 64 CREATE TABLE IF NOT EXISTS `trade_detail_3` ( 65 `ID` varchar(128) NOT NULL, 66 `SERIALNO` varchar(128) NOT NULL, 67 `TRADE_DATE` timestamp NULL DEFAULT NULL, 68 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 69 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 70 `BUSINESS_TYPE` varchar(40) NOT NULL, 71 `BALANCE` decimal(20,2) NOT NULL, 72 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 73 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 74 `ACCOUNT_NAME` varchar(40) NOT NULL, 75 `ACCOUNT_NO` varchar(40) NOT NULL, 76 `DIGEST` varchar(400) DEFAULT NULL, 77 `STATUS` varchar(1) NOT NULL, 78 `CREATE_BY` varchar(40) NOT NULL, 79 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 80 `UPDATE_BY` varchar(40) NOT NULL, 81 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 82 PRIMARY KEY (`ID`) 83 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 84 85 CREATE TABLE IF NOT EXISTS `trade_detail_4` ( 86 `ID` varchar(128) NOT NULL, 87 `SERIALNO` varchar(128) NOT NULL, 88 `TRADE_DATE` timestamp NULL DEFAULT NULL, 89 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 90 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 91 `BUSINESS_TYPE` varchar(40) NOT NULL, 92 `BALANCE` decimal(20,2) NOT NULL, 93 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 94 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 95 `ACCOUNT_NAME` varchar(40) NOT NULL, 96 `ACCOUNT_NO` varchar(40) NOT NULL, 97 `DIGEST` varchar(400) DEFAULT NULL, 98 `STATUS` varchar(1) NOT NULL, 99 `CREATE_BY` varchar(40) NOT NULL, 100 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 101 `UPDATE_BY` varchar(40) NOT NULL, 102 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 103 PRIMARY KEY (`ID`) 104 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 105 106 CREATE TABLE IF NOT EXISTS `trade_detail_5` ( 107 `ID` varchar(128) NOT NULL, 108 `SERIALNO` varchar(128) NOT NULL, 109 `TRADE_DATE` timestamp NULL DEFAULT NULL, 110 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 111 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 112 `BUSINESS_TYPE` varchar(40) NOT NULL, 113 `BALANCE` decimal(20,2) NOT NULL, 114 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 115 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 116 `ACCOUNT_NAME` varchar(40) NOT NULL, 117 `ACCOUNT_NO` varchar(40) NOT NULL, 118 `DIGEST` varchar(400) DEFAULT NULL, 119 `STATUS` varchar(1) NOT NULL, 120 `CREATE_BY` varchar(40) NOT NULL, 121 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 122 `UPDATE_BY` varchar(40) NOT NULL, 123 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 124 PRIMARY KEY (`ID`) 125 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 126 127 CREATE TABLE IF NOT EXISTS `trade_detail_6` ( 128 `ID` varchar(128) NOT NULL, 129 `SERIALNO` varchar(128) NOT NULL, 130 `TRADE_DATE` timestamp NULL DEFAULT NULL, 131 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 132 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 133 `BUSINESS_TYPE` varchar(40) NOT NULL, 134 `BALANCE` decimal(20,2) NOT NULL, 135 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 136 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 137 `ACCOUNT_NAME` varchar(40) NOT NULL, 138 `ACCOUNT_NO` varchar(40) NOT NULL, 139 `DIGEST` varchar(400) DEFAULT NULL, 140 `STATUS` varchar(1) NOT NULL, 141 `CREATE_BY` varchar(40) NOT NULL, 142 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 143 `UPDATE_BY` varchar(40) NOT NULL, 144 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 145 PRIMARY KEY (`ID`) 146 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 147 148 CREATE TABLE IF NOT EXISTS `trade_detail_7` ( 149 `ID` varchar(128) NOT NULL, 150 `SERIALNO` varchar(128) NOT NULL, 151 `TRADE_DATE` timestamp NULL DEFAULT NULL, 152 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 153 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 154 `BUSINESS_TYPE` varchar(40) NOT NULL, 155 `BALANCE` decimal(20,2) NOT NULL, 156 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 157 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 158 `ACCOUNT_NAME` varchar(40) NOT NULL, 159 `ACCOUNT_NO` varchar(40) NOT NULL, 160 `DIGEST` varchar(400) DEFAULT NULL, 161 `STATUS` varchar(1) NOT NULL, 162 `CREATE_BY` varchar(40) NOT NULL, 163 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 164 `UPDATE_BY` varchar(40) NOT NULL, 165 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 166 PRIMARY KEY (`ID`) 167 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 168 169 CREATE TABLE IF NOT EXISTS `trade_detail_8` ( 170 `ID` varchar(128) NOT NULL, 171 `SERIALNO` varchar(128) NOT NULL, 172 `TRADE_DATE` timestamp NULL DEFAULT NULL, 173 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 174 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 175 `BUSINESS_TYPE` varchar(40) NOT NULL, 176 `BALANCE` decimal(20,2) NOT NULL, 177 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 178 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 179 `ACCOUNT_NAME` varchar(40) NOT NULL, 180 `ACCOUNT_NO` varchar(40) NOT NULL, 181 `DIGEST` varchar(400) DEFAULT NULL, 182 `STATUS` varchar(1) NOT NULL, 183 `CREATE_BY` varchar(40) NOT NULL, 184 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 185 `UPDATE_BY` varchar(40) NOT NULL, 186 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 187 PRIMARY KEY (`ID`) 188 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 189 190 CREATE TABLE IF NOT EXISTS `trade_detail_9` ( 191 `ID` varchar(128) NOT NULL, 192 `SERIALNO` varchar(128) NOT NULL, 193 `TRADE_DATE` timestamp NULL DEFAULT NULL, 194 `DEDBIT_AMOUNT` decimal(20,2) NOT NULL, 195 `CREDIT_AMOUNT` decimal(20,2) NOT NULL, 196 `BUSINESS_TYPE` varchar(40) NOT NULL, 197 `BALANCE` decimal(20,2) NOT NULL, 198 `OPP_ACCOUNT_NAME` varchar(40) NOT NULL, 199 `OPP_ACCOUNT_NO` varchar(40) NOT NULL, 200 `ACCOUNT_NAME` varchar(40) NOT NULL, 201 `ACCOUNT_NO` varchar(40) NOT NULL, 202 `DIGEST` varchar(400) DEFAULT NULL, 203 `STATUS` varchar(1) NOT NULL, 204 `CREATE_BY` varchar(40) NOT NULL, 205 `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 206 `UPDATE_BY` varchar(40) NOT NULL, 207 `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 208 PRIMARY KEY (`ID`) 209 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4个库个库里面10条数据
1.4,BaseMapper.java(基础扫描类)
1 package bhz.uts.config.database; 2 3 4 import tk.mybatis.mapper.common.Mapper; 5 import tk.mybatis.mapper.common.MySqlMapper; 6 /** 7 * <B>系统名称:</B><BR> 8 * <B>模块名称:</B>base-sys<BR> 9 * <B>中文类名:</B>BaseMapper<BR> 10 * <B>概要说明:</B>基础数据库服务<BR> 11 * @author bhz 12 * @since 2017年2月8日 下午2:42:49 13 */ 14 public interface BaseMapper<T> extends Mapper<T>, MySqlMapper<T> { 15 16 }
1.5,DruidDataSourceConfig.java(类似dao层的xml文件配置)
1 package bhz.uts.config.database; 2 3 import java.sql.SQLException; 4 5 import javax.sql.DataSource; 6 7 import org.slf4j.Logger; 8 import org.slf4j.LoggerFactory; 9 import org.springframework.beans.factory.annotation.Value; 10 import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 11 import org.springframework.boot.context.properties.ConfigurationProperties; 12 import org.springframework.boot.web.servlet.FilterRegistrationBean; 13 import org.springframework.boot.web.servlet.ServletRegistrationBean; 14 import org.springframework.context.annotation.Bean; 15 import org.springframework.context.annotation.Configuration; 16 import org.springframework.context.annotation.Primary; 17 18 import com.alibaba.druid.support.http.StatViewServlet; 19 import com.alibaba.druid.support.http.WebStatFilter; 20 21 @Configuration 22 public class DruidDataSourceConfig { 23 24 private static Logger LOGGER = LoggerFactory 25 .getLogger(DruidDataSourceConfig.class); 26 @Value("${druid.type}") 27 private Class<? extends DataSource> dataSource; 28 29 @Bean(name="uts1") 30 @Primary//注解默认加载这个数据源 31 @ConfigurationProperties(prefix="druid.uts1")//注解加载application.yml文件 32 public DataSource uts1DataSource() throws SQLException { 33 DataSource uts1DataSource = DataSourceBuilder.create().type(dataSource).build(); 34 LOGGER.info("-----------uts1DataSource : {}---------"+uts1DataSource); 35 return uts1DataSource; 36 } 37 38 @Bean(name="uts2") 39 @ConfigurationProperties(prefix="druid.uts2") 40 public DataSource uts2DataSource() throws SQLException { 41 DataSource uts2DataSource = DataSourceBuilder.create().type(dataSource).build(); 42 LOGGER.info("-----------uts2DataSource : {}---------"+uts2DataSource); 43 return uts2DataSource; 44 } 45 46 @Bean(name="uts3") 47 @ConfigurationProperties(prefix="druid.uts3") 48 public DataSource uts3DataSource() throws SQLException { 49 DataSource uts3DataSource = DataSourceBuilder.create().type(dataSource).build(); 50 LOGGER.info("-----------uts3DataSource : {}---------"+uts3DataSource); 51 return uts3DataSource; 52 } 53 54 @Bean(name="uts4") 55 @ConfigurationProperties(prefix="druid.uts4") 56 public DataSource uts4DataSource() throws SQLException { 57 DataSource uts4DataSource = DataSourceBuilder.create().type(dataSource).build(); 58 LOGGER.info("-----------uts4DataSource : {}---------"+uts4DataSource); 59 return uts4DataSource; 60 } 61 62 @Bean 63 public ServletRegistrationBean druidServlet() { 64 65 ServletRegistrationBean reg = new ServletRegistrationBean(); 66 reg.setServlet(new StatViewServlet()); 67 // reg.setAsyncSupported(true); 68 reg.addUrlMappings("/druid/*"); 69 reg.addInitParameter("allow", "127.0.0.1"); 70 // reg.addInitParameter("deny","/deny"); 71 reg.addInitParameter("loginUsername", "bhz"); 72 reg.addInitParameter("loginPassword", "bhz"); 73 LOGGER.info(" druid console manager init : {} ", reg); 74 return reg; 75 } 76 77 @Bean 78 public FilterRegistrationBean filterRegistrationBean() { 79 FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); 80 filterRegistrationBean.setFilter(new WebStatFilter()); 81 filterRegistrationBean.addUrlPatterns("/*"); 82 filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico, /druid/*"); 83 LOGGER.info(" druid filter register : {} ", filterRegistrationBean); 84 return filterRegistrationBean; 85 } 86 87 }
1.6,MybatisConfiguration.java(加载数据源并配置到代理中来)
1 package bhz.uts.config.database; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 6 import javax.annotation.Resource; 7 import javax.sql.DataSource; 8 9 import org.apache.ibatis.session.SqlSessionFactory; 10 import org.mybatis.spring.SqlSessionFactoryBean; 11 import org.springframework.boot.autoconfigure.AutoConfigureAfter; 12 import org.springframework.context.annotation.Bean; 13 import org.springframework.context.annotation.Configuration; 14 import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 15 import org.springframework.core.io.support.ResourcePatternResolver; 16 import org.springframework.jdbc.datasource.DataSourceTransactionManager; 17 import org.springframework.transaction.PlatformTransactionManager; 18 import org.springframework.transaction.annotation.EnableTransactionManagement; 19 20 21 22 @Configuration 23 @EnableTransactionManagement 24 @AutoConfigureAfter(DruidDataSourceConfig.class) 25 public class MybatisConfiguration { 26 27 @Resource(name="uts1") 28 private DataSource uts1DataSource; 29 30 @Resource(name="uts2") 31 private DataSource uts2DataSource; 32 33 @Resource(name="uts3") 34 private DataSource uts3DataSource; 35 36 @Resource(name="uts4") 37 private DataSource uts4DataSource; 38 39 40 41 42 @Bean(name="DynamicDataSource") 43 public DynamicDataSource rounRobinDynamicDataSourceProxy() { 44 Map<Object, Object> targetSourceDateBase=new HashMap<Object, Object>(); 45 targetSourceDateBase.put(DataBaseContextHodler.DataBaseType.UTS1, uts1DataSource); 46 targetSourceDateBase.put(DataBaseContextHodler.DataBaseType.UTS2, uts2DataSource); 47 targetSourceDateBase.put(DataBaseContextHodler.DataBaseType.UTS3, uts3DataSource); 48 targetSourceDateBase.put(DataBaseContextHodler.DataBaseType.UTS4, uts4DataSource); 49 //现在把设置好的动态的map数据源交给DynamicDataSource这个类就行了,因为这个类继承了AbstractRoutingDataSource 50 //所以动态代理就让它来实现了。获取数据源的时候 51 DynamicDataSource dynamicDataSource =new DynamicDataSource(); 52 dynamicDataSource.setTargetDataSources(targetSourceDateBase); 53 dynamicDataSource.setDefaultTargetDataSource(uts1DataSource); 54 55 return dynamicDataSource; 56 } 57 58 59 @Bean(name="SqlSessionFactory") 60 public SqlSessionFactory sqlSessionFactoryBean(DynamicDataSource dynamicDataSource) { 61 SqlSessionFactoryBean bean=new SqlSessionFactoryBean(); 62 bean.setDataSource(dynamicDataSource); 63 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 64 try { 65 bean.setMapperLocations(resolver.getResources("classpath:bhz/uts/mapping/*.xml")); 66 SqlSessionFactory sqlSessionFactory = bean.getObject(); 67 sqlSessionFactory.getConfiguration().setCacheEnabled(Boolean.TRUE); 68 69 return sqlSessionFactory; 70 } catch (Exception e) { 71 throw new RuntimeException(e); 72 } 73 74 } 75 76 77 78 @Bean 79 public PlatformTransactionManager transactionManager(DynamicDataSource dynamicDataSource) throws Exception { 80 DataSourceTransactionManager txManager = new DataSourceTransactionManager(); 81 txManager.setDataSource(dynamicDataSource); 82 return txManager; 83 } 84 }
1.7,DynamicDataSource.java(取代理用的类)
package bhz.uts.config.database; import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; public class DynamicDataSource extends AbstractRoutingDataSource{ @Override//determineCurrentLookupKey它是在切面完,在dao层执行之前再来执行的。 /* 继承AbstractRoutingDataSource并重写其中的方法determineCurrentLookupKey(), * 在该方法中使用DatabaseContextHolder获取当前线程的DatabaseType。 * 因为动态的数据源已经封装到DynamicDataSource这个类中来了, * 现在只需要通过获取DataBaseContextHodler.getDataBaseType(); *获取key值就可以动态的获取它的数据源了。 */ protected Object determineCurrentLookupKey() { //获取之后就会把setTargetDataSources里面的value值给取到的。 return DataBaseContextHodler.getDataBaseType(); } }
1.8,DataBaseContextHodler.java(ThreadLocal线程,放置代理和代理的key的值的类,因为要根据这个key值来去DynamicDataSource这个里面取数据源的。)
1 package bhz.uts.config.database; 2 3 4 public class DataBaseContextHodler { 5 public enum DataBaseType{ 6 UTS1("uts1"), 7 UTS2("uts3"), 8 UTS3("uts3"), 9 UTS4("uts4"); 10 11 private String code; 12 private DataBaseType(String code) { 13 this.code=code; 14 } 15 public String getCode() { 16 return this.code; 17 } 18 } 19 //它会根据线程的名称是一样的来取值的。假如不用它的话则会乱掉的。线程1放进来的,取出来的则是线程2的。 20 private static final ThreadLocal<DataBaseType> contextholder=new ThreadLocal<DataBaseType>(); 21 22 23 public static void setDataBaseType(DataBaseType dataBaseType) { 24 if(dataBaseType==null) throw new NullPointerException("........."); 25 System.out.println("dataBaseType放进去"+dataBaseType); 26 contextholder.set(dataBaseType); 27 } 28 //这里取出来的是key值 29 public static DataBaseType getDataBaseType() { 30 System.out.println("dataBaseType取出来"+ contextholder.get()); 31 return contextholder.get()==null ? DataBaseType.UTS1 :contextholder.get(); 32 } 33 34 public static void clearDataBaseType() { 35 contextholder.remove(); 36 } 37 38 }
1.9,SelectConnection.java(自定义注解)
1 package bhz.uts.config.database; 2 3 import java.lang.annotation.ElementType; 4 import java.lang.annotation.Retention; 5 import java.lang.annotation.RetentionPolicy; 6 import java.lang.annotation.Target; 7 8 9 @Target({ElementType.METHOD,ElementType.TYPE}) 10 @Retention(RetentionPolicy.RUNTIME) 11 public @interface SelectConnection { 12 13 14 String name() default ""; 15 }
1.10,SelectConnectionIntercepor.java(自定义注解的实现类)
1 package bhz.uts.config.database; 2 3 import java.lang.reflect.Method; 4 5 import org.aspectj.lang.ProceedingJoinPoint; 6 import org.aspectj.lang.Signature; 7 import org.aspectj.lang.annotation.Around; 8 import org.aspectj.lang.annotation.Aspect; 9 import org.aspectj.lang.reflect.MethodSignature; 10 import org.slf4j.Logger; 11 import org.slf4j.LoggerFactory; 12 import org.springframework.core.Ordered; 13 import org.springframework.stereotype.Component; 14 15 import bhz.uts.config.database.DataBaseContextHodler.DataBaseType; 16 import bhz.uts.entity.BaseEntity; 17 import bhz.uts.utils.Pair; 18 import bhz.uts.utils.SelectorUtil; 19 20 import com.alibaba.druid.util.StringUtils; 21 22 23 24 @Aspect 25 @Component 26 public class SelectConnectionIntercepor implements Ordered { 27 28 private static Logger logger = LoggerFactory.getLogger(SelectConnectionIntercepor.class); 29 public static final String PREFIX="uts"; 30 @Around("@annotation(selectConnection)")//只要调用selectconnection就会调用这个方法 31 public Object proceed(ProceedingJoinPoint proceedingJoinPoint,SelectConnection selectConnection) throws Throwable { 32 System.out.println("---->around"); 33 //注解参数 34 System.out.println("注解参数:"+ selectConnection.name()); 35 Signature signature = proceedingJoinPoint.getSignature(); 36 MethodSignature methodSignature = (MethodSignature)signature; 37 Method targetMethod = methodSignature.getMethod(); 38 System.out.println("classname----------:" + targetMethod.getDeclaringClass().getName()); 39 System.out.println("superclass--------:" + targetMethod.getDeclaringClass().getSuperclass().getName()); 40 System.out.println("isinterface---------:" + targetMethod.getDeclaringClass().isInterface()); 41 System.out.println("target----------:" + proceedingJoinPoint.getTarget().getClass().getName()); 42 System.out.println("proxy-----------:" + proceedingJoinPoint.getThis().getClass().getName()); 43 System.out.println("method-----------:" + targetMethod.getName()); 44 System.out.println("getArgs()[0]-----------:" + (BaseEntity)proceedingJoinPoint.getArgs()[0]); 45 46 logger.info("-------------开始选择数据库-----------------"); 47 try { 48 String currentDataBaseNameString=""; 49 50 if(!StringUtils.isEmpty(selectConnection.name())) { 51 currentDataBaseNameString=selectConnection.name(); 52 }else { 53 BaseEntity baseEntity=(BaseEntity)proceedingJoinPoint.getArgs()[0]; 54 String uuid=baseEntity.getId(); 55 Pair<Integer, Integer> pair=SelectorUtil.getDataBaseNumberAndTableNumber(uuid); 56 currentDataBaseNameString=PREFIX+pair.getObject1(); 57 } 58 System.err.println("经过判断后我们的currentDataBaseNameString是:===="+currentDataBaseNameString); 59 60 for(DataBaseType type :DataBaseContextHodler.DataBaseType.values()) { 61 if(!StringUtils.isEmpty(currentDataBaseNameString)) { 62 String typeCode = type.getCode(); 63 if(typeCode.equals(currentDataBaseNameString)) { 64 DataBaseContextHodler.setDataBaseType(type); 65 System.err.println("currentDataBaseNameString的code是====="+DataBaseContextHodler.getDataBaseType().getCode()); 66 } 67 } 68 } 69 70 Object result=proceedingJoinPoint.proceed(); 71 System.out.println("result"+result); 72 return result; 73 }finally { 74 DataBaseContextHodler.clearDataBaseType(); 75 } 76 77 78 79 80 } 81 82 83 @Override 84 public int getOrder() { 85 // TODO Auto-generated method stub 86 return -1; 87 } 88 89 }
BaseEntity baseEntity=(BaseEntity)proceedingJoinPoint.getArgs()[0];
就是监控方法的参数
由于这里
TradeDetail.java的类继承了BaseEntity.java这个类,所以即使传递的是TradeDetail但是可以强制的转化成BaseEntity
return result;就是调用方法的返回值。
注意第64行,在service层调用方法之前就会执行这个方法的里面的类,在这里把获取到的key值存到到了
private static final ThreadLocal<DataBaseType> contextholder=new ThreadLocal<DataBaseType>();
这个里面。
二,任务时间控制类(在本项目中没有用到)
2.1,TaskSchedulerConfig.java
1 package bhz.uts.config.scheduler; 2 3 import java.util.concurrent.Executor; 4 import java.util.concurrent.Executors; 5 6 import org.springframework.context.annotation.Bean; 7 import org.springframework.context.annotation.Configuration; 8 import org.springframework.scheduling.annotation.EnableScheduling; 9 import org.springframework.scheduling.annotation.SchedulingConfigurer; 10 import org.springframework.scheduling.config.ScheduledTaskRegistrar; 11 12 @Configuration 13 @EnableScheduling 14 public class TaskSchedulerConfig implements SchedulingConfigurer { 15 16 @Override 17 public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { 18 scheduledTaskRegistrar.setScheduler(taskScheduler()); 19 } 20 21 @Bean(destroyMethod="shutdown") 22 public Executor taskScheduler(){ 23 return Executors.newScheduledThreadPool(100); 24 } 25 26 }
三,实体类
3.1,BaseEntity.java
1 package bhz.uts.entity; 2 3 public class BaseEntity { 4 5 private String id; 6 7 public String getId() { 8 return id; 9 } 10 11 public void setId(String id) { 12 this.id = id; 13 } 14 15 16 }
3.2,TradeDetail.java
1 package bhz.uts.entity; 2 3 import java.math.BigDecimal; 4 import java.util.Date; 5 6 public class TradeDetail extends BaseEntity { 7 8 private String serialno; 9 10 private Date tradeDate; 11 12 private BigDecimal dedbitAmount; 13 14 private BigDecimal creditAmount; 15 16 private String businessType; 17 18 private BigDecimal balance; 19 20 private String oppAccountName; 21 22 private String oppAccountNo; 23 24 private String accountName; 25 26 private String accountNo; 27 28 private String digest; 29 30 private String status; 31 32 private String createBy; 33 34 private Date createTime; 35 36 private String updateBy; 37 38 private Date updateTime; 39 40 public String getSerialno() { 41 return serialno; 42 } 43 44 public void setSerialno(String serialno) { 45 this.serialno = serialno == null ? null : serialno.trim(); 46 } 47 48 public Date getTradeDate() { 49 return tradeDate; 50 } 51 52 public void setTradeDate(Date tradeDate) { 53 this.tradeDate = tradeDate; 54 } 55 56 public BigDecimal getDedbitAmount() { 57 return dedbitAmount; 58 } 59 60 public void setDedbitAmount(BigDecimal dedbitAmount) { 61 this.dedbitAmount = dedbitAmount; 62 } 63 64 public BigDecimal getCreditAmount() { 65 return creditAmount; 66 } 67 68 public void setCreditAmount(BigDecimal creditAmount) { 69 this.creditAmount = creditAmount; 70 } 71 72 public String getBusinessType() { 73 return businessType; 74 } 75 76 public void setBusinessType(String businessType) { 77 this.businessType = businessType; 78 } 79 80 public BigDecimal getBalance() { 81 return balance; 82 } 83 84 public void setBalance(BigDecimal balance) { 85 this.balance = balance; 86 } 87 88 public String getOppAccountName() { 89 return oppAccountName; 90 } 91 92 public void setOppAccountName(String oppAccountName) { 93 this.oppAccountName = oppAccountName == null ? null : oppAccountName.trim(); 94 } 95 96 public String getOppAccountNo() { 97 return oppAccountNo; 98 } 99 100 public void setOppAccountNo(String oppAccountNo) { 101 this.oppAccountNo = oppAccountNo == null ? null : oppAccountNo.trim(); 102 } 103 104 public String getAccountName() { 105 return accountName; 106 } 107 108 public void setAccountName(String accountName) { 109 this.accountName = accountName; 110 } 111 112 public String getAccountNo() { 113 return accountNo; 114 } 115 116 public void setAccountNo(String accountNo) { 117 this.accountNo = accountNo == null ? null : accountNo.trim(); 118 } 119 120 public String getDigest() { 121 return digest; 122 } 123 124 public void setDigest(String digest) { 125 this.digest = digest == null ? null : digest.trim(); 126 } 127 128 public String getStatus() { 129 return status; 130 } 131 132 public void setStatus(String status) { 133 this.status = status == null ? null : status.trim(); 134 } 135 136 public String getCreateBy() { 137 return createBy; 138 } 139 140 public void setCreateBy(String createBy) { 141 this.createBy = createBy == null ? null : createBy.trim(); 142 } 143 144 public Date getCreateTime() { 145 return createTime; 146 } 147 148 public void setCreateTime(Date createTime) { 149 this.createTime = createTime; 150 } 151 152 public String getUpdateBy() { 153 return updateBy; 154 } 155 156 public void setUpdateBy(String updateBy) { 157 this.updateBy = updateBy == null ? null : updateBy.trim(); 158 } 159 160 public Date getUpdateTime() { 161 return updateTime; 162 } 163 164 public void setUpdateTime(Date updateTime) { 165 this.updateTime = updateTime; 166 } 167 }
四,监听类
4.1,ApplicationFactory.java(容器类)
1 package bhz.uts.listener; 2 3 import org.springframework.beans.BeansException; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.ApplicationContextAware; 6 import org.springframework.stereotype.Component; 7 /** 8 * <B>系统名称:</B><BR> 9 * <B>模块名称:</B><BR> 10 * <B>中文类名:</B>ApplicationFactory<BR> 11 * <B>概要说明:</B><BR> 12 * @author baihezhuo 13 * @since 2017年5月27日 下午4:41:47 14 */ 15 @Component 16 public class ApplicationFactory implements ApplicationContextAware { 17 18 private static ApplicationContext ctx = null; 19 20 @Override 21 public void setApplicationContext(ApplicationContext ctx) throws BeansException { 22 if (ApplicationFactory.ctx == null) { 23 ApplicationFactory.ctx = ctx; 24 } 25 } 26 27 // 获取applicationContext 28 public static ApplicationContext getApplicationContext() { 29 return ctx; 30 } 31 32 // 通过name获取 Bean. 33 public static Object getBean(String name) { 34 return getApplicationContext().getBean(name); 35 } 36 37 // 通过class获取Bean. 38 public static <T> T getBean(Class<T> clazz) { 39 return getApplicationContext().getBean(clazz); 40 } 41 42 // 通过name,以及Clazz返回指定的Bean 43 public static <T> T getBean(String name, Class<T> clazz) { 44 return getApplicationContext().getBean(name, clazz); 45 } 46 47 48 }
4.2,SpringListener.java(监控容器是否加载完的类)
1 package bhz.uts.listener; 2 3 import org.springframework.context.ApplicationListener; 4 import org.springframework.context.event.ContextRefreshedEvent; 5 import org.springframework.stereotype.Component; 6 7 import bhz.uts.netty.NettyServer; 8 9 10 @Component("springListener") 11 public class SpringListener implements ApplicationListener<ContextRefreshedEvent>{ 12 13 @Override 14 public void onApplicationEvent(ContextRefreshedEvent event) { 15 16 if(event.getApplicationContext().getParent() == null){ 17 //需要执行的逻辑代码,当spring容器初始化完成后就会执行该方法。 18 System.out.println("spring 加载完毕.."); 19 try { 20 NettyServer.getInstance().start(); 21 } catch (Exception e) { 22 e.printStackTrace(); 23 } 24 } 25 26 27 28 } 29 30 31 32 }
spring容器加载好了之后在启动服务器端的链接
五,mapper类
5.1,TradeDetailMapper.java
1 package bhz.uts.mapper; 2 3 import java.util.List; 4 import java.util.Map; 5 6 import org.apache.ibatis.annotations.Param; 7 8 import bhz.uts.config.database.BaseMapper; 9 import bhz.uts.entity.TradeDetail; 10 11 public interface TradeDetailMapper extends BaseMapper<TradeDetail> { 12 13 int updateStatusById(@Param("id")String id); 14 15 List<TradeDetail> queryByNotSync(); 16 int balanceInsert(Map<String, Object> params); 17 18 TradeDetail balanceSelectByPrimaryKey(@Param("tableName")String tableName,@Param("id")String uuid); 19 20 21 22 }
5.2,TradeDetailMapper.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > 3 <mapper namespace="bhz.uts.mapper.TradeDetailMapper" > 4 <resultMap id="BaseResultMap" type="bhz.uts.entity.TradeDetail" > 5 <id column="ID" property="id" jdbcType="VARCHAR" /> 6 <result column="SERIALNO" property="serialno" jdbcType="VARCHAR" /> 7 <result column="TRADE_DATE" property="tradeDate" jdbcType="TIMESTAMP" /> 8 <result column="DEDBIT_AMOUNT" property="dedbitAmount" jdbcType="DECIMAL" /> 9 <result column="CREDIT_AMOUNT" property="creditAmount" jdbcType="DECIMAL" /> 10 <result column="BUSINESS_TYPE" property="businessType" jdbcType="VARCHAR" /> 11 <result column="BALANCE" property="balance" jdbcType="DECIMAL" /> 12 <result column="OPP_ACCOUNT_NAME" property="oppAccountName" jdbcType="VARCHAR" /> 13 <result column="OPP_ACCOUNT_NO" property="oppAccountNo" jdbcType="VARCHAR" /> 14 <result column="ACCOUNT_NAME" property="accountName" jdbcType="VARCHAR" /> 15 <result column="ACCOUNT_NO" property="accountNo" jdbcType="VARCHAR" /> 16 <result column="DIGEST" property="digest" jdbcType="VARCHAR" /> 17 <result column="STATUS" property="status" jdbcType="VARCHAR" /> 18 <result column="CREATE_BY" property="createBy" jdbcType="VARCHAR" /> 19 <result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP" /> 20 <result column="UPDATE_BY" property="updateBy" jdbcType="VARCHAR" /> 21 <result column="UPDATE_TIME" property="updateTime" jdbcType="TIMESTAMP" /> 22 </resultMap> 23 <sql id="Base_Column_List" > 24 ID, SERIALNO, TRADE_DATE, DEDBIT_AMOUNT, CREDIT_AMOUNT, BUSINESS_TYPE, BALANCE, OPP_ACCOUNT_NAME, 25 OPP_ACCOUNT_NO, ACCOUNT_NAME, ACCOUNT_NO, DIGEST, STATUS, CREATE_BY, CREATE_TIME, 26 UPDATE_BY, UPDATE_TIME 27 </sql> 28 29 <update id="updateStatusById" > 30 UPDATE TRADE_DETAIL SET STATUS = 1 WHERE ID = #{id,jdbcType=VARCHAR} 31 </update> 32 33 <select id="queryByNotSync" resultMap="BaseResultMap" > 34 SELECT * FROM TRADE_DETAIL WHERE STATUS = 0 35 </select> 36 37 38 <insert id="balanceInsert" parameterType="bhz.uts.entity.TradeDetail"> 39 insert into ${tableName} (ID, SERIALNO, TRADE_DATE, DEDBIT_AMOUNT, CREDIT_AMOUNT, BUSINESS_TYPE, BALANCE, OPP_ACCOUNT_NAME, 40 OPP_ACCOUNT_NO, ACCOUNT_NAME, ACCOUNT_NO, DIGEST, STATUS, CREATE_BY, CREATE_TIME, 41 UPDATE_BY, UPDATE_TIME) 42 values 43 (#{id,jdbcType=VARCHAR}, 44 #{serialno,jdbcType=VARCHAR}, 45 #{tradeDate,jdbcType=TIMESTAMP}, 46 #{dedbitAmount,jdbcType=DECIMAL}, 47 #{creditAmount,jdbcType=VARCHAR}, 48 #{businessType,jdbcType=DECIMAL}, 49 #{balance,jdbcType=DECIMAL}, 50 #{oppAccountName,jdbcType=VARCHAR}, 51 #{oppAccountNo,jdbcType=VARCHAR}, 52 #{accountName,jdbcType=VARCHAR}, 53 #{accountNo,jdbcType=VARCHAR}, 54 #{digest,jdbcType=VARCHAR}, 55 #{status,jdbcType=VARCHAR}, 56 #{createBy,jdbcType=VARCHAR}, 57 #{createTime,jdbcType=TIMESTAMP}, 58 #{updateBy,jdbcType=VARCHAR}, 59 #{updateTime,jdbcType=TIMESTAMP} 60 ) 61 </insert> 62 63 64 <select id="balanceSelectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> 65 select 66 <include refid="Base_Column_List"/> 67 from ${tableName} 68 where ID=#{id,jdbcType=VARCHAR} 69 </select> 70 71 </mapper>
六,service类
6.1,TradeDetailService.java
1 package bhz.uts.service; 2 3 import java.util.Map; 4 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Service; 8 9 import com.alibaba.fastjson.JSONObject; 10 11 import bhz.uts.config.database.SelectConnection; 12 import bhz.uts.entity.TradeDetail; 13 import bhz.uts.mapper.TradeDetailMapper; 14 import bhz.uts.utils.FastJsonConvertUtil; 15 import bhz.uts.utils.Pair; 16 import bhz.uts.utils.SelectorUtil; 17 18 19 @Service 20 public class TradeDetailService { 21 22 private static final String TABLE_NAME_PREFIX = "TRADE_DETAIL_"; 23 24 @Autowired 25 private TradeDetailMapper tradeDetailMapper; 26 27 @SelectConnection 28 public TradeDetail balanceSelectByPrimaryKey(String uuid) { 29 Pair<Integer, Integer> pair = SelectorUtil.getDataBaseNumberAndTableNumber(uuid); 30 Integer tableNumber = pair.getObject2(); 31 String tableName = TABLE_NAME_PREFIX + tableNumber; 32 return tradeDetailMapper.balanceSelectByPrimaryKey(tableName, uuid); 33 } 34 35 @SelectConnection 36 public int balanceInsert(TradeDetail td) { 37 String uuid = td.getId(); 38 Pair<Integer, Integer> pair = SelectorUtil.getDataBaseNumberAndTableNumber(uuid); 39 Integer tableNumber = pair.getObject2(); 40 String tableName = TABLE_NAME_PREFIX + tableNumber; 41 42 JSONObject json = FastJsonConvertUtil.convertObjectToJSONObject(td); 43 Map<String, Object> params = FastJsonConvertUtil.convertJSONToObject(json, Map.class); 44 params.put("tableName", tableName); 45 46 return tradeDetailMapper.balanceInsert(params); 47 48 } 49 50 51 }
注解回去调用这个类,并最终调用了自定义注解的实现类
七,编辑码的请求和相应类
7.1,Req.java
1 package bhz.uts.protocol; 2 3 import java.io.Serializable; 4 5 public class Req implements Serializable { 6 7 8 private static final long serialVersionUID = 1L; 9 10 private String id ; //唯一ID 11 private String type ; //操作类型 12 private String tag ; //传输对象的类型::: 13 private String reqeustMessage; //json对象 14 public String getId() { 15 return id; 16 } 17 public void setId(String id) { 18 this.id = id; 19 } 20 public String getType() { 21 return type; 22 } 23 public void setType(String type) { 24 this.type = type; 25 } 26 public String getTag() { 27 return tag; 28 } 29 public void setTag(String tag) { 30 this.tag = tag; 31 } 32 public String getReqeustMessage() { 33 return reqeustMessage; 34 } 35 public void setReqeustMessage(String reqeustMessage) { 36 this.reqeustMessage = reqeustMessage; 37 } 46 }
7.2,Resp.java
1 package bhz.uts.protocol; 2 3 import java.io.Serializable; 4 5 public class Resp implements Serializable { 6 7 8 private static final long serialVersionUID = 1L; 9 10 private String id; 11 private String type; 12 private String tag; 13 private String responseCode; //响应码:: 14 private String responseMessage; 15 16 17 public String getId() { 18 return id; 19 } 20 public void setId(String id) { 21 this.id = id; 22 } 23 public String getType() { 24 return type; 25 } 26 public void setType(String type) { 27 this.type = type; 28 } 29 public String getTag() { 30 return tag; 31 } 32 public void setTag(String tag) { 33 this.tag = tag; 34 } 35 public String getResponseCode() { 36 return responseCode; 37 } 38 public void setResponseCode(String responseCode) { 39 this.responseCode = responseCode; 40 } 41 public String getResponseMessage() { 42 return responseMessage; 43 } 44 public void setResponseMessage(String responseMessage) { 45 this.responseMessage = responseMessage; 46 } 47 48 49 50 51 }
八,netty的服务端代码
8.1,MarshallingCodeCFactory.java(编解码类)
1 package bhz.uts.netty; 2 3 import io.netty.handler.codec.marshalling.DefaultMarshallerProvider; 4 import io.netty.handler.codec.marshalling.DefaultUnmarshallerProvider; 5 import io.netty.handler.codec.marshalling.MarshallerProvider; 6 import io.netty.handler.codec.marshalling.MarshallingDecoder; 7 import io.netty.handler.codec.marshalling.MarshallingEncoder; 8 import io.netty.handler.codec.marshalling.UnmarshallerProvider; 9 10 import org.jboss.marshalling.MarshallerFactory; 11 import org.jboss.marshalling.Marshalling; 12 import org.jboss.marshalling.MarshallingConfiguration; 13 14 /** 15 * Marshalling工厂 16 * @author(alienware) 17 * @since 2014-12-16 18 */ 19 public final class MarshallingCodeCFactory { 20 21 /** 22 * 创建Jboss Marshalling解码器MarshallingDecoder 23 * @return MarshallingDecoder 24 */ 25 public static MarshallingDecoder buildMarshallingDecoder() { 26 //首先通过Marshalling工具类的精通方法获取Marshalling实例对象 参数serial标识创建的是java序列化工厂对象。 27 final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial"); 28 //创建了MarshallingConfiguration对象,配置了版本号为5 29 final MarshallingConfiguration configuration = new MarshallingConfiguration(); 30 configuration.setVersion(5); 31 //根据marshallerFactory和configuration创建provider 32 UnmarshallerProvider provider = new DefaultUnmarshallerProvider(marshallerFactory, configuration); 33 //构建Netty的MarshallingDecoder对象,俩个参数分别为provider和单个消息序列化后的最大长度 34 MarshallingDecoder decoder = new MarshallingDecoder(provider, 1024 * 1024 * 1); 35 return decoder; 36 } 37 38 /** 39 * 创建Jboss Marshalling编码器MarshallingEncoder 40 * @return MarshallingEncoder 41 */ 42 public static MarshallingEncoder buildMarshallingEncoder() { 43 final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial"); 44 final MarshallingConfiguration configuration = new MarshallingConfiguration(); 45 configuration.setVersion(5); 46 MarshallerProvider provider = new DefaultMarshallerProvider(marshallerFactory, configuration); 47 //构建Netty的MarshallingEncoder对象,MarshallingEncoder用于实现序列化接口的POJO对象序列化为二进制数组 48 MarshallingEncoder encoder = new MarshallingEncoder(provider); 49 return encoder; 50 } 51 }
8.2,NettyServer.java(服务类)
1 package bhz.uts.netty; 2 3 import org.apache.ibatis.javassist.runtime.Cflow; 4 5 import io.netty.bootstrap.Bootstrap; 6 import io.netty.bootstrap.ServerBootstrap; 7 import io.netty.channel.ChannelFuture; 8 import io.netty.channel.ChannelInitializer; 9 import io.netty.channel.ChannelOption; 10 import io.netty.channel.EventLoopGroup; 11 import io.netty.channel.nio.NioEventLoopGroup; 12 import io.netty.channel.socket.SocketChannel; 13 import io.netty.channel.socket.nio.NioServerSocketChannel; 14 import io.netty.channel.socket.nio.NioSocketChannel; 15 16 17 public class NettyServer { 18 19 20 private static class SingletionHolder { 21 static final NettyServer instance = new NettyServer(); 22 } 23 24 public static NettyServer getInstance(){ 25 return SingletionHolder.instance; 26 27 } 28 29 private EventLoopGroup bossGroup; 30 private EventLoopGroup workGroup; 31 private ServerBootstrap b; 32 private ChannelFuture cf; 33 34 private NettyServer(){ 35 bossGroup=new NioEventLoopGroup(); 36 workGroup=new NioEventLoopGroup(); 37 b=new ServerBootstrap(); 38 b.group(bossGroup, workGroup) 39 .channel(NioServerSocketChannel.class) 40 .option(ChannelOption.SO_BACKLOG, 1024) 41 .childHandler(new ChannelInitializer<SocketChannel>() { 42 43 @Override 44 protected void initChannel(SocketChannel sc) throws Exception { 45 sc.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder()); 46 sc.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder()); 47 sc.pipeline().addLast(new NettyServerHandler()); 48 } 49 }); 50 } 51 52 public void start() { 53 try { 54 this.cf = b.bind(8765).sync(); 55 System.err.println("服务器启动了--------"); 56 } catch (InterruptedException e) { 57 e.printStackTrace(); 58 } 59 } 60 61 62 public ChannelFuture getChannelFuture() { 63 return this.cf; 64 } 65 66 public void close() throws InterruptedException { 67 this.cf.channel().closeFuture().sync(); 68 this.bossGroup.shutdownGracefully(); 69 this.workGroup.shutdownGracefully(); 70 } 71 }
8.3,NettyServerHandler.java(实现类)
1 package bhz.uts.netty; 2 3 import org.slf4j.Logger; 4 import org.slf4j.LoggerFactory; 5 6 import bhz.uts.config.database.SelectConnectionIntercepor; 7 import bhz.uts.entity.TradeDetail; 8 import bhz.uts.listener.ApplicationFactory; 9 import bhz.uts.protocol.Req; 10 import bhz.uts.protocol.Resp; 11 import bhz.uts.service.TradeDetailService; 12 import bhz.uts.utils.Const; 13 import bhz.uts.utils.FastJsonConvertUtil; 14 import io.netty.channel.ChannelHandler; 15 import io.netty.channel.ChannelHandlerContext; 16 import io.netty.channel.ChannelInboundHandlerAdapter; 17 import io.netty.util.ReferenceCountUtil; 18 19 public class NettyServerHandler extends ChannelInboundHandlerAdapter { 20 private static Logger logger = LoggerFactory.getLogger(NettyServerHandler.class); 21 22 23 @Override 24 public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 25 try { 26 27 Req req = (Req)msg; 28 String id = req.getId(); 29 String tag = req.getTag(); 30 String type = req.getType(); 31 String reqeustMessage = req.getReqeustMessage(); 32 logger.info("id {},tag {},type {},reqeustMessage {}",id,tag,type,reqeustMessage); 33 Resp resp =new Resp(); 34 try { 35 if(Const.TRADE_DETAIL.equals(tag)) { 36 TradeDetailService tradeDetailService =(TradeDetailService) ApplicationFactory.getBean("tradeDetailService"); 37 TradeDetail td = FastJsonConvertUtil.convertJSONToObject(reqeustMessage, TradeDetail.class); 38 if(Const.SAVE.equals(type)) { 39 int ret = tradeDetailService.balanceInsert(td); 40 if(ret==1) { 41 resp.setId(id); 42 resp.setTag(tag); 43 resp.setType(Const.UPDATE); 44 resp.setResponseCode(Const.RESPONSE_CODE_OK); 45 ctx.writeAndFlush(resp); 46 System.err.println("数据同步成功,id-----"+id+"----,并且返回相应信息"); 47 }else if(ret==0) { 48 resp.setId(id); 49 resp.setTag(tag); 50 resp.setType(Const.UPDATE); 51 resp.setResponseCode(Const.RESPONSE_CODE_INSERT_ERR); 52 ctx.writeAndFlush(resp); 53 System.err.println("数据同步失败,id-----"+id+"----,并且返回相应信息"); 54 } 55 } 56 } 57 } catch (Exception e) { 58 resp.setId(id); 59 resp.setTag(tag); 60 resp.setType(Const.UPDATE); 61 resp.setResponseCode(Const.RESPONSE_CODE_SERVER_ERR); 62 resp.setResponseMessage(e.getMessage()); 63 ctx.writeAndFlush(resp); 64 System.err.println("数据同步失败,id-----"+id+"----,程序抛异常了"); } 65 } finally { 66 ReferenceCountUtil.release(msg); 67 } 68 69 } 70 71 72 }
九,工具类
9.1,Const.java(常量类)
1 package bhz.uts.utils; 2 3 public final class Const { 4 5 public static final String TRADE_DETAIL = "trade_detail"; 6 public static final String TRADE_BALANCE = "trade_balance"; 7 8 public static final String QUERY = "query"; 9 public static final String SAVE = "save"; 10 public static final String UPDATE = "update"; 11 public static final String DELETE = "delete"; 12 13 14 public static final String RESPONSE_CODE_OK = "1"; 15 public static final String RESPONSE_CODE_INSERT_ERR = "2"; 16 public static final String RESPONSE_CODE_SERVER_ERR = "3"; 17 18 }
9.2,FastJsonConvertUtil.java(json转化类)
1 package bhz.uts.utils; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import com.alibaba.fastjson.JSON; 7 import com.alibaba.fastjson.JSONObject; 8 import com.alibaba.fastjson.serializer.SerializerFeature; 9 10 /** 11 * <B>系统名称:</B>通用平台<BR> 12 * <B>模块名称:</B>通用平台-公共服务<BR> 13 * <B>中文类名:</B>通用平台-公共服务-FastJsonConvert<BR> 14 * <B>概要说明:</B><BR> 15 * @author bhz 16 * @since 2016年10月10日 上午11:01:52 17 */ 18 public class FastJsonConvertUtil { 19 20 private static final SerializerFeature[] featuresWithNullValue = { SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullBooleanAsFalse, 21 SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullStringAsEmpty }; 22 23 /** 24 * <B>方法名称:</B>将JSON字符串转换为实体对象<BR> 25 * <B>概要说明:</B>将JSON字符串转换为实体对象<BR> 26 * @param data JSON字符串 27 * @param clzss 转换对象 28 * @return T 29 */ 30 public static <T> T convertJSONToObject(String data, Class<T> clzss) { 31 try { 32 T t = JSON.parseObject(data, clzss); 33 return t; 34 } catch (Exception e) { 35 e.printStackTrace(); 36 return null; 37 } 38 } 39 40 /** 41 * <B>方法名称:</B>将JSONObject对象转换为实体对象<BR> 42 * <B>概要说明:</B>将JSONObject对象转换为实体对象<BR> 43 * @param data JSONObject对象 44 * @param clzss 转换对象 45 * @return T 46 */ 47 public static <T> T convertJSONToObject(JSONObject data, Class<T> clzss) { 48 try { 49 T t = JSONObject.toJavaObject(data, clzss); 50 return t; 51 } catch (Exception e) { 52 e.printStackTrace(); 53 return null; 54 } 55 } 56 57 /** 58 * <B>方法名称:</B>将JSON字符串数组转为List集合对象<BR> 59 * <B>概要说明:</B>将JSON字符串数组转为List集合对象<BR> 60 * @param data JSON字符串数组 61 * @param clzss 转换对象 62 * @return List<T>集合对象 63 */ 64 public static <T> List<T> convertJSONToArray(String data, Class<T> clzss) { 65 try { 66 List<T> t = JSON.parseArray(data, clzss); 67 return t; 68 } catch (Exception e) { 69 e.printStackTrace(); 70 return null; 71 } 72 } 73 74 /** 75 * <B>方法名称:</B>将List<JSONObject>转为List集合对象<BR> 76 * <B>概要说明:</B>将List<JSONObject>转为List集合对象<BR> 77 * @param data List<JSONObject> 78 * @param clzss 转换对象 79 * @return List<T>集合对象 80 */ 81 public static <T> List<T> convertJSONToArray(List<JSONObject> data, Class<T> clzss) { 82 try { 83 List<T> t = new ArrayList<T>(); 84 for (JSONObject jsonObject : data) { 85 t.add(convertJSONToObject(jsonObject, clzss)); 86 } 87 return t; 88 } catch (Exception e) { 89 e.printStackTrace(); 90 return null; 91 } 92 } 93 94 /** 95 * <B>方法名称:</B>将对象转为JSON字符串<BR> 96 * <B>概要说明:</B>将对象转为JSON字符串<BR> 97 * @param obj 任意对象 98 * @return JSON字符串 99 */ 100 public static String convertObjectToJSON(Object obj) { 101 try { 102 String text = JSON.toJSONString(obj); 103 return text; 104 } catch (Exception e) { 105 e.printStackTrace(); 106 return null; 107 } 108 } 109 110 /** 111 * <B>方法名称:</B>将对象转为JSONObject对象<BR> 112 * <B>概要说明:</B>将对象转为JSONObject对象<BR> 113 * @param obj 任意对象 114 * @return JSONObject对象 115 */ 116 public static JSONObject convertObjectToJSONObject(Object obj){ 117 try { 118 JSONObject jsonObject = (JSONObject) JSONObject.toJSON(obj); 119 return jsonObject; 120 } catch (Exception e) { 121 e.printStackTrace(); 122 return null; 123 } 124 } 125 126 127 /** 128 * <B>方法名称:</B><BR> 129 * <B>概要说明:</B><BR> 130 * @param obj 131 * @return 132 */ 133 public static String convertObjectToJSONWithNullValue(Object obj) { 134 try { 135 String text = JSON.toJSONString(obj, featuresWithNullValue); 136 return text; 137 } catch (Exception e) { 138 e.printStackTrace(); 139 return null; 140 } 141 } 142 143 public static void main(String[] args) { 144 System.err.println(System.getProperties()); 145 } 146 }
9.3,GeneratorDataUtil.java(造数据的类)
1 package bhz.uts.utils; 2 3 import java.math.BigDecimal; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 import java.util.Random; 7 import java.util.UUID; 8 9 import bhz.uts.entity.TradeDetail; 10 11 public class GeneratorDataUtil { 12 13 private static Random random = new Random(); 14 15 //交易时间: 16 private static Date getRandomDate(){ 17 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 18 Date d = new Date(117, 19 random.nextInt(7), 20 (int)(Math.random()*28)+1, 21 (int)(Math.random()*23)+1, 22 (int)(Math.random()*59)+1, 23 (int)(Math.random()*59)+1); 24 System.out.println(formatter.format(d)); 25 return d; 26 } 27 28 static Object[] accounts = null; 29 static { 30 Pair p1 = new Pair<String, String>("张三", "30001040191113380583"); 31 Pair p2 = new Pair<String, String>("李四", "40003242903000023274"); 32 Pair p3 = new Pair<String, String>("王五", "50033457780002320965"); 33 Pair p4 = new Pair<String, String>("赵六", "68886000080002320926"); 34 accounts = new Object[]{p1, p2, p3, p4}; 35 } 36 37 static Object[] oppAccounts = null; 38 static { 39 Pair p1 = new Pair<String, String>("小1", "500013334380543599"); 40 Pair p2 = new Pair<String, String>("小2", "498980000566599998"); 41 Pair p3 = new Pair<String, String>("小3", "788876699990005589"); 42 Pair p4 = new Pair<String, String>("小4", "155500006660007779"); 43 Pair p5 = new Pair<String, String>("小5", "344339999333000001"); 44 oppAccounts = new Object[]{p1, p2, p3, p4, p5}; 45 } 46 47 // 48 private static String generateSerialno(Date d){ 49 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); 50 StringBuffer key = new StringBuffer(); 51 key.append(formatter.format(d)); 52 String uid = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); 53 key.append(uid.substring(12)); 54 return key.toString(); 55 } 56 57 // 58 private static Pair getRandomAccounts(){ 59 return (Pair) accounts[random.nextInt(accounts.length)]; 60 } 61 62 private static Pair getRandomOppAccounts(){ 63 return (Pair) oppAccounts[random.nextInt(oppAccounts.length)]; 64 } 65 66 67 static Object[] digests = null; 68 static { 69 String d1 = "转账"; 70 String d2 = "付款"; 71 String d3 = "百度买单"; 72 String d4 = "美团买单"; 73 String d5 = "淘宝买单"; 74 digests = new Object[]{d1, d2, d3, d4, d5}; 75 } 76 77 private static String getRandomDigest(){ 78 return (String) digests[random.nextInt(digests.length)]; 79 } 80 81 public static void main(String[] args) { 82 System.err.println(getRandomBalance()); 83 } 84 85 private static int getRandomCreditAmount(){ 86 return (int) ((Math.random()*100)+ (Math.random()*300) + (Math.random()*80)); 87 } 88 89 private static int getRandomBalance(){ 90 return (int) ((Math.random()*100000)+ (Math.random()*3000) + (Math.random()*500)); 91 } 92 93 94 public static TradeDetail generator() { 95 TradeDetail td1 = new TradeDetail(); 96 td1.setId(KeyUtil.generatorUUID()); 97 Date tradeDate = getRandomDate(); 98 99 td1.setSerialno(generateSerialno(tradeDate)); 100 td1.setTradeDate(tradeDate); 101 td1.setCreditAmount(new BigDecimal(getRandomCreditAmount())); 102 td1.setDedbitAmount(new BigDecimal(0)); 103 td1.setBusinessType("1"); 104 td1.setBalance(new BigDecimal(getRandomBalance())); 105 106 Pair account = getRandomAccounts(); 107 108 td1.setAccountName((String) account.getObject1()); 109 td1.setAccountNo((String) account.getObject2()); 110 111 112 Pair oppAccount = getRandomOppAccounts(); 113 td1.setOppAccountName((String) oppAccount.getObject1()); 114 td1.setOppAccountNo((String) oppAccount.getObject2()); 115 116 td1.setDigest(getRandomDigest()); 117 td1.setStatus("0"); 118 td1.setCreateBy("system"); 119 td1.setCreateTime(new Date()); 120 td1.setUpdateBy("system"); 121 td1.setUpdateTime(new Date()); 122 return td1; 123 124 } 125 126 }
9.4,GzipUtil.java(压缩解压类)
1 package bhz.uts.utils; 2 3 import java.io.ByteArrayInputStream; 4 import java.io.ByteArrayOutputStream; 5 import java.io.File; 6 import java.io.FileInputStream; 7 import java.io.FileOutputStream; 8 import java.util.zip.GZIPInputStream; 9 import java.util.zip.GZIPOutputStream; 10 11 public class GzipUtil { 12 13 public static byte[] gzip(byte[] data) throws Exception{ 14 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 15 GZIPOutputStream gzip = new GZIPOutputStream(bos); 16 gzip.write(data); 17 gzip.finish(); 18 gzip.close(); 19 byte[] ret = bos.toByteArray(); 20 bos.close(); 21 return ret; 22 } 23 24 public static byte[] ungzip(byte[] data) throws Exception{ 25 ByteArrayInputStream bis = new ByteArrayInputStream(data); 26 GZIPInputStream gzip = new GZIPInputStream(bis); 27 byte[] buf = new byte[1024]; 28 int num = -1; 29 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 30 while((num = gzip.read(buf, 0 , buf.length)) != -1 ){ 31 bos.write(buf, 0, num); 32 } 33 gzip.close(); 34 bis.close(); 35 byte[] ret = bos.toByteArray(); 36 bos.flush(); 37 bos.close(); 38 return ret; 39 } 40 41 public static void main(String[] args) throws Exception{ 42 43 //读取文件 44 String readPath = System.getProperty("user.dir") + File.separatorChar + "sources" + File.separatorChar + "006.jpg"; 45 File file = new File(readPath); 46 FileInputStream in = new FileInputStream(file); 47 byte[] data = new byte[in.available()]; 48 in.read(data); 49 in.close(); 50 51 System.out.println("文件原始大小:" + data.length); 52 //测试压缩 53 54 byte[] ret1 = GzipUtil.gzip(data); 55 System.out.println("压缩之后大小:" + ret1.length); 56 57 byte[] ret2 = GzipUtil.ungzip(ret1); 58 System.out.println("还原之后大小:" + ret2.length); 59 60 //写出文件 61 String writePath = System.getProperty("user.dir") + File.separatorChar + "receive" + File.separatorChar + "006.jpg"; 62 FileOutputStream fos = new FileOutputStream(writePath); 63 fos.write(ret2); 64 fos.close(); 65 66 67 } 68 69 70 71 }
9.5,KeyUtil.java(主键生成策略类)
1 package bhz.uts.utils; 2 3 import java.util.UUID; 4 5 import com.fasterxml.uuid.EthernetAddress; 6 import com.fasterxml.uuid.Generators; 7 import com.fasterxml.uuid.impl.TimeBasedGenerator; 8 9 /** 10 * <B>系统名称:</B>通用平台<BR> 11 * <B>模块名称:</B>通用平台-公共服务<BR> 12 * <B>中文类名:</B>KeyUtils<BR> 13 * <B>概要说明:</B>主键生成策略-工具类<BR> 14 * @author baihezhuo 15 * @since 2017年2月21日 下午1:55:42 16 */ 17 public class KeyUtil { 18 19 /** 20 * <B>方法名称:</B>generatorUUID<BR> 21 * <B>概要说明:</B>主键生成策略<BR> 22 * @author baihezhuo 23 * @since 2017年2月21日 下午2:00:06 24 * @return UUID String 25 */ 26 public static String generatorUUID(){ 27 TimeBasedGenerator timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface()); 28 return timeBasedGenerator.generate().toString(); 29 } 30 31 32 33 }
9.6,Pair.java(键值对类)
1 package bhz.uts.utils; 2 3 public class Pair<T1, T2> { 4 private T1 object1; 5 private T2 object2; 6 7 public Pair(T1 object1, T2 object2) { 8 this.object1 = object1; 9 this.object2 = object2; 10 } 11 12 public T1 getObject1() { 13 return object1; 14 } 15 16 public void setObject1(T1 object1) { 17 this.object1 = object1; 18 } 19 20 public T2 getObject2() { 21 return object2; 22 } 23 24 public void setObject2(T2 object2) { 25 this.object2 = object2; 26 } 27 }
9.7,SelectorUtil.java(选择库表的工具类)
1 package bhz.uts.utils; 2 3 public class SelectorUtil { 4 5 6 7 public static Pair<Integer, Integer> getDataBaseNumberAndTableNumber(String uuid){ 8 int hashCode=Math.abs(uuid.hashCode()); 9 System.err.println("hashCode是:---"+hashCode); 10 int selectDataBaseNumer=(hashCode/10)%4+1; 11 int selectTableNumer=hashCode%10; 12 System.err.println("selectDataBaseNumer:-------"+selectDataBaseNumer); 13 System.err.println("selectTableNumer:-----------"+selectTableNumer); 14 return new Pair<Integer, Integer>(selectDataBaseNumer, selectTableNumer); 15 } 16 }
这个就是根据id来选择库和表的类
十,主类
10.1,MainConfig.java(主要扫描类)
1 package bhz.uts; 2 3 import org.mybatis.spring.annotation.MapperScan; 4 import org.springframework.context.annotation.ComponentScan; 5 import org.springframework.context.annotation.Configuration; 6 7 @Configuration 8 @MapperScan(basePackages = "bhz.uts.mapper") 9 @ComponentScan(basePackages = {"bhz.uts.*", "bhz.uts.config.*"}) 10 public class MainConfig { 11 12 }
10.2,UtsConsumerApplication.java(springboot的启动类)
1 package bhz.uts; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6 @SpringBootApplication 7 public class UtsConsumerApplication { 8 9 public static void main(String[] args) { 10 SpringApplication.run(UtsConsumerApplication.class, args); 11 } 12 }
控制台
启动的时候的日志
http://localhost:8001/sender?count=10
服务端发过来请求之后的日志
1 Java HotSpot(TM) 64-Bit Server VM warning: MaxNewSize (524288k) is equal to or greater than the entire heap (524288k). A new generation size of 524224k will be used. 2 3 . ____ _ __ _ _ 4 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ 5 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 6 \\/ ___)| |_)| | | | | || (_| | ) ) ) ) 7 ' |____| .__|_| |_|_| |_\__, | / / / / 8 =========|_|==============|___/=/_/_/_/ 9 :: Spring Boot :: (v1.5.6.RELEASE) 10 11 2018-03-21 20:29:51.340 INFO 3872 --- [ main] bhz.uts.UtsConsumerApplication : Starting UtsConsumerApplication on qingruihappy with PID 3872 (D:\workspace\uts-consumer\target\classes started by Administrator in D:\workspace\uts-consumer) 12 2018-03-21 20:29:51.367 INFO 3872 --- [ main] bhz.uts.UtsConsumerApplication : No active profile set, falling back to default profiles: default 13 2018-03-21 20:29:51.624 INFO 3872 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2e56c4eb: startup date [Wed Mar 21 20:29:51 CST 2018]; root of context hierarchy 14 2018-03-21 20:29:57.664 INFO 3872 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8002 (http) 15 2018-03-21 20:29:57.714 INFO 3872 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 16 2018-03-21 20:29:57.716 INFO 3872 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16 17 2018-03-21 20:29:58.174 INFO 3872 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 18 2018-03-21 20:29:58.174 INFO 3872 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6572 ms 19 2018-03-21 20:29:58.349 INFO 3872 --- [ost-startStop-1] b.u.c.database.DruidDataSourceConfig : druid console manager init : org.springframework.boot.web.servlet.ServletRegistrationBean@4c747266 20 2018-03-21 20:29:58.407 INFO 3872 --- [ost-startStop-1] b.u.c.database.DruidDataSourceConfig : druid filter register : org.springframework.boot.web.servlet.FilterRegistrationBean@16c0e7b0 21 2018-03-21 20:29:59.167 INFO 3872 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'statViewServlet' to [/druid/*] 22 2018-03-21 20:29:59.168 INFO 3872 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 23 2018-03-21 20:29:59.180 INFO 3872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 24 2018-03-21 20:29:59.181 INFO 3872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 25 2018-03-21 20:29:59.181 INFO 3872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 26 2018-03-21 20:29:59.181 INFO 3872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 27 2018-03-21 20:29:59.181 INFO 3872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webStatFilter' to urls: [/*] 28 2018-03-21 20:29:59.415 INFO 3872 --- [ main] b.u.c.database.DruidDataSourceConfig : -----------uts1DataSource : {}---------{ 29 CreateTime:"2018-03-21 20:29:59", 30 ActiveCount:0, 31 PoolingCount:0, 32 CreateCount:0, 33 DestroyCount:0, 34 CloseCount:0, 35 ConnectCount:0, 36 Connections:[ 37 ] 38 } 39 2018-03-21 20:30:00.131 ERROR 3872 --- [ main] c.a.druid.pool.DruidAbstractDataSource : maxIdle is deprecated 40 2018-03-21 20:30:00.569 INFO 3872 --- [ main] b.u.c.database.DruidDataSourceConfig : -----------uts2DataSource : {}---------{ 41 CreateTime:"2018-03-21 20:30:00", 42 ActiveCount:0, 43 PoolingCount:0, 44 CreateCount:0, 45 DestroyCount:0, 46 CloseCount:0, 47 ConnectCount:0, 48 Connections:[ 49 ] 50 } 51 2018-03-21 20:30:00.694 ERROR 3872 --- [ main] c.a.druid.pool.DruidAbstractDataSource : maxIdle is deprecated 52 2018-03-21 20:30:00.701 INFO 3872 --- [ main] b.u.c.database.DruidDataSourceConfig : -----------uts3DataSource : {}---------{ 53 CreateTime:"2018-03-21 20:30:00", 54 ActiveCount:0, 55 PoolingCount:0, 56 CreateCount:0, 57 DestroyCount:0, 58 CloseCount:0, 59 ConnectCount:0, 60 Connections:[ 61 ] 62 } 63 2018-03-21 20:30:00.809 ERROR 3872 --- [ main] c.a.druid.pool.DruidAbstractDataSource : maxIdle is deprecated 64 2018-03-21 20:30:00.818 INFO 3872 --- [ main] b.u.c.database.DruidDataSourceConfig : -----------uts4DataSource : {}---------{ 65 CreateTime:"2018-03-21 20:30:00", 66 ActiveCount:0, 67 PoolingCount:0, 68 CreateCount:0, 69 DestroyCount:0, 70 CloseCount:0, 71 ConnectCount:0, 72 Connections:[ 73 ] 74 } 75 2018-03-21 20:30:00.942 ERROR 3872 --- [ main] c.a.druid.pool.DruidAbstractDataSource : maxIdle is deprecated 76 2018-03-21 20:30:03.297 INFO 3872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2e56c4eb: startup date [Wed Mar 21 20:29:51 CST 2018]; root of context hierarchy 77 2018-03-21 20:30:03.526 INFO 3872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 78 2018-03-21 20:30:03.527 INFO 3872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 79 2018-03-21 20:30:03.637 INFO 3872 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 80 2018-03-21 20:30:03.637 INFO 3872 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 81 2018-03-21 20:30:03.767 INFO 3872 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 82 2018-03-21 20:30:05.257 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 83 2018-03-21 20:30:05.258 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'uts1' has been autodetected for JMX exposure 84 2018-03-21 20:30:05.258 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'uts2' has been autodetected for JMX exposure 85 2018-03-21 20:30:05.259 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'uts3' has been autodetected for JMX exposure 86 2018-03-21 20:30:05.259 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'uts4' has been autodetected for JMX exposure 87 2018-03-21 20:30:05.268 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'uts2': registering with JMX server as MBean [com.alibaba.druid.pool:name=uts2,type=DruidDataSource] 88 2018-03-21 20:30:05.272 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'uts3': registering with JMX server as MBean [com.alibaba.druid.pool:name=uts3,type=DruidDataSource] 89 2018-03-21 20:30:05.272 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'uts4': registering with JMX server as MBean [com.alibaba.druid.pool:name=uts4,type=DruidDataSource] 90 2018-03-21 20:30:05.273 INFO 3872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'uts1': registering with JMX server as MBean [com.alibaba.druid.pool:name=uts1,type=DruidDataSource] 91 spring 加载完毕.. 92 服务器启动了-------- 93 2018-03-21 20:30:07.174 INFO 3872 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8002 (http) 94 2018-03-21 20:30:07.192 INFO 3872 --- [ main] bhz.uts.UtsConsumerApplication : Started UtsConsumerApplication in 17.462 seconds (JVM running for 19.649) 95 2018-03-21 20:31:49.019 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d2119747-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"王五","accountNo":"50033457780002320965","balance":47257,"businessType":"1","createBy":"system","createTime":1521635506742,"creditAmount":249,"dedbitAmount":0,"digest":"淘宝买单","id":"d2119747-2d03-11e8-b721-6c881435c21c","oppAccountName":"小3","oppAccountNo":"788876699990005589","serialno":"201706244BF4A6A153026AB2F4CB","status":"0","tradeDate":1498306489000,"updateBy":"system","updateTime":1521635506742} 96 ---->around 97 注解参数: 98 classname----------:bhz.uts.service.TradeDetailService 99 superclass--------:java.lang.Object 100 isinterface---------:false 101 target----------:bhz.uts.service.TradeDetailService 102 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 103 method-----------:balanceInsert 104 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@1898797d 105 2018-03-21 20:31:49.307 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 106 hashCode是:---1791290580 107 selectDataBaseNumer:-------3 108 selectTableNumer:-----------0 109 经过判断后我们的currentDataBaseNameString是:====uts3 110 currentDataBaseNameString的code是=====uts3 111 currentDataBaseNameString的code是=====uts3 112 dataBaseType放进去UTS2 113 dataBaseType取出来UTS2 114 dataBaseType放进去UTS3 115 dataBaseType取出来UTS3 116 hashCode是:---1791290580 117 selectDataBaseNumer:-------3 118 selectTableNumer:-----------0 119 dataBaseType取出来UTS3 120 2018-03-21 20:31:50.113 INFO 3872 --- [ntLoopGroup-3-1] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited 121 result1 122 数据同步成功,id-----d2119747-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 123 hashCode是:---5980208862018-03-21 20:31:50.174 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d37f09f8-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"张三","accountNo":"30001040191113380583","balance":6041,"businessType":"1","createBy":"system","createTime":1521635509128,"creditAmount":242,"dedbitAmount":0,"digest":"转账","id":"d37f09f8-2d03-11e8-b721-6c881435c21c","oppAccountName":"小5","oppAccountNo":"344339999333000001","serialno":"2017011449BB8DBDE4037E5FEF0C","status":"0","tradeDate":1484376566000,"updateBy":"system","updateTime":1521635509128} 124 ---->around 125 注解参数: 126 classname----------:bhz.uts.service.TradeDetailService 127 superclass--------:java.lang.Object 128 isinterface---------:false 129 target----------:bhz.uts.service.TradeDetailService 130 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 131 method-----------:balanceInsert 132 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@28978803 133 2018-03-21 20:31:50.175 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 134 135 selectDataBaseNumer:-------1 136 selectTableNumer:-----------6 137 经过判断后我们的currentDataBaseNameString是:====uts1 138 currentDataBaseNameString的code是=====uts1 139 hashCode是:---598020886 140 selectDataBaseNumer:-------1 141 selectTableNumer:-----------6 142 dataBaseType放进去UTS1 143 dataBaseType取出来UTS1 144 dataBaseType取出来UTS1 145 2018-03-21 20:31:50.315 INFO 3872 --- [ntLoopGroup-3-1] com.alibaba.druid.pool.DruidDataSource : {dataSource-2} inited 146 result1 147 2018-03-21 20:31:50.332 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d3c0cde9-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"赵六","accountNo":"68886000080002320926","balance":15425,"businessType":"1","createBy":"system","createTime":1521635509559,"creditAmount":392,"dedbitAmount":0,"digest":"付款","id":"d3c0cde9-2d03-11e8-b721-6c881435c21c","oppAccountName":"小2","oppAccountNo":"498980000566599998","serialno":"2017020549B0945E0DDAB51D5682","status":"0","tradeDate":1486272364000,"updateBy":"system","updateTime":1521635509559} 148 ---->around 149 注解参数: 150 classname----------:bhz.uts.service.TradeDetailService 151 superclass--------:java.lang.Object 152 isinterface---------:false 153 target----------:bhz.uts.service.TradeDetailService 154 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 155 method-----------:balanceInsert 156 数据同步成功,id-----d37f09f8-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 157 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@5cdbf201 158 2018-03-21 20:31:50.333 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 159 hashCode是:---420301458 160 selectDataBaseNumer:-------2 161 selectTableNumer:-----------8 162 经过判断后我们的currentDataBaseNameString是:====uts2 163 hashCode是:---420301458 164 selectDataBaseNumer:-------2 165 selectTableNumer:-----------8 166 dataBaseType取出来null 167 result1 168 数据同步成功,id-----d3c0cde9-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 169 2018-03-21 20:31:50.344 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d3f3017a-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"赵六","accountNo":"68886000080002320926","balance":26373,"businessType":"1","createBy":"system","createTime":1521635509887,"creditAmount":221,"dedbitAmount":0,"digest":"美团买单","id":"d3f3017a-2d03-11e8-b721-6c881435c21c","oppAccountName":"小4","oppAccountNo":"155500006660007779","serialno":"20170522432D8430729C13ED61EC","status":"0","tradeDate":1495397430000,"updateBy":"system","updateTime":1521635509887} 170 ---->around 171 注解参数: 172 classname----------:bhz.uts.service.TradeDetailService 173 superclass--------:java.lang.Object 174 isinterface---------:false 175 target----------:bhz.uts.service.TradeDetailService 176 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 177 method-----------:balanceInsert 178 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@ab9c1aa 179 2018-03-21 20:31:50.345 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 180 dataBaseType放进去UTS2 181 dataBaseType取出来UTS2 182 dataBaseType放进去UTS3 183 dataBaseType取出来UTS3 184 hashCode是:---558986500 185 selectDataBaseNumer:-------3 186 selectTableNumer:-----------0 187 经过判断后我们的currentDataBaseNameString是:====uts3 188 currentDataBaseNameString的code是=====uts3 189 currentDataBaseNameString的code是=====uts3 190 hashCode是:---558986500 191 selectDataBaseNumer:-------3 192 selectTableNumer:-----------0 193 dataBaseType取出来UTS3 194 result1 195 2018-03-21 20:31:50.351 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d424239b-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"张三","accountNo":"30001040191113380583","balance":67654,"businessType":"1","createBy":"system","createTime":1521635510209,"creditAmount":206,"dedbitAmount":0,"digest":"美团买单","id":"d424239b-2d03-11e8-b721-6c881435c21c","oppAccountName":"小4","oppAccountNo":"155500006660007779","serialno":"2017052246068E5BA10E2A63B799","status":"0","tradeDate":1495435006000,"updateBy":"system","updateTime":1521635510209} 196 ---->around 197 注解参数: 198 classname----------:bhz.uts.service.TradeDetailService 199 superclass--------:java.lang.Object 200 isinterface---------:false 201 target----------:bhz.uts.service.TradeDetailService 202 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 203 method-----------:balanceInsert 204 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@6dab1555 205 2018-03-21 20:31:50.352 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 206 dataBaseType放进去UTS4 207 dataBaseType取出来UTS4 208 数据同步成功,id-----d3f3017a-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 209 hashCode是:---6907513 210 selectDataBaseNumer:-------4 211 selectTableNumer:-----------3 212 经过判断后我们的currentDataBaseNameString是:====uts4 213 currentDataBaseNameString的code是=====uts4 214 hashCode是:---6907513 215 selectDataBaseNumer:-------4 216 selectTableNumer:-----------3 217 dataBaseType取出来UTS4 218 2018-03-21 20:31:50.407 INFO 3872 --- [ntLoopGroup-3-1] com.alibaba.druid.pool.DruidDataSource : {dataSource-3} inited 219 数据同步成功,id-----d424239b-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 220 result1 221 2018-03-21 20:31:50.614 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d460905c-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"李四","accountNo":"40003242903000023274","balance":64957,"businessType":"1","createBy":"system","createTime":1521635510605,"creditAmount":49,"dedbitAmount":0,"digest":"百度买单","id":"d460905c-2d03-11e8-b721-6c881435c21c","oppAccountName":"小4","oppAccountNo":"155500006660007779","serialno":"20170318445398E39F48E9A73F0F","status":"0","tradeDate":1489812178000,"updateBy":"system","updateTime":1521635510605} 222 ---->around 223 注解参数: 224 classname----------:bhz.uts.service.TradeDetailService 225 superclass--------:java.lang.Object 226 isinterface---------:false 227 target----------:bhz.uts.service.TradeDetailService 228 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 229 method-----------:balanceInsert 230 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@71eea6ae 231 2018-03-21 20:31:50.615 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 232 hashCode是:---1631706292 233 selectDataBaseNumer:-------2 234 selectTableNumer:-----------2 235 经过判断后我们的currentDataBaseNameString是:====uts2 236 hashCode是:---1631706292 237 selectDataBaseNumer:-------2 238 selectTableNumer:-----------2 239 dataBaseType取出来null 240 result1 241 数据同步成功,id-----d460905c-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 242 hashCode是:---460759787 243 selectDataBaseNumer:-------3 244 selectTableNumer:-----------7 245 经过判断后我们的currentDataBaseNameString是:====uts3 246 currentDataBaseNameString的code是=====uts3 247 currentDataBaseNameString的code是=====uts3 248 hashCode是:---460759787 249 selectDataBaseNumer:-------3 250 selectTableNumer:-----------7 251 2018-03-21 20:31:50.908 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d48e300d-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"赵六","accountNo":"68886000080002320926","balance":82400,"businessType":"1","createBy":"system","createTime":1521635510904,"creditAmount":279,"dedbitAmount":0,"digest":"付款","id":"d48e300d-2d03-11e8-b721-6c881435c21c","oppAccountName":"小4","oppAccountNo":"155500006660007779","serialno":"20170117447E815F26CAAE20CCF2","status":"0","tradeDate":1484641536000,"updateBy":"system","updateTime":1521635510904} 252 ---->around 253 注解参数: 254 classname----------:bhz.uts.service.TradeDetailService 255 superclass--------:java.lang.Object 256 isinterface---------:false 257 target----------:bhz.uts.service.TradeDetailService 258 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 259 method-----------:balanceInsert 260 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@4568b252 261 2018-03-21 20:31:50.909 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 262 dataBaseType放进去UTS2 263 dataBaseType取出来UTS2 264 dataBaseType放进去UTS3 265 dataBaseType取出来UTS3 266 dataBaseType取出来UTS3 267 result1 268 数据同步成功,id-----d48e300d-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 269 2018-03-21 20:31:51.200 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d4babe4e-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"张三","accountNo":"30001040191113380583","balance":6910,"businessType":"1","createBy":"system","createTime":1521635511197,"creditAmount":258,"dedbitAmount":0,"digest":"转账","id":"d4babe4e-2d03-11e8-b721-6c881435c21c","oppAccountName":"小5","oppAccountNo":"344339999333000001","serialno":"20170117450CA1FB42E7C972384E","status":"0","tradeDate":1484665901000,"updateBy":"system","updateTime":1521635511197} 270 ---->around 271 注解参数: 272 classname----------:bhz.uts.service.TradeDetailService 273 superclass--------:java.lang.Object 274 isinterface---------:false 275 target----------:bhz.uts.service.TradeDetailService 276 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 277 method-----------:balanceInsert 278 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@1358b6e6 279 2018-03-21 20:31:51.201 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 280 dataBaseType放进去UTS1 281 dataBaseType取出来UTS1 282 hashCode是:---1403149728 283 selectDataBaseNumer:-------1 284 selectTableNumer:-----------8 285 经过判断后我们的currentDataBaseNameString是:====uts1 286 currentDataBaseNameString的code是=====uts1 287 hashCode是:---1403149728 288 selectDataBaseNumer:-------1 289 selectTableNumer:-----------8 290 dataBaseType取出来UTS1 291 result1 292 数据同步成功,id-----d4babe4e-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 293 hashCode是:---1317542953 294 selectDataBaseNumer:-------4 295 selectTableNumer:-----------3 296 经过判断后我们的currentDataBaseNameString是:====uts4 297 currentDataBaseNameString的code是=====uts4 298 hashCode是:---1317542953 299 selectDataBaseNumer:-------4 300 selectTableNumer:-----------3 301 2018-03-21 20:31:51.501 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d4e8ac1f-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"李四","accountNo":"40003242903000023274","balance":94890,"businessType":"1","createBy":"system","createTime":1521635511497,"creditAmount":367,"dedbitAmount":0,"digest":"付款","id":"d4e8ac1f-2d03-11e8-b721-6c881435c21c","oppAccountName":"小2","oppAccountNo":"498980000566599998","serialno":"20170726466A808FAF29D7FB93ED","status":"0","tradeDate":1501051580000,"updateBy":"system","updateTime":1521635511497} 302 ---->around 303 注解参数: 304 classname----------:bhz.uts.service.TradeDetailService 305 superclass--------:java.lang.Object 306 isinterface---------:false 307 target----------:bhz.uts.service.TradeDetailService 308 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 309 method-----------:balanceInsert 310 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@4a9e59e5 311 2018-03-21 20:31:51.502 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 312 dataBaseType放进去UTS4 313 dataBaseType取出来UTS4 314 dataBaseType取出来UTS4 315 result1 316 数据同步成功,id-----d4e8ac1f-2d03-11e8-b721-6c881435c21c----,并且返回相应信息 317 2018-03-21 20:31:51.802 INFO 3872 --- [ntLoopGroup-3-1] bhz.uts.netty.NettyServerHandler : id d51699f0-2d03-11e8-b721-6c881435c21c,tag trade_detail,type save,reqeustMessage {"accountName":"张三","accountNo":"30001040191113380583","balance":70036,"businessType":"1","createBy":"system","createTime":1521635511798,"creditAmount":88,"dedbitAmount":0,"digest":"转账","id":"d51699f0-2d03-11e8-b721-6c881435c21c","oppAccountName":"小1","oppAccountNo":"500013334380543599","serialno":"201706164067A7614264D4D69E03","status":"0","tradeDate":1497607433000,"updateBy":"system","updateTime":1521635511798} 318 ---->around 319 注解参数: 320 classname----------:bhz.uts.service.TradeDetailService 321 superclass--------:java.lang.Object 322 isinterface---------:false 323 target----------:bhz.uts.service.TradeDetailService 324 proxy-----------:bhz.uts.service.TradeDetailService$$EnhancerBySpringCGLIB$$975b1946 325 method-----------:balanceInsert 326 getArgs()[0]-----------:bhz.uts.entity.TradeDetail@3d53c750 327 2018-03-21 20:31:51.802 INFO 3872 --- [ntLoopGroup-3-1] b.u.c.d.SelectConnectionIntercepor : -------------开始选择数据库----------------- 328 hashCode是:---1767363709 329 selectDataBaseNumer:-------3 330 selectTableNumer:-----------9 331 经过判断后我们的currentDataBaseNameString是:====uts3 332 dataBaseType放进去UTS2 333 currentDataBaseNameString的code是=====uts3dataBaseType取出来UTS2 334 dataBaseType放进去UTS3 335 dataBaseType取出来UTS3 336 337 currentDataBaseNameString的code是=====uts3 338 hashCode是:---1767363709 339 selectDataBaseNumer:-------3 340 selectTableNumer:-----------9 341 dataBaseType取出来UTS3 342 result1 343 数据同步成功,id-----d51699f0-2d03-11e8-b721-6c881435c21c----,并且返回相应信息