package com.zhongzheng.controller.exam;

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

import cn.hutool.http.HttpStatus;
import com.github.pagehelper.PageInfo;
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.modules.exam.vo.ExamKnowledgeVo;
import com.zhongzheng.modules.exam.bo.ExamKnowledgeQueryBo;
import com.zhongzheng.modules.exam.bo.ExamKnowledgeAddBo;
import com.zhongzheng.modules.exam.bo.ExamKnowledgeEditBo;
import com.zhongzheng.modules.exam.service.IExamKnowledgeService;
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 ruoyi
 * @date 2021-10-18
 */
@Api(value = "知识点控制器", tags = {"知识点管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/exam/knowledge")
public class ExamKnowledgeController extends BaseController {

    private final IExamKnowledgeService iExamKnowledgeService;

    /**
     * 查询知识点列表
     */
    @ApiOperation("查询知识点列表")
    @PreAuthorize("@ss.hasPermi('exam:knowledge:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamKnowledgeVo> list(ExamKnowledgeQueryBo bo) {
        startPage();
        List<ExamKnowledgeVo> list = iExamKnowledgeService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出知识点列表
     */
/*    @ApiOperation("导出知识点列表")
    @PreAuthorize("@ss.hasPermi('exam:knowledge:export')")
    @Log(title = "知识点", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ExamKnowledgeVo> export(ExamKnowledgeQueryBo bo) {
        List<ExamKnowledgeVo> list = iExamKnowledgeService.queryList(bo);
        ExcelUtil<ExamKnowledgeVo> util = new ExcelUtil<ExamKnowledgeVo>(ExamKnowledgeVo.class);
        return util.exportExcel(list, "知识点");
    }*/

    /**
     * 获取知识点详细信息
     */
    @ApiOperation("获取知识点详细信息")
    @PreAuthorize("@ss.hasPermi('exam:knowledge:query')")
    @GetMapping("/{knowledgeId}")
    public AjaxResult<ExamKnowledgeVo> getInfo(@PathVariable("knowledgeId" ) Long knowledgeId) {
        return AjaxResult.success(iExamKnowledgeService.queryById(knowledgeId));
    }

    /**
     * 新增知识点
     */
    @ApiOperation("新增知识点")
    @PreAuthorize("@ss.hasPermi('exam:knowledge:add')")
    @Log(title = "知识点", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody ExamKnowledgeAddBo bo) {
        return toAjax(iExamKnowledgeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改知识点
     */
    @ApiOperation("修改知识点")
    @PreAuthorize("@ss.hasPermi('exam:knowledge:edit')")
    @Log(title = "知识点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody ExamKnowledgeEditBo bo) {
        return toAjax(iExamKnowledgeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除知识点
     */
/*    @ApiOperation("删除知识点")
    @PreAuthorize("@ss.hasPermi('exam:knowledge:remove')")
    @Log(title = "知识点" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{knowledgeIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] knowledgeIds) {
        return toAjax(iExamKnowledgeService.deleteWithValidByIds(Arrays.asList(knowledgeIds), true) ? 1 : 0);
    }*/
}
