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.TBaseGoods;
import com.ruoyi.business.service.ITBaseGoodsService;
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-07
 */
@Controller
@RequestMapping("/business/goods")
public class TBaseGoodsController extends BaseController
{
    private String prefix = "business/goods";

    @Autowired
    private ITBaseGoodsService tBaseGoodsService;

    @RequiresPermissions("business:goods:view")
    @GetMapping()
    public String goods()
    {
        return prefix + "/goods";
    }

    /**
     * 查询商品资料列表
     */
    @RequiresPermissions("business:goods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TBaseGoods tBaseGoods)
    {
        startPage();
        List<TBaseGoods> list = tBaseGoodsService.selectTBaseGoodsList(tBaseGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品资料列表
     */
    @RequiresPermissions("business:goods:export")
    @Log(title = "商品资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBaseGoods tBaseGoods)
    {
        List<TBaseGoods> list = tBaseGoodsService.selectTBaseGoodsList(tBaseGoods);
        ExcelUtil<TBaseGoods> util = new ExcelUtil<TBaseGoods>(TBaseGoods.class);
        return util.exportExcel(list, "商品资料数据");
    }

    /**
     * 新增商品资料
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品资料
     */
    @RequiresPermissions("business:goods:add")
    @Log(title = "商品资料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBaseGoods tBaseGoods)
    {
        return toAjax(tBaseGoodsService.insertTBaseGoods(tBaseGoods));
    }

    /**
     * 修改商品资料
     */
    @RequiresPermissions("business:goods:edit")
    @GetMapping("/edit/{goodsId}")
    public String edit(@PathVariable("goodsId") String goodsId, ModelMap mmap)
    {
        TBaseGoods tBaseGoods = tBaseGoodsService.selectTBaseGoodsByGoodsId(goodsId);
        mmap.put("tBaseGoods", tBaseGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品资料
     */
    @RequiresPermissions("business:goods:edit")
    @Log(title = "商品资料", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBaseGoods tBaseGoods)
    {
        return toAjax(tBaseGoodsService.updateTBaseGoods(tBaseGoods));
    }

    /**
     * 删除商品资料
     */
    @RequiresPermissions("business:goods:remove")
    @Log(title = "商品资料", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tBaseGoodsService.deleteTBaseGoodsByGoodsIds(ids));
    }

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