From cb58fdbdc4391136e7176210e3f1969606f11903 Mon Sep 17 00:00:00 2001
From: lss <Lss@HanInfo>
Date: 星期四, 29 五月 2025 16:52:21 +0800
Subject: [PATCH] 合肥佳通

---
 HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs |  880 ++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 514 insertions(+), 366 deletions(-)

diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
index 1e6dc8f..028afc0 100644
--- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
+++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -11,8 +11,11 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection.Emit;
+using System.ServiceModel;
 using System.Threading;
 using System.Threading.Tasks;
+using System.Web.UI.WebControls;
 using static HH.WCS.JiaTong.api.ApiModel;
 using static HH.WCS.JiaTong.api.OtherModel;
 using static HH.WCS.JiaTong.LISTA.process.HttpModel;
@@ -53,62 +56,61 @@
             try
             {
                 var db = new SqlHelper<object>().GetInstance();
+                string CntrCode = "";//鎵樼洏缂栫爜
+                string ItemCode = "";//鐗╂枡缂栫爜
+                if (partData != null)
+                {
+                    CntrCode = partData.rfid;//鎵樼洏缂栫爜
+                    ItemCode = partData.partNumber;//鐗╂枡缂栫爜
+                }
                 string Start = ""; //鍙栬揣鐐�-                string CntrCode = partData.rfid;//鎵樼洏缂栫爜
-                string ItemCode = partData.partNumber;//鐗╂枡缂栫爜
                 string End = "";
-                string areacode = "";
                 string note = ""; //绔嬪簱涓嬪彂浠诲姟闇�閫氱煡mes鎺ュ彛鐗╂枡鍒颁綅锛岀敤澶囨敞鑷姩杩涜鍖哄垎
                                   //鏍规嵁鐗╂枡鑾峰彇瀵瑰簲搴撳尯
-                #region 鏍规嵁鐗╂枡纭鍑哄簱鏉ユ簮
-                var iteminfo = db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE.Trim() == ItemCode).First();
-                if (iteminfo != null)
-                {
-                    //LogHelper.Info($"Createtask==>鐗╂枡鏁版嵁:{JsonConvert.SerializeObject(iteminfo)}");
-                    areacode = iteminfo.S_WH_CODE;
-                }
-
-                if (string.IsNullOrEmpty(areacode))
-                {
-                    LogHelper.Info($"Createtask==>鏍规嵁鐗╂枡缂栫爜:{ItemCode}鏈兘鎵惧埌鐗╂枡鏉ユ簮锛岄渶鍚屾鐗╂枡鏁版嵁");
-                    result.code = "1";
-                    result.msg = $"鏍规嵁鐗╂枡缂栫爜:{ItemCode}鏈兘鎵惧埌鐗╂枡鏉ユ簮锛岄渶鍚屾鐗╂枡鏁版嵁";
-                    AddErrorInfo("瀵绘壘鍑哄簱鍖哄け璐�, result.msg);
-                    return result;
-                }
-                //var task = db.Queryable<WCSTask>().Where(a => a.S_EQ_NO.Trim() == taskData.taskNum).First();
-                //if (task != null)
+                #region 鏍规嵁浠诲姟鏉ユ簮瀛楁鍒ゆ柇搴撳尯鏉ユ簮鏉ユ簮
+                //var iteminfo = db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE.Trim() == ItemCode).First();
+                //if (iteminfo != null)
                 //{
-                //    LogHelper.Info($"Createtask==> 浠诲姟鍙穥taskData.taskNum},璇ヤ换鍔″凡缁忓瓨鍦紝涓嶅厑璁稿垱寤轰换鍔�);
+                //    //LogHelper.Info($"Createtask==>鐗╂枡鏁版嵁:{JsonConvert.SerializeObject(iteminfo)}");
+                //    areacode = iteminfo.S_WH_CODE;
+                //}
+
+                //if (string.IsNullOrEmpty(areacode))
+                //{
+                //    LogHelper.Info($"Createtask==>鏍规嵁鐗╂枡缂栫爜:{ItemCode}鏈兘鎵惧埌鐗╂枡鏉ユ簮锛岄渶鍚屾鐗╂枡鏁版嵁");
                 //    result.code = "1";
-                //    result.msg = $"浠诲姟鍙穥taskData.taskNum},璇ヤ换鍔″凡缁忓瓨鍦紝涓嶅厑璁稿垱寤轰换鍔�;
+                //    result.msg = $"鏍规嵁鐗╂枡缂栫爜:{ItemCode}鏈兘鎵惧埌鐗╂枡鏉ユ簮锛岄渶鍚屾鐗╂枡鏁版嵁";
+                //    AddErrorInfo("瀵绘壘鍑哄簱鍖哄け璐�, result.msg);
                 //    return result;
                 //}
-                int n_type = 0;  //浠诲姟鏉ユ簮 1.閽笣绔嬪簱  2.鑳剁墖搴� 3.棰勫搴�,4.鍘熸潗鏂欏簱,閫氳繃鐗╂枡纭浠诲姟鏉ユ簮
 
-                switch (areacode)
+                int n_type = 0;  //浠诲姟鏉ユ簮 1.瀵嗙偧绔嬪簱  3.棰勫搴�,4.鍘熸潗鏂欏簱
+                string Source = "";
+                switch (taskData.source)
                 {
                     case "ML":
                         n_type = 1;
-                        break;
-                    case "JP":
-                        n_type = 2;
+                        Source = "瀵嗙偧";
                         break;
                     case "YBK":
                         n_type = 3;
+                        Source = "棰勫搴�;
                         break;
-                    case "wmwhse1":
+                    case "YCL":
                         n_type = 4;
+                        Source = "鍘熸潗鏂�;
                         break;
                 }
-                LogHelper.Info($"Createtask==>浠诲姟绫诲瀷:{n_type}");
+                Console.WriteLine($"Createtask==>浠诲姟鏉ユ簮:{n_type}");
                 if (n_type == 0)
                 {
                     result.code = "1";
-                    result.msg = $"鐗╂枡搴撳尯:{areacode}灞炰簬鏈畾涔夊簱鍖猴紝璇锋鏌ョ墿鏂欒〃閲嶆柊瀹氫箟鐗╂枡搴撳尯";
-                    AddErrorInfo("鐗╂枡搴撳尯鏈畾涔�, result.msg);
+                    result.msg = $"浠诲姟鏉ユ簮:{taskData.source}灞炰簬鏈畾涔夊簱鍖猴紝璇锋鏌ョ墿鏂欐潵婧愭槸鍚﹀睘浜庣害瀹氬瓧娈�;
+                    AddErrorInfo("浠诲姟鏉ユ簮鏈畾涔�, result.msg);
                     return result;
                 }
+
+
                 #endregion
 
                 Location endloc = new Location();
@@ -122,7 +124,7 @@
                     {
                         //鍒涘缓鎵樼洏鐗╂枡缁戝畾淇℃伅锛屽苟璁$畻缁堢偣璐т綅
                         Start = taskData.pickStation;
-                        if (CreateCntrIteminfo(Start, CntrCode, ItemCode, partData.partDesc, partData.partType, partData.lotNumber, partData.unit, partData.weight, taskData.carrierType, taskData.grade))
+                        if (CreateCntrIteminfo(partData, taskData))
                         {
                             endloc = Computeloc(CntrCode, taskData.dropStation, taskData.carrierType);
                             if (endloc != null)
@@ -133,7 +135,7 @@
                             {
                                 result.code = "1";
                                 result.msg = $"鏈哄彴缂栫爜:{taskData.dropStation}锛屾湭鎵惧埌鍙敤璐т綅";
-                                AddErrorInfo("瀵绘壘鍑哄簱璐т綅澶辫触", result.msg);
+                                AddErrorInfo("瀵绘壘鍑哄簱璐т綅澶辫触", result.msg, Source);
                                 return result;
                             }
                         }
@@ -141,20 +143,22 @@
                         {
                             result.code = "1";
                             result.msg = "鍒涘缓鎵樼洏鐗╂枡淇℃伅澶辫触";
-                            AddErrorInfo("鍒涘缓鎵樼洏澶辫触", result.msg);
+                            AddErrorInfo("鍒涘缓鎵樼洏澶辫触", result.msg, Source);
                             return result;
                         }
                     }
                     else
                     {
-                        LogHelper.Info($"Putin==> 浠诲姟璧风偣:{taskData.pickStation}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃");
+
                         result.code = "1";
                         result.msg = $"Putin==> 浠诲姟璧风偣:{taskData.pickStation}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
-                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg);
+                        LogHelper.Info($"Putin==> {result.msg}");
+                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
                     }
                 }
                 else if (taskData.taskType == 2)//鍏ュ簱娴佺▼锛岀洿鎺ヤ娇鐢ㄨ捣鐐硅揣浣嶅拰缁堢偣璐т綅鐢熸垚浠诲姟锛岃捣鐐归渶瑕佹湁鎵樼洏
                 {
+                    note = "鍏ュ簱";
                     startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                     if (startloc != null)
                     {
@@ -168,17 +172,12 @@
                         {
                             result.code = "1";
                             result.msg = $"鏍规嵁璧风偣{Start},鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�;
-                            AddErrorInfo("鎵樼洏鏌ユ壘澶辫触", result.msg);
+                            AddErrorInfo("鎵樼洏鏌ユ壘澶辫触", result.msg, Source);
                             return result;
                         }
 
                     }
-                    //鍒ゆ柇鏄惁鏄┖鎵樺洖搴�-                    var CntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == CntrCode).First();
-                    if (CntrItem == null)
-                    {
-                        note = "绌烘墭鍥炲簱";//浜曟澗绌烘墭鍥炲簱锛岄渶瑕佷笌鍙犵洏鏈哄畨鍏ㄤ氦浜�-                    }
+
                     endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
                     if (endloc != null)
                     {
@@ -188,23 +187,37 @@
                     {
                         result.code = "1";
                         result.msg = $"鏍规嵁缁堢偣{End},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
-                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg);
+                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
                         return result;
                     }
                 }
                 else if (taskData.taskType == 3)//绉诲簱娴佺▼锛岀洿鎺ヤ娇鐢ㄨ捣鐐硅揣浣嶅拰缁堢偣璐т綅鐢熸垚浠诲姟锛�                 {
+                    note = "鍑哄簱";
                     //鍒涘缓鎵樼洏鐗╂枡缁戝畾淇℃伅锛屽苟璁$畻缁堢偣璐т綅
-
                     startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                     if (startloc != null)
                     {
                         Start = taskData.pickStation;
                     }
+                    else
+                    {
+                        result.code = "1";
+                        result.msg = $"鏍规嵁璧风偣{taskData.pickStation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
+                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
+                        return result;
+                    }
                     endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
                     if (endloc != null)
                     {
                         End = taskData.dropStation;
+                    }
+                    else
+                    {
+                        result.code = "1";
+                        result.msg = $"鏍规嵁缁堢偣{taskData.dropStation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
+                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
+                        return result;
                     }
                 }
                 else if (taskData.taskType == 4)//鍘熸潗鏂欏簱闇�鍒ゆ柇鏄惁闇�鍒嗛厤鐢垫浠诲姟,鍒涘缓鍒嗘。浠诲姟
@@ -229,7 +242,7 @@
                         {
                             result.code = "1";
                             result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐�{startloc.S_AREA_CODE},缁堢偣锛歿endloc.S_AREA_CODE}鏈壘鍒板搴斿簱鍖�;
-                            AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg);
+                            AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
                             return result;
                         }
                         if (startArea.N_FLOOR == endArea.N_FLOOR)
