package com.ruoyi.hezhi.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.hezhi.domain.TbLiveBroadcast;
import com.ruoyi.hezhi.service.ITbLiveBroadcastService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 直播Controller
 *
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/hezhi/liveBroadcast")
public class TbLiveBroadcastController extends BaseController
{
    @Autowired
    private ITbLiveBroadcastService tbLiveBroadcastService;

    /**
     * 查询直播列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:liveBroadcast:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbLiveBroadcast tbLiveBroadcast)
    {
        startPage();
        List<TbLiveBroadcast> list = tbLiveBroadcastService.selectTbLiveBroadcastList(tbLiveBroadcast);
        return getDataTable(list);
    }

    /**
     * 导出直播列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:liveBroadcast:export')")
    @Log(title = "直播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLiveBroadcast tbLiveBroadcast)
    {
        List<TbLiveBroadcast> list = tbLiveBroadcastService.selectTbLiveBroadcastList(tbLiveBroadcast);
        ExcelUtil<TbLiveBroadcast> util = new ExcelUtil<TbLiveBroadcast>(TbLiveBroadcast.class);
        util.exportExcel(response, list, "直播数据");
    }

    /**
     * 获取直播详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:liveBroadcast:query')")
    @GetMapping(value = "/{liveBroadcastId}")
    public AjaxResult getInfo(@PathVariable("liveBroadcastId") Long liveBroadcastId)
    {
        return success(tbLiveBroadcastService.selectTbLiveBroadcastByLiveBroadcastId(liveBroadcastId));
    }

    /**
     * 新增直播
     */
    @PreAuthorize("@ss.hasPermi('hezhi:liveBroadcast:add')")
    @Log(title = "直播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbLiveBroadcast tbLiveBroadcast)
    {
        return toAjax(tbLiveBroadcastService.insertTbLiveBroadcast(tbLiveBroadcast));
    }

    /**
     * 修改直播
     */
    @PreAuthorize("@ss.hasPermi('hezhi:liveBroadcast:edit')")
    @Log(title = "直播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbLiveBroadcast tbLiveBroadcast)
    {
        return toAjax(tbLiveBroadcastService.updateTbLiveBroadcast(tbLiveBroadcast));
    }

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