package com.api;

import com.api.dao.AccountMapper;
import com.api.entity.AccountEntity;
import com.api.service.AccountService;
import com.api.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class MybatisPlusTest {
    @Autowired
    AccountMapper accountMapper;
    @Autowired
    AccountService accountService;
    @Test
    public void test1() {
        QueryWrapper<AccountEntity> accountEntityQueryWrapper = new QueryWrapper<>();
        accountEntityQueryWrapper.eq("id",16);
        AccountEntity accountEntity = accountMapper.selectOne(accountEntityQueryWrapper);
    }
    @Test
    public void test2() {
//        StringUtils.isNotBlank()
        // 使用lambdaWrapper
        LambdaQueryWrapper<AccountEntity> accountEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
        accountEntityLambdaQueryWrapper.eq(AccountEntity::getDepId,1);
        List<AccountEntity> list = accountService.list(accountEntityLambdaQueryWrapper);
    }
    @Test
    public void testPage() {
        Page<AccountEntity> accountEntityPage = new Page<>();
        accountEntityPage.setCurrent(2);
        accountEntityPage.setSize(2);
        LambdaQueryWrapper<AccountEntity> accountEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
        accountEntityLambdaQueryWrapper.eq(AccountEntity::getDepId,1);
        IPage<AccountEntity> page = accountService.page(accountEntityPage, accountEntityLambdaQueryWrapper);
    }
    @Test
    public void testMapperPage() {
        Page<AccountEntity> accountEntityPage = new Page<>();
        accountEntityPage.setCurrent(2);
        accountEntityPage.setSize(2);
        accountEntityPage = accountMapper.getPageVO(accountEntityPage, 1);
    }


}
