From e8323315b683a76509b9c1ecc717bb5b6a9ee08a Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期二, 14 四月 2026 18:07:04 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/RuiShengZhiNeng/GaoPuLiTiKu

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs |  387 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 371 insertions(+), 16 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs"
index ad25d35..4ad2f40 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs"
@@ -10,6 +10,11 @@
 using WIDESEAWCS_DTO.WMS;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO;
+using WIDESEAWCS_DTO.AGV.HIKROBOT;
+using System.Diagnostics.CodeAnalysis;
+using System.Reflection.PortableExecutable;
+using WIDESEAWCS_QuartzJob;
 
 namespace WIDESEAWCS_TaskInfoService
 {
@@ -25,10 +30,41 @@
         /// <returns></returns>
         public WebResponseContent CreateHKNewInTask(TaskDTO taskDTO, int taskType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
+                Dt_HKLocationInfo? hKLocationInfo = null;
+                if (taskType==(int)TaskTypeEnum.STURR)
+                {
+                    var reslut=_stationInfo.Repository.QueryFirst(x=>x.StationCode==taskDTO.fromLocationCode) ?? throw new Exception($"鏈壘鍒拌捣鐐硅揣浣嶃�恵taskDTO.fromLocationCode}銆�");
+                }
+                #region 鐐瑰埌鐐�
+                if (!string.IsNullOrEmpty(taskDTO.toLocationCode))
+                {
+                    hKLocationInfo = _hKLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"鏈壘鍒扮粓鐐硅揣浣嶃�恵taskDTO.toLocationCode}銆�");
+                    if (hKLocationInfo.LocationStatus != (int)LocationStatusEnum.Free) throw new Exception($"缁堢偣璐т綅銆恵taskDTO.toLocationCode}銆戣揣浣嶇姸鎬佷笉涓虹┖璐т綅");
+                }
+                #endregion
                 //鑾峰彇璐т綅淇℃伅
-                Dt_HKLocationInfo? hKLocationInfo = _hKLocationInfoService.GetFreeLocationInfo(taskDTO.toAreaCode) ?? throw new Exception($"鏈壘鍒扮粓鐐瑰簱鍖恒�恵taskDTO.toAreaCode}銆戝彲鐢ㄧ┖璐т綅锛�"); ;
+                else
+                    hKLocationInfo = _hKLocationInfoService.GetFreeLocationInfo(taskDTO.toAreaCode) ?? throw new Exception($"鏈壘鍒扮粓鐐瑰簱鍖恒�恵taskDTO.toAreaCode}銆戝彲鐢ㄧ┖璐т綅锛�");
+                if (taskType == (int)TaskTypeEnum.Q1TSJ4)
+                {
+                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
+                    if (device.IsConnected)
+                    {
+                        var reslu = device.GetValue<HoistEnum, string>(HoistEnum.Emptycontainernumber);
+                        var result = reslu?.TrimEnd('\0')?.Substring(2);
+                        if (reslu == taskDTO.containerCode && result != null)
+                        {
+                            throw new Exception($"褰撳墠鐨勬枡绠卞彿涓簕reslu}涓巤taskDTO.containerCode}鏂欑鍙蜂笉鍖归厤");
+                        }
+                    }
+                    else
+                    {
+                        throw new Exception("鎻愬崌鏈轰俊鎭澶囪繛鎺ュけ璐�");
+                    }
+                }
                 Dt_Task dt_Task = new Dt_Task()
                 {
                     TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
@@ -46,17 +82,42 @@
                     Creater = "WMS",
                 };
                 hKLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
-                Db.Ado.BeginTran();
-                BaseDal.AddData(dt_Task);
-                _hKLocationInfoService.Repository.UpdateData(hKLocationInfo);
-                Db.Ado.CommitTran();
-                return WebResponseContent.Instance.OK();
+
+                #region 涓嬪彂娴峰悍AGV浠诲姟
+                content = SendHIKROBOTTask(dt_Task);
+                if (!content.Status) throw new Exception(content.Message);
+                dt_Task.TaskState = (int)TaskStatusEnum.Execut;
+                dt_Task.Dispatchertime = DateTime.Now;
+                #endregion
+                try
+                {
+                    Db.Ado.BeginTran();
+                    BaseDal.AddData(dt_Task);
+                    _hKLocationInfoService.Repository.UpdateData(hKLocationInfo);
+                    Db.Ado.CommitTran();
+                }
+                catch (Exception ex)
+                {
+                    Db.Ado.RollbackTran();
+                    throw new Exception(ex.Message);
+                }
+
+                content.OK(data: new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = "鎴愬姛锛�"
+                });
             }
             catch (Exception ex)
             {
-                Db.Ado.RollbackTran();
-                throw new Exception(ex.Message);
+                content.Data = new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = $"澶辫触锛亄ex.Message}"
+                };
+                content.Error(ex.Message);
             }
