package com.api;

import com.api.dao.AccountMapper;
import com.api.dao.ProductMapper;
import com.api.entity.AccountEntity;
import com.api.entity.ProductEntity;
import com.api.enums.SexEnum;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class MybatisPlusTest2 {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private AccountMapper accountMapper;
    // 测试乐观锁
    @Test
    public void testOpt() {
        ProductEntity productZhang = productMapper.selectById(0);
        ProductEntity productWang = productMapper.selectById(0);
        productZhang.setProductPrice(productZhang.getProductPrice()+1);
        int updateZhang = productMapper.updateById(productZhang);
        productWang.setProductPrice(productWang.getProductPrice()-11);
        int updateWang = productMapper.updateById(productWang);
        if(updateWang == 0) {
            ProductEntity wangNew = productMapper.selectById(0);
            wangNew.setProductPrice(wangNew.getProductPrice()-11);
            productMapper.updateById(wangNew);
        }
    }
    @Test
    public void testEnum() {
        AccountEntity addEntity = new AccountEntity();
        addEntity.setUserName("limei");
        addEntity.setDepId(2);
        addEntity.setBalance(10000.0);
        addEntity.setSex(SexEnum.FEMALE);
        int insert = accountMapper.insert(addEntity);
    }


}