@@ -253,7 +266,9 @@
                                 N_START_LAYER = 1,
                                 N_END_LAYER = 1,
                                 S_WMS_NO = taskData.wmsTaskNo,
-                                Z_TYPE = n_type
+                                Z_TYPE = n_type,
+
+
                             };
                             LogHelper.Info("鍒涘缓浠诲姟锛� + JsonConvert.SerializeObject(wcsTask), "CreateTask");
                             if (WCSHelper.CreateTask(wcsTask))
@@ -288,7 +303,8 @@
                                 N_START_LAYER = 1,
                                 N_END_LAYER = 1,
                                 S_WMS_NO = taskData.wmsTaskNo,
-                                Z_TYPE = n_type
+                                Z_TYPE = n_type,
+                                S_MES_NO = taskData.mesTaskNo
                             };
                             var wcsTask1 = new WCSTask
                             {
@@ -308,8 +324,8 @@
                                 S_WMS_NO = taskData.wmsTaskNo,
                                 N_START_LAYER = 1,
                                 N_END_LAYER = 1,
-                                Z_TYPE = n_type
-
+                                Z_TYPE = n_type,
+                                S_MES_NO = taskData.mesTaskNo
 
                             };
 
@@ -329,27 +345,41 @@
                         return result;
                     }
                 }
-                else if (taskData.taskType == 5)//绉诲簱娴佺▼锛岀洿鎺ヤ娇鐢ㄨ捣鐐硅揣浣嶅拰缁堢偣璐т綅鐢熸垚浠诲姟锛�+                else if (taskData.taskType == 5)//绉诲簱娴佺▼锛岀洿鎺ヤ娇鐢ㄨ捣鐐硅揣浣嶅拰缁堢偣璐т綅鐢熸垚浠诲姟锛屽苟缁戝畾鎵樼洏
                 {
                     //鍒涘缓鎵樼洏鐗╂枡缁戝畾淇℃伅锛屽苟璁$畻缁堢偣璐т綅
-                    if (CreateCntrIteminfo(taskData.pickStation, CntrCode, ItemCode, partData.partDesc, partData.partType, partData.lotNumber, partData.unit, partData.weight, taskData.carrierType, taskData.grade))
+                    if (CreateCntrIteminfo(partData, taskData))
                     {
                         startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                         if (startloc != null)
                         {
                             Start = taskData.pickStation;
                         }
+                        else
+                        {
+                            result.code = "1";
+                            result.msg = $"鏍规嵁璧风偣{taskData.pickStation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
+                            AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
+                            return result;
+                        }
                         endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
                         if (endloc != null)
                         {
                             End = taskData.dropStation;
+                        }
+                        else
+                        {
+                            result.code = "1";
+                            result.msg = $"鏍规嵁缁堢偣{taskData.dropStation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
+                            AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
+                            return result;
                         }
                     }
                     else
                     {
                         result.code = "1";
                         result.msg = "鍒涘缓鎵樼洏鐗╂枡淇℃伅澶辫触";
-                        AddErrorInfo("鍒涘缓鎵樼洏澶辫触", result.msg);
+                        AddErrorInfo("鍒涘缓鎵樼洏澶辫触", result.msg, Source);
                         return result;
                     }
 
@@ -357,6 +387,7 @@
                 //鏆傚瓨浣嶅洖搴�                 else if (taskData.taskType == 6)//鍏ュ簱娴佺▼锛岀洿鎺ヤ娇鐢ㄨ捣鐐硅揣浣嶅拰缁堢偣璐т綅鐢熸垚浠诲姟
                 {
+                    note = "鍏ュ簱";
                     //鏍规嵁鎵樼洏鍙锋壘璐т綅
                     var CntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE == partData.rfid).First();
                     if (CntrRel != null)
@@ -371,7 +402,7 @@
                         {
                             result.code = "1";
                             result.msg = $"鏍规嵁鎵樼洏{partData.rfid},鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�;
-                            AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg);
+                            AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
                             return result;
                         }
                     }
@@ -384,7 +415,7 @@
                     {
                         result.code = "1";
                         result.msg = $"鏍规嵁缁堢偣{End},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
-                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg);
+                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
                         return result;
                     }
                 }
@@ -393,7 +424,7 @@
                 {
                     note = "寮傚父搴撳尯鍏ュ簱";
                     //鍒涘缓鎵樼洏鐗╂枡缁戝畾淇℃伅锛屽苟璁$畻缁堢偣璐т綅
-                    if (CreateCntrIteminfo(taskData.pickStation, CntrCode, ItemCode, partData.partDesc, partData.partType, partData.lotNumber, partData.unit, partData.weight, taskData.carrierType, taskData.grade))
+                    if (CreateCntrIteminfo(partData, taskData))
                     {
                         startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                         if (startloc != null)
@@ -412,7 +443,7 @@
                             {
                                 result.code = "1";
                                 result.msg = $"缁堢偣搴撳尯锛歿taskData.dropStation}鏃犲彲鐢ㄨ揣浣�;
-                                AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                                AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                                 return result;
                             }
 
@@ -421,7 +452,7 @@
                         {
                             result.code = "1";
                             result.msg = $"鏍规嵁缁堢偣搴撳尯锛歿taskData.dropStation},鏈壘鍒板搴旇揣浣�;
-                            AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                            AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                             return result;
                         }
                     }
@@ -429,7 +460,7 @@
                     {
                         result.code = "1";
                         result.msg = "鍒涘缓鎵樼洏鐗╂枡淇℃伅澶辫触";
-                        AddErrorInfo("鍒涘缓鎵樼洏澶辫触", result.msg);
+                        AddErrorInfo("鍒涘缓鎵樼洏澶辫触", result.msg, Source);
                         return result;
                     }
                 }
@@ -445,7 +476,7 @@
                     {
                         result.code = "1";
                         result.msg = $"鏍规嵁璧风偣:{taskData.pickStation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
-                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg);
+                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
                         return result;
                     }
                     endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
@@ -457,7 +488,7 @@
                     {
                         result.code = "1";
                         result.msg = $"鏍规嵁缁堢偣:{End},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
-                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg);
+                        AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source);
                         return result;
                     }
                 }
@@ -466,7 +497,7 @@
                     LogHelper.Info($"Createtask==> 浠诲姟绫诲瀷鏈夎");
                     result.code = "1";
                     result.msg = "浠诲姟绫诲瀷锛歿taskData.taskType}涓嶅湪瑙勫畾鑼冨洿鍐�;
