package com.shkj.wms.third.rcs;

import com.shkj.common.core.domain.Result;
import com.shkj.wms.third.rcs.dto.RcsCreateTaskDto;
import com.shkj.wms.third.rcs.enums.RCSTaskTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

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

@Component("testTask")
public class Test {

    @Autowired
    private RCSUtil rcsUtil;

    //@Scheduled(cron = " 10 * * * * ? ")
    public void startTestTask(){
        System.out.println("任务下发开始+++++++++++++++++++++++++++++++");

        //下挂->入库口
        RcsCreateTaskDto rcsCreateTaskDto = new RcsCreateTaskDto();
        rcsCreateTaskDto.setTaskId(String.valueOf((int)(Math.random()*10000)));
        rcsCreateTaskDto.setTaskType(RCSTaskTypeEnum.A_TO_B_HAND_PUT.getValue());
        List targetList = new ArrayList();

        targetList.add("KW17");
        targetList.add("LY106");
        Random random = new Random();
        int randomNumber = random.nextInt(3) + 1;
        if (randomNumber== 1){
            targetList.add("KW5");
        }
        if (randomNumber== 2){
            targetList.add("KW7");
        }
        if (randomNumber== 3){
            targetList.add("KW9");
        }

        rcsCreateTaskDto.setTargets(targetList);
        Result result = rcsUtil.rcsCreateTask(rcsCreateTaskDto);
        if (result.getCode() == 200){
            System.out.println("++++++++++++++++++++++++++++++++++++++下挂->入库口任务成功++++++++++++");
        }else {
            System.out.println("++++++++++++++++++++++++++++"+result.getMsg()+"+++++++++++++++++++++++++++++++");
        }

        //立库出小组装
        RcsCreateTaskDto rcsCreateTaskDto1 = new RcsCreateTaskDto();
        rcsCreateTaskDto1.setTaskId(String.valueOf((int)(Math.random()*10000)));
        rcsCreateTaskDto1.setTaskType(31);
        List targetList1 = new ArrayList();
        if (randomNumber== 1){
            targetList.add("KW6");
        }
        if (randomNumber== 2){
            targetList.add("KW8");
        }
        if (randomNumber== 3){
            targetList.add("KW10");
        }
        targetList1.add("LY106");
        targetList1.add("KW5");
        targetList1.add("KW19");
        rcsCreateTaskDto1.setTargets(targetList1);
        Result result1 = rcsUtil.rcsCreateTask(rcsCreateTaskDto1);
        if (result1.getCode() == 200){
            System.out.println("++++++++++++++++++++++++++++++++++++++立库出小组装任务成功++++++++++++");
        }else {
            System.out.println("++++++++++++++++++++++++++++"+result1.getMsg()+"+++++++++++++++++++++++++++++++");
        }

        //小组装回机械手
        RcsCreateTaskDto rcsCreateTaskDto2 = new RcsCreateTaskDto();
        rcsCreateTaskDto2.setTaskId(String.valueOf((int)(Math.random()*10000)));
        rcsCreateTaskDto2.setTaskType(RCSTaskTypeEnum.TO_B_AND_PUT1.getValue());
        List targetList2 = new ArrayList();
        targetList2.add("KW19");
        targetList2.add("LY106");
        targetList2.add("KW17");
        rcsCreateTaskDto2.setTargets(targetList2);
        Result result2 = rcsUtil.rcsCreateTask(rcsCreateTaskDto2);
        if (result.getCode() == 200){
            System.out.println("++++++++++++++++++++++++++++++++++++++小组装回机械手任务成功++++++++++++");
        }else {
            System.out.println("++++++++++++++++++++++++++++"+result2.getMsg()+"+++++++++++++++++++++++++++++++");
        }

        //机械手入平库
        RcsCreateTaskDto rcsCreateTaskDto3 = new RcsCreateTaskDto();
        rcsCreateTaskDto3.setTaskId(String.valueOf((int)(Math.random()*10000)));
        rcsCreateTaskDto3.setTaskType(RCSTaskTypeEnum.A_TO_B_NO_PUT.getValue());
        List targetList3 = new ArrayList();
        targetList3.add("KW17");
        targetList3.add("LY106");
        targetList3.add("KW18");
        rcsCreateTaskDto3.setTargets(targetList3);
        Result result3 = rcsUtil.rcsCreateTask(rcsCreateTaskDto3);
        if (result.getCode() == 200){
            System.out.println("++++++++++++++++++++++++++++++++++++++机械手入平库任务成功++++++++++++");
        }else {
            System.out.println("++++++++++++++++++++++++++++"+result3.getMsg()+"+++++++++++++++++++++++++++++++");
        }

        //平库回机械手
        RcsCreateTaskDto rcsCreateTaskDto4 = new RcsCreateTaskDto();
        rcsCreateTaskDto4.setTaskId(String.valueOf((int)(Math.random()*10000)));
        rcsCreateTaskDto4.setTaskType(RCSTaskTypeEnum.TO_B_AND_PUT1.getValue());
        List targetList4 = new ArrayList();
        targetList4.add("KW18");
        targetList4.add("LY106");
        targetList4.add("KW17");
        rcsCreateTaskDto4.setTargets(targetList4);
        Result result4 = rcsUtil.rcsCreateTask(rcsCreateTaskDto4);
        if (result.getCode() == 200){
            System.out.println("++++++++++++++++++++++++++++++++++++++平库回机械手任务成功++++++++++++");
        }else {
            System.out.println("++++++++++++++++++++++++++++"+result4.getMsg()+"+++++++++++++++++++++++++++++++");
        }
    }

}
