|
@ -11,7 +11,6 @@ using CellularManagement.Domain.Entities.Device; |
|
|
using CellularManagement.Domain.Repositories.Device; |
|
|
using CellularManagement.Domain.Repositories.Device; |
|
|
using CellularManagement.Domain.Repositories.Base; |
|
|
using CellularManagement.Domain.Repositories.Base; |
|
|
using CellularManagement.Infrastructure.Repositories.Base; |
|
|
using CellularManagement.Infrastructure.Repositories.Base; |
|
|
using CellularManagement.Domain.Models; |
|
|
|
|
|
|
|
|
|
|
|
namespace CellularManagement.Infrastructure.Repositories.Device; |
|
|
namespace CellularManagement.Infrastructure.Repositories.Device; |
|
|
|
|
|
|
|
@ -251,18 +250,17 @@ public class CellularDeviceRuntimeRepository : BaseRepository<CellularDeviceRunt |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 根据设备编号列表批量获取运行时状态(每个设备只返回最新的一条记录,支持多种状态过滤)
|
|
|
/// 根据设备编号列表批量获取运行时状态(每个设备只返回最新的一条记录,支持多种状态过滤)
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public async Task<IList<DeviceRuntimeDto>> GetRuntimesByDeviceCodesAsync(IEnumerable<string> deviceCodes, IEnumerable<DeviceRuntimeStatus>? runtimeStatuses = null, CancellationToken cancellationToken = default) |
|
|
public async Task<IList<CellularDeviceRuntime>> GetRuntimesByDeviceCodesAsync(IEnumerable<string> deviceCodes, IEnumerable<DeviceRuntimeStatus>? runtimeStatuses = null, CancellationToken cancellationToken = default) |
|
|
{ |
|
|
{ |
|
|
var deviceCodeList = deviceCodes.ToList(); |
|
|
var deviceCodeList = deviceCodes.ToList(); |
|
|
if (!deviceCodeList.Any()) |
|
|
if (!deviceCodeList.Any()) |
|
|
{ |
|
|
{ |
|
|
return new List<DeviceRuntimeDto>(); |
|
|
return new List<CellularDeviceRuntime>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 构建SQL查询,只返回需要的字段
|
|
|
// 构建SQL查询,支持多种状态过滤
|
|
|
var sql = @"
|
|
|
var sql = @"
|
|
|
SELECT DISTINCT ON (""DeviceCode"") |
|
|
SELECT DISTINCT ON (""DeviceCode"") * |
|
|
""DeviceCode"", ""RuntimeStatus"", ""RuntimeCode"", ""NetworkStackCode"" |
|
|
|
|
|
FROM ""tb_cellular_device_runtimes"" |
|
|
FROM ""tb_cellular_device_runtimes"" |
|
|
WHERE ""DeviceCode"" = ANY(@deviceCodes)";
|
|
|
WHERE ""DeviceCode"" = ANY(@deviceCodes)";
|
|
|
|
|
|
|
|
@ -278,8 +276,7 @@ public class CellularDeviceRuntimeRepository : BaseRepository<CellularDeviceRunt |
|
|
|
|
|
|
|
|
sql += @" ORDER BY ""DeviceCode"", ""CreatedAt"" DESC"; |
|
|
sql += @" ORDER BY ""DeviceCode"", ""CreatedAt"" DESC"; |
|
|
|
|
|
|
|
|
// 使用DeviceRuntimeDto来接收SQL查询结果
|
|
|
var result = await ExecuteSqlQueryAsync<CellularDeviceRuntime>(sql, parameters.ToArray(), cancellationToken); |
|
|
var result = await ExecuteSqlQueryAsync<DeviceRuntimeDto>(sql, parameters.ToArray(), cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
var statusFilterText = runtimeStatuses != null && runtimeStatuses.Any() |
|
|
var statusFilterText = runtimeStatuses != null && runtimeStatuses.Any() |
|
|
? string.Join(",", runtimeStatuses.Select(s => s.ToString())) |
|
|
? string.Join(",", runtimeStatuses.Select(s => s.ToString())) |
|
|