-                    AddErrorInfo("浠诲姟绫诲瀷閿欒", result.msg);
+                    AddErrorInfo("浠诲姟绫诲瀷閿欒", result.msg, Source);
                 }
                 if (taskData.taskType != 4)
                 {
@@ -509,7 +540,8 @@
                             N_START_LAYER = 1,
                             N_END_LAYER = 1,
                             S_WMS_NO = taskData.wmsTaskNo,
-                            S_NOTE = note
+                            S_NOTE = note,
+                            S_MES_NO = taskData.mesTaskNo
 
                         };
                         LogHelper.Info("鍒涘缓浠诲姟锛� + JsonConvert.SerializeObject(wcsTask), "CreateTask");
@@ -541,8 +573,6 @@
 
 
         }
-
-
 
         /// <summary>
         /// 棰勫搴撲换鍔$姸鎬佷笅鍙�@@ -602,7 +632,7 @@
                 LogHelper.Info($"AllowThrough==> 鍙傛暟涓簄ull");
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull鍊硷紝璇锋鏌ュ弬鏁版牸寮�;
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, "", model.task_no);
                 return result;
             }
 
@@ -624,7 +654,7 @@
                 {
                     result.code = "1";
                     result.msg = $"鏍规嵁涓嬪彂浠诲姟鍙穥model.task_no}鏈壘鍒板搴斾换鍔�;
-                    AddErrorInfo("鏈壘鍒颁换鍔�, result.msg);
+                    AddErrorInfo("鏈壘鍒颁换鍔�, result.msg, "", model.task_no);
                     return result;
                 }
                 return result;
@@ -657,7 +687,7 @@
             try
             {
                 //鍒涘缓鎵樼洏鏁版嵁缁戝畾鍏崇郴
-                if (ContainerHelper.CreateCntrItem(model.Rfid, model.PartNumber, model.PartDesc, model.LotNumber, model.Weight,model.Qty))
+                if (ContainerHelper.CreateCntrItem(model.Rfid, model.PartNumber, model.PartDesc, model.LotNumber, model.Weight, model.Qty, model.ProductionTime, model.MaturityTime))
                 {
                     //鍒涘缓鎴愬姛娴佺▼
                 }
@@ -665,7 +695,7 @@
                 {
                     result.code = "1";
                     result.msg = "浜у嚭淇℃伅涓嬪彂澶辫触锛屾墭鐩樼墿鏂欑粦瀹氬叧绯诲垱寤哄け璐�;
-                    AddErrorInfo("鍒涘缓缁戝畾鍏崇郴澶辫触", result.msg);
+                    AddErrorInfo("鍒涘缓缁戝畾鍏崇郴澶辫触", result.msg, "Mes");
                     return result;
                 }
                 return result;
@@ -690,31 +720,38 @@
         internal static Result Putin(Putin model, int n_type)
         {
             Result result = new Result() { code = "200", msg = "鍏ュ钩搴撲换鍔′笅鍙戞垚鍔� };
+            string Source = "Mes";
+            if (n_type == 0)
+            {
+                Source = "PDA";
+            }
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
             }
             var db = new SqlHelper<object>().GetInstance();
             Location loc = new Location();
+
             string Start = model.InitialLocation;  //璧风偣璐т綅
             string itemcode = model.PartNumber;    //鐗╂枡缂栫爜
             string areacode = "";
             try
             {
-                
+
                 #region 鍒ゆ柇鎵樼洏缁戝畾璐т綅鏄惁鍜屼笅鍙戠粦瀹氳捣鐐圭浉鍚�濡傛灉娌$粦瀹氭墭鐩樺垯缁戝畾鎵樼洏
                 var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
                 if (CntrLoc != null)
                 {
                     if (CntrLoc.S_LOC_CODE != Start)
                     {
-                        LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鎵樼洏:{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}");
+
                         result.code = "1";
                         result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}";
-                        AddErrorInfo("鎵樼洏缁戝畾浣嶇疆涓嶅悓", result.msg);
+                        LogHelper.Info($"ItemBack锛歿result.msg}");
+                        AddErrorInfo("鎵樼洏缁戝畾浣嶇疆涓嶅悓", result.msg, Source);
                         return result;
                     }
                 }
@@ -758,41 +795,49 @@
                 if (startloc != null)
                 {
                     //鏍规嵁浠撳簱 璁$畻搴撳尯
-                    if (startloc.S_WH_CODE == "101")
+                    var whcode = Settings.wareLoc.Where(a => a.AreaCode == startloc.S_WH_CODE).FirstOrDefault();
+                    if (whcode != null)
                     {
-                        areacode = "PMGQ";
+                        areacode = whcode.PMK;
                     }
                     else
                     {
-                        areacode = "PK2";
+                        result.code = "1";
+                        result.msg = $"鏍规嵁璧风偣浠撳簱缂栫爜锛歿startloc.S_WH_CODE}鏈壘鍒板搴旈厤缃枃浠�;
+                        LogHelper.Info($"Putin==> {result.msg}");
+                        AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                        return result;
                     }
-                    areacode = "FLPK";
 
                     //鍒ゆ柇鏈夋棤鐩稿悓鐗╂枡鎺�                     loc = StorageCompute(itemcode, areacode);
-                    if (loc == null)
-                    {
-                        //鏃犵浉鍚岀墿鏂欐帓鎵剧┖鎺�-                        loc = emptyRow(areacode);
-                    }
+                    //if (loc == null)
+                    //{
+                    //    //鏃犵浉鍚岀墿鏂欐帓鎵剧┖鎺�+                    //    loc = emptyRow(areacode);
+                    //}
                     if (loc != null)
                     {
                         End = loc.S_CODE;
                     }
                     else
                     {
-                        LogHelper.Info($"Putin==>搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�);
+
                         result.code = "1";
                         result.msg = $"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�;
-                        AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                        LogHelper.Info($"Putin==> {result.msg}");
+                        AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                        return result;
                     }
                 }
                 else
                 {
-                    LogHelper.Info($"Putin==> 浠诲姟璧风偣:{Start}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃");
+
                     result.code = "1";
                     result.msg = $"浠诲姟璧风偣:{Start}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
-                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
+                    LogHelper.Info($"Putin==> {result.msg}");
+                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
+                    return result;
                 }
                 #endregion
 
@@ -803,7 +848,7 @@
                     {
                         result.code = "1";
                         result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐�{Start}鏈夐攣";
-                        AddErrorInfo("璐т綅鏈夐攣", result.msg);
+                        AddErrorInfo("璐т綅鏈夐攣", result.msg, Source);
                         return result;
                     }
                     //鍒涘缓wcs浠诲姟
@@ -850,7 +895,6 @@
                 LogHelper.Error("Putin Error锛� + ex.ToString(), ex);
                 return result;
             }
-
         }
 
         /// <summary>
@@ -862,11 +906,16 @@
         internal static Result PutOut(PutOut model, int n_type)
         {
             Result result = new Result() { code = "200", msg = "鍑哄钩搴撲换鍔′笅鍙戞垚鍔� };
+            string Source = "Mes";
+            if (n_type == 0)
+            {
+                Source = "PDA";
+            }
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
             }
 
@@ -874,6 +923,7 @@
             string Start = "";
             string End = "";
             string CntrCode = "";
+
             string itemcode = model.PartNumber;
             string cntrType = "";
             string areacode = "";
@@ -885,46 +935,50 @@
 
                 #region 鏍规嵁鐗╂枡缂栫爜瑙勫垯 璁$畻鍑哄簱搴撳尯
                 //绮夋枡浠庡钩搴撳嚭搴擄紝鍏朵粬鐗╂枡闇�浠庢殏瀛樺尯鍑哄簱
-                if (model.PartNumber.StartsWith("4X"))
+                var locJt = db.Queryable<Location>().Where(a => a.S_AREA_CODE == model.WorkCenter).First();
+                if (locJt == null)
                 {
-                    areacode = "FLPK";
-                    cntrType = "PM";
+                    result.code = "1";
+                    result.msg = $"鏍规嵁鏈哄彴缂栫爜锛歿model.WorkCenter}鏈壘鍒板搴旇揣浣�;
+                    LogHelper.Info($"Putin==> {result.msg}");
+                    AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                    return result;
                 }
-                else
+                //鏍规嵁浠撳簱 璁$畻搴撳尯
+                var whcode = Settings.wareLoc.Where(a => a.AreaCode == locJt.S_WH_CODE).FirstOrDefault();
+                if (whcode != null)
                 {
-
-                    if (model.PartNumber.StartsWith("3"))
+                    if (model.PartNumber.StartsWith("4X"))
                     {
-                        cntrType = "RC";
-                        areacode = "KJZCW";
+                        areacode = whcode.PMK;
+                        cntrType = "PM";
                     }
                     else
                     {
-                        LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鐗╂枡鍙穥model.PartNumber}涓嶅睘浜庤瀹氱墿鏂�);
-                        result.code = "1";
-                        result.msg = $"鍒涘缓浠诲姟澶辫触锛岀墿鏂欏彿{model.PartNumber}涓嶅睘浜庤瀹氱墿鏂�;
-                        AddErrorInfo("鐗╂枡缂栫爜鏍煎紡閿欒", result.msg);
-                        return result;
+                        if (model.PartNumber.StartsWith("3"))
+                        {
+                            cntrType = "RC";
+                            areacode = whcode.ZCW;
+                        }
+                        else
+                        {
+
+                            result.code = "1";
+                            result.msg = $"鍒涘缓浠诲姟澶辫触锛岀墿鏂欏彿{model.PartNumber}涓嶅睘浜庤瀹氱墿鏂�;
+                            LogHelper.Info($"ItemBack锛歿result.msg}");
+                            AddErrorInfo("鐗╂枡缂栫爜鏍煎紡閿欒", result.msg, Source);
+                            return result;
+                        }
                     }
                 }
-                //鏍规嵁鐗╂枡鑾峰彇瀵瑰簲搴撳尯
-                //    var iteminfo = db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE.Trim() == itemcode).First();
-                //if (iteminfo != null)
-                //{
-                //    areacode = iteminfo.S_WH_CODE;
-                //}
-                //areacode = computeArea(itemcode);
-                //if (string.IsNullOrEmpty(areacode))
-                //{
-                //    LogHelper.Info($"PutOut==> 鏍规嵁鐗╂枡缂栫爜:{itemcode}鎵句笉鍒板搴斿簱鍖猴紝璇锋鏌ラ厤缃枃浠�);
-                //    result.code = "1";
-                //    result.msg = $"鏍规嵁鐗╂枡缂栫爜:{itemcode}鎵句笉鍒板搴斿簱鍖猴紝鐗╂枡琛ㄩ厤缃�;
-                //    AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
-                //}
-                //if (itemcode == "娴嬭瘯1")
-                //{
-                //    areacode = "PMJP";
-                //}
+                else
+                {
+                    result.code = "1";
+                    result.msg = $"鏍规嵁缁堢偣搴撳尯浠撳簱缂栫爜锛歿locJt.S_WH_CODE}鏈壘鍒板搴旈厤缃枃浠�;
+                    LogHelper.Info($"Putin==> {result.msg}");
+                    AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                    return result;
+                }
                 #endregion
 
                 #region 鏍规嵁鐗╂枡缂栫爜璁$畻鍑哄簱璐т綅锛岄�寰�嚎杈逛綅缃�@@ -942,13 +996,23 @@
                     {
                         End = Endloc.S_CODE;
                     }
+                    else
+                    {
+                        result.code = "1";
+                        result.msg = $"Computeloc==銆嬫牴鎹満鍙扮紪鐮侊細{model.WorkCenter},宸ヨ绫诲瀷锛歿cntrType} 鏈壘鍒扮┖璐т綅鏁版嵁锛岃妫�煡璐т綅琛�;
+                        LogHelper.Info($"ItemBack锛歿result.msg}");
+                        AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                        return result;
+                    }
                 }
                 else
                 {
-                    LogHelper.Info($"PutOut==> 浠诲姟鐗╂枡:{itemcode}鎵句笉鍒板搴斿簱瀛�);
+
                     result.code = "1";
                     result.msg = $"浠诲姟鐗╂枡:{itemcode}鎵句笉鍒板搴斿簱瀛�;
-                    AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                    LogHelper.Info($"ItemBack锛歿result.msg}");
+                    AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                    return result;
                 }
                 #endregion
 
@@ -959,7 +1023,7 @@
                     {
                         result.code = "1";
                         result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐箋Start}鏈夐攣";
-                        AddErrorInfo("璐т綅鏈夐攣", result.msg);
+                        AddErrorInfo("璐т綅鏈夐攣", result.msg, Source);
                         return result;
                     }
                     //鍒涘缓wcs浠诲姟
@@ -1017,11 +1081,12 @@
         internal static Result Empty(Empty model)
         {
             Result result = new Result() { code = "200", msg = "绌哄伐瑁呭洖搴撲换鍔′笅鍙戞垚鍔� };
+            string Source = "MES";
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
             }
 
@@ -1039,26 +1104,26 @@
             try
             {
                 #region 鍒ゆ柇鎵樼洏缁戝畾璐т綅鏄惁鍜屼笅鍙戠粦瀹氳捣鐐圭浉鍚�-                var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
-                if (CntrLoc != null)
-                {
-                    if (CntrLoc.S_LOC_CODE != Start)
-                    {
-                        LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鎵樼洏:{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}");
-                        result.code = "1";
-                        result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}";
-                        AddErrorInfo("鎵樼洏缁戝畾浣嶇疆涓嶅悓", result.msg);
-                        return result;
-                    }
-                }
-                else
-                {
-                    LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鎵樼洏:{model.Rfid}鏈壘鍒扮粦瀹氳揣浣�);
-                    result.code = "1";
-                    result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}鏈壘鍒扮粦瀹氳揣浣�;
-                    AddErrorInfo("鏌ユ壘鎵樼洏璐т綅澶辫触", result.msg);
-                    return result;
-                }
+                //var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
+                //if (CntrLoc != null)
+                //{
+                //    if (CntrLoc.S_LOC_CODE != Start)
+                //    {
+                //        LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鎵樼洏:{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}");
+                //        result.code = "1";
+                //        result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}";
+                //        AddErrorInfo("鎵樼洏缁戝畾浣嶇疆涓嶅悓", result.msg);
+                //        return result;
+                //    }
+                //}
+                //else
+                //{
+                //    LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鎵樼洏:{model.Rfid}鏈壘鍒扮粦瀹氳揣浣�);
+                //    result.code = "1";
+                //    result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}鏈壘鍒扮粦瀹氳揣浣�;
+                //    AddErrorInfo("鏌ユ壘鎵樼洏璐т綅澶辫触", result.msg);
+                //    return result;
+                //}
                 #endregion
 
                 #region 鏍规嵁璐т綅妤煎眰鍒ゆ柇锛�妤煎幓寰�彔鐩樹綅 鍏朵粬鐨勫洖搴�@@ -1077,7 +1142,7 @@
                             {
                                 result.code = "1";
                                 result.msg = $"鍙犵洏璐т綅涓嶅彲鐢�;
-                                AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                                AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                                 return result;
                             }
                             else
@@ -1087,14 +1152,15 @@
                         }
                         else
                         {
-                            LogHelper.Info($"鏍规嵁璐т綅澶囨敞锛氬彔鐩橈紝璐т綅妤煎眰:{startloc.N_LAYER},璐т綅浠撳簱:{startloc.S_WH_CODE}锛屾壘涓嶅埌鍙犵洏璐т綅");
+
                             result.code = "1";
                             result.msg = $"鍙犵洏璐т綅涓嶅彲鐢�;
-                            AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
+                            LogHelper.Info($"鏍规嵁璐т綅澶囨敞锛氬彔鐩橈紝璐т綅妤煎眰:{startloc.N_LAYER},璐т綅浠撳簱:{startloc.S_WH_CODE}锛屾壘涓嶅埌鍙犵洏璐т綅");
+                            AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
                             return result;
                         }
                     }
