Ejemplo n.º 1
0
        protected override void Context()
        {
            _journalPageFactory      = A.Fake <IJournalPageFactory>();
            _databaseMediator        = A.Fake <IDatabaseMediator>();
            _journalRetriever        = A.Fake <IJournalRetriever>();
            _eventPublisher          = A.Fake <IEventPublisher>();
            _journalSessionConnector = A.Fake <IJournalSessionConnector>();
            _relatedItemFactory      = A.Fake <IRelatedItemFactory>();
            _journalPageTask         = A.Fake <IJournalPageTask>();

            _dialogCreator = A.Fake <IDialogCreator>();
            sut            = new JournalTask(_journalPageFactory,
                                             _databaseMediator, _journalRetriever, _eventPublisher, _journalSessionConnector, _relatedItemFactory, _journalPageTask, _dialogCreator);


            _journal = new Journal.Journal();
            _journalRetriever.Current = _journal;

            _journalPage = new JournalPage();
        }
Ejemplo n.º 2
0
        //30 - Приёмка поезда ПР
        //31 - Выпуск поезда ПР
        //32 - Приёмка поезда ЛБ
        //33 - Сдача поезда ЛБ

        public async Task <JournalPaging> GetJournalInspectionAndTasks(int skip, int limit, string filter)
        {
            var sqlr = new InspectionRepository(_logger);

            var inspdatarep  = new InspectionDataRepository(_logger);
            var sqlTrainR    = new TrainRepository(_logger);
            var sqlUserR     = new UserRepository(_logger);
            var iR           = new InspectionRepository(_logger);
            var mR           = new MeterageRepository(_logger);
            var sqlStatusR   = new TaskStatusRepository(_logger);
            var sqlExecutorR = new ExecutorRepository(_logger);
            var sqlRTask     = new TaskRepository(_logger);
            var sqlRBrigade  = new BrigadeRepository(_logger);
            var sqlRJournal  = new JournalRepository(_logger);

            var listFull = new List <JournalDateItem>();

            var fromSqlsInspections = await sqlr.GetAll();

            foreach (var fromSqlsInspection in fromSqlsInspections)
            {
                var train = (await sqlTrainR.ByIdWithStations(fromSqlsInspection.TrainId));
                var user  = await sqlUserR.ById(fromSqlsInspection.UserId);

                var journalInspection = new JournalInspection
                {
                    Id           = fromSqlsInspection.Id,
                    Type         = "inspection",
                    InspectionId = fromSqlsInspection.Id,
                    StatusId     = (int)fromSqlsInspection.Status,
                    TypeId       = (int)fromSqlsInspection.CheckListType,
                    Date         = fromSqlsInspection.DateStart,
                    TrainName    = train.Name,
                    TrainId      = train.Id,
                    Tabs         = new JournalInspectionTabs(),
                    UserName     = user.Name,
                };

                if (user.BrigadeId != null)
                {
                    journalInspection.OwnerBrigadeType = (await sqlRBrigade.ById((int)user.BrigadeId)).BrigadeType;
                }


                //дескрипшен
                var counters = await iR.GetCounters(fromSqlsInspection.Id);

                journalInspection.Tabs.Description = new JournalInspectionDescription
                {
                    TasksCount = counters.Tasks,
                    DataEnd    = fromSqlsInspection.DateEnd,
                    //Выдает количество уникальных меток
                    AllLabelCount = counters.Labels,
                    TempCount     = counters.Measurements
                };


                //лейблы
                await getInspectionLabels(mR, fromSqlsInspection, journalInspection);

                //измерения
                await getInspectionMeterage(mR, fromSqlsInspection, journalInspection);

                //счетчики
                await GetInspectionCouters(inspdatarep, fromSqlsInspection, journalInspection);

                //говнохак под ебанутые фильтры и вывод. TypeId == 2 - Приемка, 3 - сдача
                changeInspetionTypeForUi(journalInspection);


                //Фильтруем
                var isFiltered = await InspectionFilter(filter, sqlRTask, fromSqlsInspection, journalInspection);

                if (!isFiltered)
                {
                    listFull.Add(new JournalDateItem
                    {
                        Date       = journalInspection.Date,
                        Inspection = journalInspection
                    }
                                 );
                }
            }


            //Таски

            var fromSqlsT = await sqlRJournal.GetAllTaskForJournal();

            foreach (var fromSql in fromSqlsT)
            {
                var journalTask = new JournalTask
                {
                    Type                  = "Task",
                    TaskId                = fromSql.TaskId,
                    TaskType              = fromSql.TaskType,
                    TrainName             = fromSql.TrainName,
                    TrainId               = fromSql.TrainId,
                    UserName              = fromSql.UserName,
                    Date                  = fromSql.CreateDate,
                    CarriageName          = CreateCarriageName(fromSql.TrainName, fromSql.CarriageNumber),
                    CarriageNum           = fromSql.CarriageNumber,
                    CarriageId            = fromSql.CarriageId,
                    EquipmentName         = fromSql.EquipmentName,
                    FaultName             = fromSql.FaultName,
                    InspectionInfo        = _GetInspectionInfo(fromSql.InspectionId, fromSql.InspectionType),
                    CarriagesSerialNumber = fromSql.CarriagesSerialNumber,
                    TaskAttributeId       = fromSql.TaskAttributeId
                };

                var executor = (await sqlExecutorR.GetByTaskId(fromSql.TaskId)).LastOrDefault();
                if (executor != null)
                {
                    journalTask.ExecutorBrigadeType = (int)executor.BrigadeType;
                }


                var taskStatus = sqlStatusR.GetByTrainTaskId(fromSql.TaskId);
                if (taskStatus != null)
                {
                    journalTask.StatusId = (int)sqlStatusR.GetByTrainTaskId(fromSql.TaskId).Status;
                }
                //journalTask.StatusId = fromSql.TaskId;

                var isFiltered = TaskFilter(filter, fromSql, journalTask);
                if (!isFiltered)
                {
                    //response.Add(journalTask.ToJson());
                    listFull.Add(new JournalDateItem
                    {
                        Date = journalTask.Date,
                        Task = journalTask
                    }
                                 );
                }
            }



            //sort by date
            listFull.Sort((x, y) => y.Date.CompareTo(x.Date));

            //пагинация
            List <JournalDateItem> listSkiplimit = paging(skip, ref limit, listFull);

            //Делаем жсон стрингу для вывода
            var pagingList = new List <string>();

            converToJsonString(listSkiplimit, pagingList);

            var result = new JournalPaging
            {
                Data  = pagingList.ToArray(),
                Total = listFull.Count
            };

            return(result);
        }
