package com.fs.app.controller.live;

import com.fs.app.annotation.Login;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.live.domain.LiveMsg;
import com.fs.live.service.ILiveMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直播讨论Controller
 *
 * @author fs
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/app/live/liveMsg")
public class LiveMsgController extends BaseController
{
    @Autowired
    private ILiveMsgService liveMsgService;

    /**
     * 查询直播讨论列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LiveMsg liveMsg)
    {
        startPage();
        List<LiveMsg> list = liveMsgService.selectLiveMsgList(liveMsg);
        return getDataTable(list);
    }

    /**
     * 查询直播讨论列表
     */
    @Login
    @GetMapping("/myList")
    public TableDataInfo myList(LiveMsg liveMsg)
    {
        startPage();
        liveMsg.setUserId(getUserId());
        List<LiveMsg> list = liveMsgService.selectLiveMsgList(liveMsg);
        return getDataTable(list);
    }

    /**
     * 导出直播讨论列表
     */
    @Log(title = "直播讨论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveMsg liveMsg)
    {
        List<LiveMsg> list = liveMsgService.selectLiveMsgList(liveMsg);
        ExcelUtil<LiveMsg> util = new ExcelUtil<LiveMsg>(LiveMsg.class);
        return util.exportExcel(list, "直播讨论数据");
    }



    /**
     * 新增直播讨论
     */
    @Log(title = "直播讨论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveMsg liveMsg)
    {
        return toAjax(liveMsgService.insertLiveMsg(liveMsg));
    }

    /**
     * 修改直播讨论
     */
    @Log(title = "直播讨论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveMsg liveMsg)
    {
        return toAjax(liveMsgService.updateLiveMsg(liveMsg));
    }

    /**
     * 删除直播讨论
     */
    @Log(title = "直播讨论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{msgIds}")
    public AjaxResult remove(@PathVariable Long[] msgIds)
    {
        return toAjax(liveMsgService.deleteLiveMsgByMsgIds(msgIds));
    }

}
