package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.EpsServerRevenueConfig;
import com.ruoyi.system.service.IEpsServerRevenueConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 服务器收益方式配置Controller
 * 
 * @author gyt
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/revenueConfig")
public class EpsServerRevenueConfigController extends BaseController
{
    @Autowired
    private IEpsServerRevenueConfigService epsServerRevenueConfigService;

    /**
     * 查询服务器收益方式配置列表
     */
    @RequiresPermissions("system:config:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody EpsServerRevenueConfig epsServerRevenueConfig)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(epsServerRevenueConfig.getPageNum());
        pageDomain.setPageSize(epsServerRevenueConfig.getPageSize());
        startPage(pageDomain);
        List<EpsServerRevenueConfig> list = epsServerRevenueConfigService.selectEpsServerRevenueConfigList(epsServerRevenueConfig);
        return getDataTable(list);
    }

    /**
     * 导出服务器收益方式配置列表
     */
    @RequiresPermissions("system:config:export")
    @Log(title = "服务器收益方式配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody EpsServerRevenueConfig epsServerRevenueConfig)
    {
        List<EpsServerRevenueConfig> list = epsServerRevenueConfigService.selectEpsServerRevenueConfigList(epsServerRevenueConfig);
        ExcelUtil<EpsServerRevenueConfig> util = new ExcelUtil<EpsServerRevenueConfig>(EpsServerRevenueConfig.class);
        util.showColumn(epsServerRevenueConfig.getProperties());
        util.exportExcel(response, list, "服务器收益方式配置数据");
    }


    /**
     * 修改服务器收益方式配置
     */
    @RequiresPermissions("system:config:edit")
    @Log(title = "服务器收益方式配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpsServerRevenueConfig epsServerRevenueConfig)
    {
        return toAjax(epsServerRevenueConfigService.updateEpsServerRevenueConfig(epsServerRevenueConfig));
    }

    /**
     * 流量相关数据入库
     */
    @InnerAuth
    @PostMapping("/autoSaveServiceTrafficData")
    public R<String> autoSaveServiceTrafficData(@RequestBody EpsServerRevenueConfig epsServerRevenueConfig)
    {
        return epsServerRevenueConfigService.autoSaveServiceTrafficData(epsServerRevenueConfig);
    }

}
