提交 0aa1c04f 编写于 作者: 麦壳饼's avatar 麦壳饼

重新调整获取最新数据的方式

上级 78ccf964
......@@ -19,6 +19,7 @@ namespace IoTSharp.Storage
private readonly AppSettings _appSettings;
readonly ILogger _logger;
readonly IServiceScope scope;
private readonly ApplicationDbContext _context;
public EFStorage(ILogger<EFStorage> logger, IServiceScopeFactory scopeFactor
, IOptions<AppSettings> options
......@@ -27,62 +28,47 @@ namespace IoTSharp.Storage
_appSettings = options.Value;
_logger = logger;
scope = scopeFactor.CreateScope();
_context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
}
public Task<List<TelemetryDataDto>> GetTelemetryLatest(Guid deviceId)
{
using (var _context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
{
{
var devid = from t in _context.TelemetryLatest where t.DeviceId == deviceId
select new TelemetryDataDto() { DateTime = t.DateTime, KeyName = t.KeyName, Value =t.ToObject() };
return devid.ToListAsync();
}
}
public Task<List<TelemetryDataDto>> GetTelemetryLatest(Guid deviceId, string keys)
{
using (var _context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
{
var devid = from t in _context.TelemetryLatest
where t.DeviceId == deviceId && keys.Split(',', ' ', ';').Contains(t.KeyName)
select new TelemetryDataDto() { DateTime = t.DateTime, KeyName = t.KeyName, Value = t.ToObject() };
return devid.ToListAsync();
}
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, string keys, DateTime begin)
{
using (var _context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
{
var kv = from t in _context.TelemetryData
where t.DeviceId == deviceId && keys.Split(',', ' ', ';').Contains(t.KeyName) && t.DateTime >= begin
select new TelemetryDataDto() { DateTime=t.DateTime, KeyName=t.KeyName, Value= t.ToObject() };
return kv.ToListAsync();
}
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, string keys, DateTime begin, DateTime end)
{
using (var _context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
{
var kv = from t in _context.TelemetryData
where t.DeviceId == deviceId && keys.Split(',', ' ', ';').Contains(t.KeyName) && t.DateTime >= begin && t.DateTime < end
select new TelemetryDataDto() { DateTime = t.DateTime, KeyName = t.KeyName, Value = t.ToObject() };
return kv.ToListAsync();
}
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, DateTime begin)
{
using (var _context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
{
var kv = from t in _context.TelemetryData where t.DeviceId == deviceId && t.DateTime >= begin
select new TelemetryDataDto() { DateTime = t.DateTime, KeyName = t.KeyName, Value = t.ToObject() };
return kv.ToListAsync();
}
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, DateTime begin, DateTime end)
......
......@@ -23,6 +23,7 @@ namespace IoTSharp.Storage
private readonly AppSettings _appSettings;
private readonly ILogger _logger;
private readonly IServiceScope scope;
private readonly ApplicationDbContext _context;
public ShardingStorage(ILogger<ShardingStorage> logger, IServiceScopeFactory scopeFactor
, IOptions<AppSettings> options
......@@ -31,31 +32,26 @@ namespace IoTSharp.Storage
_appSettings = options.Value;
_logger = logger;
scope = scopeFactor.CreateScope();
_context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
}
public Task<List<TelemetryDataDto>> GetTelemetryLatest(Guid deviceId)
{
using (var _context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
{
var devid = from t in _context.TelemetryLatest
where t.DeviceId == deviceId
select new TelemetryDataDto() { DateTime = t.DateTime, KeyName = t.KeyName, Value = t.ToObject() };
return devid.ToListAsync();
}
}
public Task<List<TelemetryDataDto>> GetTelemetryLatest(Guid deviceId, string keys)
{
using (var _context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
{
var devid = from t in _context.TelemetryLatest
where t.DeviceId == deviceId && keys.Split(',', ' ', ';').Contains(t.KeyName)
select new TelemetryDataDto() { DateTime = t.DateTime, KeyName = t.KeyName, Value = t.ToObject() };
return devid.ToListAsync();
}
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, string keys, DateTime begin)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册