Files
IOT_API/IOT_API/Controllers/Inspection/AlertRuleController.cs
T
2026-08-28 15:20:52 +08:00

68 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.AspNetCore.Mvc;
using Model.Dto.Inspection;
using Service.Interface;
using System.Threading.Tasks;
namespace WebAPI.Controllers
{
/// <summary>
/// 告警规则(规则实例:查看所有设备告警的规则列表)
/// </summary>
[ApiController]
[Route("api/inspection/alert-rule")]
public class AlertRuleController : ControllerBase
{
private readonly IAlertRuleService _alertRuleService;
public AlertRuleController(IAlertRuleService alertRuleService)
{
_alertRuleService = alertRuleService;
}
/// <summary>
/// 获取全部告警规则列表
/// </summary>
[HttpGet("list")]
public async Task<IActionResult> GetList()
{
return Ok(await _alertRuleService.GetListAsync());
}
/// <summary>
/// 新增告警规则(前端传 DTO
/// </summary>
[HttpPost("add")]
public async Task<IActionResult> Add([FromBody] AlertRuleDto dto)
{
return Ok(await _alertRuleService.AddAsync(dto));
}
/// <summary>
/// 修改告警规则(前端传 DTO
/// </summary>
[HttpPut("update")]
public async Task<IActionResult> Update([FromBody] AlertRuleDto dto)
{
return Ok(await _alertRuleService.UpdateAsync(dto));
}
/// <summary>
/// 删除告警规则(软删除)
/// </summary>
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(long id)
{
return Ok(await _alertRuleService.DeleteAsync(id));
}
/// <summary>
/// 启用/停用告警规则
/// </summary>
[HttpPut("{id}/enabled")]
public async Task<IActionResult> SetEnabled(long id, [FromQuery] bool enabled)
{
return Ok(await _alertRuleService.SetEnabledAsync(id, enabled));
}
}
}