Exemple #1
0
        private ContainerState CreateContainerState(ContainerPlace cp, Container c)
        {
            var            now            = DateTimeOffset.Now;
            ContainerState containerState = new ContainerState()
            {
                Id           = c.Id,
                Description  = c.Description,
                LastDetected = cp.LastDetected,
                MovedTo      = cp.DateFrom,
                Number       = c.Number,
                Type         = c.Type,
                WarehouseId  = cp.WarehouseId,
                Weight       = c.Weight,
                Status       = now.Subtract(cp.LastDetected).TotalMinutes < 1 ? Enums.ContainerStatus.Online : Enums.ContainerStatus.Expired
            };

            _containers.AddOrUpdate(containerState.Id, containerState, (id, oldCs) => containerState);
            return(containerState);
        }
Exemple #2
0
        public ContainerPlace MoveContaier(long containerId, long warehouseId, int placeNumber)
        {
            var now          = DateTimeOffset.Now;
            var currentPlace = _db.ContainerPlaces.SingleOrDefault(_ => _.ContainerId == containerId && _.WarehouseId == warehouseId && _.Finish == null);

            if (currentPlace != null)
            {
                currentPlace.Finish = now;
            }

            ContainerPlace newPlace = new ContainerPlace()
            {
                ContainerId = containerId, DateFrom = now, LastDetected = now, Number = placeNumber, WarehouseId = warehouseId
            };

            _db.ContainerPlaces.Add(newPlace);
            _db.SaveChanges();

            return(newPlace);
        }
Exemple #3
0
        public async Task UpdateContainer(string observerSerialNumber, string gattId, double rssi, int number)
        {
            using var scope = _serviceProvider.CreateScope();
            var _warehouseService = scope.ServiceProvider.GetRequiredService <IWarehouseService>();
            var now = DateTimeOffset.Now;
            // определяем от какого устройства пришёл пакет
            Warehouse warehouse = _warehouseService.GetWarehouseByObserverSerialNumber(observerSerialNumber);

            if (warehouse == null)
            {
                return;
            }
            // находим маячок в репозитории маячков
            Beacon beacon = _warehouseService.GetBeacon(gattId);

            if (beacon == null)
            {
                return;
            }
            // проверяем к контейнеру прикреплён маячок
            Container container = _warehouseService.GetContainerByBeaconId(beacon.Id);

            if (container == null)
            {
                return;
            }

            // проверяем где сейчас контейнер
            ContainerPlace containerPlace = _warehouseService.GetContainerPlace(container.Id);

            if (containerPlace == null)
            {
                // мы не знаем где этот контейнер
                // поместим его на этот склад
                _warehouseService.MoveContaier(container.Id, warehouse.Id, number);
            }
            else
            {
                // мы знаем где этот контейнер, удостоверимся что он там, где был в прошлый раз
                if (containerPlace.WarehouseId == warehouse.Id && containerPlace.Number == number)
                {
                    // он там где был в последний раз, обновим метку времени
                    _warehouseService.UpdateLastDetectedAsync(containerPlace.Id, now);
                }
                else
                {
                    // контейнер был перемещён, перемещаем его в другую точку
                    _warehouseService.MoveContaier(container.Id, warehouse.Id, number);
                }
            }

            // мы поняли что это за контейнер, обновляем его текущее состояние в кэше
            if (!_containers.TryGetValue(container.Id, out var containerState))
            {
                CreateContainerState(warehouse, container, now);
            }
            else
            {
                containerState.LastDetected = now;
                containerState.Status       = Enums.ContainerStatus.Online;
                containerState.WarehouseId  = warehouse.Id;
            }
        }