package com.xinelu.manage.controller.questionsubject;

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.questionsubject.QuestionSubject;
import com.xinelu.manage.service.questionsubject.IQuestionSubjectService;
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/questionSubject")
public class QuestionSubjectController extends BaseController {
    @Resource
    private IQuestionSubjectService questionSubjectService;

    /**
     * 查询问卷题目信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubject:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionSubject questionSubject) {
        startPage();
        List<QuestionSubject> list = questionSubjectService.selectQuestionSubjectList(questionSubject);
        return getDataTable(list);
    }

    /**
     * 导出问卷题目信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubject:export')")
    @Log(title = "问卷题目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionSubject questionSubject) {
        List<QuestionSubject> list = questionSubjectService.selectQuestionSubjectList(questionSubject);
        ExcelUtil<QuestionSubject> util = new ExcelUtil<QuestionSubject>(QuestionSubject.class);
        util.exportExcel(response, list, "问卷题目信息数据");
    }

    /**
     * 获取问卷题目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(questionSubjectService.selectQuestionSubjectById(id));
    }

    /**
     * 新增问卷题目信息
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubject:add')")
    @Log(title = "问卷题目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionSubject questionSubject) {
        return toAjax(questionSubjectService.insertQuestionSubject(questionSubject));
    }

    /**
     * 修改问卷题目信息
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubject:edit')")
    @Log(title = "问卷题目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionSubject questionSubject) {
        return toAjax(questionSubjectService.updateQuestionSubject(questionSubject));
    }

    /**
     * 删除问卷题目信息
     */
    @PreAuthorize("@ss.hasPermi('system:questionSubject:remove')")
    @Log(title = "问卷题目信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionSubjectService.deleteQuestionSubjectByIds(ids));
    }
}