Ejemplo n.º 3
0
        private static bool TaskFilter(string filter, JournalTaskFromSql fromSql, JournalTask journalTask)
        {
            var isFiltered = false;

            if (filter != null)
            {
                var filters = JsonConvert.DeserializeObject <TaskCommon.FilterBody[]>(filter);
                foreach (var item in filters)
                {
                    switch (item.Filter)
                    {
                    case "DateFrom":
                        DateTime.TryParse(item.Value, out var dateStart);
                        if (fromSql.CreateDate < dateStart)
                        {
                            isFiltered = true;
                        }
                        break;

                    case "DateTo":
                        DateTime.TryParse(item.Value, out var dateEnd);
                        dateEnd = dateEnd.AddDays(1);
                        if (fromSql.CreateDate > dateEnd)
                        {
                            isFiltered = true;
                        }
                        break;

                    case "InspectionId":
                        isFiltered = true;
                        break;

                    case "TrainName":
                        if (!fromSql.TrainName.ToLower().Contains(item.Value.ToLower()))
                        {
                            isFiltered = true;
                        }
                        break;

                    case "TrainId":
                        int.TryParse(item.Value, out var trainid);
                        if (fromSql.TrainId != trainid)
                        {
                            isFiltered = true;
                        }
                        break;

                    //по номеру вагона
                    case "CarriageNum":
                        if (int.TryParse(item.Value, out var intResult))
                        {
                            if (journalTask.CarriageNum != intResult)
                            {
                                isFiltered = true;
                            }
                        }
                        break;

                    case "CarriageId":
                        if (int.TryParse(item.Value, out var carriageid))
                        {
                            if (journalTask.CarriageId != carriageid)
                            {
                                isFiltered = true;
                            }
                        }
                        break;

                    //Инициатор
                    case "OwnerId":
                        if (!journalTask.UserName.ToLower().Contains(item.Value.ToLower()))
                        {
                            isFiltered = true;
                        }
                        break;

                    //Статус
                    case "StatusId":
                        int.TryParse(item.Value, out var intResultS);
                        if (journalTask.StatusId != intResultS)
                        {
                            isFiltered = true;
                        }
                        break;

                    case "BrigadeId":
                        int.TryParse(item.Value, out var intResultB);
                        if (journalTask.ExecutorBrigadeType != intResultB)
                        {
                            isFiltered = true;
                        }
                        break;

                    //Нет тут мероприятей блядь Есть тип. Но хуй его знает У задач он одит
                    case "TypeId":
                        int.TryParse(item.Value, out var intResultT);
                        //Мы будем гореть в аду. Ебаные аналитики хуевы
                        var realTaskType = 999;
                        if (intResultT == 40)
                        {
                            realTaskType = 0;
                        }
                        if (intResultT == 41)
                        {
                            realTaskType = 1;
                        }
                        if (intResultT == 42)
                        {
                            realTaskType = 2;
                        }
                        if (journalTask.TaskType != realTaskType)
                        {
                            isFiltered = true;
                        }
                        break;

                    case "TaskOrInspectionId":
                        if (!journalTask.TaskId.ToString().Equals(item.Value))
                        {
                            isFiltered = true;
                        }
                        break;

                    case "Equipment":
                        if (!journalTask.EquipmentName.ToLower().Contains(item.Value.ToLower()))
                        {
                            isFiltered = true;
                        }
                        break;
                    }
                }
            }

            return(isFiltered);
        }