From 58bd958f1fa8a85d0a3ac33a1ab1e2cab5d63dd2 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期四, 20 六月 2024 20:18:46 +0800 Subject: [PATCH] 按照SN号查询最新的工单 --- 代码管理/WMS/WMS_Server/WIDESEA_WMS/ToMes/OutsourceInbound.cs | 66 +++++++++++++++++++++----------- 1 files changed, 43 insertions(+), 23 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/ToMes/OutsourceInbound.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/ToMes/OutsourceInbound.cs" index 61acc33..aa074ec 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/ToMes/OutsourceInbound.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/ToMes/OutsourceInbound.cs" @@ -1,4 +1,5 @@ -锘縰sing Newtonsoft.Json; +锘縰sing Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using System; using System.Collections.Generic; @@ -47,6 +48,7 @@ list.Add(SN); } var inventoryList = inventoryRepository.Find(x => list.Contains(x.SN)).ToList(); + foreach (var inventorys in inventoryList.GroupBy(x => x.stationCode)) { try @@ -57,46 +59,64 @@ detail detail = new detail(); detail.sn = inventory.SN; lists.Add(detail); - str = str == "" ? inventory.SN : "," + inventory.SN; + str += str == "" ? inventory.SN : "," + inventory.SN; } agvInWarehousePara outWarehousePara = new agvInWarehousePara() { - //WorkOrder = task.jobID, zoneID = inventorys.Key, - //processCode = task.agv_worktype.ToString(), details = lists, layerNo = 1, stackID = "1", warehouseName = "Agv搴�", Operator = UserContext.Current.UserName, }; - var postJson = JsonConvert.SerializeObject(outWarehousePara); - var mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvOutWarehouse"); - if (mesData.Contains("杩炴帴灏濊瘯澶辫触")) throw new Exception(mesData); - MES_Response requestMes = JsonConvert.DeserializeObject<MES_Response>(mesData); - if (requestMes.code == "200" && requestMes.Type == "success") - { - //鏃ュ織璁板綍涓婁紶鏁版嵁鎴愬姛 - WriteWMSLog.LogAdd("", "鎴愬姛", "MES", "PDA", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆鍑哄簱", "agvOutWarehouse", requestMes.message); - foreach (var inventory in inventorys) + Idt_info_to_mesRepository mesRepository = new dt_info_to_mesRepository(context); + var postJson = JsonConvert.SerializeObject(outWarehousePara); + dt_info_to_mes info_To_Mes = new dt_info_to_mes() + { + Info = postJson, + ActionName = "agvOutWarehouse", + Createtime = DateTime.Now, + Remark = "浜哄伐鍚屾MES杞﹁疆鍑哄簱", + State = false + }; + mesRepository.Add(info_To_Mes, true); + + foreach (var inventory in inventorys) + { + var station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault(); + station.quantity = station.quantity - 1; + if (station.quantity < 1) { - var station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault(); + station.quantity = 0; + station.stationType = string.Empty; + station.heatNumber = string.Empty; + station.Number = string.Empty; + station.billetID = string.Empty; + station.bindSN = string.Empty; + station.enable = false; + station.tray_status = string.Empty; + station.location_state = LocationStateEnum.Empty.ToString(); + } + else + { var bindSNS = station.bindSN.Split(","); station.bindSN = OperStr(bindSNS, inventory.SN); var billetS = station.billetID.Split(","); station.billetID = OperStr(billetS, inventory.BilletNumber.ToString()); - station.quantity = station.quantity - 1; - stationinfoRepository.Update(station, true); - inventoryRepository.Delete(inventory, true); } - WriteDBLog.Write($"浜哄伐鍑哄簱鎴愬姛 ", $"璐т綅缂栧彿锛歿inventorys.Key}锛汼N鍙凤細{str}", LogState.Sucess, "PDA", user); + + #region 鍙栨秷璺熻釜DbContext涓璺熻釜鐨勫疄浣� + var currentEntry = stationinfoRepository.DbContext.ChangeTracker.Entries<dt_stationinfo>().FirstOrDefault(); + if (currentEntry != null) currentEntry.State = EntityState.Detached; + #endregion + + stationinfoRepository.Update(station, true); + inventoryRepository.Delete(inventory, true); } - else - { - WriteWMSLog.LogAdd("", "澶辫触", "MES", "PDA", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆鍑哄簱", "agvOutWarehouse", requestMes.message); - throw new Exception("浜哄伐鍑哄簱鍚屾MES杞﹁疆鍑哄簱澶辫触锛�" + requestMes.message); - } + WriteDBLog.Write($"浜哄伐鍑哄簱鎴愬姛 ", $"璐т綅缂栧彿锛歿inventorys.Key}锛汼N鍙凤細{str}", LogState.Sucess, "PDA", user); + } catch (Exception ex) { -- Gitblit v1.9.3