STATS:
- Update visualizzazione ODL ed Energy
This commit is contained in:
+152
-52
@@ -30,9 +30,10 @@ namespace MP.Stats.Data
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MpStatsService(IConfiguration configuration, ILogger<MpStatsService> logger)
|
||||
public MpStatsService(IConfiguration configuration)
|
||||
{
|
||||
_logger = logger;
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
sw.Start();
|
||||
_configuration = configuration;
|
||||
|
||||
// setup compoenti REDIS
|
||||
@@ -43,14 +44,14 @@ namespace MP.Stats.Data
|
||||
string connStr = _configuration.GetConnectionString("MP.Stats");
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
{
|
||||
_logger.LogError("ConnString empty!");
|
||||
Log.Error("MP.Stats: ConnString empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
dbController = new MP.Data.Controllers.MpStatsController(configuration);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"DbController OK");
|
||||
_logger.LogInformation(sb.ToString());
|
||||
InitDict();
|
||||
sw.Stop();
|
||||
Log.Info($"MpStatsService | MpStatsController OK | {sw.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +96,39 @@ namespace MP.Stats.Data
|
||||
result = new List<AzioniUL>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"ActionsGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"ActionsGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<AnagFLTransModel>> AnagFLTransGetAll()
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<AnagFLTransModel> result = new List<AnagFLTransModel>();
|
||||
// cerco in redis...
|
||||
DateTime adesso = DateTime.Now;
|
||||
string currKey = $"{redisBaseKey}:Cache:FLTrans";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<AnagFLTransModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.AnagFLTransGetAll();
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<AnagFLTransModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"AnagFLTransGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -127,23 +160,6 @@ namespace MP.Stats.Data
|
||||
return Task.FromResult(answ);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Aggiorna record calcolando prossima scadenza dato ultima esecuzione
|
||||
/// </summary>
|
||||
/// <param name="taskRec"></param>
|
||||
/// <returns></returns>
|
||||
public DateTime CalcNextExe(TaskListModel? taskRec)
|
||||
{
|
||||
DateTime dtNext = DateTime.Today;
|
||||
if (taskRec != null)
|
||||
{
|
||||
dtNext = dbController.CalcNextExe(taskRec);
|
||||
}
|
||||
return dtNext;
|
||||
}
|
||||
#endif
|
||||
|
||||
public Task<List<AutocompleteModel>> CommesseGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<AutocompleteModel> answ = new List<AutocompleteModel>();
|
||||
@@ -155,6 +171,41 @@ namespace MP.Stats.Data
|
||||
return Task.FromResult(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero elenco config
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfigModel>> ConfigGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<ConfigModel>? result = new List<ConfigModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{redisBaseKey}:Conf";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
//if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<ConfigModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.ConfigGetAll();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, LongCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database controller
|
||||
@@ -164,22 +215,6 @@ namespace MP.Stats.Data
|
||||
redisDb = null;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Chiamata esecuzione di un singolo task programmato
|
||||
/// </summary>
|
||||
/// <param name="TaskId"></param>
|
||||
/// <param name="SchedNext">Se true rischedula successiva chiamata</param>
|
||||
/// <returns></returns>
|
||||
public async Task<TaskResultModel> ExecuteTask(int TaskId, bool SchedNext)
|
||||
{
|
||||
TaskResultModel dbResult = dbController.ExecuteTask(TaskId, SchedNext);
|
||||
// svuoto cache!
|
||||
await FlushCache("Task");
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Pulizia cache Redis (tutta)
|
||||
/// </summary>
|
||||
@@ -188,6 +223,10 @@ namespace MP.Stats.Data
|
||||
{
|
||||
RedisValue pattern = new RedisValue($"{redisBaseKey}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
|
||||
// rileggo conf UM!
|
||||
var rawData = await AnagFLTransGetAll();
|
||||
DictFluxUm = rawData.ToDictionary(kvp => $"{kvp.CodFluxOut}", kvp => kvp.UM);
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -202,6 +241,20 @@ namespace MP.Stats.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce UM del flusso configurato
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string FluxGetUM(string codFlux)
|
||||
{
|
||||
string answ = "#";
|
||||
if (DictFluxUm.ContainsKey(codFlux))
|
||||
{
|
||||
answ = DictFluxUm[codFlux];
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
public async Task<List<Macchine>> MacchineGetAll()
|
||||
{
|
||||
// setup parametri costanti
|
||||
@@ -230,7 +283,7 @@ namespace MP.Stats.Data
|
||||
result = new List<Macchine>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"MacchineGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"MacchineGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -303,7 +356,7 @@ namespace MP.Stats.Data
|
||||
.ToList();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"StatControlliGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatControlliGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -335,7 +388,7 @@ namespace MP.Stats.Data
|
||||
result = new List<DdbTurni>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"StatDdbGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatDdbGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -354,7 +407,7 @@ namespace MP.Stats.Data
|
||||
dbResult = dbController.StatDdbGetAll(CurrFilter.DateStart, CurrFilter.DateEnd, CurrFilter.IdxMacchina, CurrFilter.IdxOdl, CurrFilter.KeyRichiesta, CurrFilter.CodArticolo, 1, 0);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
_logger.LogTrace($"Effettuata lettura COMPLETA da DB + caching per StatDdbGetAllExport: {ts.TotalMilliseconds} ms");
|
||||
Log.Trace($"Effettuata lettura COMPLETA da DB + caching per StatDdbGetAllExport: {ts.TotalMilliseconds} ms");
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
@@ -382,7 +435,7 @@ namespace MP.Stats.Data
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"StatDdbGetCount | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatDdbGetCount | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return numRec;
|
||||
}
|
||||
|
||||
@@ -420,7 +473,7 @@ namespace MP.Stats.Data
|
||||
result = new List<OdlEnergyModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"StatOdlEnergyGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatOdlEnergyGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -458,7 +511,7 @@ namespace MP.Stats.Data
|
||||
result = new List<StatsODL>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"StatOdlEnergyGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatOdlEnergyGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -490,7 +543,7 @@ namespace MP.Stats.Data
|
||||
result = new List<ResScarti>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"StatScartiGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatScartiGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -527,7 +580,7 @@ namespace MP.Stats.Data
|
||||
result = new List<TurniOee>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"StatTurniOeeGetAllCached | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatTurniOeeGetAllCached | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -559,10 +612,44 @@ namespace MP.Stats.Data
|
||||
result = new List<UserActionLog>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"StatUserLogGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
Log.Debug($"StatUserLogGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero vocabolario
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<VocabolarioModel>> VocabolarioGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<VocabolarioModel> result = new List<VocabolarioModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{redisBaseKey}:Vocabolario";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
//if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<VocabolarioModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.VocabolarioGetAll();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, LongCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<VocabolarioModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Debug($"VocabolarioGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -572,6 +659,11 @@ namespace MP.Stats.Data
|
||||
|
||||
protected static string connStringFatt = "";
|
||||
|
||||
/// <summary>
|
||||
/// Vocabolario x recupero rapido traduzioni
|
||||
/// </summary>
|
||||
protected static Dictionary<string, string> DictFluxUm = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
@@ -604,14 +696,22 @@ namespace MP.Stats.Data
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
|
||||
private static ILogger<MpStatsService> _logger;
|
||||
|
||||
private string redisBaseKey = "MP:STATS";
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Inizializzazione dict vari
|
||||
/// </summary>
|
||||
private static void InitDict()
|
||||
{
|
||||
// inizializzo dizionario vocabolario
|
||||
var rawData = dbController.AnagFLTransGetAll();
|
||||
DictFluxUm = rawData.ToDictionary(kvp => $"{kvp.CodFluxOut}", kvp => kvp.UM);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user