-                    else if (startloc.S_NOTE == "PM")
+                    else if (startloc.S_NOTE == "PB")
                     {
                         //鎵惧潡鑳跺爢鍙犲尯
                         var KjDploc = db.Queryable<Location>().Where(a => a.S_NOTE.Trim() == "鐗囪兌鍫嗗彔浣� && a.S_WH_CODE.Trim() == startloc.S_WH_CODE).ToList();
@@ -1105,7 +1171,7 @@
                             {
                                 result.code = "1";
                                 result.msg = $"鍙犵洏璐т綅涓嶅彲鐢�;
-                                AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                                AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                                 return result;
                             }
                             else
@@ -1118,80 +1184,72 @@
                             LogHelper.Info($"鏍规嵁璐т綅澶囨敞锛氱墖鑳跺爢鍙犱綅,璐т綅浠撳簱:{startloc.S_WH_CODE}锛屾壘涓嶅埌鍙犵洏璐т綅");
                             result.code = "1";
                             result.msg = $"鍙犵洏璐т綅涓嶅彲鐢�;
-                            AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
+                            AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
                             return result;
                         }
                     }
                     else
                     {
-                        #region 鏍规嵁鎵樼洏鎵惧懠鍙┖鎵樹换鍔★紝骞惰幏寰楀嚭搴撳簱鍖�-                        msts = WCSHelper.GetTaskBycntrcode(model.Rfid.Trim());
-                        if (msts.Count() > 0)
+                        #region 鏍规嵁璧风偣璐т綅绫诲瀷锛岃幏寰楀洖搴撳簱鍖�+                        //鏍规嵁浠撳簱 璁$畻搴撳尯
+                        var whcode = Settings.wareLoc.Where(a => a.AreaCode == startloc.S_WH_CODE).FirstOrDefault();
+                        if (whcode != null)
                         {
-                            msts.RemoveAll(a => string.IsNullOrEmpty(a.S_CNTR_CODE));
-                            mst = msts.OrderByDescending(a => a.T_CREATE).FirstOrDefault();
-                        }
-                        if (mst != null)
-                        {
-                            LogHelper.Info($"鎵惧埌鍑哄簱浠诲姟锛歿JsonConvert.SerializeObject(mst)}");
-                            areacode = mst.S_START_AREA;
+                            if (startloc.S_NOTE == "PM" || string.IsNullOrEmpty(startloc.S_NOTE))
+                            {
+                                areacode = whcode.PMK;
+                            }
                         }
                         else
                         {
-                            LogHelper.Info($"鍒涘缓浠诲姟澶辫触锛屾牴鎹墭鐩樼紪鐮亄model.Rfid}鏈壘鍒版墭鐩樺嚭搴撲换鍔�);
                             result.code = "1";
-                            result.msg = $"鍒涘缓浠诲姟澶辫触锛屾牴鎹墭鐩樼紪鐮亄model.Rfid}鏈壘鍒版墭鐩樺嚭搴撲换鍔�;
-                            AddErrorInfo("鏌ユ壘浠诲姟澶辫触", result.msg);
-                            return result;
-                        }
-                        if (string.IsNullOrEmpty(areacode))
-                        {
-                            LogHelper.Info($"鍒涘缓浠诲姟澶辫触锛屾牴鎹墭鐩樼紪鐮亄model.Rfid}鎵惧埌鍑哄簱浠诲姟{mst.S_CODE}鐨勮捣鐐瑰簱鍖轰负绌�);
-                            result.code = "1";
-                            result.msg = $"鍒涘缓浠诲姟澶辫触锛屾牴鎹墭鐩樼紪鐮亄model.Rfid}鎵惧埌鍑哄簱浠诲姟{mst.S_CODE}鐨勮捣鐐瑰簱鍖轰负绌�;
-                            AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                            result.msg = $"鏍规嵁璧风偣浠撳簱缂栫爜锛歿startloc.S_WH_CODE}鏈壘鍒板搴旈厤缃枃浠�;
+                            LogHelper.Info($"Putin==> {result.msg}");
+                            AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                             return result;
                         }
                         #endregion
 
                         //鍥炲簱璐т綅璁$畻搴撳尯璐т綅
                         loc = StorageCompute(itemcode, areacode);
-                        if (loc == null)
-                        {
-                            loc = emptyRow(areacode);
-                            if (loc == null)
-                            {
-                                LogHelper.Info($"搴撳尯锛歿areacode}娌℃湁绌烘帓");
-                            }
-                        }
-                        else
-                        {
-                            LogHelper.Info($"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�);
-                            result.code = "1";
-                            result.msg = $"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�;
-                            AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
-                            return result;
-                        }
+                        //if (loc == null)
+                        //{
+                        //    loc = emptyRow(areacode);
+                        //    if (loc == null)
+                        //    {
+                        //        LogHelper.Info($"搴撳尯锛歿areacode}娌℃湁绌烘帓");
+                        //    }
+                        //}
+                        //else
+                        //{
+
+                        //    result.code = "1";
+                        //    result.msg = $"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�;
+                        //    LogHelper.Info($"{result.msg}");
+                        //    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
+                        //    return result;
+                        //}
                     }
 
                 }
                 else
                 {
-                    LogHelper.Info($"Empty==> 浠诲姟璧风偣:{Start}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃");
+
                     result.code = "1";
                     result.msg = $"Empty==> 浠诲姟璧风偣:{Start}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
-                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
+                    LogHelper.Info($"{result.msg}");
+                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
                     return result;
                 }
                 #endregion
 
                 #region 鍒涘缓浠诲姟
-                if (!string.IsNullOrEmpty(Start) && loc != null)
+                if (startloc != null && loc != null)
                 {
-                    if (startloc.N_LOCK_STATE != 0)
+                    if (startloc.N_LOCK_STATE != 0 && loc.N_LOCK_STATE != 0)
                     {
                         result.code = "1";
-                        result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐箋Start}鏈夐攣";
+                        result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐硅揣浣嶇姸鎬亄startloc.N_LOCK_STATE},璧风偣璐т綅鐘舵�锛歿loc.N_LOCK_STATE}";
                         AddErrorInfo("璐т綅鏈夐攣", result.msg);
                         return result;
                     }
