예제 #1
0
        public async Task <IEnumerable <WorkOrderItemViewModel> > Execute(int id)
        {
            var elements = await _repairsGateway.GetWorkOrderTasksForWorkOrder(id);

            if (elements is null)
            {
                throw new ResourceNotFoundException("work order not found");
            }

            return(elements.Select(wt => wt.ToResponse()));
        }
예제 #2
0
        public async Task <WorkOrderResponse> Execute(int id)
        {
            var workOrder = await _repairsGateway.GetWorkOrder(id);

            var manuallyAssignedOperatives = workOrder.HasManuallyAssignedOperatives();

            if (await _featureManager.IsEnabledAsync(FeatureFlags.UpdateOperativesOnWorkOrderGet) &&
                await _featureManager.IsEnabledAsync(FeatureFlags.DRSIntegration) &&
                await workOrder.ContractorUsingDrs(_sorGateway) &&
                workOrder.StatusCode == WorkStatusCode.Open &&
                !manuallyAssignedOperatives)
            {
                _logger.LogInformation($"Calling DrsService.UpdateWorkOrderDetails from GetWorkOrderUseCase for {workOrder.Id}");

                try
                {
                    await _drsService.UpdateWorkOrderDetails(id);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, $"Failed to update work order {id} from DRS");

                    try
                    {
                        if (e.Message.Contains("Unable to find order in OptiTime Web"))
                        {
                            _logger.LogError(e, $"Couldn't find workorder, creating {id} instead DRS");
                            await _drsService.CreateOrder(workOrder);
                        }
                    }
                    catch (Exception)
                    {
                        //swallow exceptions for create
                    }
                }
            }

            var appointment = await _appointmentGateway.GetAppointment(workOrder.Id);

            var canAssignOperative = await workOrder.CanAssignOperative(_sorGateway);

            var workOrderResponse = workOrder.ToResponse(appointment, _drsOptions.Value.ManagementAddress, canAssignOperative);

            var tasks = await _repairsGateway.GetWorkOrderTasksForWorkOrder(workOrder);

            workOrderResponse.TotalSMVs = tasks is null ? 0 : tasks.Sum(t => t.StandardMinuteValue * t.Quantity);

            return(workOrderResponse);
        }
예제 #3
0
        public async Task PublishUpdate(WorkOrder workOrder)
        {
            _logger.LogInformation($"Starting PublishUpdate for work order {workOrder.Id}");

            var repairsTopicArn = Environment.GetEnvironmentVariable("REPAIRS_SNS_ARN");

            var tasks = await _repairsGateway.GetWorkOrderTasksForWorkOrder(workOrder);

            if (tasks == null || !tasks.Any())
            {
                throw new ArgumentException($"No tasks found for WorkOrder {workOrder.Id}");
            }

            List <EntityEventSns> snsMessages = await CreateMessages(workOrder, tasks);

            _logger.LogInformation($"About to publish {snsMessages.Count} messages for work order {workOrder.Id} completion");

            foreach (var message in snsMessages)
            {
                _logger.LogInformation($"Publishing {message.Id} work order {workOrder.Id} operative {message.EventData.OperativePrn}");
                await _snsGateway.Publish(message, repairsTopicArn);
            }
            return;
        }