public void LoadState(MainPageState state)
        {
            if (null != state.Stations)
            {
                _stations.AddRange(state.Stations);
            }
            if (null != state.Tracks)
            {
                _playList.AddRange(state.Tracks);
            }
            if (null != state.CurrentStationId)
            {
                // Set the backing field to avoid running the logic in the setter, property is manually notified
                _selectedStation = Stations.FirstOrDefault(s => s.Id == state.CurrentStationId.Value);
                RaisePropertyChanged(SelectedStationPropertyName);
            }

            if (null != state.CurrentTrackRadioPosition)
            {
                // LoadState happens before the window is available, thus we cannot access Player. Therefore set the backing field only.
                // The current track (if any) is loaded into the Player in AttachPlayerEvents
                _currentTrack = _playList.FirstOrDefault(t => t.RadioPosition == state.CurrentTrackRadioPosition.Value);
                RaisePropertyChanged(CurrentTrackPropertyName);
            }
        }
예제 #2
0
 private void onPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
 {
     if (propertyChangedEventArgs.PropertyName == "SelectedRegion")
     {
         Stations        = SelectedRegion.StaStations.OrderBy(f => f.StationName).ToList();
         SelectedStation = Stations.FirstOrDefault();
     }
 }
예제 #3
0
 private void OnStationUpdate(Station station)
 {
     guiDispatcher.Invoke(() =>
     {
         int id         = Stations.FirstOrDefault(s => s.Id == station.Id).Id;
         Stations[--id] = station;
         RaisePropertyChanged(nameof(Stations));
     });
 }
예제 #4
0
        public void FindPathZ(StationViewModel startStation, StationViewModel endStation)
        {
            HideStationsAndConnectionsThatIsNotOnTheSelectedPath();
            StationPathFrom.IsSelectedStationInThePath = true;
            StationPathTo.IsSelectedStationInThePath   = true;

            if (startStation.ConnectedStationO.PreviousStation == null & startStation.Line == StationPathTo.Line)
            {
                MoveToNext(startStation, endStation);
            }
            else if (startStation.ConnectedStationO.NextStation == null & startStation.Line == StationPathTo.Line)
            {
                MoveToPrevious(startStation, endStation);
            }
            else if (startStation.Line == StationPathTo.Line && check(startStation, endStation))
            {
                MoveToNext(startStation, endStation);
            }
            else if (startStation.Line == StationPathTo.Line && !check(startStation, endStation))
            {
                MoveToPrevious(startStation, endStation);
            }
            else
            {
                var transit = Stations.FirstOrDefault(s => s.TransitToLine == StationPathTo.Line & StationPathFrom.Line == s.Line);
                if (check(startStation, transit))
                {
                    MoveToNext(startStation, transit);
                    startStation = Stations.ToList().Find(s => s.Name.Trim() == transit.TransitToStation.Trim());
                    if (check(startStation, endStation))
                    {
                        MoveToNext(startStation, endStation);
                    }
                    else
                    {
                        MoveToPrevious(startStation, endStation);
                    }
                }
                else
                {
                    MoveToPrevious(startStation, transit);
                    startStation = Stations.ToList().Find(s => s.Name.Trim() == transit.TransitToStation.Trim());
                    if (!check(startStation, endStation))
                    {
                        MoveToPrevious(startStation, endStation);
                    }
                    else
                    {
                        MoveToNext(startStation, endStation);
                    }
                }
            }
        }
예제 #5
0
 public void AddStation(int station)
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         var newStation = Stations.FirstOrDefault(s => s.StationNumber == station);
         if (newStation is null)
         {
             Stations.Add(new Station {
                 StationNumber = station
             });
         }
     });
 }
