package com.zhongzheng.controller.exam;

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

import com.zhongzheng.modules.exam.bo.*;
import com.zhongzheng.modules.exam.domain.ExamArrangementGuide;
import com.zhongzheng.modules.exam.service.IExamArrangementGuideService;
import com.zhongzheng.modules.exam.vo.ExamArrangementGuideVo;
import com.zhongzheng.modules.exam.vo.ExamUserVo;
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.ExamArrangementVo;
import com.zhongzheng.modules.exam.service.IExamArrangementService;
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 change
 * @date 2021-05-19
 */
@Api(value = "考试安排，学员计划，考试指南", tags = {"考试安排，学员计划，考试指南"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/exam/arrangement")
public class ExamArrangementController extends BaseController {

    private final IExamArrangementService iExamArrangementService;

    private final IExamArrangementGuideService iExamArrangementGuideService;

    /**
     * 查询考试安排，包含考试指引列表
     */
    @ApiOperation("考试安排列表")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamArrangementVo> list(ExamArrangementQueryBo bo) {
        startPage();
        List<ExamArrangementVo> list = iExamArrangementService.queryList(bo);
        return getDataTable(list);
    }



    /**
     * 查询学员考试安排
     */
    @ApiOperation("学员计划列表")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:list')")
    @GetMapping("/listExamUser")
    public TableDataInfo<ExamUserVo> listUser(ExamArrangementQueryBo bo) {
        startPage();
        List<ExamUserVo> list = iExamArrangementService.queryUserList(bo);
        return getDataTable(list);
    }


    /**
     * 查询订阅
     */
    @ApiOperation("订阅人数列表")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:list')")
    @GetMapping("/listSub")
    public TableDataInfo<ExamUserVo> listUserSub(ExamArrangementQueryBo bo) {
        startPage();
        List<ExamUserVo> list = iExamArrangementService.queryUserSubList(bo);
        return getDataTable(list);
    }

    /**
     *查询考试指南
     */
    @ApiOperation("考试指南")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:list')")
    @GetMapping("/listGuide")
    public TableDataInfo<ExamArrangementGuideVo> listUserSub(ExamArrangementGuideQueryBo bo) {
        startPage();
        List<ExamArrangementGuideVo> list = iExamArrangementGuideService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出考试安排，包含考试指引列表
     */
 /*   @ApiOperation("导出考试安排，包含考试指引列表")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:export')")
    @Log(title = "考试安排，包含考试指引", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ExamArrangementVo> export(ExamArrangementQueryBo bo) {
        List<ExamArrangementVo> list = iExamArrangementService.queryList(bo);
        ExcelUtil<ExamArrangementVo> util = new ExcelUtil<ExamArrangementVo>(ExamArrangementVo.class);
        return util.exportExcel(list, "考试安排，包含考试指引");
    }*/
    /**
     * 新增【考试指南】
     */
    @ApiOperation("新增【考试指南】")
    @PreAuthorize("@ss.hasPermi('system:guide:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("addGuide")
    public AjaxResult<Void> add(@RequestBody ExamArrangementGuideAddBo bo) {
        return toAjax(iExamArrangementGuideService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改【考试指南】
     */
    @ApiOperation("修改【考试指南】")
    @PreAuthorize("@ss.hasPermi('system:guide:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("editGuide")
    public AjaxResult<Void> edit(@RequestBody ExamArrangementGuideEditBo bo) {
        return toAjax(iExamArrangementGuideService.updateByEditBo(bo) ? 1 : 0);
    }
    /**
     * 获取考试安排，包含考试指引详细信息
     */
    @ApiOperation("考试安排详情")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:query')")
    @GetMapping("/{id}")
    public AjaxResult<ExamArrangementVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iExamArrangementService.queryById(id));
    }

    /**
     * 新增考试安排，包含考试指引
     */
    @ApiOperation("新增考试安排")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:add')")
    @Log(title = "考试安排，包含考试指引", businessType = BusinessType.INSERT)
    @PostMapping("/addExam")
    public AjaxResult<Void> add(@RequestBody ExamArrangementAddBo bo) {
        return toAjax(iExamArrangementService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改考试安排，包含考试指引
     */
    @ApiOperation("修改考试安排")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:edit')")
    @Log(title = "考试安排，包含考试指引", businessType = BusinessType.UPDATE)
    @PostMapping("/editExam")
    public AjaxResult<Void> edit(@RequestBody ExamArrangementEditBo bo) {
        return toAjax(iExamArrangementService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除考试安排，包含考试指引
     */
    @ApiOperation("删除考试安排")
    @PreAuthorize("@ss.hasPermi('modules.exam:arrangement:remove')")
    @Log(title = "考试安排，包含考试指引" , businessType = BusinessType.DELETE)
    @PostMapping("deleteExam")
    public AjaxResult<Void> remove(@RequestBody Long[] ids) {
        return toAjax(iExamArrangementService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
