package com.zhongzheng.controller.pay;

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

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.modules.pay.vo.PaySupplyVo;
import com.zhongzheng.modules.pay.bo.PaySupplyQueryBo;
import com.zhongzheng.modules.pay.bo.PaySupplyAddBo;
import com.zhongzheng.modules.pay.bo.PaySupplyEditBo;
import com.zhongzheng.modules.pay.service.IPaySupplyService;
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-12
 */
@Api(value = "供应方控制器", tags = {"供应方管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pay/supply")
public class PaySupplyController extends BaseController {

    private final IPaySupplyService iPaySupplyService;

    /**
     * 查询供应方列表
     */
    @ApiOperation("查询供应方列表")
    @PreAuthorize("@ss.hasPermi('pay:supply:list')")
    @GetMapping("/list")
    public TableDataInfo<PaySupplyVo> list(PaySupplyQueryBo bo) {
        startPage();
        List<PaySupplyVo> list = iPaySupplyService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出供应方列表
     */
/*    @ApiOperation("导出供应方列表")
    @PreAuthorize("@ss.hasPermi('pay:supply:export')")
    @Log(title = "供应方", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<PaySupplyVo> export(PaySupplyQueryBo bo) {
        List<PaySupplyVo> list = iPaySupplyService.queryList(bo);
        ExcelUtil<PaySupplyVo> util = new ExcelUtil<PaySupplyVo>(PaySupplyVo.class);
        return util.exportExcel(list, "供应方");
    }*/

    /**
     * 获取供应方详细信息
     */
    @ApiOperation("获取供应方详细信息")
    @PreAuthorize("@ss.hasPermi('pay:supply:query')")
    @GetMapping("/{supplyId}")
    public AjaxResult<PaySupplyVo> getInfo(@PathVariable("supplyId" ) Long supplyId) {
        return AjaxResult.success(iPaySupplyService.queryById(supplyId));
    }

    /**
     * 新增供应方
     */
    @ApiOperation("新增供应方")
    @PreAuthorize("@ss.hasPermi('pay:supply:add')")
    @Log(title = "供应方", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody PaySupplyAddBo bo) {
        return toAjax(iPaySupplyService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改供应方
     */
    @ApiOperation("修改供应方")
    @PreAuthorize("@ss.hasPermi('pay:supply:edit')")
    @Log(title = "供应方", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody PaySupplyEditBo bo) {
        return toAjax(iPaySupplyService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除供应方
     */
    /*@ApiOperation("删除供应方")
    @PreAuthorize("@ss.hasPermi('pay:supply:remove')")
    @Log(title = "供应方" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplyIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] supplyIds) {
        return toAjax(iPaySupplyService.deleteWithValidByIds(Arrays.asList(supplyIds), true) ? 1 : 0);
    }*/
}
