mirror of https://github.com/jeecgboot/jeecg-boot
commit
04c55fa3ba
|
@ -2,6 +2,7 @@ package org.jeecg.modules.test.seata.account.service.impl;
|
|||
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import io.seata.core.context.RootContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.jeecg.modules.test.seata.account.entity.SeataAccount;
|
||||
|
@ -34,6 +35,7 @@ public class SeataAccountServiceImpl implements SeataAccountService {
|
|||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class)
|
||||
public void reduceBalance(Long userId, BigDecimal amount) {
|
||||
log.info("xid:"+ RootContext.getXID());
|
||||
log.info("=============ACCOUNT START=================");
|
||||
SeataAccount account = accountMapper.selectById(userId);
|
||||
Assert.notNull(account, "用户不存在");
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.jeecg.modules.test.seata.order.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
|
||||
import io.seata.core.context.RootContext;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.modules.test.seata.order.dto.PlaceOrderRequest;
|
||||
|
@ -39,6 +41,7 @@ public class SeataOrderServiceImpl implements SeataOrderService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional
|
||||
public void placeOrder(PlaceOrderRequest request) {
|
||||
log.info("xid:"+RootContext.getXID());
|
||||
log.info("=============ORDER START=================");
|
||||
Long userId = request.getUserId();
|
||||
Long productId = request.getProductId();
|
||||
|
@ -58,7 +61,12 @@ public class SeataOrderServiceImpl implements SeataOrderService {
|
|||
// 扣减库存并计算总价
|
||||
BigDecimal amount = productClient.reduceStock(productId, count);
|
||||
// 扣减余额
|
||||
accountClient.reduceBalance(userId, amount);
|
||||
String str = accountClient.reduceBalance(userId, amount);
|
||||
// feign响应被二次封装,判断使主事务回滚
|
||||
JSONObject jsonObject = JSONObject.parseObject(str);
|
||||
if (jsonObject.getInteger("code") != 200) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
order.setStatus(OrderStatus.SUCCESS);
|
||||
order.setTotalPrice(amount);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.jeecg.modules.test.seata.product.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import io.seata.core.context.RootContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
|
@ -35,6 +36,7 @@ public class SeataProductServiceImpl implements SeataProductService {
|
|||
@Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class)
|
||||
@Override
|
||||
public BigDecimal reduceStock(Long productId, Integer count) {
|
||||
log.info("xid:"+ RootContext.getXID());
|
||||
log.info("=============PRODUCT START=================");
|
||||
// 检查库存
|
||||
SeataProduct product = productMapper.selectById(productId);
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -72,6 +72,8 @@
|
|||
<!-- Log4j2爆雷漏洞 -->
|
||||
<log4j2.version>2.17.0</log4j2.version>
|
||||
<logback.version>1.2.9</logback.version>
|
||||
<!-- seata -->
|
||||
<seata.version>1.5.2</seata.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
|
@ -159,6 +161,12 @@
|
|||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
<version>${seata.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- system 模块-->
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
|
|
Loading…
Reference in New Issue