175 lines
5.7 KiB
C#
175 lines
5.7 KiB
C#
using Azure;
|
|
using FastEndpoints;
|
|
using MoviconWebApi.Common;
|
|
using MoviconWebApi.Entities;
|
|
using System;
|
|
|
|
namespace MoviconWebApi.API.DeviceAlarmApi
|
|
{
|
|
|
|
/// <summary>
|
|
/// 设备报警列表查询端点
|
|
/// </summary>
|
|
public class GetDeviceAlarmListEndpoint : Endpoint<DeviceAlarmRequest, ApiResponse<List<DeviceAlarmResponse>>>
|
|
{
|
|
private readonly IFreeSql _freeSql;
|
|
|
|
public GetDeviceAlarmListEndpoint(IFreeSql freeSql)
|
|
{
|
|
_freeSql = freeSql;
|
|
}
|
|
|
|
public override void Configure()
|
|
{
|
|
Get("/devicealarm/list");
|
|
AllowAnonymous();
|
|
Summary(s =>
|
|
{
|
|
s.Summary = "获取设备报警列表";
|
|
s.Description = "根据设备编号、时间范围和设备状态查询设备报警";
|
|
s.Response<ApiResponse<List<DeviceAlarmResponse>>>(200, "成功返回设备报警列表");
|
|
});
|
|
}
|
|
|
|
public override async Task HandleAsync(DeviceAlarmRequest req, CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
var data = await DeviceAlarmData.GetDeviceAlarmList(_freeSql, req);
|
|
Response = ApiResponse<List<DeviceAlarmResponse>>.Success(data, "success");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Response = ApiResponse<List<DeviceAlarmResponse>>.Error("500", $"获取数据失败: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设备报警分页查询端点
|
|
/// </summary>
|
|
public class GetDeviceAlarmPagedEndpoint : Endpoint<DeviceAlarmPagedRequest, ApiResponse<DeviceAlarmPagedResponse>>
|
|
{
|
|
private readonly IFreeSql _freeSql;
|
|
|
|
public GetDeviceAlarmPagedEndpoint(IFreeSql freeSql)
|
|
{
|
|
_freeSql = freeSql;
|
|
}
|
|
|
|
public override void Configure()
|
|
{
|
|
Post("/devicealarm/paged");
|
|
AllowAnonymous();
|
|
Summary(s =>
|
|
{
|
|
s.Summary = "分页获取设备报警";
|
|
s.Description = "根据设备编号、时间范围和设备状态分页查询设备报警";
|
|
s.Response<ApiResponse<DeviceAlarmPagedResponse>>(200, "成功返回设备报警分页数据");
|
|
});
|
|
}
|
|
|
|
public override async Task HandleAsync(DeviceAlarmPagedRequest req, CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
var (items, total) = await DeviceAlarmData.GetDeviceAlarmPagedList(_freeSql, req);
|
|
var pagedResponse = new DeviceAlarmPagedResponse
|
|
{
|
|
Items = items,
|
|
Total = total
|
|
};
|
|
Response = ApiResponse<DeviceAlarmPagedResponse>.Success(pagedResponse, "success");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Response = ApiResponse<DeviceAlarmPagedResponse>.Error("500", $"获取数据失败: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取最新设备报警端点
|
|
/// </summary>
|
|
public class GetLatestDeviceAlarmEndpoint : Endpoint<DeviceAlarmRequest, ApiResponse<DeviceAlarmResponse>>
|
|
{
|
|
private readonly IFreeSql _freeSql;
|
|
|
|
public GetLatestDeviceAlarmEndpoint(IFreeSql freeSql)
|
|
{
|
|
_freeSql = freeSql;
|
|
}
|
|
|
|
public override void Configure()
|
|
{
|
|
Get("/devicealarm/latest");
|
|
AllowAnonymous();
|
|
Summary(s =>
|
|
{
|
|
s.Summary = "获取最新设备报警";
|
|
s.Description = "根据设备编号获取最新的设备报警记录";
|
|
s.Response<ApiResponse<DeviceAlarmResponse>>(200, "成功返回最新设备报警");
|
|
});
|
|
}
|
|
|
|
public override async Task HandleAsync(DeviceAlarmRequest req, CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
var data = await DeviceAlarmData.GetLatestDeviceAlarm(_freeSql, req);
|
|
if (data == null)
|
|
{
|
|
Response = ApiResponse<DeviceAlarmResponse>.Error("404", "未找到设备报警记录");
|
|
}
|
|
else
|
|
{
|
|
Response = ApiResponse<DeviceAlarmResponse>.Success(data, "success");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Response = ApiResponse<DeviceAlarmResponse>.Error("500", $"获取数据失败: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取活动报警端点
|
|
/// </summary>
|
|
public class GetActiveAlarmsEndpoint : Endpoint<DeviceAlarmRequest, ApiResponse<List<DeviceAlarmResponse>>>
|
|
{
|
|
private readonly IFreeSql _freeSql;
|
|
|
|
public GetActiveAlarmsEndpoint(IFreeSql freeSql)
|
|
{
|
|
_freeSql = freeSql;
|
|
}
|
|
|
|
public override void Configure()
|
|
{
|
|
Get("/devicealarm/active");
|
|
AllowAnonymous();
|
|
Summary(s =>
|
|
{
|
|
s.Summary = "获取活动报警";
|
|
s.Description = "获取指定设备的所有活动(未结束)报警";
|
|
s.Response<ApiResponse<List<DeviceAlarmResponse>>>(200, "成功返回活动报警列表");
|
|
});
|
|
}
|
|
|
|
public override async Task HandleAsync(DeviceAlarmRequest req, CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
var data = await DeviceAlarmData.GetActiveAlarms(_freeSql, req.DeviceCode);
|
|
Response = ApiResponse<List<DeviceAlarmResponse>>.Success(data, "success");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Response = ApiResponse<List<DeviceAlarmResponse>>.Error("500", $"获取数据失败: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|