@@ -1201,7 +1259,7 @@
                         S_CODE = WCSHelper.GenerateTaskNo(),
                         S_TYPE = "绌哄伐瑁呭洖搴�,
                         S_EQ_NO = model.TaskNumber,
-                        S_START_LOC = Start,
+                        S_START_LOC = startloc.S_CODE,
                         S_END_LOC = loc.S_CODE,
                         S_START_WH = startloc.S_WH_CODE,
                         S_START_AREA = startloc.S_AREA_CODE,
@@ -1217,7 +1275,7 @@
                     LogHelper.Info("鍒涘缓鍑哄钩搴撲换鍔★細" + JsonConvert.SerializeObject(wcsTask));
                     if (WCSHelper.CreateTask(wcsTask))
                     {
-                        LocationHelper.LockLoc(Start, 2);
+                        LocationHelper.LockLoc(startloc.S_CODE, 2);
                         LocationHelper.LockLoc(loc.S_CODE, 1);
                         //  绌烘墭鍥炲簱鍒ゆ柇鎵樼洏鏈夋棤缁戝畾鐗╂枡淇℃伅 濡傛灉鏈夊垯鍒犻櫎
                         var itemcntr = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
@@ -1253,11 +1311,12 @@
         {
             var db = new SqlHelper<object>().GetInstance();
             Result result = new Result() { code = "200", msg = "绌哄伐瑁呭懠鍙换鍔′笅鍙戞垚鍔� };
+            string Source = "MES";
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
             }
 
@@ -1274,21 +1333,27 @@
             {
                 #region 鏍规嵁浠撳簱缂栫爜鍒ゆ柇搴撳尯 骞惰绠楀嚭搴撹揣浣�                 var endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == End).First();
+                //鏍规嵁浠撳簱 璁$畻搴撳尯
+
                 if (endloc != null)
                 {
-                    if (endloc.S_WH_CODE == "101")
+                    var whcode = Settings.wareLoc.Where(a => a.AreaCode == endloc.S_WH_CODE).FirstOrDefault();
+                    if (whcode != null)
                     {
-                        // itemcode = "TP";
-                        areacode = "PMGQ";
+                        areacode = whcode.PMK;
                     }
                     else
                     {
-                        //itemcode = "TP";
-                        areacode = "PK2";
+                        result.code = "1";
+                        result.msg = $"鏍规嵁璧风偣浠撳簱缂栫爜锛歿endloc.S_WH_CODE}鏈壘鍒板搴旈厤缃枃浠�;
+                        LogHelper.Info($"Putin==> {result.msg}");
+                        AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                        return result;
                     }
-                    areacode = "FLPK";
+
+
                     //璁$畻鍑哄簱鎵樼洏
-                    startloc = airlift(areacode, itemcode);
+                    startloc = LocationHelper.GetLocByAreacode(areacode);
                     if (startloc != null)
                     {
                         var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == startloc.S_CODE).First();
@@ -1299,10 +1364,10 @@
                         }
                         else
                         {
-                            LogHelper.Info($"callfixture:鍒涘缓绌哄伐瑁呭懠鍙换鍔�=>鏍规嵁璐т綅{endloc.S_CODE}鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�);
                             result.code = "1";
                             result.msg = $"鍒涘缓绌哄伐瑁呭懠鍙换鍔�=>鏍规嵁璐т綅{endloc.S_CODE}鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�;
-                            AddErrorInfo("鏌ユ壘鎵樼洏澶辫触", result.msg);
+                            LogHelper.Info($"callfixture:{result.msg}");
+                            AddErrorInfo("鏌ユ壘鎵樼洏澶辫触", result.msg, Source);
                             return result;
                         }
 
@@ -1311,11 +1376,12 @@
                 }
                 else
                 {
-                    LogHelper.Info($"callfixture==> 浠诲姟璧风偣:{End}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃");
+
                     result.code = "1";
                     result.msg = $"浠诲姟璧风偣:{End}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
-                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
-
+                    LogHelper.Info($"callfixture:{result.msg}");
+                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
+                    return result;
                 }
                 #endregion
 
@@ -1387,11 +1453,12 @@
         internal static Result ItemBack(ItemBack model)
         {
             Result result = new Result() { code = "200", msg = "浣欐枡杩斿洖浠诲姟涓嬪彂鎴愬姛" };
+            string Source = "MES";
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
 
             }
@@ -1409,28 +1476,7 @@
 
             try
             {
-                #region 鍒ゆ柇鎵樼洏缁戝畾璐т綅鏄惁鍜屼笅鍙戠粦瀹氳捣鐐圭浉鍚�-                var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
-                if (CntrLoc != null)
-                {
-                    if (CntrLoc.S_LOC_CODE != Start)
-                    {
-                        LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鎵樼洏:{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}");
-                        result.code = "1";
-                        result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}";
-                        AddErrorInfo("鎵樼洏缁戝畾浣嶇疆涓嶅悓", result.msg);
-                        return result;
-                    }
-                }
-                else
-                {
-                    LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鎵樼洏:{model.Rfid}鏈壘鍒扮粦瀹氳揣浣�);
-                    result.code = "1";
-                    result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}鏈壘鍒扮粦瀹氳揣浣�;
-                    AddErrorInfo("鏌ユ壘鎵樼洏璐т綅澶辫触", result.msg);
-                    return result;
-                }
-                #endregion
+
 
                 #region 浣欐枡杩斿洖鏍规嵁鎵樼洏鎵惧嚭搴撲换鍔�                 //浣欐枡杩斿洖鏍规嵁鎵樼洏鎵惧嚭搴撲换鍔�@@ -1465,79 +1511,120 @@
                 var startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == Start).First();
                 if (startloc != null)
                 {
-                    //绮夋枡鐩存帴鍥炲簱锛屽叾浠栫墿鏂欓渶瑕佸幓瀵瑰簲鐨勬殏瀛樺尯
-                    if (model.PartNumber.StartsWith("4X"))
+                    var whcode = Settings.wareLoc.Where(a => a.AreaCode == startloc.S_WH_CODE).FirstOrDefault();
+                    if (whcode != null)
                     {
-                        areacode = "FLPK";
-                        loc = StorageCompute(itemcode, areacode);
-                        if (loc == null)
+                        //绮夋枡鐩存帴鍥炲簱锛屽叾浠栫墿鏂欓渶瑕佸幓瀵瑰簲鐨勬殏瀛樺尯
+                        if (model.PartNumber.StartsWith("4X"))
                         {
-                            loc = emptyRow(areacode);
-                        }
-                    }
-                    else
-                    {
-                        if (model.PartNumber.StartsWith("3"))
-                        {
-                            areacode = "KJYLZCW";
+                            areacode = whcode.PMK;
+                            loc = StorageCompute(itemcode, areacode);
+                            //if (loc == null)
+                            //{
+                            //    loc = emptyRow(areacode);
+                            //}
                         }
                         else
                         {
-                            LogHelper.Info($"ItemBack锛氬垱寤轰换鍔″け璐ワ紝鐗╂枡鍙穥model.PartNumber}涓嶅睘浜庤瀹氱墿鏂�);
-                            result.code = "1";
-                            result.msg = $"鍒涘缓浠诲姟澶辫触锛岀墿鏂欏彿{model.PartNumber}涓嶅睘浜庤瀹氱墿鏂�;
-                            AddErrorInfo("鐗╂枡缂栫爜鏍煎紡閿欒", result.msg);
-                            return result;
-                        }
-                        var EndLocs = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == areacode).ToList();
-                        if (EndLocs.Count > 0)
-                        {
-                            loc = EndLocs.Find(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0);
-                            if (loc != null)
+                            #region 鍒ゆ柇鎵樼洏缁戝畾璐т綅鏄惁鍜屼笅鍙戠粦瀹氳捣鐐圭浉鍚�+                            var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
+                            if (CntrLoc != null)
                             {
-                                End = loc.S_CODE;
+                                if (CntrLoc.S_LOC_CODE != Start)
+                                {
+
+                                    result.code = "1";
+                                    result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}缁戝畾浣嶇疆涓嶆槸璧风偣锛歿Start}";
+                                    LogHelper.Info($"ItemBack锛歿result.msg}");
+                                    AddErrorInfo("鎵樼洏缁戝畾浣嶇疆涓嶅悓", result.msg, Source);
+                                    return result;
+                                }
+                            }
+                            else
+                            {
+
+                                result.code = "1";
+                                result.msg = $"鍒涘缓浠诲姟澶辫触锛屾墭鐩�{model.Rfid}鏈壘鍒扮粦瀹氳揣浣�;
+                                LogHelper.Info($"ItemBack锛歿result.msg}");
+                                AddErrorInfo("鏌ユ壘鎵樼洏璐т綅澶辫触", result.msg, Source);
+                                return result;
+                            }
+                            #endregion
+
+                            if (model.PartNumber.StartsWith("3"))
+                            {
+                                areacode = whcode.ZCW;
+                            }
+                            else
+                            {
+
+                                result.code = "1";
+                                result.msg = $"鍒涘缓浠诲姟澶辫触锛岀墿鏂欏彿{model.PartNumber}涓嶅睘浜庤瀹氱墿鏂�;
+                                LogHelper.Info($"ItemBack锛歿result.msg}");
+                                AddErrorInfo("鐗╂枡缂栫爜鏍煎紡閿欒", result.msg, Source);
+                                return result;
+                            }
+                            var EndLocs = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == areacode).ToList();
+                            if (EndLocs.Count > 0)
+                            {
+                                //loc =  EndLocs.Find(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0);
+                                loc = FindEndcolByLocList(EndLocs);
+                                if (loc != null)
+                                {
+                                    End = loc.S_CODE;
+                                }
+                                else
+                                {
+                                    result.code = "1";
+                                    result.msg = $"缁堢偣搴撳尯锛歿areacode}鏃犲彲鐢ㄨ揣浣�;
+                                    AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                                    return result;
+                                }
+
                             }
                             else
                             {
                                 result.code = "1";
-                                result.msg = $"缁堢偣搴撳尯锛歿areacode}鏃犲彲鐢ㄨ揣浣�;
-                                AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                                result.msg = $"鏍规嵁缁堢偣搴撳尯锛歿areacode},鏈壘鍒板搴旇揣浣�;
+                                AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                                 return result;
                             }
