diff --git a/MP.Data/Controllers/MpMongoController.cs b/MP.Data/Controllers/MpMongoController.cs index 3dfaaeec..baade6af 100644 --- a/MP.Data/Controllers/MpMongoController.cs +++ b/MP.Data/Controllers/MpMongoController.cs @@ -60,6 +60,29 @@ namespace MP.Data.Controllers { } return answ; } + + /// + /// Ricerca ricetta su MongoDB dato ID MongoDB + /// + /// + /// + public async Task RecipeGetByID(string mID) + { + await Task.Delay(1); + RecipeModel answ = new RecipeModel(); + try + { + // definisco filtro + var filtBuilder = Builders.Filter; + var filter = filtBuilder.Eq("_id", mID); + var collectionData = mongoDb.GetCollection("RecipeArchive"); + // recupero + answ = collectionData.Find(filter).Project("{_id: 0}").FirstOrDefault(); + } + catch + { } + return answ; + } /// /// Salva ricetta su MongoDB /// @@ -99,8 +122,6 @@ namespace MP.Data.Controllers public RecipeModel InitRecipe(string confPath, int idxPODL, Dictionary CalcArgs) { RecipeModel answ = new RecipeModel(); - // recupero dati da PODL... - // per prima cosa leggo file di conf x inizializzare ricetta... string fullPath = RecipePath(confPath); bool fileOk = File.Exists(fullPath); @@ -115,6 +136,64 @@ namespace MP.Data.Controllers return answ; } + + /// + /// Ricetta in formato calcolato (string) + /// + public string CalcRecipe(RecipeModel currRecipe) + { + string answ = ""; + // per prima cosa leggo file di conf x inizializzare ricetta... + string fullPath = RecipePath(currRecipe.TemplateFile); + bool fileOk = File.Exists(fullPath); + if (fileOk) + { + // preparo dati header + var headStrings = currRecipe.HeadVal.Select(x => $"\"{x.Key}\": \"{x.Value}\"").ToList(); + string headVals = string.Join(",", headStrings); + + + // leggo template + string rawData = File.ReadAllText(fullPath); + // recupero configurazione x inizio/fine righe + string[] righe = rawData.Split(Environment.NewLine); + List righeRed = new List(); + string sRow = ""; + string eRow = ""; + foreach (var riga in righe) + { + if (riga.Trim().StartsWith("||SROW:")) + { + sRow = riga.Trim().Replace("||SROW:", "").Replace("||", ""); + } + else if (riga.Trim().StartsWith("||EROW:")) + { + eRow = riga.Trim().Replace("||EROW:", "").Replace("||", ""); + } + else + { + righeRed.Add(riga); + } + } + // rigenero righe senza le parti da ripetere... + rawData = string.Join(Environment.NewLine, righeRed); + // effettuo sostituzione... + answ = rawData.Replace("||PlaceholderHeader||", headVals); + // per le righe prima calcolo blocchi ripetuti + List rowComp = new List(); + foreach (var item in currRecipe.RowsVal) + { + var rowsStrings = item.Value.Select(x => $"\"{x.Key}\": \"{x.Value}\"").ToList(); + rowComp.Add($"{Environment.NewLine}{sRow}{string.Join(",", rowsStrings)}{eRow}"); + } + string rowsVals = string.Join(",", rowComp); + //...poi sostituisco + answ = answ.Replace("||PlaceholderRows||", rowsVals); + } + return answ; + } + + private MongoClient client = new MongoClient("mongodb://localhost:27017"); private static IConfiguration _configuration; diff --git a/MP.Data/MgModels/RecipeModel.cs b/MP.Data/MgModels/RecipeModel.cs index 0c2d78a2..a4552080 100644 --- a/MP.Data/MgModels/RecipeModel.cs +++ b/MP.Data/MgModels/RecipeModel.cs @@ -50,7 +50,7 @@ namespace MP.Data.MgModels public List getNewRow(Dictionary CalcArgs) { List rowList = new List(); - rowList= ElementConverter(this.RowsConf.ListKeys, CalcArgs); + rowList = ElementConverter(this.RowsConf.ListKeys, CalcArgs); return rowList; } @@ -138,7 +138,7 @@ namespace MP.Data.MgModels this.Key = rawKey; this.OrigVal = rawVal; this.Value = rawVal; - // cerco se ho uno dei 3 caratteri (C/E/F): + // cerco se ho uno dei 3 caratteri (C/E/F/S): if (rawVal.Length >= 2 && rawVal.Substring(1, 1) == ":") { string selTipo = rawVal.Substring(0, 2); @@ -169,6 +169,20 @@ namespace MP.Data.MgModels this.Value = rawVal.Substring(2); break; + case "S:": + this.Type = KeyType.Calc; + // recupero item x ricerca in dizionario... + string sKey = rawVal.Substring(2); + if (CalcArgs.ContainsKey(sKey)) + { + this.Value = CalcArgs[sKey]; + } + else + { + this.Value = sKey; + } + break; + default: this.Type = KeyType.None; break; @@ -219,10 +233,26 @@ namespace MP.Data.MgModels public enum KeyType { None = 0, + /// + /// Campo calcolato (NON modificabile) + /// Calc, + /// + /// Valore da Enum + /// Enum, + /// + /// Valore fisso + /// Fixed, - Free + /// + /// Valore libero + /// + Free, + /// + /// Campo suggerito (=calcolato modificabile) + /// + Suggested } #endregion Public Enums diff --git a/MP.SPEC/Components/RecipeMan.razor b/MP.SPEC/Components/RecipeMan.razor index 8321f0e4..9e369147 100644 --- a/MP.SPEC/Components/RecipeMan.razor +++ b/MP.SPEC/Components/RecipeMan.razor @@ -13,6 +13,7 @@ else

