package com.zd.airbottle.controller;

import com.zd.airbottle.domain.QpSupplierSyntheticalAudit;
import com.zd.airbottle.service.IQpSupplierSyntheticalAuditService;
import com.zd.airbottle.domain.vo.QpSupplierSyntheticalAuditVo;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 供应商综合审核Controller
 *
 * @author zd
 * @date 2022-05-10
 */
@RestController
@Api(tags = "【供应商综合审核】")
@RequestMapping("/supplierSyntheticalAudit")
public class QpSupplierSyntheticalAuditController extends BaseController<QpSupplierSyntheticalAudit> {
    @Autowired
    private IQpSupplierSyntheticalAuditService qpSupplierSyntheticalAuditService;

    /**
     * 查询供应商综合审核列表
     */
    @PreAuthorize(hasPermi = "airbottle:supplier:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询供应商综合审核列表", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_AUDIT + PerFun.LIST)
    public TableDataInfo<QpSupplierSyntheticalAuditVo> list(QpSupplierSyntheticalAudit qpSupplierSyntheticalAudit) {
        startPage();
        List<QpSupplierSyntheticalAudit> list = qpSupplierSyntheticalAuditService.selectQpSupplierSyntheticalAuditList(qpSupplierSyntheticalAudit);
        TableDataInfo<QpSupplierSyntheticalAudit> dataTable = getDataTable(list);
        List<QpSupplierSyntheticalAuditVo> listVo = qpSupplierSyntheticalAuditService.getListVo(list, qpSupplierSyntheticalAudit.getAuditType());
        TableDataInfo<QpSupplierSyntheticalAuditVo> dataInfo = new TableDataInfo<>();
        BeanUtils.copyProperties(dataTable, dataInfo);
        dataInfo.setRows(listVo);
        return dataInfo;
    }

    /**
     * 根据供应商ID管理端获取供应商综合审核详细信息
     */
    @ApiOperation(value = "管理端获取供应商综合审核详细信息", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_AUDIT + PerFun.QUERY)
    @PreAuthorize(hasPermi = "airbottle:supplier:query")
    @GetMapping(value = "/supplier/{syntheticId}")
    public ResultData<List<QpSupplierSyntheticalAuditVo>> getAuditInfo(@PathVariable("syntheticId") Long syntheticId) {
        return ResultData.success(qpSupplierSyntheticalAuditService.getAuditInfo(syntheticId));
    }

    /**
     * 新增供应商综合审核
     */
    @ApiOperation(value = "新增供应商综合审核", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_AUDIT + PerFun.ADD)
    @PreAuthorize(hasPermi = "airbottle:supplier:add")
    @Log(title = "供应商综合审核", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public ResultData<Boolean> add(@RequestBody QpSupplierSyntheticalAudit qpSupplierSyntheticalAudit) {
        return ResultData.result(qpSupplierSyntheticalAuditService.insertQpSupplierSyntheticalAudit(qpSupplierSyntheticalAudit));
    }

    /**
     * 修改供应商综合审核
     */
    @ApiOperation(value = "修改供应商综合审核", notes = "权限字符：" + PerPrefix.MODULE_AIRBOTTLE + PerPrefix.BUSINESS_SUPPLIER_AUDIT + PerFun.EDIT)
    @PreAuthorize(hasPermi = "airbottle:audit:edit")
    @Log(title = "供应商综合审核", businessType = BusinessType.UPDATE)
    @PutMapping("edit")
    public ResultData<Boolean> edit(@RequestBody QpSupplierSyntheticalAudit qpSupplierSyntheticalAudit) {
        return ResultData.result(qpSupplierSyntheticalAuditService.updateQpSupplierSyntheticalAudit(qpSupplierSyntheticalAudit));
    }

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