package com.shkj.wms.controller.business;

import com.shkj.common.annotation.Log;
import com.shkj.common.annotation.RepeatSubmit;
import com.shkj.common.core.controller.BaseController;
import com.shkj.common.core.domain.Result;
import com.shkj.common.core.page.TableDataInfo;
import com.shkj.common.enums.BusinessType;
import com.shkj.wms.bo.BaseBarcodesOutAddBo;
import com.shkj.wms.bo.BaseBarcodesOutQueryBo;
import com.shkj.wms.bo.BaseBarcodesOutThirdPointBo;
import com.shkj.wms.bo.BaseGoodsDervieBo;
import com.shkj.wms.outbound.SchedulingOutboundInfo;
import com.shkj.wms.service.IBusinBillheadService;
import com.shkj.wms.service.IBusinDataTaskService;
import com.shkj.wms.third.ykl.ThirdYklResult;
import com.shkj.wms.vo.BusinBillHeadPlanOutVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor(onConstructor_ =@Autowired)
@RestController
@RequestMapping("/wms/billout")
public class BusinBillOutController extends BaseController {

    @Autowired
    IBusinBillheadService iBusinBillheadService;

    @Autowired
    SchedulingOutboundInfo schedulingOutboundInfo;

    @Autowired
    IBusinDataTaskService businDataTaskService;

    /**
     * 定时生成出库任务测试
     */
    @PostMapping("/saveBillHeadBodyOut2")
    @RepeatSubmit
    public void saveBillHeadBodyOut2(){
        schedulingOutboundInfo.outboundInfoTask();
    }


    @Log(title = "紧急出库确认出库-方式1",businessType = BusinessType.UPDATE)
    @PostMapping("/saveBillHeadBodyOut")
    @RepeatSubmit
    public Result<Boolean> saveBillHeadBodyOut(@Valid @RequestBody List<BaseBarcodesOutAddBo> bos){
        return   businDataTaskService.insertBusinTask(bos);

    }

    @Log(title = "紧急出库确认出库-方式2",businessType = BusinessType.UPDATE)
    @PostMapping("/saveBillHeadBodyOutByDervie")
    @RepeatSubmit
    public Result<Boolean> saveBillHeadBodyOutByDervie(@Valid @RequestBody List<BaseGoodsDervieBo> bos){
        return   businDataTaskService.insertBusinTaskByDervie(bos);
    }


    @Log(title = "出库计划管理",businessType = BusinessType.UPDATE)
    @PostMapping("/getBillHeadBodyPlanOut")
    @RepeatSubmit
    public TableDataInfo<BusinBillHeadPlanOutVo> getBillHeadBodyPlanOut(BaseBarcodesOutQueryBo bo){
        startPage();
        List<BusinBillHeadPlanOutVo> list = iBusinBillheadService.getBillHeadBodyPlanOut(bo);
        return getDataTable(list);

    }

    @Log(title = "手动调度出库信息",businessType = BusinessType.UPDATE)
    @PostMapping("/exeOutboundInfo")
    @RepeatSubmit
    public Result<Boolean> exeOutboundInfo(){
        //schedulingOutboundInfo.outboundInfo();
        return  Result.ok();
    }


    /**
     * 指定货位出库
     * @param locationCode
     * @return
     */
    @Log(title = "指定货位出库",businessType = BusinessType.UPDATE)
    @PostMapping("/namedLoctionOutput")
    @RepeatSubmit
    public Result<Boolean> namedLoctionOutput(@Valid @RequestParam String locationCode){
        return   businDataTaskService.insertBusinTask(locationCode);
    }
    
}
