package com.shkj.wms.controller.business;

import java.util.List;

import com.shkj.wms.bo.SysStockNumQueryBo;
import com.shkj.wms.config.ValidList;
import com.shkj.wms.vo.SysStockNumDetailVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.shkj.common.annotation.Log;
import com.shkj.common.enums.BusinessType;
import com.shkj.common.core.controller.BaseController;
import com.shkj.common.core.domain.Result;
import com.shkj.wms.vo.SysStockVo;
import com.shkj.wms.bo.SysStockQueryBo;
import com.shkj.wms.bo.SysStockAddBo;
import com.shkj.wms.bo.SysStockEditBo;
import com.shkj.wms.service.ISysStockService;
import com.shkj.common.core.page.TableDataInfo;
import com.shkj.common.utils.poi.ExcelUtil;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * 库存管理Controller
 *
 * @menu 库存管理管理
 * @author lch
 * @date 2023-05-07
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/stock")
public class SysStockController extends BaseController {

    private final ISysStockService iSysStockService;

    /**
     * 查询库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:list')")
    @GetMapping("/list")
    public TableDataInfo<SysStockVo> list(SysStockQueryBo bo) {
        startPage();
        List<SysStockVo> list = iSysStockService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:export')")
    @GetMapping("/export")
    public void export(HttpServletResponse response, SysStockQueryBo bo) {
        List<SysStockVo> list = iSysStockService.queryList(bo);
        ExcelUtil<SysStockVo> util = new ExcelUtil<SysStockVo>(SysStockVo.class);
        util.exportExcel(response, list, "库存管理数据");
    }

    /**
     * 获取库存管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:query')")
    @GetMapping("/{id}")
    public Result<SysStockVo> getInfo(@PathVariable("id" ) Long id) {
        return iSysStockService.queryById(id);
    }

    /**
     * 新增库存管理
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:add')")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result<Boolean> add(@Valid @RequestBody SysStockAddBo bo) {
        return iSysStockService.insertByAddBo(bo);
    }

    /**
     * 修改库存管理
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:edit')")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result<Boolean> edit(@Valid @RequestBody SysStockEditBo bo) {
        return iSysStockService.updateByEditBo(bo);
    }

    /**
     * 删除库存管理
     */
    @PreAuthorize("@ss.hasPermi('wms:stock:remove')")
    @Log(title = "库存管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public Result<Boolean> remove(@Valid @RequestBody ValidList<Long> ids) {
        return iSysStockService.deleteWithValidById(ids, true);
    }

    /**
     * 库存明细
     * @param bo
     * @return
     */
    @GetMapping("/queryStockDetailList")
    public TableDataInfo<List<SysStockNumDetailVo>> queryStockDetailList(SysStockNumQueryBo bo) {
        startPage();
        List<SysStockNumDetailVo> list = iSysStockService.queryStockDetailList(bo);
        return getDataTable(list);
    }

}
