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

import javax.annotation.Resource;

/**
 * 拼团商品Controller
 *
 * @author ruoyi
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/mall/mallCombineGoods")
public class MallCombineGoodsController extends BaseController
{
    @Resource
    private IMallCombineGoodsService mallCombineGoodsService;

    /**
     * 查询拼团商品列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCombineGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallCombineGoods mallCombineGoods)
    {
        startPage();
        List<MallCombineGoods> list = mallCombineGoodsService.selectMallCombineGoodsList(mallCombineGoods);
        return getDataTable(list);
    }

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

    /**
     * 获取拼团商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCombineGoods:query')")
    @GetMapping(value = "/{combineId}")
    public AjaxResult getInfo(@PathVariable("combineId") Long combineId)
    {
        return AjaxResult.success(mallCombineGoodsService.selectMallCombineGoodsByCombineId(combineId));
    }

    /**
     * 新增拼团商品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCombineGoods:add')")
    @Log(title = "拼团商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallCombineGoods mallCombineGoods)
    {
        return mallCombineGoodsService.insertMallCombineGoods(mallCombineGoods);
    }

    /**
     * 修改拼团商品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCombineGoods:edit')")
    @Log(title = "拼团商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallCombineGoods mallCombineGoods)
    {
        return toAjax(mallCombineGoodsService.updateMallCombineGoods(mallCombineGoods));
    }

    /**
     * 删除拼团商品
     */
    @PreAuthorize("@ss.hasPermi('mall:mallCombineGoods:remove')")
    @Log(title = "拼团商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{combineIds}")
    public AjaxResult remove(@PathVariable Long[] combineIds)
    {
        return toAjax(mallCombineGoodsService.deleteMallCombineGoodsByCombineIds(combineIds));
    }

    /**
     * 拼团商品可选商品列表
     */
    @GetMapping("/enableCombineGoodsList")
    public AjaxResult enableCombineGoodsList(){
        return AjaxResult.success(mallCombineGoodsService.enableCombineGoodsList());
    }
}
