public async Task TaskFucker(ActCategoriesRepository sqlRAct, List <TaskRepository.TrainTaskWithStatus> tasks, ActCategoriesRepository.EquipmentActsPdf item) { var sqlRTs = new TaskStatusRepository(_logger); foreach (var task in tasks) { var iWantSleep = await sqlRAct.GetByEquipmentId(task.EquipmentModel.Equipment.Id); if (iWantSleep.Count > 0) { var value = iWantSleep.FirstOrDefault(); if (value.Name.Equals(item.ActName)) { if (item.BadR1 == null) { item.BadR1 = 0; } item.BadR1++; item.CarriageNumR1.Add(task.Carriage.Number);//$" {other.CreateCarriageNameWithOutTrain(task.Carriage.Number)};"; //выполненые var taskStatuses = await sqlRTs.ByTaskId(task.Id); var isDone = false; foreach (var status in taskStatuses) { if (status.Status == TaskStatus.Closed) { if (item.GoodR2 == null) { item.GoodR2 = 0; } item.GoodR2++; item.CarriageNumR2.Add(task.Carriage.Number); isDone = true; break; } } if (!isDone) { if (item.BadR3 == null) { item.BadR3 = 0; } item.BadR3++; item.CarriageNumR3.Add(task.Carriage.Number); } } } } }
private async static Task <TrainTask> CheckTrainTaskExist(TaskStatusRepository sqlRStatus, List <TrainTask> allTasks) { TrainTask trainTaskToAdd = null; if (allTasks.Count > 0) { foreach (var value in allTasks) { var statuses = await sqlRStatus.ByTaskId(value.Id); if (statuses.Length > 0 && statuses.Last().Status != TaskStatus.Closed) { trainTaskToAdd = value; } } } return(trainTaskToAdd); }
/// <summary> /// Инциденты – вкладка с перечнем открытых инцидентов на составе, с возможностью перехода в форму инцидента при клике по нему. Информация будет выводится в табличном виде, со следующим набором полей: /// </summary> private static async Task <ReportResponse> GetNotClosedTrainTaskTable(ReportRequest input, int planedRouteTrainId, ILogger logger) { var sqlRTrains = new TrainRepository(logger); var sqlRTask = new TaskRepository(logger); var sqlRPlanedRouteTrains = new PlanedRouteTrainsRepository(logger); var sqlRRoute = new RoutesRepository(logger); var sqlRInspections = new InspectionRepository(logger); var sqlRTaskAttributes = new TrainTaskAttributesRepository(logger); var sqlREquipmentModel = new EquipmentModelsRepository(logger); var sqlREquipment = new EquipmentRepository(logger); var sqlRCarriage = new CarriageRepository(logger); var sqlRTaskStatus = new TaskStatusRepository(logger); var result = new ReportResponse { Rows = new List <Row>() }; result.Columns = new List <Column> { new Column("col0", "Номер", "number"), new Column("col1", "Статус", "string"), new Column("col2", "Тип", "string"), new Column("col3", "Вагон", "string"), new Column("col4", "Оборудование", "string"), new Column("col5", "Дата", "date"), }; var planedRouteTrain = await sqlRPlanedRouteTrains.ById(planedRouteTrainId); //var route = await sqlRRoute.ById(planedRouteTrain.RouteId); var trainTasks = await sqlRTask.ByTrainId(planedRouteTrain.TrainId); var notClosedTasks = new List <TrainTask>(); foreach (var trainTask in trainTasks) { var status = await sqlRTaskStatus.ByTaskId(trainTask.Id); if (status.Length == 0) { continue; } if (status.Last().Status != TaskStatus.Closed) { notClosedTasks.Add(trainTask); } } foreach (var notClosedTask in notClosedTasks) { var taskAtributes = await sqlRTaskAttributes.ByTaskId(notClosedTask.Id); var lastStatus = await sqlRTaskStatus.ByTaskId(notClosedTask.Id); var carriage = await sqlRCarriage.GetById(notClosedTask.CarriageId); var equipmentModel = await sqlREquipmentModel.ById(notClosedTask.EquipmentModelId); var equpment = await sqlREquipment.ById(equipmentModel.EquipmentId); foreach (var taskAtribute in taskAtributes) { var row = new Row { Id = new RowId(notClosedTask.Id, 1), HasItems = false.ToString(), ParentId = null, //Номер Col0 = $"И{notClosedTask.Id}", //Статус Col1 = GetStringTaskStatus(lastStatus.Last().Status), //Тип Col2 = GetStringTaskType(notClosedTask.TaskType), //Вагон Col3 = $"{carriage.Number} - {carriage.Serial}", //Оборудование Col4 = equpment.Name, //Дата Col5 = notClosedTask.CreateDate.ToStringDateTime(), }; result.Rows.Add(row); } } return(result); }
private static async Task <List <Row> > GetTaskData(List <TrainTask> tasks, ILogger logger) { var sqlRUsers = new UserRepository(logger); var sqlRTaskStatus = new TaskStatusRepository(logger); var sqlRTaskExecutors = new ExecutorRepository(logger); var sqlRTaskComment = new CommentRepository(logger); var sqlRCarriages = new CarriageRepository(logger); var sqlREquipmentModel = new EquipmentModelsRepository(logger); var sqlREquipment = new EquipmentRepository(logger); var sqlRTrains = new TrainRepository(logger); var sqlRTrainTaskAttributes = new TrainTaskAttributesRepository(logger); var sqlRFault = new FaultsRepository(logger); var rows = new List <Row>(); foreach (var task in tasks) { var currentTaskStatus = (await sqlRTaskStatus.ByTaskId(task.Id)).Last(); var carriage = await sqlRCarriages.ById(task.CarriageId); var user = GetUserById(sqlRUsers, task.UserId); var taskExecutor = (await sqlRTaskExecutors.GetByTaskId(task.Id)).Last(); var equipmentModel = await sqlREquipmentModel.ById(task.EquipmentModelId); var equipment = await sqlREquipment.ById(equipmentModel.EquipmentId); var taskAttributes = await sqlRTrainTaskAttributes.ByTaskId(task.Id); var lastComment = (await sqlRTaskComment.GetByTaskId(task.Id)).LastOrDefault(); var fault = new Fault(); if (taskAttributes.Count == 1 && taskAttributes.First().FaultId.HasValue) { fault = await sqlRFault.ById(taskAttributes.First().FaultId.Value); } var updateData = GetTaskLastUpdate(lastComment, taskExecutor, currentTaskStatus); var toadd = new Row { Id = new RowId(task.Id, 2), HasItems = false.ToString(), ParentId = null, //Ид Col0 = "И" + task.Id, //Статус Col1 = GetStringTaskStatus(currentTaskStatus.Status), //Тип Col2 = GetStringTaskType(task.TaskType), //Состав Col3 = GetTrainById(sqlRTrains, carriage.TrainId).Name, //Инициатор Col4 = user.Name, //Исполнитель Col5 = GetStringBrigadeType(taskExecutor.BrigadeType), //Дата Col6 = task.CreateDate.ToStringDateTime(), ////Вагон Col7 = carriage.Number.ToString(), //Оборудование Col8 = equipment.Name, ////Типовая Неисправность Col9 = fault?.Name, //Обновлено Col10 = updateData?.Date.ToStringDateTime(), //Обновил Col11 = updateData?.User.Name }; if (taskAttributes.Count > 1) { toadd.HasItems = true.ToString(); } rows.Add(toadd); } return(rows); }
private static async Task <FilteredTaskInspection> FilterPaginate(ReportRequest input, ILogger logger, bool isFillTask = true, bool isFillInspection = true) { var sqlRInspections = new InspectionRepository(logger); var sqlRTask = new TaskRepository(logger); var sqlRTaskStatus = new TaskStatusRepository(logger); var sharedTaskInspections = new List <SharedTaskInspection>(); if (!int.TryParse(input.Paging.Skip, out var skip)) { throw new ValidationException(Error.ParserErrorInt); } if (!int.TryParse(input.Paging.Limit, out var limit)) { throw new ValidationException(Error.ParserErrorInt); } List <Inspection> inspections; if (isFillInspection) { inspections = await sqlRInspections.GetAllSortByProperty("DateStart", "DESC"); foreach (var inspection in inspections) { sharedTaskInspections.Add(new SharedTaskInspection { Inspection = inspection }); } } List <TrainTask> tasks; if (isFillTask) { tasks = await sqlRTask.GetAllSortByProperty("CreateDate", "DESC"); foreach (var item in tasks) { sharedTaskInspections.Add(new SharedTaskInspection { TrainTask = item }); } } var sharedTaskInspectionFiltered = new List <SharedTaskInspection>(); if (input.Filters.Any()) { foreach (var filter in input.Filters) { foreach (var sharedTaskInspection in sharedTaskInspections) { switch (filter.ColumnName) { //Статус case "col1": string filterField = null; if (sharedTaskInspection.Inspection != null) { filterField = GetStringInspectionStatus(sharedTaskInspection.Inspection.Status); } if (sharedTaskInspection.TrainTask != null) { var currentTaskStatus = (await sqlRTaskStatus.ByTaskId(sharedTaskInspection.TrainTask.Id)).Last(); filterField = GetStringTaskStatus(currentTaskStatus.Status); } if (StringFilter(filterField, filter)) { sharedTaskInspectionFiltered.Add(sharedTaskInspection); } break; default: throw new NotImplementedException(Error.InDevelopment); } } } sharedTaskInspections = sharedTaskInspectionFiltered; } if (skip > sharedTaskInspections.Count) { sharedTaskInspections = new List <SharedTaskInspection>(); } if (skip == sharedTaskInspections.Count) { limit = 1; } if (skip + limit > sharedTaskInspections.Count) { limit = sharedTaskInspections.Count - skip; } var total = sharedTaskInspections.Count; sharedTaskInspections = sharedTaskInspections.GetRange(skip, limit); inspections = sharedTaskInspections.Where(x => x.Inspection != null).Select(q => q.Inspection).ToList(); tasks = sharedTaskInspections.Where(x => x.TrainTask != null).Select(q => q.TrainTask).ToList(); return(new FilteredTaskInspection { Inspections = inspections, TrainTask = tasks, Total = total }); }
public async Task <List <HistoryTaskDto> > AddHistoryData(int id) { var list = new List <HistoryTaskDto>(); var cr = new CommentRepository(_logger); var dr = new DocumentRepository(_logger); var er = new ExecutorRepository(_logger); var sr = new TaskStatusRepository(_logger); var comments = await cr.GetByTaskId(id); var docs = await dr.GetByTaskId(id); var executors = await er.GetByTaskId(id); var statuses = await sr.ByTaskId(id); foreach (var comment in comments) { var docsComment = docs.Where(item => item.TrainTaskCommentId == comment.Id).ToList(); var filesDto = new List <FileTaskDto>(); foreach (var item in docsComment) { var toAdd = new FileTaskDto { DocumentType = (int)item.DocumentType, Id = item.Id, Name = item.Name }; filesDto.Add(toAdd); } if (filesDto.Count != 0 || !string.IsNullOrWhiteSpace(comment.Text)) { list.Add(new HistoryTaskDto { Date = comment.Date, Files = filesDto, Type = TaskHistoryType.Comment.ToString(), User = comment.User.Name, UserBrigadeType = (int?)comment.User.Brigade?.BrigadeType, Text = comment.Text }); } } TrainTaskExecutor prevExec = null; foreach (var exec in executors) { list.Add(new HistoryTaskDto { Date = exec.Date, NewExecutorBrigadeType = (int)exec.BrigadeType, OldExecutorBrigadeType = prevExec == null ? null : (int?)prevExec.BrigadeType, Type = TaskHistoryType.Executor.ToString(), User = exec.User.Name, UserBrigadeType = (int?)exec.User.Brigade?.BrigadeType, }); prevExec = exec; } TrainTaskStatus prevSt = null; foreach (var st in statuses) { list.Add(new HistoryTaskDto { Date = st.Date, NewStatus = (int)st.Status, OldStatus = prevSt == null ? null : (int?)prevSt.Status, Type = TaskHistoryType.Status.ToString(), User = st.User.Name, UserBrigadeType = (int?)st.User.Brigade?.BrigadeType, }); prevSt = st; } var ret = list.OrderBy(o => o.Date).ToList(); return(ret); }
public async Task <TaskByIdDto> GetTaskById(int id, int permissions = -1) { using (var conn = new SqlConnection(AppSettings.ConnectionString)) { var sqlRExecutor = new ExecutorRepository(_logger); var sqlRTaskStatus = new TaskStatusRepository(_logger); var sqlRTask = new TaskSqls(); var fromSql = (await conn.QueryAsync <TaskDetailFromSql>(sqlRTask.GetTrainTaskByIdAndAttributeId(id))).ToList(); var task = fromSql.First(); var result = new TaskByIdDto { Id = task.Id, Data = task.CreateDate, InitiatorName = task.InitiatorName, TrainName = task.TrainName, EquipmentName = task.EquipmentName, CarriageSerial = task.CarriageSerial, //CreateCarriageName(task.TrainName, task.CarriageNumber), TaskType = task.TaskType }; //Текущий статус var taskStatuses = await sqlRTaskStatus.ByTaskId(id); var currentTaskStatus = taskStatuses.Last().Status; result.StatusId = (int)currentTaskStatus; //Текущий исполнитель var taskExecutors = await sqlRExecutor.GetByTaskId(id); BrigadeType currentTaskExecutor = 0; if (taskExecutors.Count > 0) { currentTaskExecutor = taskExecutors.Last().BrigadeType; result.BrigadeType = (int)currentTaskExecutor; } //Уровень задачи var taskLevel = fromSql.OrderBy(x => x.TaskLevel).Select(x => x.TaskLevel).First(); result.TaskLevel = taskLevel.HasValue ? (int)taskLevel : 0; //Доступные статусы var possibleTaskStatuses = sqlRTaskStatus.GetAvailableStatusesNewTask(currentTaskStatus, currentTaskExecutor, permissions); result.PossibleTaskStatuses = possibleTaskStatuses.Select(x => (int)x).ToList(); //Неисправности из атрибутов result.Faults = new List <FaultTaskDto>(); result.Inspections = new List <InspectionTaskDto>(); foreach (var item in fromSql) { if (item.AttributeFaultId != null) { await AddFaultData(result, item); } if (item.AttributeInspectionId != 0) { await AddInspectionData(result, item); } } //Добавить в фаулты данные по чеклистам из инпекции var withCheckListEquipmentId = fromSql.Where(x => x.AttributeCheckListEquipmentId != null) .DistinctBy(y => y.AttributeCheckListEquipmentId).ToList(); foreach (var item in withCheckListEquipmentId) { await AddFaultDataFromCheckListEquipmentId(result, item); } result.History = await AddHistoryData(id); return(result); } }