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.core.page.TableSupport;
import com.shkj.common.enums.BusinessType;
import com.shkj.wms.bo.BaseAreaQueryListBo;
import com.shkj.wms.bo.BaseAreaSaveOrUpdateBo;
import com.shkj.wms.common.SwitchStatusEntity;
import com.shkj.wms.service.IBaseAreaService;
import com.shkj.wms.service.IBaseStorageService;
import com.shkj.wms.vo.BaseAreaListVo;
import com.shkj.wms.vo.BaseAreaNoOtherVo;
import com.shkj.wms.vo.BaseAreaVoExt;
import lombok.RequiredArgsConstructor;
import com.shkj.wms.config.ValidList;
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 javax.validation.Valid;

/**
 * 库房区域管理
 *
 * @menu 区域资料管理
 * @author lch
 * @date 2022-05-13
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/area")
public class BaseAreaController extends BaseController {

    private final IBaseAreaService iBaseAreaService;

    private final IBaseStorageService iBaseStorageService;

//    /**
//     * 查询区域资料列表
//     */
//    @PreAuthorize("@ss.hasPermi('wms:area:list')")
//    @GetMapping("/list")
//    public TableDataInfo<BaseAreaVo> list(BaseAreaQueryBo bo) {
//        startPage();
//        List<BaseAreaVo> list = iBaseAreaService.queryList(bo);
//        return getDataTable(list);
//    }
//
//    /**
//     * 导出区域资料列表
//     */
//    @PreAuthorize("@ss.hasPermi('wms:area:export')")
//    @GetMapping("/export")
//    public void export(HttpServletResponse response, BaseAreaQueryBo bo) {
//        List<BaseAreaVo> list = iBaseAreaService.queryList(bo);
//        ExcelUtil<BaseAreaVo> util = new ExcelUtil<BaseAreaVo>(BaseAreaVo.class);
//        util.exportExcel(response, list, "区域资料数据");
//    }
//
//    /**
//     * 获取区域资料详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('wms:area:query')")
//    @GetMapping("/{id}")
//    public Result<BaseAreaVo> getInfo(@PathVariable("id" ) Long id) {
//        return iBaseAreaService.queryById(id);
//    }
//
//    /**
//     * 新增区域资料
//     */
//    @PreAuthorize("@ss.hasPermi('wms:area:add')")
//    @Log(title = "区域资料", businessType = BusinessType.INSERT)
//    @PostMapping("/add")
//    public Result<Boolean> add(@Valid @RequestBody BaseAreaAddBo bo) {
//        return iBaseAreaService.insertByAddBo(bo);
//    }
//
//    /**
//     * 修改区域资料
//     */
//    @PreAuthorize("@ss.hasPermi('wms:area:edit')")
//    @Log(title = "区域资料", businessType = BusinessType.UPDATE)
//    @PostMapping("/edit")
//    public Result<Boolean> edit(@Valid @RequestBody BaseAreaEditBo bo) {
//        return iBaseAreaService.updateByEditBo(bo);
//    }
//
//    /**
//     * 删除区域资料
//     */
//    @PreAuthorize("@ss.hasPermi('wms:area:remove')")
//    @Log(title = "区域资料" , businessType = BusinessType.DELETE)
//    @DeleteMapping("/remove")
//    public Result<Boolean> remove(@Valid @RequestBody ValidList<Long> ids) {
//        return iBaseAreaService.deleteWithValidById(ids, true);
//    }

  /*  *//**
     * 根据人员获取区域Code
     *//*
    @GetMapping("/queryBaseAreaByUserNo")
    public Result<BaseAreaVoExt> queryBaseAreaByUserNo(String userName){
        return iBaseAreaService.queryBaseAreaByUserNo(userName);
    }*/

    /**
     * 获取当前仓的所有区域信息（带库别简单信息 )
     */
    @GetMapping("/queryBaseAreaAndStorageList")
    public List<BaseAreaListVo> queryBaseAreaAndStorageList(){
        return iBaseAreaService.queryBaseAreaAndStorageList();
    }




    /**
     * 分页获取库区集合
     * @param bo
     * @return
     */
    @GetMapping("/queryBaseAreaList")
    public TableDataInfo<BaseAreaNoOtherVo> queryBaseAreaList(BaseAreaQueryListBo bo) {
        startPage();
        List<BaseAreaNoOtherVo> list = iBaseAreaService.queryBaseAreaList(bo);
        return getDataTable(list);
    }

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

    /**
     * 删除指定的区域信息
     * @param ids
     * @return
     */
    @PostMapping("/removeBaseArea")
    public Result<Boolean> removeBaseArea(@Valid @RequestBody ValidList<Long> ids){
        return iBaseAreaService.deleteWithValidById(ids,true);
    }


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