package com.ruoyi.mall.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.MallAppGoods;
import com.ruoyi.mall.service.IMallAppGoodsService ;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * app商品Controller
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/mall/goods")
public class MallAppGoodsController extends BaseController
{
    @Autowired
    private IMallAppGoodsService mallAppGoodsService;

    /**
     * 查询app商品列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallAppGoods mallAppGoods)
    {
        startPage();
        List<MallAppGoods> list = mallAppGoodsService.selectMallAppGoodsList(mallAppGoods);
        return getDataTable(list);
    }

    /**
     * 导出app商品列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:export')")
    @Log(title = "app商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallAppGoods mallAppGoods) throws IOException {
        List<MallAppGoods> list = mallAppGoodsService.selectMallAppGoodsList(mallAppGoods);
        ExcelUtil<MallAppGoods> util = new ExcelUtil<MallAppGoods>(MallAppGoods.class);
        util.exportExcel(response, list, "app商品数据");
    }

    /**
     * 获取app商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallAppGoodsService.selectMallAppGoodsById(id));
    }

    /**
     * 新增app商品
     */
    @PreAuthorize("@ss.hasPermi('system:goods:add')")
    @Log(title = "app商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallAppGoods mallAppGoods)
    {
        return toAjax(mallAppGoodsService.insertMallAppGoods(mallAppGoods));
    }

    /**
     * 修改app商品
     */
    @PreAuthorize("@ss.hasPermi('system:goods:edit')")
    @Log(title = "app商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallAppGoods mallAppGoods)
    {
        return toAjax(mallAppGoodsService.updateMallAppGoods(mallAppGoods));
    }

    /**
     * 删除app商品
     */
    @PreAuthorize("@ss.hasPermi('system:goods:remove')")
    @Log(title = "app商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallAppGoodsService.deleteMallAppGoodsByIds(ids));
    }
}
