package com.ruoyi.frequency.mallordergoods.controller;

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.frequency.mallordergoods.entity.MallOrderGoods;
import com.ruoyi.frequency.mallordergoods.service.MallOrderGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单商品Controller
 *
 * @author liwenlong
 * @date 2024-01-25
 */
@RestController
@RequestMapping("/frequency/mallordergoods")
public class MallOrderGoodsController extends BaseController
{
    @Autowired
    private MallOrderGoodsService mallOrderGoodsService;

    /**
     * 查询订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallordergoods:list')")
    @GetMapping("/list")
    public TableDataInfo<MallOrderGoods> list(MallOrderGoods mallOrderGoods)
    {
        startPage();
        List<MallOrderGoods> list = mallOrderGoodsService.selectMallOrderGoodsList(mallOrderGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallordergoods:export')")
    @Log(title = "订单商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallOrderGoods mallOrderGoods)
    {
        List<MallOrderGoods> list = mallOrderGoodsService.selectMallOrderGoodsList(mallOrderGoods);
        ExcelUtil<MallOrderGoods> util = new ExcelUtil<MallOrderGoods>(MallOrderGoods.class);
        return util.exportExcel(list, "订单商品数据");
    }

    /**
     * 获取订单商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallordergoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<MallOrderGoods> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallOrderGoodsService.selectMallOrderGoodsById(id));
    }

    /**
     * 新增订单商品
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallordergoods:add')")
    @Log(title = "订单商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallOrderGoods mallOrderGoods)
    {
        return toAjax(mallOrderGoodsService.insertMallOrderGoods(mallOrderGoods));
    }

    /**
     * 修改订单商品
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallordergoods:edit')")
    @Log(title = "订单商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallOrderGoods mallOrderGoods)
    {
        return toAjax(mallOrderGoodsService.updateMallOrderGoods(mallOrderGoods));
    }

    /**
     * 删除订单商品
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallordergoods:remove')")
    @Log(title = "订单商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(mallOrderGoodsService.deleteMallOrderGoodsByIds(ids,delFlag));
    }
}
