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.IExamBeforeGoodsService;
import com.zhongzheng.modules.exam.service.IExamBeforeUrlService;
import com.zhongzheng.modules.exam.vo.ExamApplyVo;
import com.zhongzheng.modules.exam.vo.ExamBeforeUrlVo;
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.ExamBeforeVo;
import com.zhongzheng.modules.exam.service.IExamBeforeService;
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/before")
public class ExamBeforeController extends BaseController {

    private final IExamBeforeService iExamBeforeService;
    private final IExamBeforeUrlService iExamBeforeUrlService;
    private final IExamBeforeGoodsService iExamBeforeGoodsService;

    /**
     * 查询前培安排列表
     */
    @ApiOperation("查询前培安排列表")
    @PreAuthorize("@ss.hasPermi('system:before:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamBeforeVo> list(ExamBeforeQueryBo bo) {
        startPage();
        List<ExamBeforeVo> list = iExamBeforeService.queryList(bo);
        return getDataTable(list);
    }


    /**
     * 获取前培安排详细信息
     */
    @ApiOperation("获取前培安排详细信息")
    @PreAuthorize("@ss.hasPermi('system:before:query')")
    @GetMapping("/{beforeId}")
    public AjaxResult<ExamBeforeVo> getInfo(@PathVariable("beforeId" ) Long beforeId) {
        return AjaxResult.success(iExamBeforeService.queryById(beforeId));
    }

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

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

    /**
     * 查询前培url列表
     */
    @ApiOperation("查询前培url列表")
    @PreAuthorize("@ss.hasPermi('system:url:list')")
    @GetMapping("/listUrl")
    public TableDataInfo<ExamBeforeUrlVo> list(ExamBeforeUrlQueryBo bo) {
        startPage();
        List<ExamBeforeUrlVo> list = iExamBeforeUrlService.queryList(bo);
        return getDataTable(list);
    }

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


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

    /**
     * 获取考试地点 考培地点
     */
    @ApiOperation("查看前陪绑定商品")
    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping("/goodsInfo")
    public AjaxResult<ExamBeforeVo> getGoodsInfo(ExamBeforeQueryBo bo) {
        ExamBeforeVo examBeforeVo = iExamBeforeService.getGoodsInfo(bo);
        return  AjaxResult.success(examBeforeVo);
    }

}
