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 |  559 +++++++++++++++++++++++++++++++------------------------
 1 files changed, 318 insertions(+), 241 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 13161c9..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;
@@ -80,7 +83,7 @@
                 //    AddErrorInfo("瀵绘壘鍑哄簱鍖哄け璐�, result.msg);
                 //    return result;
                 //}
-              
+
                 int n_type = 0;  //浠诲姟鏉ユ簮 1.瀵嗙偧绔嬪簱  3.棰勫搴�,4.鍘熸潗鏂欏簱
                 string Source = "";
                 switch (taskData.source)
@@ -155,6 +158,7 @@
                 }
                 else if (taskData.taskType == 2)//鍏ュ簱娴佺▼锛岀洿鎺ヤ娇鐢ㄨ捣鐐硅揣浣嶅拰缁堢偣璐т綅鐢熸垚浠诲姟锛岃捣鐐归渶瑕佹湁鎵樼洏
                 {
+                    note = "鍏ュ簱";
                     startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                     if (startloc != null)
                     {
@@ -173,12 +177,7 @@
                         }
 
                     }
-                    //鍒ゆ柇鏄惁鏄┖鎵樺洖搴�-                    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)
                     {
@@ -194,8 +193,8 @@
                 }
                 else if (taskData.taskType == 3)//绉诲簱娴佺▼锛岀洿鎺ヤ娇鐢ㄨ捣鐐硅揣浣嶅拰缁堢偣璐т綅鐢熸垚浠诲姟锛�                 {
+                    note = "鍑哄簱";
                     //鍒涘缓鎵樼洏鐗╂枡缁戝畾淇℃伅锛屽苟璁$畻缁堢偣璐т綅
-
                     startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                     if (startloc != null)
                     {
@@ -267,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))
@@ -302,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
                             {
@@ -322,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
 
                             };
 
@@ -385,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)
@@ -537,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");
@@ -683,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))
                 {
                     //鍒涘缓鎴愬姛娴佺▼
                 }
@@ -791,23 +795,27 @@
                 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;
@@ -819,6 +827,7 @@
                         result.msg = $"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�;
                         LogHelper.Info($"Putin==> {result.msg}");
                         AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                        return result;
                     }
                 }
                 else
@@ -828,6 +837,7 @@
                     result.msg = $"浠诲姟璧风偣:{Start}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
                     LogHelper.Info($"Putin==> {result.msg}");
                     AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
+                    return result;
                 }
                 #endregion
 
@@ -885,7 +895,6 @@
                 LogHelper.Error("Putin Error锛� + ex.ToString(), ex);
                 return result;
             }
-
         }
 
         /// <summary>
@@ -926,47 +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
                     {
+                        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;
+                            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 鏍规嵁鐗╂枡缂栫爜璁$畻鍑哄簱璐т綅锛岄�寰�嚎杈逛綅缃�@@ -984,6 +996,14 @@
                     {
                         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
                 {
@@ -992,6 +1012,7 @@
                     result.msg = $"浠诲姟鐗╂枡:{itemcode}鎵句笉鍒板搴斿簱瀛�;
                     LogHelper.Info($"ItemBack锛歿result.msg}");
                     AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
+                    return result;
                 }
                 #endregion
 
@@ -1083,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 鏍规嵁璐т綅妤煎眰鍒ゆ柇锛�妤煎幓寰�彔鐩樹綅 鍏朵粬鐨勫洖搴�@@ -1139,7 +1160,7 @@
                             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();
@@ -1169,33 +1190,21 @@
                     }
                     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
                         {
-
                             result.code = "1";
-                            result.msg = $"鍒涘缓浠诲姟澶辫触锛屾牴鎹墭鐩樼紪鐮亄model.Rfid}鏈壘鍒版墭鐩樺嚭搴撲换鍔�;
-                            LogHelper.Info($"{result.msg}");
-                            AddErrorInfo("鏌ユ壘浠诲姟澶辫触", result.msg, Source);
-                            return result;
-                        }
-                        if (string.IsNullOrEmpty(areacode))
-                        {
-
-                            result.code = "1";
-                            result.msg = $"鍒涘缓浠诲姟澶辫触锛屾牴鎹墭鐩樼紪鐮亄model.Rfid}鎵惧埌鍑哄簱浠诲姟{mst.S_CODE}鐨勮捣鐐瑰簱鍖轰负绌�;
-                            LogHelper.Info($"{result.msg}");
+                            result.msg = $"鏍规嵁璧风偣浠撳簱缂栫爜锛歿startloc.S_WH_CODE}鏈壘鍒板搴旈厤缃枃浠�;
+                            LogHelper.Info($"Putin==> {result.msg}");
                             AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                             return result;
                         }
@@ -1203,23 +1212,23 @@
 
                         //鍥炲簱璐т綅璁$畻搴撳尯璐т綅
                         loc = StorageCompute(itemcode, areacode);
-                        if (loc == null)
-                        {
-                            loc = emptyRow(areacode);
-                            if (loc == null)
-                            {
-                                LogHelper.Info($"搴撳尯锛歿areacode}娌℃湁绌烘帓");
-                            }
-                        }
-                        else
-                        {
+                        //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;
-                        }
+                        //    result.code = "1";
+                        //    result.msg = $"搴撳尯:{areacode}鏃犲彲鐢ㄨ揣浣�;
+                        //    LogHelper.Info($"{result.msg}");
+                        //    AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
+                        //    return result;
+                        //}
                     }
 
                 }
