forked from ddrilling/AsbCloudServer
Drop useless method
This commit is contained in:
parent
91c85c8fdc
commit
638d8eb3da
@ -10,7 +10,6 @@ namespace AsbCloudApp.Services
|
|||||||
Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token);
|
Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token);
|
||||||
Task<MeasureDto> GetLastAsync(int idWell, int idCategory, CancellationToken token);
|
Task<MeasureDto> GetLastAsync(int idWell, int idCategory, CancellationToken token);
|
||||||
Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, CancellationToken token);
|
Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, CancellationToken token);
|
||||||
Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token);
|
|
||||||
Task<int> InsertAsync(int idWell, MeasureDto data, CancellationToken token);
|
Task<int> InsertAsync(int idWell, MeasureDto data, CancellationToken token);
|
||||||
Task<int> UpdateAsync(int idWell, MeasureDto data, CancellationToken token);
|
Task<int> UpdateAsync(int idWell, MeasureDto data, CancellationToken token);
|
||||||
Task<int> MarkAsDeleteAsync(int idWell, int idData, CancellationToken token);
|
Task<int> MarkAsDeleteAsync(int idWell, int idData, CancellationToken token);
|
||||||
|
@ -47,42 +47,6 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token)
|
|
||||||
{
|
|
||||||
var categories = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
|
|
||||||
if (!categories.Any())
|
|
||||||
return default;
|
|
||||||
|
|
||||||
var queries = categories.Select(c => db.Measures.Include(m => m.Category)
|
|
||||||
.Where(m => m.IdWell == idWell && m.IdCategory == c.Id && !m.IsDeleted)
|
|
||||||
.OrderByDescending(m => m.Timestamp)
|
|
||||||
.Take(1)
|
|
||||||
);
|
|
||||||
|
|
||||||
var qi = queries.GetEnumerator();
|
|
||||||
qi.MoveNext();
|
|
||||||
var query = qi.Current;
|
|
||||||
while (qi.MoveNext())
|
|
||||||
query = query.Union(qi.Current);
|
|
||||||
|
|
||||||
//var query = db.Measures
|
|
||||||
// .Where(e => e.IdWell == idWell)
|
|
||||||
// .GroupBy(e => e.IdCategory)
|
|
||||||
// .Select(g => g.Where(e => e.Timestamp == g.Max(m => m.Timestamp)).First());
|
|
||||||
|
|
||||||
//var query = db.Measures
|
|
||||||
// .Where(m => m.IdWell == idWell && m.Timestamp == db.Measures
|
|
||||||
// .Where(subm => subm.IdWell == m.IdWell && subm.IdCategory == m.IdCategory).Max(subm => subm.Timestamp));
|
|
||||||
|
|
||||||
var entities = await query
|
|
||||||
.AsNoTracking()
|
|
||||||
.ToListAsync(token)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
var dtos = entities.Adapt<MeasureDto, Measure>((d, s) => d.CategoryName = s.Category?.Name);
|
|
||||||
return dtos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, CancellationToken token)
|
public async Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = db.Measures.Include(m => m.Category)
|
var query = db.Measures.Include(m => m.Category)
|
||||||
@ -105,6 +69,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (data.Data is null)
|
if (data.Data is null)
|
||||||
throw new ArgumentException("data.data is not optional", nameof(data));
|
throw new ArgumentException("data.data is not optional", nameof(data));
|
||||||
var entity = data.Adapt<Measure>();
|
var entity = data.Adapt<Measure>();
|
||||||
|
entity.IdWell = idWell;
|
||||||
db.Measures.Add(entity);
|
db.Measures.Add(entity);
|
||||||
return db.SaveChangesAsync(token);
|
return db.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
@ -122,10 +87,10 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.Where(m => m.Id == data.Id && !m.IsDeleted)
|
.Where(m => m.Id == data.Id && !m.IsDeleted)
|
||||||
.FirstOrDefaultAsync(token)
|
.FirstOrDefaultAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (entity is null)
|
if (entity is null)
|
||||||
throw new ArgumentException("id doesn't exist", nameof(data));
|
throw new ArgumentException("id doesn't exist", nameof(data));
|
||||||
|
|
||||||
|
entity.IdWell = idWell;
|
||||||
entity.Timestamp = data.Timestamp;
|
entity.Timestamp = data.Timestamp;
|
||||||
entity.Data = data.Data;
|
entity.Data = data.Data;
|
||||||
|
|
||||||
|
@ -32,17 +32,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
|
||||||
[Route("lastAll")]
|
|
||||||
public async Task<IActionResult> GetAllLastAsync([FromRoute] int idWell, CancellationToken token = default)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
var result = await measureService.GetAllLastAsync(idWell, token).ConfigureAwait(false);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("last/{idCategory}")]
|
[Route("last/{idCategory}")]
|
||||||
public async Task<IActionResult> GetLastAsync([FromRoute] int idWell, [FromRoute] int idCategory, CancellationToken token = default)
|
public async Task<IActionResult> GetLastAsync([FromRoute] int idWell, [FromRoute] int idCategory, CancellationToken token = default)
|
||||||
|
Loading…
Reference in New Issue
Block a user