From 0c2124ab83fcc330e9620f02fbf02dedf8980526 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 17 三月 2026 16:56:43 +0800
Subject: [PATCH] 优化海康AGV三楼四楼任务

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs |  240 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 225 insertions(+), 15 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..c7a6a39 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,9 @@
 using WIDESEAWCS_DTO.WMS;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO;
+using WIDESEAWCS_DTO.AGV.HIKROBOT;
+using System.Diagnostics.CodeAnalysis;
 
 namespace WIDESEAWCS_TaskInfoService
 {
@@ -25,10 +28,20 @@
         /// <returns></returns>
         public WebResponseContent CreateHKNewInTask(TaskDTO taskDTO, int taskType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
+                Dt_HKLocationInfo? hKLocationInfo = null;
+                #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}銆戝彲鐢ㄧ┖璐т綅锛�");
                 Dt_Task dt_Task = new Dt_Task()
                 {
                     TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
@@ -46,17 +59,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,6 +104,7 @@
         /// <returns></returns>
         public WebResponseContent CreateHKNewOutTask(TaskDTO taskDTO, int taskType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
                 Dt_HKLocationInfo? hKLocationInfo = _hKLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"鏈壘鍒拌捣鐐瑰簱浣嶃�恵taskDTO.fromLocationCode}銆戯紒");
@@ -88,18 +127,189 @@
                     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浠诲姟瀹炰綋杞崲澶辫触");
+                #endregion
+                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);
+
+                hIKROBOTTaskSubmit.initPriority = task.Grade;
+                hIKROBOTTaskSubmit.robotTaskCode = task.WMSTaskNum;
+                hIKROBOTTaskSubmit.taskType = tasktype.ToString(); ExtraDto extraDto = new ExtraDto();
+                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.F01:
+                        break;
+                    case TaskTypeEnum.RK3F:
+                    case TaskTypeEnum.CK3F:
+                    case TaskTypeEnum.F02:
+                        {
+                            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.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:
+                        break;
+                    case TaskTypeEnum.Q3CK:
+                        break;
+                    case TaskTypeEnum.Move:
+                        break;
+                    case TaskTypeEnum.CPMoveInventory:
+                        break;
+                    default:
+                        break;
+                }
+            }
+            catch (Exception ex)
+            {
+
+            }
+            return hIKROBOTTaskSubmit;
+        }
     }
 }

--
Gitblit v1.9.3