예제 #1
0
        private List <MachineInfoViewModel> GetMachines(List <MachineInfoModel> allMachines, bool onlyActive)
        {
            var result = new List <MachineInfoViewModel>();
            List <MachineInfoModel> dataAllMachines = null;

            if (onlyActive)
            {
                dataAllMachines = allMachines.Where(m => m.PlantId > 0 && (m.ExpirationDate == null || m.ExpirationDate > DateTime.UtcNow)).OrderBy(m => m.Serial).ToList();
            }
            else
            {
                dataAllMachines = allMachines.Where(p => p.PlantId > 0).OrderBy(m => m.Serial).ToList();
            }

            dataAllMachines.OrderBy(m => m.Serial);
            foreach (var dataMachine in dataAllMachines)
            {
                var machine = allMachines.FirstOrDefault(w => w.Id == dataMachine.Id);

                if (machine?.Type == null || machine.Model == null)
                {
                    continue;
                }

                var mac = new MachineInfoViewModel
                {
                    id          = machine.Id,
                    description = machine.Description == string.Empty ? null : machine.Description,
                    model       = machine.Model.Name,
                    machineName = machine.MachineName,
                    icon        = machine.Type.Image,
                    expired     = dataMachine.ExpirationDate == null || dataMachine.ExpirationDate > DateTime.UtcNow,
                    id_mtype    = machine.Type?.Id ?? 0,
                    serial      = machine.Serial
                };

                result.Add(mac);
            }

            result.OrderBy(m => m.serial).ToList();
            return(result);
        }
예제 #2
0
        public List <MachineMessagesDataViewModel> GetVueModel(PlantModel plant, List <MachineInfoModel> allMachines, PeriodModel period)
        {
            if (period.StartDate == DateTime.MinValue || period.EndDate == DateTime.MinValue)
            {
                period.EndDate   = DateTime.UtcNow;
                period.StartDate = DateTime.Now.AddDays(-30);
            }
            var result = new List <MachineMessagesDataViewModel>();

            var dataAllMachines = _mesService.GetPlantData(plant);

            foreach (var dataMachine in dataAllMachines)
            {
                var machine = allMachines.FirstOrDefault(w => w.Id == dataMachine.MachineId);

                if (machine == null)
                {
                    continue;
                }

                var machineInfo = new MachineInfoViewModel()
                {
                    id          = machine.Id,
                    description = machine.Description == string.Empty ? null : machine.Description,
                    model       = machine.Model.Name,
                    machineName = machine.MachineName,
                    icon        = machine.Type.Image,
                    serial      = machine.Serial
                };


                var data = _messageService.GetMessageDetails(machine, period);

                if (data.Count == 0)
                {
                    continue;
                }

                var msgDet = data.Select(a => new MessageDetailViewModel()
                {
                    code       = a.Code,
                    parameters = a.Params,
                    timestamp  = DateTime.SpecifyKind(a.Day ?? DateTime.MinValue, DateTimeKind.Utc),
                    utc        = machine.UTC ?? 0,
                    type       = ((enTypeAlarm)a.Type).GetDescription(),
                    //((enTypeAlarm)a.StateId).GetDescription(),
                    group       = a.GroupName,
                    time        = CommonViewService.getTimeViewModel(a.ElapsedTime),
                    description = a.Description
                }).ToList();

                foreach (var det in msgDet)
                {
                    var msg = new MachineMessagesDataViewModel();
                    msg.message = det;
                    msg.machine = machineInfo;
                    result.Add(msg);
                }
            }
            if (result.Count == 0)
            {
                result = null;
            }

            return(result);
        }