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.InitialCpuInfo;
import com.ruoyi.rocketmq.service.IInitialCpuInfoService;
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;

/**
 * CPU监控信息Controller
 * 
 * @author gyt
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/cpuInfo")
public class InitialCpuInfoController extends BaseController
{
    @Autowired
    private IInitialCpuInfoService initialCpuInfoService;

    /**
     * 查询CPU监控信息列表
     */
    @RequiresPermissions("rocketmq:cpuInfo:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InitialCpuInfo initialCpuInfo)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(initialCpuInfo.getPageNum());
        pageDomain.setPageSize(initialCpuInfo.getPageSize());
        startPage(pageDomain);
        List<InitialCpuInfo> list = initialCpuInfoService.selectInitialCpuInfoList(initialCpuInfo);
        return getDataTable(list);
    }

    /**
     * 导出CPU监控信息列表
     */
    @RequiresPermissions("rocketmq:cpuInfo:export")
    @Log(title = "CPU监控信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialCpuInfo initialCpuInfo)
    {
        List<InitialCpuInfo> list = initialCpuInfoService.selectInitialCpuInfoList(initialCpuInfo);
        ExcelUtil<InitialCpuInfo> util = new ExcelUtil<InitialCpuInfo>(InitialCpuInfo.class);
        util.exportExcel(response, list, "CPU监控信息数据");
    }

    /**
     * 获取CPU监控信息详细信息
     */
    @RequiresPermissions("rocketmq:cpuInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialCpuInfoService.selectInitialCpuInfoById(id));
    }

    /**
     * 新增CPU监控信息
     */
    @RequiresPermissions("rocketmq:cpuInfo:add")
    @Log(title = "CPU监控信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialCpuInfo initialCpuInfo)
    {
        return toAjax(initialCpuInfoService.insertInitialCpuInfo(initialCpuInfo));
    }

    /**
     * 修改CPU监控信息
     */
    @RequiresPermissions("rocketmq:cpuInfo:edit")
    @Log(title = "CPU监控信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialCpuInfo initialCpuInfo)
    {
        return toAjax(initialCpuInfoService.updateInitialCpuInfo(initialCpuInfo));
    }

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

    /**
     * 查询CPU监控信息列表并封装为多折线ECharts图表数据
     */
    @RequiresPermissions("rocketmq:cpuInfo:list")
    @PostMapping("/cpuLoadEcharts")
    public AjaxResult cpuLoadEcharts(@RequestBody InitialCpuInfo initialCpuInfo) {
        Map<String, Object> echartsData = initialCpuInfoService.cupLoadEcharts(initialCpuInfo);
        return success(echartsData);
    }
    /**
     * 查询CPU监控信息列表并封装为多折线ECharts图表数据
     */
    @RequiresPermissions("rocketmq:cpuInfo:list")
    @PostMapping("/cpuTimeEcharts")
    public AjaxResult cpuTimeEcharts(@RequestBody InitialCpuInfo initialCpuInfo) {
        Map<String, Object> echartsData = initialCpuInfoService.cpuTimeEcharts(initialCpuInfo);
        return success(echartsData);
    }
}
