dengjunjie
5 天以前 4ad27940cc8a276616af9cdc9ac85d793a6b1d9e
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs
@@ -8,6 +8,7 @@
using System.Reflection.Metadata;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.LocationEnum;
@@ -176,7 +177,7 @@
                                    BaseDal.UpdateData(task);
                                }
                                // //四楼出提升机 å…¥åº“ ä¹‹å‰æ˜¯AGV_ToExecute  //要写成取货完成状态TakeFinish
                                else if ((task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt() || task.TaskType == TaskTypeEnum.F03.ObjToInt()) && task.TaskState == (int)TaskStatusEnum.AGV_ToExecute)
                                else if ((task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt() || task.TaskType == TaskTypeEnum.F03.ObjToInt()) && task.TaskState == (int)TaskStatusEnum.TakeFinish)
                                {
                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
                                    if (device == null) task.ExceptionMessage = "未找到提升机信息";
@@ -283,7 +284,7 @@
                        case "intolift": //进入电梯
                            {
                                //六楼到一楼的入库任务
                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01)
                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01 || task.TaskType == (int)TaskTypeEnum.Q3CK)
                                {
                                    task.TaskState = TaskStatusEnum.Hkintolift.ObjToInt();
                                    BaseDal.UpdateData(task);
@@ -292,7 +293,7 @@
                            break;
                        case "leavelift": //离开电梯
                            {
                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01)
                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01|| task.TaskType == (int)TaskTypeEnum.Q3CK)
                                {
                                    task.TaskState = TaskStatusEnum.HKleavelift.ObjToInt();
                                    BaseDal.UpdateData(task);
@@ -391,6 +392,21 @@
                                    TaskCompleted(task, deviceTypeEnum);
                                }
                            }
                            if (Rgv.content.status == 5)
                            {
                                task.ExceptionMessage = Rgv.content.errorReason;
                                var Error = _taskErrorMessageService.Repository.QueryFirst(x => x.ErrorCode == Rgv.content.errorCode && x.DeviceType == (int)deviceTypeEnum);
                                if (Error != null)
                                {
                                    task.ExceptionMessage = Error.ExceptionMessage;
                                    MatchCollection matches = Regex.Matches(Rgv.content.errorReason, @"\(([^)]+)\)");
                                    if (matches.Count > 0)
                                        task.ExceptionMessage = ReplacePlaceholders(Rgv.content.errorReason, Error.ExceptionMessage);
                                    ErrorTaskFeedback(task, true, Error.ErrorCode.ToString());
                                }
                                else
                                    ErrorTaskFeedback(task, true);
                            }
                        }
                    }
                }
@@ -405,6 +421,30 @@
                _trackloginfoService.AddTrackLog(TaskDTO, content, $"{deviceName}任务状态反馈", "", "");
            }
            return content;
        }
        #endregion
        #region å¼‚常信息转换
        /// <summary>
        /// å¼‚常信息()内容转换
        /// </summary>
        /// <param name="source"></param>
        /// <param name="targetTemplate"></param>
        /// <returns></returns>
        public string ReplacePlaceholders(string source, string targetTemplate)
        {
            // æå–源字符串中的所有括号值
            var values = Regex.Matches(source, @"\(([^)]+)\)")
                              .Cast<Match>()
                              .Select(m => m.Groups[1].Value)
                              .ToList();
            // æ›¿æ¢ç›®æ ‡æ¨¡æ¿ä¸­çš„æ‰€æœ‰ (%v)
            int idx = 0;
            string result = Regex.Replace(targetTemplate, @"\(\%v\)", _ =>
                idx < values.Count ? values[idx++] : "");
            return result;
        }
        #endregion
@@ -597,38 +637,22 @@
                        dt_RGVLocationInfo.LocationStatus = locationStatusEnum.ObjToInt();
                        _rGVLocationInfoService.Repository.UpdateData(dt_RGVLocationInfo);
                    }
                }
                else//平库库位
                {
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
        #region æ›´æ–°ä¸€æ¥¼ç«™å°çŠ¶æ€
        public WebResponseContent UpdateStandStatus(Dt_Task task, string stationCode, LocationStatusEnum locationStatusEnum)
        {
            try
            {
                Dt_StationManger? stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == task.TargetAddress);
                //stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
                if (stationManger != null)
                {
                    if (locationStatusEnum == LocationStatusEnum.Free) //如果起点完成就给货位赋值托盘号
                    Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == locationCode);
                    if (stationManger != null)
                    {
                        stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
                        if (locationStatusEnum == LocationStatusEnum.Free) //如果起点完成就给货位赋值托盘号
                        {
                            stationManger.Remark = "";
                            stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                        }
                        else
                        {
                            stationManger.Remark = palletCode;
                            stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
                        }
                        _stationMangerService.UpdateData(stationManger);
                    }
                    else
                    {
                        stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                    }
                    _stationMangerService.UpdateData(stationManger);
                }
                return WebResponseContent.Instance.OK();
            }
@@ -640,7 +664,7 @@
        #endregion
        #region ä¸ŠæŠ¥WMS
        public WebResponseContent TaskFeedback(Dt_Task dt_Task, int Status, bool Del = true)
        public WebResponseContent TaskFeedback(Dt_Task dt_Task, int Status, bool Del = false)
        {
            WebResponseContent content = new WebResponseContent();
            WMSInOutBoundCompleteFeedback boundCompleteFeedback = new WMSInOutBoundCompleteFeedback();
@@ -683,7 +707,7 @@
        }
        #endregion
        #region å¤±è´¥ä»»åŠ¡ä¸ŠæŠ¥WMS并删除任务
        public WebResponseContent ErrorTaskFeedback(Dt_Task dt_Task, bool Del)
        public WebResponseContent ErrorTaskFeedback(Dt_Task dt_Task, bool Del = false, string ErrorCode = "")
        {
            WebResponseContent content = new WebResponseContent();
            WMSInOutBoundCompleteFeedback boundCompleteFeedback = new WMSInOutBoundCompleteFeedback();
@@ -699,7 +723,7 @@
                    boundCompleteFeedback.fromStationCode = dt_Task.SourceAddress;
                    boundCompleteFeedback.toLocationCode = dt_Task.TargetAddress;
                    boundCompleteFeedback.status = 3;
                    boundCompleteFeedback.custStatus = "";
                    boundCompleteFeedback.custStatus = ErrorCode;
                    boundCompleteFeedback.memo = dt_Task.ExceptionMessage;
                    string response = HttpHelper.Post(apiInfo.ApiAddress, boundCompleteFeedback.Serialize());
                    agvContent = response.DeserializeObject<WMSReturn>();
@@ -720,15 +744,12 @@
            finally
            {
                _trackloginfoService.AddTrackLog(boundCompleteFeedback, content, "出入库任务状态反馈WMS", "", "");
                if (agvContent != null && agvContent.code == 200 && Del) BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动删除);
                if (agvContent != null && agvContent.code == 200 && Del)
                    BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动删除);
                else BaseDal.UpdateData(dt_Task);
            }
            return content;
        }
        #endregion
    }
}