package org.dromara.ems.record.controller;

import org.dromara.common.log.annotation.Log;
import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.record.domain.EmsRecordAlarmRule;
import org.dromara.ems.record.service.IEmsRecordAlarmRuleService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 异常告警规则Controller
 * 
 * @author Yinq
 * @date 2024-05-15
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/record/recordAlarmRule")
public class EmsRecordAlarmRuleController extends EmsBaseController
{
    
    private final IEmsRecordAlarmRuleService emsRecordAlarmRuleService;

    /**
     * 查询异常告警规则列表
     */
    @SaCheckPermission("ems/record:recordAlarmRule:list")
    @GetMapping("/list")
    public TableDataInfo list(EmsRecordAlarmRule emsRecordAlarmRule)
    {
        startPage();
        List<EmsRecordAlarmRule> list = emsRecordAlarmRuleService.selectEmsRecordAlarmRuleList(emsRecordAlarmRule);
        return getDataTable(list);
    }

    /**
     * 导出异常告警规则列表
     */
    @SaCheckPermission("ems/record:recordAlarmRule:export")
    @Log(title = "异常告警规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsRecordAlarmRule emsRecordAlarmRule)
    {
        List<EmsRecordAlarmRule> list = emsRecordAlarmRuleService.selectEmsRecordAlarmRuleList(emsRecordAlarmRule);
        ExcelUtil.exportExcel(list, "异常告警规则数据", EmsRecordAlarmRule.class, response);
    }

    /**
     * 获取异常告警规则详细信息
     */
    @SaCheckPermission("ems/record:recordAlarmRule:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId)
    {
        return success(emsRecordAlarmRuleService.selectEmsRecordAlarmRuleByObjId(objId));
    }

    /**
     * 新增异常告警规则
     */
    @SaCheckPermission("ems/record:recordAlarmRule:add")
    @Log(title = "异常告警规则", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsRecordAlarmRule emsRecordAlarmRule)
    {
        return toAjax(emsRecordAlarmRuleService.insertEmsRecordAlarmRule(emsRecordAlarmRule));
    }

    /**
     * 修改异常告警规则
     */
    @SaCheckPermission("ems/record:recordAlarmRule:edit")
    @Log(title = "异常告警规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsRecordAlarmRule emsRecordAlarmRule)
    {
        return toAjax(emsRecordAlarmRuleService.updateEmsRecordAlarmRule(emsRecordAlarmRule));
    }

    /**
     * 删除异常告警规则
     */
    @SaCheckPermission("ems/record:recordAlarmRule:remove")
    @Log(title = "异常告警规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public R<?> remove(@PathVariable Long[] objIds)
    {
        return toAjax(emsRecordAlarmRuleService.deleteEmsRecordAlarmRuleByObjIds(objIds));
    }


    /**
     * 查询异常告警规则列表
     */
    @SaCheckPermission("ems/record:recordAlarmRule:list")
    @GetMapping("/getEmsRecordAlarmRuleList")
    public R<?> getEmsRecordAlarmRuleList(EmsRecordAlarmRule emsRecordAlarmRule)
    {
        List<EmsRecordAlarmRule> list = emsRecordAlarmRuleService.selectEmsRecordAlarmRuleList(emsRecordAlarmRule);
        return success(list);
    }

    /**
     * 获取异常告警规则总数
     */
    @GetMapping("/getEmsRecordAlarmRuleTotalCount")
    public int getEmsRecordAlarmRuleTotalCount()
    {
        return emsRecordAlarmRuleService.getEmsRecordAlarmRuleTotalCount();
    }
}
