package com.zhongzheng.controller.bank;

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

import com.zhongzheng.modules.bank.bo.QuestionBankExamAddBo;
import com.zhongzheng.modules.bank.bo.QuestionBankExamEditBo;
import com.zhongzheng.modules.bank.bo.QuestionBankExamQueryBo;
import com.zhongzheng.modules.bank.service.IQuestionBankExamService;
import com.zhongzheng.modules.bank.vo.QuestionBankExamVo;
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.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 题库试卷Controller
 *
 * @author hjl
 * @date 2021-05-20
 */
@Api(value = "题库试卷控制器", tags = {"题库试卷管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/bank/exam")
public class QuestionBankExamController extends BaseController {

    private final IQuestionBankExamService iQuestionBankExamService;

    /**
     * 查询题库试卷列表
     */
    @ApiOperation("查询题库试卷列表")
    @PreAuthorize("@ss.hasPermi('bank:exam:list')")
    @GetMapping("/list")
    public TableDataInfo<QuestionBankExamVo> list(QuestionBankExamQueryBo bo) {
        startPage();
        List<QuestionBankExamVo> list = iQuestionBankExamService.selectBankExamList(bo);
        return getDataTable(list);
    }

    /**
     * 导出题库试卷列表
     */
    /*@ApiOperation("导出题库试卷列表")
    @PreAuthorize("@ss.hasPermi('bank:exam:export')")
    @Log(title = "题库试卷", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<QuestionBankExamVo> export(QuestionBankExamQueryBo bo) {
        List<QuestionBankExamVo> list = iQuestionBankExamService.queryList(bo);
        ExcelUtil<QuestionBankExamVo> util = new ExcelUtil<QuestionBankExamVo>(QuestionBankExamVo.class);
        return util.exportExcel(list, "题库试卷");
    }*/

    /**
     * 获取题库试卷详细信息
     */
    @ApiOperation("获取题库试卷详细信息")
    @PreAuthorize("@ss.hasPermi('bank:exam:query')")
    @GetMapping("/{examId}")
    public AjaxResult<QuestionBankExamVo> getInfo(@PathVariable("examId" ) Long examId) {
        return AjaxResult.success(iQuestionBankExamService.queryById(examId));
    }

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

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

    /**
     * 删除题库试卷
     */
    @ApiOperation("删除题库试卷")
    @PreAuthorize("@ss.hasPermi('bank:exam:remove')")
    @Log(title = "题库试卷" , businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult<Void> remove(@RequestBody Long[] examIds) {
        return toAjax(iQuestionBankExamService.deleteWithValidByIds(Arrays.asList(examIds), true) ? 1 : 0);
    }
}
