2021-08-27 17:55:22 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
2021-08-02 11:39:39 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
2021-08-27 17:55:22 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Cache;
|
2021-08-02 11:39:39 +05:00
|
|
|
|
using Mapster;
|
2021-08-24 10:59:10 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-08-27 17:55:22 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-08-02 11:39:39 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public class LastDataService : ILastDataService
|
2021-08-02 11:39:39 +05:00
|
|
|
|
{
|
|
|
|
|
private readonly IAsbCloudDbContext db;
|
2021-08-27 17:55:22 +05:00
|
|
|
|
private readonly CacheTable<LastDataCategory> cacheCategories;
|
2021-08-02 11:39:39 +05:00
|
|
|
|
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public LastDataService(IAsbCloudDbContext db, Cache.CacheDb cacheDb)
|
2021-08-02 11:39:39 +05:00
|
|
|
|
{
|
|
|
|
|
this.db = db;
|
2021-08-27 17:55:22 +05:00
|
|
|
|
cacheCategories = cacheDb.GetCachedTable<LastDataCategory>((DbContext)db);
|
2021-08-02 11:39:39 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public async Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token)
|
2021-08-02 11:39:39 +05:00
|
|
|
|
{
|
2021-08-27 17:55:22 +05:00
|
|
|
|
var entities = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
|
|
|
|
|
var dto = entities.ToDictionary(e=>e.Id, e=>e.Name);
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
2021-08-02 11:39:39 +05:00
|
|
|
|
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public async Task<IEnumerable<LastDataDto>> GetAllLastAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var entities = await db.LastData
|
|
|
|
|
.Include(e => e.Category)
|
|
|
|
|
.Where(e => e.IdWell == idWell)
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.ToListAsync(token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
var dtos = entities.Adapt<LastDataDto, LastData>((d, s) => d.CategoryName = s.Category.Name);
|
|
|
|
|
return dtos;
|
|
|
|
|
}
|
2021-08-02 12:23:18 +05:00
|
|
|
|
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public Task<IEnumerable<LastDataDto>> GetHisoryAsync(int idWell, int idCategory, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
throw new System.NotImplementedException();
|
2021-08-02 11:39:39 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public Task<int> InsertAsync(int idWell, LastDataDto data, CancellationToken token)
|
2021-08-02 11:39:39 +05:00
|
|
|
|
{
|
2021-08-27 17:55:22 +05:00
|
|
|
|
throw new System.NotImplementedException();
|
|
|
|
|
}
|
2021-08-02 12:23:18 +05:00
|
|
|
|
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public Task<int> MarkAsDeleteAsync(int idWell, int idData, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
throw new System.NotImplementedException();
|
|
|
|
|
}
|
2021-08-02 12:23:18 +05:00
|
|
|
|
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public Task<int> UpdateAsync(int idWell, LastDataDto data, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
throw new System.NotImplementedException();
|
|
|
|
|
}
|
2021-08-02 12:23:18 +05:00
|
|
|
|
|
2021-08-27 17:55:22 +05:00
|
|
|
|
public Task<int> DeleteAsync(int idWell, int idData, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
throw new System.NotImplementedException();
|
2021-08-02 11:39:39 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|