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.City;
import com.cesgroup.homwork.mybatis.sample.mapper.CityMapper;
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.HashMap;
import java.util.List;
import java.util.Map;

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

    @Resource
    private CityMapper cityMapper;
    @Autowired
    private BatchService batchService;
    ///////////////////////////////////////////////////
    ////
    ////                   测试类型转换
    ////
    ///////////////////////////////////////////////////

    @Test
    void select() {
        Console.log(JSONUtil.toJsonStr( cityMapper.findById("ea5f9ecd8ee44fa9b83373902fc854e4")));
    }

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