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.RmAlarmLog;
import com.ruoyi.rocketmq.service.IRmAlarmLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 客户端告警信息Controller
 * 
 * @author gyt
 * @date 2025-11-10
 */
@RestController
@RequestMapping("/alarmLog")
public class RmAlarmLogController extends BaseController
{
    @Autowired
    private IRmAlarmLogService rmAlarmLogService;

    /**
     * 查询客户端告警信息列表
     */
    @RequiresPermissions("rocketmq:alarmLog:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RmAlarmLog rmAlarmLog)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmAlarmLog.getPageNum());
        pageDomain.setPageSize(rmAlarmLog.getPageSize());
        startPage(pageDomain);
        List<RmAlarmLog> list = rmAlarmLogService.selectRmAlarmLogList(rmAlarmLog);
        return getDataTable(list);
    }

    /**
     * 导出客户端告警信息列表
     */
    @RequiresPermissions("rocketmq:alarmLog:export")
    @Log(title = "客户端告警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmAlarmLog rmAlarmLog)
    {
        List<RmAlarmLog> list = rmAlarmLogService.selectRmAlarmLogList(rmAlarmLog);
        ExcelUtil<RmAlarmLog> util = new ExcelUtil<RmAlarmLog>(RmAlarmLog.class);
        util.showColumn(rmAlarmLog.getProperties());
        util.exportExcel(response, list, "客户端告警信息数据");
    }

    /**
     * 获取客户端告警信息详细信息
     */
    @RequiresPermissions("rocketmq:alarmLog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmAlarmLogService.selectRmAlarmLogById(id));
    }

    /**
     * 新增客户端告警信息
     */
    @RequiresPermissions("rocketmq:alarmLog:add")
    @Log(title = "客户端告警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmAlarmLog rmAlarmLog)
    {
        return toAjax(rmAlarmLogService.insertRmAlarmLog(rmAlarmLog));
    }

    /**
     * 修改客户端告警信息
     */
    @RequiresPermissions("rocketmq:alarmLog:edit")
    @Log(title = "客户端告警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmAlarmLog rmAlarmLog)
    {
        return toAjax(rmAlarmLogService.updateRmAlarmLog(rmAlarmLog));
    }

    /**
     * 删除客户端告警信息
     */
    @RequiresPermissions("rocketmq:alarmLog:remove")
    @Log(title = "客户端告警信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmAlarmLogService.deleteRmAlarmLogByIds(ids));
    }
}
