package com.tongran.system.controller;

import com.tongran.common.core.domain.R;
import com.tongran.common.core.utils.poi.ExcelUtil;
import com.tongran.common.core.web.controller.BaseController;
import com.tongran.common.core.web.domain.AjaxResult;
import com.tongran.common.core.web.page.PageDomain;
import com.tongran.common.core.web.page.TableDataInfo;
import com.tongran.common.log.annotation.Log;
import com.tongran.common.log.enums.BusinessType;
import com.tongran.common.security.annotation.InnerAuth;
import com.tongran.common.security.annotation.RequiresPermissions;
import com.tongran.system.domain.EpsServerRevenueConfig;
import com.tongran.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 tongran
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/revenueConfig")
@RequiresPermissions("system:revenueConfig")
public class EpsServerRevenueConfigController extends BaseController
{
    @Autowired
    private IEpsServerRevenueConfigService epsServerRevenueConfigService;

    /**
     * 查询服务器收益方式配置列表
     */
    @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);
    }

    /**
     * 导出服务器收益方式配置列表
     */
    @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, "服务器收益方式配置数据");
    }


    /**
     * 修改服务器收益方式配置
     */
    @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);
    }

}
