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.InitialMemoryInfo;
import com.ruoyi.rocketmq.service.IInitialMemoryInfoService;
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("/memoryInfo")
public class InitialMemoryInfoController extends BaseController
{
    @Autowired
    private IInitialMemoryInfoService initialMemoryInfoService;

    /**
     * 查询内存监控信息列表
     */
    @RequiresPermissions("rocketmq:memoryInfo:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InitialMemoryInfo initialMemoryInfo)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(initialMemoryInfo.getPageNum());
        pageDomain.setPageSize(initialMemoryInfo.getPageSize());
        startPage(pageDomain);
        List<InitialMemoryInfo> list = initialMemoryInfoService.selectInitialMemoryInfoList(initialMemoryInfo);
        return getDataTable(list);
    }

    /**
     * 导出内存监控信息列表
     */
    @RequiresPermissions("rocketmq:memoryInfo:export")
    @Log(title = "内存监控信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialMemoryInfo initialMemoryInfo)
    {
        List<InitialMemoryInfo> list = initialMemoryInfoService.selectInitialMemoryInfoList(initialMemoryInfo);
        ExcelUtil<InitialMemoryInfo> util = new ExcelUtil<InitialMemoryInfo>(InitialMemoryInfo.class);
        util.exportExcel(response, list, "内存监控信息数据");
    }

    /**
     * 获取内存监控信息详细信息
     */
    @RequiresPermissions("rocketmq:memoryInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialMemoryInfoService.selectInitialMemoryInfoById(id));
    }

    /**
     * 新增内存监控信息
     */
    @RequiresPermissions("rocketmq:memoryInfo:add")
    @Log(title = "内存监控信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialMemoryInfo initialMemoryInfo)
    {
        return toAjax(initialMemoryInfoService.insertInitialMemoryInfo(initialMemoryInfo));
    }

    /**
     * 修改内存监控信息
     */
    @RequiresPermissions("rocketmq:memoryInfo:edit")
    @Log(title = "内存监控信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialMemoryInfo initialMemoryInfo)
    {
        return toAjax(initialMemoryInfoService.updateInitialMemoryInfo(initialMemoryInfo));
    }

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

    /**
     * 查询交换空间可用量监控数据
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/swapSizeFreeEcharts")
    public AjaxResult swapSizeFreeEcharts(@RequestBody InitialMemoryInfo initialMemoryInfo) {
        Map<String, Object> echartsData = initialMemoryInfoService.swapSizeFreeEcharts(initialMemoryInfo);
        return AjaxResult.success(echartsData);
    }

    /**
     * 查询内存利用率监控数据
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/untilzationEcharts")
    public AjaxResult untilzationEcharts(@RequestBody InitialMemoryInfo initialMemoryInfo) {
        Map<String, Object> echartsData = initialMemoryInfoService.untilzationEcharts(initialMemoryInfo);
        return AjaxResult.success(echartsData);
    }

    /**
     * 查询内存可用量监控数据（KB）
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/availableMemoryEcharts")
    public AjaxResult availableMemoryEcharts(@RequestBody InitialMemoryInfo initialMemoryInfo) {
        Map<String, Object> echartsData = initialMemoryInfoService.availableMemoryEcharts(initialMemoryInfo);
        return AjaxResult.success(echartsData);
    }

    /**
     * 查询交换空间百分比监控数据
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/swapSizePercentEcharts")
    public AjaxResult swapSizePercentEcharts(@RequestBody InitialMemoryInfo initialMemoryInfo) {
        Map<String, Object> echartsData = initialMemoryInfoService.swapSizePercentEcharts(initialMemoryInfo);
        return AjaxResult.success(echartsData);
    }

    /**
     * 查询可用内存百分比监控数据
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/percentEcharts")
    public AjaxResult percentEcharts(@RequestBody InitialMemoryInfo initialMemoryInfo) {
        Map<String, Object> echartsData = initialMemoryInfoService.percentEcharts(initialMemoryInfo);
        return AjaxResult.success(echartsData);
    }

}
