Commit db9a6484 authored by Administrator's avatar Administrator

创建项目

parent 7b8c2b61
...@@ -4,6 +4,7 @@ import cn.quant.baa.pay.annotation.BusinessMapping; ...@@ -4,6 +4,7 @@ import cn.quant.baa.pay.annotation.BusinessMapping;
import cn.quant.baa.pay.component.Sequencer; import cn.quant.baa.pay.component.Sequencer;
import cn.quant.baa.pay.context.TransactionSession; import cn.quant.baa.pay.context.TransactionSession;
import cn.quant.baa.pay.model.BusinessRequest; import cn.quant.baa.pay.model.BusinessRequest;
import cn.quant.spring.LogicallyException;
import cn.quant.spring.context.ServerApplicationContext; import cn.quant.spring.context.ServerApplicationContext;
import cn.quant.spring.util.StringUtils; import cn.quant.spring.util.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
...@@ -35,8 +36,14 @@ public class BusinessMappingAspect { ...@@ -35,8 +36,14 @@ public class BusinessMappingAspect {
private ServerApplicationContext serverApplicationContext; private ServerApplicationContext serverApplicationContext;
public void session(Object arg) { public void session(Object arg) {
if (arg == null) {
TransactionSession.newInstance(null, serverApplicationContext, sequencer);
return;
}
if (BusinessRequest.class.isInstance(arg)) { if (BusinessRequest.class.isInstance(arg)) {
TransactionSession.newInstance((BusinessRequest) arg, serverApplicationContext, sequencer); TransactionSession.newInstance((BusinessRequest) arg, serverApplicationContext, sequencer);
}else{
throw new IllegalArgumentException("Illegal business mapping session.");
} }
} }
...@@ -56,6 +63,8 @@ public class BusinessMappingAspect { ...@@ -56,6 +63,8 @@ public class BusinessMappingAspect {
, annotation.session(), args.length, method)); , annotation.session(), args.length, method));
} }
session(args[annotation.session() - 1]); session(args[annotation.session() - 1]);
} else {
session(null);
} }
try { try {
Object object = joinPoint.proceed(); Object object = joinPoint.proceed();
......
...@@ -8,6 +8,7 @@ import cn.quant.spring.context.ServerApplicationContext; ...@@ -8,6 +8,7 @@ import cn.quant.spring.context.ServerApplicationContext;
import cn.quant.spring.data.jpa.entity.OptimisticEntity; import cn.quant.spring.data.jpa.entity.OptimisticEntity;
import cn.quant.spring.data.jpa.repository.JapRepositoryProxy; import cn.quant.spring.data.jpa.repository.JapRepositoryProxy;
import cn.quant.spring.data.jpa.repository.RepositoryProxy; import cn.quant.spring.data.jpa.repository.RepositoryProxy;
import cn.quant.spring.util.DateUtils;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -42,7 +43,7 @@ public class TransactionSession extends BusinessSession { ...@@ -42,7 +43,7 @@ public class TransactionSession extends BusinessSession {
return sequencer.nextId(id); return sequencer.nextId(id);
} }
public int partitionKey(long id){ public int partitionKey(long id) {
return sequencer.partitionKey(id); return sequencer.partitionKey(id);
} }
...@@ -65,11 +66,19 @@ public class TransactionSession extends BusinessSession { ...@@ -65,11 +66,19 @@ public class TransactionSession extends BusinessSession {
TransactionSession session = local.get(); TransactionSession session = local.get();
if (session == null) { if (session == null) {
session = new TransactionSession(context, sequencer); session = new TransactionSession(context, sequencer);
Date businessDate = request.getBusinessDate(); if (request == null) {
if (businessDate == null) {
session.setBusinessDate(LocalDateTime.now()); session.setBusinessDate(LocalDateTime.now());
session.setRequestTime(DateUtils.now());
} else {
session.setRequestTime(request.getRequestTime());
Date businessDate = request.getBusinessDate();
if (businessDate == null) {
session.setBusinessDate(LocalDateTime.now());
} else {
session.setBusinessDate(DateUtils.toLocalDateTime(businessDate));
}
} }
session.setRequestTime(request.getRequestTime());
local.set(session); local.set(session);
} }
return session; return session;
......
...@@ -50,6 +50,11 @@ ...@@ -50,6 +50,11 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>cn.quant.baa.pay</groupId>
<artifactId>baa-pay-server</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>servers</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>target/bin</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${project.package.name}.jar</source>
<outputDirectory>/</outputDirectory>
<destName>${project.package.name}.jar</destName>
</file>
<file>
<source>target/config/application-${spring.profiles.active}.properties</source>
<outputDirectory>/config</outputDirectory>
<destName>application.properties</destName>
</file>
<file>
<source>target/config/logback-spring.xml</source>
<outputDirectory>/config</outputDirectory>
<destName>logback-spring.xml</destName>
</file>
</files>
</assembly>
\ No newline at end of file
package cn.quant.baa.pay.config; package cn.quant.baa.pay.config;
import com.fasterxml.jackson.databind.DeserializationFeature; import cn.quant.spring.boot.config.WebMessageConfigurer;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List;
/** /**
* Created by hechao on 2018/6/28. * Created by hechao on 2018/6/28.
*/ */
@Configuration @Configuration
public class WebMvcConfiguration implements WebMvcConfigurer { public class WebMvcConfiguration extends WebMessageConfigurer {
private MappingJackson2HttpMessageConverter messageConverter;
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(messageConverter);
}
@Bean @Bean
public MappingJackson2HttpMessageConverter httpMessageConverter() { public MappingJackson2HttpMessageConverter httpMessageConverter() {
messageConverter = new MappingJackson2HttpMessageConverter();
SimpleModule simpleModule = new SimpleModule(); MappingJackson2HttpMessageConverter converter = super.httpMessageConverter();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance); ObjectMapper objectMapper = converter.getObjectMapper();
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
simpleModule.addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
simpleModule.addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); return converter;
simpleModule.addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE);
simpleModule.addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE);
simpleModule.addSerializer(ZonedDateTime.class, ZonedDateTimeSerializer.INSTANCE);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(simpleModule);
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
messageConverter.setObjectMapper(objectMapper);
return messageConverter;
} }
} }
package cn.quant.baa.pay.rest;
/**
* Created by Administrator on 2021/9/26 0026.
*/
public class TransactionController extends BusinessController{
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="${dubbo.application.name}"/>
<dubbo:registry address="${dubbo.registry.address}"/>
<dubbo:protocol name="${dubbo.protocol.name}" port="${dubbo.protocol.port}" />
<bean id="testDubboService" class="cn.quant.baa.pay.dubbo.service.TestDubboServiceImpl"></bean>
<dubbo:service protocol="dubbo" interface="cn.quant.baa.pay.dubbo.facade.TestDubboServiceFacade"
ref="testDubboService"
version="${cn.quant.baa.pay.dubbo.facade.TestDubboServiceFacade.version}"
timeout="${cn.quant.baa.pay.dubbo.facade.TestDubboServiceFacade.timeout}" retries="0"/>
</beans>
...@@ -13,8 +13,7 @@ server.servlet.context-path=/ ...@@ -13,8 +13,7 @@ server.servlet.context-path=/
quant.server.number=1 quant.server.number=1
quant.server.sequencer.operator=TWEPOCH_PLUS quant.server.sequencer.operator=TWEPOCH_PLUS
quant.server.sequencer.sequence-bits=8 quant.server.sequencer.sequence-bits=8
#Database #Databasespring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=jdbc:mysql://172.17.5.17:31548/baa_pay_1.0?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai spring.datasource.url=jdbc:mysql://172.17.5.17:31548/baa_pay_1.0?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
spring.datasource.username=qa spring.datasource.username=qa
...@@ -30,6 +29,10 @@ spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect ...@@ -30,6 +29,10 @@ spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.database=MYSQL spring.jpa.database=MYSQL
quant.baapay.local-cache-expire.time=6000 quant.baapay.acquirer.local-cache-expire.time=6000
quant.baapay.local-cache-expire.unit=SECONDS quant.baapay.acquirer.local-cache-expire.unit=SECONDS
quant.baapay.local-cache-expire.size=1000 quant.baapay.acquirer.local-cache-expire.size=1000
\ No newline at end of file
quant.baapay.profile.local-cache-expire.time=6000
quant.baapay.profile.local-cache-expire.unit=SECONDS
quant.baapay.profile.local-cache-expire.size=1000
\ No newline at end of file
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.mariadb.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/employees</property>
<!-- JDBC connection pool (use the built-in) -->
<!--
<property name="connection.pool_size">1</property>
-->
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping class="cn.quant.baa.pay.jpa.entity.UserEntity"/>
<!-- Drop and re-create the database schema on startup -->
<!--
<property name="hbm2ddl.auto">update</property>
-->
</session-factory>
</hibernate-configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="ROLLINGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.dir}/${project.name}/${project.name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logging.dir}/${project.name}/${project.name}.%d{yyyy-MM-dd}-%i.log</fileNamePattern>
<maxHistory>90</maxHistory>
<maxFileSize>512MB</maxFileSize>
<totalSizeCap>10GB</totalSizeCap>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder>
<charset>utf-8</charset>
<Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}][%p][%t|%logger{1.}|%M] - %msg %ex{full}%n</Pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!--<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %ex{full}%n</pattern>-->
<pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}][%p][%t|%logger{1.}|%M] - %msg %ex{full}%n</pattern>
</encoder>
</appender>
<logger name="cn.quant.baa.pay" level="DEBUG"/>
<logger name="javax.activation" level="ERROR"/>
<logger name="org.quartz.core" level="ERROR"/>
<logger name="org.quartz.simpl" level="ERROR"/>
<logger name="io.lettuce.core" level="ERROR"/>
<logger name="io.netty" level="ERROR"/>
<logger name="com.zaxxer.hikari.pool" level="ERROR"/>
<logger name="com.alibaba.dubbo.common.extension" level="ERROR"/>
<logger name="sun.net.www.protocol.http" level="ERROR"/>
<logger name="com.ctrip.framework.apollo.internals" level="ERROR"/>
<logger name="org.apache.zookeeper" level="ERROR"/>
<logger name="org.apache.curator" level="ERROR"/>
<logger name="org.apache.coyote" level="ERROR"/>
<logger name="org.apache.catalina" level="ERROR"/>
<logger name="org.hibernate.hql" level="ERROR"/>
<logger name="org.hibernate.loader" level="ERROR"/>
<logger name="org.hibernate.type" level="ERROR"/>
<logger name="org.hibernate.persister" level="ERROR"/>
<logger name="org.hibernate.cfg" level="ERROR"/>
<logger name="org.hibernate.mapping" level="ERROR"/>
<logger name="org.hibernate.jpa.event" level="ERROR"/>
<logger name="org.hibernate.validator.internal" level="ERROR"/>
<logger name="org.hibernate.engine.internal" level="ERROR"/>
<logger name="org.hibernate.boot.model" level="ERROR"/>
<logger name="org.hibernate.boot.internal" level="ERROR"/>
<logger name="org.apache.tomcat.util" level="ERROR"/>
<logger name="org.springframework.orm" level="ERROR"/>
<logger name="org.springframework.jmx" level="ERROR"/>
<logger name="org.springframework.jndi" level="ERROR"/>
<logger name="org.springframework.aop" level="ERROR"/>
<logger name="org.springframework.web" level="ERROR"/>
<logger name="org.springframework.context" level="ERROR"/>
<logger name="org.springframework.core" level="ERROR"/>
<logger name="org.springframework.beans" level="ERROR"/>
<logger name="org.springframework.boot.web" level="ERROR"/>
<logger name="org.springframework.boot.actuate" level="ERROR"/>
<logger name="org.springframework.boot.context" level="ERROR"/>
<logger name="org.springframework.boot.autoconfigure.logging" level="ERROR"/>
<logger name="org.springframework.data.redis" level="ERROR"/>
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE"/>
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="ERROR"/>
<logger name="org.hibernate.engine.QueryParameters" level="ERROR"/>
<logger name="org.hibernate.SQL" level="ERROR" />
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLINGFILE"/>
</root>
</configuration>
\ No newline at end of file
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
</contextListener> </contextListener>
<appender name="ROLLINGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <appender name="ROLLINGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.dir}/${project.name}/${project.name}.log</file> <file>/home/quant_group/logs/${project.name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logging.dir}/${project.name}/${project.name}.%d{yyyy-MM-dd}-%i.log</fileNamePattern> <fileNamePattern>/home/quant_group/logs/${project.name}.%d{yyyy-MM-dd}-%i.log</fileNamePattern>
<maxHistory>90</maxHistory> <maxHistory>90</maxHistory>
<maxFileSize>512MB</maxFileSize> <maxFileSize>512MB</maxFileSize>
<totalSizeCap>10GB</totalSizeCap> <totalSizeCap>10GB</totalSizeCap>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
</encoder> </encoder>
</appender> </appender>
<logger name="cn.quant.baa.pay" level="ERROR"/> <logger name="cn.quant.baa.pay" level="WARN"/>
<logger name="javax.activation" level="ERROR"/> <logger name="javax.activation" level="ERROR"/>
<logger name="org.quartz.core" level="ERROR"/> <logger name="org.quartz.core" level="ERROR"/>
<logger name="org.quartz.simpl" level="ERROR"/> <logger name="org.quartz.simpl" level="ERROR"/>
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<logger name="org.hibernate.engine.QueryParameters" level="ERROR"/> <logger name="org.hibernate.engine.QueryParameters" level="ERROR"/>
<logger name="org.hibernate.SQL" level="ERROR" /> <logger name="org.hibernate.SQL" level="ERROR" />
<root level="${logging.level}"> <root level="WARN">
<appender-ref ref="STDOUT"/> <appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLINGFILE"/> <appender-ref ref="ROLLINGFILE"/>
</root> </root>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!--这里的loacation是你连接数据库的jar包,可以从项目依赖里面找-->
<classPathEntry location="e:\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar"/>
<context id="context">
<!-- 是否生成注释 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库连接,数据库版本高的话需要添加时区serverTimezone=GMT%2B8 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/employees"
userId="root" password="111111" />
<!-- 生成的包名和工程名 -->
<javaModelGenerator targetPackage="cn.quant.baa.pay.jpa.entity.mysql"
targetProject="src/main/java/"/>
<!-- xml映射文件 -->
<sqlMapGenerator targetPackage="mapping"
targetProject="src/main/resources/" />
<!-- mapper接口 -->
<javaClientGenerator targetPackage="cn.quant.baa.pay.mybatis.mapper"
targetProject="src/main/java/" type="XMLMAPPER" />
<!-- 数据库表 以及是否生成example,可以同时生成多个-->
<table tableName="departments" domainObjectName="DepartmentsEntity"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
\ No newline at end of file
...@@ -16,6 +16,7 @@ public class WebMvcConfiguration extends WebMessageConfigurer { ...@@ -16,6 +16,7 @@ public class WebMvcConfiguration extends WebMessageConfigurer {
@Bean @Bean
public MappingJackson2HttpMessageConverter httpMessageConverter() { public MappingJackson2HttpMessageConverter httpMessageConverter() {
MappingJackson2HttpMessageConverter converter = super.httpMessageConverter(); MappingJackson2HttpMessageConverter converter = super.httpMessageConverter();
ObjectMapper objectMapper = converter.getObjectMapper(); ObjectMapper objectMapper = converter.getObjectMapper();
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
......
...@@ -56,7 +56,7 @@ public class TransactionController extends BusinessController { ...@@ -56,7 +56,7 @@ public class TransactionController extends BusinessController {
@ResponseBody @ResponseBody
@BusinessMapping(session = 1) @BusinessMapping
@PostMapping("/pay") @PostMapping("/pay")
public ResponseEntity pay(@RequestBody BusinessRequest<PayRequestData> request) throws Exception { public ResponseEntity pay(@RequestBody BusinessRequest<PayRequestData> request) throws Exception {
PayRequestData requestData = request.getData(); PayRequestData requestData = request.getData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment