package com.zhongzheng.controller.exam;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
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.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.modules.exam.vo.ExamPaperVo;
import com.zhongzheng.modules.exam.bo.ExamPaperQueryBo;
import com.zhongzheng.modules.exam.bo.ExamPaperAddBo;
import com.zhongzheng.modules.exam.bo.ExamPaperEditBo;
import com.zhongzheng.modules.exam.service.IExamPaperService;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 试卷类型Controller
 * 
 * @author ruoyi
 * @date 2021-10-18
 */
@Api(value = "试卷类型控制器", tags = {"试卷类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/exam/paper")
public class ExamPaperController extends BaseController {

    private final IExamPaperService iExamPaperService;

    /**
     * 查询试卷类型列表
     */
    @ApiOperation("查询试卷类型列表")
    @PreAuthorize("@ss.hasPermi('exam:paper:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamPaperVo> list(ExamPaperQueryBo bo) {
        startPage();
        List<ExamPaperVo> list = iExamPaperService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出试卷类型列表
     */
 /*   @ApiOperation("导出试卷类型列表")
    @PreAuthorize("@ss.hasPermi('exam:paper:export')")
    @Log(title = "试卷类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ExamPaperVo> export(ExamPaperQueryBo bo) {
        List<ExamPaperVo> list = iExamPaperService.queryList(bo);
        ExcelUtil<ExamPaperVo> util = new ExcelUtil<ExamPaperVo>(ExamPaperVo.class);
        return util.exportExcel(list, "试卷类型");
    }*/

    /**
     * 获取试卷类型详细信息
     */
    @ApiOperation("获取试卷类型详细信息")
    @PreAuthorize("@ss.hasPermi('exam:paper:query')")
    @GetMapping("/{paperId}")
    public AjaxResult<ExamPaperVo> getInfo(@PathVariable("paperId" ) Long paperId) {
        return AjaxResult.success(iExamPaperService.queryById(paperId));
    }

    /**
     * 新增试卷类型
     */
    @ApiOperation("新增试卷类型")
    @PreAuthorize("@ss.hasPermi('exam:paper:add')")
    @Log(title = "试卷类型", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody ExamPaperAddBo bo) {
        return toAjax(iExamPaperService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改试卷类型
     */
    @ApiOperation("修改试卷类型")
    @PreAuthorize("@ss.hasPermi('exam:paper:edit')")
    @Log(title = "试卷类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody ExamPaperEditBo bo) {
        return toAjax(iExamPaperService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除试卷类型
     */
/*    @ApiOperation("删除试卷类型")
    @PreAuthorize("@ss.hasPermi('exam:paper:remove')")
    @Log(title = "试卷类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{paperIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] paperIds) {
        return toAjax(iExamPaperService.deleteWithValidByIds(Arrays.asList(paperIds), true) ? 1 : 0);
    }*/
}
