package com.ruoyi.rocketmq.controller;

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.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rocketmq.domain.InitialSwitchInfo;
import com.ruoyi.rocketmq.service.IInitialSwitchInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 交换机流量监控信息Controller
 * 
 * @author gyt
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/switchInfo")
public class InitialSwitchInfoController extends BaseController
{
    @Autowired
    private IInitialSwitchInfoService initialSwitchInfoService;

    /**
     * 查询交换机流量监控信息列表
     */
    @RequiresPermissions("rocketmq:switchInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(InitialSwitchInfo initialSwitchInfo)
    {
        startPage();
        List<InitialSwitchInfo> list = initialSwitchInfoService.selectInitialSwitchInfoList(initialSwitchInfo);
        return getDataTable(list);
    }

    /**
     * 导出交换机流量监控信息列表
     */
    @RequiresPermissions("rocketmq:switchInfo:export")
    @Log(title = "交换机流量监控信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialSwitchInfo initialSwitchInfo)
    {
        List<InitialSwitchInfo> list = initialSwitchInfoService.selectInitialSwitchInfoList(initialSwitchInfo);
        ExcelUtil<InitialSwitchInfo> util = new ExcelUtil<InitialSwitchInfo>(InitialSwitchInfo.class);
        util.exportExcel(response, list, "交换机流量监控信息数据");
    }

    /**
     * 获取交换机流量监控信息详细信息
     */
    @RequiresPermissions("rocketmq:switchInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialSwitchInfoService.selectInitialSwitchInfoById(id));
    }

    /**
     * 新增交换机流量监控信息
     */
    @RequiresPermissions("rocketmq:switchInfo:add")
    @Log(title = "交换机流量监控信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialSwitchInfo initialSwitchInfo)
    {
        return toAjax(initialSwitchInfoService.insertInitialSwitchInfo(initialSwitchInfo));
    }

    /**
     * 修改交换机流量监控信息
     */
    @RequiresPermissions("rocketmq:switchInfo:edit")
    @Log(title = "交换机流量监控信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialSwitchInfo initialSwitchInfo)
    {
        return toAjax(initialSwitchInfoService.updateInitialSwitchInfo(initialSwitchInfo));
    }

    /**
     * 删除交换机流量监控信息
     */
    @RequiresPermissions("rocketmq:switchInfo:remove")
    @Log(title = "交换机流量监控信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialSwitchInfoService.deleteInitialSwitchInfoByIds(ids));
    }

    /**
     * 获取网络端口基础信息
     * @param initialSwitchInfo
     * @return
     */
    @RequiresPermissions("rocketmq:switchInfo:list")
    @PostMapping("/getSwitchNetDetailsMsg")
    public AjaxResult switchNetDetailsMsg(@RequestBody InitialSwitchInfo initialSwitchInfo){
        return success(initialSwitchInfoService.getSwitchNetDetailsMsg(initialSwitchInfo));
    }

    /**
     * 获取网络端口网络速率
     * @param initialSwitchInfo
     * @return
     */
    @RequiresPermissions("rocketmq:switchInfo:list")
    @PostMapping("/switchNetSpeedEcharts")
    public AjaxResult switchNetSpeedEcharts(@RequestBody InitialSwitchInfo initialSwitchInfo){
        Map<String, Object> echartsData = initialSwitchInfoService.switchNetSpeedEcharts(initialSwitchInfo);
        return success(echartsData);
    }
    /**
     * 获取网络端口丢包数
     * @param initialSwitchInfo
     * @return
     */
    @RequiresPermissions("rocketmq:switchInfo:list")
    @PostMapping("/switchNetDiscardsEcharts")
    public AjaxResult switchNetDiscardsEcharts(@RequestBody InitialSwitchInfo initialSwitchInfo){
        Map<String, Object> echartsData = initialSwitchInfoService.switchNetDiscardsEcharts(initialSwitchInfo);
        return success(echartsData);
    }
    /**
     * 获取网络端口bites总数
     * @param initialSwitchInfo
     * @return
     */
    @RequiresPermissions("rocketmq:switchInfo:list")
    @PostMapping("/switchNetTotalEcharts")
    public AjaxResult switchNetTotalEcharts(@RequestBody InitialSwitchInfo initialSwitchInfo){
        Map<String, Object> echartsData = initialSwitchInfoService.switchNetTotalEcharts(initialSwitchInfo);
        return success(echartsData);
    }
    /**
     * 获取网络端口的错误包数
     * @param initialSwitchInfo
     * @return
     */
    @RequiresPermissions("rocketmq:switchInfo:list")
    @PostMapping("/switchNetErrDiscardsEcharts")
    public AjaxResult switchNetErrDiscardsEcharts(@RequestBody InitialSwitchInfo initialSwitchInfo){
        Map<String, Object> echartsData = initialSwitchInfoService.switchNetErrDiscardsEcharts(initialSwitchInfo);
        return success(echartsData);
    }
}