-
+                            //loc = StorageCompute(itemcode, areacode);
+                            //if (loc == null)
+                            //{
+                            //    loc = emptyRow(areacode);
+                            //}
+                        }
+                        if (loc != null)
+                        {
+                            End = loc.S_CODE;
                         }
                         else
                         {
+
                             result.code = "1";
-                            result.msg = $"鏍规嵁缁堢偣搴撳尯锛歿areacode},鏈壘鍒板搴旇揣浣�;
-                            AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg);
+                            result.msg = $"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�;
+                            AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
                             return result;
                         }
-                        //loc = StorageCompute(itemcode, areacode);
-                        //if (loc == null)
-                        //{
-                        //    loc = emptyRow(areacode);
-                        //}
-                    }
-                    if (loc != null)
-                    {
-                        End = loc.S_CODE;
                     }
                     else
                     {
-                        LogHelper.Info($"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�);
+
                         result.code = "1";
-                        result.msg = $"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�;
-                        AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
+                        result.msg = $"鏍规嵁璧风偣浠撳簱缂栫爜锛歿startloc.S_WH_CODE}鏈壘鍒板搴旈厤缃枃浠�;
+                        LogHelper.Info($"Putin==> {result.msg}");
+                        AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                         return result;
                     }
+
                 }
                 else
                 {
-                    LogHelper.Info($"璐т綅:{Start}鎵句笉鍒板搴旇揣浣�);
+
                     result.code = "1";
                     result.msg = $"璐т綅:{Start}鎵句笉鍒板搴旇揣浣�;
-                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
+                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
                     return result;
                 }
 
@@ -1627,11 +1714,12 @@
                 msg = "绾胯竟搴撳瓨鏌ヨ鎴愬姛"
 
             };
+            string Source = "MES";
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
 
             }
@@ -1678,11 +1766,12 @@
         internal static Result add(add model)
         {
             Result result = new Result() { code = "200", msg = "鐗╂枡涓绘暟鎹垱寤烘垚鍔� };
+            string Source = "MES";
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
             }
             try
@@ -1691,24 +1780,27 @@
                 if (db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE == model.PartNumber).Count() > 0)
                 {
                     result.code = "1";
-                    result.msg = "鐗╂枡涓绘暟鎹凡瀛樺湪";
-                    AddErrorInfo("鐗╂枡涓绘暟鎹凡瀛樺湪", result.msg);
+                    result.msg = $"鐗╂枡缂栫爜:{model.PartNumber}鐨勭墿鏂欎富鏁版嵁宸插瓨鍦�;
+                    //  AddErrorInfo("鐗╂枡涓绘暟鎹凡瀛樺湪", result.msg, Source);
+                    LogHelper.Info($"add:{result.msg}");
                     return result;
                 }
                 TN_Material itemInfo = new TN_Material();
                 itemInfo.S_ITEM_CODE = model.PartNumber;
                 itemInfo.ITEM_TYPE = model.PartClass;
                 itemInfo.S_ITEM_NAME = model.PartDesc;
-                itemInfo.REMARK1 = model.StewingTime.ToString("yyyy-MM-dd");
-                itemInfo.REMARK2 = model.OverdueTime.ToString("yyyy-MM-dd");
+                itemInfo.REMARK1 = model.StewingTime;
+                itemInfo.REMARK2 = model.OverdueTime;
                 itemInfo.S_MP_TYPE = model.Unit;
