package com.xinelu.manage.controller.questionsubjectoption;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.questionsubjectoption.QuestionSubjectOption;
import com.xinelu.manage.service.questionsubjectoption.IQuestionSubjectOptionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 问卷题目选项答案Controller
 *
 * @author xinelu
 * @date 2024-02-29
 */
@RestController
@RequestMapping("/system/questionSubjectOption")
public class QuestionSubjectOptionController extends BaseController {
    @Resource
    private IQuestionSubjectOptionService questionSubjectOptionService;

    /**
     * 查询问卷题目选项答案列表
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubjectOption:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionSubjectOption questionSubjectOption) {
        startPage();
        List<QuestionSubjectOption> list = questionSubjectOptionService.selectQuestionSubjectOptionList(questionSubjectOption);
        return getDataTable(list);
    }

    /**
     * 导出问卷题目选项答案列表
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubjectOption:export')")
    @Log(title = "问卷题目选项答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionSubjectOption questionSubjectOption) {
        List<QuestionSubjectOption> list = questionSubjectOptionService.selectQuestionSubjectOptionList(questionSubjectOption);
        ExcelUtil<QuestionSubjectOption> util = new ExcelUtil<QuestionSubjectOption>(QuestionSubjectOption.class);
        util.exportExcel(response, list, "问卷题目选项答案数据");
    }

    /**
     * 获取问卷题目选项答案详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubjectOption:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(questionSubjectOptionService.selectQuestionSubjectOptionById(id));
    }

    /**
     * 新增问卷题目选项答案
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubjectOption:add')")
    @Log(title = "问卷题目选项答案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionSubjectOption questionSubjectOption) {
        return toAjax(questionSubjectOptionService.insertQuestionSubjectOption(questionSubjectOption));
    }

    /**
     * 修改问卷题目选项答案
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubjectOption:edit')")
    @Log(title = "问卷题目选项答案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionSubjectOption questionSubjectOption) {
        return toAjax(questionSubjectOptionService.updateQuestionSubjectOption(questionSubjectOption));
    }

    /**
     * 删除问卷题目选项答案
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubjectOption:remove')")
    @Log(title = "问卷题目选项答案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionSubjectOptionService.deleteQuestionSubjectOptionByIds(ids));
    }
}
