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.IQuestionModuleChapterService;
import com.zhongzheng.modules.bank.service.IQuestionModuleService;
import com.zhongzheng.modules.bank.vo.ExamQuestionVo;
import com.zhongzheng.modules.bank.vo.QuestionChapterVo;
import com.zhongzheng.modules.bank.vo.QuestionModuleVo;
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/module")
public class QuestionModuleController extends BaseController {

    private final IQuestionModuleService iQuestionModuleService;

    private final IQuestionBusinessService iQuestionBusinessService;

    private final IQuestionModuleChapterService iQuestionModuleChapterService;

    /**
     * 查询题目模块列表
     */
    @ApiOperation("查询题目模块列表")
    @PreAuthorize("@ss.hasPermi('system:module:list')")
    @GetMapping("/list")
    public TableDataInfo<QuestionModuleVo> list(QuestionModuleQueryBo bo) {
        startPage();
        List<QuestionModuleVo> list = iQuestionModuleService.getList(bo);
        return getDataTable(list);
    }

    /**
     * 导出题目模块列表
     */
    /*@ApiOperation("导出题目模块列表")
    @PreAuthorize("@ss.hasPermi('system:module:export')")
    @Log(title = "题目模块", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<QuestionModuleVo> export(QuestionModuleQueryBo bo) {
        List<QuestionModuleVo> list = iQuestionModuleService.queryList(bo);
        ExcelUtil<QuestionModuleVo> util = new ExcelUtil<QuestionModuleVo>(QuestionModuleVo.class);
        return util.exportExcel(list, "题目模块");
    }*/

    /**
     * 获取题目模块详细信息
     */
    @ApiOperation("获取题目模块详细信息")
    @PreAuthorize("@ss.hasPermi('system:module:query')")
    @GetMapping("/{questionModuleId}")
    public AjaxResult<QuestionModuleVo> getInfo(@PathVariable("questionModuleId" ) Long questionModuleId) {
        return AjaxResult.success(iQuestionModuleService.queryById(questionModuleId));
    }

    /**
     * 新增题目模块
     */
    @ApiOperation("新增题目模块")
    @PreAuthorize("@ss.hasPermi('system:module:add')")
    @Log(title = "题目模块", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody QuestionModuleAddBo bo) {
        return toAjax(iQuestionModuleService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改题目模块
     */
    @ApiOperation("修改题目模块")
    @PreAuthorize("@ss.hasPermi('system:module:edit')")
    @Log(title = "题目模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody QuestionModuleEditBo bo) {
        return toAjax(iQuestionModuleService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除题目模块
     */
   /* @ApiOperation("删除题目模块")
    @PreAuthorize("@ss.hasPermi('system:module:remove')")
    @Log(title = "题目模块" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{questionModuleIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] questionModuleIds) {
        return toAjax(iQuestionModuleService.deleteWithValidByIds(Arrays.asList(questionModuleIds), 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_MODULE);
        List<QuestionBusiness> list = iQuestionBusinessService.getListById(bo);
        return getDataTable(list);
    }

    /**
     * 查询关联章卷列表
     */
    @ApiOperation("查询关联章卷列表")
    @PreAuthorize("@ss.hasPermi('system:business:list')")
    @GetMapping("/chapter/list")
    public AjaxResult<List<QuestionChapterVo>> chapterList(QuestionModuleChapterQueryBo bo) {
        List<QuestionChapterVo> list = iQuestionModuleChapterService.getList(bo);
        return AjaxResult.success(list);
    }
}
