From 0b5ccdca6263cf7a2cee460f30c76ef1efea2811 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期六, 27 四月 2024 17:47:27 +0800 Subject: [PATCH] 人工出库,人工入库,人工移库,PDA扫码确认外协物料已被取走接口 --- 代码管理/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs | 242 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 237 insertions(+), 5 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs" index c00277e..8ac8691 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WMS/Services/system/Partial/dt_inventoryService.cs" @@ -21,6 +21,21 @@ using WIDESEA_Comm.LogInfo; using WIDESEA_Core.ManageUser; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; +using WIDESEA_Core.EFDbContext; +using WIDESEA_WMS.Repositories; +using System.Collections.Generic; +using System.Threading.Tasks; +using static WIDESEA_Comm.MES_Info.BasicSN; +using System.Collections; +using static FreeSql.Internal.GlobalFilter; +using WIDESEA_Comm.MES_Info.Request; +using System.Xml.Linq; +using Newtonsoft.Json; +using Confluent.Kafka; +using WIDESEA_WMS.Common; +using WIDESEA_Comm.MES_Info; +using System.Reflection; +using static System.Collections.Specialized.BitVector32; namespace WIDESEA_WMS.Services { @@ -42,6 +57,170 @@ //base.Init(dbRepository); } + + /// <summary> + /// 娣诲姞搴撳瓨 + /// </summary> + /// <param name="saveDataModel"></param> + /// <returns></returns> + public override WebResponseContent Add(SaveModel saveDataModel) + { + WebResponseContent content = new WebResponseContent(); + VOLContext context = new VOLContext(); + IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context); + Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); + var stationCode = saveDataModel.MainData["stationCode"].ToString(); + try + { + if (string.IsNullOrEmpty(stationCode)) throw new Exception($"缂撳瓨鏋剁紪鍙蜂笉鑳戒负绌�!"); + if (!stationCode.Contains("B") && !stationCode.Contains("C") && !stationCode.Contains("D")) throw new Exception($"缂撳瓨鏋剁被鍨嬫湁璇�!"); + var station = stationinfoRepository.Find(x => x.stationCode == stationCode).FirstOrDefault(); + if (station == null) throw new Exception($"鏈壘鍒拌揣浣峽stationCode}"); + var bindSNs = saveDataModel.MainData["SN"].ToString().Split(","); + var SNS = bindSNs.GroupBy(x => x).Where(x => x.Count() > 1).Select(x => x.Key); + foreach (var SN in SNS) + { + throw new Exception($"閲嶅鐨凷N鍙穥SN}"); + } + List<detail> list = new List<detail>(); + List<VV_Mes_Workinfo> workinfos = new List<VV_Mes_Workinfo>(); + foreach (var item in bindSNs) + { + var work = workinfoRepository.Find(x => x.SN == item && x.processCode == "17").FirstOrDefault(); + if (work == null) throw new Exception($"鏈壘鍒拌溅杞甋N鍙凤細{item}鐨勫伐鍗曚俊鎭紒"); + workinfos.Add(work); + detail detail = new detail(); + detail.sn = item; + list.Add(detail); + } + agvInWarehousePara outWarehousePara = new agvInWarehousePara() + { + //WorkOrder = task.jobID, + zoneID = stationCode, + //processCode = task.agv_worktype.ToString(), + details = list, + layerNo = 1, + stackID = "1", + warehouseName = "Agv搴�", + Operator = UserContext.Current.UserName, + }; + var postJson = JsonConvert.SerializeObject(outWarehousePara); + var mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvInWarehouse"); + 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", "WMS", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆鍏ュ簱", "agvInWarehouse", requestMes.message); + foreach (var workinfo in workinfos) + { + dt_inventory inventory = new dt_inventory() + { + SN = workinfo.SN, + Name = workinfo.productName, + FigureNumber = workinfo.drawingNo, + materialCode = workinfo.materialCode, + HeatNumber = workinfo.heatID, + drawingNoVer = workinfo.drawingNoVer, + BilletNumber = workinfo.billetID, + OnlineTime = DateTime.Now, + Operator = "admin", + stationCode = stationCode, + area = station.area, + jobID = workinfo.jobID, + workOrder = workinfo.workOrder, + ID = Guid.NewGuid() + }; + _repository.Add(inventory, true); + } + WriteDBLog.Write($"鎵嬪姩娣诲姞搴撳瓨 ", $"璐т綅缂栧彿锛歿stationCode}锛汼N鍙凤細{saveDataModel.MainData["SN"]}", LogState.Sucess, "WMS", UserContext.Current.UserName); + } + else + { + WriteWMSLog.LogAdd("", "澶辫触", "MES", "WMS", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆鍏ュ簱", "agvInWarehouse", requestMes.message); + throw new Exception("浜哄伐鍚屾MES杞﹁疆鍏ュ簱澶辫触锛�" + requestMes.message); + } + } + catch (Exception ex) + { + content.Message = ex.Message; + WriteDBLog.Write($"鎵嬪姩娣诲姞搴撳瓨 ", new { 閿欒淇℃伅 = ex.Message, 鏁版嵁 = $"璐т綅缂栧彿锛歿stationCode}锛汼N鍙凤細{saveDataModel.MainData["SN"]}" }, LogState.Error, "WMS", UserContext.Current.UserName); + } + return content; + //return base.Add(saveDataModel); + } + /// <summary> + /// 淇敼搴撳瓨 + /// </summary> + /// <param name="saveModel"></param> + /// <returns></returns> + public override WebResponseContent Update(SaveModel saveModel) + { + WebResponseContent content = new WebResponseContent(); + string str = ""; + try + { + VOLContext context = new VOLContext(); + Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); + var stationCode = saveModel.MainData["stationCode"].ToString(); + if (string.IsNullOrEmpty(stationCode)) throw new Exception($"缂撳瓨鏋剁紪鍙蜂笉鑳戒负绌�!"); + if (!stationCode.Contains("B") && !stationCode.Contains("C") && !stationCode.Contains("D")) throw new Exception($"缂撳瓨鏋剁被鍨嬫湁璇�!"); + if (!stationinfoRepository.Find(x => x.stationCode == stationCode).Any()) throw new Exception($"鏈壘鍒拌揣浣峽stationCode}"); + var inventory = _repository.Find(x => x.ID.ToString() == saveModel.MainData["ID"].ToString()).FirstOrDefault(); + str = $"鍘熻揣浣嶇紪鍙凤細{inventory.stationCode}锛涚幇璐т綅缂栧彿锛歿stationCode}锛汼N鍙凤細{inventory.SN}"; + List<detail1> list1 = new List<detail1>(); + detail1 detail = new detail1(); + detail.sn = inventory.SN; + list1.Add(detail); + agvMoveWarehousePara moveWarehousePara = new agvMoveWarehousePara() + { + fromZoneID = inventory.stationCode, + toZoneID = stationCode, + details = list1, + fromLayerNo = "1", + fromStackID = "1", + fromWarehouseName = "Agv搴�", + toLayerNo = "1", + toStackID = "1", + toWarehouseName = "Agv搴�", + Operator = UserContext.Current.UserName, + }; + var postJson = JsonConvert.SerializeObject(moveWarehousePara); + var mesData = Request.RequestData(postJson, MESAPIAddress.IPAddress_MES + "agvMoveWarehouse"); + 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", "WMS", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆绉诲簱", "agvMoveWarehouse", requestMes.message); + inventory.stationCode = stationCode; + _repository.Update(inventory, true); + WriteDBLog.Write($"鎵嬪姩绉诲簱搴撳瓨 ", str, LogState.Sucess, "WMS", UserContext.Current.UserName); + } + else + { + WriteWMSLog.LogAdd("", "澶辫触", "MES", "WMS", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆绉诲簱", "agvMoveWarehouse", requestMes.message); + throw new Exception("浜哄伐鍚屾MES杞﹁疆绉诲簱澶辫触锛�" + requestMes.message); + } + + content.OK(); + } + catch (Exception ex) + { + content.Message = ex.Message; + WriteDBLog.Write($"鎵嬪姩绉诲簱搴撳瓨 ", new { 閿欒淇℃伅 = ex.Message, 鏁版嵁 = str }, LogState.Error, "WMS", UserContext.Current.UserName); + } + return content; + //return base.Update(saveModel); + } + /// <summary> + /// 鍒犻櫎搴撳瓨 + /// </summary> + /// <param name="keys"></param> + /// <param name="delList"></param> + /// <returns></returns> public override WebResponseContent Del(object[] keys, bool delList = true) { WebResponseContent content = new WebResponseContent(); @@ -49,17 +228,70 @@ try { List<string> KeyList = new List<string>(); - foreach ( string key in keys ) + foreach (string key in keys) { KeyList.Add(key); } - var inventoryList= _repository.Find(x=>KeyList.Contains(x.ID.ToString())).ToList(); - str = $"{string.Join('銆�', inventoryList.Select(t => t.SN).ToArray())}"; - content = base.Del(keys, delList); - WriteDBLog.Write($"鎵嬪姩鍒犻櫎搴撳瓨 ", str, LogState.Sucess, "WMS", UserContext.Current.UserName); + var inventoryList = _repository.Find(x => KeyList.Contains(x.ID.ToString())).ToList(); + //str = $"{string.Join('銆�', inventoryList.Select(t => t.SN).ToArray())}"; + foreach (var inventorys in inventoryList.GroupBy(x => x.stationCode)) + { + try + { + List<detail> lists = new List<detail>(); + foreach (var inventory in inventorys) + { + detail detail = new detail(); + detail.sn = inventory.SN; + lists.Add(detail); + 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", "WMS", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆鍑哄簱", "agvOutWarehouse", requestMes.message); + + foreach (var inventory in inventorys) + { + _repository.Delete(inventory, true); + } + WriteDBLog.Write($"鎵嬪姩鍒犻櫎搴撳瓨 ", $"璐т綅缂栧彿锛歿inventorys.Key}锛汼N鍙凤細{str}", LogState.Sucess, "WMS", UserContext.Current.UserName); + } + else + { + WriteWMSLog.LogAdd("", "澶辫触", "MES", "WMS", postJson, mesData, "浜哄伐鍚屾MES杞﹁疆鍑哄簱", "agvOutWarehouse", requestMes.message); + throw new Exception("浜哄伐鍚屾MES杞﹁疆鍑哄簱澶辫触锛�" + requestMes.message); + } + } + catch (Exception ex) + { + content.Message = ex.Message; + WriteDBLog.Write($"鎵嬪姩鍒犻櫎搴撳瓨 ", new { 閿欒淇℃伅 = ex.Message, 鏁版嵁 = str }, LogState.Error, "WMS", UserContext.Current.UserName); + } + + } + content.OK(); + //content = base.Del(keys, delList); + //WriteDBLog.Write($"鎵嬪姩鍒犻櫎搴撳瓨 ", str, LogState.Sucess, "WMS", UserContext.Current.UserName); } catch (Exception ex) { + content.Message = ex.Message; WriteDBLog.Write($"鎵嬪姩鍒犻櫎搴撳瓨 ", new { 閿欒淇℃伅 = ex.Message, 鏁版嵁 = str }, LogState.Error, "WMS", UserContext.Current.UserName); } -- Gitblit v1.9.3