package com.prolog.eis;

import com.prolog.eis.dto.bindgrid.BGDGridDto;
import com.prolog.eis.dto.bindgrid.BindGridDispatchDto;
import com.prolog.eis.service.bindgrid.BindGridAlgorithmService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Version: 1.0
 * @Author: wuhan
 * @Created: 2024/8/2 23:16
 */
@SpringBootTest(classes = DispatchApplication.class)
@RunWith(SpringRunner.class)
public class BindGridTest {
    @Resource
    private BindGridAlgorithmService bindGridAlgorithmService;

    @Test
    public void test() {
        for (int i = 0; i < 20; i++) {
            try {
                BindGridDispatchDto dispatchDto = new BindGridDispatchDto();
                this.createGrid(dispatchDto, "1", "g1", 0);
                this.createGrid(dispatchDto, "2", "g1", 0);
                this.createGrid(dispatchDto, "3", "g1", 0);
                this.createGrid(dispatchDto, "4", "g2", 555);
                this.createGrid(dispatchDto, "5", "g2", 0);
                this.createGrid(dispatchDto, "6", "g2", 0);
                for (int j = 1; j <= 100; j++) {
                    dispatchDto.getOrderIdList().add(j);
                }
                dispatchDto.init();

                List<BGDGridDto> bindGridList = bindGridAlgorithmService.bindGrid(dispatchDto);
                int temp = bindGridList.size();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    private void createGrid(BindGridDispatchDto dispatchDto, String gridNo, String groupNo, int orderId) {
        BGDGridDto grid = new BGDGridDto();
        grid.setGridNo(gridNo);
        grid.setGroupNo(groupNo);
        grid.setBindOrderId(orderId);
        dispatchDto.getGridList().add(grid);
    }
}
