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

/**
 * 主播Controller
 * 
 * @author fs
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/live/liveAnchor")
public class LiveAnchorController extends BaseController
{
    @Autowired
    private ILiveAnchorService liveAnchorService;

    /**
     * 查询主播列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveAnchor:list')")
    @GetMapping("/list")
    public TableDataInfo list(LiveAnchor liveAnchor)
    {
        startPage();
        List<LiveAnchor> list = liveAnchorService.selectLiveAnchorList(liveAnchor);
        return getDataTable(list);
    }

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

    /**
     * 获取主播详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:liveAnchor:query')")
    @GetMapping(value = "/{anchorId}")
    public AjaxResult getInfo(@PathVariable("anchorId") Long anchorId)
    {
        return AjaxResult.success(liveAnchorService.selectLiveAnchorByAnchorId(anchorId));
    }

    /**
     * 新增主播
     */
    @PreAuthorize("@ss.hasPermi('live:liveAnchor:add')")
    @Log(title = "主播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveAnchor liveAnchor)
    {
        return toAjax(liveAnchorService.insertLiveAnchor(liveAnchor));
    }

    /**
     * 修改主播
     */
    @PreAuthorize("@ss.hasPermi('live:liveAnchor:edit')")
    @Log(title = "主播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveAnchor liveAnchor)
    {
        return toAjax(liveAnchorService.updateLiveAnchor(liveAnchor));
    }

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