68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
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));
|
||
}
|
||
}
|
||
}
|