Testata Ricetta

+ Display @if (!showHead) { @CurrRecipe?.HeadVal.Count par @@ -41,15 +42,14 @@ else {
- @*@item.Key*@ - @if (item.Type == RecipeModel.Element.KeyType.Fixed) + @if (item.Type == RecipeModel.Element.KeyType.Fixed || item.Type == RecipeModel.Element.KeyType.Calc) { } else if (item.Type == MP.Data.MgModels.RecipeModel.Element.KeyType.Enum) { + @if (item.Type == RecipeModel.Element.KeyType.Fixed || item.Type == RecipeModel.Element.KeyType.Calc) + { + + } + else if (item.Type == MP.Data.MgModels.RecipeModel.Element.KeyType.Enum) + { + + } + else + { + + }
diff --git a/MP.SPEC/Components/RecipeMan.razor.cs b/MP.SPEC/Components/RecipeMan.razor.cs index b3a9199e..6fcb6e38 100644 --- a/MP.SPEC/Components/RecipeMan.razor.cs +++ b/MP.SPEC/Components/RecipeMan.razor.cs @@ -45,10 +45,10 @@ namespace MP.SPEC.Components await ReloadData(); } - protected Dictionary GetListByType(string DictType) + protected Dictionary GetHeadListByType(string DictType) { Dictionary answ = new Dictionary(); - // inn primis il "selezionare" + // in primis il "selezionare" answ.Add("", "--- Selezionare ---"); // cerco tipo in enums... if (CurrRecipe != null && CurrRecipe.HeadConf.EnumVal.ContainsKey(DictType)) @@ -60,6 +60,21 @@ namespace MP.SPEC.Components } return answ; } + protected Dictionary GetRowListByType(string DictType) + { + Dictionary answ = new Dictionary(); + // in primis il "selezionare" + answ.Add("", "--- Selezionare ---"); + // cerco tipo in enums... + if (CurrRecipe != null && CurrRecipe.RowsConf.EnumVal.ContainsKey(DictType)) + { + foreach (var item in CurrRecipe.RowsConf.EnumVal[DictType]) + { + answ.Add(item.Key, item.Value); + } + } + return answ; + } protected override async Task OnParametersSetAsync() { @@ -116,9 +131,12 @@ namespace MP.SPEC.Components { // sistemo lista bool x righe showRows = new Dictionary(); - for (int i = 1; i <= CurrRecipe.RowsVal.Count; i++) + if (CurrRecipe != null) { - showRows.Add($"{i}", false); + for (int i = 1; i <= CurrRecipe.RowsVal.Count; i++) + { + showRows.Add($"{i}", false); + } } } diff --git a/MP.SPEC/Controllers/RecipeController.cs b/MP.SPEC/Controllers/RecipeController.cs new file mode 100644 index 00000000..7ac28676 --- /dev/null +++ b/MP.SPEC/Controllers/RecipeController.cs @@ -0,0 +1,43 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using MP.Data.MgModels; +using MP.SPEC.Data; +using NLog; + +namespace MP.SPEC.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class RecipeController : ControllerBase + { + /// + /// Dataservice x accesso DB + /// + protected MpDataService DService { get; set; } + + public RecipeController(IConfiguration configuration, MpDataService DataService) + { + Log.Info("Starting MpDataService INIT"); + _configuration = configuration; + DService = DataService; + Log.Info("Avviata classe Recipe"); + + } + private static IConfiguration _configuration = null!; + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + [HttpGet("GetRecipe")] + public async Task GetRecipe(int idxPODL) + { + string answ = ""; + var reqRecipe = await DService.RecipeGetByPODL(idxPODL); + if(reqRecipe!=null) + { + answ = DService.CalcRecipe(reqRecipe); + } + return answ; + } + } +} diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 7554bd33..80e555e7 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -82,6 +82,7 @@ namespace MP.SPEC.Data { return mongoController.InitRecipe(confPath, idxPODL, CalcArgs); } + /// /// Salva ricetta su MongoDB /// @@ -111,6 +112,11 @@ namespace MP.SPEC.Data return result; } + public string CalcRecipe(RecipeModel currRecipe) + { + return mongoController.CalcRecipe(currRecipe); + } + #region Public Methods /// diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index a9fbdd60..42ad337e 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2302.916 + 6.16.2302.1311 @@ -17,7 +17,9 @@ - + + PreserveNewest + diff --git a/MP.SPEC/Program.cs b/MP.SPEC/Program.cs index 13deb26f..e650e8a4 100644 --- a/MP.SPEC/Program.cs +++ b/MP.SPEC/Program.cs @@ -65,7 +65,13 @@ app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); -app.MapBlazorHub(); -app.MapFallbackToPage("/_Host"); +app.UseEndpoints(endpoints => +{ + endpoints.MapControllers(); + endpoints.MapBlazorHub(); + endpoints.MapFallbackToPage("/_Host"); +}); +//app.MapBlazorHub(); +//app.MapFallbackToPage("/_Host"); app.Run(); diff --git a/MP.SPEC/Recipe/Fimat/RecipeConf.json b/MP.SPEC/Recipe/Fimat/RecipeConf.json index ced4c417..534d2a53 100644 --- a/MP.SPEC/Recipe/Fimat/RecipeConf.json +++ b/MP.SPEC/Recipe/Fimat/RecipeConf.json @@ -1,5 +1,5 @@ { - "TemplateFile": "TemplateOutput.tpl", + "TemplateFile": "Fimat/TemplateOutput.tpl", "NumRow": 2, "HeadConf": { "ListKeys": { diff --git a/MP.SPEC/Recipe/Fimat/TemplateOutput.tpl b/MP.SPEC/Recipe/Fimat/TemplateOutput.tpl index 99e3d023..a4adbb03 100644 --- a/MP.SPEC/Recipe/Fimat/TemplateOutput.tpl +++ b/MP.SPEC/Recipe/Fimat/TemplateOutput.tpl @@ -2,10 +2,13 @@ "A_Recipe": { "DesRecipe": { "DesData": { - [[TemplateHead.json]] + ||PlaceholderHeader|| }, - "ColRecipe": [ - [[TemplateRows.json]] - ] + "ColRecipe": [ + ||SROW:{"ColData":{|| + ||PlaceholderRows|| + ||EROW:}}|| + ] + } } } \ No newline at end of file diff --git a/MP.SPEC/Recipe/README.md b/MP.SPEC/Recipe/README.md index 9925615a..5f86f69b 100644 --- a/MP.SPEC/Recipe/README.md +++ b/MP.SPEC/Recipe/README.md @@ -1,13 +1,124 @@ # Ricette - [Ricette](#ricette) - [Gestione formati e tag x ricette](#gestione-formati-e-tag-x-ricette) + - [Definizione tag ricette](#definizione-tag-ricette) + - [Esempio tracciato Template](#esempio-tracciato-template) + - [Esempio tracciato configurazione complessivo](#esempio-tracciato-configurazione-complessivo) - [Campi Calcolati](#campi-calcolati) # Gestione formati e tag x ricette -Nelle ricette ci possono essere campi liberi, campi da enum (da configurare nel json) e campi calcolati +Nelle ricette ci possono essere campi liberi, campi da enum (da configurare nel json) e campi calcolati. +E' utile riportare un esempio di tracciato finale desiderato insieme ad un file template tpl da cui attingere x la realizzazione insieme ai campi definiti x testata e corpo. + +In particolare sia per testata che corpo sono indicati casi di dati enumerativi (in modo che sia usato uno tra i valori ammessi) + + +## Definizione tag ricette + +I tag ammessi x le ricette sono di seguito riassunti e definiti: + +| Cod | Significato | Definizione | +|-----|-------------|--------------------------------------------| +| C | Calcolato | Campo calcolato (NON modificabile) | +| E | Enum | IdxODL numerico | +| F | Fixed | IdxODL numerico | +| S | Suggested | Campo calcolato e suggerito (modificabile) | + +IN particolare gli Enum sono poi da riportare nella struttura degli EnumVal che deve completare i valori di testata o di corpo. + +## Esempio tracciato Template + +Ecco un esempio di template + +```csharp +{ + "A_Recipe": { + "DesRecipe": { + "DesData": { + ||PlaceholderHeader|| + }, + "ColRecipe": [ + ||SROW:{"ColData":{|| + ||PlaceholderRows|| + ||EROW":}}|| + ] + } +} +``` + +il blocco ||PlaceholderHeader|| verrà sostituito per intero dai valori di testata. + +Il blocco delel righe è invece più complesso e composto da 3 parti: + * nel primo blocco, ||SROW:{"ColData":{||, si cerca start riga e si prende il valore compreso tra ||SROW:: e || come testata riga da ripetere + * nel secondo blocco si sostituiscono tutti i valori della riga i-esima + * nel terzo blocco ||EROW":}}|| si sistema la chiusura della riga (end row) + + + +## Esempio tracciato configurazione complessivo + +```json +{ + "TemplateFile": "TemplateOutput.tpl", + "NumRow": 2, + "HeadConf": { + "ListKeys": { + "CustDrumCode": "F:", + "Taglio-N": "F:1", + "LotID": "C:IdxPODL", + "OrderCode": "C:CodePODL", + "Prio": "E:Priority", + "DrumType": "E:DrumType", + "Customer": "Tenditalia", + "Design": "DESIGN", + "Quantity-kg": "1.00" + }, + "EnumVal": { + "Priority": { + "N": "Normal", + "H": "Hight" + }, + "DrumType": { + "1": "Small", + "2": "Medium", + "3": "Big" + } + } + }, + "RowsConf": { + "ListKeys": { + "Weight-gr-prev": "F:0.00", + "CompNumber": "C:RowNum", + "ColourCode": "C001", + "Description": "COLOR1", + "TypComp": "E:ColType", + "PartsWeight": "1.00", + "PartsPerc": "0.10", + "Weight-gr": "30.00" + }, + "EnumVal": { + "ColType": { + "C": "Color", + "A": "Thickener", + "X": "Auxiliaries" + } + } + } +} +``` + +Come si può notare, il tracciato di configurazione comprende i seguenti blocchi: +| Blocco | descrizione | +|-------------------|--------------------------------------| +| HeadConf | Configurazione campi testata | +| HeadConf:ListKeys | Elenco chiavi/valori x testata | +| HeadConf:EnumVal | Elenco enumerativi ammessi x testata | +| RowsConf | Configurazione campi riga | +| RowsConf:ListKeys | Elenco chiavi/valori x righe | +| RowsConf:EnumVal | Elenco enumerativi ammessi x righe | ## Campi Calcolati diff --git a/MP.SPEC/Recipe/README.pdf b/MP.SPEC/Recipe/README.pdf index 3f36eaff..02bb87f2 100644 Binary files a/MP.SPEC/Recipe/README.pdf and b/MP.SPEC/Recipe/README.pdf differ diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index a5bd0cef..72eabcda 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2302.916

+

Versione: 6.16.2302.1311


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 0003f78b..67c61c02 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2302.916 +6.16.2302.1311 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index c322d1cd..2e44f23a 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2302.916 + 6.16.2302.1311 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false