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.Live;
import com.fs.live.service.ILiveService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 直播Controller
 * 
 * @author fs
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/live/live")
public class LiveController extends BaseController
{
    @Autowired
    private ILiveService liveService;

    /**
     * 查询直播列表
     */
    @PreAuthorize("@ss.hasPermi('live:live:list')")
    @GetMapping("/list")
    public TableDataInfo list(Live live)
    {
        startPage();
        List<Live> list = liveService.selectLiveList(live);
        return getDataTable(list);
    }

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

    /**
     * 获取直播详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:live:query')")
    @GetMapping(value = "/{liveId}")
    public AjaxResult getInfo(@PathVariable("liveId") Long liveId)
    {
        return AjaxResult.success(liveService.selectLiveByLiveId(liveId));
    }

    /**
     * 新增直播
     */
    @PreAuthorize("@ss.hasPermi('live:live:add')")
    @Log(title = "直播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Live live)
    {
        return toAjax(liveService.insertLive(live));
    }

    /**
     * 修改直播
     */
    @PreAuthorize("@ss.hasPermi('live:live:edit')")
    @Log(title = "直播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Live live)
    {
        return toAjax(liveService.updateLive(live));
    }

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