diff --git a/MP-TAB-SERV/Components/AlarmsMan.razor b/MP-TAB-SERV/Components/AlarmsMan.razor index 60caf372..0f9b4cfe 100644 --- a/MP-TAB-SERV/Components/AlarmsMan.razor +++ b/MP-TAB-SERV/Components/AlarmsMan.razor @@ -1,5 +1,6 @@ - + + @if (isProcessing) { @@ -53,12 +54,6 @@ else { } - @*
- Invia -
*@ - @*
- Set -
*@ diff --git a/MP-TAB-SERV/Components/AlarmsMan.razor.cs b/MP-TAB-SERV/Components/AlarmsMan.razor.cs index da71a876..63e67d7b 100644 --- a/MP-TAB-SERV/Components/AlarmsMan.razor.cs +++ b/MP-TAB-SERV/Components/AlarmsMan.razor.cs @@ -3,6 +3,8 @@ using Microsoft.JSInterop; using MP.Data; using MP.Data.DatabaseModels; using MP.Data.Services; +using NLog; +using System.Text; using static EgwCoreLib.Utils.DtUtils; namespace MP_TAB_SERV.Components @@ -42,6 +44,7 @@ namespace MP_TAB_SERV.Components #region Protected Fields protected bool isProcessing = false; + protected bool isSending = false; protected int NumRecPage = 10; protected int PageNum = 1; @@ -51,27 +54,46 @@ namespace MP_TAB_SERV.Components #region Protected Properties + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; + protected List ListComplete { get; set; } = new List(); protected List ListPaged { get; set; } = new List(); [Inject] - protected TabDataService TabDServ { get; set; } = null!; - + protected MailService MailServ { get; set; } = null!; [Inject] - protected MailService MailServ { get; set; } = null!; + protected MessageService MServ { get; set; } = null!; + + [Inject] + protected TabDataService TabDServ { get; set; } = null!; #endregion Protected Properties #region Protected Methods + protected async Task DoAck(AlarmLogModel currAlarm) + { + if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler registrare ACK dell'allarme?{Environment.NewLine}[{currAlarm.ValDecoded}]")) + return; + + isSending = true; + await Task.Delay(1); + TabDServ.AlarmLogSetAck(currAlarm.AlarmLogId, DateTime.Now, $"{MServ.MatrOpr} - {MServ.CognomeNome}"); + isSending = false; + await Task.Delay(1); + await InvokeAsync(StateHasChanged); + } + protected override async Task OnInitializedAsync() { await Task.Delay(1); if (RecMSE != null) { IdxMaccSel = RecMSE.IdxMacchina; + CurrPeriodo = new Periodo(PeriodSet.LastWeek); await doUpdate(); } } @@ -88,6 +110,47 @@ namespace MP_TAB_SERV.Components UpdateTable(); } + protected async Task SendNotify(AlarmLogModel currAlarm) + { + if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler inviare notifica allarme?{Environment.NewLine}[{currAlarm.ValDecoded}]")) + return; + + isSending = true; + await Task.Delay(1); + await InvokeAsync(StateHasChanged); + List dest = new List(); + dest.Add("samuele@steamware.net"); + string oggetto = $"Notifica allarme impianto {currAlarm.MachineId}"; + StringBuilder sb = new StringBuilder(); + sb.AppendLine("Attenzione: allarme presente per un periodo superiore alla soglia di controllo."); + sb.AppendLine(); + sb.AppendLine($"{currAlarm.ValDecoded}"); + sb.AppendLine(); + sb.AppendLine($"Info Area: {currAlarm.MemAddress}.{currAlarm.MemIndex} | Status {currAlarm.StatusVal}"); + sb.AppendLine(); + string corpo = sb.ToString().Replace($"{Environment.NewLine}", "
"); + MailKitMailData mData = new MailKitMailData() + { + To = dest, + Subject = oggetto, + Body = corpo + }; + bool done = await MailServ.SendAsync(mData); + if (done) + { + // salvo invio Notifica allarme + TabDServ.AlarmLogSetNotify(currAlarm.AlarmLogId, DateTime.Now); + Log.Info($"Notifica allarme {currAlarm.AlarmLogId} inviato a {string.Join(",", dest)}"); + } + else + { + Log.Error($"Errore in invio email allarmi attivi per {currAlarm.AlarmLogId}"); + } + isSending = false; + await Task.Delay(1); + await InvokeAsync(StateHasChanged); + } + protected async Task SetMacc(string selIdxMacc) { isProcessing = true; @@ -119,40 +182,17 @@ namespace MP_TAB_SERV.Components #endregion Protected Methods + #region Private Fields + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + #region Private Properties private Periodo CurrPeriodo { get; set; } = new Periodo(); private string IdxMaccSel { get; set; } = ""; #endregion Private Properties - - protected async Task SendNotify(AlarmLogModel currAlarm) - { - if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler inviare notifica allarme?{Environment.NewLine}[{currAlarm.ValDecoded}]")) - return; - - isProcessing = true; - List dest = new List(); - dest.Add("samuele@steamware.net"); - string body = $"Registrato allarme {currAlarm.ValDecoded}"; - MailKitMailData mData = new MailKitMailData() - { - To = dest, - Subject = "MAPO Alarm Notification", - Body = body - }; - await MailServ.SendAsync(mData); - isProcessing = false; - await Task.Delay(1); - } - protected async Task DoAck(AlarmLogModel currAlarm) - { - if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler registrare ACK dell'allarme?{Environment.NewLine}[{currAlarm.ValDecoded}]")) - return; - await Task.Delay(1); - } - - [Inject] - protected IJSRuntime JSRuntime { get; set; } = null!; } } \ No newline at end of file diff --git a/MP-TAB-SERV/Components/ProdAdvDispl.razor.cs b/MP-TAB-SERV/Components/ProdAdvDispl.razor.cs index 1b73ea39..dcc3e9d3 100644 --- a/MP-TAB-SERV/Components/ProdAdvDispl.razor.cs +++ b/MP-TAB-SERV/Components/ProdAdvDispl.razor.cs @@ -101,7 +101,7 @@ namespace MP_TAB_SERV.Components decimal denom = (decimal)CountData.numPzOrd / 100; //CountData.numPzProd > CountData.numPzOrd ? (decimal)CountData.numPzProd / 100 : (decimal)CountData.numPzOrd / 100; denom = denom == 0 ? 1 : denom; // calcolo se sono nel caso prod < ordinati o se sono andato OVER - if (CountData.numPzProd < CountData.numPzOrd) + if (CountData.numPzProd <= CountData.numPzOrd) { nGreen = (int)Math.Floor((decimal)CountData.numPzConf / denom); nYellow = (int)Math.Floor((decimal)(CountData.numPzProd - CountData.numPzConf) / denom); @@ -111,18 +111,18 @@ namespace MP_TAB_SERV.Components else { // green: confermati verdi - // devo verificare SE ne ho confermati meno che ordinati o meno... + nGreen = (int)Math.Floor((decimal)CountData.numPzConf / denom); + // gialli: extra prodotti fino a 100... if (CountData.numPzConf < CountData.numPzOrd) { - nGreen = (int)Math.Floor((decimal)CountData.numPzConf / denom); + nYellow = (int)Math.Floor((decimal)(CountData.numPzProd - CountData.numPzConf) / denom); } else { - nGreen = (int)Math.Floor((decimal)CountData.numPzOrd / denom); + nYellow = 100 - nGreen; } // blu: quanti sono "extra" e da confermare - nBlue = (int)Math.Floor((decimal)(CountData.numPzProd) / denom) - nGreen; - nYellow = 0; + nBlue = (int)Math.Floor((decimal)(CountData.numPzProd - CountData.numPzOrd) / denom); nGray = 0; } diff --git a/MP-TAB-SERV/Components/ShowProcessing.razor b/MP-TAB-SERV/Components/ShowProcessing.razor index 30428703..6f44bfa4 100644 --- a/MP-TAB-SERV/Components/ShowProcessing.razor +++ b/MP-TAB-SERV/Components/ShowProcessing.razor @@ -5,7 +5,7 @@
- ELABORAZIONE IN CORSO + @Message
@@ -15,5 +15,6 @@ @code { [Parameter] public bool IsProcessing { get; set; } = false; - + [Parameter] + public string Message { get; set; } = "ELABORAZIONE IN CORSO"; } diff --git a/MP-TAB-SERV/MP-TAB-SERV.csproj b/MP-TAB-SERV/MP-TAB-SERV.csproj index c108203d..ae85f99c 100644 --- a/MP-TAB-SERV/MP-TAB-SERV.csproj +++ b/MP-TAB-SERV/MP-TAB-SERV.csproj @@ -3,7 +3,7 @@ net6.0 enable - 6.16.2310.1208 + 6.16.2310.1211 enable MP_TAB_SERV diff --git a/MP-TAB-SERV/Resources/ChangeLog.html b/MP-TAB-SERV/Resources/ChangeLog.html index 47dfdc08..e861a692 100644 --- a/MP-TAB-SERV/Resources/ChangeLog.html +++ b/MP-TAB-SERV/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2310.1208

+

Versione: 6.16.2310.1211


Note di rilascio:
  • diff --git a/MP-TAB-SERV/Resources/VersNum.txt b/MP-TAB-SERV/Resources/VersNum.txt index 7c81d2eb..b4c85468 100644 --- a/MP-TAB-SERV/Resources/VersNum.txt +++ b/MP-TAB-SERV/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2310.1208 +6.16.2310.1211 diff --git a/MP-TAB-SERV/Resources/manifest.xml b/MP-TAB-SERV/Resources/manifest.xml index 4e3f1daa..7b340c07 100644 --- a/MP-TAB-SERV/Resources/manifest.xml +++ b/MP-TAB-SERV/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2310.1208 + 6.16.2310.1211 https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/MP-TAB-SERV.zip https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/ChangeLog.html false diff --git a/MP.Data/Controllers/MpTabController.cs b/MP.Data/Controllers/MpTabController.cs index 75aed825..1c7cea51 100644 --- a/MP.Data/Controllers/MpTabController.cs +++ b/MP.Data/Controllers/MpTabController.cs @@ -52,6 +52,52 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Registrato ACK allarme + /// + /// Id Allarme + /// Data Ack + /// User Ack + /// + public bool AlarmLogSetAck(int alarmLogId, DateTime dtAck, string userAck) + { + bool fatto = false; + using (var dbCtx = new MoonProContext(_configuration)) + { + var AlarmLogId = new SqlParameter("@AlarmLogId", alarmLogId); + var DtAck = new SqlParameter("@DtAck", dtAck); + var UserAck = new SqlParameter("@UserAck", userAck); + + var result = dbCtx + .Database + .ExecuteSqlRaw("EXEC stp_AL_setAck @AlarmLogId, @DtAck, @UserAck", AlarmLogId, DtAck, UserAck); + fatto = result != 0; + } + return fatto; + } + + /// + /// Registrato invio notifica allarme + /// + /// Id Allarme + /// Data notifica + /// + public bool AlarmLogSetNotify(int alarmLogId, DateTime dtNotify) + { + bool fatto = false; + using (var dbCtx = new MoonProContext(_configuration)) + { + var AlarmLogId = new SqlParameter("@AlarmLogId", alarmLogId); + var DtNotify = new SqlParameter("@DtNotify", dtNotify); + + var result = dbCtx + .Database + .ExecuteSqlRaw("EXEC stp_AL_setNotify @AlarmLogId, @DtNotify", AlarmLogId, DtNotify); + fatto = result != 0; + } + return fatto; + } + /// /// Restituisce l'anagrafica EVENTI per intero /// diff --git a/MP.Data/Services/MailService.cs b/MP.Data/Services/MailService.cs index 01e3f7b3..9c8d6d2c 100644 --- a/MP.Data/Services/MailService.cs +++ b/MP.Data/Services/MailService.cs @@ -13,8 +13,7 @@ using System.Threading.Tasks; namespace MP.Data.Services { /// - /// Implementazione MailKit come descritto qui - /// https://blog.christian-schou.dk/send-emails-with-asp-net-core-with-mailkit/ + /// Implementazione MailKit come descritto qui https://blog.christian-schou.dk/send-emails-with-asp-net-core-with-mailkit/ /// public class MailService : IMailService { @@ -131,8 +130,8 @@ namespace MP.Data.Services #region Private Fields - private readonly MailKitMailSettings _settings; private static Logger Log = LogManager.GetCurrentClassLogger(); + private readonly MailKitMailSettings _settings; #endregion Private Fields } diff --git a/MP.Data/Services/MessageService.cs b/MP.Data/Services/MessageService.cs index 61581c35..62301baa 100644 --- a/MP.Data/Services/MessageService.cs +++ b/MP.Data/Services/MessageService.cs @@ -100,6 +100,19 @@ namespace MP.Data.Services return answ; } } + public string CognomeNome + { + get + { + string answ = ""; + //int answ = -1; + if (_rigaOper != null) + { + answ = $"{_rigaOper.Cognome} {_rigaOper.Nome}"; + } + return answ; + } + } public AnagOperatoriModel? RigaOper { diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index b1cedb4c..8b6ab37c 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -68,6 +68,69 @@ namespace MP.Data.Services #region Public Methods + /// + /// Elenco allarmi macchina + /// + /// Macchina + /// Inizio periodo + /// Fine periodo + /// + /// + public async Task> AlarmLogListFilt(string idxMacchina, DateTime dtFrom, DateTime dtTo, bool showMulti) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:AlarmLog:{idxMacchina}:{dtFrom:yyyyMMdd-HHmmss}:{dtTo::yyyyMMdd-HHmmss}:{showMulti}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = await Task.FromResult(dbTabController.AlarmLogListFilt(idxMacchina, dtFrom, dtTo, showMulti)); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, UltraFastCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"AlarmLogListFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + + /// + /// Registrato ACK allarme + /// + /// Id Allarme + /// Data Ack + /// User Ack + /// + public bool AlarmLogSetAck(int alarmLogId, DateTime dtAck, string userAck) + { + bool answ = dbTabController.AlarmLogSetAck(alarmLogId, dtAck, userAck); + return answ; + } + + /// + /// Registrato ACK allarme + /// + /// Id Allarme + /// Data Ack + /// + public bool AlarmLogSetNotify(int alarmLogId, DateTime dtNotify) + { + bool answ = dbTabController.AlarmLogSetNotify(alarmLogId, dtNotify); + return answ; + } + /// /// Elenco completo EVENTI /// @@ -523,6 +586,39 @@ namespace MP.Data.Services return result; } + /// Elenco PODL macchina Macchina Solo disponibili (1) o tutte (0) Gruppo + public async Task> ListPODLByMacc(string idxMacchina, bool onlyFree, bool onlyDirect) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:PODL:{idxMacchina}:{onlyFree}:{onlyDirect}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = await Task.FromResult(dbTabController.ListPODLByMacc(idxMacchina, onlyFree, onlyDirect)); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ListPODLByMacc | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Effettua ricalcolo MSE x macchina indicata /// @@ -890,80 +986,6 @@ namespace MP.Data.Services return result; } - /// - /// Elenco allarmi macchina - /// - /// Macchina - /// Inizio periodo - /// Fine periodo - /// - /// - public async Task> AlarmLogListFilt(string idxMacchina, DateTime dtFrom, DateTime dtTo, bool showMulti) - { - string source = "DB"; - Stopwatch sw = new Stopwatch(); - sw.Start(); - List? result = new List(); - // cerco in redis... - string currKey = $"{redisBaseKey}:AlarmLog:{idxMacchina}:{dtFrom:yyyyMMdd-HHmmss}:{dtTo::yyyyMMdd-HHmmss}:{showMulti}"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = await Task.FromResult(dbTabController.AlarmLogListFilt(idxMacchina, dtFrom, dtTo, showMulti)); - // serializzp e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, UltraFastCache); - } - if (result == null) - { - result = new List(); - } - sw.Stop(); - Log.Debug($"AlarmLogListFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms"); - return result; - } - - /// Elenco PODL macchina - /// - /// Macchina - /// Solo disponibili (1) o tutte (0) - /// Gruppo - /// - public async Task> ListPODLByMacc(string idxMacchina, bool onlyFree, bool onlyDirect) - { - string source = "DB"; - Stopwatch sw = new Stopwatch(); - sw.Start(); - List? result = new List(); - // cerco in redis... - string currKey = $"{redisBaseKey}:PODL:{idxMacchina}:{onlyFree}:{onlyDirect}"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = await Task.FromResult(dbTabController.ListPODLByMacc(idxMacchina, onlyFree, onlyDirect)); - // serializzp e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - } - if (result == null) - { - result = new List(); - } - sw.Stop(); - Log.Debug($"ListPODLByMacc | {source} | {sw.Elapsed.TotalMilliseconds}ms"); - return result; - } - /// /// Toggle stato turno ///