Modifica model macchine

This commit is contained in:
Samuele E. Locatelli
2025-06-28 09:20:48 +02:00
parent 1ec3aa58d4
commit 2d83e27d89
27 changed files with 353 additions and 263 deletions
+72 -55
View File
@@ -16,6 +16,14 @@ namespace MP.AppAuth.Controllers
#endregion Public Fields
#region Private Fields
private static IConfiguration _configuration;
private static Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Public Constructors
public MPController(IConfiguration configuration)
@@ -92,54 +100,6 @@ namespace MP.AppAuth.Controllers
return dbResult;
}
/// <summary>
/// Elenco Record x AnagMicroStati
/// </summary>
/// <returns></returns>
public List<AnagraficaMicroStati> AnagMicroStati()
{
List<AnagraficaMicroStati> dbResult = new List<AnagraficaMicroStati>();
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
{
dbResult = localDbCtx
.DbSetAnagMicroStati
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco Record x AnagraficaStati
/// </summary>
/// <returns></returns>
public List<AnagraficaStati> AnagStati()
{
List<AnagraficaStati> dbResult = new List<AnagraficaStati>();
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
{
dbResult = localDbCtx
.DbSetAnagStati
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco Record x ListValues
/// </summary>
/// <returns></returns>
public List<ListValues> ListValues()
{
List<ListValues> dbResult = new List<ListValues>();
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
{
dbResult = localDbCtx
.DbSetListValue
.ToList();
}
return dbResult;
}
/// <summary>
/// Delete Record AnagKeyValue
/// </summary>
@@ -210,6 +170,38 @@ namespace MP.AppAuth.Controllers
return fatto;
}
/// <summary>
/// Elenco Record x AnagMicroStati
/// </summary>
/// <returns></returns>
public List<AnagraficaMicroStati> AnagMicroStati()
{
List<AnagraficaMicroStati> dbResult = new List<AnagraficaMicroStati>();
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
{
dbResult = localDbCtx
.DbSetAnagMicroStati
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco Record x AnagraficaStati
/// </summary>
/// <returns></returns>
public List<AnagraficaStati> AnagStati()
{
List<AnagraficaStati> dbResult = new List<AnagraficaStati>();
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
{
dbResult = localDbCtx
.DbSetAnagStati
.ToList();
}
return dbResult;
}
/// <summary>
/// Delete Record Config
/// </summary>
@@ -288,6 +280,38 @@ namespace MP.AppAuth.Controllers
}
}
/// <summary>
/// Elenco Record x ListValues
/// </summary>
/// <returns></returns>
public List<ListValues> ListValues()
{
List<ListValues> dbResult = new List<ListValues>();
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
{
dbResult = localDbCtx
.DbSetListValue
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco Record Macchine
/// </summary>
/// <returns></returns>
public List<MacchineModel> MacchineGetAll()
{
List<MacchineModel> dbResult = new List<MacchineModel>();
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
{
dbResult = localDbCtx
.DbSetMacchine
.ToList();
}
return dbResult;
}
/// <summary>
/// Delete Record Vocabolario
/// </summary>
@@ -356,12 +380,5 @@ namespace MP.AppAuth.Controllers
}
#endregion Public Methods
#region Private Fields
private static IConfiguration _configuration;
private static Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
}
}
@@ -1,24 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
#nullable disable
namespace MP.AppAuth.Models
{
public partial class Macchine
[Table("Macchine")]
public partial class MacchineModel
{
#region Public Properties
public string CodMacchina { get; set; }
public int ColNum { get; set; }
public string Css { get; set; }
public string Descrizione { get; set; }
public string IdxMacchina { get; set; }
public string Locazione { get; set; }
public string CodMacchina { get; set; }
public string Nome { get; set; }
public string Descrizione { get; set; }
public string Locazione { get; set; }
public string Note { get; set; }
public int RowNum { get; set; }
public string Css { get; set; }
public string Url { get; set; }
public int ColNum { get; set; }
public int RowNum { get; set; }
#endregion Public Properties
}
+3 -3
View File
@@ -70,7 +70,7 @@ namespace MP.AppAuth
public virtual DbSet<KeepAlive> DbSetKeepAlive { get; set; }
public virtual DbSet<LinkMenuJqm> DbSetLinkMenuJqm { get; set; }
public virtual DbSet<ListValues> DbSetListValue { get; set; }
public virtual DbSet<Macchine> DbSetMacchine { get; set; }
public virtual DbSet<MacchineModel> DbSetMacchine { get; set; }
public virtual DbSet<UpdMan> DbSetUpdMan { get; set; }
public virtual DbSet<VocabolarioModel> DbSetVocabolario { get; set; }
@@ -410,11 +410,11 @@ namespace MP.AppAuth
entity.Property(e => e.Ordinal).HasColumnName("ordinal");
});
modelBuilder.Entity<Macchine>(entity =>
modelBuilder.Entity<MacchineModel>(entity =>
{
entity.HasKey(e => e.IdxMacchina);
entity.ToTable("Macchine");
//entity.ToTable("Macchine");
entity.Property(e => e.IdxMacchina).HasMaxLength(50);
+177 -142
View File
@@ -26,6 +26,54 @@ namespace MP.AppAuth.Services
#endregion Public Fields
#region Private Fields
// gestione key Redis
private const string redisBaseAddr = "MP:LAND";
private const string rKeyDirittiUser = $"{redisBaseAddr}:DIR_USER";
private const string rKeyMacchine = $"{redisBaseAddr}:MACCHINE";
private const string rKeyPermUser = $"{redisBaseAddr}:PERM_USER";
private static IConfiguration _configuration;
private static ILogger<AppAuthService> _logger;
private static JsonSerializerSettings? JSSettings;
private static Logger Log = LogManager.GetCurrentClassLogger();
private static string Modulo = "";
/// <summary>
/// Durata cache lunga IN SECONDI
/// </summary>
private int cacheTtlLong = 60 * 5;
/// <summary>
/// Durata cache breve IN SECONDI
/// </summary>
private int cacheTtlShort = 60 * 1;
/// <summary>
/// Oggetto per connessione a REDIS
/// </summary>
private IConnectionMultiplexer redisConn;
//ISubscriber sub = redis.GetSubscriber();
/// <summary>
/// Oggetto DB redis da impiegare x chiamate R/W
/// </summary>
private StackExchange.Redis.IDatabase redisDb = null!;
private Random rnd = new Random();
private Dictionary<string, string> Vocabolario = new Dictionary<string, string>();
#endregion Private Fields
#region Public Constructors
public AppAuthService(IConfiguration configuration, ILogger<AppAuthService> logger, IConnectionMultiplexer redisConnMult)
@@ -64,6 +112,36 @@ namespace MP.AppAuth.Services
#endregion Public Constructors
#region Private Properties
private string CodApp { get; set; } = "";
/// <summary>
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
/// </summary>
private TimeSpan FastCache
{
get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000);
}
/// <summary>
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
/// </summary>
private TimeSpan LongCache
{
get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000);
}
/// <summary>
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
/// </summary>
private TimeSpan UltraLongCache
{
get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000);
}
#endregion Private Properties
#region Public Methods
/// <summary>
@@ -114,54 +192,6 @@ namespace MP.AppAuth.Services
return await Task.FromResult(dbResult);
}
/// <summary>
/// Lista AnagEventi
/// </summary>
/// <returns></returns>
public async Task<List<AnagraficaIngressi>> AnagIngressi()
{
List<AnagraficaIngressi> dbResult = new List<AnagraficaIngressi>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = MpDbController.AnagIngressi();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per AnagIngressi: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
/// <summary>
/// Lista AnagEventi
/// </summary>
/// <returns></returns>
public async Task<List<AnagraficaMicroStati>> AnagMicroStati()
{
List<AnagraficaMicroStati> dbResult = new List<AnagraficaMicroStati>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = MpDbController.AnagMicroStati();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per AnagMicroStati: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
/// <summary>
/// Lista AnagStati
/// </summary>
/// <returns></returns>
public async Task<List<AnagraficaStati>> AnagStati()
{
List<AnagraficaStati> dbResult = new List<AnagraficaStati>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = MpDbController.AnagStati();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per AnagStati: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
/// <summary>
/// Lista Gruppi
/// </summary>
@@ -178,22 +208,6 @@ namespace MP.AppAuth.Services
return await Task.FromResult(dbResult);
}
/// <summary>
/// Elenco ListValues
/// </summary>
/// <returns></returns>
public async Task<List<ListValues>> ListValues()
{
List<ListValues> dbResult = new List<ListValues>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = MpDbController.ListValues();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per ListValues: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
public async Task<List<AnagraficaGruppi>> AnagGruppiFilt(string codTipo)
{
List<AnagraficaGruppi> dbResult = new List<AnagraficaGruppi>();
@@ -206,6 +220,22 @@ namespace MP.AppAuth.Services
return await Task.FromResult(dbResult);
}
/// <summary>
/// Lista AnagEventi
/// </summary>
/// <returns></returns>
public async Task<List<AnagraficaIngressi>> AnagIngressi()
{
List<AnagraficaIngressi> dbResult = new List<AnagraficaIngressi>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = MpDbController.AnagIngressi();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per AnagIngressi: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
public async Task<bool> AnagKeyValAdd(AnagKeyValueModel currRec)
{
bool answ = false;
@@ -254,6 +284,22 @@ namespace MP.AppAuth.Services
return await Task.FromResult(answ);
}
/// <summary>
/// Lista AnagEventi
/// </summary>
/// <returns></returns>
public async Task<List<AnagraficaMicroStati>> AnagMicroStati()
{
List<AnagraficaMicroStati> dbResult = new List<AnagraficaMicroStati>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = MpDbController.AnagMicroStati();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per AnagMicroStati: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
public async Task<List<AnagraficaOperatori>> AnagOperByGroupList(string codGruppo, string searchVal)
{
List<AnagraficaOperatori> dbResult = new List<AnagraficaOperatori>();
@@ -283,6 +329,22 @@ namespace MP.AppAuth.Services
return await Task.FromResult(dbResult);
}
/// <summary>
/// Lista AnagStati
/// </summary>
/// <returns></returns>
public async Task<List<AnagraficaStati>> AnagStati()
{
List<AnagraficaStati> dbResult = new List<AnagraficaStati>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = MpDbController.AnagStati();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per AnagStati: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
public async Task<bool> ConfigAdd(ConfigModel currRec)
{
bool answ = false;
@@ -382,6 +444,57 @@ namespace MP.AppAuth.Services
CheckVoc();
}
/// <summary>
/// Elenco ListValues
/// </summary>
/// <returns></returns>
public async Task<List<ListValues>> ListValues()
{
List<ListValues> dbResult = new List<ListValues>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = MpDbController.ListValues();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per ListValues: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
/// <summary>
/// Elenco Macchine gestite
/// </summary>
/// <param name="UserName"></param>
/// <returns></returns>
public List<MacchineModel> MacchineGetAll()
{
string source = "DB";
List<MacchineModel>? dbResult = new List<MacchineModel>();
string currKey = $"{rKeyMacchine}";
Stopwatch sw = new Stopwatch();
sw.Start();
string? rawData = redisDb.StringGet(currKey);
if (!string.IsNullOrEmpty(rawData) && rawData.Length > 2)
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<MacchineModel>>(rawData);
dbResult = tempResult ?? new List<MacchineModel>();
}
else
{
// recupero diritti utente
dbResult = MpDbController.MacchineGetAll();
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
redisDb.StringSet(currKey, rawData, UltraLongCache);
}
if (dbResult == null)
{
dbResult = new List<MacchineModel>();
}
sw.Stop();
Log.Debug($"MacchineGetAll | {source} | {sw.ElapsedMilliseconds} ms");
return dbResult;
}
/// <summary>
/// Elenco permessi dato utente
/// </summary>
@@ -539,84 +652,6 @@ namespace MP.AppAuth.Services
#endregion Protected Methods
#region Private Fields
// gestione key Redis
private const string redisBaseAddr = "MP:LAND";
private const string rKeyDirittiUser = $"{redisBaseAddr}:DIR_USER";
private const string rKeyPermUser = $"{redisBaseAddr}:PERM_USER";
private static IConfiguration _configuration;
private static ILogger<AppAuthService> _logger;
private static List<Macchine> ElencoMacchine = new List<Macchine>();
private static JsonSerializerSettings? JSSettings;
private static Logger Log = LogManager.GetCurrentClassLogger();
private static string Modulo = "";
/// <summary>
/// Durata cache lunga IN SECONDI
/// </summary>
private int cacheTtlLong = 60 * 5;
/// <summary>
/// Durata cache breve IN SECONDI
/// </summary>
private int cacheTtlShort = 60 * 1;
/// <summary>
/// Oggetto per connessione a REDIS
/// </summary>
private IConnectionMultiplexer redisConn;
//ISubscriber sub = redis.GetSubscriber();
/// <summary>
/// Oggetto DB redis da impiegare x chiamate R/W
/// </summary>
private StackExchange.Redis.IDatabase redisDb = null!;
private Random rnd = new Random();
private Dictionary<string, string> Vocabolario = new Dictionary<string, string>();
#endregion Private Fields
#region Private Properties
private string CodApp { get; set; } = "";
/// <summary>
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
/// </summary>
private TimeSpan FastCache
{
get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000);
}
/// <summary>
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
/// </summary>
private TimeSpan LongCache
{
get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000);
}
/// <summary>
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
/// </summary>
private TimeSpan UltraLongCache
{
get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000);
}
#endregion Private Properties
#region Private Methods
/// <summary>