45cb6b9f59
- aggiunta migrations - correzioni versione ef6 da ef8 - correzioni init varie
83 lines
2.5 KiB
C#
83 lines
2.5 KiB
C#
using EgwCoreLib.Utils;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.Data.DbModels.Utils;
|
|
using MP.Data.Repository.Utils;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data.Services.Utils
|
|
{
|
|
public class StatsAggrService : BaseServ, IStatsAggrService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public StatsAggrService(
|
|
IConfiguration config,
|
|
IConnectionMultiplexer redis,
|
|
IStatsAggrRepository repo) : base(config, redis)
|
|
{
|
|
_className = "StatsAggr";
|
|
_repo = repo;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<StatsAggregatedModel>> GetFiltAsync(DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
return await TraceAsync($"{_className}.GetFilt", async (activity) =>
|
|
{
|
|
return await GetOrSetCacheAsync(
|
|
$"{_redisBaseKey}:{_className}:DT:{dtStart:yyyyMMdd}:{dtEnd:yyyyMMdd}",
|
|
async () => await _repo.GetFiltAsync(dtStart, dtEnd),
|
|
UltraLongCache
|
|
);
|
|
});
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<DtUtils.Periodo> GetRangeAsync()
|
|
{
|
|
return await TraceAsync($"{_className}.GetRange", async (activity) =>
|
|
{
|
|
return await GetOrSetCacheAsync(
|
|
$"{_redisBaseKey}:{_className}:Range",
|
|
async () => await _repo.GetRangeAsync(),
|
|
UltraFastCache
|
|
);
|
|
});
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<int> UpsertManyAsync(List<StatsAggregatedModel> listRecords, bool removeOld)
|
|
{
|
|
return await TraceAsync($"{_className}.UpsertMany", async (activity) =>
|
|
{
|
|
string operation = "UpsertMany";
|
|
var success = await _repo.UpsertManyAsync(listRecords, removeOld);
|
|
|
|
activity?.SetTag("db.operation", operation);
|
|
|
|
if (success > 0)
|
|
{
|
|
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
|
}
|
|
|
|
return success;
|
|
});
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly string _className;
|
|
private readonly IStatsAggrRepository _repo;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |