package com.ruoyi.frequency.mallrefundordergoods.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.mallrefundordergoods.entity.MallRefundOrderGoods;
import com.ruoyi.frequency.mallrefundordergoods.service.MallRefundOrderGoodsService;
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/mallrefundordergoods")
public class MallRefundOrderGoodsController extends BaseController
{
    @Autowired
    private MallRefundOrderGoodsService mallRefundOrderGoodsService;

    /**
     * 查询订单退款商品关联列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefundordergoods:list')")
    @GetMapping("/list")
    public TableDataInfo<MallRefundOrderGoods> list(MallRefundOrderGoods mallRefundOrderGoods)
    {
        startPage();
        List<MallRefundOrderGoods> list = mallRefundOrderGoodsService.selectMallRefundOrderGoodsList(mallRefundOrderGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单退款商品关联列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefundordergoods:export')")
    @Log(title = "订单退款商品关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallRefundOrderGoods mallRefundOrderGoods)
    {
        List<MallRefundOrderGoods> list = mallRefundOrderGoodsService.selectMallRefundOrderGoodsList(mallRefundOrderGoods);
        ExcelUtil<MallRefundOrderGoods> util = new ExcelUtil<MallRefundOrderGoods>(MallRefundOrderGoods.class);
        return util.exportExcel(list, "订单退款商品关联数据");
    }

    /**
     * 获取订单退款商品关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefundordergoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<MallRefundOrderGoods> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallRefundOrderGoodsService.selectMallRefundOrderGoodsById(id));
    }

    /**
     * 新增订单退款商品关联
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefundordergoods:add')")
    @Log(title = "订单退款商品关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallRefundOrderGoods mallRefundOrderGoods)
    {
        return toAjax(mallRefundOrderGoodsService.insertMallRefundOrderGoods(mallRefundOrderGoods));
    }

    /**
     * 修改订单退款商品关联
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallrefundordergoods:edit')")
    @Log(title = "订单退款商品关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallRefundOrderGoods mallRefundOrderGoods)
    {
        return toAjax(mallRefundOrderGoodsService.updateMallRefundOrderGoods(mallRefundOrderGoods));
    }

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