package com.tongran.system.controller;

import com.tongran.common.core.utils.poi.ExcelUtil;
import com.tongran.common.core.web.controller.BaseController;
import com.tongran.common.core.web.domain.AjaxResult;
import com.tongran.common.log.annotation.Log;
import com.tongran.common.log.enums.BusinessType;
import com.tongran.common.security.annotation.RequiresPermissions;
import com.tongran.system.domain.RmMonitorConfig;
import com.tongran.system.service.IRmMonitorConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 监控配置Controller
 * 
 * @author tongran
 * @date 2025-11-12
 */
@RestController
@RequestMapping("/monitorConfig")
@RequiresPermissions("system:monitorConfig")
public class RmMonitorConfigController extends BaseController
{
    @Autowired
    private IRmMonitorConfigService rmMonitorConfigService;

    /**
     * 查询监控配置列表
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody RmMonitorConfig rmMonitorConfig)
    {
        List<RmMonitorConfig> list = rmMonitorConfigService.selectRmMonitorConfigList(rmMonitorConfig);
        return success(list);
    }

    /**
     * 导出监控配置列表
     */
    @Log(title = "监控配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmMonitorConfig rmMonitorConfig)
    {
        List<RmMonitorConfig> list = rmMonitorConfigService.selectRmMonitorConfigList(rmMonitorConfig);
        ExcelUtil<RmMonitorConfig> util = new ExcelUtil<RmMonitorConfig>(RmMonitorConfig.class);
        util.exportExcel(response, list, "监控配置数据");
    }

    /**
     * 获取监控配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmMonitorConfigService.selectRmMonitorConfigById(id));
    }

    /**
     * 新增监控配置
     */
    @Log(title = "监控配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmMonitorConfig rmMonitorConfig)
    {
        return toAjax(rmMonitorConfigService.insertRmMonitorConfig(rmMonitorConfig));
    }

    /**
     * 修改监控配置
     */
    @Log(title = "监控配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmMonitorConfig rmMonitorConfig)
    {
        return toAjax(rmMonitorConfigService.updateRmMonitorConfig(rmMonitorConfig));
    }

    /**
     * 删除监控配置
     */
    @Log(title = "监控配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmMonitorConfigService.deleteRmMonitorConfigByIds(ids));
    }
}
