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.PaySourceVo;
import com.zhongzheng.modules.pay.bo.PaySourceQueryBo;
import com.zhongzheng.modules.pay.bo.PaySourceAddBo;
import com.zhongzheng.modules.pay.bo.PaySourceEditBo;
import com.zhongzheng.modules.pay.service.IPaySourceService;
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/source")
public class PaySourceController extends BaseController {

    private final IPaySourceService iPaySourceService;

    /**
     * 查询渠道来源列表
     */
    @ApiOperation("查询渠道来源列表")
    @PreAuthorize("@ss.hasPermi('pay:source:list')")
    @GetMapping("/list")
    public TableDataInfo<PaySourceVo> list(PaySourceQueryBo bo) {
        startPage();
        List<PaySourceVo> list = iPaySourceService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出渠道来源列表
     */
/*    @ApiOperation("导出渠道来源列表")
    @PreAuthorize("@ss.hasPermi('pay:source:export')")
    @Log(title = "渠道来源", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<PaySourceVo> export(PaySourceQueryBo bo) {
        List<PaySourceVo> list = iPaySourceService.queryList(bo);
        ExcelUtil<PaySourceVo> util = new ExcelUtil<PaySourceVo>(PaySourceVo.class);
        return util.exportExcel(list, "渠道来源");
    }*/

    /**
     * 获取渠道来源详细信息
     */
    @ApiOperation("获取渠道来源详细信息")
    @PreAuthorize("@ss.hasPermi('pay:source:query')")
    @GetMapping("/{sourceId}")
    public AjaxResult<PaySourceVo> getInfo(@PathVariable("sourceId" ) Long sourceId) {
        return AjaxResult.success(iPaySourceService.queryById(sourceId));
    }

    /**
     * 新增渠道来源
     */
    @ApiOperation("新增渠道来源")
    @PreAuthorize("@ss.hasPermi('pay:source:add')")
    @Log(title = "渠道来源", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody PaySourceAddBo bo) {
        return toAjax(iPaySourceService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改渠道来源
     */
    @ApiOperation("修改渠道来源")
    @PreAuthorize("@ss.hasPermi('pay:source:edit')")
    @Log(title = "渠道来源", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody PaySourceEditBo bo) {
        return toAjax(iPaySourceService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除渠道来源
     */
/*    @ApiOperation("删除渠道来源")
    @PreAuthorize("@ss.hasPermi('pay:source:remove')")
    @Log(title = "渠道来源" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{sourceIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] sourceIds) {
        return toAjax(iPaySourceService.deleteWithValidByIds(Arrays.asList(sourceIds), true) ? 1 : 0);
    }*/
}
