package com.prolog.eis;

import com.prolog.eis.dto.bindgridex.BGDExDispatchDto;
import com.prolog.eis.dto.bindgridex.BGDExGridDto;
import com.prolog.eis.dto.bindgridex.BGDExOrderDto;
import com.prolog.eis.service.bindgridex.BindGridExAlgorithmService;
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 BindGridExTest {
    @Resource
    private BindGridExAlgorithmService bindGridExAlgorithmService;

    @Test
    public void test() {
        for (int i = 0; i < 20; i++) {
            try {
                BGDExDispatchDto dispatchDto = new BGDExDispatchDto();
                this.createGrid(dispatchDto, "1", "g1", null);
                this.createGrid(dispatchDto, "2", "g1", null);
                this.createGrid(dispatchDto, "3", "g1", null);
                this.createGrid(dispatchDto, "4", "g2", 555);
                this.createGrid(dispatchDto, "5", "g2", null);
                this.createGrid(dispatchDto, "6", "g2", null);
                for (int j = 1; j <= 100; j++) {
                    BGDExOrderDto order = new BGDExOrderDto();
                    order.setOrderId(j);
                    order.setWaveNo("Wave1");
                    order.setDetailCount(j);

                    dispatchDto.getOrderList().add(order);
                }
                dispatchDto.init();

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

    private void createGrid(BGDExDispatchDto dispatchDto, String gridNo, String groupNo, Integer orderId) {
        BGDExGridDto grid = new BGDExGridDto();
        grid.setGridNo(gridNo);
        grid.setGroupNo(groupNo);
        grid.setBindOrderId(orderId);
        dispatchDto.getGridList().add(grid);
    }
}
