package com.zhongzheng.controller.exam;

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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zhongzheng.modules.exam.bo.ExamConfigAddBo;
import com.zhongzheng.modules.exam.bo.ExamConfigEditBo;
import com.zhongzheng.modules.exam.bo.ExamConfigQueryBo;
import com.zhongzheng.modules.exam.service.IExamConfigService;
import com.zhongzheng.modules.exam.vo.ExamConfigVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 考题配置Controller
 *
 * @author hjl
 * @date 2021-05-21
 */
@Api(value = "考题配置控制器", tags = {"考题配置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/exam/config")
public class ExamConfigController extends BaseController {

    private final IExamConfigService iExamConfigService;

    /**
     * 查询考题配置列表
     */
    @ApiOperation("查询考题配置列表")
    @PreAuthorize("@ss.hasPermi('exam:config:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamConfigVo> list(ExamConfigQueryBo bo) {
        startPage();
        List<ExamConfigVo> list = iExamConfigService.selectExamConfigList(bo);
        return getDataTable(list);
    }

    /**
     * 导出考题配置列表
     */
    /*@ApiOperation("导出考题配置列表")
    @PreAuthorize("@ss.hasPermi('exam:config:export')")
    @Log(title = "考题配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ExamConfigVo> export(ExamConfigQueryBo bo) {
        List<ExamConfigVo> list = iExamConfigService.queryList(bo);
        ExcelUtil<ExamConfigVo> util = new ExcelUtil<ExamConfigVo>(ExamConfigVo.class);
        return util.exportExcel(list, "考题配置");
    }*/

    /**
     * 获取考题配置详细信息
     */
    @ApiOperation("获取考题配置详细信息")
    @PreAuthorize("@ss.hasPermi('exam:config:query')")
    @GetMapping("/{id}")
    public AjaxResult<ExamConfigVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iExamConfigService.queryById(id));
    }

    /**
     * 新增考题配置
     */
    @ApiOperation("新增考题配置")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('exam:config:add')")
    @Log(title = "考题配置", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ExamConfigAddBo bo) {
        return toAjax(iExamConfigService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改考题配置
     */
    @ApiOperation("修改考题配置")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('exam:config:edit')")
    @Log(title = "考题配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@Validated  @RequestBody ExamConfigEditBo bo) {
        return toAjax(iExamConfigService.updateByEditBo(bo) ? 1 : 0);
    }

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