package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.TMiStock;
import com.ruoyi.business.service.ITMiStockService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.DictService;
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.*;

import java.util.List;

/**
 * 库存Controller
 *
 * @author wms
 * @date 2022-07-26
 */
@Controller
@RequestMapping("/business/goodsReport")
public class GoodReportController extends BaseController {
    private String prefix = "business/goodsReport";

    @Autowired
    private ITMiStockService tMiStockService;

    @Autowired
    private DictService dict;

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

    /**
     * 查询库存列表
     */
    @RequiresPermissions("business:goodsReport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TMiStock tMiStock)
    {
        startPage();
//        tMiStock.setSts(dict.getType("stock_sts").get(0).getDictValue());
        List<TMiStock> list = tMiStockService.selectTMiStockOutList(tMiStock);
        return getDataTable(list);
    }

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

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

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

    /**
     * 状态说明弹框
     */
    @GetMapping("/stsDescribe")
    public String stsDescribe()
    {
        return prefix + "/stsdescribe";
    }

    /**
     * 根据状态筛选库存数据
     */
    @PostMapping("/filter/{sts}")
    @ResponseBody
    public TableDataInfo filter(@PathVariable("sts") String sts)
    {
        startPage();
        TMiStock tMiStock = new TMiStock();
        tMiStock.setSts(sts);
        List<TMiStock> list = tMiStockService.selectStock(tMiStock);
        return getDataTable(list);
    }
}