-
-                db.Insertable<TN_Material>(itemInfo).ExecuteCommand();
+                if (db.Insertable<TN_Material>(itemInfo).ExecuteCommand() > 0)
+                {
+                    LogHelper.Info($"add:鐗╂枡缂栫爜:{model.PartNumber}鐨勭墿鏂欎富鏁版嵁宸插悓姝�);
+                }
+                ;
                 return result;
             }
             catch (Exception ex)
             {
-
                 result.code = "1";
                 result.msg = $"鐗╂枡涓绘暟鎹垱寤哄け璐�閿欒淇℃伅锛歿ex}";
                 LogHelper.Error("add Error锛� + ex.ToString(), ex);
@@ -1724,11 +1816,12 @@
         internal static Result CreatTask(CreatTask model)
         {
             Result result = new Result() { code = "200", msg = "鐐瑰鐐逛换鍔″垱寤烘垚鍔� };
+            string Source = "MES";
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
             }
             string Start = ""; //鍙栬揣鐐�@@ -1754,7 +1847,7 @@
                     {
                         result.code = "1";
                         result.msg = $"鍒涘缓浠诲姟澶辫触锛屾牴鎹捣鐐箋model.InitialLocation}鏈壘鍒板搴旇揣浣嶇粦瀹氭墭鐩樻墭鐩�;
-                        AddErrorInfo("鏌ユ壘鎵樼洏澶辫触", result.msg);
+                        AddErrorInfo("鏌ユ壘鎵樼洏澶辫触", result.msg, Source);
                         return result;
                     }
                 }
@@ -1832,11 +1925,12 @@
         internal static Result CreatelevatorTask(Elevator model)
         {
             Result result = new Result() { code = "200", msg = "鐐瑰鐐逛换鍔″垱寤烘垚鍔� };
+            string Source = "MES";
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
             }
 
@@ -1856,17 +1950,18 @@
                     {
                         result.code = "1";
                         result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐箋startloc.S_CODE}鏈夐攣";
-                        AddErrorInfo("璐т綅鏈夐攣", result.msg);
+                        AddErrorInfo("璐т綅鏈夐攣", result.msg, Source);
                         return result;
                     }
 
                     var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == startloc.S_CODE).First();
                     if (cntr == null)
                     {
-                        LogHelper.Info($"callfixture:鍒涘缓绌哄伐瑁呭懠鍙换鍔�=>鏍规嵁璐т綅{endloc.S_CODE}鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�);
+
                         result.code = "1";
                         result.msg = $"璧风偣{model.Data.start_loc_code}鏈煡璇㈢粦瀹氭墭鐩�;
-                        AddErrorInfo("鏌ユ壘鎵樼洏澶辫触", result.msg);
+                        LogHelper.Info($"callfixture:鍒涘缓绌哄伐瑁呭懠鍙换鍔�=>{result.msg}");
+                        AddErrorInfo("鏌ユ壘鎵樼洏澶辫触", result.msg, Source);
                         return result;
                     }
 
@@ -1880,7 +1975,7 @@
                     {
                         result.code = "1";
                         result.msg = $"鍒涘缓浠诲姟澶辫触锛屾牴鎹揣浣嶇紪鐮�{dtcode}鏈壘鍒扮數姊揣浣�;
-                        AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
+                        AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
                         return result;
                     }
 
@@ -1953,8 +2048,6 @@
 
         }
 
-
-
         /// <summary>
         /// 璐т綅淇℃伅涓婁紶
         /// </summary>
@@ -1964,6 +2057,7 @@
         {
 
             Result result = new Result() { code = "200", msg = "璐т綅淇℃伅涓婁紶鎴愬姛" };
+            String Source = "MES";
             RequestList<UploadLoc> result1 = new RequestList<UploadLoc>();
             List<UploadLoc> listuploadloc = new List<UploadLoc>();
             var db = new SqlHelper<object>().GetInstance();
@@ -1987,7 +2081,7 @@
                 {
                     result.code = "1";
                     result.msg = $"璐т綅涓婁紶澶辫触锛屾牴鎹揣浣嶇紪鐮亄item.Location}鏈壘鍒板搴旂殑璐т綅淇℃伅";
-                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg);
+                    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
                     return result;
                 }
             }
@@ -2018,11 +2112,27 @@
                 LogHelper.Info($"鐗╂枡鍒颁綅鍥炴姤澶辫触=>鍥炴姤鍦板潃娌℃湁閰嶇疆");
                 result.code = "1";
                 result.msg = $"鐗╂枡鍒颁綅鍥炴姤澶辫触=>鍥炴姤鍦板潃娌℃湁閰嶇疆";
-                AddErrorInfo("鍦板潃閿欒", result.msg);
+                AddErrorInfo("鍦板潃閿欒", result.msg, Source);
             }
             return result;
         }
+        internal static DeviceInfoModel Device()
+        {
 
+            DeviceInfoModel device = new DeviceInfoModel();
+
+            List<DeviceInfos> deviceInfos = new List<DeviceInfos>();//鍙犵洏鏈烘姤閿欎俊鎭�+            AgvInfos gvInfos = new AgvInfos();//agv鎶ラ敊淇℃伅
+            //鑾峰彇鍐呭瓨涓彔鐩樻満鐨勬姤閿欎俊鎭�+            foreach (var dpjInfo in DeviceProcess.DpjInfoDirectory)
+            {
+                deviceInfos.Add(new DeviceInfos() { Device = dpjInfo.Value.DeviceName, DeviceInfo = dpjInfo.Value.ErrorInfo });
+            }
+            device.DeviceInfos = deviceInfos;
+
+
+            return device;
+        }
 
         /// <summary>
         /// 搴撲綅娓呯┖
@@ -2032,11 +2142,12 @@
         internal static Result ClearLoc(ClearTask model)
         {
             Result result = new Result() { code = "200", msg = "搴撲綅娓呴櫎鎴愬姛" };
+            string Source = "MES";
             if (model == null)
             {
                 result.code = "1";
                 result.msg = "鍙傛暟涓簄ull";
-                AddErrorInfo("鍙傛暟涓虹┖", result.msg);
+                AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source);
                 return result;
             }
             string loc = model.LocationNum;
@@ -2056,8 +2167,8 @@
                         if (CntrItem != null)
                         {
 
-                            LocationHelper.UnBindingLoc(loc, new List<string>() { "cntrcode" });
-                            //  db.Deleteable<LocCntrRel>().Where(it => it.S_LOC_CODE.Trim() == loc).ExecuteCommand();
+                            LocationHelper.UnBindingLoc(loc, new List<string>() { cntrcode });
+                            // db.Deleteable<LocCntrRel>().Where(it => it.S_LOC_CODE.Trim() == loc).ExecuteCommand();
                             db.Deleteable<CntrItemDetail>().Where(it => it.S_CNTR_CODE.Trim() == cntrcode).ExecuteCommand();
 
                         }
@@ -2076,7 +2187,7 @@
                 {
                     result.code = "1";
                     result.msg = $"鏍规嵁璐т綅:{loc}鎵句笉鍒拌揣浣嶅叧绯�;
-                    AddErrorInfo("璐т綅涓虹┖", result.msg);
+                    AddErrorInfo("璐т綅涓虹┖", result.msg, Source);
                     return result;
                 }
             }
