package com.gree.mall.manager.controller.contract;

import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.annotation.ZfireList;
import com.gree.mall.manager.bean.contract.CompanyCaAuthVO;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.contract.CompanyCaAuthLogic;
import com.gree.mall.manager.plus.entity.CompanyCaAuth;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import com.gree.mall.manager.zfire.util.FieldUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@Api(value = "企业CA认证API", tags ={"企业CA认证API"} )
@RequestMapping("/company/ca/auth")
public class CompanyCaAuthController {

    @Resource
    CompanyCaAuthLogic companyCaAuthLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "企业CA认证-列表")
    public ResponseHelper<IPage<CompanyCaAuthVO>> list(@RequestBody ZfireParamBean zfireParamBean) {
        IPage<CompanyCaAuthVO> list = companyCaAuthLogic.list(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<CompanyCaAuthVO>() {
        });
    }

    @PostMapping("/list/export")
    @ApiOperation(value = "企业CA认证-导出")
    public void listExport(@RequestBody ZfireParamBean zfireParamBean, HttpServletRequest request, HttpServletResponse response) throws Exception {
        //2.查询要导出的内容
        IPage<CompanyCaAuthVO> list = companyCaAuthLogic.list(zfireParamBean);
        //3.导出
        FieldUtils.exportData(list.getRecords(), zfireParamBean.getExportFields(), request, response);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "企业CA认证-详情")
    public ResponseHelper<CompanyCaAuth> detail(@RequestParam String companyCaAuthId) {
        CompanyCaAuth detail = companyCaAuthLogic.detail(companyCaAuthId);
        return ResponseHelper.success(detail);
    }

    @PostMapping("/add")
    @ApiOperation(value = "企业CA认证-添加")
    public ResponseHelper add(@RequestBody CompanyCaAuth companyCaAuth) {
        companyCaAuthLogic.add(companyCaAuth);
        return ResponseHelper.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "企业CA认证-修改")
    public ResponseHelper update(@RequestBody CompanyCaAuth companyCaAuth) {
        companyCaAuthLogic.update(companyCaAuth);
        return ResponseHelper.success();
    }

    @PostMapping("/del")
    @ApiOperation(value = "企业CA认证-删除")
    public ResponseHelper delete(@RequestParam String companyCaAuthId) {
        companyCaAuthLogic.delete(companyCaAuthId);
        return ResponseHelper.success();
    }

    @PostMapping("/get/auth")
    @ApiOperation(value = "企业CA认证-获取法大大认证")
    public ResponseHelper getAuth(@RequestParam String companyCaAuthId) throws Exception {
        String url = companyCaAuthLogic.getAuth(companyCaAuthId);
        return ResponseHelper.success(url);
    }
}
