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.PageDomain;
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.InitialDockerInfo;
import com.ruoyi.rocketmq.service.IInitialDockerInfoService;
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("/dockerInfo")
public class InitialDockerInfoController extends BaseController
{
    @Autowired
    private IInitialDockerInfoService initialDockerInfoService;

    /**
     * 查询容器监控信息列表
     */
    @RequiresPermissions("rocketmq:dockerInfo:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InitialDockerInfo initialDockerInfo)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(initialDockerInfo.getPageNum());
        pageDomain.setPageSize(initialDockerInfo.getPageSize());
        startPage(pageDomain);
        List<InitialDockerInfo> list = initialDockerInfoService.selectInitialDockerInfoList(initialDockerInfo);
        return getDataTable(list);
    }

    /**
     * 导出容器监控信息列表
     */
    @RequiresPermissions("rocketmq:dockerInfo:export")
    @Log(title = "容器监控信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialDockerInfo initialDockerInfo)
    {
        List<InitialDockerInfo> list = initialDockerInfoService.selectInitialDockerInfoList(initialDockerInfo);
        ExcelUtil<InitialDockerInfo> util = new ExcelUtil<InitialDockerInfo>(InitialDockerInfo.class);
        util.exportExcel(response, list, "容器监控信息数据");
    }

    /**
     * 获取容器监控信息详细信息
     */
    @RequiresPermissions("rocketmq:dockerInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialDockerInfoService.selectInitialDockerInfoById(id));
    }

    /**
     * 新增容器监控信息
     */
    @RequiresPermissions("rocketmq:dockerInfo:add")
    @Log(title = "容器监控信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialDockerInfo initialDockerInfo)
    {
        return toAjax(initialDockerInfoService.insertInitialDockerInfo(initialDockerInfo));
    }

    /**
     * 修改容器监控信息
     */
    @RequiresPermissions("rocketmq:dockerInfo:edit")
    @Log(title = "容器监控信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialDockerInfo initialDockerInfo)
    {
        return toAjax(initialDockerInfoService.updateInitialDockerInfo(initialDockerInfo));
    }

    /**
     * 删除容器监控信息
     */
    @RequiresPermissions("rocketmq:dockerInfo:remove")
    @Log(title = "容器监控信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialDockerInfoService.deleteInitialDockerInfoByIds(ids));
    }

    /**
     * 容器基础信息
     * @param initialDockerInfo
     * @return
     */
    @RequiresPermissions("rocketmq:dockerInfo:list")
    @PostMapping("/getDockerDetailsMsg")
    public AjaxResult dockerDetailsMsg(@RequestBody InitialDockerInfo initialDockerInfo){
        return success(initialDockerInfoService.getDockerDetailsMsg(initialDockerInfo));
    }

    /**
     * cpu利用率
     * @param initialDockerInfo
     * @return
     */
    @RequiresPermissions("rocketmq:dockerInfo:list")
    @PostMapping("/cpuUtilEcharts")
    public AjaxResult cpuUtilEcharts(@RequestBody InitialDockerInfo initialDockerInfo){
        Map<String, Object> echartsData = initialDockerInfoService.cpuUtilEcharts(initialDockerInfo);
        return success(echartsData);
    }
    /**
     * 内存利用率
     * @param initialDockerInfo
     * @return
     */
    @RequiresPermissions("rocketmq:dockerInfo:list")
    @PostMapping("/memUtilEcharts")
    public AjaxResult memUtilEcharts(@RequestBody InitialDockerInfo initialDockerInfo){
        Map<String, Object> echartsData = initialDockerInfoService.memUtilEcharts(initialDockerInfo);
        return success(echartsData);
    }

    /**
     * 容器的网络速率(KB/s)
     * @param initialDockerInfo
     * @return
     */
    @RequiresPermissions("rocketmq:dockerInfo:list")
    @PostMapping("/netSpeedEcharts")
    public AjaxResult netSpeedEcharts(@RequestBody InitialDockerInfo initialDockerInfo){
        Map<String, Object> echartsData = initialDockerInfoService.netSpeedEcharts(initialDockerInfo);
        return success(echartsData);
    }
    /**
     * 获取指定服务器的容器id
     * @param initialDockerInfo
     * @return
     */
    @RequiresPermissions("rocketmq:mountPointInfo:list")
    @PostMapping("/getAllDockerId")
    public AjaxResult getAllDockerId(@RequestBody InitialDockerInfo initialDockerInfo){
        List<Map> list = initialDockerInfoService.getAllDockerId(initialDockerInfo);
        return success(list);
    }
}