@@ -2105,51 +2216,52 @@
         internal static Location StorageCompute(string itemcode, string areacode)
         {
             var db = new SqlHelper<object>().GetInstance();
-            Location result = null;
-            //鏌ヨ鎵�湁鏈夋墭鐩樼殑鎺�-            var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM > 0 && a.S_AREA_CODE.Trim() == areacode).OrderByDescending(a => a.N_COL).Take(1).PartitionBy(a => a.N_ROW).ToList();
-            if (list.Count > 0)
-            {
-                for (int i = 0; i < list.Count; i++)
-                {
-                    LogHelper.Info($"鏈夋墭鐩樻帓鍙穥list[i].N_ROW}锛岀墿鏂欑紪鐮亄itemcode},搴撳尯{areacode}");
-                    //鍒ゆ柇鎵樼洏鐗╂枡鏄惁鐩稿悓鐗╂枡淇℃伅鐩稿悓
-                    var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == list[i].S_CODE).First();
-                    if (cntr != null)
-                    {
-                        if (string.IsNullOrEmpty(itemcode))//绌烘墭鍏ュ簱
-                        {
-                            var iteminfo = ContainerHelper.GetCntrItemRel(cntr.S_CNTR_CODE).FirstOrDefault();
-                            if (iteminfo == null)
-                            {
-                                //鐗╂枡鐩稿悓鍏ヨ揣浣嶅悗涓�綅璐т綅
-                                result = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => a.S_AREA_CODE.Trim() == areacode && a.N_ROW == list[i].N_ROW && a.N_COL > list[i].N_COL).First();
-                            }
-                        }
-                        else//婊℃嫋鍏ュ簱
-                        {
-                            var iteminfo = ContainerHelper.GetCntrItemRel(cntr.S_CNTR_CODE).FirstOrDefault();
-                            if (iteminfo != null)
-                            {
-                                if (iteminfo.S_ITEM_CODE == itemcode)
-                                {
-                                    //鐗╂枡鐩稿悓鍏ヨ揣浣嶅悗涓�綅璐т綅
-                                    result = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => a.S_AREA_CODE.Trim() == areacode && a.N_ROW == list[i].N_ROW && a.N_COL > list[i].N_COL).First();
+            Location result = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).First();
+            //鏌ヨ鎵�湁鏈夋墭鐩樼殑鎺掓病閿佺殑鎺�+            // var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM > 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).OrderByDescending(a => a.N_COL).Take(1).PartitionBy(a => a.N_ROW).ToList();
+            // if (list.Count > 0)
+            //{
+            //    for (int i = 0; i < list.Count; i++)
+            //    {
+            //        LogHelper.Info($"鏈夋墭鐩樻帓鍙穥list[i].N_ROW}锛岀墿鏂欑紪鐮亄itemcode},搴撳尯{areacode}");
+            //        //鏌ヨ璐т綅缁戝畾鎵樼洏
+            //        var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == list[i].S_CODE).First();
+            //        if (cntr != null)
+            //        {
+            //            //鏌ヨ鎵樼洏鐗╂枡淇℃伅
+            //            var iteminfo = ContainerHelper.GetCntrItemRel(cntr.S_CNTR_CODE).FirstOrDefault();
 
-                                }
-                            }
-                        }
-                        if (result != null)
-                        {
-                            return result;
-                        }
-                    }
-                    else
-                    {
-                        LogHelper.Info($"鏍规嵁璐х墿缂栫爜{list[i].S_CODE}鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�);
-                    }
-                }
-            }
+            //            if (string.IsNullOrEmpty(itemcode))//绌烘墭鍏ュ簱
+            //            {
+            //                if (iteminfo == null)
+            //                {
+            //                    //鐗╂枡鐩稿悓鍏ヨ揣浣嶅悗涓�綅璐т綅
+            //                    result = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => a.S_AREA_CODE.Trim() == areacode && a.N_ROW == list[i].N_ROW && a.N_COL > list[i].N_COL && a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM == 0).First();
+            //                }
+            //            }
+            //            else//婊℃嫋鍏ュ簱
+            //            {
+            //                if (iteminfo != null)
+            //                {
+            //                    if (iteminfo.S_ITEM_CODE == itemcode)
+            //                    {
+            //                        //鐗╂枡鐩稿悓鍏ヨ揣浣嶅悗涓�綅璐т綅
+            //                        result = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => a.S_AREA_CODE.Trim() == areacode && a.N_ROW == list[i].N_ROW && a.N_COL > list[i].N_COL && a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM == 0).First();
+
+            //                    }
+            //                }
+            //            }
+            //            if (result != null)
+            //            {
+            //                return result;
+            //            }
+            //        }
+            //        else
+            //        {
+            //            LogHelper.Info($"鏍规嵁璐х墿缂栫爜{list[i].S_CODE}鏈壘鍒版墭鐩樿揣浣嶇粦瀹氬叧绯�);
+            //        }
+            //    }
+            //}
             return result;
         }
 
@@ -2218,7 +2330,14 @@
 
             #endregion
             var loc = LocationHelper.GetLocByItemCode(areacode, itemcode, level);
-            result = FindStartcolByLoclist(loc);
+            LogHelper.Info($"airlift=>鏍规嵁搴撳尯缂栫爜:{areacode}锛岀墿鏂欑紪鐮�{itemcode},鐗╂枡绛夌骇璁$畻鍑烘湁鎵樼洏璐т綅{JsonConvert.SerializeObject(loc)}");
+            // result = FindStartcolByLoclist(loc);
+            if (loc.Count > 0)
+            {
+                result = loc.OrderByDescending(a => a.N_COL).First();
+            }
+
+            LogHelper.Info($"airlift=>鍙敤璐т綅涓猴細{JsonConvert.SerializeObject(result)}");
             return result;
         }
 
@@ -2242,26 +2361,31 @@
             }
             return result;
         }
+
         /// <summary>
-        /// 鍒涘缓鎵樼洏鐗╂枡缁戝畾鍏崇郴
+        /// 绔嬪簱浠诲姟涓嬪彂鍒涘缓鎵樼洏鐗╂枡缁戝畾鍏崇郴
         /// </summary>
-        /// <param name="loc">璐т綅缂栫爜</param>
-        /// <param name="cntr">鎵樼洏缂栫爜</param>
-        /// <param name="partNumber">鐗╂枡缂栫爜</param>
-        /// <param name="partDesc">鐗╂枡鎻忚堪</param>
-        /// <param name="partType">鐗╂枡绫诲瀷</param>
-        /// <param name="cntrtype">鎵樼洏绫诲瀷</param>
-        /// <param name="unit">鐗╂枡鍗曚綅</param>
-        /// <param name="weight">鐗╂枡閲嶉噺</param>
-        internal static bool CreateCntrIteminfo(string loc, string cntr, string partNumber, string partDesc, string partType, string batch, string unit, string weight, string cntrtype = "1", string level = "")
+        internal static bool CreateCntrIteminfo(partData partData, taskData taskData)
         {
-            return ContainerHelper.CreateCntrItem(loc, cntr, partNumber, partDesc, partType, cntrtype, batch, weight, unit, level);
+            if (partData == null && taskData == null)
+            {
+                LogHelper.Info($"CreateCntrIteminfo==> 绔嬪簱浠诲姟涓嬪彂鍙傛暟鏈夌┖锛屽垱寤虹墿鏂欐墭鐩樼粦瀹氬叧绯诲け璐�);
+                return false;
+            }
+            else
+            {
+                return ContainerHelper.CreateCntrItem(taskData.pickStation, partData.rfid, partData.partNumber, partData.partDesc, partData.partType, taskData.carrierType, partData.lotNumber, taskData.wmsLot, partData.weight, partData.unit,
+                    taskData.tyreType, taskData.supplier, taskData.receiveLot, taskData.subpool, partData.productionTime, partData.maturityTime, taskData.level);
+            }
+
         }
+        private static object _lockLocation = new object();
         /// <summary>
         /// 鏍规嵁鎵樼洏缂栫爜锛屾満鍙扮紪鐮侊紝宸ヨ绫诲瀷璁$畻鏈哄彴绾胯竟鍖哄煙
         /// </summary>
         /// <param name="cntrcode">鎵樼洏缂栫爜</param>
         /// <param name="jtcode">鏈哄彴缂栫爜</param>
+        /// <param name="cntrType">鎵樼洏绫诲瀷</param>
         /// <returns></returns>
         internal static Location Computeloc(string cntrcode, string jtcode, string cntrType)
         {
@@ -2271,17 +2395,19 @@
 
             //  var location = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == cntrcode).First();
 
-
-            var loc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).First();
-            if (loc != null)
+            lock (_lockLocation)
             {
-                End = loc;
-            }
-            else
-            {
-                LogHelper.Info($"Computeloc==銆嬫牴鎹満鍙板垎缁勶細{jtcode},宸ヨ绫诲瀷锛歿cntrType} 鏈壘鍒扮┖璐т綅鏁版嵁锛岃妫�煡璐т綅琛�);
-            }
+                var loc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).First();
+                if (loc != null)
+                {
+                    End = loc;
+                }
+                else
+                {
+                    LogHelper.Info($"Computeloc==銆嬫牴鎹満鍙板垎缁勶細{jtcode},宸ヨ绫诲瀷锛歿cntrType} 鏈壘鍒扮┖璐т綅鏁版嵁锛岃妫�煡璐т綅琛�);
+                }
 
+            }
             return End;
         }
 
@@ -2301,7 +2427,7 @@
             {
                 var error = new ErrorInfo
                 {
-                    EEEORMESSAGE = errorInfo,
+                    ERRORMESSAGE = errorInfo,
                     TASKNO = taskno,
                     AREACODE = areacode,
                     REMAKE = remake,
@@ -2328,7 +2454,7 @@
         /// </summary>
         /// <param name="locations"></param>
         /// <returns></returns>
-        internal static Location FindEndcolByLocList(List<Location> locations, string itemcode)
+        internal static Location FindEndcolByLocList(List<Location> locations)
         {
             try
             {
@@ -2421,6 +2547,28 @@
             }
 
         }
+
+        /// <summary>
+        /// 鑾峰彇瀵瑰簲閿欒缂栫爜鐨勫皬杞︽暟閲�+        /// </summary>
+        /// <param name="Error1">閿欒鐮�</param>
+        /// <param name="Error2">閿欒鐮�</param>
+        /// <param name="faildCode"></param>
+        /// <returns></returns>
+        internal static int GetAgvQty(string Error1, string Error2 = "0", string faildCode = "0")
+        {
+            try
+            {
+                var db = new SqlHelper<HangChaAGV>().GetInstance();
+                return db.Queryable<HangChaAGV>().Where(a => a.faildCode == faildCode && a.errCode2 == Error2 && a.agvErrCode == Error1).Count();
+            }
+            catch (Exception)
+            {
+
+                throw;
+            }
+
+        }
         #endregion
 
 

--
Gitblit v1.9.1