forked from ddrilling/AsbCloudServer
70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudInfrastructure.Services.Cache;
|
|
using Mapster;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
{
|
|
public class LastDataService : ILastDataService
|
|
{
|
|
private readonly IAsbCloudDbContext db;
|
|
private readonly CacheTable<LastDataCategory> cacheCategories;
|
|
|
|
public LastDataService(IAsbCloudDbContext db, Cache.CacheDb cacheDb)
|
|
{
|
|
this.db = db;
|
|
cacheCategories = cacheDb.GetCachedTable<LastDataCategory>((DbContext)db);
|
|
}
|
|
|
|
public async Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token)
|
|
{
|
|
var entities = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
|
|
var dto = entities.ToDictionary(e=>e.Id, e=>e.Name);
|
|
return dto;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public Task<IEnumerable<LastDataDto>> GetHisoryAsync(int idWell, int idCategory, CancellationToken token)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public Task<int> InsertAsync(int idWell, LastDataDto data, CancellationToken token)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public Task<int> MarkAsDeleteAsync(int idWell, int idData, CancellationToken token)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public Task<int> UpdateAsync(int idWell, LastDataDto data, CancellationToken token)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public Task<int> DeleteAsync(int idWell, int idData, CancellationToken token)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
}
|
|
}
|