a876ac0495
- Update con statistiche DB calcolate - aggiunto obj connesisone cadmin con timeout a 5 minuti
260 lines
10 KiB
C#
260 lines
10 KiB
C#
using MP.Data.DatabaseModels;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data
|
|
{
|
|
public class Utils
|
|
{
|
|
#region Public Properties
|
|
|
|
public static string redKeyArtUsed
|
|
{
|
|
get => RedHash($"SPEC:Cache:CheckArtUsed");
|
|
}
|
|
|
|
public static string redKeyTabCheckArt
|
|
{
|
|
get => RedHash($"CACHE:TabCheckArt");
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public static string ConvMinToTime(double minutes)
|
|
{
|
|
// FIXME TODO: da rendere parametrico da appsettings.json...
|
|
var ts = TimeSpan.FromMinutes(minutes);
|
|
string answ = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}"; //.{ts.Milliseconds}
|
|
return answ;
|
|
}
|
|
|
|
public static string ConvMsecToTime(long milliseconds)
|
|
{
|
|
// FIXME TODO: da rendere parametrico da appsettings.json...
|
|
var ts = TimeSpan.FromMilliseconds(milliseconds);
|
|
string answ = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}"; //.{ts.Milliseconds}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hash dati STATUS x la macchina specificata
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public static RedisKey dtMaccHash(string idxMacchina)
|
|
{
|
|
return (RedisKey)$"{redisBaseAddr}DtMac:{idxMacchina}";
|
|
}
|
|
|
|
public static string FormDurata(double durataMinuti)
|
|
{
|
|
string answ = "";
|
|
TimeSpan tsDurata = TimeSpan.FromMinutes(durataMinuti);
|
|
if (tsDurata.TotalDays < 1)
|
|
{
|
|
answ = $"{tsDurata.Hours:00}h {tsDurata.Minutes:00}'";
|
|
}
|
|
else
|
|
{
|
|
answ = $"{tsDurata.Days}gg {tsDurata.Hours:00}h";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// RedisKey calcolata x tabella HSI
|
|
/// </summary>
|
|
/// <param name="idxFamIn"></param>
|
|
/// <returns></returns>
|
|
public static RedisKey hSMI(int idxFamIn)
|
|
{
|
|
return (RedisKey)$"{redisBaseAddr}hSMI:{idxFamIn}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inizializzazione con periodo e arrotondamento
|
|
/// </summary>
|
|
/// <param name="minRound"></param>
|
|
/// <returns></returns>
|
|
public static DateTime InitDatetime(DateTime dtRif, int minRound)
|
|
{
|
|
TimeSpan DayElapsed = dtRif.Subtract(dtRif.Date);
|
|
int minDay = (int)Math.Ceiling((double)(DayElapsed.TotalMinutes / minRound)) * minRound;
|
|
DateTime endRounded = DateTime.Today.AddMinutes(minDay);
|
|
return endRounded;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Nome della variabile HASH da utilizzare (dato CodModulo / Server / DB impiegato
|
|
/// dafunzionalita' DbConfig) + idxMacchina richiesto...
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public static RedisKey OptParHash(string idxMacchina)
|
|
{
|
|
return (RedisKey)$"{redisBaseAddr}OpPar:{idxMacchina}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Nome della variabile HASH da utilizzare (dato CodModulo / Server / DB impiegato da
|
|
/// funzionalita' DbConfig) + idxMacchina richiesto...
|
|
/// </summary>
|
|
public static RedisKey RedHash(string keyName)
|
|
{
|
|
return (RedisKey)$"MP:Data:{keyName}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Formato RedisKey delal chaive richeista (completa)
|
|
/// </summary>
|
|
public static RedisKey RedKeyHash(string keyName)
|
|
{
|
|
return (RedisKey)$"{redisBaseAddr}{keyName}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Formato RedisValue delal chaive richeista (completa)
|
|
/// </summary>
|
|
public static RedisValue RedValue(string keyName)
|
|
{
|
|
return (RedisValue)$"{redisBaseAddr}{keyName}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua salvataggio in file di un generico oggetto in formato CSV
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="reportData"></param>
|
|
/// <param name="path"></param>
|
|
/// <param name="separator">Separatore da impiegare</param>
|
|
/// <returns></returns>
|
|
public static async Task SaveToCsv<T>(List<T> reportData, string path, char separator)
|
|
{
|
|
var lines = new List<string>();
|
|
IEnumerable<PropertyDescriptor> props = TypeDescriptor.GetProperties(typeof(T)).OfType<PropertyDescriptor>();
|
|
var header = string.Join(";", props.ToList().Select(x => x.Name));
|
|
lines.Add(header);
|
|
var valueLines = reportData.Select(row => string.Join(separator, header.Split(separator).Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
|
|
//var valueLines = reportData.Select(row => string.Join(";", header.Split(';').Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
|
|
lines.AddRange(valueLines);
|
|
await Task.Run(() => File.WriteAllLines(path, lines.ToArray()));
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Public Classes
|
|
|
|
public class POdlExt
|
|
{
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Clona un POdleExt, tutti i valori (compreso idxOdl)
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public static PODLExpModel clone(PODLExpModel selRec, bool resetOdl)
|
|
{
|
|
// creo record duplicato...
|
|
PODLExpModel newRec = new PODLExpModel()
|
|
{
|
|
Attivabile = resetOdl ? false : selRec.Attivabile,
|
|
CodArticolo = selRec.CodArticolo,
|
|
CodCli = selRec.CodCli,
|
|
CodGruppo = selRec.CodGruppo,
|
|
DueDate = selRec.DueDate,
|
|
IdxMacchina = selRec.IdxMacchina,
|
|
IdxOdl = resetOdl ? 0 : selRec.IdxOdl,
|
|
IdxPromessa = 0,
|
|
InsertDate = selRec.InsertDate,
|
|
KeyBCode = selRec.KeyBCode,
|
|
KeyRichiesta = selRec.KeyRichiesta,
|
|
Note = $"DUPLICATED - {selRec.Note}",
|
|
NumPezzi = selRec.NumPezzi,
|
|
Priorita = selRec.Priorita,
|
|
PzPallet = selRec.PzPallet,
|
|
Tcassegnato = selRec.Tcassegnato,
|
|
Recipe = selRec.Recipe
|
|
};
|
|
return newRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clona un POdleExt a POdl
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public static PODLModel convertToPOdl(PODLExpModel selRec)
|
|
{
|
|
// creo record duplicato...
|
|
PODLModel newRec = new PODLModel()
|
|
{
|
|
Attivabile = selRec.Attivabile,
|
|
CodArticolo = selRec.CodArticolo,
|
|
CodCli = selRec.CodCli,
|
|
CodGruppo = selRec.CodGruppo,
|
|
DueDate = selRec.DueDate,
|
|
IdxMacchina = selRec.IdxMacchina,
|
|
IdxOdl = selRec.IdxOdl,
|
|
IdxPromessa = selRec.IdxPromessa,
|
|
InsertDate = selRec.InsertDate,
|
|
KeyBCode = selRec.KeyBCode,
|
|
KeyRichiesta = selRec.KeyRichiesta,
|
|
Note = selRec.Note,
|
|
NumPezzi = selRec.NumPezzi,
|
|
Priorita = selRec.Priorita,
|
|
PzPallet = selRec.PzPallet,
|
|
Tcassegnato = selRec.Tcassegnato,
|
|
Recipe = selRec.Recipe
|
|
};
|
|
return newRec;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
|
|
#endregion Public Classes
|
|
|
|
#region Private Fields
|
|
|
|
public const string redisActionReq = redisBaseAddr + "Action:Req";
|
|
public const string redisAnagGruppi = redisBaseAddr + "Cache:AnagGruppi";
|
|
public const string redisArtByDossier = redisBaseAddr + "Cache:ArtByDossier";
|
|
public const string redisArtList = redisBaseAddr + "Cache:ArtList";
|
|
public const string redisBaseAddr = "MP:";
|
|
public const string redisConfKey = redisBaseAddr + "Cache:Config";
|
|
public const string redisAKVKey = redisBaseAddr + "Cache:AKV";
|
|
public const string redisParetoFLKey = redisBaseAddr + "Cache:ParetoFL";
|
|
public const string redisStatsProcFL = redisBaseAddr + "Stats:ProcessFL";
|
|
public const string redisStatsDbMaint = redisBaseAddr + "Stats:DbMaint";
|
|
public const string redisDossByMac = redisBaseAddr + "Cache:DossByMac";
|
|
public const string redisFluxByMac = redisBaseAddr + "Cache:FluxByMac";
|
|
public const string redisFluxLogFilt = redisBaseAddr + "Cache:FluxLogFilt";
|
|
public const string redisGiacenzaList = redisBaseAddr + "Cache:GiacenzaList";
|
|
public const string redisMacByFlux = redisBaseAddr + "Cache:MacByFlux";
|
|
public const string redisMacList = redisBaseAddr + "Cache:MacList";
|
|
public const string redisMacRecipeConf = redisBaseAddr + "Cache:RecipeConf";
|
|
public const string redisMacRecipePath = redisBaseAddr + "Cache:RecipePath";
|
|
public const string redisOdlByBatch = redisXdlData + "OdlByBatch";
|
|
public const string redisOdlCurrByMac = redisXdlData + "OdlByMac";
|
|
public const string redisOdlList = redisXdlData + "OdlList";
|
|
public const string redisParamPageExp = redisBaseAddr + "Cache:ParamPage";
|
|
public const string redisPOdlByOdl = redisXdlData + "POdlByOdl";
|
|
public const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl";
|
|
public const string redisPOdlList = redisXdlData + "POdlList";
|
|
public const string redisRecipeConf = redisBaseAddr + "Cache:Recipe:Conf";
|
|
public const string redisStatoCom = redisBaseAddr + "Cache:StatoCom";
|
|
public const string redisTipoArt = redisBaseAddr + "Cache:TipoArt";
|
|
public const string redisVocabolario = redisBaseAddr + "Cache:Vocabolario";
|
|
public const string redisXdlData = redisBaseAddr + "Cache:XDL:";
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |