package com.zhongzheng.controller.bank;

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

import com.zhongzheng.modules.bank.bo.QuestionDetailAddBo;
import com.zhongzheng.modules.bank.bo.QuestionDetailEditBo;
import com.zhongzheng.modules.bank.bo.QuestionDetailQueryBo;
import com.zhongzheng.modules.bank.service.IQuestionDetailService;
import com.zhongzheng.modules.bank.vo.QuestionDetailVo;
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("/question/detail")
public class QuestionDetailController extends BaseController {

    private final IQuestionDetailService iQuestionDetailService;

    /**
     * 查询题目详情列表
     */
    @ApiOperation("查询题目详情列表")
    @PreAuthorize("@ss.hasPermi('question:detail:list')")
    @GetMapping("/list")
    public TableDataInfo<QuestionDetailVo> list(QuestionDetailQueryBo bo) {
        startPage();
        List<QuestionDetailVo> list = iQuestionDetailService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出题目详情列表
     */
    /*@ApiOperation("导出题目详情列表")
    @PreAuthorize("@ss.hasPermi('question:detail:export')")
    @Log(title = "题目详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<QuestionDetailVo> export(QuestionDetailQueryBo bo) {
        List<QuestionDetailVo> list = iQuestionDetailService.queryList(bo);
        ExcelUtil<QuestionDetailVo> util = new ExcelUtil<QuestionDetailVo>(QuestionDetailVo.class);
        return util.exportExcel(list, "题目详情");
    }*/

    /**
     * 获取题目详情详细信息
     */
    @ApiOperation("获取题目详情详细信息")
    @PreAuthorize("@ss.hasPermi('question:detail:query')")
    @GetMapping("/{questionDetailId}")
    public AjaxResult<QuestionDetailVo> getInfo(@PathVariable("questionDetailId" ) Long questionDetailId) {
        return AjaxResult.success(iQuestionDetailService.queryById(questionDetailId));
    }

    /**
     * 新增题目详情
     */
    @ApiOperation("新增题目详情")
    @PreAuthorize("@ss.hasPermi('question:detail:add')")
    @Log(title = "题目详情", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody QuestionDetailAddBo bo) {
        return toAjax(iQuestionDetailService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改题目详情
     */
    @ApiOperation("修改题目详情")
    @PreAuthorize("@ss.hasPermi('question:detail:edit')")
    @Log(title = "题目详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody QuestionDetailEditBo bo) {
        return toAjax(iQuestionDetailService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除题目详情
     */
    @ApiOperation("删除题目详情")
    @PreAuthorize("@ss.hasPermi('question:detail:remove')")
    @Log(title = "题目详情" , businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult<Void> remove(@PathVariable Long[] questionDetailIds) {
        return toAjax(iQuestionDetailService.deleteWithValidByIds(Arrays.asList(questionDetailIds), true) ? 1 : 0);
    }
}
