package com.zd.airbottle.controller;

import com.zd.airbottle.domain.QpSupplierCredentials;
import com.zd.airbottle.service.IQpSupplierCredentialsService;
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.ResultData;
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.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 供应商证件Controller
 *
 * @author zd
 * @date 2022-05-10
 */
@RestController
@Api(tags = "【供应商证件】")
@RequestMapping("/supplierCredentials")
public class QpSupplierCredentialsController extends BaseController<QpSupplierCredentials> {
    @Autowired
    private IQpSupplierCredentialsService qpSupplierCredentialsService;

    /**
     * 查询供应商证件列表
     */
    @PreAuthorize(hasPermi = "airbottle:supplier:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询供应商证件列表", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_CREDENTIALS + PerFun.LIST)
    public TableDataInfo<QpSupplierCredentials> list(QpSupplierCredentials qpSupplierCredentials) {
        startPage();
        List<QpSupplierCredentials> list = qpSupplierCredentialsService.selectQpSupplierCredentialsList(qpSupplierCredentials);
        return getDataTable(list);
    }

    /**
     * 导出供应商证件列表
     */
    @ApiOperation(value = "导出供应商证件列表", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_CREDENTIALS + PerFun.EXPORT)
    @PreAuthorize(hasPermi = "airbottle:supplier:export")
    @Log(title = "供应商证件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QpSupplierCredentials qpSupplierCredentials) throws IOException {
        List<QpSupplierCredentials> list = qpSupplierCredentialsService.selectQpSupplierCredentialsList(qpSupplierCredentials);
        ExcelUtil<QpSupplierCredentials> util = new ExcelUtil<>(QpSupplierCredentials.class);
        util.exportExcel(response, list, "供应商证件数据");
    }

    /**
     * 获取供应商证件详细信息
     */
    @ApiOperation(value = "获取供应商证件详细信息", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_CREDENTIALS + PerFun.QUERY)
    @PreAuthorize(hasPermi = "airbottle:supplier:query")
    @GetMapping(value = "/{id}")
    public ResultData<QpSupplierCredentials> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(qpSupplierCredentialsService.selectQpSupplierCredentialsById(id));
    }

    /**
     * 新增供应商证件
     */
    @ApiOperation(value = "新增供应商证件", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_CREDENTIALS + PerFun.ADD)
    @PreAuthorize(hasPermi = "airbottle:supplier:add")
    @Log(title = "供应商证件", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public ResultData<Boolean> add(@RequestBody QpSupplierCredentials qpSupplierCredentials) {
        return ResultData.result(qpSupplierCredentialsService.insertQpSupplierCredentials(qpSupplierCredentials));
    }

    /**
     * 修改供应商证件
     */
    @ApiOperation(value = "修改供应商证件", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_CREDENTIALS + PerFun.EDIT)
    @PreAuthorize(hasPermi = "airbottle:supplier:edit")
    @Log(title = "供应商证件", businessType = BusinessType.UPDATE)
    @PutMapping("edit")
    public ResultData<Boolean> edit(@RequestBody QpSupplierCredentials qpSupplierCredentials) {
        return ResultData.result(qpSupplierCredentialsService.updateQpSupplierCredentials(qpSupplierCredentials));
    }

    /**
     * 删除供应商证件
     */
    @ApiOperation(value = "删除供应商证件", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_CREDENTIALS + PerFun.REMOVE)
    @PreAuthorize(hasPermi = "airbottle:supplier:remove")
    @Log(title = "供应商证件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData<Boolean> remove(@PathVariable Long[] ids) {
        return ResultData.result(qpSupplierCredentialsService.deleteQpSupplierCredentialsByIds(ids));
    }
}
