package com.ruoyi.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TMiStock;
import com.ruoyi.business.service.ITMiStockService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存Controller
 * 
 * @author wms
 * @date 2022-05-29
 */
@Controller
@RequestMapping("/business/stock")
public class TMiStockController extends BaseController
{
    private String prefix = "business/stock";

    @Autowired
    private ITMiStockService tMiStockService;

    @RequiresPermissions("business:stock:view")
    @GetMapping()
    public String stock(ModelMap mmap)
    {
        mmap.put("tMiStock", new TMiStock());
        return prefix + "/stock";
    }

    /**
     * 查询库存列表
     */
    @RequiresPermissions("business:stock:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TMiStock tMiStock)
    {
        startPage();
        List<TMiStock> list = tMiStockService.selectTMiStockList(tMiStock);
        return getDataTable(list);
    }

    /**
     * 导出库存列表
     */
    @RequiresPermissions("business:stock:export")
    @Log(title = "库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TMiStock tMiStock)
    {
        List<TMiStock> list = tMiStockService.selectTMiStockList(tMiStock);
        ExcelUtil<TMiStock> util = new ExcelUtil<TMiStock>(TMiStock.class);
        return util.exportExcel(list, "库存数据");
    }

    /**
     * 新增库存
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存
     */
    @RequiresPermissions("business:stock:add")
    @Log(title = "库存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TMiStock tMiStock)
    {
        return toAjax(tMiStockService.insertTMiStock(tMiStock));
    }

    /**
     * 修改库存
     */
    @RequiresPermissions("business:stock:edit")
    @GetMapping("/edit/{stockId}")
    public String edit(@PathVariable("stockId") String stockId, ModelMap mmap)
    {
        TMiStock tMiStock = tMiStockService.selectTMiStockByStockId(stockId);
        mmap.put("tMiStock", tMiStock);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存
     */
    @RequiresPermissions("business:stock:edit")
    @Log(title = "库存", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TMiStock tMiStock)
    {
        return toAjax(tMiStockService.updateTMiStock(tMiStock));
    }

    /**
     * 删除库存
     */
    @RequiresPermissions("business:stock:remove")
    @Log(title = "库存", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tMiStockService.deleteTMiStockByStockIds(ids));
    }

    /**
     * 弹框表格
     */
    @GetMapping("/modalPage")
    public String table()
    {
        return prefix + "/stockModal";
    }

    /**
     * 查询出库用库存列表
     */
    @RequiresPermissions("business:stock:outlist")
    @PostMapping("/outlist")
    @ResponseBody
    public TableDataInfo outList(TMiStock tMiStock)
    {
        startPage();
        List<TMiStock> list = tMiStockService.selectTMiStockOutList(tMiStock);
        return getDataTable(list);
    }
}
