package com.tongran.rocketmq.controller;

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.TableDataInfo;
import com.tongran.common.log.annotation.Log;
import com.tongran.common.log.enums.BusinessType;
import com.tongran.common.security.annotation.RequiresPermissions;
import com.tongran.rocketmq.domain.InitialSwitchInfo;
import com.tongran.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 tongran
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/switchInfo")
@RequiresPermissions("rocketmq:switchInfo")
public class InitialSwitchInfoController extends BaseController
{
    @Autowired
    private IInitialSwitchInfoService initialSwitchInfoService;

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

    /**
     * 导出交换机流量监控信息列表
     */
    @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, "交换机流量监控信息数据");
    }

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

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

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

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

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

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