From d0a265713fd18162f3a82bdcd22e267df7298c7b Mon Sep 17 00:00:00 2001 From: 杨前锦 <1010338399@qq.com> Date: 星期一, 26 五月 2025 08:59:52 +0800 Subject: [PATCH] 印尼佳通-半制品代码逻辑优化 --- HH.WCS.Mobox3/HH.WCS.Mobox3.YNJT_PT/api/ApiHelper.cs | 556 +++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 410 insertions(+), 146 deletions(-) diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.YNJT_PT/api/ApiHelper.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.YNJT_PT/api/ApiHelper.cs index 03a5549..98b534f 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.YNJT_PT/api/ApiHelper.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.YNJT_PT/api/ApiHelper.cs @@ -1,10 +1,12 @@ 锘縰sing HH.WCS.Mobox3.YNJT_PT.device; +using HH.WCS.Mobox3.YNJT_PT.models; using HH.WCS.Mobox3.YNJT_PT.process; using HH.WCS.Mobox3.YNJT_PT.util; using HH.WCS.Mobox3.YNJT_PT.wms; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SqlSugar; +using Swashbuckle.Swagger; using System; using System.Collections.Generic; using System.Linq; @@ -12,6 +14,8 @@ using System.Threading; using static HH.WCS.Mobox3.YNJT_PT.api.ApiModel; using static HH.WCS.Mobox3.YNJT_PT.api.OtherModel; +using static HH.WCS.Mobox3.YNJT_PT.api.WmsController; +using static System.Net.Mime.MediaTypeNames; namespace HH.WCS.Mobox3.YNJT_PT.api { /// <summary> @@ -21,6 +25,404 @@ static ApiHelper() { } + + /// <summary> + /// 鎴愬瀷鏈轰笅绾胯褰�+ /// </summary> + /// <param name="model"></param> + public static ResponseResult cxjOffLineRecord(OffLineModel model) + { + ResponseResult response = new ResponseResult(); + var container = ContainerHelper.GetCntr(model.rfid); + var location = LocationHelper.GetLoc(model.loc); + if (location != null) + { + if (container == null) + { + ContainerHelper.AddCntr(model.rfid); + } + + try + { + OffLineRecord record = new OffLineRecord() + { + S_RFID = model.rfid, + S_LOC = model.loc, + N_IS_URGENT = model.isUrgent, + T_OFF_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + N_IS_FULL = model.isFull, + + }; + WMSHelper.addOffLineRecord(record); + } + catch (Exception ex) + { + LogHelper.Info($"娣诲姞鎴愬瀷鏈轰笅绾胯褰曢敊璇紝閿欒鍘熷洜锛歿ex.Message}", "WMS"); + response.code = 500; + response.msg = "WMS绯荤粺鍐呴儴閿欒锛岃鑱旂郴寮�彂浜哄憳鎺掓煡闂"; + } + } + else + { + response.code = 1; + response.msg = $"璐т綅锛歿model.loc}涓嶅瓨鍦�; + } + return response; + } + + /// <summary> + /// 涓嬬嚎璇锋眰 + /// </summary> + /// <returns></returns> + public static ResponseResult offLineRequest(NotifyDeviceSignalModel model) + { + ResponseResult response = new ResponseResult(); + var startLoc = LocationHelper.GetLoc(model.loc); + if (startLoc != null) + { + List<BarcodeModel> extData = model.extData; + int dataCount = extData.Count; + if (dataCount > 0) + { + var rfidExistNull = extData.Where(a => string.IsNullOrEmpty(a.rfid)).Count()>0; + if (rfidExistNull) + { + response.code = 1; + response.msg = "rfid涓嶈兘涓虹┖"; + } + else + { + Dictionary<BarcodeModel, bool> rfidDic = new Dictionary<BarcodeModel, bool>(); + foreach (var ext in extData) + { + string rfid = ext.rfid; + if (rfid.Contains("ET")) + { + rfidDic.Add(ext, false); + } + else + { + // 1.鏌ヨ鎴愬瀷鏈轰腑闂磋〃锛宺fid 鏄惁瀛樺湪 + var offLineRecord = WMSHelper.getOffLineRecord(rfid); + if (offLineRecord != null) + { + // 2.鏌ヨ鐗╂枡鏉$爜淇℃伅琛紝鏉$爜淇℃伅鏄惁瀛樺湪 + var itemBarcodeInfo = WMSHelper.GetGreenTireInformation(ext.barcode); + if (itemBarcodeInfo == null) + { + rfidDic.Add(ext, false); + } + else + { + rfidDic.Add(ext, true); + } + } + else + { + rfidDic.Add(ext, false); + } + } + } + + // 鍒ゆ柇鏄惁鏈夊紓甯告墭鐩�+ bool isNormal = rfidDic.Where(a => a.Value == false).Count() == 0; + if (isNormal && extData.Count == 2) + { + // 鍙屾墭姝e父鏂欏叆搴�+ Location endLoc = null; + var itemBarcodeInfo = WMSHelper.GetGreenTireInformation(extData[0].barcode); + string groupNo = WMSHelper.GenerateTaskGroupNo(); + var endLocList = WMSHelper.getInStockEndLoc(itemBarcodeInfo.ITEMCODE, 2); + if (endLocList.Count == 2) + { + var rfidList = rfidDic.Keys.ToList(); + for (int i = 0; i < rfidList.Count; i++) + { + endLoc = endLocList[i]; + var wmsTask = new WMSTask() + { + S_CNTR_CODE = rfidList[i].rfid, + S_CODE = WMSHelper.GenerateTaskNo(), + S_START_LOC = startLoc.S_CODE, + S_START_AREA = startLoc.S_AREA_CODE, + S_END_LOC = endLoc.S_CODE, + S_END_AREA = endLoc.S_AREA_CODE, + S_TYPE = "婊℃枡涓嬬嚎鍏ュ簱浠诲姟", + S_OP_DEF_CODE = model.reqId, + S_OP_DEF_NAME = "鎴愬瀷鏈烘弧鏂欎笅绾垮叆搴�, + N_PRIORITY = 1, + T_START_TIME = DateTime.Now, + S_GROUP_NO = groupNo, + }; + if (WMSHelper.CreateWmsTask(wmsTask)) + { + // 鍒涘缓涓�鍏ュ簱浠诲姟 + WCSTask wcsTask = new WCSTask() + { + S_OP_NAME = wmsTask.S_OP_DEF_NAME, + S_OP_CODE = wmsTask.S_CODE, + S_CODE = WCSHelper.GenerateTaskNo(), + S_CNTR_CODE = wmsTask.S_CNTR_CODE, + S_TYPE = wmsTask.S_TYPE, + S_START_LOC = startLoc.S_CODE, + S_START_AREA = startLoc.S_AREA_CODE, + S_END_LOC = endLoc.S_CODE, + S_END_AREA = endLoc.S_AREA_CODE, + S_SCHEDULE_TYPE = "WCS", + N_PRIORITY = 1, + T_START_TIME = DateTime.Now, + }; + + if (WCSHelper.CreateTask(wcsTask)) + { + // 璧风偣銆佹帴椹崇偣銆佺粓鐐瑰姞閿�+ LocationHelper.LockLoc(wcsTask.S_START_LOC, 2); + LocationHelper.LockLoc(wcsTask.S_END_LOC, 1); + + // 鏇存柊浣滀笟浠诲姟鐘舵� + wmsTask.N_B_STATE = 1; + WMSHelper.UpdateTaskState(wmsTask); + + // 缁戝畾瀹瑰櫒鐗╂枡淇℃伅 + WMSHelper.bindBarcodeItemInfo(wmsTask.S_CNTR_CODE,itemBarcodeInfo); + } + } + } + } + else + { + response.code = 1; + response.msg = "搴撳尯娌℃湁鍙叆鐨勭┖璐т綅"; + } + } + else + { + // 寮傚父鏂欏嚭搴撴淇�鎴�鍗曟嫋鐗╂枡鍏ュ簱 + foreach (var dic in rfidDic) + { + Location middleLoc = null; + Location endLoc = null; + if (dic.Value) + { + var itemBarcodeInfo = WMSHelper.GetGreenTireInformation(dic.Key.barcode); + var endLocList = WMSHelper.getInStockEndLoc(itemBarcodeInfo.ITEMCODE, 1); + if (endLocList.Count == 1) + { + endLoc = endLocList[0]; + var wmsTask = new WMSTask() + { + S_CNTR_CODE = dic.Key.rfid, + S_CODE = WMSHelper.GenerateTaskNo(), + S_START_LOC = startLoc.S_CODE, + S_START_AREA = startLoc.S_AREA_CODE, + S_END_LOC = endLoc.S_CODE, + S_END_AREA = endLoc.S_AREA_CODE, + S_TYPE = "婊℃枡涓嬬嚎鍏ュ簱浠诲姟", + S_OP_DEF_CODE = model.reqId, + S_OP_DEF_NAME = "鎴愬瀷鏈烘弧鏂欎笅绾垮叆搴�, + N_PRIORITY = 1, + T_START_TIME = DateTime.Now, + }; + if (WMSHelper.CreateWmsTask(wmsTask)) + { + // 鍒涘缓涓�鍏ュ簱浠诲姟 + WCSTask wcsTask = new WCSTask() + { + S_OP_NAME = wmsTask.S_OP_DEF_NAME, + S_OP_CODE = wmsTask.S_CODE, + S_CODE = WCSHelper.GenerateTaskNo(), + S_CNTR_CODE = wmsTask.S_CNTR_CODE, + S_TYPE = wmsTask.S_TYPE, + S_START_LOC = startLoc.S_CODE, + S_START_AREA = startLoc.S_AREA_CODE, + S_END_LOC = endLoc.S_CODE, + S_END_AREA = endLoc.S_AREA_CODE, + S_SCHEDULE_TYPE = "WCS", + N_PRIORITY = 1, + T_START_TIME = DateTime.Now, + }; + + if (WCSHelper.CreateTask(wcsTask)) + { + // 璧风偣銆佹帴椹崇偣銆佺粓鐐瑰姞閿�+ LocationHelper.LockLoc(wcsTask.S_START_LOC, 2); + LocationHelper.LockLoc(wcsTask.S_END_LOC, 1); + + // 鏇存柊浣滀笟浠诲姟鐘舵� + wmsTask.N_B_STATE = 1; + WMSHelper.UpdateTaskState(wmsTask); + + // 缁戝畾瀹瑰櫒鐗╂枡淇℃伅 + WMSHelper.bindBarcodeItemInfo(wmsTask.S_CNTR_CODE, itemBarcodeInfo); + } + } + } + else + { + response.code = 1; + response.msg = "搴撳尯娌℃湁鍙叆鐨勭┖璐т綅"; + } + } + else + { + middleLoc = WMSHelper.getMinTaskMiddleLoc(1); // 1.寮傚父鎺掑嚭浣�+ endLoc = WMSHelper.getAbnormalAreaEmptyLoc(Settings.abnormalArea); + var wmsTask = new WMSTask() + { + S_CNTR_CODE = dic.Key.rfid, + S_CODE = WMSHelper.GenerateTaskNo(), + S_START_LOC = startLoc.S_CODE, + S_START_AREA = startLoc.S_AREA_CODE, + S_END_LOC = endLoc.S_CODE, + S_END_AREA = endLoc.S_AREA_CODE, + S_TYPE = "寮傚父鎵樼洏鍑哄簱浠诲姟", + S_OP_DEF_CODE = model.reqId, + S_OP_DEF_NAME = "寮傚父鎵樼洏鍑哄簱妫�慨", + N_PRIORITY = 1, + T_START_TIME = DateTime.Now, + }; + if (WMSHelper.CreateWmsTask(wmsTask)) + { + // 鍒涘缓涓�鍏ュ簱浠诲姟 + WCSTask wcsTask = new WCSTask() + { + S_OP_NAME = wmsTask.S_OP_DEF_NAME, + S_OP_CODE = wmsTask.S_CODE, + S_CODE = WCSHelper.GenerateTaskNo(), + S_CNTR_CODE = wmsTask.S_CNTR_CODE, + S_TYPE = wmsTask.S_TYPE, + S_START_LOC = startLoc.S_CODE, + S_START_AREA = startLoc.S_AREA_CODE, + S_END_LOC = middleLoc.S_CODE, + S_END_AREA = middleLoc.S_AREA_CODE, + S_SCHEDULE_TYPE = "WCS", + N_PRIORITY = 1, + T_START_TIME = DateTime.Now, + }; + + if (WCSHelper.CreateTask(wcsTask)) + { + // 璧风偣銆佹帴椹崇偣銆佺粓鐐瑰姞閿�+ LocationHelper.LockLoc(wcsTask.S_START_LOC, 2); + LocationHelper.LockLoc(wcsTask.S_END_LOC, 1); + + // 鏇存柊浣滀笟浠诲姟鐘舵� + wmsTask.N_B_STATE = 1; + WMSHelper.UpdateTaskState(wmsTask); + } + } + } + } + } + } + } + else + { + response.code = 1; + response.msg = "鍏ュ弬缂哄皯鎵樼洏鍜屾潯鐮佷俊鎭�; + } + } + else + { + response.code = 1; + response.msg = "璧风偣璐т綅涓嶅瓨鍦�; + } + return response; + } + + /// <summary> + /// 璇荤爜璇锋眰 + /// </summary> + public static ResponseResult readCodeRequest(NotifyDeviceSignalModel model) + { + ResponseResult response = new ResponseResult(); + readCodeFeedbackResponse readCodeFeedbackResponse = new readCodeFeedbackResponse() + { + verifyResult = true + }; + var wmsTask = WMSHelper.GetWmsTask(model.taskNo); + if (wmsTask != null) + { + if (wmsTask.S_TYPE != "寮傚父鎵樼洏鍑哄簱浠诲姟") + { + Location endLoc = null; + Location middleLoc = null; + // 鍒ゆ柇rfid鏄惁寮傚父 + if (model.cntrNo != wmsTask.S_CNTR_CODE) + { + middleLoc = WMSHelper.getMinTaskMiddleLoc(1); // 1.寮傚父鎺掑嚭浣�+ endLoc = WMSHelper.getAbnormalAreaEmptyLoc(Settings.abnormalArea); + wmsTask.S_END_LOC = endLoc.S_CODE; + wmsTask.S_END_AREA = endLoc.S_AREA_CODE; + WMSHelper.UpdateTaskEnd(wmsTask); + + var wcsTask = WCSHelper.GetTaskBySrcNo(wmsTask.S_CODE); + if (wcsTask != null) + { + wcsTask.S_END_LOC = middleLoc.S_CODE; + wcsTask.S_END_AREA = middleLoc.S_AREA_CODE; + WCSHelper.updateTaskEnd(wcsTask); + } + + readCodeFeedbackResponse.verifyResult = false; + readCodeFeedbackResponse.endLoc = middleLoc.S_CODE; + response.data = readCodeFeedbackResponse; + } + else + { + var cntrItemRels = ContainerHelper.GetCntrItemRel(wmsTask.S_CNTR_CODE); + if (cntrItemRels.Count > 0) + { + if (cntrItemRels[0].S_ITEM_STATE != "OK") + { + middleLoc = WMSHelper.getMinTaskMiddleLoc(1); // 1.寮傚父鎺掑嚭浣�+ endLoc = WMSHelper.getAbnormalAreaEmptyLoc(Settings.abnormalArea); + wmsTask.S_END_LOC = endLoc.S_CODE; + wmsTask.S_END_AREA = endLoc.S_AREA_CODE; + WMSHelper.UpdateTaskEnd(wmsTask); + + var wcsTask = WCSHelper.GetTaskBySrcNo(wmsTask.S_CODE); + if (wcsTask != null) + { + wcsTask.S_END_LOC = middleLoc.S_CODE; + wcsTask.S_END_AREA = middleLoc.S_AREA_CODE; + WCSHelper.updateTaskEnd(wcsTask); + } + + readCodeFeedbackResponse.verifyResult = false; + readCodeFeedbackResponse.endLoc = middleLoc.S_CODE; + response.data = readCodeFeedbackResponse; + } + } + } + } + } + else + { + response.code = 1; + response.msg = $"浠诲姟鍙凤細{model.taskNo},鏈煡璇㈠埌鎵ц涓殑浠诲姟"; + } + response.data = readCodeFeedbackResponse; + return response; + } + + /// <summary> + /// 纭寲鏈哄懠鍙儦鑳庡嚭搴�+ /// </summary> + /// <param name="model"></param> + public static ResponseResult callItemOutStock(CallItemModel model) + { + ResponseResult response = new ResponseResult(); + + return response; + } + + public class readCodeFeedbackResponse + { + public bool verifyResult { get; set; } + public string endLoc { get; set; } + } + /// <summary> /// 鍒涘缓浠诲姟 /// </summary> @@ -118,117 +520,6 @@ cacheInstockInfos.Add(pair); } } - - - internal static object in_lock = new object(); - - /// <summary> - /// pad鍏ュ簱 - /// </summary> - /// <param name="model"></param> - /// <returns></returns> - internal static SimpleResult Instock(InstockInfo model) { - var result = new SimpleResult(); - //pda鍏ュ簱 - //1 鍒ゆ柇璧风偣鏈夋病鏈変换鍔★紝鏈夋病鏈夊叆搴撻攣 - lock (in_lock) { - var loc = LocationHelper.GetLoc(model.start); - if (loc != null && loc.N_LOCK_STATE == 0) - { - //2 鏍规嵁缁堢偣搴撳尯璁$畻缁堢偣 - var end = WMSHelper.GetInstockEnd(model.item, model.endArea); - LogHelper.Info("缁堢偣璐т綅锛� + JsonConvert.SerializeObject(end), "TSSG"); - if (end != null) - { - var cntrCode = ContainerHelper.GenerateCntrNo(); - var wcsTask = new WCSTask - { - S_OP_NAME = "鍏ュ簱", - S_CODE = WCSHelper.GenerateTaskNo(), - S_TYPE = "涓嬬嚎鍏ュ簱", - S_START_LOC = model.start, - S_END_LOC = end.S_CODE, - S_SCHEDULE_TYPE = "NDC", - N_CNTR_COUNT = 1, - S_CNTR_CODE = cntrCode, - N_START_LAYER = 1, - N_END_LAYER = end.N_CURRENT_NUM + 1 - }; - if (ContainerHelper.BindNewCntrItem(model.start, cntrCode, model.item) && WCSHelper.CreateTask(wcsTask)) - { - LocationHelper.LockLoc(model.start, 2); - LocationHelper.LockLoc(end.S_CODE, 1); - result.resultCode = 0; - result.resultMsg = $"浠诲姟鍒涘缓鎴愬姛,浠诲姟鍙蜂负{wcsTask.S_CODE},缁堢偣涓簕end.S_CODE}"; - } - } - else - { - addKeyValuePair(model.ip, model); - LogHelper.Info("缂撳瓨鍏ュ簱淇℃伅锛� + JsonConvert.SerializeObject(model), "TSSG"); - result.resultCode = 2; - result.resultMsg = "鏈幏鍙栧埌鍏ュ簱缁堢偣"; - } - } - else - { - result.resultCode = 1; - result.resultMsg = "璧风偣鏈変换鍔℃湭瀹屾垚"; - } - } - return result; - } - - /// <summary> - /// 绉诲簱 - /// </summary> - /// <param name="model"></param> - /// <returns></returns> - internal static SimpleResult shiftStock(ShiftStockInfo model) - { - var result = new SimpleResult(); - //1 鏍规嵁璧风偣搴撳尯銆佹帓 纭畾璧峰璐т綅 - var startLoc = WMSHelper.GetShiftStockStart(model.startArea, model.startRow); - if (startLoc != null && startLoc.N_LOCK_STATE == 0) - { - //2 鏍规嵁缁堢偣搴撳尯璁$畻缁堢偣 - var end = WMSHelper.GetShiftStockEnd( model.endArea, model.endRow); - if (end != null && end.N_LOCK_STATE == 0) - { - var wcsTask = new WCSTask - { - S_OP_NAME = "绉诲簱", - S_CODE = WCSHelper.GenerateTaskNo(), - S_TYPE = "绉诲簱", - S_START_LOC = startLoc.S_CODE, - S_END_LOC = end.S_CODE, - S_SCHEDULE_TYPE = "NDC", - N_CNTR_COUNT = 1, - S_CNTR_CODE = startLoc.LocCntrRel.S_CNTR_CODE, - N_START_LAYER = startLoc.N_CURRENT_NUM, - N_END_LAYER = end.N_CURRENT_NUM + 1 - }; - if (WCSHelper.CreateTask(wcsTask)) - { - LocationHelper.LockLoc(startLoc.S_CODE, 2); - LocationHelper.LockLoc(end.S_CODE, 1); - result.resultCode = 0; - result.resultMsg = $"浠诲姟鍒涘缓鎴愬姛,浠诲姟鍙蜂负{wcsTask.S_CODE},缁堢偣涓簕end.S_CODE}"; - } - } - else - { - result.resultCode = 2; - result.resultMsg = "缁堢偣搴撳尯娌℃湁鍙叆鐨勮揣浣�; - } - } - else - { - result.resultCode = 1; - result.resultMsg = "鏈壘鍒版寚瀹氱墿鏂�; - } - return result; - } internal static CodeInfo GetCodeInfo(string code, string org) { //return new CodeInfo { Fitemid_XK=code, FSourceNo="123456"}; @@ -258,43 +549,16 @@ public static void agvCarAlarm(string forkliftNo, string errCode , string errCode2 , string failCode) { bool turnLight = false; - var errCodeList = Settings.agvAlarmNoList.Where(a => a.type == 1).Select(a => a.dex).ToList(); - var errCode2List = Settings.agvAlarmNoList.Where(a => a.type == 2).Select(a => a.dex).ToList(); - var failCodeList = Settings.agvAlarmNoList.Where(a => a.type == 3).Select(a => a.dex).ToList(); - - if (errCodeList.Contains(int.Parse(errCode))) - { - turnLight = true; - LogHelper.Info("StopWord 閿欒鐮侊細" + errCode, "HosttoagvCar"); - } - if (errCode2List.Contains(int.Parse(errCode2))) - { - turnLight = true; - LogHelper.Info("StopWord2 閿欒鐮侊細" + errCode2, "HosttoagvCar"); - } - if (failCodeList.Contains(int.Parse(failCode))) - { - turnLight = true; - LogHelper.Info("failCode 閿欒鐮侊細" + failCode, "HosttoagvCar"); - } - - var alertorDevices = Settings.alertorLightInfos.Where(a => a.deviceNo == 5 || a.deviceNo == 6).ToList(); - foreach (var alertorDevice in alertorDevices) - { - if (turnLight) - { - var result = HH.WCS.Mobox3.YNJT_PT.device.PlcHelper.SendHex(alertorDevice.address, alertorDevice.turnLight); - LogHelper.Info("寮�伅锛宮odbus 杩斿洖淇″彿锛� + result, "HosttoagvCar"); - } - /*else - { - var result = HH.WCS.Mobox3.YNJT_PT.device.PlcHelper.SendHex(alertorDevice.address, alertorDevice.offLight); - LogHelper.Info("鍏崇伅锛宮odbus 杩斿洖淇″彿锛� + result, "HosttoagvCar"); - }*/ - } + } - + public class OffLineModel + { + public string rfid { get; set; } // 鎵樼洏鍙�+ public string loc { get; set; } // 涓嬬嚎璐т綅 + public int isUrgent { get; set; } // N_IS_URGENT 鏄惁鍔犳�锛�.鍚�1.鏄級 + public int isFull { get; set; } // 鏄惁婊℃嫋 0.鍚�1.鏄�+ } public class AddTaskModel { public string From { get; set; } public string To { get; set; } -- Gitblit v1.9.1