From 64ec1a7fb55389d8db371d112e49f741de866796 Mon Sep 17 00:00:00 2001
From: lss <Lss@HanInfo>
Date: 星期三, 18 六月 2025 16:41:26 +0800
Subject: [PATCH] 业务开发与优化

---
 HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs |  256 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 198 insertions(+), 58 deletions(-)

diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs
index 5f8b1bc..92791ce 100644
--- a/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs
+++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs
@@ -143,18 +143,19 @@
 
 
         private static object lockObj = new object();
+
         /// <summary>
         /// 鍒涘缓浠诲姟
         /// </summary>
         /// <param name="model"></param>
         /// <returns></returns>
-        internal static Result createtask(CreateTaskModel model)
+        internal static Result<Empty> createtask(CreateTaskModel model)
         {
-            Result result = new Result { resultCode = 0, resultMsg = "鍒涘缓鎴愬姛" };
+            Result<Empty> result = new Result<Empty> { Code = 0, Msg = "鍒涘缓鎴愬姛" };
             if (model == null)
             {
-                result.resultCode = -1;
-                result.resultMsg = "鍏ュ弬涓虹┖";
+                result.Code = -1;
+                result.Msg = "鍏ュ弬涓虹┖";
                 return result;
             }
             var db = new SqlHelper<object>().GetInstance();
@@ -167,7 +168,6 @@
             {
                 try
                 {
-
                     // 1 绌烘墭鍥炲簱
                     if (model.TaskType == "1")
                     {
@@ -177,9 +177,9 @@
                         startloc = LocationHelper.GetLoc(model.startBit);
                         if (startloc == null)
                         {
-                            result.resultCode = -1;
-                            result.resultMsg = $"鏍规嵁璧风偣:{model.startBit}鏈壘鍒拌揣浣嶄俊鎭�;
-                            LogHelper.Info($"creattask:鏍规嵁璧风偣:{model.startBit}鏈壘鍒拌揣浣嶄俊鎭�);
+                            result.Code = -1;
+                            result.Msg = $"鏍规嵁璧风偣:{model.startBit}鏈壘鍒拌揣浣嶄俊鎭�;
+                            LogHelper.Info($"creattask:{result.Msg}");
                             return result;
                         }
                         else
@@ -187,9 +187,9 @@
                             var cntr = LocationHelper.GetLocCntrRel(endloc.S_CODE).FirstOrDefault();
                             if (cntr == null)
                             {
-                                result.resultCode = -1;
-                                result.resultMsg = $"鏍规嵁璧风偣:{model.startBit}鏈壘鍒扮粦瀹氭墭鐩�;
-                                LogHelper.Info($"creattask:鏍规嵁璧风偣:{model.startBit}鏈壘鍒扮粦瀹氭墭鐩�);
+                                result.Code = -1;
+                                result.Msg = $"鏍规嵁璧风偣:{model.startBit}鏈壘鍒扮粦瀹氭墭鐩�;
+                                LogHelper.Info($"creattask:{result.Msg}");
                                 return result;
                             }
                             else
@@ -200,14 +200,74 @@
                         #endregion
 
                         #region 璁$畻绔嬪簱缁堢偣
-                        endloc = LocationHelper.InStorage(startloc);
+
+                        endloc = LocationHelper.InStorage("");
                         if (endloc == null)
                         {
-                            result.resultCode = -1;
-                            result.resultMsg = $"鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌";
-                            LogHelper.Info($"creattask:鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌");
+                            result.Code = -1;
+                            result.Msg = $"鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌";
+                            LogHelper.Info($"creattask:{result.Msg}");
                             return result;
                         }
+                        #endregion
+
+                        #region 鍒涘缓浣滀笟
+                        if (startloc != null && endloc != null)
+                        {
+                            //鍒涘缓浣滀笟
+                            var wcsTask = new WMSTask
+                            {
+                                S_CODE = WMSHelper.GenerateTaskNo(),
+                                S_TYPE = Type,
+                                N_TYPE = int.Parse(model.TaskType),
+                                S_START_LOC = start,
+                                S_END_LOC = endloc.S_CODE,
+                                S_CNTR_CODE = cntrcode,
+                                S_END_WH = endloc.S_WH_CODE,
+                                S_START_WH = startloc.S_WH_CODE,
+                                S_START_AREA = startloc.S_AREA_CODE,
+                                S_END_AREA = endloc.S_AREA_CODE,
+
+                            };
+                            LogHelper.Info("鍒涘缓浣滀笟锛� + JsonConvert.SerializeObject(wcsTask), "CreateTask");
+                            if (WMSHelper.CreateTask(wcsTask))
+                            {
+                                LocationHelper.LockLoc(startloc.S_CODE, 2);
+                                LocationHelper.LockLoc(endloc.S_CODE, 1);
+                                LogHelper.Info("鍒涘缓浣滀笟鎴愬姛");
+                                //绌烘墭鍥炲簱鎴愬姛锛屽鏋滃瓨鍦ㄧ墿鏂欐暟鎹紝鍒犻櫎
+                                var itemcntr = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == cntrcode).First();
+                                if (itemcntr != null) { db.Deleteable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == cntrcode).ExecuteCommand(); }
+                                LogHelper.Info("鍒涘缓浠诲姟鎴愬姛");
+                            }
+                        }
+                        #endregion
+
+                    }
+                    // 2 鍑哄簱
+                    if (model.TaskType == "2")
+                    {
+                        Type = "鍑哄簱";
+
+                        #region 鑾峰彇缁堢偣淇℃伅
+                        startloc = LocationHelper.GetLoc(model.endBit);
+                        if (startloc == null)
+                        {
+                            result.Code = -1;
+                            result.Msg = $"鏍规嵁缁堢偣:{model.startBit}鏈壘鍒拌揣浣嶄俊鎭�;
+                            LogHelper.Info($"creattask:{result.Msg}");
+                            return result;
+                        }
+                        #endregion
+
+                        #region 鏍规嵁鐗╂枡璁$畻鍑哄簱鎵樼洏锛屽厛杩涘厛鍑猴紝浼樺厛鍑哄渚�+                        //鍏堣绠楀唴渚ц揣浣嶏紝鍒ゆ柇鏄惁鏈夊崟缁勬墭鐩�+                        var locations = LocationHelper.GetLocByItemCodeOrderyTime("", model.ItemCode);
+                        if (locations.Count > 0)
+                        {
+                            endloc = locations.OrderBy(a => a.N_COL).First();
+                        }
+
                         #endregion
 
                         #region 鍒涘缓浣滀笟
@@ -241,20 +301,18 @@
                     }
                     else
                     {
-                        result.resultCode = -1;
-                        result.resultMsg = $"浠诲姟绫诲瀷鏈夎锛寋model.TaskType}浠诲姟绫诲瀷涓嶆槸瑙勫畾浠诲姟绫诲瀷";
-                        LogHelper.Info($"creattask:浠诲姟绫诲瀷鏈夎锛寋model.TaskType}浠诲姟绫诲瀷涓嶆槸瑙勫畾浠诲姟绫诲瀷");
+                        result.Code = -1;
+                        result.Msg = $"浠诲姟绫诲瀷鏈夎锛寋model.TaskType}浠诲姟绫诲瀷涓嶆槸瑙勫畾浠诲姟绫诲瀷";
+                        LogHelper.Info($"creattask:{result.Msg}");
                         return result;
                     }
-
-
 
                     return result;
                 }
                 catch (Exception ex)
                 {
-                    result.resultCode = -1;
-                    result.resultMsg = $"{ex.ToString()}";
+                    result.Code = -1;
+                    result.Msg = $"{ex.ToString()}";
                     return result;
 
                 }
@@ -268,18 +326,19 @@
         /// </summary>
         /// <param name="model"></param>
         /// <returns></returns>
-        internal static Result NotifyDeviceSignal(NotifyDeviceSignalModel model)
+        internal static Result<Empty> NotifyDeviceSignal(NotifyDeviceSignalModel model)
         {
-            Result result = new Result { resultCode = 0, resultMsg = "鍒涘缓鎴愬姛" };
+            Result<Empty> result = new Result<Empty> { Code = 0, Msg = "鍒涘缓鎴愬姛" };
             if (model == null)
             {
-                result.resultCode = -1;
-                result.resultMsg = "鍏ュ弬涓虹┖";
+                result.Code = -1;
+                result.Msg = "鍏ュ弬涓虹┖";
                 return result;
             }
             Location endloc = new Location();
             Location startloc = new Location();
             string cntrcode = model.CntrNo;
+            // string itemCode = "";
             var db = new SqlHelper<object>().GetInstance();
 
             if (model.DeviceNo == "1")//鍙犵洏鏈�@@ -289,9 +348,9 @@
                 var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == model.Loc).ToList();
                 if (CntrLoc.Count < 4)
                 {
-                    result.resultCode = -1;
-                    result.resultMsg = $"鏍规嵁璐т綅:{model.Loc}鑾峰彇鎵樼洏鏁伴噺灏忎簬4";
-                    LogHelper.Info($"EquipmentInfo:鏍规嵁璐т綅:{model.Loc}鑾峰彇鎵樼洏鏁伴噺灏忎簬4");
+                    result.Code = -1;
+                    result.Msg = $"鏍规嵁璐т綅:{model.Loc}鑾峰彇鎵樼洏鏁伴噺灏忎簬4";
+                    LogHelper.Info($"EquipmentInfo:{result.Msg}");
                     return result;
                 }
                 else
@@ -302,21 +361,22 @@
                 startloc = LocationHelper.GetLoc(model.Loc);
                 if (startloc == null)
                 {
-                    result.resultCode = -1;
-                    result.resultMsg = $"鏍规嵁璧风偣:{model.Loc}鏈壘鍒拌揣浣嶄俊鎭�;
-                    LogHelper.Info($"EquipmentInfo:鏍规嵁璧风偣:{model.Loc}鏈壘鍒拌揣浣嶄俊鎭�);
+                    result.Code = -1;
+                    result.Msg = $"鏍规嵁璧风偣:{model.Loc}鏈壘鍒拌揣浣嶄俊鎭�;
+                    LogHelper.Info($"EquipmentInfo:{result.Msg}");
                     return result;
                 }
 
                 #endregion
 
                 #region 璁$畻绔嬪簱缁堢偣
-                endloc = LocationHelper.InStorage(startloc);
+
+                endloc = LocationHelper.InStorage("");
                 if (endloc == null)
                 {
-                    result.resultCode = -1;
-                    result.resultMsg = $"鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌";
-                    LogHelper.Info($"EquipmentInfo:鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌");
+                    result.Code = -1;
+                    result.Msg = $"鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌";
+                    LogHelper.Info($"EquipmentInfo:{result.Msg}");
                     return result;
                 }
 
@@ -359,28 +419,37 @@
                     var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE == cntrcode).First();
                     if (CntrLoc == null)
                     {
-                        result.resultCode = -1;
-                        result.resultMsg = $"鏍规嵁鎵樼洏:{cntrcode}鏈壘鍒扮粦瀹氭墭鐩�;
-                        LogHelper.Info($"EquipmentInfo:鏍规嵁鎵樼洏:{cntrcode}鏈壘鍒扮粦瀹氭墭鐩�);
+                        result.Code = -1;
+                        result.Msg = $"鏍规嵁鎵樼洏:{cntrcode}鏈壘鍒扮粦瀹氭墭鐩�;
+                        LogHelper.Info($"EquipmentInfo:{result.Msg}");
                         return result;
                     }
                     startloc = LocationHelper.GetLoc(CntrLoc.S_LOC_CODE);
                     if (startloc == null)
                     {
-                        result.resultCode = -1;
-                        result.resultMsg = $"鏍规嵁璧风偣:{CntrLoc.S_LOC_CODE}鏈壘鍒拌揣浣嶄俊鎭�;
-                        LogHelper.Info($"EquipmentInfo:鏍规嵁璧风偣:{CntrLoc.S_LOC_CODE}鏈壘鍒拌揣浣嶄俊鎭�);
+                        result.Code = -1;
+                        result.Msg = $"鏍规嵁璧风偣:{CntrLoc.S_LOC_CODE}鏈壘鍒拌揣浣嶄俊鎭�;
+                        LogHelper.Info($"EquipmentInfo:{result.Msg}");
                         return result;
                     }
 
                     #endregion
 
                     #region 璁$畻绔嬪簱缁堢偣
-                    endloc = LocationHelper.InStorage(startloc);
+                    //鑾峰彇鎵樼洏鐗╂枡缁戝畾鍏崇郴
+                    var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == model.CntrNo).First();
+                    if (cntrItem == null)
+                    {
+                        result.Code = -1;
+                        result.Msg = $"鏍规嵁鎵樼洏:{model.CntrNo}鏈壘鍒扮墿鏂欎俊鎭�;
+                        LogHelper.Info($"EquipmentInfo:{result.Msg}");
+                        return result;
+                    }
+                    endloc = LocationHelper.InStorage(cntrItem.S_ITEM_CODE);
                     if (endloc == null)
                     {
-                        result.resultCode = -1;
-                        result.resultMsg = $"鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌";
+                        result.Code = -1;
+                        result.Msg = $"鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌";
                         LogHelper.Info($"EquipmentInfo:鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌");
                         return result;
                     }
@@ -425,17 +494,17 @@
                         var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE == cntrcode).First();
                         if (CntrLoc == null)
                         {
-                            result.resultCode = -1;
-                            result.resultMsg = $"鏍规嵁鎵樼洏:{cntrcode}鏈壘鍒扮粦瀹氭墭鐩�;
-                            LogHelper.Info($"EquipmentInfo:鏍规嵁鎵樼洏:{cntrcode}鏈壘鍒扮粦瀹氭墭鐩�);
+                            result.Code = -1;
+                            result.Msg = $"鏍规嵁鎵樼洏:{cntrcode}鏈壘鍒扮粦瀹氭墭鐩�;
+                            LogHelper.Info($"EquipmentInfo:{result.Msg}");
                             return result;
                         }
                         startloc = LocationHelper.GetLoc(CntrLoc.S_LOC_CODE);
                         if (startloc == null)
                         {
-                            result.resultCode = -1;
-                            result.resultMsg = $"鏍规嵁璧风偣:{CntrLoc.S_LOC_CODE}鏈壘鍒拌揣浣嶄俊鎭�;
-                            LogHelper.Info($"EquipmentInfo:鏍规嵁璧风偣:{CntrLoc.S_LOC_CODE}鏈壘鍒拌揣浣嶄俊鎭�);
+                            result.Code = -1;
+                            result.Msg = $"鏍规嵁璧风偣:{CntrLoc.S_LOC_CODE}鏈壘鍒拌揣浣嶄俊鎭�;
+                            LogHelper.Info($"EquipmentInfo:{result.Msg}");
                             return result;
                         }
 
@@ -447,9 +516,9 @@
                         endloc = db.Queryable<Location>().Where(a => a.S_CODE == DiePanLoc).First();
                         if (endloc == null)
                         {
-                            result.resultCode = -1;
-                            result.resultMsg = $"鏍规嵁璐т綅缂栫爜锛歿DiePanLoc}鏈壘鍒板彔鐩樿揣浣�;
-                            LogHelper.Info($"EquipmentInfo:鏍规嵁璐т綅缂栫爜锛歿DiePanLoc}鏈壘鍒板彔鐩樿揣浣�);
+                            result.Code = -1;
+                            result.Msg = $"鏍规嵁璐т綅缂栫爜锛歿DiePanLoc}鏈壘鍒板彔鐩樿揣浣�;
+                            LogHelper.Info($"EquipmentInfo:{result.Msg}");
                             return result;
                         }
                         #endregion
@@ -479,14 +548,14 @@
                                 LogHelper.Info("鍒涘缓浠诲姟鎴愬姛");
                             }
                         }
-                        
+
                         #endregion
                     }
                     else
                     {
-                        result.resultCode = -1;
-                        result.resultMsg = $"褰撳墠鍙犵洏鏈虹姸鎬佷笉灞炰簬鍙犵洏鐘舵�锛屼笉鍏佽绌烘墭鍙犳墭";
-                        LogHelper.Info($"EquipmentInfo:褰撳墠鍙犵洏鏈虹姸鎬佷笉灞炰簬鍙犵洏鐘舵�锛屼笉鍏佽绌烘墭鍙犳墭");
+                        result.Code = -1;
+                        result.Msg = $"褰撳墠鍙犵洏鏈虹姸鎬佷笉灞炰簬鍙犵洏鐘舵�锛屼笉鍏佽绌烘墭鍙犳墭";
+                        LogHelper.Info($"EquipmentInfo:{result.Msg}");
                         return result;
                     }
                 }
@@ -496,9 +565,80 @@
             return result;
         }
 
+        internal static Result<ReseltApplyDestModel> ApplyDest(ApplyDestModel model)
+        {
+            Result<ReseltApplyDestModel> result = new Result<ReseltApplyDestModel> { Code = 0, Msg = "鍒涘缓鎴愬姛" };
+            if (model == null)
+            {
+                result.Code = -1;
+                result.Msg = "鍏ュ弬涓虹┖";
+                return result;
+            }
+            var db = new SqlHelper<object>().GetInstance();
+            string ItemCode = "";
+            var task = WCSHelper.GetTask(model.TaskNo);
+            if (task != null)
+            {
+
+                //鏍规嵁浠诲姟鎵樼洏鑾峰彇鐗╂枡淇℃伅
+
+                var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == task.S_CNTR_CODE).First();
+                if (cntrItem != null)
+                {
+                    ItemCode = cntrItem.S_ITEM_CODE;
+                }
+
+                var endloc = LocationHelper.InStorage(ItemCode);
+                if (endloc != null) { 
+                    result.Data = new ReseltApplyDestModel() { Loc = endloc.S_CODE };
+                }
+                else
+                {
+                    result.Code = -1;
+                    result.Msg = "褰撳墠娌℃湁鍙敤缁堢偣鍙互鍒嗛厤";
+                    return result;
+                }
+             
+            }
+            else
+            {
+                result.Code = 1;
+                result.Msg = "浠诲姟涓嶅瓨鍦�;
+                return result;
+            }
 
 
 
+            return result;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鎵樼洏鐗╂枡淇℃伅
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        internal static Result<Empty> GetCntrInfo(GetCntrInfoModel model)
+        {
+            Result<Empty> result = new Result<Empty> { Code = 0, Msg = "鍒涘缓鎴愬姛" };
+            if (model == null)
+            {
+                result.Code = -1;
+                result.Msg = "鍏ュ弬涓虹┖";
+                return result;
+            }
+
+            var db = new SqlHelper<object>().GetInstance();
+            string cntrCode = model.CntrNo;
+
+            var CntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == cntrCode).ToList();
+            if (CntrItem.Count > 0)
+            {
+
+            }
+
+            return result;
+        }
+
         /// <summary>
         /// 缁戝畾鎵樼洏鐗╂枡  
         /// </summary>

--
Gitblit v1.9.1