package com.ruoyi.abuwx.controller.exam;

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

import com.ruoyi.abuwx.service.exam.IExmQuestionTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.abuwx.domain.exam.ExmQuestionType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题库Controller
 * 
 * @author ruoyi
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/system/question/type")
@Api(tags = "题库管理")
public class ExmQuestionTypeController extends BaseController
{
    @Autowired
    private IExmQuestionTypeService exmQuestionTypeService;

    /**
     * 查询题库列表
     */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExmQuestionType exmQuestionType)
    {
        startPage();
        List<ExmQuestionType> list = exmQuestionTypeService.selectExmQuestionTypeList(exmQuestionType);
        return getDataTable(list);
    }

    /**
     * 导出题库列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExmQuestionType exmQuestionType)
    {
        List<ExmQuestionType> list = exmQuestionTypeService.selectExmQuestionTypeList(exmQuestionType);
        ExcelUtil<ExmQuestionType> util = new ExcelUtil<ExmQuestionType>(ExmQuestionType.class);
        util.exportExcel(response, list, "题库数据");
    }

    /**
     * 获取题库详细信息
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(exmQuestionTypeService.selectExmQuestionTypeById(id));
    }

    /**
     * 新增题库
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "题库", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增")
    public AjaxResult add(@RequestBody ExmQuestionType exmQuestionType)
    {
        return toAjax(exmQuestionTypeService.insertExmQuestionType(exmQuestionType));
    }

    /**
     * 修改题库
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "题库", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改")
    public AjaxResult edit(@RequestBody ExmQuestionType exmQuestionType)
    {
        return toAjax(exmQuestionTypeService.updateExmQuestionType(exmQuestionType));
    }

    /**
     * 删除题库
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "题库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("批量删除")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(exmQuestionTypeService.deleteExmQuestionTypeByIds(ids));
    }
}
