From 9ddec4808631025d36d3c5a816d55ef77a29d4c7 Mon Sep 17 00:00:00 2001 From: lss <2538410689@qq.com> Date: 星期三, 16 七月 2025 17:30:30 +0800 Subject: [PATCH] 111 --- HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs | 329 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 269 insertions(+), 60 deletions(-) diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs index 0f89ebf..68fe676 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs @@ -47,6 +47,7 @@ /// <returns></returns> internal static Result Createtask(CreateTask model) { + Result result = new Result() { code = "0", msg = "鍒涘缓鎴愬姛" }; if (model == null) { @@ -187,7 +188,7 @@ } } - + } else { @@ -584,13 +585,13 @@ } int pri = 1; var area = Settings.wareLoc.Where(a => a.AreaCode == endloc.S_WH_CODE).First(); - if (area != null) + if (area != null) { if (area.XbAreaCodes.Contains(endloc.S_AREA_CODE)) { pri = 2; } - } + } //鍒涘缓wcs浠诲姟 var wcsTask = new WCSTask { @@ -794,6 +795,176 @@ + } + + public static object _Point = new object(); + /// <summary> + /// 鐐瑰鐐规帴鍙�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + internal static Result Point(PointModel model) + { + Result result = new Result() { code = "200", msg = "鍏ュ钩搴撲换鍔′笅鍙戞垚鍔� }; + string Source = "Mes"; + + if (model == null) + { + result.code = "1"; + result.msg = "鍙傛暟涓簄ull"; + AddErrorInfo("鍙傛暟涓虹┖", result.msg, Source); + return result; + } + //1.鍑哄钩搴擄紝2鍏ュ钩搴擄紝3骞冲簱绌哄伐瑁呭懠鍙紝4骞冲簱浣欐枡鍥炲簱锛�绮夋枡绌烘墭杩斿洖銆�+ var db = new SqlHelper<object>().GetInstance(); + string type = ""; + Location startloc = null; + Location endloc = null; + switch (model.Status) + { + case "1": + type = "鍑哄钩搴�; + break; + case "2": + type = "鍏ュ钩搴�; + break; + case "3": + type = "骞冲簱绌哄伐瑁呭懠鍙�; + break; + case "4": + type = "骞冲簱浣欐枡鍥炲簱"; + break; + case "5": + type = "绮夋枡绌烘墭杩斿洖"; + break; + } + if (string.IsNullOrEmpty(type)) + { + result.code = "1"; + result.msg = $"浠诲姟绫诲瀷{model.Status},涓嶅湪瑙勫畾鑼冨洿"; + AddErrorInfo("浠诲姟绫诲瀷閿欒", result.msg, Source); + return result; + } + + try + { + lock (_Point) + { + startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.InitialLocation).First(); + if (startloc == null) + { + result.code = "1"; + result.msg = $"鏍规嵁璧风偣{model.InitialLocation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃"; + 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 }); + } + } + endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.TargetLocation).First(); + if (endloc == null) + { + result.code = "1"; + result.msg = $"鏍规嵁缁堢偣{model.TargetLocation},鎵句笉鍒板搴旇揣浣嶏紝璇锋鏌ヨ揣浣嶈〃"; + AddErrorInfo("璐т綅鏌ユ壘澶辫触", result.msg, Source); + return result; + } + + + #region 鍒涘缓浠诲姟 + if (endloc != null && startloc != null) + { + if (startloc.N_LOCK_STATE != 0) + { + result.code = "1"; + result.msg = $"鍒涘缓浠诲姟澶辫触锛岃捣鐐�{startloc.S_CODE}鏈夐攣"; + AddErrorInfo("璐т綅鏈夐攣", result.msg, Source); + return result; + } + //鍒涘缓wcs浠诲姟 + var wcsTask = new WCSTask + { + S_CODE = WCSHelper.GenerateTaskNo(), + S_TYPE = type, + S_EQ_NO = model.TaskNumber, + S_START_LOC = startloc.S_CODE, + S_END_LOC = endloc.S_CODE, + 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_CNTR_COUNT = 1, + N_SCHEDULE_TYPE = 1, + S_CNTR_CODE = model.Rfid, + N_START_LAYER = 1, + N_END_LAYER = 1, + N_PRIORITY = 1, + Z_TYPE = 5 + }; + LogHelper.Info("鍒涘缓鐐瑰鐐逛换鍔★細" + JsonConvert.SerializeObject(wcsTask)); + if (WCSHelper.CreateTask(wcsTask)) + { + if (type == "骞冲簱浣欐枡鍥炲簱") + { //鍒涘缓浠诲姟鎴愬姛 鏇存柊浣欐枡淇℃伅 + var CntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First(); + if (CntrItem != null) + { + CntrItem.F_WEIGHT = model.Weight.ToString(); + CntrItem.S_BS_TYPE = "浣欐枡"; + //CntrItem.F_QTY = float.Parse(model.qty); + //CntrItem.S_ITEM_STATE = model..QualityStatus; + + db.Updateable(CntrItem).UpdateColumns(a => new { a.F_WEIGHT, a.S_BS_TYPE }).ExecuteCommand(); + } + } + + LocationHelper.LockLoc(startloc.S_CODE, 2); + LocationHelper.LockLoc(endloc.S_CODE, 1); + LogHelper.Info("鍒涘缓浠诲姟鎴愬姛"); + } + 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.ToString(); + LogHelper.Error("Putin Error锛� + ex.ToString(), ex); + return result; + } } public static object _Putin = new object(); @@ -1092,27 +1263,51 @@ #region 鏍规嵁鐗╂枡缂栫爜璁$畻鍑哄簱璐т綅锛岄�寰�嚎杈逛綅缃� Location Endloc = null; + //鏍规嵁鐗╂枡缂栫爜璁$畻鍑哄簱璐т綅 var loc = airlift(areacode, itemcode, model.PartLevel, model.PowderType); if (loc != null) { Start = loc.S_CODE; - //鏍规嵁鍑哄簱璐т綅鎵惧埌缁戝畾鎵樼洏锛岃幏鍙栧叆鏈哄彴璐т綅 + var CntrRel = LocationHelper.GetLocCntrRel(loc.S_CODE).FirstOrDefault(); CntrCode = CntrRel.S_CNTR_CODE; - Endloc = Computeloc(CntrCode, model.WorkCenter, cntrType); - if (Endloc != null) + //缁欑粓鐐圭敤缁堢偣锛屾病缁欑粓鐐圭敤鏈哄彴搴撳尯璁$畻璐т綅 + if (string.IsNullOrEmpty(model.TargetLocation)) { - End = Endloc.S_CODE; + + Endloc = Computeloc(CntrCode, model.WorkCenter, cntrType); + if (Endloc != null) + { + End = Endloc.S_CODE; + } + else + { + result.code = "1"; + result.msg = $"Computeloc==銆嬫牴鎹満鍙扮紪鐮侊細{model.WorkCenter},宸ヨ绫诲瀷锛歿cntrType} 鏈壘鍒扮┖璐т綅鏁版嵁锛岃妫�煡璐т綅琛�; + LogHelper.Info($"ItemBack锛歿result.msg}"); + AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source); + return result; + } } else { - result.code = "1"; - result.msg = $"Computeloc==銆嬫牴鎹満鍙扮紪鐮侊細{model.WorkCenter},宸ヨ绫诲瀷锛歿cntrType} 鏈壘鍒扮┖璐т綅鏁版嵁锛岃妫�煡璐т綅琛�; - LogHelper.Info($"ItemBack锛歿result.msg}"); - AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source); - return result; + + Endloc = db.Queryable<Location>().Where(a => a.S_CODE == model.TargetLocation).First(); + if (Endloc != null) + { + End = Endloc.S_CODE; + } + else + { + result.code = "1"; + result.msg = $"Computeloc==銆嬫牴鎹粓鐐硅揣浣嶏細{model.TargetLocation} 鏈壘鍒拌揣浣嶆暟鎹紝璇锋鏌ヨ揣浣嶈〃"; + LogHelper.Info($"ItemBack锛歿result.msg}"); + AddErrorInfo("鏌ユ壘搴撳尯澶辫触", result.msg, Source); + return result; + } } + } else { @@ -1423,7 +1618,7 @@ N_START_LAYER = 1, N_END_LAYER = endlayer, N_PRIORITY = 1, - S_B_STATE="绛夊緟鎺ㄩ�", + S_B_STATE = "绛夊緟鎺ㄩ�", Z_TYPE = 5 }; LogHelper.Info("鍒涘缓绌烘墭鍥炲簱浠诲姟锛� + JsonConvert.SerializeObject(wcsTask)); @@ -2547,30 +2742,30 @@ var db = new SqlHelper<HangChaAGV>().GetInstance(); DeviceInfoModel device = new DeviceInfoModel(); - List<DeviceInfos> deviceInfos = new List<DeviceInfos>();//鍙犵洏鏈烘姤閿欎俊鎭�+ // List<DeviceInfos> deviceInfos = new List<DeviceInfos>();//鍙犵洏鏈烘姤閿欎俊鎭� // List<AgvInfos> agvInfos = new List<AgvInfos>();//agv鎶ラ敊淇℃伅 //鑾峰彇鍐呭瓨涓彔鐩樻満鐨勬姤閿欎俊鎭�- foreach (var dpjInfo in DeviceProcess.DpjInfoDirectory) - { - deviceInfos.Add(new DeviceInfos() { Device = dpjInfo.Value.DeviceName, DeviceInfo = dpjInfo.Value.ErrorInfo }); - } + //foreach (var dpjInfo in DeviceProcess.DpjInfoDirectory) + //{ + // deviceInfos.Add(new DeviceInfos() { Device = dpjInfo.Value.DeviceName, DeviceInfo = dpjInfo.Value.ErrorInfo }); + //} // device.DeviceInfos = deviceInfos; //鑾峰彇杞﹁締鎶ヨ淇℃伅 var agvDeviceInfo = db.Queryable<HangChaAGV>().ToList(); if (agvDeviceInfo.Count > 0) { device.AgvQty = agvDeviceInfo.Count; - device.AgvErrorQty = agvDeviceInfo.FindAll(a => a.agvErrCode != "0" || a.agvErrCode != "0" || a.faildCode != "0").Count; - device.AgvChargeQty = agvDeviceInfo.FindAll(a => a.agvErrCode == "1").Count; - device.AgvRunQty = agvDeviceInfo.FindAll(a => a.agvErrCode == "1").Count; - foreach (var agv in agvDeviceInfo) - { - string agvErrorInfo = GetAgvAlarmSendCodeTwo(agv.agvErrCode, agv.errCode2, agv.faildCode); - deviceInfos.Add(new DeviceInfos() { AgvNo = agv.agvNo, AgvInfo = agvErrorInfo }); - } + device.AgvErrorQty = agvDeviceInfo.FindAll(a => a.agvErrCode != "0" || int.Parse(a.errCode2) > 1 || int.Parse(a.faildCode) > 1).Count; + device.AgvChargeQty = agvDeviceInfo.FindAll(a => a.errCode2 == "1").Count; + device.AgvRunQty = agvDeviceInfo.FindAll(a => a.agvErrCode == "0" && a.errCode2 == "0" && a.faildCode == "1").Count; + //foreach (var agv in agvDeviceInfo) + //{ + // string agvErrorInfo = GetAgvAlarmSendCodeTwo(agv.agvNo, agv.agvErrCode, agv.errCode2, agv.faildCode); + // deviceInfos.Add(new DeviceInfos() { AgvNo = agv.agvNo, AgvInfo = agvErrorInfo }); + //} } - device.DeviceInfos = deviceInfos; + // device.DeviceInfos = deviceInfos; return device; } @@ -2578,56 +2773,65 @@ /// <summary> /// agv灏忚溅鏁呴殰鐮佸鐞� /// </summary> + ///<param name="agvNo">杞﹀彿</param> /// <param name="errCode1">閿欒鐮�</param> /// <param name="errCode2">閿欒鐮�</param> /// <param name="faildCode">閿欒鐮�</param> /// <returns></returns> - private static string GetAgvAlarmSendCodeTwo(string errCode1, string errCode2, string faildCode) + private static string GetAgvAlarmSendCodeTwo(string agvNo, string errCode1, string errCode2, string faildCode) { string result = ""; //灏嗘姤璀︿俊鎭暣鍚�- string binSW1 = Convert.ToString(int.Parse(errCode1), 2).PadLeft(22, '0'); + string binSW1 = Convert.ToString(int.Parse(errCode1), 2).PadLeft(25, '0'); string binSW2 = Convert.ToString(int.Parse(errCode1), 2).PadLeft(20, '0'); string binFc = Convert.ToString(int.Parse(errCode1), 2).PadLeft(16, '0'); var arr1 = binSW1.ToArray(); var arr2 = binSW2.ToArray(); var arr3 = binFc.ToArray(); - for (int i = 0; i <= arr1.Length; i++) + var AgvError = Settings.agvError.Where(a => a.agvNo.Contains(agvNo)).FirstOrDefault(); + if (AgvError != null) { - if (arr1[i] == '1') + for (int i = 0; i <= arr1.Length; i++) { - var ErrorInfo = Settings.agvErrorCode1.Where(a => a.ErrorCode == i).FirstOrDefault(); - if (ErrorInfo != null) + if (arr1[i] == '1') { - result = result + "," + $"{ErrorInfo.ErrorInfo}"; - } + var ErrorInfo = AgvError.AgvErrorCode1.Find(a => a.ErrorCode == i); + if (ErrorInfo != null) + { + result = result + "," + $"{ErrorInfo.ErrorInfo}"; + } + } + } + for (int i = 0; i <= arr2.Length; i++) + { + if (arr1[i] == '1') + { + var ErrorInfo = AgvError.AgvErrorCode2.Find(a => a.ErrorCode == i); + if (ErrorInfo != null) + { + result = result + "," + $"{ErrorInfo.ErrorInfo}"; + } + + } + } + for (int i = 0; i <= arr3.Length; i++) + { + if (arr1[i] == '1') + { + var ErrorInfo = AgvError.AgvFaildCode.Find(a => a.ErrorCode == i); + if (ErrorInfo != null) + { + result = result + "," + $"{ErrorInfo.ErrorInfo}"; + } + + } } } - for (int i = 0; i <= arr2.Length; i++) + else { - if (arr1[i] == '1') - { - var ErrorInfo = Settings.agvErrorCode2.Where(a => a.ErrorCode == i).FirstOrDefault(); - if (ErrorInfo != null) - { - result = result + "," + $"{ErrorInfo.ErrorInfo}"; - } - } - } - for (int i = 0; i <= arr3.Length; i++) - { - if (arr1[i] == '1') - { - var ErrorInfo = Settings.agvFaildCode.Where(a => a.ErrorCode == i).FirstOrDefault(); - if (ErrorInfo != null) - { - result = result + "," + $"{ErrorInfo.ErrorInfo}"; - } - - } } return result; } @@ -2676,7 +2880,8 @@ /// <param name="level">鐗╂枡绛夌骇</param> /// <param name="powderType">鏈哄瀷</param> /// <returns></returns> - internal static Location airlift(string areacode, string itemcode, string level, string powderType) + internal static Location + airlift(string areacode, string itemcode, string level, string powderType) { var db = new SqlHelper<object>().GetInstance(); Location result = null; @@ -2816,13 +3021,17 @@ lock (_lockLocation) { - var loc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "鏃�).First(); - if (loc != null) + if (string.IsNullOrEmpty(cntrType)) { - End = loc; + End = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "鏃�).First(); } else { + End = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "鏃�).First(); + } + + if (End == null) + { LogHelper.Info($"Computeloc==銆嬫牴鎹満鍙板垎缁勶細{jtcode},宸ヨ绫诲瀷锛歿cntrType} 鏈壘鍒扮┖璐т綅鏁版嵁锛岃妫�煡璐т綅琛�); } -- Gitblit v1.9.1