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.InitialBandwidthTraffic;
import com.tongran.rocketmq.service.IInitialBandwidthTrafficService;
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-20
 */
@RestController
@RequestMapping("/traffic")
@RequiresPermissions("rocketmq:traffic")
public class InitialBandwidthTrafficController extends BaseController
{
    @Autowired
    private IInitialBandwidthTrafficService initialBandwidthTrafficService;
    /**
     * 查询初始带宽流量列表
     */
    @GetMapping("/list")
    public TableDataInfo list(InitialBandwidthTraffic initialBandwidthTraffic)
    {
        startPage();
        List<InitialBandwidthTraffic> list = initialBandwidthTrafficService.selectInitialBandwidthTrafficList(initialBandwidthTraffic);
        return getDataTable(list);
    }

    /**
     * 导出初始带宽流量列表
     */
    @Log(title = "初始带宽流量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialBandwidthTraffic initialBandwidthTraffic)
    {
        List<InitialBandwidthTraffic> list = initialBandwidthTrafficService.selectInitialBandwidthTrafficList(initialBandwidthTraffic);
        ExcelUtil<InitialBandwidthTraffic> util = new ExcelUtil<InitialBandwidthTraffic>(InitialBandwidthTraffic.class);
        util.exportExcel(response, list, "初始带宽流量数据");
    }

    /**
     * 获取初始带宽流量详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialBandwidthTrafficService.selectInitialBandwidthTrafficById(id));
    }

    /**
     * 新增初始带宽流量
     */
    @Log(title = "初始带宽流量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic)
    {
        return toAjax(initialBandwidthTrafficService.insertInitialBandwidthTraffic(initialBandwidthTraffic));
    }

    /**
     * 修改初始带宽流量
     */
    @Log(title = "初始带宽流量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic)
    {
        return toAjax(initialBandwidthTrafficService.updateInitialBandwidthTraffic(initialBandwidthTraffic));
    }

    /**
     * 删除初始带宽流量
     */
    @Log(title = "初始带宽流量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialBandwidthTrafficService.deleteInitialBandwidthTrafficByIds(ids));
    }


    /**
     * 服务器详情
     * @param initialBandwidthTraffic
     * @return
     */
    @PostMapping("/serverDetails")
    public AjaxResult serverDetails(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        Map<String, Object> map= initialBandwidthTrafficService.serverDetails(initialBandwidthTraffic);
        return success(map);
    }
    /**
     * 网络接口基础信息
     * @param initialBandwidthTraffic
     * @return
     */
    @PostMapping("/netInterfaceDetailsMsg")
    public AjaxResult netInterfaceDetailsMsg(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        InitialBandwidthTraffic netInterfaceDetailsMsg = initialBandwidthTrafficService.getNetInterfaceDetailsMsg(initialBandwidthTraffic);
        return success(netInterfaceDetailsMsg);
    }

    /**
     * 查询eth0流量信息并封装为多折线ECharts图表数据
     */
    @PostMapping("/netInterfaceTrafficEcharts")
    public AjaxResult netInterfaceTrafficEcharts(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        Map<String, Object> echartsData = initialBandwidthTrafficService.netInterfaceTrafficEcharts(initialBandwidthTraffic);
        return success(echartsData);
    }
    /**
     * 查询eth0 IPV4流量信息并封装为多折线ECharts图表数据
     */
    @PostMapping("/netInterfaceIpv4TrafficEcharts")
    public AjaxResult netInterfaceIpv4TrafficEcharts(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        Map<String, Object> echartsData = initialBandwidthTrafficService.netInterfaceIpv4TrafficEcharts(initialBandwidthTraffic);
        return success(echartsData);
    }
    /**
     * 查询eth0 IPV6流量信息并封装为多折线ECharts图表数据
     */
    @PostMapping("/netInterfaceIpv6TrafficEcharts")
    public AjaxResult netInterfaceIpv6TrafficEcharts(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        Map<String, Object> echartsData = initialBandwidthTrafficService.netInterfaceIpv6TrafficEcharts(initialBandwidthTraffic);
        return success(echartsData);
    }

    /**
     * eth0丢包数
     * @param initialBandwidthTraffic
     * @return
     */
    @PostMapping("/netInterfaceDroppedEcharts")
    public AjaxResult netInterfaceDroppedEcharts(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        Map<String, Object> echartsData = initialBandwidthTrafficService.netInterfaceDroppedEcharts(initialBandwidthTraffic);
        return success(echartsData);
    }

    /**
     * 查询多个网卡流量信息并封装为多折线ECharts图表数据
     */
    @PostMapping("/netBatchTrafficEcharts")
    public AjaxResult netBatchTrafficEcharts(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        List<Map<String, Object>> echartsData = initialBandwidthTrafficService.netBatchTrafficEcharts(initialBandwidthTraffic);
        return success(echartsData);
    }

    /**
     * 查询eth0 Ping丢包率信息并封装为多折线ECharts图表数据
     */
    @PostMapping("/pingDroppedEcharts")
    public AjaxResult pingDroppedEcharts(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        Map<String, Object> echartsData = initialBandwidthTrafficService.pingDroppedEcharts(initialBandwidthTraffic);
        return success(echartsData);
    }

}
