forked from lenve/javaboy-code-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,832 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.javaboy</groupId> | ||
<artifactId>account</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<spring-boot.version>2.3.7.RELEASE</spring-boot.version> | ||
<spring-cloud-alibaba.version>2.2.2.RELEASE</spring-cloud-alibaba.version> | ||
<spring-cloud.version>Hoxton.SR9</spring-cloud.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-starter-alibaba-seata</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
<version>2.1.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-openfeign</artifactId> | ||
</dependency> | ||
<dependency> | ||
<artifactId>common</artifactId> | ||
<groupId>org.javaboy</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>${spring-cloud.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-alibaba-dependencies</artifactId> | ||
<version>${spring-cloud-alibaba.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>2.3.7.RELEASE</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
15 changes: 15 additions & 0 deletions
15
seata-at/account/src/main/java/org/javaboy/AccountApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.javaboy; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; | ||
|
||
@SpringBootApplication | ||
@EnableEurekaClient | ||
public class AccountApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AccountApplication.class, args); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
seata-at/account/src/main/java/org/javaboy/account/controller/AccountController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.javaboy.account.controller; | ||
|
||
import org.javaboy.account.service.AccountService; | ||
import org.javaboy.common.RespBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
@RestController | ||
public class AccountController { | ||
|
||
@Autowired | ||
AccountService accountService; | ||
|
||
@PostMapping("/deductAccount") | ||
public RespBean deductAccount(String account, Double money) { | ||
if (accountService.deductAccount(account, money)) { | ||
return RespBean.ok("扣款成功"); | ||
} | ||
return RespBean.error("扣款失败"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
seata-at/account/src/main/java/org/javaboy/account/mapper/AccountMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.javaboy.account.mapper; | ||
|
||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.apache.ibatis.annotations.Select; | ||
import org.apache.ibatis.annotations.Update; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
@Mapper | ||
public interface AccountMapper { | ||
@Update("update account_tbl set money=money-#{money} where user_id=#{account}") | ||
int updateAccount(@Param("account") String account, @Param("money") Double money); | ||
|
||
@Select("select money from account_tbl where user_id=#{account}") | ||
Double getMoneyByAccount(String account); | ||
} |
31 changes: 31 additions & 0 deletions
31
seata-at/account/src/main/java/org/javaboy/account/service/AccountService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.javaboy.account.service; | ||
|
||
import org.javaboy.account.mapper.AccountMapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
@Service | ||
public class AccountService { | ||
|
||
@Autowired | ||
AccountMapper accountMapper; | ||
|
||
public boolean deductAccount(String account, Double money) { | ||
accountMapper.updateAccount(account, money); | ||
Double m = accountMapper.getMoneyByAccount(account); | ||
if (m >= 0) { | ||
return true; | ||
}else{ | ||
throw new RuntimeException("账户余额不足"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
server.port=1111 | ||
spring.application.name=account | ||
eureka.client.service-url.defaultZone=http://localhost:8761/eureka | ||
|
||
spring.datasource.username=root | ||
spring.datasource.password=123 | ||
spring.datasource.url=jdbc:mysql:///account?serverTimezone=Asia/Shanghai&useSSL=false | ||
|
||
spring.cloud.alibaba.seata.tx-service-group=my_test_tx_group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
transport { | ||
# tcp udt unix-domain-socket | ||
type = "TCP" | ||
#NIO NATIVE | ||
server = "NIO" | ||
#enable heartbeat | ||
heartbeat = true | ||
# the client batch send request enable | ||
enableClientBatchSendRequest = true | ||
#thread factory for netty | ||
threadFactory { | ||
bossThreadPrefix = "NettyBoss" | ||
workerThreadPrefix = "NettyServerNIOWorker" | ||
serverExecutorThread-prefix = "NettyServerBizHandler" | ||
shareBossWorker = false | ||
clientSelectorThreadPrefix = "NettyClientSelector" | ||
clientSelectorThreadSize = 1 | ||
clientWorkerThreadPrefix = "NettyClientWorkerThread" | ||
# netty boss thread size,will not be used for UDT | ||
bossThreadSize = 1 | ||
#auto default pin or 8 | ||
workerThreadSize = "default" | ||
} | ||
shutdown { | ||
# when destroy server, wait seconds | ||
wait = 3 | ||
} | ||
serialization = "seata" | ||
compressor = "none" | ||
} | ||
service { | ||
#transaction service group mapping | ||
vgroupMapping.my_test_tx_group = "default" | ||
#only support when registry.type=file, please don't set multiple addresses | ||
default.grouplist = "127.0.0.1:8091" | ||
#degrade, current not support | ||
enableDegrade = false | ||
#disable seata | ||
disableGlobalTransaction = false | ||
} | ||
|
||
client { | ||
rm { | ||
asyncCommitBufferLimit = 10000 | ||
lock { | ||
retryInterval = 10 | ||
retryTimes = 30 | ||
retryPolicyBranchRollbackOnConflict = true | ||
} | ||
reportRetryCount = 5 | ||
tableMetaCheckEnable = false | ||
reportSuccessEnable = false | ||
} | ||
tm { | ||
commitRetryCount = 5 | ||
rollbackRetryCount = 5 | ||
} | ||
undo { | ||
dataValidation = true | ||
logSerialization = "jackson" | ||
logTable = "undo_log" | ||
} | ||
log { | ||
exceptionRate = 100 | ||
} | ||
} |
Oops, something went wrong.