package com.zhongzheng.controller.base;

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

import com.zhongzheng.modules.base.bo.CertificateAddBo;
import com.zhongzheng.modules.base.bo.CertificateEditBo;
import com.zhongzheng.modules.base.bo.CertificateQueryBo;
import com.zhongzheng.modules.base.service.ICertificateService;
import com.zhongzheng.modules.base.vo.CertificateVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
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.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.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 证书Controller
 *
 * @author ruoyi
 * @date 2021-10-08
 */
@Api(value = "证书控制器", tags = {"证书管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/base/certificate")
public class CertificateController extends BaseController {

    private final ICertificateService iCertificateService;

    /**
     * 查询证书列表
     */
    @ApiOperation("查询证书列表")
    @PreAuthorize("@ss.hasPermi('system:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo<CertificateVo> list(CertificateQueryBo bo) {
        startPage();
        List<CertificateVo> list = iCertificateService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出证书列表
     */
   /* @ApiOperation("导出证书列表")
    @PreAuthorize("@ss.hasPermi('system:certificate:export')")
    @Log(title = "证书", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CertificateVo> export(CertificateQueryBo bo) {
        List<CertificateVo> list = iCertificateService.queryList(bo);
        ExcelUtil<CertificateVo> util = new ExcelUtil<CertificateVo>(CertificateVo.class);
        return util.exportExcel(list, "证书");
    }*/

    /**
     * 获取证书详细信息
     */
    @ApiOperation("获取证书详细信息")
    @PreAuthorize("@ss.hasPermi('system:certificate:query')")
    @GetMapping("/{id}")
    public AjaxResult<CertificateVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCertificateService.queryById(id));
    }

    /**
     * 新增证书
     */
    @ApiOperation("新增证书")
    @PreAuthorize("@ss.hasPermi('system:certificate:add')")
    @Log(title = "证书", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CertificateAddBo bo) {
        return toAjax(iCertificateService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改证书
     */
    @ApiOperation("修改证书")
    @PreAuthorize("@ss.hasPermi('system:certificate:edit')")
    @Log(title = "证书", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody CertificateEditBo bo) {
        return toAjax(iCertificateService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除证书
     */
   /* @ApiOperation("删除证书")
    @PreAuthorize("@ss.hasPermi('system:certificate:remove')")
    @Log(title = "证书" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iCertificateService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }*/
}
