package com.ruoyi.rocketmq.controller;

import com.ruoyi.common.core.domain.R;
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.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rocketmq.domain.RmAlarmRecord;
import com.ruoyi.rocketmq.service.IRmAlarmRecordService;
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-12
 */
@RestController
@RequestMapping("/alarmRecord")
public class RmAlarmRecordController extends BaseController
{
    @Autowired
    private IRmAlarmRecordService rmAlarmRecordService;

    /**
     * 查询告警记录列表
     */
    @RequiresPermissions("rocketmq:record:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RmAlarmRecord rmAlarmRecord)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmAlarmRecord.getPageNum());
        pageDomain.setPageSize(rmAlarmRecord.getPageSize());
        startPage(pageDomain);
        List<RmAlarmRecord> list = rmAlarmRecordService.selectRmAlarmRecordList(rmAlarmRecord);
        return getDataTable(list);
    }
    /**
     * 查询告警记录列表
     */
    @InnerAuth
    @PostMapping("/getAlarmList")
    public R<List<RmAlarmRecord>> getAlarmList(@RequestBody RmAlarmRecord rmAlarmRecord)
    {
        List<RmAlarmRecord> list = rmAlarmRecordService.selectRmAlarmRecordList(rmAlarmRecord);
        return R.ok(list);
    }

    /**
     * 导出告警记录列表
     */
    @RequiresPermissions("rocketmq:record:export")
    @Log(title = "告警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmAlarmRecord rmAlarmRecord)
    {
        List<RmAlarmRecord> list = rmAlarmRecordService.selectRmAlarmRecordList(rmAlarmRecord);
        ExcelUtil<RmAlarmRecord> util = new ExcelUtil<RmAlarmRecord>(RmAlarmRecord.class);
        util.exportExcel(response, list, "告警记录数据");
    }

    /**
     * 获取告警记录详细信息
     */
    @RequiresPermissions("rocketmq:record:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmAlarmRecordService.selectRmAlarmRecordById(id));
    }

    /**
     * 资源告警处理情况
     * @return
     */
    @GetMapping(value = "/alarmHandlingStatus")
    public R<Map> alarmHandlingStatus(){
        Map alarmRecordMap = rmAlarmRecordService.alarmHandlingStatus();
        return R.ok(alarmRecordMap);
    }
}
