package com.cesgroup.homwork.mybatis;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONUtil;
import com.cesgroup.homwork.mybatis.sample.entity.User;
import com.cesgroup.homwork.mybatis.sample.mapper.UserMapper;
import com.cesgroup.homwork.mybatis.sample.service.BatchService;
import org.junit.jupiter.api.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 javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
class MybatisApplicationTests {

    @Resource
    private UserMapper userMapper;
    @Autowired
    private BatchService batchService;

    /**
     * 测试类型转换
     */
    @Test
    void select() {
        Console.log(JSONUtil.toJsonStr( userMapper.findById("ea5f9ecd8ee44fa9b83373902fc854e4")));
    }


    /**
     * 测试批量处
     */
    @Test
    void batch() {
        List<User> users = new ArrayList<User>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setName(RandomUtil.randomString("是否是法发热人刚明年吧",4));
            users.add(user);
        }
        batchService.batchInsertUser(users);
    }
}
