package com.shkj.wms.controller.busin;

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.enums.BusinessType;
import com.shkj.wms.plc.PlcEventTask;
import com.shkj.wms.plc.PlcEventTmpTask;
import com.shkj.wms.scheduled.ScheduledTasks;
import com.shkj.wms.service.IBusinEnptyContainerService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor(onConstructor_ =@Autowired)
@RestController
@RequestMapping("/wcs/task")
public class TaskController extends BaseController {

    @Autowired
    ScheduledTasks scheduledTasks;

    @Autowired
    PlcEventTmpTask plcEventTmpTask;

    @Autowired
    PlcEventTask plcEventTask;

    @Autowired
    IBusinEnptyContainerService iBusinEnptyContainerService;

    /**
     * 执行task
     */
    @Log(title = "手动调度任务流程",businessType = BusinessType.UPDATE)
    @PostMapping("/exeTask")
    @RepeatSubmit
    public Result<Bool> exeTask(){
        scheduledTasks.task();
        return  Result.ok();
    }

    /**
     * 执行PLC相关任务--测试
     */
    @Log(title = "执行PLC相关任务",businessType = BusinessType.UPDATE)
    @PostMapping("/exePlcTmpTask")
    @RepeatSubmit
    public Result<Bool> exePlcTmpTask(){
        plcEventTmpTask.init();
        return  Result.ok();
    }

    /**
     * 执行PLC相关任务--正式
     */
    @Log(title = "执行PLC相关任务",businessType = BusinessType.UPDATE)
    @PostMapping("/exePlcTask")
    @RepeatSubmit
    public Result<Bool> exePlcTask(){
        plcEventTask.init();
        return  Result.ok();
    }

    /**
     * 空治具出库流程
     */
    @Log(title = "空治具出库流程",businessType = BusinessType.UPDATE)
    @PostMapping("/exeEmptyContainerFromWare")
    @RepeatSubmit
    public Result<Bool> exeEmptyContainerFromWare(){
        iBusinEnptyContainerService.emptyContainerFromWare();
        return  Result.ok();
    }

    /**
     * 空治具出库流程
     */
    @Log(title = "空治具出库流程",businessType = BusinessType.UPDATE)
    @PostMapping("/intask")
    @RepeatSubmit
    public Result<Bool> intask(Long taskId,Long containerId){
        scheduledTasks.inTask(taskId,containerId);
        return  Result.ok();
    }



}
