package com.shkj.wms.controller.base;

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.*;
import com.shkj.wms.common.SwitchStatusEntity;
import com.shkj.wms.service.IBaseContainerService;
import com.shkj.wms.config.ValidList;
import com.shkj.wms.vo.BaseContainerInWWarehoseVo;
import com.shkj.wms.vo.BaseContainerVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 托盘管理
 *
 * @author lch
 * @menu 托盘资料管理
 * @date 2022-04-23
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/container")
public class BaseContainerController extends BaseController {

    private final IBaseContainerService iBaseContainerService;

    /**
     * 根据编号校验托盘是否存在以及可用 (已废弃)
     *
     * @param containerCode
     * @return
     */
    @GetMapping("/checkBaseContainer")
    public Result<BaseContainerVo> checkBaseContainer(@NotNull String containerCode) {
        return iBaseContainerService.checkBaseContainer(containerCode);
    }



    /**
     * 查看托盘资料列表
     * @param bo
     * @return
     */
    @GetMapping("/queryBaseContainerList")
    public TableDataInfo<BaseContainerVo> queryBaseContainerList(BaseContainerQueryListBo bo) {
        startPage();
        List<BaseContainerVo> list = iBaseContainerService.queryBaseContainerList(bo);
        return getDataTable(list);
    }

    /**
     * 保存或者修改托盘资料（根据是否有id来判断新增或者修改）
     * @param list
     * @return
     */
    @PostMapping("/saveOrUpdateBaseContainers")
    @RepeatSubmit
    public Result<Boolean> saveOrUpdateBaseContainers(@Valid @RequestBody ValidList<BaseContainerSaveOrUpdateBo> list){
        return iBaseContainerService.saveOrUpdateBaseContainers(list);
    }

    /**
     * 切换状态
     */
    @Log(title = "切换状态" , businessType = BusinessType.UPDATE)
    @PostMapping("/switchStatus")
    public Result<Boolean> switchStatus(@Valid @RequestBody BaseContainerSwitchBo switchStatusEntity) {
        return iBaseContainerService.switchStatus(switchStatusEntity.getId(), switchStatusEntity.getStatus());
    }

    /**
     * 删除托盘资料
     * @param ids
     * @return
     */
    @PostMapping("/removeBaseContainers")
    public Result<Boolean> removeBaseContainers(@Valid @RequestBody ValidList<Long> ids) {
        return iBaseContainerService.removeBaseContainers(ids);
    }

    /**
     * 批量保存托盘数据 一次性增加很多托盘
     */
    @PostMapping("/saveManyBaseContainers")
    @RepeatSubmit
    public Result<Boolean> saveManyBaseContainers(@Valid @RequestBody BaseContainerManySaveBo bo){
        return iBaseContainerService.saveManyBaseContainers(bo);
    }


    /**
     * 根据扫描的托盘，返回托盘相关信息
     */
    @GetMapping("/checkContainer")
    @RepeatSubmit
    public Result<BaseContainerVo> checkContainerCode(@RequestParam("containerCode") String containerCode){
        return iBaseContainerService.checkBaseContainer(containerCode);
    }


    /**
     * 根据扫描的托盘，验证是否存在及是否库位上已有托盘
     */
    @GetMapping("/checkContainerCodeNoInv")
    @RepeatSubmit
    public Result<BaseContainerVo> checkContainerCodeNoInv(@RequestParam("containerCode") String containerCode){
        return iBaseContainerService.checkContainerCodeNoInv(containerCode);
    }


    /**
     * 查询托盘上无库存的托盘列表
     */
    @GetMapping("/getContainerNoInv")
    @RepeatSubmit
    public Result<List<BaseContainerVo>> getContainerNoInv(){
        return Result.ok().data(iBaseContainerService.getContainerNoInv());
    }


//    /**
//     * 空治具在库查询
//     * @param bo
//     * @return
//     */
//    @GetMapping("/queryContainerInWWarehoseList")
//    public TableDataInfo<BaseContainerVo> queryContainerInWWarehoseList(BaseContainerQueryListBo bo) {
//        startPage();
//        List<BaseContainerInWWarehoseVo> list = iBaseContainerService.queryContainerInWWarehoseList(bo);
//        return getDataTable(list);
//    }
}
