package com.ruoyi.system.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.domain.RmResourceGroup;
import com.ruoyi.system.domain.RmResourceRegistration;
import com.ruoyi.system.service.EpsInitialTrafficDataService;
import com.ruoyi.system.service.IRmResourceGroupService;
import com.ruoyi.system.service.IRmResourceRegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资源监控API
 * 
 * @author gyt
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/resourceMonitor")
public class ResourceMonitorController extends BaseController
{
    @Autowired
    private EpsInitialTrafficDataService epsInitialTrafficDataService;
    @Autowired
    private IRmResourceGroupService rmResourceGroupService;
    @Autowired
    private IRmResourceRegistrationService rmResourceRegistrationService;

    /**
     * 获取资源分组列表
     * @return
     */
    @GetMapping("/resourceGroupList")
    public AjaxResult resourceGroupList(){
        RmResourceGroup rmResourceGroup = new RmResourceGroup();
        return success(rmResourceGroupService.selectRmResourceGroupList(rmResourceGroup));
    }

    /**
     * 服务器整体发送带宽利用率
     * @return
     */
    @GetMapping("/trafficRateByServer")
    public AjaxResult trafficRateByServer(){
        return success(epsInitialTrafficDataService.trafficRateByServer());
    }

    /**
     * 获取资源列表
     * @return
     */
    @PostMapping("/getRegisterListByGroupId")
    public TableDataInfo getRegisterListByGroupId(@RequestBody RmResourceGroup rmResourceGroup){
        // 拿到注册信息
        PageInfo<RmResourceRegistration> pageInfo = rmResourceGroupService.getRegisterList(rmResourceGroup);
        return getDataTable(pageInfo.getList(), pageInfo.getTotal());
    }
    /**
     * 获取资源列表
     * @return
     */
    @PostMapping("/getAllRegisterListByGroupId")
    public AjaxResult getAllRegisterListByGroupId(@RequestBody RmResourceGroup rmResourceGroup){
        // 拿到注册信息
        List<RmResourceRegistration> list = rmResourceGroupService.getAllRegisterList(rmResourceGroup);
        return success(list);
    }
}
