Primo prototipo OEE con cache funzionante
This commit is contained in:
@@ -7,7 +7,10 @@ using System.Configuration;
|
||||
using NLog;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MP.Data.Controllers
|
||||
{
|
||||
@@ -18,14 +21,18 @@ namespace MP.Data.Controllers
|
||||
private static IConfiguration _configuration;
|
||||
private static MoonPro_STATSContext dbCtx;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private readonly IDistributedCache distributedCache;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MpStatsController(IConfiguration configuration)
|
||||
public MpStatsController(IConfiguration configuration, IMemoryCache memoryCache, IDistributedCache distributedCache)
|
||||
{
|
||||
_configuration = configuration;
|
||||
this.memoryCache = memoryCache;
|
||||
this.distributedCache = distributedCache;
|
||||
dbCtx = new MoonPro_STATSContext(configuration);
|
||||
Log.Info("Avviata classe MpStatsController.MpStatsController");
|
||||
}
|
||||
@@ -228,21 +235,39 @@ namespace MP.Data.Controllers
|
||||
/// <param name="IdxMacchina"></param>
|
||||
/// <param name="DataEnd"></param>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.TurniOee> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
public async Task<List<DatabaseModels.TurniOee>> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
||||
{
|
||||
List<DatabaseModels.TurniOee> dbResult = new List<DatabaseModels.TurniOee>();
|
||||
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina);
|
||||
var idxODL = new SqlParameter("@IdxODL", IdxODL);
|
||||
var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta);
|
||||
var codArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
||||
var cacheKey = "oeeData";
|
||||
string rawData;
|
||||
var redisCustomerList = await distributedCache.GetAsync(cacheKey);
|
||||
if (redisCustomerList != null)
|
||||
{
|
||||
rawData = Encoding.UTF8.GetString(redisCustomerList);
|
||||
dbResult = JsonConvert.DeserializeObject<List<MP.Data.DatabaseModels.TurniOee>>(rawData);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
||||
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
||||
var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina);
|
||||
var idxODL = new SqlParameter("@IdxODL", IdxODL);
|
||||
var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta);
|
||||
var codArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetTurniOee
|
||||
.FromSqlRaw("EXEC stp_UI_TurniOee_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo)
|
||||
.ToList();
|
||||
dbResult = dbCtx
|
||||
.DbSetTurniOee
|
||||
.FromSqlRaw("EXEC stp_UI_TurniOee_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo)
|
||||
.ToList();
|
||||
|
||||
rawData = JsonConvert.SerializeObject(dbResult);
|
||||
redisCustomerList = Encoding.UTF8.GetBytes(rawData);
|
||||
var options = new DistributedCacheEntryOptions()
|
||||
.SetAbsoluteExpiration(DateTime.Now.AddMinutes(10))
|
||||
.SetSlidingExpiration(TimeSpan.FromMinutes(2));
|
||||
await distributedCache.SetAsync(cacheKey, redisCustomerList, options);
|
||||
}
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace MP.Stats.Data
|
||||
}
|
||||
else
|
||||
{
|
||||
dbController = new MP.Data.Controllers.MpStatsController(configuration);
|
||||
dbController = new MP.Data.Controllers.MpStatsController(configuration, memoryCache, distributedCache);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"DbController OK");
|
||||
//sb.AppendLine($"CST: {dbController.CustomersCount()} | CNT: {dbController.CountersCount()} | BSK: {dbController.BasketsCount()} | NGT: {dbController.NegotiationsCount()} | DOC: {dbController.DocsCount()} | ITM: {dbController.ItemsCount()} | RES: {dbController.ResourcesCount()}");
|
||||
@@ -107,28 +107,9 @@ namespace MP.Stats.Data
|
||||
return Task.FromResult(dbController.StatScartiGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo).ToArray());
|
||||
}
|
||||
|
||||
public async Task<MP.Data.DatabaseModels.TurniOee[]> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, string searchVal = "")
|
||||
public Task<List<MP.Data.DatabaseModels.TurniOee>> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, string searchVal = "")
|
||||
{
|
||||
List<MP.Data.DatabaseModels.TurniOee> answ = new List<MP.Data.DatabaseModels.TurniOee>();
|
||||
var cacheKey = "oeeData";
|
||||
string serializedCustomerList;
|
||||
var redisCustomerList = await distributedCache.GetAsync(cacheKey);
|
||||
if (redisCustomerList != null)
|
||||
{
|
||||
serializedCustomerList = Encoding.UTF8.GetString(redisCustomerList);
|
||||
answ = JsonConvert.DeserializeObject<List<MP.Data.DatabaseModels.TurniOee>>(serializedCustomerList);
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = dbController.StatTurniOeeGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo);
|
||||
serializedCustomerList = JsonConvert.SerializeObject(answ);
|
||||
redisCustomerList = Encoding.UTF8.GetBytes(serializedCustomerList);
|
||||
var options = new DistributedCacheEntryOptions()
|
||||
.SetAbsoluteExpiration(DateTime.Now.AddMinutes(10))
|
||||
.SetSlidingExpiration(TimeSpan.FromMinutes(2));
|
||||
await distributedCache.SetAsync(cacheKey, redisCustomerList, options);
|
||||
}
|
||||
return answ.ToArray();
|
||||
return dbController.StatTurniOeeGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo);
|
||||
}
|
||||
|
||||
public Task<MP.Data.DatabaseModels.TurniPareto[]> StatTurniParetoGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, string searchVal = "")
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
{
|
||||
@*<BasketEditor Basket="@currBasket" DataReset="ResetData" DataUpdated="UpdateData"></BasketEditor>*@
|
||||
}
|
||||
@if (ListRecords == null)
|
||||
@if (ListRecords == null || totalCount == 0 || ListRecords.Count() == 0)
|
||||
{
|
||||
<div class="progress-bar progress-bar-striped progress-bar-animated" style="width:70%"></div>
|
||||
}
|
||||
@@ -66,6 +66,6 @@
|
||||
}
|
||||
</div>
|
||||
<div class="card-footer py-1">
|
||||
<DataPager PageSize="@numRecord" currPage="@currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="@SearchRecords.Count()" />
|
||||
<DataPager PageSize="@numRecord" currPage="@currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="@totalCount" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MP.Stats.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -15,7 +16,7 @@ namespace MP.Stats.Pages
|
||||
|
||||
private MP.Data.DatabaseModels.TurniOee[] ListRecords;
|
||||
|
||||
private MP.Data.DatabaseModels.TurniOee[] SearchRecords;
|
||||
private List<MP.Data.DatabaseModels.TurniOee> SearchRecords;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
@@ -41,6 +42,19 @@ namespace MP.Stats.Pages
|
||||
[Inject]
|
||||
protected MpStatsService StatService { get; set; }
|
||||
|
||||
protected int totalCount
|
||||
{
|
||||
get
|
||||
{
|
||||
int answ = 0;
|
||||
if (SearchRecords != null)
|
||||
{
|
||||
answ = SearchRecords.Count;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
Reference in New Issue
Block a user