+            return content;
         }
         /// <summary>
         /// 鍒涘缓娴峰悍AGV鍑哄簱浠诲姟
@@ -66,12 +127,23 @@
         /// <returns></returns>
         public WebResponseContent CreateHKNewOutTask(TaskDTO taskDTO, int taskType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
+                //4妤煎簱鍐呭埌鎻愬崌鏈�
                 Dt_HKLocationInfo? hKLocationInfo = _hKLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"鏈壘鍒拌捣鐐瑰簱浣嶃�恵taskDTO.fromLocationCode}銆戯紒");
                 if (hKLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"璧风偣搴撲綅銆恵taskDTO.fromLocationCode}銆戝綋鍓嶅簱浣嶇姸鎬佷笉鍙嚭搴擄紒");
                 if (hKLocationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"璧风偣搴撲綅銆恵taskDTO.fromLocationCode}銆戠粦瀹氭枡绠卞彿銆恵hKLocationInfo.PalletCode}銆戜笌浠诲姟鏂欑鍙枫�恵taskDTO.containerCode}銆戜笉鍖归厤锛�");
-                Dt_Task dt_Task = new Dt_Task()
+                //搴撳唴鍒扮幇杈圭殑鐐瑰埌鐐逛换鍔★紝鏄惁闇�瑕佸垽鏂揣浣嶇姸鎬侊紵
+                if (taskType == (int)TaskTypeEnum.STU0003)
+                {
+                    var reslut = _stationInfo.Repository.QueryFirst(x => x.StationCode == taskDTO.toLocationCode) ?? throw new Exception($"鏈壘鍒扮粓鐐硅揣浣嶃�恵taskDTO.toLocationCode}銆�");
+                    if (reslut.StationStatus != (int)LocationStatusEnum.Free)
+                    {
+                        throw new Exception($"缁堢偣绔欏彴銆恵taskDTO.toLocationCode}銆戠姸鎬佷笉涓虹┖闂诧紒");
+                    }
+                }
+                    Dt_Task dt_Task = new Dt_Task()
                 {
                     TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                     WMSTaskNum = taskDTO.taskCode,
@@ -88,18 +160,301 @@
                     Creater = "WMS",
                 };
                 hKLocationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt();
-                Db.Ado.BeginTran();
-                BaseDal.AddData(dt_Task);
-                _hKLocationInfoService.Repository.UpdateData(hKLocationInfo);
-                Db.Ado.CommitTran();
-                return WebResponseContent.Instance.OK();
+                #region 涓嬪彂娴峰悍AGV浠诲姟
+                content = SendHIKROBOTTask(dt_Task);
+                if (!content.Status) throw new Exception(content.Message);
+                dt_Task.TaskState = (int)TaskStatusEnum.Execut;
+                dt_Task.Dispatchertime = DateTime.Now;
+                #endregion
+                try
+                {
+                    Db.Ado.BeginTran();
+                    BaseDal.AddData(dt_Task);
+                    _hKLocationInfoService.Repository.UpdateData(hKLocationInfo);
+                    Db.Ado.CommitTran();
+                }
+                catch (Exception ex)
+                {
+                    Db.Ado.RollbackTran();
+                    throw new Exception(ex.Message);
+                }
+                return content.OK(data: new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = "鎴愬姛锛�"
+                });
             }
             catch (Exception ex)
             {
-                Db.Ado.RollbackTran();
-                throw new Exception(ex.Message);
+                content.Data = new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = $"澶辫触锛亄ex.Message}"
+                };
+                return content.Error(ex.Message);
             }
         }
         #endregion
