mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
commit
02b7997d16
@ -10,6 +10,11 @@ import com.mybatisfle.test.mybatisflexspringbootseata.mapper.OrderTblMapper;
|
||||
import com.mybatisfle.test.mybatisflexspringbootseata.mapper.StockTblMapper;
|
||||
import com.mybatisflex.core.datasource.DataSourceKey;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import io.seata.core.context.RootContext;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import org.mybatis.logging.Logger;
|
||||
import org.mybatis.logging.LoggerFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -17,6 +22,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class TestService {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TestService.class);
|
||||
|
||||
@Autowired
|
||||
AccountTblMapper accountTblMapper;
|
||||
|
||||
@ -27,27 +34,29 @@ public class TestService {
|
||||
StockTblMapper stockTblMapper;
|
||||
|
||||
// @Transactional
|
||||
@GlobalTransactional
|
||||
public boolean buy() {
|
||||
// DataSourceKey.use("accountdb");
|
||||
LOGGER.warn(() -> "xid:"+RootContext.getXID());
|
||||
QueryWrapper account =new QueryWrapper();
|
||||
account.where(AccountTblTableDef.ACCOUNT_TBL.USER_ID.eq("1001"));
|
||||
AccountTbl accountTbl = accountTblMapper.selectOneByQuery(account);
|
||||
accountTbl.setMoney(accountTbl.getMoney() - 5);
|
||||
accountTblMapper.update(accountTbl);
|
||||
// DataSourceKey.use("stockdb");
|
||||
// QueryWrapper stock = new QueryWrapper();
|
||||
// stock.where("id=1");
|
||||
// StockTbl stockTbl = stockTblMapper.selectOneByQuery(stock);
|
||||
// stockTbl.setCount(stockTbl.getCount() - 1);
|
||||
// stockTblMapper.update(stockTbl);
|
||||
// DataSourceKey.use("orderdb");
|
||||
// OrderTbl orderTbl = new OrderTbl();
|
||||
// orderTbl.setCount(5);
|
||||
// orderTbl.setMoney(5);
|
||||
// orderTbl.setUserId(accountTbl.getUserId());
|
||||
// orderTbl.setCount(1);
|
||||
// orderTbl.setCommodityCode(stockTbl.getCommodityCode());
|
||||
// orderTblMapper.insert(orderTbl);
|
||||
DataSourceKey.use("stockdb");
|
||||
QueryWrapper stock = new QueryWrapper();
|
||||
stock.where("id=1");
|
||||
StockTbl stockTbl = stockTblMapper.selectOneByQuery(stock);
|
||||
stockTbl.setCount(stockTbl.getCount() - 1);
|
||||
stockTblMapper.update(stockTbl);
|
||||
DataSourceKey.use("orderdb");
|
||||
OrderTbl orderTbl = new OrderTbl();
|
||||
orderTbl.setCount(5);
|
||||
orderTbl.setMoney(5);
|
||||
orderTbl.setUserId(accountTbl.getUserId());
|
||||
orderTbl.setCount(1);
|
||||
orderTbl.setCommodityCode(stockTbl.getCommodityCode());
|
||||
orderTblMapper.insert(orderTbl);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user