package com.youchain.modules.quartz.task;

import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.service.PointService;
import com.youchain.businessdata.domain.AgvTask;
import com.youchain.businessdata.service.AgvTaskService;
import com.youchain.modules.quartz.utils.TimeNumberUtils;
import com.youchain.utils.BaseStatus;
import com.youchain.utils.BizStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 料箱回空箱
 */
@Slf4j
@Service
public class hkxTask {
    @Autowired
    public AgvTaskService agvTaskService;

    @Autowired
    public PointService pointService;


    public void hkxTask() {

            //有没有回入库空箱的任务
            if (agvTaskService.findByendSlotCode("S-001-002-001-001",BizStatus.EMPTY_IN,"PICKER_MOVE")) {
                int queryCount = agvTaskService.QueryCount("6x2");
                if (queryCount >= 4 && queryCount <=6){
                    //起点
                    Point startPoint = pointService.getPoint("", BaseStatus.FREE, BaseStatus.BOX, "出库缓存输送线空箱接驳口");

                    //终点
                    Point endPoint = pointService.getPoint("", BaseStatus.FREE, BaseStatus.BOX, "入库输送线空箱接驳口");

                    //生成反空箱料箱任务任务
                    List<AgvTask> agvTaskList = new ArrayList<>();
                    for (int i = 0; i < queryCount; i++) {
                        AgvTask newAgvTask = new AgvTask(BizStatus.EMPTY_IN, TimeNumberUtils.getKLXTaskCode(), startPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, "PICKER_MOVE");
                        agvTaskService.create(newAgvTask);
                        agvTaskList.add(newAgvTask);
                    }
                    String rul=agvTaskService.sendAgvTaskLXImpl(agvTaskList);
                    log.info(rul);
                }else{
                    log.info("出库缓存输送线下层空箱不满足条件，不下发任务！");
                }


            }else{
                log.info("有执行中回空箱的料箱入库任务！");
            }


    }
}
