package com.ruoyi.mall.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MallGoodsProduct;
import com.ruoyi.mall.service.IMallGoodsProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品 产品Controller
 * 
 * @author chang
 * @date 2021-11-25
 */
@RestController
@RequestMapping("/mall/mallGoodsProduct")
public class MallGoodsProductController extends BaseController
{
    @Autowired
    private IMallGoodsProductService mallGoodsProductService;

    /**
     * 查询商品 产品列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallGoodsProduct mallGoodsProduct)
    {
        startPage();
        List<MallGoodsProduct> list = mallGoodsProductService.selectMallGoodsProductList(mallGoodsProduct);
        return getDataTable(list);
    }

    /**
     * 导出商品 产品列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsProduct:export')")
    @Log(title = "商品 产品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallGoodsProduct mallGoodsProduct)
    {
        List<MallGoodsProduct> list = mallGoodsProductService.selectMallGoodsProductList(mallGoodsProduct);
        ExcelUtil<MallGoodsProduct> util = new ExcelUtil<MallGoodsProduct>(MallGoodsProduct.class);
        return util.exportExcel(list, "商品 产品数据");
    }

    /**
     * 获取商品 产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsProduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallGoodsProductService.selectMallGoodsProductById(id));
    }

    /**
     * 新增商品 产品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsProduct:add')")
    @Log(title = "商品 产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallGoodsProduct mallGoodsProduct)
    {
        return toAjax(mallGoodsProductService.insertMallGoodsProduct(mallGoodsProduct));
    }

    /**
     * 修改商品 产品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsProduct:edit')")
    @Log(title = "商品 产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallGoodsProduct mallGoodsProduct)
    {
        return toAjax(mallGoodsProductService.updateMallGoodsProduct(mallGoodsProduct));
    }

    /**
     * 删除商品 产品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsProduct:remove')")
    @Log(title = "商品 产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallGoodsProductService.deleteMallGoodsProductByIds(ids));
    }
}
