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 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.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.exam.domain.LabCertificate;
import com.zd.exam.service.ILabCertificateService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.page.TableDataInfo;

/**
 * 证书管理Controller
 *
 * @author zd
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/certificate")
@Api(tags = {"证书管理"})
public class LabCertificateController extends BaseController {
    @Autowired
    private ILabCertificateService labCertificateService;

    /**
     * 查询证书管理列表 "exam:certificate:list"
     */
    @ApiOperation(value = "查询证书管理列表",notes="权限字符："+PerPrefix.EXAM_CERTIFICATE+ PerFun.LIST)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_CERTIFICATE+ PerFun.LIST)
    @GetMapping("/list")
    public TableDataInfo list(LabCertificate labCertificate) {
        startPage();
        List<LabCertificate> list = labCertificateService.selectLabCertificateList(labCertificate);
        return getDataTable(list);
    }

    /**
     * 查询证书下拉列表
     *
     * @return
     */
    @ApiOperation(value = "查询证书下拉列表")
    @PostMapping("/queryOption")
    public AjaxResult queryOption(LabCertificate labCertificate) {
        List<LabCertificate> list = labCertificateService.selectLabCertificateList(labCertificate);
        return AjaxResult.success(list);
    }

    /**
     * 导出证书管理列表 "exam:certificate:export"
     */
    @ApiOperation(value = "导出证书管理列表",notes="权限字符："+PerPrefix.EXAM_CERTIFICATE+ PerFun.EXPORT)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_CERTIFICATE+ PerFun.EXPORT)
    @Log(title = "证书管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabCertificate labCertificate) throws IOException {
        List<LabCertificate> list = labCertificateService.selectLabCertificateList(labCertificate);
        ExcelUtil<LabCertificate> util = new ExcelUtil<LabCertificate>(LabCertificate.class);
        util.exportExcel(response, list, "证书管理数据");
    }

    /**
     * 获取证书管理详细信息 "exam:certificate:query"
     */
    @ApiOperation(value = "获取证书管理详细信息",notes="权限字符："+PerPrefix.EXAM_CERTIFICATE+ PerFun.QUERY)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_CERTIFICATE+ PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(labCertificateService.selectLabCertificateById(id));
    }

    /**
     * 新增证书管理 "exam:certificate:add"
     */
    @ApiOperation(value = "新增证书管理 ",notes="权限字符："+PerPrefix.EXAM_CERTIFICATE+ PerFun.ADD)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_CERTIFICATE+ PerFun.ADD)
    @Log(title = "证书管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabCertificate labCertificate) {
        return toAjax(labCertificateService.insertLabCertificate(labCertificate));
    }

    /**
     * 修改证书管理 "exam:certificate:edit"
     */
    @ApiOperation(value = "修改证书管理",notes="权限字符："+PerPrefix.EXAM_CERTIFICATE+ PerFun.EDIT)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_CERTIFICATE+ PerFun.EDIT)
    @Log(title = "证书管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabCertificate labCertificate) {
        return toAjax(labCertificateService.updateLabCertificate(labCertificate));
    }

    /**
     * 删除证书管理 "exam:certificate:remove"
     */
    @ApiOperation(value = "删除证书管理",notes="权限字符："+PerPrefix.EXAM_CERTIFICATE+ PerFun.REMOVE)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_CERTIFICATE+ PerFun.REMOVE)
    @Log(title = "证书管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(labCertificateService.deleteLabCertificateByIds(ids));
    }
}
