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.InitialSystemInfo;
import com.ruoyi.rocketmq.domain.vo.SystemMsgVo;
import com.ruoyi.rocketmq.service.IInitialSystemInfoService;
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("/systemInfo")
public class InitialSystemInfoController extends BaseController
{
    @Autowired
    private IInitialSystemInfoService initialSystemInfoService;

    /**
     * 查询系统监控信息列表
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InitialSystemInfo initialSystemInfo)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(initialSystemInfo.getPageNum());
        pageDomain.setPageSize(initialSystemInfo.getPageSize());
        startPage(pageDomain);
        List<InitialSystemInfo> list = initialSystemInfoService.selectInitialSystemInfoList(initialSystemInfo);
        return getDataTable(list);
    }

    /**
     * 导出系统监控信息列表
     */
    @RequiresPermissions("rocketmq:systemInfo:export")
    @Log(title = "系统监控信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialSystemInfo initialSystemInfo)
    {
        List<InitialSystemInfo> list = initialSystemInfoService.selectInitialSystemInfoList(initialSystemInfo);
        ExcelUtil<InitialSystemInfo> util = new ExcelUtil<InitialSystemInfo>(InitialSystemInfo.class);
        util.exportExcel(response, list, "系统监控信息数据");
    }

    /**
     * 获取系统监控信息详细信息
     */
    @RequiresPermissions("rocketmq:systemInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialSystemInfoService.selectInitialSystemInfoById(id));
    }

    /**
     * 新增系统监控信息
     */
    @RequiresPermissions("rocketmq:systemInfo:add")
    @Log(title = "系统监控信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialSystemInfo initialSystemInfo)
    {
        return toAjax(initialSystemInfoService.insertInitialSystemInfo(initialSystemInfo));
    }

    /**
     * 修改系统监控信息
     */
    @RequiresPermissions("rocketmq:systemInfo:edit")
    @Log(title = "系统监控信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialSystemInfo initialSystemInfo)
    {
        return toAjax(initialSystemInfoService.updateInitialSystemInfo(initialSystemInfo));
    }

    /**
     * 删除系统监控信息
     */
    @RequiresPermissions("rocketmq:systemInfo:remove")
    @Log(title = "系统监控信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialSystemInfoService.deleteInitialSystemInfoByIds(ids));
    }
    /**
     * 查询系统进程监控信息列表并封装为多折线ECharts图表数据
     * @param initialSystemInfo
     * @return
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/systemProcessEcharts")
    public AjaxResult systemProcessEcharts(@RequestBody InitialSystemInfo initialSystemInfo) {
        Map<String, Object> echartsData = initialSystemInfoService.systemProcessEcharts(initialSystemInfo);
        return success(echartsData);
    }
    /**
     * 查询系统登陆用户数(个)监控信息列表并封装为多折线ECharts图表数据
     * @param initialSystemInfo
     * @return
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/systemUserNumEcharts")
    public AjaxResult systemUserNumEcharts(@RequestBody InitialSystemInfo initialSystemInfo) {
        Map<String, Object> echartsData = initialSystemInfoService.systemUserNumEcharts(initialSystemInfo);
        return success(echartsData);
    }

    /**
     * 系统基础信息
     * @param initialSystemInfo
     * @return
     */
    @RequiresPermissions("rocketmq:systemInfo:list")
    @PostMapping("/systemDetailsMsg")
    public AjaxResult systemDetailsMsg(@RequestBody InitialSystemInfo initialSystemInfo) {
        SystemMsgVo systemDetailsMsg = initialSystemInfoService.getSystemDetailsMsg(initialSystemInfo);
        return success(systemDetailsMsg);
    }

}
