package com.shkj.wms.controller.base;

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.wms.bo.BaseContainerManySaveBo;
import com.shkj.wms.bo.BaseContainerQueryListBo;
import com.shkj.wms.bo.BaseContainerSaveOrUpdateBo;
import com.shkj.wms.bo.CheckContainerBo;
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;

/**
 * 容器资料Controller
 *
 * @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
     */
   /* @PostMapping("/checkContainer")
    public Result<BaseContainerVo> checkContainer(@Valid @RequestBody CheckContainerBo bo) {
        return iBaseContainerService.checkContainer(bo);
    }*/

    /**
     * 查看具有权限的容器资料列表
     * @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);
    }

    /**
     * 删除容器资料
     * @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);
    }


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