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

    /**
     * 导出初始带宽流量列表
     */
    @RequiresPermissions("rocketmq:traffic:export")
    @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, "初始带宽流量数据");
    }

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

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

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

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


    /**
     * 网络接口基础信息
     * @param initialBandwidthTraffic
     * @return
     */
    @RequiresPermissions("rocketmq:traffic:list")
    @PostMapping("/netInterfaceDetailsMsg")
    public AjaxResult netInterfaceDetailsMsg(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
        InitialBandwidthTraffic netInterfaceDetailsMsg = initialBandwidthTrafficService.getNetInterfaceDetailsMsg(initialBandwidthTraffic);
        return success(netInterfaceDetailsMsg);
    }

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

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

}
