From 73a926018601d9a5a5a3d3f4c051537f45a8eff4 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期四, 14 三月 2024 09:33:38 +0800 Subject: [PATCH] 优化代码逻辑 --- 代码管理/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs | 86 ++++++++++++++++++++++++++++++++++++++---- 1 files changed, 77 insertions(+), 9 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs" index e953d35..25caaff 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs" @@ -15,6 +15,7 @@ using WIDESEA_Core.EFDbContext; using WIDESEA_Core.Extensions; using WIDESEA_Core.FreeDB; +using WIDESEA_Entity.DomainModels; using WIDESEA_WCS.IRepositories; using WIDESEA_WCS.Jobs; using WIDESEA_WCS.Repositories; @@ -85,25 +86,36 @@ ///鏌ユ壘涓婃枡鍖虹殑璐т綅 - var Stations = stationinfoRepository.Find(x => x.area == "6"); + var Stations = stationinfoRepository.Find(x => x.area == area_code(number)); //缂撳瓨鏋舵湭鍚敤绂佹妗佹灦杩涘叆 foreach (var station in Stations) { - if (!station.enable) + if (!station.enable || station.location_state != LocationStateEnum.Stroge.ToString()) Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆 } - var Station = Stations?.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.quantity).First(); + var Station = Stations?.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.quantity).FirstOrDefault(); if (Station != null) { var SNS = Station.bindSN.Split(","); + List<string> list = new List<string>(); + foreach (var SN in SNS) + { + if (!string.IsNullOrEmpty(SN)) + list.Add(SN); + } //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷� - if (SNS.Length != Station.quantity) + if (list.Count != Station.quantity) { Station.location_state = LocationStateEnum.Abnormal.ToString(); + Station.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�"; stationinfoRepository.Update(Station, true); Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆 - throw new Exception("涓婃枡浣嶈溅杞暟閲忎笌SN鍙锋暟閲忎笉涓�鑷达紝涓婃枡浣嶇紪鍙凤細" + Station.stationCode); + #region 鏃ュ織璁板綍 + WriteDBLog.Error("涓婃枡鍖�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�", "PCS"); + #endregion + return; + //throw new Exception("涓婃枡浣嶈溅杞暟閲忎笌SN鍙锋暟閲忎笉涓�鑷达紝涓婃枡浣嶇紪鍙凤細" + Station.stationCode); } var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == Station.stationCode).ToList(); var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃� @@ -114,9 +126,14 @@ Gantry_client.WriteByOrder("W_AreaNr", (Int16)area, number);//鍖哄煙璐т綅鍙� Gantry_client.WriteByOrder("W_IndexNr", (Int16)SNS.Length, number);//鎵樼洏涓婄殑绗嚑涓溅杞� Gantry_client.WriteByOrder("W_Storage_Type", (Int16)1, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁 - Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(Station.stationType), number);//杞﹁疆绫诲瀷 + Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(QueryMateriel(Station.stationType).TypeId), number);//杞﹁疆绫诲瀷 Gantry_client.WriteByOrder("W_Wheel_id", SNS[SNS.Length - 1], number);//杞﹁疆SN鍙� Gantry_client.WriteByOrder("W_RequestUnload", true, number); + #region 鏃ュ織璁板綍 + WriteDBLog.Success("涓婃枡鍖虹敵璇�", $"璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}\n璇诲彇绗竴涓溅杞厜鐢典俊鍙凤細{MaterialSignal}\n\n" + + $"鍐欏叆妗佹灦淇℃伅锛歕n鍖哄煙璐т綅鍙凤細{area}\n鎵樼洏涓婄殑绗嚑涓溅杞細{SNS.Length}\n鎵樼洏绫诲瀷锛歿1}\n杞﹁疆绫诲瀷锛歿QueryMateriel(Station.stationType).TypeId}" + + $"\n杞﹁疆SN鍙凤細{SNS[SNS.Length - 1]}\nW_RequestUnload锛歵rue", "PCS"); + #endregion } else { @@ -133,28 +150,65 @@ if (!Date_Vaild)//淇℃伅鏈夎锛岃褰曟棩蹇� { Station.location_state = LocationStateEnum.Abnormal.ToString(); + Station.remark = $"鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�"; stationinfoRepository.Update(Station, true); Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆 - throw new Exception($"鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗曪紝涓婃枡浣嶇紪鍙凤細{Station.stationCode}"); + //throw new Exception($"鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗曪紝涓婃枡浣嶇紪鍙凤細{Station.stationCode}"); + WriteDBLog.Error("涓婃枡鍖轰俊鎭煡璇�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�", "PCS"); + return; } } var finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);//澶瑰彇瀹屾垚 - if (finished) + var updatefinished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "W_Storage_update").First(), Gantry_client);//璐т綅鐘舵�佹洿鏂� + if (!finished && updatefinished) + Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂� + if (finished && !updatefinished) { Station.quantity = Station.quantity - 1; Station.bindSN = OperStr(SNS); + if (Station.quantity <= 0) + { + Station.stationType = string.Empty; + //Station.location_state = LocationStateEnum.Empty.ToString(); + Station.Number = string.Empty; + Station.heatNumber = string.Empty; + } var count = stationinfoRepository.Update(Station, true); if (count < 1) - throw new Exception($"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{Station.stationCode}"); + { + WriteDBLog.Error("鍙栨枡瀹屾垚", $"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{Station.stationCode}", "PCS"); + //throw new Exception($"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{Station.stationCode}"); + return; + } Gantry_client.WriteByOrder("W_Storage_update", true, number);//璐т綅鐘舵�佹洿鏂� Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆 + #region 鏃ュ織璁板綍 + WriteDBLog.Success("鍙栨枡瀹屾垚", $"鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂帮細{true}\nW_RequestUnload锛歿false}", "PCS"); + #endregion + //finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client); + //while (finished) + //{ + // finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client); + // Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂� + //} } + //else if (!finished && updatefinished) + // Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂� + } + else + Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆 } catch (Exception ex) { //WritePCSLog.LogAdd(requestin.AreaNr.ToString(), respone.success == 1 ? "鎴愬姛 " : "澶辫触", "WMS", "AGV", json, JsonConvert.SerializeObject(respone), remark, "妫�娴嬬嚎涓婃枡鍖�", ex.Message); } + } + public static string area_code(string area_name) + { + FreeDB freeDB = new FreeDB(); + var areainfo = freeDB.Select<dt_areainfo>().Where(x => x.area_name == area_name).First(); + return areainfo.area_code.ToString(); } private string OperStr(string[] strArrty) @@ -164,5 +218,19 @@ return Newsn; } + public static dt_geometry_data QueryMateriel(string type) + { + VOLContext Context = new VOLContext(); + Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context); + var materielinfo = dataRepository.Find(x => x.Description == type).OrderBy(x => x.TypeId).FirstOrDefault(); + return materielinfo; + } + public static string QueryMateriel(int typeId) + { + VOLContext Context = new VOLContext(); + Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context); + var materielinfo = dataRepository.FindFirst(x => x.TypeId == typeId); + return materielinfo.Description; + } } } -- Gitblit v1.9.3