package com.yzt.airconditionersystem;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yzt.airconditionersystem.bean.Operator;
import com.yzt.airconditionersystem.bean.Project;
import com.yzt.airconditionersystem.service.OperatorService;
import com.yzt.airconditionersystem.service.ProjectService;
import com.yzt.airconditionersystem.util.MyUtils;
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-15 17:18
 */
@SpringBootTest
public class ProjectTest {

    @Autowired
    private ProjectService projectService;
    @Autowired
    private OperatorService operatorService;

    @Test
    public void testInsert() {
        List<Project> list = new ArrayList<>();
        List<Operator> operatorList = operatorService.list();

        for (int i = 0; i < 50; i++) {
            String companyName = MyUtils.companyName((int) (Math.random() * 14 + 4));
            Project project = new Project(null, "吴悦",
                    operatorList.get((int)(Math.random() * 100)).getId(),
                    "广东省广州市",
                    MyUtils.name((int) (Math.random() * 16 + 4)),
                    null, null);
            list.add(project);
        }

        boolean b = projectService.saveBatch(list);
        System.out.println(b);

    }

    @Test
    public void testGet() {
        Page<Project> page = new Page<>(1, 10);
        LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
        page = projectService.page(page, queryWrapper);
        System.out.println(page.getRecords());
    }


}
