feat(seata): 添加本地事务
This commit is contained in:
parent
b59f70afbe
commit
849bc54d26
|
@ -5,9 +5,10 @@ import org.mybatis.spring.annotation.MapperScan;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("com.atguigu.account.mapper")
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
|
|
|
@ -4,15 +4,18 @@ import com.atguigu.account.mapper.AccountTblMapper;
|
|||
import com.atguigu.account.service.AccountService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
@Service
|
||||
public class AccountServiceImpl implements AccountService {
|
||||
|
||||
@Autowired
|
||||
AccountTblMapper accountTblMapper;
|
||||
|
||||
@Override
|
||||
public void debit(String userId, int money) {
|
||||
// 扣减账户余额
|
||||
accountTblMapper.debit(userId,money);
|
||||
accountTblMapper.debit(userId, money);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication;
|
|||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class SeataBusinessMainApplication {
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
package com.atguigu.business.service.impl;
|
||||
|
||||
import com.alibaba.nacos.shaded.io.grpc.Grpc;
|
||||
import com.atguigu.business.service.BusinessService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Grpc.TransportAttr
|
||||
@Service
|
||||
public class BusinessServiceImpl implements BusinessService {
|
||||
@Override
|
||||
public void purchase(String userId, String commodityCode, int orderCount) {
|
||||
//TODO 1. 扣减库存
|
||||
// TODO 1. 扣减库存
|
||||
|
||||
//TODO 2. 创建订单
|
||||
// TODO 2. 创建订单
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ import org.mybatis.spring.annotation.MapperScan;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("com.atguigu.order.mapper")
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
|
|
|
@ -5,7 +5,9 @@ import com.atguigu.order.mapper.OrderTblMapper;
|
|||
import com.atguigu.order.service.OrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
|
@ -14,12 +16,12 @@ public class OrderServiceImpl implements OrderService {
|
|||
|
||||
@Override
|
||||
public OrderTbl create(String userId, String commodityCode, int orderCount) {
|
||||
//1、计算订单价格
|
||||
// 1、计算订单价格
|
||||
int orderMoney = calculate(commodityCode, orderCount);
|
||||
|
||||
//TODO 2、扣减账户余额
|
||||
// TODO 2、扣减账户余额
|
||||
|
||||
//3、保存订单
|
||||
// 3、保存订单
|
||||
OrderTbl orderTbl = new OrderTbl();
|
||||
orderTbl.setUserId(userId);
|
||||
orderTbl.setCommodityCode(commodityCode);
|
||||
|
@ -33,6 +35,6 @@ public class OrderServiceImpl implements OrderService {
|
|||
|
||||
// 计算价格
|
||||
private int calculate(String commodityCode, int orderCount) {
|
||||
return 9*orderCount;
|
||||
return 9 * orderCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@ import org.mybatis.spring.annotation.MapperScan;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("com.atguigu.storage.mapper")
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class SeataStorageMainApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SeataStorageMainApplication.class, args);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@ import com.atguigu.storage.mapper.StorageTblMapper;
|
|||
import com.atguigu.storage.service.StorageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
@Service
|
||||
public class StorageServiceImpl implements StorageService {
|
||||
|
||||
|
|
Loading…
Reference in New Issue