通知告警规则引擎
This commit is contained in:
@@ -1,14 +1,67 @@
|
||||
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
|
||||
{
|
||||
// TODO: 实现 告警规则 相关接口
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Model.Dto.Inspection;
|
||||
using Service.Interface;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据转发(配置数据转发规则,支持通过消息通知的方式定时转发数据)
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/inspection/data-forward")]
|
||||
public class DataForwardController : ControllerBase
|
||||
{
|
||||
private readonly IDataForwardService _dataForwardService;
|
||||
|
||||
public DataForwardController(IDataForwardService dataForwardService)
|
||||
{
|
||||
_dataForwardService = dataForwardService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部转发规则列表
|
||||
/// </summary>
|
||||
[HttpGet("list")]
|
||||
public async Task<IActionResult> GetList()
|
||||
{
|
||||
return Ok(await _dataForwardService.GetListAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增转发规则(前端传 DTO)
|
||||
/// </summary>
|
||||
[HttpPost("add")]
|
||||
public async Task<IActionResult> Add([FromBody] DataForwardRuleDto dto)
|
||||
{
|
||||
return Ok(await _dataForwardService.AddAsync(dto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改转发规则(前端传 DTO)
|
||||
/// </summary>
|
||||
[HttpPut("update")]
|
||||
public async Task<IActionResult> Update([FromBody] DataForwardRuleDto dto)
|
||||
{
|
||||
return Ok(await _dataForwardService.UpdateAsync(dto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除转发规则(软删除)
|
||||
/// </summary>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> Delete(long id)
|
||||
{
|
||||
return Ok(await _dataForwardService.DeleteAsync(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用/停用转发规则
|
||||
/// </summary>
|
||||
[HttpPut("{id}/enabled")]
|
||||
public async Task<IActionResult> SetEnabled(long id, [FromQuery] bool enabled)
|
||||
{
|
||||
return Ok(await _dataForwardService.SetEnabledAsync(id, enabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -31,7 +31,11 @@ namespace WebAPI
|
||||
DatabaseConfig.SetTenant(tenantId);
|
||||
DatabaseConfig.CreateDatabaseAndCheckConnection(createDatabase: true, checkConnection: true);
|
||||
SqlSugarContext.InitDatabase();
|
||||
builder.Services.AddControllers()
|
||||
builder.Services.AddControllers(options =>
|
||||
{
|
||||
// 非空字符串属性(如 Remark)缺失时不报 400,前端可以只传部分字段
|
||||
options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true;
|
||||
})
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
||||
|
||||
Reference in New Issue
Block a user