package com.zhongzheng.controller.exam;

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

import com.zhongzheng.modules.exam.bo.ExamNoteAddBo;
import com.zhongzheng.modules.exam.bo.ExamNoteEditBo;
import com.zhongzheng.modules.exam.bo.ExamNoteQueryBo;
import com.zhongzheng.modules.exam.service.IExamNoteService;
import com.zhongzheng.modules.exam.vo.ExamNoteVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 考试重点Controller
 *
 * @author hjl
 * @date 2021-05-21
 */
@Api(value = "考试重点控制器", tags = {"考试重点管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/exam/note")
public class ExamNoteController extends BaseController {

    private final IExamNoteService iExamNoteService;

    /**
     * 查询考试重点列表
     */
    @ApiOperation("查询考试重点列表")
    @PreAuthorize("@ss.hasPermi('exam:note:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamNoteVo> list(ExamNoteQueryBo bo) {
        startPage();
        List<ExamNoteVo> list = iExamNoteService.selectExamNoteList(bo);
        return getDataTable(list);
    }

    /**
     * 导出考试重点列表
     */
    /*@ApiOperation("导出考试重点列表")
    @PreAuthorize("@ss.hasPermi('exam:note:export')")
    @Log(title = "考试重点", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ExamNoteVo> export(ExamNoteQueryBo bo) {
        List<ExamNoteVo> list = iExamNoteService.queryList(bo);
        ExcelUtil<ExamNoteVo> util = new ExcelUtil<ExamNoteVo>(ExamNoteVo.class);
        return util.exportExcel(list, "考试重点");
    }*/

    /**
     * 获取考试重点详细信息
     */
    @ApiOperation("获取考试重点详细信息")
    @PreAuthorize("@ss.hasPermi('exam:note:query')")
    @GetMapping("/{fileId}")
    public AjaxResult<ExamNoteVo> getInfo(@PathVariable("fileId" ) Long fileId) {
        return AjaxResult.success(iExamNoteService.queryById(fileId));
    }

    /**
     * 新增考试重点
     */
    @ApiOperation("新增考试重点")
    @PreAuthorize("@ss.hasPermi('exam:note:add')")
    @Log(title = "考试重点", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ExamNoteAddBo bo) {
        return toAjax(iExamNoteService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改考试重点
     */
    @ApiOperation("修改考试重点")
    @PreAuthorize("@ss.hasPermi('exam:note:edit')")
    @Log(title = "考试重点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@Validated @RequestBody ExamNoteEditBo bo) {
        return toAjax(iExamNoteService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除考试重点
     */
    @ApiOperation("删除考试重点")
    @PreAuthorize("@ss.hasPermi('exam:note:remove')")
    @Log(title = "考试重点" , businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult<Void> remove(@RequestBody Long[] fileIds) {
        return toAjax(iExamNoteService.deleteWithValidByIds(Arrays.asList(fileIds), true) ? 1 : 0);
    }
}
