package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.QuestionTask;
import com.ruoyi.abuwx.service.IQuestionTaskService;
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-07
 */
@RestController
@RequestMapping("/question/task")
public class QuestionTaskController extends BaseController {
    @Autowired
    private IQuestionTaskService questionTaskService;

    /**
     * 查询每日答题任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionTask questionTask) {
        startPage();
        List<QuestionTask> list = questionTaskService.selectQuestionTaskList(questionTask);
        return getDataTable(list);
    }

    /**
     * 导出每日答题任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:task:export')")
    @Log(title = "每日答题任务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionTask questionTask) {
        List<QuestionTask> list = questionTaskService.selectQuestionTaskList(questionTask);
        ExcelUtil<QuestionTask> util = new ExcelUtil<QuestionTask>(QuestionTask.class);
        util.exportExcel(response, list, "每日答题任务管理数据");
    }

    /**
     * 获取每日答题任务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(questionTaskService.selectQuestionTaskById(id));
    }

    /**
     * 新增每日答题任务管理
     */
    @PreAuthorize("@ss.hasPermi('question:task:add')")
    @Log(title = "每日答题任务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionTask questionTask) {
        return toAjax(questionTaskService.insertQuestionTask(questionTask));
    }

    /**
     * 修改每日答题任务管理
     */
    @PreAuthorize("@ss.hasPermi('question:task:edit')")
    @Log(title = "每日答题任务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionTask questionTask) {
        return toAjax(questionTaskService.updateQuestionTask(questionTask));
    }

    /**
     * 删除每日答题任务管理
     */
    @PreAuthorize("@ss.hasPermi('question:task:remove')")
    @Log(title = "每日答题任务管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionTaskService.deleteQuestionTaskByIds(ids));
    }
}
