package com.yzt.airconditionersystem;

import com.yzt.airconditionersystem.bean.Company;
import com.yzt.airconditionersystem.bean.Operator;
import com.yzt.airconditionersystem.enums.CompanyTypeEnum;
import com.yzt.airconditionersystem.mapper.OperatorMapper;
import com.yzt.airconditionersystem.service.CompanyService;
import com.yzt.airconditionersystem.service.OperatorService;
import com.yzt.airconditionersystem.util.MyUtils;
import org.apache.ibatis.annotations.Mapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;

/**
 * @author TzZach
 * @since 2022-04-13 11:59
 */
@SpringBootTest
public class OperatorTest {

    @Autowired
    private OperatorMapper operatorMapper;
    @Autowired
    private OperatorService operatorService;
    @Autowired
    private CompanyService companyService;

    @Test
    public void testCompanyInsert() {
        List<Company> companies = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Company company = new Company(null, "12345678", MyUtils.name(4), MyUtils.name(6),
                    MyUtils.name(7), MyUtils.name(7),
                    MyUtils.name(4), MyUtils.phone(), CompanyTypeEnum.CLIENT.getId());
            companies.add(company);
        }

        companyService.saveBatch(companies);
    }

    @Test
    public void testSelect() {
        List<Operator> list = operatorService.list();
        list.forEach(System.out::println);
    }


    @Test
    public void testInsert() {
        List<Operator> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            String name = MyUtils.name(4);
            Operator operator = new Operator(null, name, MyUtils.companyName(7), "广东省广州市",
                    "海珠区东沙街", name, MyUtils.phone());
            list.add(operator);
        }
        boolean b = operatorService.saveBatch(list);
        System.out.println(b);
    }

    @Test
    public void testSQLCondition(){
        Operator one = operatorMapper.getOne(new Operator(null, "", "", "", "", "吴悦", ""));
        System.out.println(one);
    }

    @Test
    public void testInsert1() {
        String name = MyUtils.name(4);
        Operator operator = new Operator(null, name, MyUtils.companyName(7), "广东省广州市",
                "海珠区东沙街", name, MyUtils.phone());
        int insert = operatorMapper.insert(operator);
        Integer id = operator.getId();
        System.out.println(id);
    }



}
