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.SecurityUtils;
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.ElUserExam;
import com.zd.exam.service.IElUserExamService;

/**
 * 考试记录Controller
 *
 * @author liubo
 * @date 2021-09-01
 */
@RestController
@RequestMapping("/user/exam")
@Api(tags = {"考试记录"})
public class ElUserExamController extends BaseController {
    @Autowired
    private IElUserExamService elUserExamService;

    /**
     * 查询考试记录列表
     */
//    @PreAuthorize(hasPermi = "exam:user_exam:list")
    @ApiOperation(value = "查询考试记录列表")
    @GetMapping("/list")
    public TableDataInfo list(ElUserExam elUserExam) {
        startPage();
        List<ElUserExam> list = elUserExamService.selectElUserExamList(elUserExam);
        return getDataTable(list);
    }

    /**
     * 查询登录用户考试记录列表
     */
    @ApiOperation(value = "查询登录用户考试记录列表")
    @GetMapping("/list/my")
    public TableDataInfo myList(ElUserExam elUserExam) {
        elUserExam.setJoinUserId(SecurityUtils.getUserId());
        startPage();
        List<ElUserExam> list = elUserExamService.selectElUserExamList(elUserExam);
        return getDataTable(list);
    }

    /**
     * 导出考试记录列表
     */
//    @PreAuthorize(hasPermi = "exam:user_exam:export")
//    @Log(title = "考试记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ElUserExam elUserExam) throws IOException {
//        List<ElUserExam> list = elUserExamService.selectElUserExamList(elUserExam);
//        ExcelUtil<ElUserExam> util = new ExcelUtil<ElUserExam>(ElUserExam.class);
//        util.exportExcel(response, list, "考试记录数据");
//    }

    /**
     * 获取考试记录详细信息
     */
//    @PreAuthorize(hasPermi = "exam:user_exam:query")
    @ApiOperation(value = "获取考试记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(elUserExamService.selectElUserExamById(id));
    }

    /**
     * 新增考试记录
     */
//    @PreAuthorize(hasPermi = "exam:user_exam:add")
//    @Log(title = "考试记录", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody ElUserExam elUserExam) {
//        return toAjax(elUserExamService.insertElUserExam(elUserExam));
//    }

    /**
     * 修改考试记录
     */
//    @PreAuthorize(hasPermi = "exam:user_exam:edit")
//    @Log(title = "考试记录", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody ElUserExam elUserExam) {
//        return toAjax(elUserExamService.updateElUserExam(elUserExam));
//    }

    /**
     * 删除考试记录 "exam:user_exam:remove"
     */
    @ApiOperation(value = "删除考试记录 ")
    @PreAuthorize(hasPermi = PerPrefix.EXAM_USER_EXAM+ PerFun.REMOVE)
    @Log(title = "考试记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(elUserExamService.deleteElUserExamByIds(ids));
    }
}
