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.MallAppOrderGoods;
import com.ruoyi.mall.service.IMallAppOrderGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * app-线下订单商品Controller
 *
 * @author ruoyi
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/mall/mallAppOrderGoods")
public class MallAppOrderGoodsController extends BaseController
{
    @Resource
    private IMallAppOrderGoodsService mallAppOrderGoodsService;

    /**
     * 查询app-线下订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallAppOrderGoods mallAppOrderGoods)
    {
        startPage();
        mallAppOrderGoods.setDelFlag("0");
        List<MallAppOrderGoods> list = mallAppOrderGoodsService.selectMallAppOrderGoodsList(mallAppOrderGoods);
        return getDataTable(list);
    }

    /**
     * 导出app-线下订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderGoods:export')")
    @Log(title = "app-线下订单商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallAppOrderGoods mallAppOrderGoods)
    {
        List<MallAppOrderGoods> list = mallAppOrderGoodsService.selectMallAppOrderGoodsList(mallAppOrderGoods);
        ExcelUtil<MallAppOrderGoods> util = new ExcelUtil<MallAppOrderGoods>(MallAppOrderGoods.class);
        return util.exportExcel(list, "app-线下订单商品数据");
    }

    /**
     * 获取app-线下订单商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallAppOrderGoodsService.selectMallAppOrderGoodsById(id));
    }

    /**
     * 新增app-线下订单商品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderGoods:add')")
    @Log(title = "app-线下订单商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallAppOrderGoods mallAppOrderGoods)
    {
        return toAjax(mallAppOrderGoodsService.insertMallAppOrderGoods(mallAppOrderGoods));
    }

    /**
     * 修改app-线下订单商品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderGoods:edit')")
    @Log(title = "app-线下订单商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallAppOrderGoods mallAppOrderGoods)
    {
        return toAjax(mallAppOrderGoodsService.updateMallAppOrderGoods(mallAppOrderGoods));
    }

    /**
     * 删除app-线下订单商品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderGoods:remove')")
    @Log(title = "app-线下订单商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallAppOrderGoodsService.deleteMallAppOrderGoodsByIds(ids));
    }

    /**
     * 查询app-线下订单商品列表
     */
    @GetMapping("/getMallAppOrderGoodsList")
    public AjaxResult getMallAppOrderGoodsList(MallAppOrderGoods mallAppOrderGoods)
    {
        mallAppOrderGoods.setDelFlag("0");
        List<MallAppOrderGoods> list = mallAppOrderGoodsService.selectMallAppOrderGoodsList(mallAppOrderGoods);
        return AjaxResult.success(list);
    }
}
