From de280c0bd8433f7c991cf833ffa8cf34b8e76d96 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Mon, 30 Dec 2019 17:43:49 +0100 Subject: [PATCH] Preparata richiesta pr0ocessing validazione (coda iniziale) --- AppData/ComLib.cs | 84 ++++++++++++++++--- NKC_WF/Controllers/BatchProcController.cs | 45 +++++++++- .../WebUserControls/cmp_batchDetail.ascx.cs | 4 +- NKC_WF/WebUserControls/cmp_batchList.ascx.cs | 2 + 4 files changed, 118 insertions(+), 17 deletions(-) diff --git a/AppData/ComLib.cs b/AppData/ComLib.cs index fd282cd..b54111a 100644 --- a/AppData/ComLib.cs +++ b/AppData/ComLib.cs @@ -243,14 +243,84 @@ namespace AppData KeyValuePair[] answ = memLayer.ML.redGetHash(redMsgList); return answ; } + /// + /// resetta la richeista corrente in modo che non ce ne siano altre in coda + /// + /// + public static bool resetBatchReq() + { + bool answ = false; + try + { + currBatchReq = ""; + answ = true; + } + catch + { } + return answ; + } + public static string currBatchReqKey + { + get + { + return $"{redOutPath}:CURR"; + } + } + /// + /// Valore della richiesta corrente di elaborazione batch + /// + public static string currBatchReq + { + get + { + return memLayer.ML.getRSV(currBatchReqKey); + } + set + { + // scrivo su REDIS + memLayer.ML.setRSV(currBatchReqKey, value); + } + } + public static bool sendFirstValidationBatch() + { + bool answ = false; + // verifico se sia vuota la richeista corrente (= chiuso...) + // ora verifico, se ci sono batch in stato 8 (da validare) --> metto in coda! + var tabBatch = DataLayer.man.taBL.getByStatus(8); + bool hasValReq = tabBatch.Count > 0; + if (hasValReq) + { + // invia a redis una richiesta... + ComLib.sendMaterials(); + // recupero PRIMO batchID da validare + int nextBatchId = 0; + try + { + nextBatchId = tabBatch[0].BatchID; + } + catch + { } + if (nextBatchId > 0) + { + // richiedo! + ComLib.sendBatchReq(nextBatchId, "Estimation", 1); + // registro su DB nesting iniziato... QUANDO MI RISPONDE dovrò verificare che era un abtch x VALIDAZIONE + DataLayer.man.taBL.updateStatus(nextBatchId, (int)BatchStatus.EstimationRequested, "", 0); + answ = true; + } + } + // resituisco + return answ; + } /// /// Invia una richiesta di esecuzione di Nesting x un Batch /// /// Batch di cui si chiede processing /// note opzionali + /// Tipo processo: 1 = stima, 2 = nesting /// - public static bool sendBatchReq(int BatchID, string note) + public static bool sendBatchReq(int BatchID, string note, int pType) { bool answ = false; // per prima cosa mi serve una "nuova busta" per inviare i messaggi @@ -261,7 +331,6 @@ namespace AppData // in base allo stato del BATCH corrente determino il tempo e le opzioni da inviare... var batch = DataLayer.man.taBL.getByKey(BatchID); int mTime = 1; - int pType = 1; if (batch[0].STATUS < (int)BatchStatus.EstimationDone) { mTime = memLayer.ML.cdvi("estimMaxTime"); @@ -269,11 +338,8 @@ namespace AppData else { mTime = memLayer.ML.cdvi("nestMaxTime"); - pType = 2; } - - // init oggetti x fare cicli... Order currOrder = null; Kit currentKit = null; @@ -352,9 +418,7 @@ namespace AppData memLayer.ML.setRSV(redKey, redVal); // invio notifica che c'è una busta da processare - redKey = $"{redOutPath}:CURR"; - // scrivo su REDIS - memLayer.ML.setRSV(redKey, nextEnv); + memLayer.ML.setRSV(currBatchReqKey, nextEnv); answ = true; } catch (Exception exc) @@ -468,9 +532,7 @@ namespace AppData memLayer.ML.setRSV(redKey, redVal); // invio notifica che c'è una busta da processare - redKey = $"{redOutPath}:CURR"; - // scrivo su REDIS - memLayer.ML.setRSV(redKey, nextEnv); + memLayer.ML.setRSV(currBatchReqKey, nextEnv); answ = true; } catch (Exception exc) diff --git a/NKC_WF/Controllers/BatchProcController.cs b/NKC_WF/Controllers/BatchProcController.cs index bbab138..ffee080 100644 --- a/NKC_WF/Controllers/BatchProcController.cs +++ b/NKC_WF/Controllers/BatchProcController.cs @@ -21,9 +21,10 @@ namespace NKC_WF.Controllers { batchRequest answ = new batchRequest(); // in primis: controllo su redis SE HO una richiista CURRENT di processing... - string redKey = $"{ComLib.redOutPath}:CURR"; - string redVal = memLayer.ML.getRSV(redKey); - string envNum = redVal; +#if false + string redKey = $"{ComLib.currBatchReqKey}"; + string redVal = memLayer.ML.getRSV(redKey); + string envNum = redVal; // se c'è carico "la busta" come ID if (!string.IsNullOrEmpty(redVal)) { @@ -41,6 +42,27 @@ namespace NKC_WF.Controllers catch { } } +#endif + string redKey = ""; + string redVal = ""; + string envNum = ComLib.currBatchReq; + // se c'è carico "la busta" come ID + if (!string.IsNullOrEmpty(envNum)) + { + // cerco in REDIS se ci sia l'item richiesto + redKey = $"{ComLib.redOutPath}:{envNum}"; + // leggo da redis la stringa... + redVal = memLayer.ML.getRSV(redKey); + // PROVO a deserializzare... + try + { + answ = JsonConvert.DeserializeObject(redVal); + // aggiungo LA SUA ENV NUM!!!! + answ.EnvNum = envNum; + } + catch + { } + } return answ; } @@ -118,7 +140,7 @@ namespace NKC_WF.Controllers * IN BASE al tipo di risposta saprò se * - è BatchReq / OfflineOrder * - è stima iniziale o dettaglio (x batch) - * ... + * - si tratta di una stima di validazione o meno... * *************************************************/ if (batchProcAnsw.OrderType == oType.BatchRequest) @@ -228,9 +250,24 @@ namespace NKC_WF.Controllers { answ = "NO"; } + // se tutto OK --> tolgo ultimo batch + if (answ == "OK") + { + + // invio notifica che c'è una busta da processare + bool resetOk = ComLib.resetBatchReq(); + // se tutto ok e ci sono da validare parts --> procedo! + if (resetOk) + { + bool nextValidSent = ComLib.sendFirstValidationBatch(); + } + } + // restituisco risposta return answ; } + + #if false // POST: api/BatchProc diff --git a/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs b/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs index 2b68a39..1bdf080 100644 --- a/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs @@ -80,7 +80,7 @@ namespace NKC_WF.WebUserControls { // invia a redis una richiesta... ComLib.sendMaterials(); - ComLib.sendBatchReq(BatchId, "Estimation"); + ComLib.sendBatchReq(BatchId, "Estimation", 1); // registro su DB nesting iniziato... DataLayer.man.taBL.updateStatus(BatchId, (int)BatchStatus.EstimationRequested, "", 0); @@ -99,7 +99,7 @@ namespace NKC_WF.WebUserControls { // invia a redis a a richiesta... ComLib.sendMaterials(); - ComLib.sendBatchReq(BatchId, "Nesting"); + ComLib.sendBatchReq(BatchId, "Nesting", 2); // registro su DB nesting iniziato... DataLayer.man.taBL.updateStatus(BatchId, (int)BatchStatus.NestRequested, "", -1); diff --git a/NKC_WF/WebUserControls/cmp_batchList.ascx.cs b/NKC_WF/WebUserControls/cmp_batchList.ascx.cs index 7d81fb1..2adb6bc 100644 --- a/NKC_WF/WebUserControls/cmp_batchList.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_batchList.ascx.cs @@ -202,6 +202,8 @@ namespace NKC_WF.WebUserControls try { DataLayer.man.taBL.createPartValBatch(memLayer.ML.CRS("cadBaseBath")); + // eventualmente mando primo batch da validare... + bool newValidSent = ComLib.sendFirstValidationBatch(); } catch { }