package com.transaction_anno.service.impl;

import com.transaction_anno.entity.AccountEntity;
import com.transaction_anno.service.AccountService;
import com.transaction_anno.service.AccountTwoService;
import com.transaction_anno.service.AccountTxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountTxServiceImpl implements AccountTxService {
    @Autowired
    AccountService accountService;
    @Autowired
    AccountTwoService accountTwoService;

//    @Transactional(propagation = Propagation.REQUIRED)
    @Transactional
    @Override
    public void transformTx() {
        // 转账操作
        AccountEntity reduceEntity = new AccountEntity();
        AccountEntity addEntity = new AccountEntity();
        reduceEntity.setId(16).setBalance(3.0);
        addEntity.setId(17).setBalance(3.0);
        accountService.reduceAccount(reduceEntity);
        accountTwoService.addAccountBalance(addEntity);
    }
}
