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.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.InitialSwitchMpuInfo;
import com.ruoyi.rocketmq.service.IInitialSwitchMpuInfoService;
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;

/**
 * MPU信息Controller
 * 
 * @author gyt
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/switchMpuInfo")
public class InitialSwitchMpuInfoController extends BaseController
{
    @Autowired
    private IInitialSwitchMpuInfoService initialSwitchMpuInfoService;

    /**
     * 查询MPU信息列表
     */
    @RequiresPermissions("rocketmq:info:list")
    @GetMapping("/list")
    public TableDataInfo list(InitialSwitchMpuInfo initialSwitchMpuInfo)
    {
        startPage();
        List<InitialSwitchMpuInfo> list = initialSwitchMpuInfoService.selectInitialSwitchMpuInfoList(initialSwitchMpuInfo);
        return getDataTable(list);
    }

    /**
     * 导出MPU信息列表
     */
    @RequiresPermissions("rocketmq:info:export")
    @Log(title = "MPU信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialSwitchMpuInfo initialSwitchMpuInfo)
    {
        List<InitialSwitchMpuInfo> list = initialSwitchMpuInfoService.selectInitialSwitchMpuInfoList(initialSwitchMpuInfo);
        ExcelUtil<InitialSwitchMpuInfo> util = new ExcelUtil<InitialSwitchMpuInfo>(InitialSwitchMpuInfo.class);
        util.exportExcel(response, list, "MPU信息数据");
    }

    /**
     * 获取MPU信息详细信息
     */
    @RequiresPermissions("rocketmq:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialSwitchMpuInfoService.selectInitialSwitchMpuInfoById(id));
    }

    /**
     * 新增MPU信息
     */
    @RequiresPermissions("rocketmq:info:add")
    @Log(title = "MPU信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialSwitchMpuInfo initialSwitchMpuInfo)
    {
        return toAjax(initialSwitchMpuInfoService.insertInitialSwitchMpuInfo(initialSwitchMpuInfo));
    }

    /**
     * 修改MPU信息
     */
    @RequiresPermissions("rocketmq:info:edit")
    @Log(title = "MPU信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialSwitchMpuInfo initialSwitchMpuInfo)
    {
        return toAjax(initialSwitchMpuInfoService.updateInitialSwitchMpuInfo(initialSwitchMpuInfo));
    }

    /**
     * 删除MPU信息
     */
    @RequiresPermissions("rocketmq:info:remove")
    @Log(title = "MPU信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialSwitchMpuInfoService.deleteInitialSwitchMpuInfoByIds(ids));
    }

    /**
     * 获取所有mpu名称
     * @param initialSwitchMpuInfo
     * @return
     */
    @RequiresPermissions("rocketmq:info:list")
    @PostMapping("/getAllMpuName")
    public AjaxResult getAllMpuName(@RequestBody InitialSwitchMpuInfo initialSwitchMpuInfo){
        List<Map> list = initialSwitchMpuInfoService.getAllMpuName(initialSwitchMpuInfo);
        return success(list);
    }
    /**
     * 获取mpu基础信息
     * @param initialSwitchMpuInfo
     * @return
     */
    @RequiresPermissions("rocketmq:info:list")
    @PostMapping("/getMpuMsg")
    public AjaxResult getMpuMsg(@RequestBody InitialSwitchMpuInfo initialSwitchMpuInfo){
        List<InitialSwitchMpuInfo> list = initialSwitchMpuInfoService.getMpuMsg(initialSwitchMpuInfo);
        return success(list);
    }
    /**
     * 获取mpu的cpu使用率
     * @param initialSwitchMpuInfo
     * @return
     */
    @RequiresPermissions("rocketmq:info:list")
    @PostMapping("/getMpuCpuUse")
    public AjaxResult getMpuCpuUse(@RequestBody InitialSwitchMpuInfo initialSwitchMpuInfo){
        Map<String, Object> echartsData = initialSwitchMpuInfoService.getMpuCpuUse(initialSwitchMpuInfo);
        return success(echartsData);
    }
    /**
     * 获取mpu的内存使用率
     * @param initialSwitchMpuInfo
     * @return
     */
    @RequiresPermissions("rocketmq:info:list")
    @PostMapping("/getMpuMemUse")
    public AjaxResult getMpuMemUse(@RequestBody InitialSwitchMpuInfo initialSwitchMpuInfo){
        Map<String, Object> echartsData = initialSwitchMpuInfoService.getMpuMemUse(initialSwitchMpuInfo);
        return success(echartsData);
    }
    /**
     * 获取mpu的温度
     * @param initialSwitchMpuInfo
     * @return
     */
    @RequiresPermissions("rocketmq:info:list")
    @PostMapping("/getMpuTemperature")
    public AjaxResult getMpuTemperature(@RequestBody InitialSwitchMpuInfo initialSwitchMpuInfo){
        Map<String, Object> echartsData = initialSwitchMpuInfoService.getMpuTemperature(initialSwitchMpuInfo);
        return success(echartsData);
    }
}
