package com.fs.live.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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.live.domain.LiveGoods;
import com.fs.live.service.ILiveGoodsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 直播商品Controller
 * 
 * @author fs
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/live/liveGoods")
public class LiveGoodsController extends BaseController
{
    @Autowired
    private ILiveGoodsService liveGoodsService;

    /**
     * 查询直播商品列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(LiveGoods liveGoods)
    {
        startPage();
        List<LiveGoods> list = liveGoodsService.selectLiveGoodsList(liveGoods);
        return getDataTable(list);
    }

    /**
     * 导出直播商品列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveGoods:export')")
    @Log(title = "直播商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveGoods liveGoods)
    {
        List<LiveGoods> list = liveGoodsService.selectLiveGoodsList(liveGoods);
        ExcelUtil<LiveGoods> util = new ExcelUtil<LiveGoods>(LiveGoods.class);
        return util.exportExcel(list, "直播商品数据");
    }

    /**
     * 获取直播商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:liveGoods:query')")
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return AjaxResult.success(liveGoodsService.selectLiveGoodsByGoodsId(goodsId));
    }

    /**
     * 新增直播商品
     */
    @PreAuthorize("@ss.hasPermi('live:liveGoods:add')")
    @Log(title = "直播商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveGoods liveGoods)
    {
        return toAjax(liveGoodsService.insertLiveGoods(liveGoods));
    }

    /**
     * 修改直播商品
     */
    @PreAuthorize("@ss.hasPermi('live:liveGoods:edit')")
    @Log(title = "直播商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveGoods liveGoods)
    {
        return toAjax(liveGoodsService.updateLiveGoods(liveGoods));
    }

    /**
     * 删除直播商品
     */
    @PreAuthorize("@ss.hasPermi('live:liveGoods:remove')")
    @Log(title = "直播商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(liveGoodsService.deleteLiveGoodsByGoodsIds(goodsIds));
    }
}
