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.RmAlarmPushConfig;
import com.tongran.rocketmq.service.IRmAlarmPushConfigService;
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-11
 */
@RestController
@RequestMapping("/alarmPushConfig")
@RequiresPermissions("rocketmq:alarmPushConfig")
public class RmAlarmPushConfigController extends BaseController
{
    @Autowired
    private IRmAlarmPushConfigService rmAlarmPushConfigService;

    /**
     * 查询告警推送配置列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RmAlarmPushConfig rmAlarmPushConfig)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmAlarmPushConfig.getPageNum());
        pageDomain.setPageSize(rmAlarmPushConfig.getPageSize());
        startPage(pageDomain);
        List<RmAlarmPushConfig> list = rmAlarmPushConfigService.selectRmAlarmPushConfigList(rmAlarmPushConfig);
        return getDataTable(list);
    }

    /**
     * 导出告警推送配置列表
     */
    @Log(title = "告警推送配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmAlarmPushConfig rmAlarmPushConfig)
    {
        List<RmAlarmPushConfig> list = rmAlarmPushConfigService.selectRmAlarmPushConfigList(rmAlarmPushConfig);
        ExcelUtil<RmAlarmPushConfig> util = new ExcelUtil<RmAlarmPushConfig>(RmAlarmPushConfig.class);
        util.showColumn(rmAlarmPushConfig.getProperties());
        util.exportExcel(response, list, "告警推送配置数据");
    }

    /**
     * 获取告警推送配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmAlarmPushConfigService.selectRmAlarmPushConfigById(id));
    }

    /**
     * 新增告警推送配置
     */
    @Log(title = "告警推送配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmAlarmPushConfig rmAlarmPushConfig)
    {
        return toAjax(rmAlarmPushConfigService.insertRmAlarmPushConfig(rmAlarmPushConfig));
    }

    /**
     * 修改告警推送配置
     */
    @Log(title = "告警推送配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmAlarmPushConfig rmAlarmPushConfig)
    {
        return toAjax(rmAlarmPushConfigService.updateRmAlarmPushConfig(rmAlarmPushConfig));
    }

    /**
     * 删除告警推送配置
     */
    @Log(title = "告警推送配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmAlarmPushConfigService.deleteRmAlarmPushConfigByIds(ids));
    }
}
