package com.shkj.wms.controller.business;

import com.shkj.common.annotation.Log;
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.common.utils.poi.ExcelUtil;
import com.shkj.wcs.third.stacker.StkCallUtil;
import com.shkj.wms.bo.PdaInvByContainerCodeBo;
import com.shkj.wms.bo.STKMoveBo;
import com.shkj.wms.domain.BusinPlcException;
import com.shkj.wms.service.IBusinOutInPlanService;
import com.shkj.wms.service.IBusinPlcExceptionService;
import com.shkj.wms.service.ISysStockDetailService;
import com.shkj.wms.service.ISysThirdExceptionRequestService;
import com.shkj.wms.vo.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * PLC异常内容Controller
 * 
 * @author zjx
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/wms/largeScreen")
public class BusinLargeScreenController extends BaseController
{
    @Autowired
    private IBusinPlcExceptionService businPlcExceptionService;


    @Autowired
    private ISysStockDetailService iSysStockDetailService;

    @Autowired
    private IBusinOutInPlanService iBusinOutInPlanService;

    @Autowired
    private ISysThirdExceptionRequestService sysThirdExceptionRequestService;

    @Autowired
    StkCallUtil stkCallUtil;


    /**
     * 大屏：输送线，堆垛机的异常信息
     */
    @GetMapping("/getExecMsgFromRedis")
    public Result<List<BusinPlcException>> getExecMsgFromRedis()
    {
       return Result.ok().data(businPlcExceptionService.getExecMsgFromRedis());
    }

    /**
     * 今日入库数量、出库数量、在库库存数量接口
     */

    @GetMapping("/getPutInOutStockQty")
    public  Result<List<SysStockAndInOutVo>> getPutInOutStockQty()
    {
        return iSysStockDetailService.getPutInOutStockQty();
    }

    /**
     * 库存管理：各区的库存数量及所占比例
     */
    @GetMapping("/getInventoryManagement")
    public Result<List<SysStockByAreaVo>> getInventoryManagement()
    {
        return iSysStockDetailService.getInventoryManagement();
    }

    /**
     * 库存管理：各区域的库存重量总和、及所占库存重量的占比
     */
    @GetMapping("/getInvWeightManagement")
    public Result<List<SysStockWeightByAreaVo>> getInvWeightManagement()
    {
        Result<List<SysStockWeightByAreaVo>> invWeightManagement = iSysStockDetailService.getInvWeightManagement();
        return invWeightManagement;
    }



    /**
     * 库位使用率：拖上上未存放任一模具则算未使用
     */
    @GetMapping("/getLocationUsageRate")
    public Result<List<SysStockByReteVo>> getLocationUsageRate()
    {
        return iSysStockDetailService.getLocationUsageRate();

    }

    /**
     * 设备状态：获取堆垛机、输送线、提升机的设备状态
     */

    @GetMapping("/getDeviceStatus")
    public Result<Boolean> getDeviceStatus()
    {

        return Result.ok().data(businPlcExceptionService.getPlcStatusFromRedis());
    }

    /**
     * 任务管理、待出库任务、待入库任务、已超时任务
     */

	@GetMapping("/getTaskManagement")
    public Result<List<BusinTaskManageVo>> getTaskManagement()
    {
        return  Result.ok().data(iBusinOutInPlanService.getTaskManagement());
    }


    /**
     * 立库可视化，根据库位获取库位上的模具信息
     * @param locationCode 库位编号
     * @return
     */
    @GetMapping("/getLocationMoldByLocationCode")
    public Result<List<BaseMoldVo>> getLocationMoldByLocationCode(String  locationCode) {
       return Result.ok().data(iSysStockDetailService.getLocationMoldByLocationCode(locationCode));
    }


    /**
     * 大屏：输送线，堆垛机的异常信息
     */
    @GetMapping("/getPutInExeMsgFromRedis")
    public Result<List<BusinPlcException>> getPutInExeMsgFromRedis()
    {
        return Result.ok().data(businPlcExceptionService.getExecMsgFromRedis());
    }

    /**
     * 大屏：输送线，堆垛机的异常信息
     */
    @PostMapping("/doTask")
    public void doTask() throws InterruptedException {
        sysThirdExceptionRequestService.doTask();

    }



}
