From 84c580cccb118f5ec4a039d0009255935c3c2490 Mon Sep 17 00:00:00 2001
From: cjs <2216046164@qq.com>
Date: 星期二, 17 六月 2025 17:31:40 +0800
Subject: [PATCH] 111

---
 ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/WMSHelper.cs |  284 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 251 insertions(+), 33 deletions(-)

diff --git a/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/WMSHelper.cs b/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/WMSHelper.cs
index e566c2f..9754fb4 100644
--- a/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/WMSHelper.cs
+++ b/ams/Hanhe.iWCS.TaizhouGEMTwoProtocol/WMSHelper.cs
@@ -423,40 +423,31 @@
                         }
                         else
                         {
-                            var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoComTwo>(Query.EQ("timeStamp", timeStamp), "TimeCuoInfoCom");
-                            CMMLog.Info($"WMSIn-{startBit}:{ItemCode}锛氭煡璇㈡潯浠讹細timeStamp={timeStamp},璇诲嚭 TimeCuoInfoComTwo 琛ㄦ暟鎹负锛歿JsonConvert.SerializeObject(time)}");
-                            if (ItemCode == "time" && time != null)
-                            {
-                                CMMLog.Info($"WMSIn-{startBit}:time鑾峰彇鏃堕棿鎴虫暟鎹负锛歿time.TimeCuo}锛�);
-                                model.data.Add(new ItemData()
-                                {
-                                    //1妤兼媶鐩樻満璋僕MS鑾峰彇鍏ュ簱缁堢偣锛屼紶杈撴椂闂存埑鏁版嵁锛堟殏瀹氾級
-                                    //isFold = time.isFold,
-                                    //packingMachineNumber = time.packingMachineNumber,
-                                    itemCode = time.productModel,
-                                    lotNo = time.lotNo,
-                                    machineNo = time.packingMachineNumber1.ToString(),
-                                    packageCode = time.bagNumber1.ToString(),
-                                    //palletLayers = time.bagNumber1.ToString(),
-                                    foldingbag = time.isFold1.ToString(),
-                                    //totalWeight = time.totalWeight,
-                                    timeStamp = int.Parse(time.TimeCuo),
-                                    //productType = time.productModel,
-                                    //bagNumber = time.bagNumber,
-                                    //needWeight = time.needWeight,
-                                    realWeight = time.realWeight1,
-                                    //batchNumber = time.batchNumber,
-                                    //totalCount = time.totalCount,
-
-                                    Jm_Item_Code = time.materialCode,
-                                    Jm_Item_Name = time.materialName,
-                                    Jm_Item_Model = time.productModel,
-                                    Jm_Item_Unit = time.measurementUnit,
-                                    Jm_Item_Staff = employee_id
-                                });
-                            }
+                            //var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoComTwo>(Query.EQ("timeStamp", timeStamp), "TimeCuoInfoCom");
+                            //CMMLog.Info($"WMSIn-{startBit}:{ItemCode}锛氭煡璇㈡潯浠讹細timeStamp={timeStamp},璇诲嚭 TimeCuoInfoComTwo 琛ㄦ暟鎹负锛歿JsonConvert.SerializeObject(time)}");
+                            //var erpItemTableInfo = MongoDBSingleton.Instance.FindOne<ERPItemTable>(Query.EQ("item_code", time.materialCode), "ERPItemTable");
+                            //CMMLog.Info($"WMSIn-{startBit}:鏌ヨ鏉′欢锛歩tem_code={time.materialCode},璇诲嚭 ERPItemTable 琛ㄦ暟鎹负锛歿JsonConvert.SerializeObject(erpItemTableInfo)}");
+                            //if (ItemCode == "time" && time != null && erpItemTableInfo != null)
+                            //{
+                            //    CMMLog.Info($"WMSIn-{startBit}:time鑾峰彇鏃堕棿鎴虫暟鎹负锛歿time.TimeCuo}锛�);
+                            //    model.data.Add(new ItemData()
+                            //    {
+                            //        itemCode = time.productModel,
+                            //        lotNo = time.lotNo,
+                            //        machineNo = time.packingMachineNumber1.ToString(),
+                            //        packageCode = time.bagNumber1.ToString(),
+                            //        foldingbag = time.isFold1.ToString(),
+                            //        timeStamp = int.Parse(time.TimeCuo),
+                            //        realWeight = time.realWeight1,
+                            //
+                            //        Jm_Item_Code = time.materialCode,
+                            //        Jm_Item_Name = time.materialName,
+                            //        Jm_Item_Model = time.productModel,
+                            //        Jm_Item_Unit = time.measurementUnit,
+                            //        Jm_Item_Staff = employee_id
+                            //    });
+                            //}
                         }
-                        
                     }
                     else
                     {
@@ -539,6 +530,233 @@
             return result;
         }
 
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="startBit"></param>
+        /// <param name="ItemCode"></param>
+        /// <param name="taskNo"></param>
+        /// <param name="trayCode"></param>
+        /// <param name="timeStamp"></param>
+        /// <param name="employee_id">鍛樺伐缂栫爜</param>
+        /// <returns></returns>
+        public static bool WMSInTwo(string startBit, string ItemCode, ref string taskNo, ref string trayCode, string timeStamp = "", string employee_id = "", bool isTwo = false, string trayType = "")
+        {
+            //XMZ001A11-1
+            //startBit = startBit.Substring(0, 9);
+            bool result = false;
+            HardwareAccessObject hao = HardwareAccessHelper.Instance.GetEquipmentsHAO(Constants.WMS_DEVICE_TYPE_WMS);
+            string msg = "";
+            if (hao != null)
+            {
+                //http://192.168.1.199:9001/api/wmsapi/InWorkArea
+                WMSInModel model = new WMSInModel();
+                model.startBit = startBit;
+                model.isTransport = "N";
+                model.needCreateAMSTask = "Y";
+                model.projectCode = "glm";
+                model.trayType = trayType;
+                model.data = new List<ItemData>();
+                CMMLog.Info($"WMSInTwo-{startBit}:ItemCode绫诲瀷涓猴細{ItemCode}");
+                if (!string.IsNullOrEmpty(ItemCode))
+                {
+                    //var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoCom>(Query.Or(Query.EQ("isNeedTray", 1), Query.EQ("isNeedTray", 2)), "TimeCuoInfoCom");
+                    if (ItemCode == "time" || ItemCode == "鎷嗙洏鍙樻洿")
+                    {
+                        if (!isTwo)
+                        {
+                            int timeInt = int.Parse(trayCode);
+                            var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoCom>(Query.EQ("timeStamp", timeInt), "TimeCuoInfoCom");
+                            CMMLog.Info($"WMSInTwo-{startBit}:{ItemCode}锛氭煡璇㈡潯浠讹細timeStamp={timeInt},璇诲嚭 TimeCuoInfoCom 琛ㄦ暟鎹负锛歿JsonConvert.SerializeObject(time)}");
+                            if (ItemCode == "time" && time != null)
+                            {
+                                int TimeStamp = string.IsNullOrEmpty(timeStamp) ? time.timeStamp : int.Parse(timeStamp);
+                                CMMLog.Info($"WMSInTwo-{startBit}:time鑾峰彇鏃堕棿鎴虫暟鎹负锛歿TimeStamp}锛�);
+                                model.data.Add(new ItemData()
+                                {
+                                    //1妤兼媶鐩樻満璋僕MS鑾峰彇鍏ュ簱缁堢偣锛屼紶杈撴椂闂存埑鏁版嵁锛堟殏瀹氾級
+                                    //isFold = time.isFold,
+                                    //packingMachineNumber = time.packingMachineNumber,
+                                    itemCode = time.productModel,
+                                    lotNo = time.batchNumber,
+                                    machineNo = time.packingMachineNumber.ToString(),
+                                    packageCode = time.bagNumber,
+                                    palletLayers = time.isNeedTray.ToString(),
+                                    foldingbag = time.isFold.ToString(),
+                                    //totalWeight = time.totalWeight,
+                                    timeStamp = TimeStamp,
+                                    photoURL = time.photoURL,
+                                    //productType = time.productModel,
+                                    //bagNumber = time.bagNumber,
+                                    //needWeight = time.needWeight,
+                                    realWeight = time.realWeight,
+                                    //batchNumber = time.batchNumber,
+                                    //totalCount = time.totalCount,
+
+                                    Jm_Item_Code = time.materialCode,
+                                    Jm_Item_Name = time.materialName,
+                                    Jm_Item_Model = time.productModel,
+                                    Jm_Item_Unit = time.measurementUnit,
+                                    Jm_Item_Staff = employee_id
+                                });
+
+                                // 闈濫RP鍙樻洿娴佺▼鍙互鐩存帴鍒犻櫎 TimeCuoInfoCom 琛�+                                if (ERPService.ERPSwitch01 == "0")
+                                {
+                                    CMMLog.Info($"WMSInTwo-{startBit}:鏌ヨ鏉′欢锛歵imeStamp={timeInt},闈濫RP鍙樻洿娴佺▼鐩存帴鍒犻櫎 TimeCuoInfoCom 琛紒");
+                                    MongoDBSingleton.Instance.Remove<TimeCuoInfoCom>(Query.EQ("timeStamp", timeInt), RemoveFlags.Single);
+                                }
+                            }
+                            else if (ItemCode == "鎷嗙洏鍙樻洿")
+                            {
+                                model.data.Add(new ItemData()
+                                {
+                                    //1妤兼媶鐩樻満璋僕MS鑾峰彇鍏ュ簱缁堢偣锛屼紶杈撴椂闂存埑鏁版嵁锛堟殏瀹氾級
+                                    //isFold = time.isFold,
+                                    //packingMachineNumber = time.packingMachineNumber,
+                                    itemCode = "1",
+                                    lotNo = "1",
+                                    machineNo = "1",
+                                    packageCode = "1",
+                                    palletLayers = "1",
+
+                                    foldingbag = "1",
+                                    //totalWeight = time.totalWeight,
+                                    timeStamp = 1,
+                                    photoURL = "1",
+                                    //productType = time.productModel,
+                                    //bagNumber = time.bagNumber,
+                                    //needWeight = time.needWeight,
+                                    realWeight = 1,
+                                    //batchNumber = time.batchNumber,
+                                    //totalCount = time.totalCount,
+                                });
+                            }
+                        }
+                        else
+                        {
+                            //var time = MongoDBSingleton.Instance.FindOne<TimeCuoInfoComTwo>(Query.EQ("timeStamp", timeStamp), "TimeCuoInfoCom");
+                            //CMMLog.Info($"WMSInTwo-{startBit}:{ItemCode}锛氭煡璇㈡潯浠讹細timeStamp={timeStamp},璇诲嚭 TimeCuoInfoComTwo 琛ㄦ暟鎹负锛歿JsonConvert.SerializeObject(time)}");
+                            //if (ItemCode == "time" && time != null)
+                            //{
+                            //    CMMLog.Info($"WMSInTwo-{startBit}:time鑾峰彇鏃堕棿鎴虫暟鎹负锛歿time.TimeCuo}锛�);
+                            //    model.data.Add(new ItemData()
+                            //    {
+                            //        //1妤兼媶鐩樻満璋僕MS鑾峰彇鍏ュ簱缁堢偣锛屼紶杈撴椂闂存埑鏁版嵁锛堟殏瀹氾級
+                            //        //isFold = time.isFold,
+                            //        //packingMachineNumber = time.packingMachineNumber,
+                            //        itemCode = time.productModel,
+                            //        lotNo = time.lotNo,
+                            //        machineNo = time.packingMachineNumber1.ToString(),
+                            //        packageCode = time.bagNumber1.ToString(),
+                            //        //palletLayers = time.bagNumber1.ToString(),
+                            //        foldingbag = time.isFold1.ToString(),
+                            //        //totalWeight = time.totalWeight,
+                            //        timeStamp = int.Parse(time.TimeCuo),
+                            //        //productType = time.productModel,
+                            //        //bagNumber = time.bagNumber,
+                            //        //needWeight = time.needWeight,
+                            //        realWeight = time.realWeight1,
+                            //        //batchNumber = time.batchNumber,
+                            //        //totalCount = time.totalCount,
+                            //
+                            //        Jm_Item_Code = time.materialCode,
+                            //        Jm_Item_Name = time.materialName,
+                            //        Jm_Item_Model = time.productModel,
+                            //        Jm_Item_Unit = time.measurementUnit,
+                            //        Jm_Item_Staff = employee_id
+                            //    });
+                            //}
+                        }
+
+                    }
+                    else
+                    {
+                        var info = MongoDBSingleton.Instance.FindOne<MachineInfoTetracobalt>(Query.EQ("trayCode", ItemCode), "MachineInfoTetracobalt");
+                        // ERP鍙樻洿鏂板鏁版嵁鐩存帴浠� ERP鐗╂枡涓棿琛�ERPItemTable 鑾峰彇(鏍规嵁鐗╂枡缂栫爜)
+                        CMMLog.Info($"WMSInTwo-{startBit}:鏌ヨ鏉′欢锛歵rayCode={ItemCode},璇诲嚭 MachineInfoTetracobalt 琛ㄦ暟鎹负锛歿JsonConvert.SerializeObject(info)}");
+                        if (info != null)
+                        {
+                            var erpItemTableInfo = MongoDBSingleton.Instance.FindOne<ERPItemTable>(Query.EQ("item_code", info.materialCode), "ERPItemTable");
+                            CMMLog.Info($"WMSInTwo-{startBit}:鏌ヨ鏉′欢锛歩tem_code={info.materialCode},璇诲嚭 ERPItemTable 琛ㄦ暟鎹负锛歿JsonConvert.SerializeObject(erpItemTableInfo)}");
+                            model.locationGear = info.secondNg.ToString();
+                            model.trayCode = info.trayCode;
+                            string product = !string.IsNullOrEmpty(info.productType) ? info.productType : erpItemTableInfo.item_spec;
+                            model.data.Add(new ItemData()
+                            {
+                                itemCode = product,
+                                lotNo = info.lotNo,
+                                machineNo = info.machineNo,
+                                packageCode = info.packageCode,
+                                palletLayers = info.palletLayers,
+                                foldingbag = info.overlappingLayers,
+                                itemState = info.secondNg,
+                                productWeight = info.productWeight,
+                                trayCodeWeight = info.trayCodeWeight,
+                                oneTrayWeight = info.oneTrayWeight,
+                                //bagNo = info.bagNo,
+                                //productType = info.productType,
+                                //materialCode = info.materialCode,
+                                //location = info.location,
+                                //addWeight = info.addWeight,
+                                //packNg = info.packNg,
+                                //addState = info.addState,
+
+                                Jm_Item_Code = info.materialCode,
+                                Jm_Item_Name = erpItemTableInfo.item_name,
+                                Jm_Item_Model = erpItemTableInfo.item_spec,
+                                Jm_Item_Unit = erpItemTableInfo.item_uom,
+                                Jm_Item_Staff = info.trayCodeWeight
+                            });
+                        }
+                    }
+                }
+                string msgData = JsonConvert.SerializeObject(model);
+                string reqStr = "鐗╂枡鍚�" + ItemCode + ";鏁伴噺";
+                string feedback = "";
+
+                CMMLog.Info($"WMSInTwo-{startBit}:銆愯皟鐢╳ms鑾峰彇鍏ュ簱璐т綅銆�鍙戦�鏁版嵁锛歿JsonConvert.SerializeObject(msgData)}锛岀墿鏂欐潯浠讹細ItemCode锛歿ItemCode},trayCode锛歿trayCode}");
+                var url = hao.WebUrl + "GlmInSendTask";
+                try
+                {
+                    //hao.WebUrl = "http://192.168.1.199:9001/api/";
+                    feedback = helper.WebPost(url, msgData).Replace(@"\", "").Trim();
+                    Console.WriteLine(feedback);
+                    CMMLog.Info($"WMSInTwo-{startBit}:銆愯皟鐢╳ms鑾峰彇鍏ュ簱璐т綅銆�鎺ユ敹鏁版嵁锛� + feedback);
+                    if (!string.IsNullOrEmpty(feedback))
+                    {
+                        //var wmsResponse = JsonConvert.DeserializeObject<WMSResponseModel>(feedback.Substring(1, feedback.Length - 2));
+                        var wmsResponse = JsonConvert.DeserializeObject<WMSResponseModel>(feedback);
+                        //var res = feedback.Replace("{", "").Replace("}", "").Replace(":", "=").Replace(",", ";").Replace('"', ' ');
+                        if (wmsResponse.Success == true)
+                        {
+                            msg = $"WMSInTwo-{startBit}:銆愯皟鐢╳ms鑾峰彇鍏ュ簱璐т綅銆戞垚鍔燂紒杩斿洖缁撴灉=" + wmsResponse.Success + ";璋冪敤WebUrl=" + url + ";杈撳叆鍙傛暟=" + msgData;
+                        }
+                        else
+                        {
+                            string errMsg = wmsResponse.Code + "-" + wmsResponse.Msg;
+                            msg = $"WMSInTwo-{startBit}:銆愯皟鐢╳ms鑾峰彇鍏ュ簱璐т綅銆戝け璐ワ紒閿欒鍘熷洜=" + errMsg + ";璋冪敤WebUrl=" + url + ";杈撳叆鍙傛暟=" + msgData;
+                        }
+                        result = wmsResponse.Success;
+                    }
+                    else
+                    {
+                        string errMsg = "鍙傛暟鍙嶉绌哄�";
+                        msg = $"WMSInTwo-{startBit}:銆愯皟鐢╳ms鑾峰彇鍏ュ簱璐т綅銆戝け璐ワ紒閿欒鍘熷洜=" + errMsg + ";璋冪敤WebUrl=" + url + ";杈撳叆鍙傛暟=" + msgData;
+                    }
+                }
+                catch (Exception e)
+                {
+                    CMMLog.Error(string.Format($"WMSInTwo-{startBit}:銆愯皟鐢╳ms鑾峰彇鍏ュ簱璐т綅澶辫触銆戝紓甯竰0}", e.Message), e);
+                    msg = $"WMSInTwo-{startBit}:銆愯皟鐢╳ms鑾峰彇鍏ュ簱璐т綅銆戝け璐ワ紒瑙f瀽杩斿洖鍊煎嚭閿�" + feedback + ";璋冪敤WebUrl=" + url + ";杈撳叆鍙傛暟=" + msgData;
+                }
+            }
+            else msg = string.Format($"WMSInTwo-{startBit}:璋冪敤wms澶辫触锛宎ms宸ヤ綔涓績娌℃湁璁剧疆锛�);
+            CMMLog.Info(msg);
+            Console.WriteLine(msg);
+            return result;
+        }
+
         public static bool WMSOut(string endBit, string ItemCode) {
             //endBit = endBit.Substring(0, 9);
             bool result = false;

--
Gitblit v1.9.1