package com.tongran.rocketmq.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.core.web.page.PageDomain;
import com.tongran.common.core.web.page.TableDataInfo;
import com.tongran.common.log.annotation.Log;
import com.tongran.common.log.enums.BusinessType;
import com.tongran.common.security.annotation.RequiresPermissions;
import com.tongran.rocketmq.domain.RmMonitorTemplate;
import com.tongran.rocketmq.domain.vo.RmMonitorTemplateVo;
import com.tongran.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 tongran
 * @date 2025-09-09
 */
@RestController
@RequestMapping("/template")
@RequiresPermissions("rocketmq:template")
public class RmMonitorTemplateController extends BaseController
{
    @Autowired
    private IRmMonitorTemplateService rmMonitorTemplateService;

    /**
     * 查询监控模板列表
     */
    @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);
    }

    /**
     * 导出监控模板列表
     */
    @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, "监控模板数据");
    }

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

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

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

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