@@ -1235,12 +1244,12 @@
                 #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;
                     }
@@ -1250,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,
@@ -1266,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();
@@ -1324,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();
@@ -1366,7 +1381,7 @@
                     result.msg = $"浠诲姟璧风偣:{End}鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃";
                     LogHelper.Info($"callfixture:{result.msg}");
                     AddErrorInfo("鏌ユ壘璐т綅澶辫触", result.msg, Source);
-
+                    return result;
                 }
                 #endregion
 
@@ -1461,30 +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)
-                    {
 
-                        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
 
                 #region 浣欐枡杩斿洖鏍规嵁鎵樼洏鎵惧嚭搴撲换鍔�                 //浣欐枡杩斿洖鏍规嵁鎵樼洏鎵惧嚭搴撲换鍔�@@ -1519,73 +1511,113 @@
                 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
                         {
-
-                            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);
-                            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}鏃犲彲鐢ㄨ揣浣�;
+                                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, Source);
+                            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, Source);
+                        result.msg = $"鏍规嵁璧风偣浠撳簱缂栫爜锛歿startloc.S_WH_CODE}鏈壘鍒板搴旈厤缃枃浠�;
+                        LogHelper.Info($"Putin==> {result.msg}");
+                        AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source);
                         return result;
                     }
+
                 }
                 else
                 {
@@ -1760,10 +1792,11 @@
                 itemInfo.REMARK1 = model.StewingTime;
                 itemInfo.REMARK2 = model.OverdueTime;
                 itemInfo.S_MP_TYPE = model.Unit;
-                if (db.Insertable<TN_Material>(itemInfo).ExecuteCommand()>0)
+                if (db.Insertable<TN_Material>(itemInfo).ExecuteCommand() > 0)
                 {
                     LogHelper.Info($"add:鐗╂枡缂栫爜:{model.PartNumber}鐨勭墿鏂欎富鏁版嵁宸插悓姝�);
-                } ;
+                }
+                ;
                 return result;
             }
             catch (Exception ex)
@@ -2083,7 +2116,23 @@
             }
             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>
         /// 搴撲綅娓呯┖
@@ -2118,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();
 
                         }
@@ -2167,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;
         }
 
@@ -2281,7 +2331,12 @@
             #endregion
             var loc = LocationHelper.GetLocByItemCode(areacode, itemcode, level);
             LogHelper.Info($"airlift=>鏍规嵁搴撳尯缂栫爜:{areacode}锛岀墿鏂欑紪鐮�{itemcode},鐗╂枡绛夌骇璁$畻鍑烘湁鎵樼洏璐т綅{JsonConvert.SerializeObject(loc)}");
-            result = FindStartcolByLoclist(loc);
+            // result = FindStartcolByLoclist(loc);
+            if (loc.Count > 0)
+            {
+                result = loc.OrderByDescending(a => a.N_COL).First();
+            }
+
             LogHelper.Info($"airlift=>鍙敤璐т綅涓猴細{JsonConvert.SerializeObject(result)}");
             return result;
         }
@@ -2399,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
             {
@@ -2492,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