From 9cba325e0d7c30644606e63e5df01faba0c42038 Mon Sep 17 00:00:00 2001 From: lss <2538410689@qq.com> Date: 星期三, 06 八月 2025 17:18:41 +0800 Subject: [PATCH] 优化 --- HH.WCS.Mobox3 - 大车间/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs | 257 +++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 215 insertions(+), 42 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 4cdb138..ce27583 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" @@ -92,7 +92,7 @@ // AddErrorInfo("瀵绘壘鍑哄簱鍖哄け璐�, result.msg); // return result; //} - + string state = "绛夊緟"; int n_type = 0; //浠诲姟鏉ユ簮 1.瀵嗙偧绔嬪簱 3.棰勫搴�,4.鍘熸潗鏂欏簱 string Source = ""; switch (taskData.source) @@ -104,6 +104,10 @@ case "YBK": n_type = 2; Source = "棰勫搴�; + if (taskData.taskType == 1) + { + state = "绛夊緟鎺ㄩ�"; + } break; } @@ -170,15 +174,7 @@ AddErrorInfo("搴撳尯鏌ユ壘澶辫触", result.msg); return result; } - int pri = 1; - var area = Settings.wareLoc.Where(a => a.AreaCode == endloc.S_WH_CODE).First(); - if (area != null) - { - if (area.XbAreaCodes.Contains(endloc.S_AREA_CODE)) - { - pri = 2; - } - } + //鍒涘缓wcs浠诲姟 var wcsTask = new WCSTask { @@ -193,12 +189,13 @@ S_END_AREA = endloc.S_AREA_CODE, N_SCHEDULE_TYPE = 1, S_CNTR_CODE = CntrCode, - N_PRIORITY = pri, + 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 }; @@ -241,8 +238,183 @@ } + /// <summary> + /// 棰勫搴撲换鍔$姸鎬佷笅鍙�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + internal static Result MstStateInquire(MstStateInquire model) + { + Result result = new Result() { code = "0", 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) + { + if (task.S_B_STATE != "绛夊緟鎺ㄩ�") + { + result.code = "1"; + result.msg = $"鎺ㄩ�澶辫触锛屼换鍔″凡缁忓鐞�; + AddErrorInfo("鎺ㄩ�澶辫触", result.msg); + return result; + } + task.S_B_STATE = "绛夊緟"; + if (db.Updateable(task).UpdateColumns(a => new { a.S_B_STATE }).ExecuteCommand() < 0) + { + result.code = "1"; + result.msg = $"鎺ㄩ�澶辫触锛屼慨鏀逛换鍔$姸鎬佸け璐ワ紝璇烽噸鏂颁笅鍙�; + AddErrorInfo("鎺ㄩ�澶辫触", result.msg); + return result; + } + } + 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; + } + + } + + /// <summary> + /// 鐐瑰鐐逛换鍔″垱寤�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + internal static Result CreatTask(CreatTask model) + { + Result result = new Result() { code = "0", msg = "鐐瑰鐐逛换鍔″垱寤烘垚鍔� }; + string Source = "MES"; + if (model == null) + { + result.code = "1"; + result.msg = "鍙傛暟涓簄ull"; + AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source); + return result; + } + string Start = ""; //鍙栬揣鐐�+ var db = new SqlHelper<object>().GetInstance(); + // string CntrCode = model.partData.rfid;//鎵樼洏缂栫爜 + // string ItemCode = model.partData.partNumber;//鐗╂枡缂栫爜 + string End = ""; + string CntrCode = ""; + Location endloc = new Location(); + Location startloc = new Location(); + try + { + startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.InitialLocation).First(); + if (startloc != null) + { + Start = model.InitialLocation; + } + else + { + result.code = "1"; + result.msg = $"鏍规嵁璧风偣{model.InitialLocation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃"; + AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source); + return result; + } + endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.TargetLocation).First(); + if (endloc != null) + { + End = model.TargetLocation; + } + else + { + result.code = "1"; + result.msg = $"鏍规嵁缁堢偣{model.TargetLocation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃"; + AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source); + return result; + } + #region 鍒涘缓浠诲姟 + if (!string.IsNullOrEmpty(Start) && !string.IsNullOrEmpty(End)) + { + if (startloc.N_LOCK_STATE != 0) + { + result.code = "1"; + result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐箋Start}鏈夐攣"; + AddErrorInfo("璐т綅鏈夐攣", result.msg); + return result; + } + //鍒涘缓wcs浠诲姟 + var wcsTask = new WCSTask + { + S_CODE = WCSHelper.GenerateTaskNo(), + // S_TYPE = model.taskData.taskType.ToString(), + // S_EQ_NO = model.taskData.taskNum, + S_START_LOC = Start, + S_END_LOC = End, + N_CNTR_COUNT = 1, + S_START_WH = startloc.S_WH_CODE, + S_START_AREA = startloc.S_AREA_CODE, + S_END_WH = endloc.S_WH_CODE, + S_END_AREA = endloc.S_AREA_CODE, + N_SCHEDULE_TYPE = 1, + S_CNTR_CODE = CntrCode, + N_START_LAYER = 1, + N_END_LAYER = 1, + N_PRIORITY = 1, + // N_TYPE = n_type + }; + LogHelper.Info("鍒涘缓浠诲姟锛� + JsonConvert.SerializeObject(wcsTask), "CreateTask"); + if (WCSHelper.CreateTask(wcsTask)) + { + //LocationHelper.LockLoc(Start, 2); + //LocationHelper.LockLoc(End, 1); + LogHelper.Info("鍒涘缓浠诲姟鎴愬姛"); + return result; + } + else + { + result.code = "1"; + result.msg = $"浠诲姟鍒涘缓澶辫触"; + AddErrorInfo("浠诲姟鍒涘缓澶辫触", result.msg, Source); + return result; + } + } + else + { + result.code = "1"; + result.msg = "鍒涘缓浠诲姟澶辫触锛屾湭鎵惧埌瀵瑰簲鐨勫彇璐х偣鎴栧嵏璐х偣"; + return result; + } + #endregion + + return result; + + } + catch (Exception ex) + { + + result.code = "1"; + result.msg = $"鐗╂枡涓绘暟鎹垱寤哄け璐�閿欒淇℃伅锛歿ex}"; + LogHelper.Error("鐐瑰鐐逛换鍔�Error锛� + ex.ToString(), ex); + return result; + } + + } public static object _Point = new object(); /// <summary> @@ -252,7 +424,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) @@ -305,25 +477,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) { @@ -428,21 +600,22 @@ RequestList<UploadLoc> result1 = new RequestList<UploadLoc>(); List<UploadLoc> listuploadloc = new List<UploadLoc>(); var db = new SqlHelper<object>().GetInstance(); + //鑾峰彇鏃堕棿鎴�+ var time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); + result1.RequestId = "鏉弶AGV" + time; + result1.UseToken = "iFQ5fExGrLYLXliHYWzs"; foreach (var item in model) { var loc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == item.Location).First(); if (loc != null) { UploadLoc upload = new UploadLoc(); - //鑾峰彇鏃堕棿鎴�- var time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); - result1.RequestId = "鏉弶AGV" + time; - result1.UseToken = "iFQ5fExGrLYLXliHYWzs"; - upload.LocationNum = loc.S_CODE; - upload.Type = loc.S_TYPE; - upload.LockState = loc.S_LOCK_STATE; - upload.WorkCenter = loc.S_AREA_CODE; - upload.Warehouse = loc.S_AREA_CODE; + + upload.locationNum = loc.S_CODE; + upload.type = loc.S_TYPE; + upload.lockState = loc.S_LOCK_STATE; + upload.workCenter = loc.S_AREA_CODE; + upload.warehouse = loc.S_AREA_CODE; listuploadloc.Add(upload); } else @@ -460,7 +633,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") @@ -473,7 +646,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 -- Gitblit v1.9.1