예제 #6
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            using (var package = new ExcelPackage(new FileInfo("./DataSources/stations.xlsx")))
            {
                var firstSheet      = package.Workbook.Worksheets["stations"];
                var numberOfRow     = firstSheet.Dimension.Rows;
                var numberOfColumns = firstSheet.Dimension.Columns;

                for (int i = 2; i <= numberOfRow; i++)
                {
                    modelBuilder.Entity <Station>().HasData(
                        new Station()
                    {
                        Id   = Guid.NewGuid(),
                        Name = firstSheet.Cells[$"A{i}"].Text,
                        Lat  = firstSheet.Cells[$"B{i}"].Text,
                        Lon  = firstSheet.Cells[$"C{i}"].Text
                    });
                }
            }

            using (var package = new ExcelPackage(new FileInfo("./DataSources/time-series.xlsx")))
            {
                var firstSheet      = package.Workbook.Worksheets["stations"];
                var numberOfRow     = firstSheet.Dimension.Rows;
                var numberOfColumns = firstSheet.Dimension.Columns;

                for (int i = 3; i <= numberOfRow; i++)
                {
                    for (int j = 2; j <= 8; j++)
                    {
                        modelBuilder.Entity <Weather>().HasData(
                            new Weather()
                        {
                            Id              = Guid.NewGuid(),
                            Date            = (DateTimeOffset)firstSheet.Cells[$"A{i}"].Value,
                            Station         = Stations.FirstOrDefault(a => a.Id == new Guid("7eba244-620f-492b-b0de-59683aaa5633")),
                            TypeOfIndicator = j < 5 ? "Percipitation" : "Temperature",
                            Value           = firstSheet.Cells[$"{(Char)((65) + (j - 1))}{i}"].Text
                        });
                    }
                }
            }

            base.OnModelCreating(modelBuilder);
        }
        private async Task LoadInformationAsync()
        {
            var stations = await Task.Run(() => _repository.Stations.GetRangeAsync());

            foreach (var station in stations)
            {
                Stations.Add(new StationModel(station, _repository));
            }

            SelectedStationMap = Stations.FirstOrDefault();


            timer.Interval = new TimeSpan(0, 0, 10);
            timer.Tick    += timer_Tick;
            timer.Start();
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            var index = Stations.IndexOf(SelectedStationMap);

            if (index == Stations.Count - 1)
            {
                //var station = Stations.FirstOrDefault();
                //station?.LoadRelatedInfo();
                ;
                SelectedStationMap = Stations.FirstOrDefault();
            }
            else
            {
                //var station = Stations.ElementAt(index + 1);
                //station?.LoadRelatedInfo();
                SelectedStationMap = Stations.ElementAt(index + 1);
            }
        }
