package com.zhongzheng.controller.bank;

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

import com.zhongzheng.modules.bank.bo.QuestionBankChapterAddBo;
import com.zhongzheng.modules.bank.bo.QuestionBankChapterEditBo;
import com.zhongzheng.modules.bank.bo.QuestionBankChapterQueryBo;
import com.zhongzheng.modules.bank.service.IQuestionBankChapterService;
import com.zhongzheng.modules.bank.vo.QuestionBankChapterVo;
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-05-20
 */
@Api(value = "题库大章控制器", tags = {"题库大章管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/bank/chapter")
public class QuestionBankChapterController extends BaseController {

    private final IQuestionBankChapterService iQuestionBankChapterService;

    /**
     * 查询题库大章列表
     */
    @ApiOperation("查询题库大章列表")
    @PreAuthorize("@ss.hasPermi('bank:chapter:list')")
    @GetMapping("/list")
    public TableDataInfo<QuestionBankChapterVo> list(QuestionBankChapterQueryBo bo) {
        startPage();
        List<QuestionBankChapterVo> list = iQuestionBankChapterService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出题库大章列表
     */
    /*@ApiOperation("导出题库大章列表")
    @PreAuthorize("@ss.hasPermi('bank:chapter:export')")
    @Log(title = "题库大章", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<QuestionBankChapterVo> export(QuestionBankChapterQueryBo bo) {
        List<QuestionBankChapterVo> list = iQuestionBankChapterService.queryList(bo);
        ExcelUtil<QuestionBankChapterVo> util = new ExcelUtil<QuestionBankChapterVo>(QuestionBankChapterVo.class);
        return util.exportExcel(list, "题库大章");
    }*/

    /**
     * 获取题库大章详细信息
     */
    @ApiOperation("获取题库大章详细信息")
    @PreAuthorize("@ss.hasPermi('bank:chapter:query')")
    @GetMapping("/{bankChapterId}")
    public AjaxResult<QuestionBankChapterVo> getInfo(@PathVariable("bankChapterId" ) Long bankChapterId) {
        return AjaxResult.success(iQuestionBankChapterService.queryById(bankChapterId));
    }

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

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

    /**
     * 删除题库大章
     */
    @ApiOperation("删除题库大章")
    @PreAuthorize("@ss.hasPermi('bank:chapter:remove')")
    @Log(title = "题库大章" , businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult<Void> remove(@RequestBody Long[] bankChapterIds) {
        return toAjax(iQuestionBankChapterService.deleteWithValidByIds(Arrays.asList(bankChapterIds), true) ? 1 : 0);
    }
}
