package com.shkj.wms.controller.base;

import java.util.List;

import com.shkj.common.annotation.Log;
import com.shkj.common.annotation.RepeatSubmit;
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.IBaseLocationService;
import com.shkj.wms.config.ValidList;
import com.shkj.wms.vo.BaseLocationDetailVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.shkj.common.core.controller.BaseController;
import com.shkj.common.core.domain.Result;
import com.shkj.wms.vo.BaseLocationVo;

import javax.validation.Valid;

/**
 * 货位资料Controller
 *
 * @menu 货位资料管理
 * @author lch
 * @date 2022-04-23
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/location")
public class BaseLocationController extends BaseController {

    private final IBaseLocationService iBaseLocationService;

    /**
     * 查询货位资料列表
     */
    @GetMapping("/pageBaseLocation")
    public TableDataInfo<BaseLocationVo> pageBaseLocation(BaseLocationQueryPageBo bo) {
        startPage();
        List<BaseLocationVo> list = iBaseLocationService.queryBaseLocationList(bo);
        return getDataTable(list);
    }

    /**
     * 根据区域获取对应的货位所具有的巷道信息
     */
    @GetMapping("/queryBaseLocationTunnelList")
    public Result<List<String>> queryBaseLocationTunnelList(BaseLocationQueryListBo bo) {
        List<String> list = iBaseLocationService.queryBaseLocationTunnelList(bo);
        return Result.ok().data(list);
    }

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

    /**
     * 按规则保存多个货位资料集合
     * @param bo
     * @return
     */
    @PostMapping("/saveBaseLocationMany")
    @RepeatSubmit
    public Result<Boolean> saveBaseLocationMany(@Valid @RequestBody BaseLocationManyBo bo){
        return iBaseLocationService.saveBaseLocationMany(bo);
    }


    /**
     * 删除货位资料
     */
    @PostMapping("/removeBaseLocation")
    public Result<Boolean> remove(@Valid @RequestBody ValidList<Long> ids) {
        return iBaseLocationService.deleteWithValidById(ids, true);
    }


    /**
     * 禁用启用货位
     */
    @PostMapping("/enableDisableLocation")
    public Result<Boolean> enableDisableLocation(@Valid @RequestBody BaseLocationRemoveBo bo) {
        return iBaseLocationService.deleteWithValidById(bo.getIds(), bo.getStatus());
    }





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

    /**
     * 查询货位--map
     */
    @GetMapping("/getBaseLocationForMap")
    public TableDataInfo<BaseLocationVo> getBaseLocationForMap(BaseLocationQueryPageBo bo) {
        startPage();
        List<BaseLocationVo> list = iBaseLocationService.getBaseLocationForMap(bo);
        return getDataTable(list);
    }

    /**
     * 获取可用的目的货位
     *
     * @param bo
     * @return
     */
    @PostMapping("/queryTargetLocation")
    public Result<List<BaseLocationDetailVo>> queryTargetLocation(@Valid @RequestBody BaseLocationUrgentBo bo) {
        return iBaseLocationService.queryTargetLocation(bo);
    }

}
