package com.shkj.wms.outbound;

import com.shkj.system.service.ISysParameterService;
import com.shkj.wms.bo.BaseBarcodesOutAddBo;
import com.shkj.wms.domain.BaseBarcodesOut;
import com.shkj.wms.domain.BusinDataTask;
import com.shkj.wms.mapper.BaseBarcodesOutMapper;
import com.shkj.wms.mapper.BaseLocationMapper;
import com.shkj.wms.mapper.BaseLocationPlcMapper;
import com.shkj.wms.service.*;
import com.shkj.wms.service.impl.BaseLocationServiceImpl;
import com.shkj.wms.service.impl.SysStockDetailServiceImpl;
import com.shkj.wms.utils.TunnelTaskUtil;
import com.shkj.wms.vo.BaseBarcodesOutVo;
import com.shkj.wms.vo.BaseLocationVo;
import com.shkj.wms.vo.BusinDataTaskGoodsVo;
import com.shkj.wms.vo.SysStockDetailVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author zjx
 */
@Component
@Slf4j
public class SchedulingOutboundInfo {

    @Autowired
    BaseBarcodesOutMapper baseBarcodesOutMapper;

    @Autowired
    IBusinBillheadService iBusinBillheadService;

    @Resource
    IBusinDataTaskService iBusinDataTaskService;


    @Resource
    IBaseBarcodesOutService iBaseBarcodesOutService;
    @Resource
    SysStockDetailServiceImpl sysStockDetailServiceimpl;

    @Autowired
    BaseLocationServiceImpl baseLocationService;

    @Resource
    IBusinDataTaskService businDataTaskService;
    /**
     * 每10分钟执行一次出库任务
     *
     * @return
     */
    @Scheduled(fixedDelay = 1*600000)
    public void outboundInfoTask(){
        //查询待生成出库单任务的车辆队列
        List<BaseBarcodesOutAddBo> barcodesOutList = iBaseBarcodesOutService.selectVinOutboundList();
        businDataTaskService.insertBusinTask(barcodesOutList);
    }



   /* *//**
     * 出库任务
     *//*
    public void  outboundInfo(){
        //获取出库表中待出库的信息
        List<BaseBarcodesOutVo> baseBarcodesOutVoList = iBaseBarcodesOutService.getBarcodesnoOutData();
        //将所有的产品编码聚合
        List<String> goodsno = baseBarcodesOutVoList.stream().map(e -> e.getGoodsNo()).collect(Collectors.toList());
        //拿到所有的货位信息
        List<SysStockDetailVo> SysStockDetailVoList = sysStockDetailServiceimpl.getLocation(goodsno);
        //拿到分体可以在同一任务出库的产品编码和货位信息
        Map<String, List<String>> locationneaten = sysStockDetailServiceimpl.getLocationneaten(SysStockDetailVoList);
        //将所有的货位信息进行聚合
//        List<Long> locationList = SysStockDetailVoList.stream().map(e -> e.getLocationId()).collect(Collectors.toList());

        for (BaseBarcodesOutVo outVo: baseBarcodesOutVoList) {
            //通过货位拿到巷道信息
            List<BaseLocationVo> tunnelVo = baseLocationService.getTunnel(outVo.getGoodsNo());
            List<String> tunnelall = tunnelVo.stream().map(e -> e.getTunnel()).collect(Collectors.toList());
            //拿到任务数最少的巷道
            String tunnelone=this.quickSort(tunnelall);
            List<BaseLocationVo> tunnelLocation = tunnelVo.stream().filter(e -> e.getTunnel().equals(tunnelone)).collect(Collectors.toList());
            //根据巷道分配货位
            BaseLocationVo baseLocationVo = tunnelLocation.get(0);

            //修改出库表状态为进行中并添加任务
            BusinDataTask businDataTask = new BusinDataTask();
            //回填任务相关数据
            businDataTask.setBatch(outVo.getBatch());
            businDataTask.setToColumn(String.valueOf(baseLocationVo.getHeight()));
            businDataTask.setToLayer(baseLocationVo.getLocationColumn());
            businDataTask.setToRow(baseLocationVo.getLocationRow());
            //添加巷道任务数和总任务数
            TunnelTaskUtil.getInstance().addOutboundTaskNum(baseLocationVo.getTunnel());
            TunnelTaskUtil.getInstance().getOutboundTaskNum(baseLocationVo.getTunnel());
            iBusinDataTaskService.save(businDataTask);
        }





    }*/


}
