package com.game.business.controller;

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

import com.game.common.core.domain.R;
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.game.common.annotation.Log;
import com.game.common.core.controller.BaseController;
import com.game.common.core.domain.AjaxResult;
import com.game.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.game.business.domain.AppChargeChannel;
import com.game.business.service.IAppChargeChannelService;
import com.game.common.utils.poi.ExcelUtil;
import com.game.common.core.page.TableDataInfo;

/**
 * 充值渠道Controller
 * 
 * @author game
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/business/channel")
@Api(value = "AppChargeChannelController", description = "充值渠道接口", tags = {"充值渠道"})
public class AppChargeChannelController extends BaseController
{
    @Autowired
    private IAppChargeChannelService appChargeChannelService;

    /**
     * 查询充值渠道列表
     */
    @PreAuthorize("@ss.hasPermi('business:channel:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询充值渠道列表", notes = "获取充值渠道列表")
    public TableDataInfo<AppChargeChannel> list(AppChargeChannel appChargeChannel)
    {
        startPage();
        List<AppChargeChannel> list = appChargeChannelService.selectAppChargeChannelList(appChargeChannel);
        return getDataTable(list);
    }

    /**
     * 查询充值渠道列表
     */
    @GetMapping("/allList")
    @ApiOperation(value = "查询充值渠道列表", notes = "获取充值渠道列表")
    public R<List<AppChargeChannel>> allList(AppChargeChannel appChargeChannel)
    {
        appChargeChannel.setStatus(1L);
        List<AppChargeChannel> list = appChargeChannelService.selectAppChargeChannelList(appChargeChannel);
        if(null == list){
            list = new ArrayList<>();
        }
        AppChargeChannel chargeChannel = new AppChargeChannel();
        chargeChannel.setId(-1L);
        chargeChannel.setName("其他");
        chargeChannel.setRate(0.00);
        list.add(chargeChannel);
        return R.ok(list);
    }

    /**
     * 导出充值渠道列表
     */
    @PreAuthorize("@ss.hasPermi('business:channel:export')")
    @Log(title = "充值渠道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出充值渠道列表", notes = "导出充值渠道列表")
    public void export(HttpServletResponse response, AppChargeChannel appChargeChannel)
    {
        List<AppChargeChannel> list = appChargeChannelService.selectAppChargeChannelList(appChargeChannel);
        ExcelUtil<AppChargeChannel> util = new ExcelUtil<AppChargeChannel>(AppChargeChannel.class);
        util.exportExcel(response, list, "充值渠道数据");
    }

    /**
     * 获取充值渠道详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:channel:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取充值渠道详细信息", notes = "获取充值渠道详细信息")
    public R<AppChargeChannel> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(appChargeChannelService.selectAppChargeChannelById(id));
    }

    /**
     * 新增充值渠道
     */
    @PreAuthorize("@ss.hasPermi('business:channel:add')")
    @Log(title = "充值渠道", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增充值渠道", notes = "新增充值渠道")
    @PostMapping
    public R add(@RequestBody AppChargeChannel appChargeChannel)
    {
        return R.ok(appChargeChannelService.insertAppChargeChannel(appChargeChannel));
    }

    /**
     * 修改充值渠道
     */
    @PreAuthorize("@ss.hasPermi('business:channel:edit')")
    @Log(title = "充值渠道", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改充值渠道", notes = "修改充值渠道")
    @PutMapping
    public R edit(@RequestBody AppChargeChannel appChargeChannel)
    {
        return R.ok(appChargeChannelService.updateAppChargeChannel(appChargeChannel));
    }

    /**
     * 删除充值渠道
     */
    @PreAuthorize("@ss.hasPermi('business:channel:remove')")
    @Log(title = "充值渠道", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除充值渠道", notes = "删除充值渠道")
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return R.ok(appChargeChannelService.deleteAppChargeChannelByIds(ids));
    }
}
