package com.zhongzheng.controller.bank;

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

import com.zhongzheng.modules.bank.bo.*;
import com.zhongzheng.modules.bank.domain.QuestionBusiness;
import com.zhongzheng.modules.bank.service.IQuestionBusinessService;
import com.zhongzheng.modules.bank.service.IQuestionChapterExamService;
import com.zhongzheng.modules.bank.service.IQuestionChapterService;
import com.zhongzheng.modules.bank.vo.ExamQuestionVo;
import com.zhongzheng.modules.bank.vo.ExamVo;
import com.zhongzheng.modules.bank.vo.QuestionChapterVo;
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.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 章卷Controller
 *
 * @author hjl
 * @date 2021-10-25
 */
@Api(value = "章卷控制器", tags = {"章卷管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/bank/chapter")
public class QuestionChapterController extends BaseController {

    private final IQuestionChapterService iQuestionChapterService;

    private final IQuestionBusinessService iQuestionBusinessService;

    private final IQuestionChapterExamService iQuestionChapterExamService;

    /**
     * 查询章卷列表
     */
    @ApiOperation("查询章卷列表")
    @PreAuthorize("@ss.hasPermi('system:chapter:list')")
    @GetMapping("/list")
    public TableDataInfo<QuestionChapterVo> list(QuestionChapterQueryBo bo) {
        startPage();
        List<QuestionChapterVo> list = iQuestionChapterService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出章卷列表
     */
  /*  @ApiOperation("导出章卷列表")
    @PreAuthorize("@ss.hasPermi('system:chapter:export')")
    @Log(title = "章卷", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<QuestionChapterVo> export(QuestionChapterQueryBo bo) {
        List<QuestionChapterVo> list = iQuestionChapterService.queryList(bo);
        ExcelUtil<QuestionChapterVo> util = new ExcelUtil<QuestionChapterVo>(QuestionChapterVo.class);
        return util.exportExcel(list, "章卷");
    }*/

    /**
     * 获取章卷详细信息
     */
    @ApiOperation("获取章卷详细信息")
    @PreAuthorize("@ss.hasPermi('system:chapter:query')")
    @GetMapping("/{chapterExamId}")
    public AjaxResult<QuestionChapterVo> getInfo(@PathVariable("chapterExamId" ) Long chapterExamId) {
        return AjaxResult.success(iQuestionChapterService.queryById(chapterExamId));
    }

    /**
     * 新增章卷
     */
    @ApiOperation("新增章卷")
    @PreAuthorize("@ss.hasPermi('system:chapter:add')")
    @Log(title = "章卷", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody QuestionChapterAddBo bo) {
        return toAjax(iQuestionChapterService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改章卷
     */
    @ApiOperation("修改章卷")
    @PreAuthorize("@ss.hasPermi('system:chapter:edit')")
    @Log(title = "章卷", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody QuestionChapterEditBo bo) {
        return toAjax(iQuestionChapterService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除章卷
     */
    /*@ApiOperation("删除章卷")
    @PreAuthorize("@ss.hasPermi('system:chapter:remove')")
    @Log(title = "章卷" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{chapterExamIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] chapterExamIds) {
        return toAjax(iQuestionChapterService.deleteWithValidByIds(Arrays.asList(chapterExamIds), true) ? 1 : 0);
    }*/
    /**
     * 查询题目业务层次关系列表
     */
    @ApiOperation("查询业务层次关系列表")
    @PreAuthorize("@ss.hasPermi('system:business:list')")
    @GetMapping("/business/list")
    public TableDataInfo<QuestionBusiness> businessList(QuestionBusinessQueryBo bo) {
        startPage();
        bo.setType(QuestionBusiness.TYPE_QUESTION_CHAPTER);
        List<QuestionBusiness> list = iQuestionBusinessService.getListById(bo);
        return getDataTable(list);
    }
    /**
     * 查询关联试卷列表
     */
    @ApiOperation("查询关联试卷列表")
    @PreAuthorize("@ss.hasPermi('system:business:list')")
    @GetMapping("/exam/list")
    public AjaxResult<List<ExamVo>> examList(QuestionChapterExamQueryBo bo) {
        List<ExamVo> list = iQuestionChapterExamService.getList(bo);
        return AjaxResult.success(list);
    }

}
