package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.R;
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.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.InitialSwitchInfoDetails;
import com.ruoyi.system.service.IInitialSwitchInfoDetailsService;
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-26
 */
@RestController
@RequestMapping("/switchInfoDetails")
public class InitialSwitchInfoDetailsController extends BaseController
{
    @Autowired
    private IInitialSwitchInfoDetailsService initialSwitchInfoDetailsService;
    /**
     * 查询交换机监控信息列表
     */
    @RequiresPermissions("system:switchInfoDetails:list")
    @GetMapping("/list")
    public TableDataInfo list(InitialSwitchInfoDetails initialSwitchInfoDetails)
    {
        startPage();
        List<InitialSwitchInfoDetails> list = initialSwitchInfoDetailsService.selectInitialSwitchInfoDetailsList(initialSwitchInfoDetails);
        return getDataTable(list);
    }

    /**
     * 导出交换机监控信息列表
     */
    @RequiresPermissions("system:switchInfoDetails:export")
    @Log(title = "交换机监控信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialSwitchInfoDetails initialSwitchInfoDetails)
    {
        List<InitialSwitchInfoDetails> list = initialSwitchInfoDetailsService.selectInitialSwitchInfoDetailsList(initialSwitchInfoDetails);
        ExcelUtil<InitialSwitchInfoDetails> util = new ExcelUtil<InitialSwitchInfoDetails>(InitialSwitchInfoDetails.class);
        util.exportExcel(response, list, "交换机监控信息数据");
    }

    /**
     * 获取交换机监控信息详细信息
     */
    @RequiresPermissions("system:switchInfoDetails:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialSwitchInfoDetailsService.selectInitialSwitchInfoDetailsById(id));
    }

    /**
     * 新增交换机监控信息
     */
    @RequiresPermissions("system:switchInfoDetails:add")
    @Log(title = "交换机监控信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
    {
        return toAjax(initialSwitchInfoDetailsService.insertInitialSwitchInfoDetails(initialSwitchInfoDetails));
    }

    /**
     * 修改交换机监控信息
     */
    @RequiresPermissions("system:switchInfoDetails:edit")
    @Log(title = "交换机监控信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
    {
        return toAjax(initialSwitchInfoDetailsService.updateInitialSwitchInfoDetails(initialSwitchInfoDetails));
    }

    /**
     * 删除交换机监控信息
     */
    @RequiresPermissions("system:switchInfoDetails:remove")
    @Log(title = "交换机监控信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialSwitchInfoDetailsService.deleteInitialSwitchInfoDetailsByIds(ids));
    }
    /**
     * 交换机流量相关数据入库
     */
    @InnerAuth
    @PostMapping("/autoSaveSwitchTraffic")
    public R<String> autoSaveSwitchTraffic(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
    {
        return initialSwitchInfoDetailsService.autoSaveSwitchTraffic(initialSwitchInfoDetails);
    }
    /**
     * 图形分析-95带宽值mbps/日 v1.1
     */
    @RequiresPermissions("system:bandwidth:list")
    @PostMapping("/getGraphicalAnalysisDaily")
    public AjaxResult getGraphicalAnalysisDaily(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
    {
        List<Map<String, Object>> echartsData = initialSwitchInfoDetailsService.getGraphicalAnalysisDaily(initialSwitchInfoDetails);
        return success(echartsData);
    }
    /**
     * 图形分析-95带宽值mbps/月 v1.1
     */
    @RequiresPermissions("system:bandwidth:list")
    @PostMapping("/getGraphicalAnalysisMonthy")
    public AjaxResult getGraphicalAnalysisMonthy(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
    {
        List<Map<String, Object>> echartsData = initialSwitchInfoDetailsService.getGraphicalAnalysisMonthy(initialSwitchInfoDetails);
        return success(echartsData);
    }
}
