mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-04 04:45:28 +08:00
JeecgBoot 3.1.0 版本发布,基于代码生成器的企业级低代码平台
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>jeecg-cloud-test</artifactId>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<version>3.1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<description>分布式事务测试模块</description>
|
||||
<artifactId>jeecg-cloud-test-seata</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<artifactId>jeecg-boot-starter-seata</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,59 @@
|
||||
package org.jeecg.modules.test.seata.controller;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.jeecg.modules.test.seata.dto.PlaceOrderRequest;
|
||||
import org.jeecg.modules.test.seata.service.SeataOrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/order")
|
||||
@Api(tags = "seata测试")
|
||||
public class SeataOrderController {
|
||||
|
||||
@Autowired
|
||||
private SeataOrderService orderService;
|
||||
|
||||
/**
|
||||
* 自由下单
|
||||
*/
|
||||
@PostMapping("/placeOrder")
|
||||
@ApiOperation(value = "自由下单", notes = "自由下单")
|
||||
public String placeOrder(@Validated @RequestBody PlaceOrderRequest request) {
|
||||
orderService.placeOrder(request);
|
||||
return "下单成功";
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试商品库存不足-异常回滚
|
||||
*/
|
||||
@PostMapping("/test1")
|
||||
@ApiOperation(value = "测试商品库存不足", notes = "测试商品库存不足")
|
||||
public String test1() {
|
||||
//商品单价10元,库存20个,用户余额50元,模拟一次性购买22个。 期望异常回滚
|
||||
orderService.placeOrder(new PlaceOrderRequest(1L, 1L, 22));
|
||||
return "下单成功";
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试用户账户余额不足-异常回滚
|
||||
*/
|
||||
@PostMapping("/test2")
|
||||
@ApiOperation(value = "测试用户账户余额不足", notes = "测试用户账户余额不足")
|
||||
public String test2() {
|
||||
//商品单价10元,库存20个,用户余额50元,模拟一次性购买6个。 期望异常回滚
|
||||
orderService.placeOrder(new PlaceOrderRequest(1L, 1L, 6));
|
||||
return "下单成功";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package org.jeecg.modules.test.seata.dto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
/**
|
||||
* @Description: 订单请求对象
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PlaceOrderRequest {
|
||||
|
||||
@NotNull
|
||||
private Long userId;
|
||||
|
||||
@NotNull
|
||||
private Long productId;
|
||||
|
||||
@NotNull
|
||||
private Integer amount;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package org.jeecg.modules.test.seata.dto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Description: 余额请求对象
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ReduceBalanceRequest {
|
||||
|
||||
private Long userId;
|
||||
private Integer price;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package org.jeecg.modules.test.seata.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
/**
|
||||
* @Description: 库存请求对象
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ReduceStockRequest {
|
||||
|
||||
private Long productId;
|
||||
private Integer amount;
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package org.jeecg.modules.test.seata.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 账户
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@TableName("account")
|
||||
public class SeataAccount {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 余额
|
||||
*/
|
||||
private Double balance;
|
||||
|
||||
private Date lastUpdateTime;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package org.jeecg.modules.test.seata.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.jeecg.modules.test.seata.enums.OrderStatus;
|
||||
|
||||
/**
|
||||
* @Description: 订单
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Builder
|
||||
@Data
|
||||
@TableName("p_order")
|
||||
public class SeataOrder {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 订单状态
|
||||
*/
|
||||
private OrderStatus status;
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
private Integer amount;
|
||||
/**
|
||||
* 总金额
|
||||
*/
|
||||
private Double totalPrice;
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package org.jeecg.modules.test.seata.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
/**
|
||||
* @Description: 产品
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@TableName("product")
|
||||
public class SeataProduct {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 价格
|
||||
*/
|
||||
private Double price;
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
private Integer stock;
|
||||
|
||||
private Date lastUpdateTime;
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package org.jeecg.modules.test.seata.enums;
|
||||
|
||||
/**
|
||||
* @Description: 订单状态
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
public enum OrderStatus {
|
||||
/**
|
||||
* INIT
|
||||
*/
|
||||
INIT,
|
||||
/**
|
||||
* SUCCESS
|
||||
*/
|
||||
SUCCESS,
|
||||
/**
|
||||
* FAIL
|
||||
*/
|
||||
FAIL
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package org.jeecg.modules.test.seata.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.jeecg.modules.test.seata.entity.SeataAccount;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface SeataAccountMapper extends BaseMapper<SeataAccount> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package org.jeecg.modules.test.seata.mapper;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.jeecg.modules.test.seata.entity.SeataOrder;
|
||||
|
||||
@Mapper
|
||||
public interface SeataOrderMapper extends BaseMapper<SeataOrder> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package org.jeecg.modules.test.seata.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.jeecg.modules.test.seata.entity.SeataProduct;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface SeataProductMapper extends BaseMapper<SeataProduct> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package org.jeecg.modules.test.seata.service;
|
||||
|
||||
/**
|
||||
* @Description: 账户接口
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface SeataAccountService {
|
||||
/**
|
||||
* @param userId 用户 ID
|
||||
* @param price 扣减金额
|
||||
*/
|
||||
void reduceBalance(Long userId, Double price);
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package org.jeecg.modules.test.seata.service;
|
||||
|
||||
import org.jeecg.modules.test.seata.dto.PlaceOrderRequest;
|
||||
|
||||
/**
|
||||
* @Description: 订单接口
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface SeataOrderService {
|
||||
/**
|
||||
* 下单
|
||||
*
|
||||
* @param placeOrderRequest 订单请求参数
|
||||
*/
|
||||
void placeOrder(PlaceOrderRequest placeOrderRequest);
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package org.jeecg.modules.test.seata.service;
|
||||
|
||||
/**
|
||||
* @Description: 产品接口
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface SeataProductService {
|
||||
/**
|
||||
* 扣减库存
|
||||
*
|
||||
* @param productId 商品 ID
|
||||
* @param amount 扣减数量
|
||||
* @return 商品总价
|
||||
*/
|
||||
Double reduceStock(Long productId, Integer amount);
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package org.jeecg.modules.test.seata.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.modules.test.seata.entity.SeataAccount;
|
||||
import org.jeecg.modules.test.seata.mapper.SeataAccountMapper;
|
||||
import org.jeecg.modules.test.seata.service.SeataAccountService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SeataAccountServiceImpl implements SeataAccountService {
|
||||
@Resource
|
||||
private SeataAccountMapper accountMapper;
|
||||
|
||||
/**
|
||||
* 事务传播特性设置为 REQUIRES_NEW 开启新的事务
|
||||
*/
|
||||
@DS("account")
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void reduceBalance(Long userId, Double price) {
|
||||
log.info("=============ACCOUNT START=================");
|
||||
SeataAccount account = accountMapper.selectById(userId);
|
||||
Assert.notNull(account, "用户不存在");
|
||||
Double balance = account.getBalance();
|
||||
log.info("下单用户{}余额为 {},商品总价为{}", userId, balance, price);
|
||||
|
||||
if (balance < price) {
|
||||
log.warn("用户 {} 余额不足,当前余额:{}", userId, balance);
|
||||
throw new RuntimeException("余额不足");
|
||||
}
|
||||
log.info("开始扣减用户 {} 余额", userId);
|
||||
double currentBalance = account.getBalance() - price;
|
||||
account.setBalance(currentBalance);
|
||||
accountMapper.updateById(account);
|
||||
log.info("扣减用户 {} 余额成功,扣减后用户账户余额为{}", userId, currentBalance);
|
||||
log.info("=============ACCOUNT END=================");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package org.jeecg.modules.test.seata.service.impl;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.modules.test.seata.dto.PlaceOrderRequest;
|
||||
import org.jeecg.modules.test.seata.entity.SeataOrder;
|
||||
import org.jeecg.modules.test.seata.enums.OrderStatus;
|
||||
import org.jeecg.modules.test.seata.mapper.SeataOrderMapper;
|
||||
import org.jeecg.modules.test.seata.service.SeataAccountService;
|
||||
import org.jeecg.modules.test.seata.service.SeataOrderService;
|
||||
import org.jeecg.modules.test.seata.service.SeataProductService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
/**
|
||||
* @Description: 订单服务类
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SeataOrderServiceImpl implements SeataOrderService {
|
||||
|
||||
@Resource
|
||||
private SeataOrderMapper orderMapper;
|
||||
@Autowired
|
||||
private SeataAccountService accountService;
|
||||
@Autowired
|
||||
private SeataProductService productService;
|
||||
|
||||
@DS("order")
|
||||
@Override
|
||||
@Transactional
|
||||
@GlobalTransactional
|
||||
public void placeOrder(PlaceOrderRequest request) {
|
||||
log.info("=============ORDER START=================");
|
||||
Long userId = request.getUserId();
|
||||
Long productId = request.getProductId();
|
||||
Integer amount = request.getAmount();
|
||||
log.info("收到下单请求,用户:{}, 商品:{},数量:{}", userId, productId, amount);
|
||||
|
||||
|
||||
SeataOrder order = SeataOrder.builder()
|
||||
.userId(userId)
|
||||
.productId(productId)
|
||||
.status(OrderStatus.INIT)
|
||||
.amount(amount)
|
||||
.build();
|
||||
|
||||
orderMapper.insert(order);
|
||||
log.info("订单一阶段生成,等待扣库存付款中");
|
||||
// 扣减库存并计算总价
|
||||
Double totalPrice = productService.reduceStock(productId, amount);
|
||||
// 扣减余额
|
||||
accountService.reduceBalance(userId, totalPrice);
|
||||
|
||||
order.setStatus(OrderStatus.SUCCESS);
|
||||
order.setTotalPrice(totalPrice);
|
||||
orderMapper.updateById(order);
|
||||
log.info("订单已成功下单");
|
||||
log.info("=============ORDER END=================");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package org.jeecg.modules.test.seata.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.jeecg.modules.test.seata.entity.SeataProduct;
|
||||
import org.jeecg.modules.test.seata.mapper.SeataProductMapper;
|
||||
import org.jeecg.modules.test.seata.service.SeataProductService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @Description: 产品服务类
|
||||
* @author: zyf
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SeataProductServiceImpl implements SeataProductService {
|
||||
|
||||
@Resource
|
||||
private SeataProductMapper productMapper;
|
||||
|
||||
/**
|
||||
* 事务传播特性设置为 REQUIRES_NEW 开启新的事务
|
||||
*/
|
||||
@DS("product")
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
@Override
|
||||
public Double reduceStock(Long productId, Integer amount) {
|
||||
log.info("=============PRODUCT START=================");
|
||||
// 检查库存
|
||||
SeataProduct product = productMapper.selectById(productId);
|
||||
Assert.notNull(product, "商品不存在");
|
||||
Integer stock = product.getStock();
|
||||
log.info("商品编号为 {} 的库存为{},订单商品数量为{}", productId, stock, amount);
|
||||
|
||||
if (stock < amount) {
|
||||
log.warn("商品编号为{} 库存不足,当前库存:{}", productId, stock);
|
||||
throw new RuntimeException("库存不足");
|
||||
}
|
||||
log.info("开始扣减商品编号为 {} 库存,单价商品价格为{}", productId, product.getPrice());
|
||||
// 扣减库存
|
||||
int currentStock = stock - amount;
|
||||
product.setStock(currentStock);
|
||||
productMapper.updateById(product);
|
||||
double totalPrice = product.getPrice() * amount;
|
||||
log.info("扣减商品编号为 {} 库存成功,扣减后库存为{}, {} 件商品总价为 {} ", productId, currentStock, amount, totalPrice);
|
||||
log.info("=============PRODUCT END=================");
|
||||
return totalPrice;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
seata:
|
||||
enable-auto-data-source-proxy: false
|
||||
service:
|
||||
grouplist:
|
||||
default: 127.0.0.1:8091
|
||||
vgroup-mapping:
|
||||
springboot-seata-group: default
|
||||
# seata 事务组编号 用于TC集群名
|
||||
tx-service-group: springboot-seata-group
|
||||
transport:
|
||||
heartbeat: false
|
||||
spring:
|
||||
datasource:
|
||||
dynamic:
|
||||
seata: true # 开启对 seata的支持
|
||||
seata-mode: AT #支持XA及AT模式,默认AT
|
||||
datasource:
|
||||
# 设置 账号数据源配置
|
||||
account:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/jeecg-account?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false
|
||||
username: root
|
||||
password: root
|
||||
schema: classpath:sql/schema-account.sql
|
||||
# 设置 订单数据源配置
|
||||
order:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/jeecg-order?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false
|
||||
username: root
|
||||
password: root
|
||||
schema: classpath:sql/schema-order.sql
|
||||
# 设置商品 数据源配置
|
||||
product:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/jeecg-product?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false
|
||||
username: root
|
||||
password: root
|
||||
schema: classpath:sql/schema-product.sql
|
||||
@ -0,0 +1,29 @@
|
||||
DROP TABLE IF EXISTS account;
|
||||
CREATE TABLE account
|
||||
(
|
||||
id INT(11) NOT NULL AUTO_INCREMENT,
|
||||
balance DOUBLE DEFAULT NULL,
|
||||
last_update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
DEFAULT CHARSET = utf8;
|
||||
|
||||
DROP TABLE IF EXISTS undo_log;
|
||||
CREATE TABLE undo_log
|
||||
(
|
||||
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
branch_id BIGINT(20) NOT NULL,
|
||||
xid VARCHAR(100) NOT NULL,
|
||||
context VARCHAR(128) NOT NULL,
|
||||
rollback_info LONGBLOB NOT NULL,
|
||||
log_status INT(11) NOT NULL,
|
||||
log_created DATETIME NOT NULL,
|
||||
log_modified DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY ux_undo_log (xid, branch_id)
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
DEFAULT CHARSET = utf8;
|
||||
INSERT INTO account (id, balance)
|
||||
VALUES (1, 50);
|
||||
@ -0,0 +1,32 @@
|
||||
DROP TABLE IF EXISTS p_order;
|
||||
CREATE TABLE p_order
|
||||
(
|
||||
id INT(11) NOT NULL AUTO_INCREMENT,
|
||||
user_id INT(11) DEFAULT NULL,
|
||||
product_id INT(11) DEFAULT NULL,
|
||||
amount INT(11) DEFAULT NULL,
|
||||
total_price DOUBLE DEFAULT NULL,
|
||||
status VARCHAR(100) DEFAULT NULL,
|
||||
add_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
last_update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
DEFAULT CHARSET = utf8;
|
||||
|
||||
DROP TABLE IF EXISTS undo_log;
|
||||
CREATE TABLE undo_log
|
||||
(
|
||||
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
branch_id BIGINT(20) NOT NULL,
|
||||
xid VARCHAR(100) NOT NULL,
|
||||
context VARCHAR(128) NOT NULL,
|
||||
rollback_info LONGBLOB NOT NULL,
|
||||
log_status INT(11) NOT NULL,
|
||||
log_created DATETIME NOT NULL,
|
||||
log_modified DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY ux_undo_log (xid, branch_id)
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
DEFAULT CHARSET = utf8;
|
||||
@ -0,0 +1,31 @@
|
||||
DROP TABLE IF EXISTS product;
|
||||
CREATE TABLE product
|
||||
(
|
||||
id INT(11) NOT NULL AUTO_INCREMENT,
|
||||
price DOUBLE DEFAULT NULL,
|
||||
stock INT(11) DEFAULT NULL,
|
||||
last_update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
DEFAULT CHARSET = utf8;
|
||||
|
||||
DROP TABLE IF EXISTS undo_log;
|
||||
CREATE TABLE undo_log
|
||||
(
|
||||
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
branch_id BIGINT(20) NOT NULL,
|
||||
xid VARCHAR(100) NOT NULL,
|
||||
context VARCHAR(128) NOT NULL,
|
||||
rollback_info LONGBLOB NOT NULL,
|
||||
log_status INT(11) NOT NULL,
|
||||
log_created DATETIME NOT NULL,
|
||||
log_modified DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY ux_undo_log (xid, branch_id)
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
DEFAULT CHARSET = utf8;
|
||||
|
||||
INSERT INTO product (id, price, stock)
|
||||
VALUES (1, 10, 20);
|
||||
@ -0,0 +1,79 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Type : MariaDB
|
||||
Source Server Version : 100316
|
||||
Source Host : localhost:3300
|
||||
Source Schema : seata
|
||||
|
||||
Target Server Type : MariaDB
|
||||
Target Server Version : 100316
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 05/01/2022 20:25:07
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for branch_table
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `branch_table`;
|
||||
CREATE TABLE `branch_table` (
|
||||
`branch_id` bigint(20) NOT NULL,
|
||||
`xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`transaction_id` bigint(20) NULL DEFAULT NULL,
|
||||
`resource_group_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`resource_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`branch_type` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`status` tinyint(4) NULL DEFAULT NULL,
|
||||
`client_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`gmt_create` datetime(6) NULL DEFAULT NULL,
|
||||
`gmt_modified` datetime(6) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`branch_id`) USING BTREE,
|
||||
INDEX `idx_xid`(`xid`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for global_table
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `global_table`;
|
||||
CREATE TABLE `global_table` (
|
||||
`xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`transaction_id` bigint(20) NULL DEFAULT NULL,
|
||||
`status` tinyint(4) NOT NULL,
|
||||
`application_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`transaction_service_group` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`transaction_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`timeout` int(11) NULL DEFAULT NULL,
|
||||
`begin_time` bigint(20) NULL DEFAULT NULL,
|
||||
`application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`gmt_create` datetime(0) NULL DEFAULT NULL,
|
||||
`gmt_modified` datetime(0) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`xid`) USING BTREE,
|
||||
INDEX `idx_gmt_modified_status`(`gmt_modified`, `status`) USING BTREE,
|
||||
INDEX `idx_transaction_id`(`transaction_id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for lock_table
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `lock_table`;
|
||||
CREATE TABLE `lock_table` (
|
||||
`row_key` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`xid` varchar(96) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`transaction_id` bigint(20) NULL DEFAULT NULL,
|
||||
`branch_id` bigint(20) NOT NULL,
|
||||
`resource_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`table_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`pk` varchar(36) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
|
||||
`gmt_create` datetime(0) NULL DEFAULT NULL,
|
||||
`gmt_modified` datetime(0) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`row_key`) USING BTREE,
|
||||
INDEX `idx_branch_id`(`branch_id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@ -0,0 +1,12 @@
|
||||
CREATE TABLE `undo_log` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`branch_id` bigint(20) NOT NULL,
|
||||
`xid` varchar(100) NOT NULL,
|
||||
`context` varchar(128) NOT NULL,
|
||||
`rollback_info` longblob NOT NULL,
|
||||
`log_status` int(11) NOT NULL,
|
||||
`log_created` datetime NOT NULL,
|
||||
`log_modified` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8;
|
||||
Reference in New Issue
Block a user