From ede3b3103cc39dbfff9c93e9a08fb1a9855387e4 Mon Sep 17 00:00:00 2001 From: lss <2538410689@qq.com> Date: 星期四, 24 七月 2025 17:31:55 +0800 Subject: [PATCH] 大车间 --- HH.WCS.Mobox3 - 大车间/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs | 336 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 293 insertions(+), 43 deletions(-) diff --git "a/HH.WCS.Mobox3 - \345\244\247\350\275\246\351\227\264/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs" "b/HH.WCS.Mobox3 - \345\244\247\350\275\246\351\227\264/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs" index a36c9f6..478b8ee 100644 --- "a/HH.WCS.Mobox3 - \345\244\247\350\275\246\351\227\264/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs" +++ "b/HH.WCS.Mobox3 - \345\244\247\350\275\246\351\227\264/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs" @@ -1,9 +1,9 @@ -锘縰sing HH.WCS.JiaTong.device; -using HH.WCS.JiaTong.dispatch; -using HH.WCS.JiaTong.LISTA.models; -using HH.WCS.JiaTong.process; -using HH.WCS.JiaTong.util; -using HH.WCS.JiaTong.wms; +锘縰sing HH.WCS.JiaTong_DCJ.device; +using HH.WCS.JiaTong_DCJ.dispatch; +using HH.WCS.JiaTong_DCJ.LISTA.models; +using HH.WCS.JiaTong_DCJ.process; +using HH.WCS.JiaTong_DCJ.util; +using HH.WCS.JiaTong_DCJ.wms; using Newtonsoft.Json; using NLog.Fluent; using S7.Net; @@ -17,12 +17,12 @@ 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; -using static HH.WCS.JiaTong.util.Settings; +using static HH.WCS.JiaTong_DCJ.api.ApiModel; +using static HH.WCS.JiaTong_DCJ.api.OtherModel; +using static HH.WCS.JiaTong_DCJ.LISTA.process.HttpModel; +using static HH.WCS.JiaTong_DCJ.util.Settings; -namespace HH.WCS.JiaTong.api +namespace HH.WCS.JiaTong_DCJ.api { /// <summary> /// api鎺ュ彛杈呭姪绫�@@ -39,13 +39,247 @@ public static object _lockCreateTask = new object(); - - - - + /// <summary> + /// 绔嬪簱浠诲姟涓嬪彂=銆嬪垱寤轰换鍔�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + internal static Result Createtask(CreateTask model) + { + + Result result = new Result() { code = "0", msg = "鍒涘缓鎴愬姛" }; + if (model == null) + { + LogHelper.Info($"Createtask==> 鍙傛暟涓簄ull"); + result.code = "1"; + result.msg = "鍙傛暟涓簄ull鍊硷紝璇锋鏌ュ弬鏁版牸寮�; + AddErrorInfo("涓嬪彂鍙傛暟涓簄ull", result.msg); + return result; + } + partData partData = model.partData; + taskData taskData = model.taskData; + + try + { + var db = new SqlHelper<object>().GetInstance(); + string CntrCode = "";//鎵樼洏缂栫爜 + string ItemCode = "";//鐗╂枡缂栫爜 + if (partData != null) + { + CntrCode = partData.rfid;//鎵樼洏缂栫爜 + ItemCode = partData.partNumber;//鐗╂枡缂栫爜 + } + string Start = ""; //鍙栬揣鐐�+ string End = ""; + string note = ""; //绔嬪簱涓嬪彂浠诲姟闇�閫氱煡mes鎺ュ彛鐗╂枡鍒颁綅锛岀敤澶囨敞鑷姩杩涜鍖哄垎 + //鏍规嵁鐗╂枡鑾峰彇瀵瑰簲搴撳尯 + #region 鏍规嵁浠诲姟鏉ユ簮瀛楁鍒ゆ柇搴撳尯鏉ユ簮鏉ユ簮 + //var iteminfo = db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE.Trim() == ItemCode).First(); + //if (iteminfo != null) + //{ + // //LogHelper.Info($"Createtask==>鐗╂枡鏁版嵁:{JsonConvert.SerializeObject(iteminfo)}"); + // areacode = iteminfo.S_WH_CODE; + //} + + //if (string.IsNullOrEmpty(areacode)) + //{ + // LogHelper.Info($"Createtask==>鏍规嵁鐗╂枡缂栫爜:{ItemCode}鏈兘鎵惧埌鐗╂枡鏉ユ簮锛岄渶鍚屾鐗╂枡鏁版嵁"); + // result.code = "1"; + // result.msg = $"鏍规嵁鐗╂枡缂栫爜:{ItemCode}鏈兘鎵惧埌鐗╂枡鏉ユ簮锛岄渶鍚屾鐗╂枡鏁版嵁"; + // AddErrorInfo("瀵绘壘鍑哄簱鍖哄け璐�, result.msg); + // return result; + //} + string state = "绛夊緟"; + int n_type = 0; //浠诲姟鏉ユ簮 1.瀵嗙偧绔嬪簱 3.棰勫搴�,4.鍘熸潗鏂欏簱 + string Source = ""; + switch (taskData.source) + { + case "ML": + n_type = 1; + Source = "瀵嗙偧"; + break; + case "YBK": + n_type = 2; + Source = "棰勫搴�; + state = "绛夊緟鎺ㄩ�"; + break; + + } + Console.WriteLine($"Createtask==>浠诲姟鏉ユ簮:{n_type}"); + if (n_type == 0) + { + result.code = "1"; + result.msg = $"浠诲姟鏉ユ簮:{taskData.source}灞炰簬鏈畾涔夊簱鍖猴紝璇锋鏌ョ墿鏂欐潵婧愭槸鍚﹀睘浜庣害瀹氬瓧娈�; + AddErrorInfo("浠诲姟鏉ユ簮鏈畾涔�, result.msg); + return result; + } + + + #endregion + + Location endloc = null; + Location startloc = null; + lock (_lockCreateTask) + { + note = "鍑哄簱"; + //鍒涘缓鎵樼洏鐗╂枡缁戝畾淇℃伅锛屽苟璁$畻缁堢偣璐т綅 + startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First(); + if (startloc != null) + { + Start = taskData.pickStation; + } + else + { + result.code = "1"; + result.msg = $"鏍规嵁璧风偣{taskData.pickStation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃"; + AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source); + return result; + } + endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First(); + if (endloc != null) + { + End = taskData.dropStation; + } + else + { + result.code = "1"; + result.msg = $"鏍规嵁缁堢偣{taskData.dropStation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃"; + AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source); + return result; + } + + if (!string.IsNullOrEmpty(Start) && !string.IsNullOrEmpty(End)) + { + if (startloc.N_LOCK_STATE != 0) + { + result.code = "1"; + result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐箋Start}鏈夐攣"; + AddErrorInfo("璐т綅鏈夐攣", result.msg); + return result; + } + var startArea = db.Queryable<Area>().Where(a => a.S_CODE.Trim() == startloc.S_AREA_CODE.Trim()).First(); + var endArea = db.Queryable<Area>().Where(a => a.S_CODE.Trim() == endloc.S_AREA_CODE.Trim()).First(); + if (startArea == null || endArea == null) + { + LogHelper.Info($"璧风偣锛歿JsonConvert.SerializeObject(startArea)}"); + LogHelper.Info($"缁堢偣锛歿JsonConvert.SerializeObject(endArea)}"); + result.code = "1"; + result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐�{startloc.S_AREA_CODE},缁堢偣{endloc.S_AREA_CODE}鏈壘鍒板搴斿簱鍖�; + AddErrorInfo("搴撳尯鏌ユ壘澶辫触", result.msg); + return result; + } + + //鍒涘缓wcs浠诲姟 + var wcsTask = new WCSTask + { + S_CODE = WCSHelper.GenerateTaskNo(), + S_TYPE = startArea.S_NAME + "->" + endArea.S_NAME, + S_EQ_NO = taskData.taskNum, + S_START_LOC = Start, + S_END_LOC = End, + N_CNTR_COUNT = 1, + S_START_WH = startloc.S_WH_CODE, + S_END_WH = endloc.S_WH_CODE, + S_END_AREA = endloc.S_AREA_CODE, + N_SCHEDULE_TYPE = 1, + S_CNTR_CODE = CntrCode, + N_PRIORITY = 1, + Z_TYPE = n_type, + N_START_LAYER = 1, + N_END_LAYER = 1, + S_WMS_NO = taskData.wmsTaskNo, + S_NOTE = note, + S_B_STATE = state, + S_MES_NO = taskData.mesTaskNo + + }; + LogHelper.Info("鍒涘缓浠诲姟锛� + JsonConvert.SerializeObject(wcsTask), "CreateTask"); + if (WCSHelper.CreateTask(wcsTask)) + { + // LocationHelper.LockLoc(Start, 2); + //LocationHelper.LockLoc(End, 1); + LogHelper.Info("鍒涘缓浠诲姟鎴愬姛"); + } + else + { + result.code = "1"; + result.msg = $"浠诲姟鍒涘缓澶辫触"; + AddErrorInfo("浠诲姟鍒涘缓澶辫触", result.msg, Source); + return result; + } + } + else + { + result.code = "1"; + result.msg = "鍒涘缓浠诲姟澶辫触锛屾湭鎵惧埌瀵瑰簲鐨勫彇璐х偣鎴栧嵏璐х偣"; + return result; + } + + } + + return result; + } + catch (Exception ex) + { + + result.code = "1"; + result.msg = ex.ToString(); + LogHelper.Error("Createtask Error锛� + ex.ToString() + "琛屽彿:" + ex.StackTrace, ex); + return result; + } + + + } + + + /// <summary> + /// 棰勫搴撲换鍔$姸鎬佷笅鍙�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + internal static Result MstStateInquire(MstStateInquire model) + { + Result result = new Result() { code = "200", msg = "鐘舵�涓嬪彂鎴愬姛" }; + var db = new SqlHelper<object>().GetInstance(); + if (model == null) + { + LogHelper.Info($"MstStateInquire==> 鍙傛暟涓簄ull"); + result.code = "1"; + result.msg = "鍙傛暟涓簄ull鍊硷紝璇锋鏌ュ弬鏁版牸寮�; + AddErrorInfo("鍙傛暟涓虹┖", result.msg); + return result; + } + try + { + //鎵惧埌浠诲姟锛屼慨鏀逛换鍔$姸鎬�+ var task = db.Queryable<WCSTask>().Where(a => a.S_EQ_NO.Trim() == model.taskNum).First(); + if (task != null) + { + task.S_B_STATE ="绛夊緟"; + db.Updateable(task).UpdateColumns(a => new { a.S_B_STATE}).ExecuteCommand(); + } + else + { + result.code = "1"; + result.msg = $"鏍规嵁涓嬪彂浠诲姟鍙穥model.taskNum}鏈壘鍒板搴斾换鍔�; + AddErrorInfo("鏈壘鍒颁换鍔�, result.msg); + return result; + } + return result; + } + catch (Exception ex) + { + result.code = "1"; + result.msg = ex.ToString(); + LogHelper.Error("TrayItembind Error锛� + ex.ToString(), ex); + return result; + } + + } + public static object _Point = new object(); /// <summary> @@ -55,7 +289,7 @@ /// <returns></returns> internal static Result Point(PointModel model) { - Result result = new Result() { code = "200", msg = "鍏ュ钩搴撲换鍔′笅鍙戞垚鍔� }; + Result result = new Result() { code = "200", msg = "浠诲姟涓嬪彂鎴愬姛" }; string Source = "Mes"; if (model == null) @@ -108,25 +342,25 @@ AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source); return result; } - else - { - //鍒ゆ柇璧风偣鏄惁缁戝畾鍏朵粬鎵樼洏 - var CntrRel = LocationHelper.GetLocCntrRel(startloc.S_CODE).OrderBy(a => a.T_CREATE).FirstOrDefault(); - if (CntrRel != null) - { - if (CntrRel.S_CNTR_CODE != model.Rfid) - { - result.code = "1"; - result.msg = $"鏍规嵁璧风偣锛歿model.InitialLocation}鑾峰彇鎵樼洏:{CntrRel.S_CNTR_CODE}涓庝笅鍙戞墭鐩橈細{model.Rfid}涓嶄竴鑷达紝璇锋鏌ユ墭鐩樼爜鏄惁姝g‘"; - AddErrorInfo("鎵樼洏鐮佹牎妫�け璐�, result.msg, Source); - return result; - } - } - else - { - LocationHelper.BindingLoc(startloc.S_CODE, new List<string> { model.Rfid }); - } - } + //else + //{ + // //鍒ゆ柇璧风偣鏄惁缁戝畾鍏朵粬鎵樼洏 + // var CntrRel = LocationHelper.GetLocCntrRel(startloc.S_CODE).OrderBy(a => a.T_CREATE).FirstOrDefault(); + // if (CntrRel != null) + // { + // if (CntrRel.S_CNTR_CODE != model.Rfid) + // { + // result.code = "1"; + // result.msg = $"鏍规嵁璧风偣锛歿model.InitialLocation}鑾峰彇鎵樼洏:{CntrRel.S_CNTR_CODE}涓庝笅鍙戞墭鐩橈細{model.Rfid}涓嶄竴鑷达紝璇锋鏌ユ墭鐩樼爜鏄惁姝g‘"; + // AddErrorInfo("鎵樼洏鐮佹牎妫�け璐�, result.msg, Source); + // return result; + // } + // } + // else + // { + // LocationHelper.BindingLoc(startloc.S_CODE, new List<string> { model.Rfid }); + // } + //} endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.TargetLocation).First(); if (endloc == null) { @@ -217,7 +451,7 @@ } } - + /// <summary> /// 璐т綅淇℃伅涓婁紶 /// </summary> @@ -243,7 +477,7 @@ result1.UseToken = "iFQ5fExGrLYLXliHYWzs"; upload.LocationNum = loc.S_CODE; upload.Type = loc.S_TYPE; - upload.LockState =loc.S_LOCK_STATE; + upload.LockState = loc.S_LOCK_STATE; upload.WorkCenter = loc.S_AREA_CODE; upload.Warehouse = loc.S_AREA_CODE; listuploadloc.Add(upload); @@ -263,7 +497,7 @@ var url = Settings.tableUrls.Find(a => a.id == 3); if (url != null) { - LogHelper.Info($"璐т綅涓婃姤涓婃姤锛氬湴鍧�{url}锛屽唴瀹癸細{date}"); + LogHelper.Info($"璐т綅涓婃姤涓婃姤锛氬湴鍧�{url.url}锛屽唴瀹癸細{date}"); var r = httpHelper.MesWebPost(url.url, date); result = JsonConvert.DeserializeObject<Result>(r); if (result.code == "200") @@ -276,7 +510,7 @@ result.code = "1"; result.msg = result.msg; } - ApiHelper.AddInfo("Mes", "Mes鐐瑰鐐逛换鍔′笅鍙�, JsonConvert.SerializeObject(date), JsonConvert.SerializeObject(result), "Post", url.url); + ApiHelper.AddInfo("Mes", "璐т綅鍚屾", JsonConvert.SerializeObject(date), JsonConvert.SerializeObject(result), "Post", url.url); } else @@ -298,8 +532,8 @@ var db = new SqlHelper<HangChaAGV>().GetInstance(); DeviceInfoModel device = new DeviceInfoModel(); - // List<DeviceInfos> deviceInfos = new List<DeviceInfos>();//鍙犵洏鏈烘姤閿欎俊鎭�- // List<AgvInfos> agvInfos = new List<AgvInfos>();//agv鎶ラ敊淇℃伅 + // List<DeviceInfos> deviceInfos = new List<DeviceInfos>();//鍙犵洏鏈烘姤閿欎俊鎭�+ // List<AgvInfos> agvInfos = new List<AgvInfos>();//agv鎶ラ敊淇℃伅 //鑾峰彇鍐呭瓨涓彔鐩樻満鐨勬姤閿欎俊鎭� //foreach (var dpjInfo in DeviceProcess.DpjInfoDirectory) @@ -321,7 +555,7 @@ // deviceInfos.Add(new DeviceInfos() { AgvNo = agv.agvNo, AgvInfo = agvErrorInfo }); //} } - // device.DeviceInfos = deviceInfos; + // device.DeviceInfos = deviceInfos; return device; } @@ -394,7 +628,23 @@ #endregion #region 鍚堣偉浣抽�涓氬姟鏂规硶 + /// <summary> + /// 绔嬪簱浠诲姟涓嬪彂鍒涘缓鎵樼洏鐗╂枡缁戝畾鍏崇郴 + /// </summary> + internal static bool CreateCntrIteminfo(partData partData, taskData taskData) + { + if (partData == null && taskData == null) + { + LogHelper.Info($"CreateCntrIteminfo==> 绔嬪簱浠诲姟涓嬪彂鍙傛暟鏈夌┖锛屽垱寤虹墿鏂欐墭鐩樼粦瀹氬叧绯诲け璐�); + return false; + } + else + { + return ContainerHelper.CreateCntrItem(taskData.pickStation, partData.rfid, partData.partNumber, partData.partDesc, partData.partType, taskData.carrierType, partData.lotNumber, taskData.wmsLot, partData.weight, partData.unit, + taskData.tyreType, taskData.supplier, taskData.receiveLot, taskData.subpool, partData.productionTime, partData.maturityTime, taskData.level, partData.qty, partData.qtyCfg); + } + } /// <summary> /// 鎵樼洏鍏ュ簱绠楁硶 @@ -527,7 +777,7 @@ return result; } - + //internal static bool CreateCntrLoc(taskData taskData) //{ -- Gitblit v1.9.1