예제 #9
0
        private async Task <bool> SaveExisting()
        {
            var existing = Stations.FirstOrDefault(s => s.Id == this.currentStation.Id);

            if (existing != null)
            {
                var model = await base.Api.PutAsync <StationModel>(
                    Constants.Endpoints.Stations, this.currentStation.Model);

                if (model == null)
                {
                    return(false);
                }

                existing.Model = model;
            }

            return(true);
        }
        public ITravelPlanner ArriveAt(int stationId, string time)
        {
            if (Stations.FirstOrDefault(s => s.ID == stationId) is null)
            {
                throw new Exception("Can´t find this station, please choose another station");
            }
            TimeSpan parsedTime;

            try
            {
                parsedTime = TimeSpan.Parse(time);
            }
            catch
            {
                throw new Exception("Invalid time format");
            }

            // I want to find the last spot of the travelPlanDatas list to add to it, we are adding the arrive at data
            TravelPlanData workingData = travelPlanDatas[^ 1];
예제 #11
0
        /// <summary>
        /// Метод возвращает экземпляр класса <see cref="Station"/> или, если в таблице нет такой записи, создаёт её
        /// </summary>
        /// <param name="name">Название станции</param>
        /// <param name="railRoadName">Название железной дороги</param>
        /// <param name="stateName">Название региона</param>
        /// <param name="countryName">Название страны</param>
        /// <returns>Экземпляр класса <see cref="Station"/></returns>
        public Station GetStation(string name, string railRoadName, string stateName, string countryName)
        {
            var station = Stations.FirstOrDefault(s => s.Name.Equals(name) &&
                                                  s.State.Name.Equals(stateName) &&
                                                  s.RailRoad.Name.Equals(railRoadName));

            if (station == null)
            {
                station = new Station
                {
                    Name     = name,
                    State    = GetState(stateName, countryName),
                    RailRoad = GetRailRoad(railRoadName, countryName)
                };
                Stations.Add(station);
                SaveChanges();
            }

            return(station);
        }
예제 #12
0
        protected override async Task FetchDataAsync()
        {
            var stations = await base.Api.GetAsync <List <StationModel> >(
                $"{Constants.Endpoints.Stations}?{Constants.ApiOptions.IncludeDeleted}");

            var regions = await base.Api.GetAsync <List <RegionModel> >(
                $"{Constants.Endpoints.Regions}?{Constants.ApiOptions.IncludeDeleted}");

            var castedStations = stations.Select(s => new StationViewModel(s, Save, Cancel));
            var castedRegions  = regions.Select(r => new RegionViewModel(r, Save, Cancel));

            Stations.AddRange(castedStations);
            Regions.AddRange(castedRegions);

            var selectedStationId = Navigator.GetNavigationData <Guid>();

            if (selectedStationId != null && selectedStationId != Guid.Empty)
            {
                this.Selected = Stations.FirstOrDefault(s => s.Id == selectedStationId);
            }
        }
        private async Task UpdateList(RecordChangedEventArgs <Station> e)
        {
            await Task.Delay(1);

            if (e.ChangeType == ChangeType.None)
            {
                return;
            }

            if (e.ChangeType == ChangeType.Delete)
            {
                var s = Stations.FirstOrDefault(c => c.Model.StationId == e.Entity.StationId);
                if (s == null)
                {
                    return;
                }

                Stations.Remove(s);
            }
            if (e.ChangeType == ChangeType.Insert)
            {
                if (Stations.Contains(new StationModel(e.Entity, _repository)))
                {
                    return;
                }
                Stations.Add(new StationModel(e.Entity, _repository));
            }
            if (e.ChangeType == ChangeType.Update)
            {
                var s = Stations.FirstOrDefault(c => c.Model.StationId == e.Entity.StationId);
                if (s == null)
                {
                    return;
                }
                var i = Stations.IndexOf(s);
                Stations.Remove(s);
                Stations.Insert(i, new StationModel(e.Entity, _repository));
            }
        }
        public ITravelPlanner StartAt(int stationId, string time)
        {
            if (Stations.FirstOrDefault(s => s.ID == stationId) is null)
            {
                throw new Exception("Can´t find this station, please choose another station");
            }
            TimeSpan parsedTime;

            try
            {
                parsedTime = TimeSpan.Parse(time);
            }
            catch
            {
                throw new Exception("Invalid time format");
            }
            travelPlanDatas.Add(new TravelPlanData {
                TrainID = selectedTrainID, StartStationID = stationId, StartTime = parsedTime
            });

            return(this);
        }
예제 #15
0
        public T Find <T>(string name) where T : class
        {
            var typeName = typeof(T).Name;

            switch (typeName)
            {
            case nameof(MotionCardWrapper):
                return(MotionExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            case nameof(IDiEx):
                return(DiExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            case nameof(IDoEx):
                return(DoExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            case nameof(IVioEx):
                return(VioExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            case nameof(ICylinderEx):
                return(CylinderExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            case nameof(IAxisEx):
                return(AxisExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            case nameof(PlatformEx):
                return(Platforms.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            case nameof(Station):
                return(Stations.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            case nameof(StationTask):
                return(Tasks.FirstOrDefault(ex => ex.Value.Name == name).Value as T);

            default:
                return(null);
            }
        }
예제 #16
0
        /// <summary>
        /// 以任务号为依据,对堆垛机进行重新编写控制逻辑
        /// 1.
        /// </summary>
        /// <param name="stocker"></param>
        /// <param name="plc"></param>
        /// <returns></returns>
        public BllResult ExcuteSingle(Equipment stocker, IPLC plc)
        {
            //联机、无故障
            if (Validate(stocker).Success)
            {
                #region 第一步:任务执行判断,用于手动情况或异常的处理
                if (stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.Fork1TaskExcuteStatus.ToString()).Value == SRMTaskExcuteStatus.任务执行中.GetIndexString())
                {
                    //任务执行中就return
                    return(BllResultFactory.Sucess());
                }
                if (stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.Fork1TaskExcuteStatus.ToString()).Value == SRMTaskExcuteStatus.任务中断_出错.GetIndexString())
                {
                    //由人工处理,一般为空出和重入
                    return(BllResultFactory.Sucess());
                }
                if (stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.Fork1TaskExcuteStatus.ToString()).Value == SRMTaskExcuteStatus.发任务错误.GetIndexString())
                {
                    //由人工处理,需要重新下发任务
                    return(BllResultFactory.Sucess());
                }
                #endregion
                #region 任务和货位

                //找出所有下发未完成的任务
                var tasksResult = AppSession.Dal.GetCommonModelByCondition <TaskEntity>($"where taskStatus < {TaskEntityStatus.任务完成.GetIndexInt()} " +
                                                                                        $"and taskStatus>={TaskEntityStatus.下发任务.GetIndexInt()} and deleted = 0 and warehouseCode={AppSession.WarehouseCode}");
                if (!tasksResult.Success)
                {
                    //如果没有找到任务就直接返回
                    return(BllResultFactory.Error(tasksResult.Msg));
                }
                //找出同巷道的库位
                //找出同巷道的库位,考虑到可能多个巷道移库,这里分别查询出所有库位和当前堆垛机所在的库位
                var locationsResult = AppSession.LocationService.GetAllLocations(null, null, null, null, null, null, null, stocker.WarehouseCode);
                if (!locationsResult.Success)
                {
                    return(BllResultFactory.Error(locationsResult.Msg));
                }
                var locations        = locationsResult.Data;
                var locationsRoadWay = locationsResult.Data.Where(t => t.RoadWay == stocker.RoadWay).ToList();

                //hack:这里筛选本巷道的任务,规则为起始或目标库位在本巷道中,所以,当将来出现跨巷道移库时,需要特别处理跨巷道移库任务
                var tasks = tasksResult.Data.Where(t => locationsRoadWay.Count(a => a.Code == t.FromLocationCode || a.Code == t.ToLocationCode) > 0).ToList();
                #endregion
                string Fork1TaskExecuteStatus = stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.Fork1TaskExcuteStatus.ToString()).Value;
                //堆垛机待机情况下
                if (Fork1TaskExecuteStatus == SRMTaskExcuteStatus.待机.GetIndexString())
                {
                    //货叉任务待机时,可执行放和取任务,同时当执行完成时,交互后堆垛机会从任务完成更新为待机
                    //TODO:WCSFork1TaskFlag  WCSTaskAccount 用于高速堆垛机
                    string WcsFork1TaskFlag = stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.WCSFork1TaskFlag.ToString()).Value;
                    if (WcsFork1TaskFlag == SRMForkTaskFlag.除任务.GetIndexString())
                    {
                        return(ClearWCSData(stocker, plc, TaskAccount.New));
                    }
                    else if (WcsFork1TaskFlag == SRMForkTaskFlag.任务完成.GetIndexString())
                    {
                        return(ClearWCSData(stocker, plc, TaskAccount.New));
                    }
                    string WcsTaskAccount = stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.WCSTaskAccount.ToString()).Value;
                    if (WcsTaskAccount == SRMForkTaskFlag.任务完成.GetIndexString())
                    {
                        return(ClearWCSData(stocker, plc, TaskAccount.New));
                    }
                    else if (WcsTaskAccount == SRMForkTaskFlag.无任务.GetIndexString())
                    {
                        #region 优先处理重新下发的任务
                        //todo://任务重发逻辑待完成
                        #endregion
                        //获取需要下发给堆垛机的任务
                        if (stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.Fork1ForkHasPallet.ToString()).Value == "True")
                        {
                            Logger.Log($"堆垛机{stocker.Name}显示货叉上有货,高速堆垛机不应该出现有托盘的时候还出现待机无任务的情况", LogLevel.Error);
                            return(BllResultFactory.Error());
                        }
                        else
                        {
                            //判断任务限制情况
                            var tempTasks = tasks;
                            //hack:关于拣选的限制暂时没有做
                            string taskLimit = stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.TaskLimit.ToString()).Value;
                            if (taskLimit == SRMTaskLimit.限制出库.GetIndexString())
                            {
                                //限制出库,则不能执行下发状态的出库性质任务
                                var temp = tasks.Where(t => t.TaskStatus == TaskEntityStatus.发任务.GetIndexInt())
                                           .Where(t => t.TaskType != TaskType.整盘出库.GetIndexInt() && t.TaskType != TaskType.空容器出库.GetIndexInt() && t.TaskType != TaskType.换站.GetIndexInt() &&
                                                  t.TaskType != TaskType.盘点.GetIndexInt() && t.TaskType != TaskType.出库查看.GetIndexInt() && t.TaskType != TaskType.分拣出库.GetIndexInt()).ToList();
                                tempTasks = tasks.Where(t => temp.Count(a => a.Id == t.Id) == 0).ToList();
                            }
                            else if (taskLimit == SRMTaskLimit.限制入库.GetIndexString())
                            {
                                //限制入库,则不能响应待入状态的入库性质任务
                                tempTasks = tasks.Where(t => t.TaskStatus != TaskEntityStatus.响应接入站台到达.GetIndexInt()).ToList();
                            }
                            if (tempTasks.Count == 0)
                            {
                                return(BllResultFactory.Error());
                            }
                            else
                            {
                                // 这里不需要判断高速堆垛机的位置[一个入口,一个出口,循环]  根据任务依次执行即可
                                TaskEntity task = tempTasks.Where(t => t.TaskStatus == TaskEntityStatus.发任务.GetIndexInt() ||
                                                                  t.TaskStatus == TaskEntityStatus.响应接入站台到达.GetIndexInt()).FirstOrDefault();
                                if (task != null)
                                {
                                    //出库性质的任务
                                    if (task.TaskStatus == TaskEntityStatus.发任务.GetIndexInt() &&
                                        (task.TaskType == TaskType.整盘出库.GetIndexInt() || task.TaskType == TaskType.空容器出库.GetIndexInt() ||
                                         task.TaskType == TaskType.补充入库.GetIndexInt() || task.TaskType == TaskType.分拣出库.GetIndexInt() ||
                                         task.TaskType == TaskType.盘点.GetIndexInt() || task.TaskType == TaskType.出库查看.GetIndexInt() ||
                                         task.TaskType == TaskType.移库.GetIndexInt() || task.TaskType == TaskType.移位.GetIndexInt()))
                                    {
                                        //TODO:判断该出库口是否有任务未完成

                                        //解析任务并下发
                                        if (task.TaskType != TaskType.移库.GetIndexInt() || task.TaskType != TaskType.移位.GetIndexInt())  //不是移库、移位的任务,都需要解析出库站台
                                        {
                                            Location  from    = locations.FirstOrDefault(t => t.Code == task.FromLocationCode);
                                            Equipment station = Stations.FirstOrDefault(t => t.Code == task.ToPort);
                                            if (from != null && station != null)
                                            {
                                                task.TaskStatus = TaskEntityStatus.发堆垛机库内取货.GetIndexInt();

                                                var res = AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                                if (res.Success)
                                                {
                                                    var result = SendTaskToStocker(stocker, plc, SuperSRMTaskMode.完整任务,
                                                                                   SRMForkTaskFlag.库内取货, from.RowIndex1.ToString(), from.Line.ToString(), from.Layer.ToString(), "0",
                                                                                   SRMForkTaskFlag.库外放货, station.RowIndex1.ToString(), station.ColumnIndex.ToString(), station.LayerIndex.ToString(), station.StationIndex.ToString(),
                                                                                   task.Id.ToString(), TaskAccount.New);
                                                    if (result.Success)
                                                    {
                                                        Logger.Log($"下发堆垛机{stocker.Name},任务:{task.Id},任务类型:{task.TaskType},货叉类型:{SRMForkTaskFlag.库内取货}成功,库位:{from.Code},出库口:{task.ToPort}", LogLevel.Info);
                                                        return(BllResultFactory.Sucess());
                                                    }
                                                    else
                                                    {
                                                        Logger.Log($"下发堆垛机{stocker.Name},任务:{task.Id},任务类型:{task.TaskType},货叉类型:{SRMForkTaskFlag.库内取货}失败:{result.Msg};回滚任务{task.Id}状态。", LogLevel.Error);
                                                        task.TaskStatus = TaskEntityStatus.发任务.GetIndexInt();
                                                        AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                                        return(BllResultFactory.Error());
                                                    }
                                                }
                                                else
                                                {
                                                    Logger.Log($"下发堆垛机{stocker.Name}库内取货时,更新任务{task.Id}状态失败:{res.Msg}", LogLevel.Error);
                                                    return(BllResultFactory.Error($"下发堆垛机{stocker.Name}库内取货时,更新任务{task.Id}状态失败:{res.Msg}"));
                                                }
                                            }
                                            return(BllResultFactory.Error($"任务:{task.Id}对应的来源库位:{task.FromLocationCode}和去向站台:{task.ToPort}出现的了问题"));
                                        }
                                        else
                                        {
                                            Location from = locations.Where(t => t.Code == task.FromLocationCode).FirstOrDefault();
                                            Location to   = locations.Where(t => t.Code == task.ToLocationCode).FirstOrDefault();
                                            if (from != null && to != null)
                                            {
                                                task.TaskStatus = TaskEntityStatus.发堆垛机库内取货.GetIndexInt();

                                                var res = AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                                if (res.Success)
                                                {
                                                    BllResult result;
                                                    if (task.TaskType == TaskType.移库.GetIndexInt())
                                                    {
                                                        result = SendTaskToStocker(stocker, plc, SuperSRMTaskMode.完整任务,
                                                                                   SRMForkTaskFlag.库内取货, from.RowIndex1.ToString(), from.Line.ToString(), from.Layer.ToString(), "0",
                                                                                   SRMForkTaskFlag.库内放货, to.RowIndex1.ToString(), to.Line.ToString(), to.Layer.ToString(), "0",
                                                                                   task.Id.ToString(), TaskAccount.New);
                                                    }
                                                    else
                                                    {
                                                        result = SendTaskToStocker(stocker, plc, SuperSRMTaskMode.无,
                                                                                   SRMForkTaskFlag.无任务, from.RowIndex1.ToString(), from.Line.ToString(), from.Layer.ToString(), "0",
                                                                                   SRMForkTaskFlag.无任务, to.RowIndex1.ToString(), to.Line.ToString(), to.Layer.ToString(), "0",
                                                                                   task.Id.ToString(), TaskAccount.New);
                                                    }
                                                    if (result.Success)
                                                    {
                                                        Logger.Log($"下发堆垛机{stocker.Name},任务:{task.Id},任务类型:{task.TaskType},货叉类型:{SRMForkTaskFlag.库内取货}成功,库位:{from.Code},出库口:{task.ToPort}", LogLevel.Info);
                                                        return(BllResultFactory.Sucess());
                                                    }
                                                    else
                                                    {
                                                        Logger.Log($"下发堆垛机{stocker.Name},任务:{task.Id},任务类型:{task.TaskType},货叉类型:{SRMForkTaskFlag.库内取货}失败:{result.Msg};回滚任务{task.Id}状态。", LogLevel.Error);
                                                        task.TaskStatus = TaskEntityStatus.发任务.GetIndexInt();
                                                        AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                                        return(BllResultFactory.Error());
                                                    }
                                                }
                                                else
                                                {
                                                    Logger.Log($"下发堆垛机{stocker.Name}库内取货时,更新任务{task.Id}状态失败:{res.Msg}", LogLevel.Error);
                                                    return(BllResultFactory.Error($"下发堆垛机{stocker.Name}库内取货时,更新任务{task.Id}状态失败:{res.Msg}"));
                                                }
                                            }
                                            return(BllResultFactory.Error($"任务类型:{task.TaskType}对应的来源库位:{task.FromLocationCode}和目标库位:{task.ToLocationCode}"));
                                        }
                                    }
                                    //入库性质的任务
                                    if (task.TaskStatus == TaskEntityStatus.响应堆垛机库外取货完成.GetIndexInt() &&
                                        (task.TaskType == TaskType.整盘入库.GetIndexInt() || task.TaskType == TaskType.空容器入库.GetIndexInt() ||
                                         task.TaskType == TaskType.补充入库.GetIndexInt() || task.TaskType == TaskType.分拣出库.GetIndexInt() ||
                                         task.TaskType == TaskType.盘点.GetIndexInt() || task.TaskType == TaskType.出库查看.GetIndexInt()))
                                    {
                                        Location  to      = locations.Where(t => t.Code == task.ToLocationCode).FirstOrDefault();
                                        Equipment station = Stations.Where(t => t.Code == task.Gateway).FirstOrDefault();
                                        if (station != null && to != null)
                                        {
                                            task.TaskStatus = TaskEntityStatus.发堆垛机库外取货.GetIndexInt();

                                            var res = AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                            if (res.Success)
                                            {
                                                var result = SendTaskToStocker(stocker, plc, SuperSRMTaskMode.完整任务,
                                                                               SRMForkTaskFlag.库外取货, station.RowIndex1.ToString(), station.ColumnIndex.ToString(), station.LayerIndex.ToString(), station.StationIndex.ToString(),
                                                                               SRMForkTaskFlag.库内放货, to.RowIndex1.ToString(), to.Line.ToString(), to.Layer.ToString(), "0",
                                                                               task.Id.ToString(), TaskAccount.New);
                                                if (result.Success)
                                                {
                                                    Logger.Log($"下发堆垛机{stocker.Name},任务:{task.Id},任务类型:{task.TaskType},货叉类型:{SRMForkTaskFlag.库内取货}成功,库位:{to.Code},入库站台:{task.Gateway}", LogLevel.Info);
                                                    return(BllResultFactory.Sucess());
                                                }
                                                else
                                                {
                                                    Logger.Log($"下发堆垛机{stocker.Name},任务:{task.Id},任务类型:{task.TaskType},货叉类型:{SRMForkTaskFlag.库内取货}失败:{result.Msg};回滚任务{task.Id}状态。", LogLevel.Error);
                                                    task.TaskStatus = TaskEntityStatus.响应接入站台到达.GetIndexInt();
                                                    AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                                    return(BllResultFactory.Error());
                                                }
                                            }
                                            else
                                            {
                                                Logger.Log($"下发堆垛机{stocker.Name}库外取货时,更新任务{task.Id}状态失败:{res.Msg}", LogLevel.Error);
                                                return(BllResultFactory.Error($"下发堆垛机{stocker.Name}库内取货时,更新任务{task.Id}状态失败:{res.Msg}"));
                                            }
                                        }

                                        return(BllResultFactory.Error($"任务:{task.Id}对应的库位:{task.FromLocationCode},{task.ToLocationCode}和接入站台:{task.Gateway},{task.ToPort}出现的了问题"));
                                    }

                                    //入库性质的换站任务
                                    if (task.TaskStatus == TaskEntityStatus.响应堆垛机库外取货完成.GetIndexInt() && task.TaskType == TaskType.换站.GetIndexInt())
                                    {
                                        Equipment station = Stations.Where(t => t.Code == task.Gateway).FirstOrDefault();
                                        Equipment to      = Stations.Where(t => t.Code == task.ToPort).FirstOrDefault();
                                        if (station != null && to != null)
                                        {
                                            task.TaskStatus = TaskEntityStatus.发堆垛机库外取货.GetIndexInt();

                                            var res = AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                            if (res.Success)
                                            {
                                                var result = SendTaskToStocker(stocker, plc, SuperSRMTaskMode.完整任务,
                                                                               SRMForkTaskFlag.库外取货, station.RowIndex1.ToString(), station.ColumnIndex.ToString(), station.LayerIndex.ToString(), station.StationIndex.ToString(),
                                                                               SRMForkTaskFlag.库外放货, to.RowIndex1.ToString(), to.ColumnIndex.ToString(), to.LayerIndex.ToString(), to.StationIndex.ToString(),
                                                                               task.Id.ToString(), TaskAccount.New);
                                                if (result.Success)
                                                {
                                                    Logger.Log($"下发堆垛机{stocker.Name},任务:{task.Id},任务类型:{task.TaskType},货叉类型:{SRMForkTaskFlag.库内取货}成功,库位:{to.Code},入库站台:{task.Gateway}", LogLevel.Info);
                                                    return(BllResultFactory.Sucess());
                                                }
                                                else
                                                {
                                                    Logger.Log($"下发堆垛机{stocker.Name},任务:{task.Id},任务类型:{task.TaskType},货叉类型:{SRMForkTaskFlag.库内取货}失败:{result.Msg};回滚任务{task.Id}状态。", LogLevel.Error);
                                                    task.TaskStatus = TaskEntityStatus.响应接入站台到达.GetIndexInt();
                                                    AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                                    return(BllResultFactory.Error());
                                                }
                                            }
                                            else
                                            {
                                                Logger.Log($"下发堆垛机{stocker.Name}库外取货时,更新任务{task.Id}状态失败:{res.Msg}", LogLevel.Error);
                                                return(BllResultFactory.Error($"下发堆垛机{stocker.Name}库内取货时,更新任务{task.Id}状态失败:{res.Msg}"));
                                            }
                                        }

                                        return(BllResultFactory.Error($"任务:{task.Id}对应的接入站台:{task.Gateway},{task.ToPort}出现的了问题"));
                                    }
                                    {
                                        Logger.Log($"堆垛机{stocker.Name}待机空闲,出现有任务需要执行,但是任务状态{task.TaskStatus}和任务类型{task.TaskTypeDesc}不匹配", LogLevel.Error);
                                        return(BllResultFactory.Error());
                                    }
                                }
                                else
                                {
                                    var tmpTsk = tempTasks.Where(t => t.TaskStatus > TaskEntityStatus.发任务.GetIndexInt());
                                    if (tmpTsk != null)
                                    {
                                        Logger.Log($"堆垛机{stocker.Name}待机空闲,出现有任务需要执行,但是根据条件没刷选出任何任务", LogLevel.Error);
                                        return(BllResultFactory.Error());
                                    }
                                    return(BllResultFactory.Sucess());
                                }
                            }
                        }
                    }

                    else
                    {
                        //hack:其他情况1-库内取货,2-库内放货,3-库外入库,4库外出库, 5重新分配入库地址,暂时不做处理,这里也应不需要处理这些情况
                    }
                }
                else if (Fork1TaskExecuteStatus == SRMTaskExcuteStatus.任务完成.GetIndexString())
                {
                    //todo:响应任务完成
                    //一共4种完成情况  高速堆垛机只有2中情况会有完成信号  库外出库和库内放货
                    //根据任务号和货叉类型进行任务完成处理
                    int taskNo   = int.Parse(stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "Fork1TaskNo").Value);
                    int forkType = int.Parse(stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "Fork1TaskType").Value);

                    //库内放货完成
                    if (forkType == SRMForkTaskFlag.库内放货.GetIndexInt())
                    {
                        var task = tasks.FirstOrDefault(t => t.Id == taskNo && t.TaskStatus < TaskEntityStatus.任务完成.GetIndexInt() && t.TaskStatus >= TaskEntityStatus.发堆垛机库内取货.GetIndexInt() &&
                                                        locations.Count(a => a.Code == t.ToLocationCode) > 0);
                        if (task != null)
                        {
                            //调用WMS任务完成接口  ---- TODO:huhai20190416先注解

                            //var tempResult = AppSession.Dal.CompleteTask(task.Id.ToString(), AppSession.Client, AppSession.Urls);
                            //if (!tempResult.Success)
                            //{
                            //    Logger.Log($"任务{task.Id}状态修改失败!!", LogLevel.Error);
                            //}
                            task.TaskStatus = TaskEntityStatus.任务完成.GetIndexInt();
                            var tempResult = AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                            if (tempResult.Success)
                            {
                                //标记交换区地址,任务完成10
                                //var prop = stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1TaskFlag");
                                //prop.Value = "10";
                                var prop = stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "WCSTaskAccount");
                                prop.Value = TaskAccount.OK.GetIndexString();
                                //var sendResult = S7Helper.PlcSplitWrite(plc, new List<EquipmentProp> { prop }, 20);
                                var sendResult = plc.Writes(new List <EquipmentProp> {
                                    prop
                                });
                                if (sendResult.Success)
                                {
                                    Logger.Log($"堆垛机{stocker.Name}完成库内放货成功,任务:{task.Id}", LogLevel.Success);
                                    return(BllResultFactory.Sucess());
                                }
                                else
                                {
                                    //hack:这里如果更新PLC地址失败,WMS端并不会回滚,此时应考虑如何人工处理;
                                    Logger.Log($"堆垛机{stocker.Name}完成库内放货失败,任务:{task.Id},原因:{sendResult.Msg}", LogLevel.Error);
                                    return(BllResultFactory.Error());
                                }
                            }
                            else
                            {
                                Logger.Log($"完成堆垛机{stocker.Name}库内放货失败,任务{task.Id}请求WMS接口失败:{tempResult.Msg}", LogLevel.Error);
                                return(BllResultFactory.Error($"完成堆垛机{stocker.Name}库内放货失败,任务{task.Id}请求WMS接口失败:{tempResult.Msg}"));
                            }
                        }
                    }
                    //库外放货完成时
                    else if (forkType == SRMForkTaskFlag.库外放货.GetIndexInt())
                    {
                        var task = tasks.FirstOrDefault(t => t.Id == taskNo && t.TaskStatus <TaskEntityStatus.发堆垛机库外放货.GetIndexInt() && t.TaskStatus> TaskEntityStatus.发任务.GetIndexInt() &&
                                                        locations.Count(a => a.Code == t.FromLocationCode) > 0);
                        if (task != null)
                        {
                            //更新任务状态
                            int preStatus = task.TaskStatus;
                            task.TaskStatus = TaskEntityStatus.响应堆垛机库外放货完成.GetIndexInt();
                            var tempResult = AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                            if (tempResult.Success)
                            {
                                //标记交换区地址,任务完成10
                                //var prop = stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1TaskFlag");
                                //prop.Value = "10";
                                var prop = stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "WCSTaskAccount");
                                prop.Value = "10";
                                //var sendResult = S7Helper.PlcSplitWrite(plc, new List<EquipmentProp> { prop }, 20);
                                var sendResult = plc.Writes(new List <EquipmentProp> {
                                    prop
                                });
                                if (sendResult.Success)
                                {
                                    Logger.Log($"堆垛机{stocker.Name}完成库外放货成功,任务:{task.Id}", LogLevel.Success);
                                    return(BllResultFactory.Sucess());
                                }
                                else
                                {
                                    Logger.Log($"堆垛机{stocker.Name}完成库外放货失败,任务:{task.Id},原因:{sendResult.Msg}", LogLevel.Error);
                                    task.TaskStatus = preStatus;
                                    AppSession.Dal.UpdateCommonModel <TaskEntity>(task);
                                    return(BllResultFactory.Error());
                                }
                            }
                            else
                            {
                                Logger.Log($"完成堆垛机{stocker.Name}库外放货时,更新任务{task.Id}状态失败:{tempResult.Msg}", LogLevel.Error);
                                return(BllResultFactory.Error($"完成堆垛机{stocker.Name}库外放货时,更新任务{task.Id}状态失败:{tempResult.Msg}"));
                            }
                        }
                    }
                    //未知情况
                    Logger.Log($"堆垛机{stocker.Name}的任务完成时候和系统对应的任务出现了异常:PLC:{taskNo}或 货叉的任务类型:{forkType} ", LogLevel.Warning);
                    return(BllResultFactory.Error($"堆垛机{stocker.Name}的任务完成时候和系统对应的任务出现了异常:PLC:{taskNo}或 货叉的任务类型:{forkType} "));
                }
                else
                {
                    //Logger.Log($"堆垛机{stocker.Name}的任务完成时候和系统对应的任务出现了异常:PLC:{taskNo}或 货叉的任务类型:{forkType} ", LogLevel.Warning);
                    //未知情况
                    Logger.Log($"堆垛机{stocker.Name}出现了未知的执行状态:{stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "Fork1TaskExcuteStatus").Value}", LogLevel.Warning);
                    return(BllResultFactory.Sucess());
                }
            }
            return(BllResultFactory.Sucess());
        }
예제 #17
0
        public Station GetStationbyId(long id)
        {
            Station station = Stations.FirstOrDefault(s => s.Id == id);

            return(station);
        }
예제 #18
0
 public static Station FindStationById(int id)
 {
     return(Stations.FirstOrDefault(x => x.Id == id));
 }
예제 #19
0
 public bool DeleteStation(long id)
 {
     Stations.FirstOrDefault(s => s.Id == id).Actief = false;
     return(true);
 }