package com.zhongzheng.controller.bank;

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

import com.zhongzheng.modules.bank.bo.QuestionBankSectionAddBo;
import com.zhongzheng.modules.bank.bo.QuestionBankSectionEditBo;
import com.zhongzheng.modules.bank.bo.QuestionBankSectionQueryBo;
import com.zhongzheng.modules.bank.service.IQuestionBankSectionService;
import com.zhongzheng.modules.bank.vo.QuestionBankSectionVo;
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/section")
public class QuestionBankSectionController extends BaseController {

    private final IQuestionBankSectionService iQuestionBankSectionService;

    /**
     * 查询题库小节列表
     */
    @ApiOperation("查询题库小节列表")
    @PreAuthorize("@ss.hasPermi('bank:section:list')")
    @GetMapping("/list")
    public TableDataInfo<QuestionBankSectionVo> list(QuestionBankSectionQueryBo bo) {
        startPage();
        List<QuestionBankSectionVo> list = iQuestionBankSectionService.selectBankSectionList(bo);
        return getDataTable(list);
    }

    /**
     * 导出题库小节列表
     */
    /*@ApiOperation("导出题库小节列表")
    @PreAuthorize("@ss.hasPermi('system:section:export')")
    @Log(title = "题库小节", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<QuestionBankSectionVo> export(QuestionBankSectionQueryBo bo) {
        List<QuestionBankSectionVo> list = iQuestionBankSectionService.queryList(bo);
        ExcelUtil<QuestionBankSectionVo> util = new ExcelUtil<QuestionBankSectionVo>(QuestionBankSectionVo.class);
        return util.exportExcel(list, "题库小节");
    }*/

    /**
     * 获取题库小节详细信息
     */
    @ApiOperation("获取题库小节详细信息")
    @PreAuthorize("@ss.hasPermi('bank:section:query')")
    @GetMapping("/{bankSectionId}")
    public AjaxResult<QuestionBankSectionVo> getInfo(@PathVariable("bankSectionId" ) Long bankSectionId) {
        return AjaxResult.success(iQuestionBankSectionService.queryById(bankSectionId));
    }

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

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

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