forked from ddrilling/AsbCloudServer
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Repositories;
|
|
using AsbCloudDb.Model;
|
|
using Mapster;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Repository
|
|
{
|
|
public class DataSaubStatRepository : IDataSaubStatRepository
|
|
{
|
|
private readonly IAsbCloudDbContext db;
|
|
|
|
public DataSaubStatRepository(IAsbCloudDbContext dbContext)
|
|
{
|
|
db = dbContext;
|
|
}
|
|
|
|
public async Task<IEnumerable<DataSaubStatDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token)
|
|
{
|
|
var stats = await db.Set<DataSaubStat>()
|
|
.Where(s => idTelemetries.Contains(s.IdTelemetry))
|
|
.GroupBy(s => s.IdTelemetry, (key, group) => group.OrderByDescending(el => el.DateEnd).First().Adapt<DataSaubStatDto>())
|
|
.ToArrayAsync(token);
|
|
|
|
return stats;
|
|
}
|
|
|
|
public async Task<int> InsertRangeAsync(IEnumerable<DataSaubStatDto> dataSaubStats, CancellationToken token)
|
|
{
|
|
var entities = dataSaubStats.Select(data => data.Adapt<DataSaubStat>());
|
|
db.Set<DataSaubStat>().AddRange(entities);
|
|
return await db.SaveChangesAsync(token);
|
|
}
|
|
}
|
|
}
|