package com.zhongzheng.controller.exam;

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

import com.zhongzheng.modules.exam.bo.*;
import com.zhongzheng.modules.exam.service.IExamApplyGoodsService;
import com.zhongzheng.modules.exam.service.IExamApplySiteService;
import com.zhongzheng.modules.exam.vo.ExamApplySiteVo;
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.ExamApplyVo;
import com.zhongzheng.modules.exam.service.IExamApplyService;
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-07
 */
@Api(value = "考试安排控制器", tags = {"考试安排管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/apply")
public class ExamApplyController extends BaseController {

    private final IExamApplyService iExamApplyService;

    private final IExamApplySiteService iExamApplySiteService;

    private final IExamApplyGoodsService iExamApplyGoodsService;

    /**
     * 查询考试安排列表
     */
    @ApiOperation("查询考试安排列表")
    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamApplyVo> list(ExamApplyQueryBo bo) {
        startPage();
        List<ExamApplyVo> list = iExamApplyService.queryList(bo);
        return getDataTable(list);
    }


    /**
     * 获取考试安排详细信息
     */
    @ApiOperation("获取考试安排详细信息")
    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping("/{applyId}")
    public AjaxResult<ExamApplyVo> getInfo(@PathVariable("applyId" ) Long applyId) {
        return AjaxResult.success(iExamApplyService.queryById(applyId));
    }

    /**
     * 获取考试地点 考培地点
     */
    @ApiOperation("获取考试地点 考培地点")
    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping("/siteInfo")
    public TableDataInfo<ExamApplySiteVo> getSiteInfo(ExamApplyQueryBo bo) {
        List<ExamApplySiteVo> examApplySiteVo = iExamApplyService.getSiteInfo(bo);
        return getDataTable(examApplySiteVo);
    }

    /**
     * 新增考试安排
     */
    @ApiOperation("新增考试安排")
    @PreAuthorize("@ss.hasPermi('system:apply:add')")
    @Log(title = "考试安排", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody ExamApplyAddBo bo) {
        return toAjax(iExamApplyService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改考试安排
     */
    @ApiOperation("修改考试安排")
    @PreAuthorize("@ss.hasPermi('system:apply:edit')")
    @Log(title = "考试安排", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult<Void> edit(@RequestBody ExamApplyEditBo bo) {
        return toAjax(iExamApplyService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 新增考试安排地点
     */
    @ApiOperation("新增考试安排地点")
    @PreAuthorize("@ss.hasPermi('system:site:add')")
    @Log(title = "考试安排地点", businessType = BusinessType.INSERT)
    @PostMapping("addSite")
    public AjaxResult<Void> addSite(@RequestBody List<ExamApplySiteAddBo> bo) {
        return toAjax(iExamApplySiteService.addSite(bo) ? 1 : 0);
    }


    /**
     * 新增考试安排绑定商品
     */
    @ApiOperation("新增考试安排绑定商品")
    @PreAuthorize("@ss.hasPermi('system:goods:add')")
    @Log(title = "考试安排绑定商品", businessType = BusinessType.INSERT)
    @PostMapping("addGoods")
    public AjaxResult<Void> addGoods(@RequestBody ExamApplyGoodsAddBo bo) {
        return toAjax(iExamApplyGoodsService.addGoods(bo) ? 1 : 0);
    }

    /**
     * 获取考试地点 考培地点
     */
    @ApiOperation("查看考试安排绑定商品")
    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping("/goodsInfo")
    public AjaxResult<ExamApplyVo> getGoodsInfo(ExamApplyQueryBo bo) {
        ExamApplyVo examApplyVos = iExamApplyService.getGoodsInfo(bo);
        return  AjaxResult.success(examApplyVos);
    }

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


}
