yanjinhui
2026-03-03 afbd9149dd39d33d66bb27eaf9ac34c3de36ac7a
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs
@@ -7,6 +7,7 @@
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.LocationEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO;
using WIDESEAWCS_DTO.RGV.FOURBOT;
@@ -128,56 +129,98 @@
        /// <param name="tasks"></param>
        public void SendCheckShapeingOkTask(List<Dt_Task> tasks)
        {
            FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
            try
            {
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("未找到四向车任务下发接口配置信息!请检查接口配置");
                List<Dt_RGVLocationInfo> rGVLocationInfos = new List<Dt_RGVLocationInfo>();
                List<Dt_StationManger> stationMangers = new List<Dt_StationManger>();
                var tasksToUpdate = new List<Dt_Task>();
                var locationsToUpdate = new List<Dt_RGVLocationInfo>();
                var stationsToUpdate = new List<Dt_StationManger>();
                #region ä»»åŠ¡ä¸‹å‘
                foreach (var item in tasks)
                {
                    #region èŽ·å–è´§ä½
                    var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(item.Roadway);
                    if (rGVLocationInfo == null)
                    try
                    {
                        item.ExceptionMessage = $"未找到终点库区【{item.Roadway}】可用空货位!";
                    }
                    #endregion
                    else
                    {
                        #region èŽ·å–è´§ä½
                        var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(item.Roadway);
                        if (rGVLocationInfo == null)
                        {
                            item.ExceptionMessage = $"未找到终点库区【{item.Roadway}】可用空货位!";
                            continue;
                        }
                        #endregion
                        var fOURBOTnewMovePodTask = new FOURBOTnewMovePodTask
                        {
                            priority = item.Grade,
                            podID = item.PalletCode,
                            destination = rGVLocationInfo.LocationCode,
                            desExt = new { unload = 1 }, // æ˜¯å¦æ”¾ä¸‹å®¹å™¨,0否1是
                            desType = 2
                        };
                        item.CurrentAddress = item.NextAddress;
                        item.NextAddress = rGVLocationInfo.LocationCode;
                        item.Roadway = rGVLocationInfo.RoadwayNo;
                        fOURBOTnewMovePodTask.priority = item.Grade;
                        fOURBOTnewMovePodTask.podID = item.PalletCode;
                        fOURBOTnewMovePodTask.destination = item.NextAddress;
                        fOURBOTnewMovePodTask.desExt = new
                        {
                            unload = 1//是否放下容器,0否1是
                        };
                        fOURBOTnewMovePodTask.desType = 2;
                        string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
                        FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                        var fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                        if (fOURBOTReturn.returnCode == 0)
                        {
                            FOURBOTnewMovePodTaskResponseData fOURBO = fOURBOTReturn.data as FOURBOTnewMovePodTaskResponseData ?? throw new Exception("未获取到四向车返回的任务ID");
                            var data = fOURBOTReturn.data.ToString();
                            var fOURBO = data.DeserializeObject<FOURBOTnewMovePodTaskResponseData>();
                            item.RGVTaskId = fOURBO.taskID;
                            item.TaskState = (int)TaskStatusEnum.Puting;
                            rGVLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
                            rGVLocationInfos.Add(rGVLocationInfo);
                            locationsToUpdate.Add(rGVLocationInfo);
                            #region é‡Šæ”¾å…¥åº“站台
                            Dt_StationManger stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
                            stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                            stationMangers.Add(stationManger);
                            var stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
                            if (stationManger != null)
                            {
                                stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                                stationsToUpdate.Add(stationManger);
                            }
                            #endregion
                        }
                        else
                        {
                            item.ExceptionMessage = $"四向车接口返回错误:{fOURBOTReturn.returnMsg}";
                            // è®°å½•失败的任务
                        }
                    }
                }
                _taskService.Db.Ado.BeginTran();
                _taskService.UpdateData(tasks);
                _rGVLocationInfoService.UpdateData(rGVLocationInfos);
                _stationMangerService.UpdateData(stationMangers);
                _taskService.Db.Ado.CommitTran();
                    catch (Exception ex)
                    {
                        item.ExceptionMessage = $"处理任务异常:{ex.Message}";
                        WriteError($"{nameof(TaskJob)}-{item.TaskId}", ex.Message, ex);
                    }
                    tasksToUpdate.Add(item);
                }
                #endregion
                #region æ›´æ–°æ•°æ®
                // å¦‚果有需要更新的数据,才执行事务
                if (tasksToUpdate.Any() || locationsToUpdate.Any() || stationsToUpdate.Any())
                {
                    try
                    {
                        _unitOfWorkManage.BeginTran();
                        if (tasksToUpdate.Any())
                            _taskService.UpdateData(tasksToUpdate);
                        if (locationsToUpdate.Any())
                            _rGVLocationInfoService.UpdateData(locationsToUpdate);
                        if (stationsToUpdate.Any())
                            _stationMangerService.UpdateData(stationsToUpdate);
                        _unitOfWorkManage.CommitTran();
                    }
                    catch (Exception ex)
                    {
                        _unitOfWorkManage.RollbackTran();
                        WriteError(nameof(TaskJob), ex.Message, ex);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {