Fix Fanuc library

WIP alarms filters
This commit is contained in:
Lucio Maranta
2018-11-14 17:32:21 +01:00
parent aaaa8f8462
commit 209c14530f
16 changed files with 207 additions and 178 deletions
+29 -11
View File
@@ -7,6 +7,7 @@ using System.Data.Entity;
using System.IO;
using System.Linq;
using static Step.Model.Constants;
using static Step.Config.ServerConfig;
namespace Step.Database.Controllers
{
@@ -26,22 +27,39 @@ namespace Step.Database.Controllers
dbCtx.Dispose();
}
public List<DTOAlarmHistoricModel> GetPaginatedWithFilter(string message, List<ALARM_TYPE> types, int page, int pageSize, DateTime startDate, DateTime endDate, List<int> userIds)
public List<DTOAlarmHistoricModel> GetPaginatedWithFilter(string title, List<ALARM_TYPE> types, int page, int pageSize, DateTime startDate, DateTime endDate, List<int> userIds, Dictionary<int, string> plcMessages)
{
var occurrences = dbCtx
List<int> ncAlarmDescIds = dbCtx
.AlarmDescriptions
.Where(x => x.Title.Contains(title))
.Select(x => x.AlarmId)
.ToList();
// Add Plc messages
List<int> plcAlarmDescIds =
plcMessages
.Where(x => x.Value.Contains(title))
.Select(x => x.Key)
.ToList();
var occurrencesQuery = dbCtx
.AlarmOccurrences
.OrderBy(x => x.AlarmOccurrenceId)
.Include("Users")
.Include("Users")
.Where(x =>
x.TimeStamp >= startDate && x.TimeStamp <= endDate
&& types.Contains(x.Type)
&& x.Users.Any(y => userIds.Any(z => z == y.UserId))
)
.Skip(page * pageSize)
.Take(pageSize)
.Include("AlarmDescription")
.ToList();
&& ((x.Source == ALARM_SOURCE.NC && ncAlarmDescIds.Contains(x.AlarmDescriptionId.Value))
|| (x.Source == ALARM_SOURCE.PLC && plcAlarmDescIds.Contains(x.PlcMessageId.Value)))
);
var occurrences = occurrencesQuery
.Skip(page * pageSize)
.Take(pageSize)
.Include("AlarmDescription")
.ToList();
return occurrences
.Select(x => (DTOAlarmHistoricModel)x)
.ToList();
@@ -51,7 +69,7 @@ namespace Step.Database.Controllers
{
dbCtx.AlarmOccurrences.AddRange(alarms);
dbCtx.SaveChanges();
dbCtx.SaveChangesAsync();
}
public void InsertNewNcAlarmDescriptions(List<AlarmDescriptionsModel> descriptions)
@@ -66,7 +84,7 @@ namespace Step.Database.Controllers
dbCtx.AlarmDescriptions.Add(desc);
}
dbCtx.SaveChanges();
dbCtx.SaveChangesAsync();
}
public void InsertNewAlarmUser(List<AlarmUserModel> loggedUser)