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

/**
 * 问答Controller
 * 
 * @author fs
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/live/liveQuestion")
public class LiveQuestionController extends BaseController
{
    @Autowired
    private ILiveQuestionService liveQuestionService;

    /**
     * 查询问答列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestion:list')")
    @GetMapping("/list")
    public TableDataInfo list(LiveQuestion liveQuestion)
    {
        startPage();
        List<LiveQuestion> list = liveQuestionService.selectLiveQuestionList(liveQuestion);
        return getDataTable(list);
    }

    /**
     * 导出问答列表
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestion:export')")
    @Log(title = "问答", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveQuestion liveQuestion)
    {
        List<LiveQuestion> list = liveQuestionService.selectLiveQuestionList(liveQuestion);
        ExcelUtil<LiveQuestion> util = new ExcelUtil<LiveQuestion>(LiveQuestion.class);
        return util.exportExcel(list, "问答数据");
    }

    /**
     * 获取问答详细信息
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestion:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return AjaxResult.success(liveQuestionService.selectLiveQuestionByQuestionId(questionId));
    }

    /**
     * 新增问答
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestion:add')")
    @Log(title = "问答", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveQuestion liveQuestion)
    {
        return toAjax(liveQuestionService.insertLiveQuestion(liveQuestion));
    }

    /**
     * 修改问答
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestion:edit')")
    @Log(title = "问答", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveQuestion liveQuestion)
    {
        return toAjax(liveQuestionService.updateLiveQuestion(liveQuestion));
    }

    /**
     * 删除问答
     */
    @PreAuthorize("@ss.hasPermi('live:liveQuestion:remove')")
    @Log(title = "问答", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(liveQuestionService.deleteLiveQuestionByQuestionIds(questionIds));
    }
}
