1346 lines
52 KiB
C#
1346 lines
52 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using MP.MONO.Core.DTO;
|
|
using MP.MONO.Data.DbModels;
|
|
using MP.MONO.Data.DTO;
|
|
using NLog;
|
|
using System.Diagnostics;
|
|
using static MP.MONO.Core.Enums;
|
|
|
|
namespace MP.MONO.Data.Controllers
|
|
{
|
|
public class MpDbController : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public MpDbController()
|
|
{ }
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Elenco records anagrafica allarmi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AlarmListModel> AlarmListGetAll()
|
|
{
|
|
List<AlarmListModel>? dbResult = new List<AlarmListModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAlarmList
|
|
.OrderBy(x => x.FullValue)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmListGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di un record anagrafica allarmi (o se esiste restituisce quello esistente)
|
|
/// </summary>
|
|
/// <param name="newItem">Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public AlarmListModel? AlarmListInsert(string alarmText)
|
|
{
|
|
AlarmListModel? foundRec = new AlarmListModel();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
// verifico che NON esista con pèari descrizione...
|
|
foundRec = localDbCtx
|
|
.DbSetAlarmList
|
|
.FirstOrDefault(x => x.FullValue == alarmText);
|
|
// se non c'è aggiungo
|
|
if (foundRec == null)
|
|
{
|
|
foundRec = new AlarmListModel()
|
|
{
|
|
FullValue = alarmText
|
|
};
|
|
localDbCtx
|
|
.DbSetAlarmList
|
|
.Add(foundRec);
|
|
localDbCtx.SaveChanges();
|
|
// rifaccio search
|
|
foundRec = localDbCtx
|
|
.DbSetAlarmList
|
|
.FirstOrDefault(x => x.FullValue == alarmText);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmListInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return foundRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di una lista record anagrafica allarmi
|
|
/// </summary>
|
|
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmListInsertMany(List<AlarmListModel> newItems)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
await localDbCtx
|
|
.DbSetAlarmList
|
|
.AddRangeAsync(newItems);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmListInsertMany{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco allarmi (ultimi dato "skip")
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="skipRec"></param>
|
|
/// <param name="numRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<AlarmLogModel>> AlarmLogGetFilt(int MachineId, int skipRec, int numRec)
|
|
{
|
|
List<AlarmLogModel> dbResult = new List<AlarmLogModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = await localDbCtx
|
|
.DbSetAlarmLog
|
|
.AsNoTracking()
|
|
.Where(x => x.MachineId == MachineId)
|
|
.Include(m => m.MachineNav)
|
|
.OrderByDescending(x => x.AlarmLogId)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToListAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmLogGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
//await Task.Delay(1);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary> Recupero elenco allarmi con data <= alla data di riferimento (ultimi dato
|
|
/// "skip") </summary> <param name="MachineId"></param> <param name="dtRif"></param> <param
|
|
/// name="skipRec"></param> <param name="numRec"></param> <returns></returns>
|
|
public List<AlarmLogModel> AlarmLogGetFiltByDate(int MachineId, DateTime dtRif, int skipRec, int numRec)
|
|
{
|
|
List<AlarmLogModel> dbResult = new List<AlarmLogModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAlarmLog
|
|
.AsNoTracking()
|
|
.Where(x => (x.MachineId == MachineId) && (x.DtRif <= dtRif))
|
|
.Include(m => m.MachineNav)
|
|
.OrderByDescending(x => x.AlarmLogId)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmLogGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di un record AlarmLog
|
|
/// </summary>
|
|
/// <param name="newItem">Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmLogInsert(AlarmLogModel newItem)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
localDbCtx
|
|
.DbSetAlarmLog
|
|
.Add(newItem);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmLogInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di una lista record AlarmLog
|
|
/// </summary>
|
|
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmLogInsertMany(List<AlarmLogModel> newItems)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
if (newItems.Count > 0)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
await localDbCtx
|
|
.DbSetAlarmLog
|
|
.AddRangeAsync(newItems);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Info($"AlarmLogInsertMany| DB insert | {newItems.Count} rec | {ts.TotalMilliseconds} ms");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmLogInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiude ultimo record dato Id (se fossero + di 1 chiude tutti...)
|
|
/// </summary>
|
|
/// <param name="AlarmId">Id Allarme</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmRecCloseActive(int AlarmId)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
var candList = localDbCtx
|
|
.DbSetAlarmRec
|
|
.Where(x => x.AlarmId == AlarmId && x.DtStart >= x.DtEnd)
|
|
.ToList();
|
|
foreach (var item in candList)
|
|
{
|
|
item.DtEnd = adesso;
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecCloseActive{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiude ultimo record di allarmi aperti (avendo verificato zia zero da un pò...)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmRecCloseStarving()
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
var candList = localDbCtx
|
|
.DbSetAlarmRec
|
|
.Where(x => x.DtStart >= x.DtEnd)
|
|
.ToList();
|
|
foreach (var item in candList)
|
|
{
|
|
item.DtEnd = adesso;
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecCloseStarving{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco allarmi Rec ATTIVI (non chiusi)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AlarmRecModel> AlarmRecGetActive()
|
|
{
|
|
List<AlarmRecModel> dbResult = new List<AlarmRecModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAlarmRec
|
|
.AsNoTracking()
|
|
.Where(x => x.DtStart >= x.DtEnd)
|
|
.Include(m => m.AlarmListNav)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecGetActive{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco allarmi Rec (ultimi dato "skip")
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="skipRec"></param>
|
|
/// <param name="numRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<AlarmRecModel>> AlarmRecGetFilt(int MachineId, int skipRec, int numRec)
|
|
{
|
|
List<AlarmRecModel> dbResult = new List<AlarmRecModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = await localDbCtx
|
|
.DbSetAlarmRec
|
|
.AsNoTracking()
|
|
.Where(x => x.MachineId == MachineId)
|
|
.Include(m => m.MachineNav)
|
|
.Include(m => m.AlarmListNav)
|
|
.OrderByDescending(x => x.DtStart)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToListAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary> Recupero elenco allarmi Rec con data <= a quella di riferimento(ultimi dato
|
|
/// "skip") </summary> <param name="MachineId"></param> <param name="dtRif"></param> <param
|
|
/// name="skipRec"></param> <param name="numRec"></param> <returns></returns>
|
|
public List<AlarmRecModel> AlarmRecGetFiltByDate(int MachineId, DateTime dtRif, int skipRec, int numRec)
|
|
{
|
|
List<AlarmRecModel> dbResult = new List<AlarmRecModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAlarmRec
|
|
.AsNoTracking()
|
|
.Where(x => (x.MachineId == MachineId) && (x.DtStart <= dtRif))
|
|
.Include(m => m.MachineNav)
|
|
.Include(m => m.AlarmListNav)
|
|
.OrderByDescending(x => x.DtStart)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero lista sommatoria durata eventi allarme per analisi, ordinati in logica di
|
|
/// pareto (Max-min)
|
|
/// </summary>
|
|
/// <param name="machineId">Id Macchina</param>
|
|
/// <param name="dtFrom">inizio analisi (evento deve iniziare/finire entro periodo)</param>
|
|
/// <param name="dtTo">fine analisi (evento deve iniziare/finire entro periodo)</param>
|
|
/// <param name="minDur">durata minima evento per venire considerato, -1 = tutti</param>
|
|
/// <param name="maxDur">durata massima evento per venire considerato, -1 = tutti</param>
|
|
/// <returns></returns>
|
|
public List<AlarmDurationDTO> AlarmRecGetParetoDur(int machineId, DateTime dtFrom, DateTime dtTo, int minDur = -1, int maxDur = -1)
|
|
{
|
|
List<AlarmDurationDTO> dbResult = new List<AlarmDurationDTO>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
// effettuo il calcolo in + step...
|
|
var rawData = localDbCtx
|
|
.DbSetAlarmRec
|
|
.AsNoTracking()
|
|
.Where(x => x.MachineId == machineId
|
|
&& (x.DtStart >= dtFrom && x.DtStart <= dtTo)
|
|
&& (x.Duration >= minDur || minDur < 0)
|
|
&& (x.Duration <= maxDur || maxDur < 0))
|
|
.ToList();
|
|
|
|
//dbResult = localDbCtx
|
|
// .DbSetAlarmRec
|
|
// .AsNoTracking()
|
|
// .Where(x => x.MachineId == machineId
|
|
// && (x.DtStart >= dtFrom && x.DtStart <= dtTo)
|
|
// && (x.Duration >= minDur || minDur < 0)
|
|
// && (x.Duration <= maxDur || maxDur < 0))
|
|
dbResult = rawData
|
|
.GroupBy(g => g.AlarmId)
|
|
.Select(g => new AlarmDurationDTO() { MachineId = machineId, AlarmId = g.Key, Duration = g.Sum(x => x.Duration) })
|
|
.ToList()
|
|
.Join(
|
|
AlarmListGetAll(),
|
|
f => f.AlarmId,
|
|
l => l.AlarmId, (dur, list) => new AlarmDurationDTO()
|
|
{
|
|
AlarmId = dur.AlarmId,
|
|
Duration = dur.Duration,
|
|
MachineId = dur.MachineId,
|
|
AlarmDescription = list.FullValue
|
|
}
|
|
)
|
|
.OrderByDescending(o => o.Duration)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecGetParetoDur{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero lista di conteggio eventi allarme per analisi, ordinati in logica di pareto (Max-min)
|
|
/// </summary>
|
|
/// <param name="machineId">Id Macchina</param>
|
|
/// <param name="dtFrom">inizio analisi (evento deve iniziare DOPO questa data)</param>
|
|
/// <param name="dtTo">fine analisi (evento deve iniziare prima di questa data)</param>
|
|
/// <param name="minDur">durata minima evento per venire considerato, -1 = tutti</param>
|
|
/// <param name="maxDur">durata massima evento per venire considerato, -1 = tutti</param>
|
|
/// <returns></returns>
|
|
public List<AlarmFreqDTO> AlarmRecGetParetoFreq(int machineId, DateTime dtFrom, DateTime dtTo, int minDur = -1, int maxDur = -1)
|
|
{
|
|
List<AlarmFreqDTO> dbResult = new List<AlarmFreqDTO>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAlarmRec
|
|
.AsNoTracking()
|
|
.Where(x => x.MachineId == machineId
|
|
&& (x.DtStart >= dtFrom && x.DtStart <= dtTo)
|
|
&& (x.Duration >= minDur || minDur < 0)
|
|
&& (x.Duration <= maxDur || maxDur < 0))
|
|
.GroupBy(g => g.AlarmId)
|
|
.Select(g => new AlarmFreqDTO() { MachineId = machineId, AlarmId = g.Key, EventCount = g.Count() })
|
|
.ToList()
|
|
.Join(
|
|
AlarmListGetAll(),
|
|
f => f.AlarmId,
|
|
l => l.AlarmId, (freq, list) => new AlarmFreqDTO()
|
|
{
|
|
AlarmId = freq.AlarmId,
|
|
EventCount = freq.EventCount,
|
|
MachineId = freq.MachineId,
|
|
AlarmDescription = list.FullValue
|
|
}
|
|
)
|
|
.OrderByDescending(o => o.EventCount)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecGetParetoFreq{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di un record AlarmRec
|
|
/// </summary>
|
|
/// <param name="newItem">Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmRecInsert(AlarmRecModel newItem)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
localDbCtx
|
|
.DbSetAlarmRec
|
|
.Add(newItem);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di una lista record AlarmRec
|
|
/// </summary>
|
|
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public bool AlarmRecInsertMany(List<AlarmRecModel> newItems)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
if (newItems.Count > 0)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
// verifico eventuali items già aperti da NON dover aggiungere...
|
|
List<int>? stillOpenAlarms = localDbCtx
|
|
.DbSetAlarmRec
|
|
.Where(x => x.DtStart >= x.DtEnd)
|
|
.Select(x => x.AlarmId)
|
|
.ToList();
|
|
|
|
// costruisco l'elenco degli ID allarmi da inserire
|
|
List<int>? listNewId = newItems
|
|
.Select(x => x.AlarmId)
|
|
.Distinct()
|
|
.ToList();
|
|
|
|
var alarm2rem = listNewId.Intersect(stillOpenAlarms).ToList();
|
|
|
|
// andrò ad inserire solo gli item NON già presenti...
|
|
foreach (var item in alarm2rem)
|
|
{
|
|
var item2del = newItems.Where(x => x.AlarmId == item).ToList();
|
|
if (item2del != null)
|
|
{
|
|
foreach (var singleItem in item2del)
|
|
{
|
|
newItems.Remove(singleItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (newItems.Count > 0)
|
|
{
|
|
// aggiungo
|
|
localDbCtx
|
|
.DbSetAlarmRec
|
|
.AddRange(newItems);
|
|
// salvo!
|
|
localDbCtx.SaveChanges();
|
|
fatto = true;
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Info($"AlarmRecInsertMany| DB insert | {newItems.Count} rec | {ts.TotalMilliseconds} ms");
|
|
}
|
|
else
|
|
{
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Info($"Allarmi già presenti non reinseriti | {ts.TotalMilliseconds} ms");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmRecInsertMany{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero DataLogDTO data condizione filtro
|
|
/// </summary>
|
|
/// <param name="machineId">ID macchina</param>
|
|
/// <param name="dataType">Tipologia di dato richiesto da enum</param>
|
|
/// <param name="fluxType">Tipo di Flusso</param>
|
|
/// <param name="inizio">DT Inizio estrazione</param>
|
|
/// <param name="fine">DT Fine estrazione</param>
|
|
/// <returns></returns>
|
|
public async Task<List<DataLogDTO>> DataLogDtoGetFilt(int machineId, DataLogType dataType, string fluxType, DateTime inizio, DateTime fine)
|
|
{
|
|
List<DataLogDTO> dbResult = new List<DataLogDTO>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = await localDbCtx
|
|
.DbSetDataLog
|
|
.Where(x => (x.MachineId == machineId) && (x.FluxType == fluxType) && (x.DataType == dataType || dataType == DataLogType.ND) && (x.DtRif >= inizio && x.DtRif <= fine))
|
|
.Select(r => new DataLogDTO() { DataLogId = r.DataLogId, DtRif = r.DtRif, ValNum = r.ValNum })
|
|
.OrderByDescending(x => x.DataLogId)
|
|
.ToListAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataLogDtoGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero record DataLog data condizione filtro
|
|
/// </summary>
|
|
/// <param name="dataType">Tipologia di dato richiesto da enum</param>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <param name="machineId"></param>
|
|
/// <param name="fluxType"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<DataLogModel>> DataLogGetFilt(DataLogType dataType, DateTime inizio, DateTime fine, int machineId, string fluxType)
|
|
{
|
|
List<DataLogModel> dbResult = new List<DataLogModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = await localDbCtx
|
|
.DbSetDataLog
|
|
.Where(x => (x.MachineId == machineId) && (x.FluxType == fluxType) && (x.DataType == dataType || dataType == DataLogType.ND) && (x.DtRif >= inizio && x.DtRif <= fine))
|
|
.Include(m => m.MachineNav)
|
|
.OrderByDescending(x => x.DataLogId)
|
|
.ToListAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataLogGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero record DataLog data condizione filtro (multi-flusso)
|
|
/// </summary>
|
|
/// <param name="dataType">Tipologia di dato richiesto da enum</param>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<DataLogModel>> DataLogGetFilt(DataLogType dataType, DateTime inizio, DateTime fine)
|
|
{
|
|
List<DataLogModel> dbResult = new List<DataLogModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = await localDbCtx
|
|
.DbSetDataLog
|
|
.Where(x => (x.DataType == dataType || dataType == DataLogType.ND) && (x.DtRif >= inizio && x.DtRif <= fine))
|
|
.Include(m => m.MachineNav)
|
|
.OrderByDescending(x => x.DataLogId)
|
|
.ToListAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataLogGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di un SET di record DataLog (post aggregazione base VC)
|
|
/// </summary>
|
|
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DataLogInsertMany(List<DataLogModel> newItems)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
await localDbCtx
|
|
.DbSetDataLog
|
|
.AddRangeAsync(newItems);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataLogInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero record DataStAg (aggregati) data condizione filtro
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="FluxType"></param>
|
|
/// <param name="skipRec"></param>
|
|
/// <param name="numRec"></param>
|
|
/// <returns></returns>
|
|
public List<DataStAgModel> DataStAgGetFilt(int MachineId, string FluxType, int skipRec, int numRec)
|
|
{
|
|
List<DataStAgModel> dbResult = new List<DataStAgModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetDataStAg
|
|
.Where(x => x.MachineId == MachineId && x.FluxType == FluxType)
|
|
.Include(m => m.MachineNav)
|
|
.OrderByDescending(x => x.DataStAgId)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataLogGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di un record DataStAg (aggregati) - creati da ANALYZER che effettua compattazione
|
|
/// </summary>
|
|
/// <param name="newItem">Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DataStAgInsert(DataStAgModel newItem)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
localDbCtx
|
|
.DbSetDataStAg
|
|
.Add(newItem);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataStAgInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
//Log.Info("Dispose di GWMSController");
|
|
}
|
|
|
|
public List<DisplayDataDTO> MachineGetDisplay()
|
|
{
|
|
List<DisplayDataDTO> answ = new List<DisplayDataDTO>();
|
|
|
|
// !!!FIXME TODO... è fake...
|
|
|
|
Random rand = new Random();
|
|
double currVal = 0;
|
|
currVal = rand.Next(10, 120) * 100;
|
|
DisplayDataDTO displ01 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "SPEED",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N0"),
|
|
Type = "SPEED-5000-10000"
|
|
};
|
|
answ.Add(displ01);
|
|
|
|
currVal = rand.Next(10, 100) * 100;
|
|
DisplayDataDTO displ02 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "FEED",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N0"),
|
|
Type = "FEED-3000-5000"
|
|
};
|
|
answ.Add(displ02);
|
|
|
|
currVal = rand.NextDouble() * 1.2;
|
|
DisplayDataDTO displ03 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "SPINDLE LOAD",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("P0"),
|
|
Type = "ORDER"
|
|
};
|
|
answ.Add(displ03);
|
|
|
|
currVal = rand.NextDouble() * 5000;
|
|
DisplayDataDTO displ04 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "X POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ04);
|
|
|
|
currVal = rand.NextDouble() * 10000;
|
|
DisplayDataDTO displ05 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Y POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ05);
|
|
|
|
currVal = rand.NextDouble() * -3000;
|
|
DisplayDataDTO displ06 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Z POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ06);
|
|
|
|
Task.Delay(200).Wait();
|
|
|
|
return answ;
|
|
}
|
|
|
|
public ProductionDTO MachineGetProd()
|
|
{
|
|
// !!!FIXME TODO... è fake...
|
|
|
|
Random rand = new Random();
|
|
int stdCycle = 5;
|
|
|
|
ProductionDTO currMachDto = new ProductionDTO()
|
|
{
|
|
Order = "ODL Test",
|
|
ItemCode = "ART.0000123",
|
|
ProgName = "P000012",
|
|
CurrQty = DateTime.Now.Minute + rand.Next(1, 40),
|
|
OrderQty = 100,
|
|
CycleTimeMin = rand.NextDouble() * stdCycle,
|
|
Message = "...simulated data..."
|
|
};
|
|
|
|
Task.Delay(400).Wait();
|
|
|
|
return currMachDto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco contatori ammessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<CounterModel> PMCounterModelGetAll()
|
|
{
|
|
List<CounterModel> dbResult = new List<CounterModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetCounter
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMCounterModelGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco Gruppi Macchina PM ammessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PMMGroupModel> PMMachGroupGetAll()
|
|
{
|
|
List<PMMGroupModel> dbResult = new List<PMMGroupModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetPMMachGroup
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMMachGroupGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione Record
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <param name="forceDelete"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PMTaskDeleteRecord(PrevMaintTaskModel currRec, bool forceDelete)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
var currVal = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.PMTaskId == currRec.PMTaskId)
|
|
.FirstOrDefault();
|
|
if (currVal != null)
|
|
{
|
|
// se effettivo delete
|
|
if (forceDelete)
|
|
{
|
|
localDbCtx
|
|
.DbSetPMTask
|
|
.Remove(currVal);
|
|
}
|
|
else
|
|
{
|
|
currVal.IsDisabled = true;
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
}
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMTaskDeleteRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Riabilitazione task disabilitato
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PMTaskEnableRecord(PrevMaintTaskModel currRec)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
var currVal = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.PMTaskId == currRec.PMTaskId)
|
|
.FirstOrDefault();
|
|
if (currVal != null)
|
|
{
|
|
// se effettivo delete
|
|
if (currRec.IsDisabled)
|
|
{
|
|
currVal.IsDisabled = false;
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
}
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMTaskEnableRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco Topics PM ammessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PMTaskTopicModel> PMTaskTopicGetAll()
|
|
{
|
|
List<PMTaskTopicModel> dbResult = new List<PMTaskTopicModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetPMTopic
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMTaskTopicGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco User Team PM ammessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PMUTModel> PMUTeamGetAll()
|
|
{
|
|
List<PMUTModel> dbResult = new List<PMUTModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetUTeam
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMUTeamGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco Task Manut Prev Previsti/Configurati (ultimi dato "skip")
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="skipRec"></param>
|
|
/// <param name="numRec"></param>
|
|
/// <returns></returns>
|
|
public List<PrevMaintTaskModel> PrevMaintTaskGetFilt(int MachineId, int skipRec, int numRec)
|
|
{
|
|
List<PrevMaintTaskModel> dbResult = new List<PrevMaintTaskModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.MachineId == MachineId)
|
|
.Include(m => m.CounterNav)
|
|
.Include(m => m.MachGroupNav)
|
|
.Include(m => m.MachineNav)
|
|
.Include(m => m.TopicNav)
|
|
.Include(m => m.UserTeamNav)
|
|
.OrderBy(x => x.ExtIdx)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PrevMaintTaskGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue update del record
|
|
/// </summary>
|
|
/// <param name="editRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PrevMaintTaskUpdate(PrevMaintTaskModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.PMTaskId == editRec.PMTaskId)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.CCode = editRec.CCode;
|
|
currRec.ExpiryVal = editRec.ExpiryVal;
|
|
currRec.ExtIdx = editRec.ExtIdx;
|
|
currRec.PMMGCode = editRec.PMMGCode;
|
|
currRec.PMTCode = editRec.PMTCode;
|
|
currRec.PMUTCode = editRec.PMUTCode;
|
|
currRec.JobDescription = editRec.JobDescription;
|
|
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
// se nuovo (user edit) --> NON protetto!
|
|
editRec.Protected = false;
|
|
localDbCtx
|
|
.DbSetPMTask
|
|
.Add(editRec);
|
|
}
|
|
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PrevMaintTaskUpdate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// genera elenco Task Schedulati missing da schema + attualmente presenti...
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> SchedMaintTaskCreateMissing(int MachineId)
|
|
{
|
|
bool answ = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
List<PrevMaintTaskModel> missTask = new List<PrevMaintTaskModel>();
|
|
|
|
// elenco dei task NON disattivati
|
|
List<PrevMaintTaskModel>? allTask = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.MachineId == MachineId && !x.IsDisabled)
|
|
.Include(i => i.CounterNav)
|
|
.ToList();
|
|
|
|
// analizzo task per idx del PMTask
|
|
var reqTask = allTask
|
|
.Select(x => x.PMTaskId)
|
|
.ToList();
|
|
|
|
var openTask = localDbCtx
|
|
.DbSetSMTask
|
|
.Where(x => x.DtExecution == DateTime.MinValue)
|
|
.Include(m => m.PMTaskeNav)
|
|
.ToList();
|
|
|
|
var currTask = openTask
|
|
.Where(x => x.PMTaskeNav.MachineId == MachineId)
|
|
.Select(x => x.PMTaskId)
|
|
.ToList();
|
|
|
|
// elenco dei SOLI task presenti
|
|
var listTaskOk = currTask.Intersect(reqTask).ToList();
|
|
|
|
// dall'elenco di quelli originali elimino presenti --> ho elenco mancanti...
|
|
foreach (var iTask in allTask)
|
|
{
|
|
// se non nell'elenco aggiungo...
|
|
if (!listTaskOk.Exists(x => x == iTask.PMTaskId))
|
|
{
|
|
missTask.Add(iTask);
|
|
}
|
|
}
|
|
|
|
var newRecs = missTask.Select(x => new PendingMaintModel()
|
|
{
|
|
CCode = x.CCode,
|
|
DtCreation = DateTime.Now,
|
|
ExpiryVal = x.ExpiryVal,
|
|
PMTaskId = x.PMTaskId,
|
|
CountStartVal = x.CounterNav.ActualVal
|
|
}).ToList();
|
|
|
|
localDbCtx
|
|
.DbSetSMTask
|
|
.AddRange(newRecs);
|
|
|
|
// salvo
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SchedMaintTaskGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco Task Schedulati dati Macchina ed intervento "master"
|
|
/// </summary>
|
|
/// <param name="MachineId">Macchina selezionata</param>
|
|
/// <param name="PMTaskId">ID del PMTask parent</param>
|
|
/// <param name="skipRec">Num record da saltare</param>
|
|
/// <param name="numRec">num rec da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<PendingMaintModel> SchedMaintTaskGetByPMTask(int MachineId, int PMTaskId, int skipRec, int numRec)
|
|
{
|
|
List<PendingMaintModel> dbResult = new List<PendingMaintModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetSMTask
|
|
.Include(i => i.CounterNav)
|
|
.Where(x => x.PMTaskeNav.MachineId == MachineId && x.PMTaskId == PMTaskId && x.DtExecution > DateTime.MinValue)
|
|
.Include(m => m.PMTaskeNav.MachGroupNav)
|
|
.Include(m => m.CounterNav)
|
|
.Include(m => m.PMTaskeNav.MachineNav)
|
|
.Include(m => m.PMTaskeNav.TopicNav)
|
|
.Include(m => m.PMTaskeNav.UserTeamNav)
|
|
.OrderByDescending(x => x.DtCreation)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SchedMaintTaskGetByPMTask{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco Task Schedulati (ultimi dato "skip")
|
|
/// </summary>
|
|
/// <param name="MachineId">Macchina selezionata</param>
|
|
/// <param name="skipRec">Num record da saltare</param>
|
|
/// <param name="numRec">num rec da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<PendingMaintModel> SchedMaintTaskGetFilt(int MachineId, int skipRec, int numRec)
|
|
{
|
|
List<PendingMaintModel> dbResult = new List<PendingMaintModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetSMTask
|
|
.Include(i => i.CounterNav)
|
|
.Where(x => x.PMTaskeNav.MachineId == MachineId && x.DtExecution == DateTime.MinValue)
|
|
.Include(m => m.PMTaskeNav.MachGroupNav)
|
|
.Include(m => m.CounterNav)
|
|
.Include(m => m.PMTaskeNav.MachineNav)
|
|
.Include(m => m.PMTaskeNav.TopicNav)
|
|
.Include(m => m.PMTaskeNav.UserTeamNav)
|
|
.OrderBy(x => x.PMTaskeNav.ExtIdx)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SchedMaintTaskGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registro esecuzione task schedualto
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="SMTaskId"></param>
|
|
/// <param name="ExecDT"></param>
|
|
/// <param name="ExecUser"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> SchedMaintTaskSetDone(int MachineId, int SMTaskId, DateTime ExecDT, string ExecUser)
|
|
{
|
|
bool answ = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
// Aggiorno il task schedulato
|
|
var dbResult = localDbCtx
|
|
.DbSetSMTask
|
|
.Include(i => i.CounterNav)
|
|
.Where(x => x.PMTaskeNav.MachineId == MachineId && x.SMTaskId == SMTaskId)
|
|
.FirstOrDefault();
|
|
if (dbResult != null)
|
|
{
|
|
// aggiorno il record
|
|
dbResult.DtExecution = ExecDT;
|
|
dbResult.UserCode = ExecUser;
|
|
dbResult.ElapsedVal = dbResult.CounterNav.ActualVal - dbResult.CountStartVal;
|
|
|
|
// aggiorno il task parent col numero di task eseguiti...
|
|
int numDone = localDbCtx
|
|
.DbSetSMTask
|
|
.Where(x => x.PMTaskId == dbResult.PMTaskId)
|
|
.Count();
|
|
var parentRecord = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.PMTaskId == dbResult.PMTaskId)
|
|
.FirstOrDefault();
|
|
if (parentRecord != null)
|
|
{
|
|
parentRecord.NumTaskDone = numDone;
|
|
}
|
|
|
|
// eseguo salvataggi!
|
|
localDbCtx.SaveChanges();
|
|
// segno fatto!
|
|
answ = true;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SchedMaintTaskSetDone{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |