From ba528c7a15058967ee3af7364035209aa0048025 Mon Sep 17 00:00:00 2001
From: lss <2538410689@qq.com>
Date: 星期一, 07 七月 2025 17:30:14 +0800
Subject: [PATCH] 测试优化

---
 HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs |  207 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 112 insertions(+), 95 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 92791ce..f382f92 100644
--- a/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs
+++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs
@@ -5,6 +5,7 @@
 using HH.WCS.DaYang.wms;
 using Newtonsoft.Json;
 using NLog.Fluent;
+using Opc.Ua;
 using SqlSugar;
 using System;
 using System.Collections.Concurrent;
@@ -159,11 +160,10 @@
                 return result;
             }
             var db = new SqlHelper<object>().GetInstance();
-            string start = model.startBit;
+            // string start = model.startBit;
             Location endloc = new Location();
             Location startloc = new Location();
             string Type = "";
-            string cntrcode = "";
             lock (lockObj)
             {
                 try
@@ -182,21 +182,7 @@
                             LogHelper.Info($"creattask:{result.Msg}");
                             return result;
                         }
-                        else
-                        {
-                            var cntr = LocationHelper.GetLocCntrRel(endloc.S_CODE).FirstOrDefault();
-                            if (cntr == null)
-                            {
-                                result.Code = -1;
-                                result.Msg = $"鏍规嵁璧风偣:{model.startBit}鏈壘鍒扮粦瀹氭墭鐩�;
-                                LogHelper.Info($"creattask:{result.Msg}");
-                                return result;
-                            }
-                            else
-                            {
-                                cntrcode = cntr.S_CNTR_CODE;
-                            }
-                        }
+
                         #endregion
 
                         #region 璁$畻绔嬪簱缁堢偣
@@ -214,15 +200,24 @@
                         #region 鍒涘缓浣滀笟
                         if (startloc != null && endloc != null)
                         {
+                            //鑾峰彇鎵樼洏
+                            var Cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == startloc.S_CODE).First();
+                            if (Cntr == null)
+                            {
+                                result.Code = -1;
+                                result.Msg = $"鏍规嵁璧风偣:{startloc.S_CODE}鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�;
+                                LogHelper.Info($"creattask:{result.Msg}");
+                                return result;
+                            }
                             //鍒涘缓浣滀笟
                             var wcsTask = new WMSTask
                             {
                                 S_CODE = WMSHelper.GenerateTaskNo(),
                                 S_TYPE = Type,
                                 N_TYPE = int.Parse(model.TaskType),
-                                S_START_LOC = start,
+                                S_START_LOC = startloc.S_CODE,
                                 S_END_LOC = endloc.S_CODE,
-                                S_CNTR_CODE = cntrcode,
+                                S_CNTR_CODE = Cntr.S_CNTR_CODE,
                                 S_END_WH = endloc.S_WH_CODE,
                                 S_START_WH = startloc.S_WH_CODE,
                                 S_START_AREA = startloc.S_AREA_CODE,
@@ -236,8 +231,8 @@
                                 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(); }
+                                var itemcntr = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == Cntr.S_CNTR_CODE).First();
+                                if (itemcntr != null) { db.Deleteable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == Cntr.S_CNTR_CODE).ExecuteCommand(); }
                                 LogHelper.Info("鍒涘缓浠诲姟鎴愬姛");
                             }
                         }
@@ -250,8 +245,8 @@
                         Type = "鍑哄簱";
 
                         #region 鑾峰彇缁堢偣淇℃伅
-                        startloc = LocationHelper.GetLoc(model.endBit);
-                        if (startloc == null)
+                        endloc = LocationHelper.GetLoc(model.endBit);
+                        if (endloc == null)
                         {
                             result.Code = -1;
                             result.Msg = $"鏍规嵁缁堢偣:{model.startBit}鏈壘鍒拌揣浣嶄俊鎭�;
@@ -262,10 +257,10 @@
 
                         #region 鏍规嵁鐗╂枡璁$畻鍑哄簱鎵樼洏锛屽厛杩涘厛鍑猴紝浼樺厛鍑哄渚�                         //鍏堣绠楀唴渚ц揣浣嶏紝鍒ゆ柇鏄惁鏈夊崟缁勬墭鐩�-                        var locations = LocationHelper.GetLocByItemCodeOrderyTime("", model.ItemCode);
-                        if (locations.Count > 0)
+                        var location = LocationHelper.GetLocByItemCodeOrderyTime("YCLLKQ", model.ItemCode);
+                        if (location != null)
                         {
-                            endloc = locations.OrderBy(a => a.N_COL).First();
+                            startloc = location;
                         }
 
                         #endregion
@@ -273,15 +268,24 @@
                         #region 鍒涘缓浣滀笟
                         if (startloc != null && endloc != null)
                         {
+                            //鑾峰彇鎵樼洏
+                            var Cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == startloc.S_CODE).First();
+                            if (Cntr == null)
+                            {
+                                result.Code = -1;
+                                result.Msg = $"鏍规嵁璧风偣:{startloc.S_CODE}鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�;
+                                LogHelper.Info($"creattask:{result.Msg}");
+                                return result;
+                            }
                             //鍒涘缓浣滀笟
                             var wcsTask = new WMSTask
                             {
                                 S_CODE = WMSHelper.GenerateTaskNo(),
                                 S_TYPE = Type,
                                 N_TYPE = int.Parse(model.TaskType),
-                                S_START_LOC = start,
+                                S_START_LOC = startloc.S_CODE,
                                 S_END_LOC = endloc.S_CODE,
-                                S_CNTR_CODE = cntrcode,
+                                S_CNTR_CODE = Cntr.S_CNTR_CODE,
                                 S_END_WH = endloc.S_WH_CODE,
                                 S_START_WH = startloc.S_WH_CODE,
                                 S_START_AREA = startloc.S_AREA_CODE,
@@ -338,76 +342,87 @@
             Location endloc = new Location();
             Location startloc = new Location();
             string cntrcode = model.CntrNo;
+            string DiePanLoc = "";
             // string itemCode = "";
             var db = new SqlHelper<object>().GetInstance();
 
             if (model.DeviceNo == "1")//鍙犵洏鏈�             {
-                #region 鑾峰彇璧风偣淇℃伅锛屽苟鍒ゆ柇绌烘墭鏄惁鍙犳弧
-                //鏍规嵁璧风偣 鑾峰彇缁戝畾鎵樼洏鏁伴噺
-                var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == model.Loc).ToList();
-                if (CntrLoc.Count < 4)
+                //鍒ゆ柇璁惧鐘舵�鏄惁灞炰簬鍙犵洏鐘舵�
+                var DeviceStatu = db.Queryable<EquipmentStatus>().Where(a => a.deviceNo == model.DeviceNo).First();
+                if (DeviceStatu != null && DeviceStatu.Status == "1")
                 {
-                    result.Code = -1;
-                    result.Msg = $"鏍规嵁璐т綅:{model.Loc}鑾峰彇鎵樼洏鏁伴噺灏忎簬4";
-                    LogHelper.Info($"EquipmentInfo:{result.Msg}");
-                    return result;
+                    #region 鑾峰彇璧风偣淇℃伅锛屽苟鍒ゆ柇绌烘墭鏄惁鍙犳弧
+                    //鏍规嵁璧风偣 鑾峰彇缁戝畾鎵樼洏鏁伴噺
+                    //var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == model.Loc).ToList();
+                    //if (CntrLoc.Count < 4)
+                    //{
+                    //    result.Code = -1;
+                    //    result.Msg = $"鏍规嵁璐т綅:{model.Loc}鑾峰彇鎵樼洏鏁伴噺灏忎簬4";
+                    //    LogHelper.Info($"EquipmentInfo:{result.Msg}");
+                    //    return result;
+                    //}
+                    //else
+                    //{
+                    //    //鎷兼帴鎵樼洏鍙�+                    //    cntrcode = CntrLoc.Select(a => a.S_CNTR_CODE).ToString();
+                    //}
+                    cntrcode = model.CntrNo;
+                    startloc = LocationHelper.GetLoc(model.Loc);
+                    if (startloc == null)
+                    {
+                        result.Code = -1;
+                        result.Msg = $"鏍规嵁璧风偣:{model.Loc}鏈壘鍒拌揣浣嶄俊鎭�;
+                        LogHelper.Info($"EquipmentInfo:{result.Msg}");
+                        return result;
+                    }
+                    #endregion
+
+                    #region 璁$畻绔嬪簱缁堢偣
+
+                    endloc = LocationHelper.InStorage("");
+                    if (endloc == null)
+                    {
+                        result.Code = -1;
+                        result.Msg = $"鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌";
+                        LogHelper.Info($"EquipmentInfo:{result.Msg}");
+                        return result;
+                    }
+
+                    #endregion
+
+                    #region 鍒涘缓浠诲姟
+                    if (startloc != null && endloc != null)
+                    {
+                        var wcsTask = new WCSTask
+                        {
+                            S_CODE = WCSHelper.GenerateTaskNo(),
+                            S_TYPE = "鍙犵洏鏈哄叆搴�,
+                            S_START_LOC = startloc.S_CODE,
+                            S_END_LOC = endloc.S_CODE,
+                            S_START_WH = startloc.S_WH_CODE,
+                            S_START_AREA = startloc.S_AREA_CODE,
+                            S_END_WH = endloc.S_WH_CODE,
+                            S_END_AREA = endloc.S_AREA_CODE,
+                            N_CNTR_COUNT = 1,
+                            N_SCHEDULE_TYPE = 2,
+                            S_CNTR_CODE = cntrcode
+                        };
+                        LogHelper.Info("鍒涘缓鍏ュ钩搴撲换鍔★細" + JsonConvert.SerializeObject(wcsTask));
+                        if (WCSHelper.CreateTask(wcsTask))
+                        {
+                            LocationHelper.LockLoc(startloc.S_CODE, 2);
+                            LocationHelper.LockLoc(endloc.S_CODE, 1);
+                            LogHelper.Info("鍒涘缓浠诲姟鎴愬姛");
+                        }
+                    }
+                    #endregion
                 }
                 else
                 {
-                    //鎷兼帴鎵樼洏鍙�-                    cntrcode = CntrLoc.Select(a => a.S_CNTR_CODE).ToString();
-                }
-                startloc = LocationHelper.GetLoc(model.Loc);
-                if (startloc == null)
-                {
-                    result.Code = -1;
-                    result.Msg = $"鏍规嵁璧风偣:{model.Loc}鏈壘鍒拌揣浣嶄俊鎭�;
-                    LogHelper.Info($"EquipmentInfo:{result.Msg}");
-                    return result;
+                   
                 }
 
-                #endregion
-
-                #region 璁$畻绔嬪簱缁堢偣
-
-                endloc = LocationHelper.InStorage("");
-                if (endloc == null)
-                {
-                    result.Code = -1;
-                    result.Msg = $"鏈绠楀埌绔嬪簱缁堢偣璐т綅锛岃妫�煡璐т綅鎯呭喌";
-                    LogHelper.Info($"EquipmentInfo:{result.Msg}");
-                    return result;
-                }
-
-                #endregion
-
-                #region 鍒涘缓浠诲姟
-                if (startloc != null && endloc != null)
-                {
-                    var wcsTask = new WCSTask
-                    {
-                        S_CODE = WCSHelper.GenerateTaskNo(),
-                        S_TYPE = "鍏ュ簱",
-                        S_START_LOC = startloc.S_CODE,
-                        S_END_LOC = endloc.S_CODE,
-                        S_START_WH = startloc.S_WH_CODE,
-                        S_START_AREA = startloc.S_AREA_CODE,
-                        S_END_WH = endloc.S_WH_CODE,
-                        S_END_AREA = endloc.S_AREA_CODE,
-                        N_CNTR_COUNT = 1,
-                        N_SCHEDULE_TYPE = 2,
-                        S_CNTR_CODE = cntrcode
-                    };
-                    LogHelper.Info("鍒涘缓鍏ュ钩搴撲换鍔★細" + JsonConvert.SerializeObject(wcsTask));
-                    if (WCSHelper.CreateTask(wcsTask))
-                    {
-                        LocationHelper.LockLoc(startloc.S_CODE, 2);
-                        LocationHelper.LockLoc(endloc.S_CODE, 1);
-                        LogHelper.Info("鍒涘缓浠诲姟鎴愬姛");
-                    }
-                }
-                #endregion
             }
             else //鍏ュ簱绌�             {
@@ -416,11 +431,12 @@
                 {
                     #region 鑾峰彇璧风偣淇℃伅
                     //鏍规嵁鎵樼洏鑾峰彇璧风偣淇℃伅
-                    var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE == cntrcode).First();
+                
+                    var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == model.Loc).First();
                     if (CntrLoc == null)
                     {
                         result.Code = -1;
-                        result.Msg = $"鏍规嵁鎵樼洏:{cntrcode}鏈壘鍒扮粦瀹氭墭鐩�;
+                        result.Msg = $"鏍规嵁璧风偣:{model.Loc}鏈壘鍒扮粦瀹氭墭鐩�;
                         LogHelper.Info($"EquipmentInfo:{result.Msg}");
                         return result;
                     }
@@ -437,7 +453,7 @@
 
                     #region 璁$畻绔嬪簱缁堢偣
                     //鑾峰彇鎵樼洏鐗╂枡缁戝畾鍏崇郴
-                    var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == model.CntrNo).First();
+                    var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == CntrLoc.S_CNTR_CODE).First();
                     if (cntrItem == null)
                     {
                         result.Code = -1;
@@ -461,7 +477,7 @@
                         var wcsTask = new WCSTask
                         {
                             S_CODE = WCSHelper.GenerateTaskNo(),
-                            S_TYPE = "鍏ュ簱",
+                            S_TYPE = "鐗╂枡鍏ュ簱",
                             S_START_LOC = startloc.S_CODE,
                             S_END_LOC = endloc.S_CODE,
                             S_START_WH = startloc.S_WH_CODE,
@@ -470,7 +486,7 @@
                             S_END_AREA = endloc.S_AREA_CODE,
                             N_CNTR_COUNT = 1,
                             N_SCHEDULE_TYPE = 2,
-                            S_CNTR_CODE = cntrcode
+                            S_CNTR_CODE = CntrLoc.S_CNTR_CODE
                         };
                         LogHelper.Info("鍒涘缓鍏ュ钩搴撲换鍔★細" + JsonConvert.SerializeObject(wcsTask));
                         if (WCSHelper.CreateTask(wcsTask))
@@ -511,7 +527,7 @@
                         #endregion
 
                         #region 鑾峰彇缁堢偣淇℃伅
-                        string DiePanLoc = "";
+
                         //鏍规嵁鎵樼洏鑾峰彇璧风偣淇℃伅
                         endloc = db.Queryable<Location>().Where(a => a.S_CODE == DiePanLoc).First();
                         if (endloc == null)
@@ -589,7 +605,8 @@
                 }
 
                 var endloc = LocationHelper.InStorage(ItemCode);
-                if (endloc != null) { 
+                if (endloc != null)
+                {
                     result.Data = new ReseltApplyDestModel() { Loc = endloc.S_CODE };
                 }
                 else
@@ -598,7 +615,7 @@
                     result.Msg = "褰撳墠娌℃湁鍙敤缁堢偣鍙互鍒嗛厤";
                     return result;
                 }
-             
+
             }
             else
             {

--
Gitblit v1.9.1