package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.QuestionSpecial;
import com.ruoyi.abuwx.service.IQuestionSpecialService;
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/special")
public class QuestionSpecialController extends BaseController {
    @Autowired
    private IQuestionSpecialService questionSpecialService;

    /**
     * 查询专项管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:special:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionSpecial questionSpecial) {
        startPage();
        List<QuestionSpecial> list = questionSpecialService.selectQuestionSpecialList(questionSpecial);
        return getDataTable(list);
    }

    /**
     * 导出专项管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:special:export')")
    @Log(title = "专项管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionSpecial questionSpecial) {
        List<QuestionSpecial> list = questionSpecialService.selectQuestionSpecialList(questionSpecial);
        ExcelUtil<QuestionSpecial> util = new ExcelUtil<QuestionSpecial>(QuestionSpecial.class);
        util.exportExcel(response, list, "专项管理数据");
    }

    /**
     * 获取专项管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:special:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(questionSpecialService.selectQuestionSpecialById(id));
    }

    /**
     * 新增专项管理
     */
    @PreAuthorize("@ss.hasPermi('question:special:add')")
    @Log(title = "专项管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionSpecial questionSpecial) {
        return toAjax(questionSpecialService.insertQuestionSpecial(questionSpecial));
    }

    /**
     * 修改专项管理
     */
    @PreAuthorize("@ss.hasPermi('question:special:edit')")
    @Log(title = "专项管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionSpecial questionSpecial) {
        return toAjax(questionSpecialService.updateQuestionSpecial(questionSpecial));
    }

    /**
     * 删除专项管理
     */
    @PreAuthorize("@ss.hasPermi('question:special:remove')")
    @Log(title = "专项管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionSpecialService.deleteQuestionSpecialByIds(ids));
    }
}
