package com.zhongzheng.controller.exam;

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

import com.zhongzheng.modules.exam.bo.ExamNumberGoodsQueryBo;
import com.zhongzheng.modules.exam.service.IExamNumberGoodsService;
import com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo;
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.ExamNumberVo;
import com.zhongzheng.modules.exam.bo.ExamNumberQueryBo;
import com.zhongzheng.modules.exam.bo.ExamNumberAddBo;
import com.zhongzheng.modules.exam.bo.ExamNumberEditBo;
import com.zhongzheng.modules.exam.service.IExamNumberService;
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-12-06
 */
@Api(value = "考试次数配置控制器", tags = {"考试次数配置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/number")
public class ExamNumberController extends BaseController {

    private final IExamNumberService iExamNumberService;
    private final IExamNumberGoodsService iExamNumberGoodsService;

    /**
     * 查询考试次数配置列表
     */
    @ApiOperation("查询考试次数配置列表")
    @PreAuthorize("@ss.hasPermi('system:number:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamNumberVo> list(ExamNumberQueryBo bo) {
        startPage();
        List<ExamNumberVo> list = iExamNumberService.ListExamNumber(bo);
        return getDataTable(list);
    }


    /**
     * 获取考试次数配置详细信息
     */
    @ApiOperation("获取考试次数配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:number:query')")
    @GetMapping("/{examNumberId}")
    public AjaxResult<ExamNumberVo> getInfo(@PathVariable("examNumberId" ) Long examNumberId) {
        return AjaxResult.success(iExamNumberService.queryById(examNumberId));
    }

    /**
     * 新增考试次数配置
     */
    @ApiOperation("新增考试次数配置")
    @PreAuthorize("@ss.hasPermi('system:number:add')")
    @Log(title = "考试次数配置", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody ExamNumberAddBo bo) {
        return toAjax(iExamNumberService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改考试次数配置
     */
    @ApiOperation("修改考试次数配置")
    @PreAuthorize("@ss.hasPermi('system:number:edit')")
    @Log(title = "考试次数配置", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult<Void> edit(@RequestBody ExamNumberEditBo bo) {
        return toAjax(iExamNumberService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 查询考试配置绑定商品列表
     */
    @ApiOperation("查询考试配置商品列表")
    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/listGoods")
    public TableDataInfo<ExamNumberGoodsVo> listGoods(ExamNumberGoodsQueryBo bo) {
        startPage();
        List<ExamNumberGoodsVo> list = iExamNumberGoodsService.listGoods(bo);
        return getDataTable(list);
    }

}
