From a765da90e5ee63e04d2d8460a5ad1ebd0e8eb4db Mon Sep 17 00:00:00 2001 From: huanghongfeng <huanghongfeng@hnkhzn.com> Date: 星期一, 15 七月 2024 21:43:59 +0800 Subject: [PATCH] 工单处理 --- 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs | 181 ++++++++++++++++++++++++-------------------- 1 files changed, 99 insertions(+), 82 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs" index ef73816..8b52c8e 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs" @@ -34,6 +34,7 @@ Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(context); Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context); + IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context); var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�"); if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒"); @@ -43,6 +44,9 @@ foreach (var item in stationinfos) { + //鍒ゅ畾浠诲姟鏄惁宸插垱寤�//濡傚凡瀛樺湪 + if (agvtaskRepository.Find(x => x.agv_fromaddress == item.stationCode).Any()) + continue; var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", item.stationCode);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃� var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", item.stationCode);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃� @@ -50,75 +54,35 @@ //鏍规嵁涓嬫枡鍙g殑缁戝畾淇℃伅鏌ヨ瀵瑰簲宸ュ崟锛屾娴嬫宸ュ崟鏄惁宸插畬鎴� 瀹屾垚鍗冲彲灏嗗叾閫佸叆搴� - dt_mes_head mesinfo = mes_HeadRepository.Find(x => x.jobID == item.Number).FirstOrDefault(); - if (mesinfo == null) + var work = workinfoRepository.Find(x => x.workOrder == item.Number && x.drawingNo == item.stationType && x.heatID == item.heatNumber && x.processCode == "17").OrderByDescending(x => x.CreateTime).FirstOrDefault(); + if (work == null) { - item.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟澶磋〃锛�"; + item.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟淇℃伅锛�"; item.location_state = LocationStateEnum.Abnormal.ToString(); - stationinfoRepository.Update(item, true); + stationinfoRepository.Update(item, x => new { x.remark, x.location_state }, true); continue; - //throw new Exception("鏈壘鍒板伐鍗曞ご琛紒宸ュ崟鍙凤細" + item.Number); } - var dt_Geometry_Data = PipelineJob.QueryMateriel(mesinfo.drawingNo); - var dt_Geometry_Data1 = PipelineJob.QueryMateriel1(mesinfo.drawingNo); - - int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum); - - - //鍒ゅ畾浠诲姟鏄惁宸插垱寤�//濡傚凡瀛樺湪 - if (agvtaskRepository.Find(x => x.agv_fromaddress == item.stationCode).Any()) + var geometry = Pipeline.QueryMateriel(work.drawingNo); + if (geometry == null) + { + item.remark = "鏈壘鍒拌溅杞俊鎭紒"; + item.location_state = LocationStateEnum.Abnormal.ToString(); + stationinfoRepository.Update(item, x => new { x.remark, x.location_state }, true); continue; + } + dt_stationinfo TargetLocation = null; string tasktype = ""; - if (item.quantity == 5 || CompeletedNum == 0) //寰幆璇诲彇杞﹁疆鏁颁负5鎴栬�呰鍗曞凡瀹屾垚鏁伴噺鐨勪笅鏂欏彛 鈫掑伐鍗曚汉宸ュ叧闂殑宸ュ崟 + + //if (item.quantity == 5) + if (item.quantity == geometry.stackNoRange) { - - - if (mesinfo.quantity <= 50 || item.stationCode.Contains("3")) //灏忎簬50浠剁洿鎺ュ嚭搴� - { - //todo 瀵绘壘鍙斁璐у鍗忔斁璐у彴 + if (!string.IsNullOrEmpty(work.area) || item.stationCode.Contains("3")) tasktype = "TaskType_OutsourceInbound"; - TargetLocation = GetEmptyLocation(stationinfoRepository); - - } else - { - //todo: 璋冪敤WMS鎺ュ彛鍒涘缓浠诲姟 tasktype = "TaskType_Inbound"; - TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data == null ? dt_Geometry_Data1.e : dt_Geometry_Data.e); - } - if (TargetLocation != null) - { - dt_agvtask agvtask = new dt_agvtask() - { - agv_fromaddress = item.stationCode, - agv_id = Guid.NewGuid(), - agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"), - agv_grade = 1, - agv_createtime = DateTime.Now, - agv_taskstate = "Create", - agv_materielid = item.stationType, - agv_qty = item.quantity, - agv_tasktype = tasktype, - agv_toaddress = TargetLocation.stationCode, - agv_userid = "绯荤粺", - bindSN = item.bindSN, - agv_worktype = Convert.ToInt32(mesinfo.processCode), - agv_materbarcode = mesinfo.materialCode, - agv_Traytype = item.tray_type, - jobID = item.Number, - agv_TrayStatus = item.tray_status - }; - agvtaskRepository.Add(agvtask, true); - item.location_state = LocationStateEnum.InBusy.ToString(); - stationinfoRepository.Update(item, true); - - TargetLocation.location_state = LocationStateEnum.InBusy.ToString(); - TargetLocation.stationType = agvtask.agv_materielid; - stationinfoRepository.Update(TargetLocation, true); - WriteDBLog.Success("鍒涘缓鍏ュ簱浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS"); - } + AGVTask.AddQueueTask(stationinfoRepository, agvtaskRepository, item, tasktype, work); } } } @@ -126,7 +90,6 @@ { WriteDBLog.Error("鍒涘缓鍏ュ簱浠诲姟", $"閿欒淇℃伅锛� {ex.Message}", "PCS"); } - } /// <summary> @@ -142,8 +105,10 @@ dt_stationinfo TargetLocation = null; #region 鍚岀被鍨嬫斁涓�琛� - var area1 = GetArea(mesinfo.quantity, e); - TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == area1).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault(); + //if (area1 == "1") + TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo).FirstOrDefault(); + + //TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == area1).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault(); if (TargetLocation != null) { #region 鍚屼竴琛屽彧鍏佽涓�涓换鍔� @@ -152,14 +117,33 @@ // return null; #endregion - #region 鍑哄簱浠诲姟浼樺厛,瀛樺湪鍑哄簱浠诲姟杩欎竴琛屽垯涓嶈兘鍏ュ簱 - var OutTask = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == area1 && x.location_state == LocationStateEnum.OutBusy.ToString()).Any(); - if (OutTask) return null; + #region 鍑哄簱浠诲姟浼樺厛,瀛樺湪鍑哄簱浠诲姟鍒欎笉鑳藉叆搴� + bool OutTask = false; + if (TargetLocation.area == "1") + { + TargetLocation = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderByDescending(x => x.line).FirstOrDefault(); + if (TargetLocation != null) + OutTask = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.OutBusy.ToString()).Any(); + if (OutTask)//杩欏垪瀛樺湪鍑哄簱浠诲姟,瀵绘壘涓�鍒楃┖璐т綅 + TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.column).FirstOrDefault(); + if (TargetLocation != null) return TargetLocation; + } + else + { + TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.column).FirstOrDefault(); + if (TargetLocation != null) + OutTask = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.OutBusy.ToString()).Any(); + //搴撳唴瀛樺湪鍑哄簱浠诲姟锛岄噸鏂板紑涓�琛屽叆搴� + if (OutTask) + TargetLocation = stationinfoRepository.Find(x => x.column == (TargetLocation.area == "2" ? 1 : 10) && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).FirstOrDefault(); + if (TargetLocation != null) return TargetLocation; + } + #endregion - TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault(); - if (TargetLocation != null) - return TargetLocation; + //TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault(); + //if (TargetLocation != null) + // return TargetLocation; } #endregion @@ -249,15 +233,19 @@ stationinfoRepository.Update(stationinfo, true); return null; } + + #region 鏌ユ壘搴撳瓨 dt_inventory inventory = null; if (detail.heatID != null) { - inventory = inventoryRepository.Find(x => /*x.HeatNumber == detail.heatID &&*/ x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).FirstOrDefault(); + inventory = inventoryRepository.Find(x => /*x.HeatNumber == detail.heatID &&*/ x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault(); } else { - inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).FirstOrDefault(); + inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault(); } + #endregion + #region 鏍规嵁搴撳瓨鏌ユ壘鍙叆搴撶┖璐т綅 if (inventory != null) @@ -277,8 +265,9 @@ + var area1 = string.IsNullOrEmpty(mesinfo.area) ? GetArea(mesinfo.quantity, e) : mesinfo.area; - if (CompeletedNum <= 15) + if (CompeletedNum <= 15 || area1 == "1") { TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault(); } @@ -289,17 +278,31 @@ //else if (180 < mesinfo.quantity && mesinfo.quantity <= 225 && e < 1100) // TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "3" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); //if (50 < mesinfo.quantity && e > 1100 || TargetLocation == null) - var area = GetArea(mesinfo.quantity, e); + + //var area = GetArea(mesinfo.quantity, e); - TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); + TargetLocation = stationinfoRepository.Find(x => x.column == (area1 == "2" ? 1 : 10) && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).OrderBy(x => x.column).FirstOrDefault(); if (TargetLocation == null) { - if (area == "2") - area = "3"; - else if (area == "3") - area = "2"; - TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); + if (area1 == "2") + area1 = "3"; + else if (area1 == "3") + area1 = "2"; + TargetLocation = stationinfoRepository.Find(x => x.column == (area1 == "2" ? 1 : 10) && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).OrderBy(x => x.column).FirstOrDefault(); + if (TargetLocation == null) + { + //TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == "1").OrderByDescending(x => x.column).FirstOrDefault(); + + //if (TargetLocation != null) + // TargetLocation = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderByDescending(x => x.line).FirstOrDefault(); + //if (TargetLocation == null) + // TargetLocation = stationinfoRepository.Find(x => x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).OrderByDescending(x => x.line).FirstOrDefault(); + if (TargetLocation == null) + TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault(); + + } + } //if (TargetLocation == null) @@ -338,7 +341,21 @@ } return TargetLocation; } - + /// <summary> + /// 涓存椂浣跨敤 + /// </summary> + /// <param name="stationinfoRepository"></param> + /// <returns></returns> + public static dt_stationinfo GetEmptyLocation1(Idt_stationinfoRepository stationinfoRepository) + { + return stationinfoRepository.Find(x => x.line == 1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "3").OrderBy(x => x.column).FirstOrDefault();//琛屽拰鍖哄煙闇�鍐欐 + } + /// <summary> + /// 鍘诲鍗� + /// </summary> + /// <param name="stationinfoRepository"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> public static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository) { dt_stationinfo TargetLocation = null; @@ -348,17 +365,17 @@ if (!Pipeline_client.IsConnected) throw new Exception("涓庨摼鏉℃満杩炴帴瓒呮椂锛�"); foreach (var item in target) { - TargetLocation = stationinfoRepository.Find(x => x.stationCode == item && x.location_state == "Empty" /*LocationStateEnum.Empty.ToString()*/ && x.enable).FirstOrDefault(); + TargetLocation = stationinfoRepository.Find(x => x.stationCode == item && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).FirstOrDefault(); var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", item);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃� var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", item);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃� if (TargetLocation != null && PalletSignal == 2 && MaterialSignal == 2) return TargetLocation; } - if (TargetLocation == null) - { - throw new Exception("澶栧崗鍏ュ簱鍙e凡婊�"); - } + //if (TargetLocation == null) + //{ + // throw new Exception("澶栧崗鍏ュ簱鍙e凡婊�"); + //} return TargetLocation; } /// <summary> -- Gitblit v1.9.3