package com.zd.exam.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.zd.exam.domain.ElUserBook;
import com.zd.exam.service.IElUserBookService;

/**
 * 错题本Controller
 *
 * @author zd
 * @date 2021-09-01
 */
@RestController
@RequestMapping("/book")
@Api(tags = {"错题本"})
public class ElUserBookController extends BaseController {
    @Autowired
    private IElUserBookService elUserBookService;

    /**
     * 查询错题本列表 "exam:book:list"
     */
    @ApiOperation(value = "查询错题本列表 ",notes="权限字符："+PerPrefix.EXAM_BOOK+ PerFun.LIST)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_BOOK+ PerFun.LIST)
    @GetMapping("/list")
    public TableDataInfo list(ElUserBook elUserBook) {
        startPage();
        List<ElUserBook> list = elUserBookService.selectElUserBookList(elUserBook);
        return getDataTable(list);
    }

    /**
     * 导出错题本列表 "exam:book:export"
     */
    @ApiOperation(value = "导出错题本列表 ",notes="权限字符："+PerPrefix.EXAM_BOOK+ PerFun.EXPORT)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_BOOK+ PerFun.EXPORT)
    @Log(title = "错题本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElUserBook elUserBook) throws IOException {
        List<ElUserBook> list = elUserBookService.selectElUserBookList(elUserBook);
        ExcelUtil<ElUserBook> util = new ExcelUtil<ElUserBook>(ElUserBook.class);
        util.exportExcel(response, list, "错题本数据");
    }

    /**
     * 获取错题本详细信息 "exam:book:query"
     */
    @ApiOperation(value = "获取错题本详细信息 ",notes="权限字符："+PerPrefix.EXAM_BOOK+ PerFun.QUERY)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_BOOK+ PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(elUserBookService.selectElUserBookById(id));
    }

    /**
     * 新增错题本 "exam:book:add"
     */
    @ApiOperation(value = "新增错题本 ",notes="权限字符："+PerPrefix.EXAM_BOOK+ PerFun.ADD)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_BOOK+ PerFun.ADD)
    @Log(title = "错题本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElUserBook elUserBook) {
        return toAjax(elUserBookService.insertElUserBook(elUserBook));
    }

    /**
     * 修改错题本 "exam:book:edit"
     */
    @ApiOperation(value = "修改错题本  ",notes="权限字符："+PerPrefix.EXAM_BOOK+ PerFun.EDIT)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_BOOK+ PerFun.EDIT)
    @Log(title = "错题本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElUserBook elUserBook) {
        return toAjax(elUserBookService.updateElUserBook(elUserBook));
    }

    /**
     * 删除错题本 "exam:book:remove"
     */
    @ApiOperation(value = "删除错题本 ",notes="权限字符："+PerPrefix.EXAM_BOOK+ PerFun.REMOVE)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_BOOK+ PerFun.REMOVE)
    @Log(title = "错题本", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(elUserBookService.deleteElUserBookByIds(ids));
    }
}
