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.RmMonitorTemplate;
import com.ruoyi.rocketmq.domain.vo.RmMonitorTemplateVo;
import com.ruoyi.rocketmq.service.IRmMonitorTemplateService;
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-09-09
 */
@RestController
@RequestMapping("/template")
public class RmMonitorTemplateController extends BaseController
{
    @Autowired
    private IRmMonitorTemplateService rmMonitorTemplateService;

    /**
     * 查询监控模板列表
     */
    @RequiresPermissions("rocketmq:template:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RmMonitorTemplate rmMonitorTemplate)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmMonitorTemplate.getPageNum());
        pageDomain.setPageSize(rmMonitorTemplate.getPageSize());
        startPage(pageDomain);
        List<RmMonitorTemplate> list = rmMonitorTemplateService.selectRmMonitorTemplateList(rmMonitorTemplate);
        return getDataTable(list);
    }

    /**
     * 导出监控模板列表
     */
    @RequiresPermissions("rocketmq:template:export")
    @Log(title = "监控模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody RmMonitorTemplate rmMonitorTemplate)
    {
        List<RmMonitorTemplate> list = rmMonitorTemplateService.selectRmMonitorTemplateList(rmMonitorTemplate);
        ExcelUtil<RmMonitorTemplate> util = new ExcelUtil<RmMonitorTemplate>(RmMonitorTemplate.class);
        util.showColumn(rmMonitorTemplate.getProperties());
        util.exportExcel(response, list, "监控模板数据");
    }

    /**
     * 获取监控模板详细信息
     */
    @RequiresPermissions("rocketmq:template:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmMonitorTemplateService.getTemplateMsgById(id));
    }

    /**
     * 新增监控模板
     */
    @RequiresPermissions("rocketmq:template:add")
    @Log(title = "监控模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmMonitorTemplateVo rmMonitorTemplateVo)
    {
        return toAjax(rmMonitorTemplateService.addRmMonitorTemplate(rmMonitorTemplateVo));
    }

    /**
     * 修改监控模板
     */
    @RequiresPermissions("rocketmq:template:edit")
    @Log(title = "监控模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmMonitorTemplateVo rmMonitorTemplateVo)
    {
        return toAjax(rmMonitorTemplateService.updateRmMonitorTemplate(rmMonitorTemplateVo));
    }

    /**
     * 删除监控模板
     */
    @RequiresPermissions("rocketmq:template:remove")
    @Log(title = "监控模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmMonitorTemplateService.deleteRmMonitorTemplateByIds(ids));
    }
    /**
     * 关联监控模板查询
     */
    @RequiresPermissions("rocketmq:template:list")
    @GetMapping("/getAllTemplate")
    public AjaxResult getAllTemplate()
    {
        List<Map> list = rmMonitorTemplateService.getAllTemplate();
        return success(list);
    }
}
