public async Task <PsaReportDocument> GetCurrentShiftReportAsync(Guid departmentId) { // чтобы создать сводку по нужной смене, нужно понять: // какой отдел и филиал интересует пользователя? var org = await GetOrgStructureItemsAsync(departmentId); var dept = org.Item1; var branch = org.Item2; // какое сейчас местное время в филиале? var currentTimeInDepartment = GetCurrentLocalTime(branch); // какой смене соответствует данное время? var absoluteShiftIndex = WorkingShiftAbsoluteIndex.GetAbsoluteIndex(currentTimeInDepartment); // выбрать из репозитория сводок все сводки с указанным absoluteShiftIndex и отделом var shiftSummaries = await _summaryService.GetSummariesInDepartmentForShift(departmentId, absoluteShiftIndex); // составить из них отчет var descriptor = GetShiftDescriptor(currentTimeInDepartment); var reportDoc = new PsaReportDocument { BranchOfficeId = (dept?.BranchOfficeId).Value, BranchOfficeName = branch?.Name, DepartmentId = departmentId, DepartmentName = dept?.Name, ShiftDate = descriptor.ShiftDate, ShiftName = descriptor.ShiftName, ShiftNumber = descriptor.ShiftNumber, ShiftStartTime = descriptor.ShiftStartTime, Summaries = shiftSummaries }; // fetch summaries for the shift in the department return(reportDoc); }
public async Task <Guid> AddAsync(SummaryDocument doc) { var existing = await TryGetSummaryEntityForInspectionAsync(doc.InspectionId); if (existing != null) { throw ItemAlreadyExistsException.MatchingEntityExists("RusHydroPsaSummary", existing.Id); } if (doc.Id == Guid.Empty) { doc.Id = Guid.NewGuid(); } var shiftAbsIndex = WorkingShiftAbsoluteIndex.GetAbsoluteIndex(doc.CompletionTime.LocalDateTime); var deptReportId = DepartmentShiftReportIdBuilder.BuildReportId(doc.DepartmentId, shiftAbsIndex); var summary = new Summary { Id = doc.Id, DepartmentShiftReportId = deptReportId, ShiftAbsoluteIndex = shiftAbsIndex, BranchOfficeId = doc.BranchOfficeId, CompletionTime = doc.CompletionTime, DepartmentId = doc.DepartmentId, EmployeeId = doc.Employee.Id, InspectionId = doc.InspectionId, SummaryDocument = doc, TenantId = _tenantIdProvider.GetTenantId(), UpdateDate = doc.UpdateDate }; _psaSummaryRepository.Add(summary); await _psaSummaryRepository.SaveChangesAsync(); return(summary.Id); }
private WorkingShiftDescriptor GetShiftDescriptor(DateTime completionLocalTime) { var absIndex = WorkingShiftAbsoluteIndex.GetAbsoluteIndex(completionLocalTime); var shiftDate = RusHydroScheduler.GetShiftStartDate(completionLocalTime, out bool _, out int shiftNumber); var shiftStart = RusHydroScheduler.GetShiftStartTime(completionLocalTime, out bool _, out int _); return(new WorkingShiftDescriptor { ShiftAbsoluteIndex = absIndex, ShiftDate = shiftDate, ShiftStartTime = shiftStart.TimeOfDay, ShiftNumber = shiftNumber, // watch out, some localizable strings here! ShiftName = shiftNumber == 1 ? "день" : "ночь" }); }
/// <summary> /// build the identifier of the report for the department shift, /// that is the current for the point in time specified by the department's local time /// </summary> /// <param name="departmentId"></param> /// <param name="localTime"></param> /// <returns></returns> public static string BuildReportId(Guid departmentId, DateTime localTime) { return(BuildReportId(departmentId, WorkingShiftAbsoluteIndex.GetAbsoluteIndex(localTime))); }