+
+        #region 涓嬪彂娴峰悍AGV浠诲姟
+        public WebResponseContent SendHIKROBOTTask([NotNull] Dt_Task task)
+        {
+            WebResponseContent content = new WebResponseContent();
+            HIKROBOTReturn hIKROBOTReturn = null;
+            HIKROBOTTaskSubmit hIKROBOTTaskSubmit = null;
+            try
+            {
+                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(HIKROBOTTaskSubmit)) ?? throw new Exception("鏈壘鍒版捣搴稟GV浠诲姟涓嬪彂鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
+                #region 瀹炰綋绫昏浆鎹�
+                hIKROBOTTaskSubmit = HIKROBOTTask(task);
+                if (hIKROBOTTaskSubmit == null) throw new Exception("娴峰悍AGV浠诲姟瀹炰綋杞崲澶辫触");
+                var json = hIKROBOTTaskSubmit.Serialize();
+                #endregion
+                // 鍒涘缓Headers瀛楀吀
+                var headers = new Dictionary<string, string>
+                {
+                    { "X-lr-request-id", DateTimeOffset.Now.ToUnixTimeSeconds().ToString()+task.TaskNum }
+                    // 濡傛灉闇�瑕佸叾浠朒eader锛屽彲浠ョ户缁坊鍔�
+                    // { "Content-Type", "application/json" }
+                };
+
+                // 浼犻�扝eaders鍙傛暟
+                string response = HttpHelper.Post(apiInfo.ApiAddress, hIKROBOTTaskSubmit.Serialize(), headers: headers);
+                //string response = HttpHelper.Post(apiInfo.ApiAddress, hIKROBOTTaskSubmit.Serialize());
+                hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
+                if (hIKROBOTReturn.code == "SUCCESS")
+                {
+                    var data = hIKROBOTReturn.data.ToString().DeserializeObject<HIKROBOTReturnData>();
+                    content.OK(data: data);
+                }
+                else
+                {
+                    throw new Exception(hIKROBOTReturn.message);
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            finally
+            {
+                _trackloginfoService.AddTrackLog(hIKROBOTTaskSubmit, content, "涓嬪彂娴峰悍AGV浠诲姟", "", hIKROBOTReturn.message);
+            }
+            return content;
+        }
+        #endregion
+        /// <summary>
+        /// 娴峰悍浠诲姟瀹炰綋绫昏浆鎹�
+        /// </summary>
+        /// <param name="task"></param>
+        /// <returns></returns>
+        public HIKROBOTTaskSubmit HIKROBOTTask(Dt_Task task)
+        {
+            HIKROBOTTaskSubmit hIKROBOTTaskSubmit = new HIKROBOTTaskSubmit();
+            try
+            {
+                var tasktype = (TaskTypeEnum)Enum.GetValues(typeof(TaskTypeEnum)).GetValue(task.TaskType - 1);
+
+                hIKROBOTTaskSubmit.initPriority = task.Grade;
+                hIKROBOTTaskSubmit.robotTaskCode = task.WMSTaskNum;
+                hIKROBOTTaskSubmit.taskType = tasktype.ToString(); ExtraDto extraDto = new ExtraDto();
+                if (task.TaskType != (int)TaskTypeEnum.MOVE && task.TaskType != (int)TaskTypeEnum.Q3RK && task.TaskType != (int)TaskTypeEnum.Q3CK && task.TaskType != (int)TaskTypeEnum.F01)
+                {
+                    CarrierInfoDto carrierInfoDto = new CarrierInfoDto()
+                    {
+                        carrierCode = task.PalletCode,
+                        carrierType = task.PalletCode.Contains("LXM") ? "DX" : "SX"
+                    };
+                    extraDto.carrierInfo.Add(carrierInfoDto);
+                    hIKROBOTTaskSubmit.extra = extraDto;
+                }
+                switch (tasktype)
+                {
+                    case TaskTypeEnum.CPInbound:
+                    case TaskTypeEnum.CPOutbound:
+                    case TaskTypeEnum.MLInbound:
+                    case TaskTypeEnum.MLOutbound:
+                        break;
+                    case TaskTypeEnum.RK3F:
+                    case TaskTypeEnum.CK3F:
+                    case TaskTypeEnum.F02:
+                    case TaskTypeEnum.F03:
+                    case TaskTypeEnum.F04:
+                        {
+                            TargetRouteDto target = new TargetRouteDto()
+                            {
+                                code = task.CurrentAddress,
+                                operation = "DELIVERY",//鍙栬揣
+                                seq = 0,
+                                type = "SITE",
+                            };
+                            TargetRouteDto targetRoute = new TargetRouteDto()
+                            {
+                                code = task.NextAddress,
+                                operation = "DELIVERY",//閫佽揣
+                                seq = 1,
+                                type = "SITE"
+                            };
+                            hIKROBOTTaskSubmit.targetRoute.Add(target);
+                            hIKROBOTTaskSubmit.targetRoute.Add(targetRoute);
+                        }
+                        break;
+                    case TaskTypeEnum.STURR:
+                    case TaskTypeEnum.Q1TSJ4:
+                        {
+                            TargetRouteDto target = new TargetRouteDto()
+                            {
+                                code = task.CurrentAddress,
+                                operation = "DELIVERY",//鍙栬揣
+                                seq = 0,
+                                type = "SITE",
+                            };
+                            TargetRouteDto targetRoute = new TargetRouteDto()
+                            {
+                                code = task.NextAddress,
+                                operation = "DELIVERY",//閫佽揣
+                                seq = 1,
+                                type = "STORAGE"
+                            };
+                            hIKROBOTTaskSubmit.targetRoute.Add(target);
+                            hIKROBOTTaskSubmit.targetRoute.Add(targetRoute);
+                        }
+                        break;
+                    case TaskTypeEnum.STU0003:
+                    case TaskTypeEnum.CHUKU1:
+                        {
+                            TargetRouteDto target = new TargetRouteDto()
+                            {
+                                code = task.CurrentAddress,
+                                operation = "DELIVERY",//鍙栬揣
+                                seq = 0,
+                                type = "STORAGE",
+                            };
+                            TargetRouteDto targetRoute = new TargetRouteDto()
+                            {
+                                code = task.NextAddress,
+                                operation = "DELIVERY",//閫佽揣
+                                seq = 1,
+                                type = "SITE",
+                            };
+                            hIKROBOTTaskSubmit.targetRoute.Add(target);
+                            hIKROBOTTaskSubmit.targetRoute.Add(targetRoute);
+                        }
+                        break;
+                    case TaskTypeEnum.Q3RK:
+                    case TaskTypeEnum.Q3CK:
+                    case TaskTypeEnum.MOVE:
+                    case TaskTypeEnum.F01:
+                        {
+                            TargetRouteDto target = new TargetRouteDto()
+                            {
+                                code = task.CurrentAddress,
+                                operation = "DELIVERY",//鍙栬揣
+                                seq = 0,
+                                type = "SITE",
+                            };
+                            TargetRouteDto targetRoute = new TargetRouteDto()
+                            {
+                                code = task.NextAddress,
+                                operation = "DELIVERY",//閫佽揣
+                                seq = 1,
+                                type = "SITE",
+                            };
+                            hIKROBOTTaskSubmit.targetRoute.Add(target);
+                            hIKROBOTTaskSubmit.targetRoute.Add(targetRoute);
+                        }
+                        break;
+                    case TaskTypeEnum.STUPTBY:
+                        {
+                            TargetRouteDto target = new TargetRouteDto()
+                            {
+                                code = task.CurrentAddress,
+                                operation = "DELIVERY",//鍙栬揣
+                                seq = 0,
+                                type = "STORAGE",
+                            };
+                            TargetRouteDto targetRoute = new TargetRouteDto()
+                            {
+                                code = task.NextAddress,
+                                operation = "DELIVERY",//閫佽揣
+                                seq = 1,
+                                type = "STORAGE",
+                            };
+                            hIKROBOTTaskSubmit.targetRoute.Add(target);
+                            hIKROBOTTaskSubmit.targetRoute.Add(targetRoute);
+                        }
+                        break;
+                    case TaskTypeEnum.CPMoveInventory:
+                        break;
+                    default:
+                        break;
+                }
+            }
+            catch (Exception ex)
+            {
+
+            }
+            return hIKROBOTTaskSubmit;
+        }
+
+
+        /// <summary>
+        /// 娴峰悍AGV浠诲姟缁х画鎵ц
+        /// </summary>
+        /// <param name="TaskCode">浠诲姟鍙�</param>
+        /// <returns></returns>
+        public WebResponseContent Hikvisiontaskscontinue(string TaskCode, string Address = null)
+        {
+            WebResponseContent content = new WebResponseContent();
+            HIKROBOTReturn hIKROBOTReturn = null;
+            HIKROBOTTaskContinue hIKROBOTTaskContinue = null;
+            try
+            {
+                // 1. 鍙傛暟楠岃瘉
+                if (string.IsNullOrWhiteSpace(TaskCode))
+                {
+                    throw new Exception("浠诲姟缂栫爜涓嶈兘涓虹┖");
+                }
+                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(HIKROBOTTaskContinue)) ?? throw new Exception("鏈壘鍒版捣搴稟GV缁х画鎵ц鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
+                hIKROBOTTaskContinue = new HIKROBOTTaskContinue()
+                {
+                    triggerCode = TaskCode,
+                    triggerType = "TASK",//鍥哄畾鍊�
+                    targetRoute = string.IsNullOrEmpty(Address) ? null :
+                    new TargetRouteDto()
+                    {
+                        code = Address,
+                        type = "SITE",
+                    }
+                };
+                var headers = new Dictionary<string, string>
+                {
+                    { "X-lr-request-id", DateTimeOffset.Now.ToUnixTimeSeconds().ToString()+TaskCode }
+                };
+                string response = HttpHelper.Post(apiInfo.ApiAddress, hIKROBOTTaskContinue.Serialize(), headers: headers);
+                hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
+
+                if (hIKROBOTReturn.code == "SUCCESS")
+                {
+                    var data = hIKROBOTReturn.data.ToString().DeserializeObject<HIKROBOTReturnData>();
+                    content.OK(data: data);
+                }
+                else
+                {
+                    throw new Exception(hIKROBOTReturn.message);
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            finally
+            {
+                _trackloginfoService.AddTrackLog(hIKROBOTTaskContinue, content, "娴峰悍AGV缁х画鎵ц浠诲姟", "", hIKROBOTReturn.message);
+
+            }
+            return content;
+        }
+
     }
 }

--
Gitblit v1.9.3