package com.zd.exam.controller;

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 com.zd.exam.domain.ElExamClassify;
import com.zd.exam.service.IElExamClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 题目类型Controller
 *
 * @author liubo
 * @date 2021-12-09
 */
@RestController
@Api(tags = "【题目类型】")
@RequestMapping("/el_classify")
public class ElExamClassifyController extends BaseController {
    @Autowired
    private IElExamClassifyService elExamClassifyService;

    /**
     * 查询题目类型列表 "exam:el_classify:list"
     */
    @PreAuthorize(hasPermi = PerPrefix.EXAM_EL_CLASSIFY+ PerFun.LIST )
    @GetMapping("/list")
    @ApiOperation(value = "查询题目类型列表",notes="权限字符："+PerPrefix.EXAM_EL_CLASSIFY+ PerFun.LIST)
    public TableDataInfo<ElExamClassify> list(ElExamClassify elExamClassify) {
        startPage();
        List<ElExamClassify> list = elExamClassifyService.selectElExamClassifyList(elExamClassify);
        return getDataTable(list);
    }

    /**
     * 查询题目类型下来框
     * @return
     */
    @PostMapping("/queryOption")
    @ApiOperation(value = "查询题目类型下来框")
    public AjaxResult queryOption(@RequestBody ElExamClassify elExamClassify) {
        List<ElExamClassify> list = elExamClassifyService.selectElExamClassifyList(elExamClassify);
        return AjaxResult.success(list);
    }

    /**
     * 导出题目类型列表  "exam:el_classify:export"
     */
    @ApiOperation(value = "导出题目类型列表",notes="权限字符："+PerPrefix.EXAM_EL_CLASSIFY+ PerFun.EXPORT)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_EL_CLASSIFY+ PerFun.EXPORT)
    @Log(title = "题目类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElExamClassify elExamClassify) throws IOException {
        List<ElExamClassify> list = elExamClassifyService.selectElExamClassifyList(elExamClassify);
        ExcelUtil<ElExamClassify> util = new ExcelUtil<ElExamClassify>(ElExamClassify.class);
        util.exportExcel(response, list, "题目类型数据");
    }

    /**
     * 获取题目类型详细信息  "exam:el_classify:query"
     */
    @ApiOperation(value = "获取题目类型详细信息",notes="权限字符："+PerPrefix.EXAM_EL_CLASSIFY+ PerFun.QUERY)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_EL_CLASSIFY+ PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(elExamClassifyService.selectElExamClassifyById(id));
    }

    /**
     * 新增题目类型  "exam:el_classify:add"
     */
    @ApiOperation(value = "新增题目类型",notes="权限字符："+PerPrefix.EXAM_EL_CLASSIFY+ PerFun.ADD)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_EL_CLASSIFY+ PerFun.ADD)
    @Log(title = "题目类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElExamClassify elExamClassify) {
        return AjaxResult.success(elExamClassifyService.insertElExamClassify(elExamClassify));
    }

    /**
     * 修改题目类型  "exam:el_classify:edit"
     */
    @ApiOperation(value = "修改题目类型",notes="权限字符："+PerPrefix.EXAM_EL_CLASSIFY+ PerFun.EDIT)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_EL_CLASSIFY+ PerFun.EDIT)
    @Log(title = "题目类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElExamClassify elExamClassify) {
        return AjaxResult.success(elExamClassifyService.updateElExamClassify(elExamClassify));
    }

    /**
     * 删除题目类型  "exam:el_classify:remove"
     */
    @ApiOperation(value = "删除题目类型",notes="权限字符："+PerPrefix.EXAM_EL_CLASSIFY+ PerFun.REMOVE)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_EL_CLASSIFY+ PerFun.REMOVE)
    @Log(title = "题目类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success(elExamClassifyService.deleteElExamClassifyByIds(ids));
    }
}
