package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.QuestionInfo;
import com.ruoyi.abuwx.service.IQuestionInfoService;
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 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 lujie
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/question/info")
public class QuestionInfoController extends BaseController {
    @Autowired
    private IQuestionInfoService questionInfoService;

    /**
     * 查询题目管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionInfo questionInfo) {
        startPage();
        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
        return getDataTable(list);
    }

    /**
     * 导出题目管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:info:export')")
    @Log(title = "题目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionInfo questionInfo) {
        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
        ExcelUtil<QuestionInfo> util = new ExcelUtil<QuestionInfo>(QuestionInfo.class);
        util.exportExcel(response, list, "题目管理数据");
    }

    /**
     * 获取题目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(questionInfoService.selectQuestionInfoById(id));
    }

    /**
     * 新增题目管理
     */
    @PreAuthorize("@ss.hasPermi('question:info:add')")
    @Log(title = "题目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionInfo questionInfo) {
        return toAjax(questionInfoService.insertQuestionInfo(questionInfo));
    }

    /**
     * 修改题目管理
     */
    @PreAuthorize("@ss.hasPermi('question:info:edit')")
    @Log(title = "题目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionInfo questionInfo) {
        return toAjax(questionInfoService.updateQuestionInfo(questionInfo));
    }

    /**
     * 删除题目管理
     */
    @PreAuthorize("@ss.hasPermi('question:info:remove')")
    @Log(title = "题目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionInfoService.deleteQuestionInfoByIds(ids));
    }
}
