package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.channel.domain.Channel;
import com.ruoyi.bst.channel.domain.ChannelQuery;
import com.ruoyi.bst.channel.domain.ChannelVO;
import com.ruoyi.bst.channel.domain.vo.ChannelNameVO;
import com.ruoyi.bst.channel.service.ChannelService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.ValidGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LogBizType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 充值渠道Controller
 *
 * @author ruoyi
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/bst/channel")
public class ChannelController extends BaseController
{
    @Autowired
    private ChannelService channelService;

    /**
     * 查询充值渠道列表
     */
    @PreAuthorize("@ss.hasPermi('bst:channel:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelQuery smChannel)
    {
        startPage();
        List<ChannelVO> list = channelService.selectChannelList(smChannel);
        return getDataTable(list);
    }

    /**
     * 查询全部充值渠道列表
     */
    @PreAuthorize("@ss.hasPermi('bst:channel:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll()
    {
        List<ChannelNameVO> list = channelService.selectAllChannelNameList();
        return success(list);
    }

    /**
     * 查询充值渠道列表
     */
    @PreAuthorize("@ss.hasPermi('bst:channel:listByIds')")
    @PostMapping("/listByIds")
    public AjaxResult listByIds(@RequestBody List<Long> ids)
    {
        List<ChannelVO> list = channelService.selectByIds(ids);
        return success(list);
    }

    /**
     * 导出充值渠道列表
     */
    @PreAuthorize("@ss.hasPermi('bst:channel:export')")
    @Log(title = "充值渠道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChannelQuery query)
    {
        List<ChannelVO> list = channelService.selectChannelList(query);
        ExcelUtil<ChannelVO> util = new ExcelUtil<ChannelVO>(ChannelVO.class);
        util.exportExcel(response, list, "充值渠道数据");
    }

    /**
     * 获取充值渠道详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:channel:query')")
    @GetMapping(value = "/{channelId}")
    public AjaxResult getInfo(@PathVariable("channelId") Long channelId)
    {
        return success(channelService.selectChannelByChannelId(channelId));
    }

    /**
     * 修改充值渠道
     */
    @PreAuthorize("@ss.hasPermi('bst:channel:edit')")
    @Log(title = "修改支付渠道", businessType = BusinessType.UPDATE, bizIdName = "arg0", bizType = LogBizType.CHANNEL)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) Channel channel)
    {
        return toAjax(channelService.updateChannel(channel));
    }

    /**
     * 新增充值渠道
     */
    @PreAuthorize("@ss.hasPermi('bst:channel:add')")
    @Log(title = "新增支付渠道", businessType = BusinessType.INSERT, bizIdName = "arg0", bizType = LogBizType.CHANNEL)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Channel channel)
    {
        return toAjax(channelService.insertChannel(channel));
    }

    /**
     * 删除充值渠道
     */
    @PreAuthorize("@ss.hasPermi('bst:channel:delete')")
    @Log(title = "删除支付渠道", businessType = BusinessType.DELETE, bizIdName = "arg0", bizType = LogBizType.CHANNEL)
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable List<Long> ids) {
        return toAjax(channelService.logicDel(ids));
    }

}
