package com.ruoyi.web.controller.ss;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.ss.channel.domain.ChannelQuery;
import com.ruoyi.ss.channel.domain.ChannelVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.channel.domain.Channel;
import com.ruoyi.ss.channel.service.ChannelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

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

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

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

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

    /**
     * 修改充值渠道
     */
    @PreAuthorize("@ss.hasPermi('system:channel:edit')")
    @Log(title = "充值渠道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) Channel form)
    {
        Channel channel = new Channel();
        channel.setChannelId(form.getChannelId());
        channel.setEnabled(form.getEnabled());
        channel.setServiceRate(form.getServiceRate());
        channel.setCostRate(form.getCostRate());
        channel.setServiceType(form.getServiceType());
        channel.setPicture(form.getPicture());
        return toAjax(smChannelService.updateSmChannel(channel));
    }

}
