From d2cef0150abe6d14cbfa60c8845795b91a1f5f97 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期六, 20 四月 2024 19:50:53 +0800 Subject: [PATCH] 添加入库触发条件,修改上料区任务逻辑 --- 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs | 449 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 361 insertions(+), 88 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 e9ff5f8..dffe3ee 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" @@ -6,60 +6,125 @@ using WIDESEA_WCS.IRepositories; using WIDESEA_WCS.Repositories; using WIDESEA_Core.EFDbContext; -using WIDESEA_Core.FreeDB; using WIDESEA_Entity.DomainModels; using WIDESEA_Comm; +using static System.Collections.Specialized.BitVector32; +using WIDESEA_Comm.TaskNo; +using WIDESEA_Entity.ToAGV; +using WIDESEA_WCS.WCSClient; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; +using WIDESEA_WMS.IRepositories; +using WIDESEA_WMS.Repositories; +using static FreeSql.Internal.GlobalFilter; +using WIDESEA_Comm.LogInfo; namespace WIDESEA_WCS.JobsPart.Common { public class StationTask { - FreeDB freeDB = new FreeDB(); - public void CreateTask() + /// <summary> + /// 鍒涘缓鍏ュ簱浠诲姟 + /// </summary> + public static void CreateTask() { - VOLContext context = new VOLContext(); - Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); - Idt_WorkinfoRepository workinfoRepository = new dt_WorkinfoRepository(context); - - List<dt_stationinfo> stationinfos = stationinfoRepository.Find(x => x.stationCode.Contains('X')); - - foreach (var item in stationinfos) + try { - //鏍规嵁涓嬫枡鍙g殑缁戝畾淇℃伅鏌ヨ瀵瑰簲宸ュ崟锛屾娴嬫宸ュ崟鏄惁宸插畬鎴� 瀹屾垚鍗冲彲灏嗗叾閫佸叆搴� - dt_Workinfo workinfo = workinfoRepository.FindFirst(x => x.WorkNumber == item.Number); - int CompeletedNum = Convert.ToInt32(workinfo.PlannedQuantity) - Convert.ToInt32(workinfo.QuantityCompletion); + VOLContext context = new VOLContext(); + 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); - //鍒ゅ畾浠诲姟鏄惁宸插垱寤�//濡傚凡瀛樺湪 - if (freeDB.Select<dt_agvtask>().Where(x => x.agv_fromaddress == item.stationCode).Count() > 0) - continue; + var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�"); + if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒"); + if (!Pipeline_client.IsConnected) throw new Exception("涓庨摼鏉℃満杩炴帴瓒呮椂锛�"); - if (item.quantity == 5 || CompeletedNum == 0) //寰幆璇诲彇杞﹁疆鏁颁负5鎴栬�呰鍗曞凡瀹屾垚鏁伴噺鐨勪笅鏂欏彛 鈫掑伐鍗曚汉宸ュ叧闂殑宸ュ崟 + List<dt_stationinfo> stationinfos = stationinfoRepository.Find(x => x.stationCode.Contains("X") && x.enable && x.quantity > 0 && !string.IsNullOrEmpty(x.stationType) && !string.IsNullOrEmpty(x.Number)).ToList(); + + foreach (var item in stationinfos) { - dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, workinfo, item); + //鍒ゅ畾浠诲姟鏄惁宸插垱寤�//濡傚凡瀛樺湪 + if (agvtaskRepository.Find(x => x.agv_fromaddress == item.stationCode).Any()) + continue; - if (TargetLocation != null) + var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", item.stationCode);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃� + var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", item.stationCode);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃� + if (PalletSignal != 1 || MaterialSignal != 1) continue; + + //鏍规嵁涓嬫枡鍙g殑缁戝畾淇℃伅鏌ヨ瀵瑰簲宸ュ崟锛屾娴嬫宸ュ崟鏄惁宸插畬鎴� 瀹屾垚鍗冲彲灏嗗叾閫佸叆搴� + + var work = workinfoRepository.Find(x => x.workOrder == item.Number && x.drawingNo == x.drawingNo && x.heatID == item.heatNumber && x.processCode == "17").FirstOrDefault(); + if (work == null) { - //todo: 璋冪敤WMS鎺ュ彛鍒涘缓浠诲姟 - dt_agvtask agvtask = new dt_agvtask() + item.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟淇℃伅锛�"; + item.location_state = LocationStateEnum.Abnormal.ToString(); + stationinfoRepository.Update(item, true); + continue; + } + + dt_stationinfo TargetLocation = null; + string tasktype = ""; + if (item.quantity == 5 /*|| CompeletedNum == 0*/) + { + + + if (/*(mesinfo.quantity <= 50 &&*/ !string.IsNullOrEmpty(work.area) || item.stationCode.Contains("3")) { - agv_fromaddress = item.stationCode, - agv_id = Guid.NewGuid(), - agv_grade = 0, - agv_barcode = "", - agv_createtime = DateTime.Now, - agv_taskstate = TaskStatus.Created.ToString(), - agv_toaddress = TargetLocation.stationCode, + //todo 瀵绘壘鍙斁璐у鍗忔斁璐у彴 + tasktype = "TaskType_OutsourceInbound"; + TargetLocation = GetEmptyLocation(stationinfoRepository); - }; + } + else + { + //todo: 璋冪敤WMS鎺ュ彛鍒涘缓浠诲姟 + tasktype = "TaskType_Inbound"; + TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, work, item); + } + 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(work.processCode), + agv_materbarcode = work.materialCode, + agv_Traytype = item.tray_type, + jobID = item.Number, + agv_TrayStatus = item.tray_status + }; + agvtaskRepository.Add(agvtask, true); - freeDB.Add(agvtask); - TargetLocation.location_state = LocationStateEnum.Busy.ToString(); - freeDB.Update(TargetLocation); + item.location_state = LocationStateEnum.InBusy.ToString(); + stationinfoRepository.Update(item, true); + + TargetLocation.location_state = LocationStateEnum.InBusy.ToString(); + TargetLocation.stationType = agvtask.agv_materielid; + TargetLocation.heatNumber = item.heatNumber; + TargetLocation.billetID = item.billetID; + TargetLocation.Number = agvtask.jobID; + stationinfoRepository.Update(TargetLocation, true); + WriteDBLog.Success("鍒涘缓鍏ュ簱浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS"); + } } } - } + catch (Exception ex) + { + WriteDBLog.Error("鍒涘缓鍏ュ簱浠诲姟", $"閿欒淇℃伅锛� {ex.Message}", "PCS"); + } + } /// <summary> @@ -69,68 +134,109 @@ /// <param name="workinfo">璁㈠崟</param> /// <param name="stationinfo">涓嬫枡鍙d俊鎭�</param> /// <returns></returns> - private dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_Workinfo workinfo, dt_stationinfo stationinfo) + public static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_mes_head mesinfo, dt_stationinfo stationinfo, int CompeletedNum, float e) { //鏀捐揣浣� dt_stationinfo TargetLocation = null; - //鏍规嵁璁㈠崟鏁伴噺鏉ュ鎵惧搴斿簱鍖轰笖鍚岀墿鏂欑被鍨嬪簱浣� + #region 鍚岀被鍨嬫斁涓�琛� + //if (area1 == "1") + TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo).FirstOrDefault(); - if (workinfo.PlannedQuantity < 50) //搴撳尯1 鐗╂枡绫诲瀷澶� + //TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == area1).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault(); + if (TargetLocation != null) { - dt_stationinfo station = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.area == "1").OrderByDescending(x => x.lastUpdateTime).FirstOrDefault(); - if (station != null) + #region 鍚屼竴琛屽彧鍏佽涓�涓换鍔� + //var count = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.enable && x.area == TargetLocation.area && x.location_state == LocationStateEnum.Busy.ToString()).ToList(); + //if (count.Count > 0) + // return null; + #endregion + + #region 鍑哄簱浠诲姟浼樺厛,瀛樺湪鍑哄簱浠诲姟鍒欎笉鑳藉叆搴� + bool OutTask = false; + if (TargetLocation.area == "1") { - //濡傚瓨鍦ㄥ悓鐗╂枡绫诲瀷涓斿湪1琛岀殑搴撳瓨鍒欐柊鍏ュ簱鐨勭墿鏂欐斁鑷冲悓鍒� 涓嶅瓨鍦ㄥ垯瀵绘壘鏂拌搴撲綅 - if (station.line == 1) - { - TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.column == station.column && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); - } - TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.line == 1 && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); + 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.area == "1" && x.location_state == LocationStateEnum.Empty.ToString() && x.line == 1 && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); - } - } - else - { - //int quantity = Convert.ToInt32(workinfo.PlannedQuantity); - //string area = GetArea(quantity); - - dt_materielinfo materielinfo = freeDB.Select<dt_materielinfo>().Where(x => x.materiel_id == stationinfo.stationType).First(); - - if (materielinfo == null) - throw new Exception($"鏃犳鐗╂枡绫诲瀷{stationinfo.stationType}搴撳尯"); - - string area = materielinfo.materiel_areaid.ToString(); - - //濡傚瓨鍦ㄥ悓绫诲瀷鐗╂枡鍒欐斁缃悓琛屽簱浣� 涓嶅瓨鍦ㄥ垯鏀剧疆鏂拌鐨勭涓�鍒椾腑 - dt_stationinfo station = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.area == area).OrderBy(x => x.lastUpdateTime).FirstOrDefault(); - if (station != null) - { - TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.line == station.line).OrderBy(x => x.column).FirstOrDefault(); - if (TargetLocation == null) - { - TargetLocation = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault(); - } - } - else - { - TargetLocation = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault(); + 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; } - //todo 濡傜墿鏂欏凡婊″垯鏀剧疆鍏朵粬搴撳尯 - //if (TargetLocation == null) - //{ - // stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault(); - //} - } + #endregion - if (TargetLocation == null) - { - throw new Exception("搴撲綅宸叉弧"); + //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 + + #region 鏍规嵁璁㈠崟鏁伴噺鏉ュ鎵惧搴斿簱鍖轰笖鍚岀墿鏂欑被鍨嬪簱浣� + //if (workinfo.PlannedQuantity < 50) //搴撳尯1 鐗╂枡绫诲瀷澶� + //{ + // dt_stationinfo station = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.area == "1").OrderByDescending(x => x.lastUpdateTime).FirstOrDefault(); + // if (station != null) + // { + // //濡傚瓨鍦ㄥ悓鐗╂枡绫诲瀷涓斿湪1琛岀殑搴撳瓨鍒欐柊鍏ュ簱鐨勭墿鏂欐斁鑷冲悓鍒� 涓嶅瓨鍦ㄥ垯瀵绘壘鏂拌搴撲綅 + // if (station.line == 1) + // { + // TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.column == station.column && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); + // } + // TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.line == 1 && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); + // } + // else + // { + // TargetLocation = stationinfoRepository.Find(x => x.area == "1" && x.location_state == LocationStateEnum.Empty.ToString() && x.line == 1 && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); + // } + //} + //else + //{ + //int quantity = Convert.ToInt32(workinfo.PlannedQuantity); + //string area = GetArea(quantity); + + //dt_materielinfo materielinfo = freeDB.Select<dt_materielinfo>().Where(x => x.materiel_id == stationinfo.stationType).First(); + + //if (materielinfo == null) + // throw new Exception($"鏃犳鐗╂枡绫诲瀷{stationinfo.stationType}搴撳尯"); + + //string area = materielinfo.materiel_areaid.ToString(); + + //濡傚瓨鍦ㄥ悓绫诲瀷鐗╂枡鍒欐斁缃悓琛屽簱浣� 涓嶅瓨鍦ㄥ垯鏀剧疆鏂拌鐨勭涓�鍒椾腑 + //dt_stationinfo station = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.area == area).OrderBy(x => x.lastUpdateTime).FirstOrDefault(); + //if (station != null) + //{ + // TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.line == station.line).OrderBy(x => x.column).FirstOrDefault(); + // if (TargetLocation == null) + // { + // TargetLocation = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault(); + // } + //} + //else + //{ + // TargetLocation = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault(); + //} + + //todo 濡傜墿鏂欏凡婊″垯鏀剧疆鍏朵粬搴撳尯 + //if (TargetLocation == null) + //{ + // stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault(); + //} + //} + //if (TargetLocation == null) + //{ + // throw new Exception("搴撲綅宸叉弧"); + //} //else if (workinfo.PlannedQuantity >= 50 && workinfo.PlannedQuantity < 110) //搴撳尯2 //{ @@ -148,24 +254,191 @@ //else if(workinfo.PlannedQuantity >= 110 && workinfo.PlannedQuantity < 180) //{ + //} + #endregion + + VOLContext context = new VOLContext(); + Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(context); + Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context); + var detail = mes_DetailRepository.Find(x => x.jobID == mesinfo.jobID).FirstOrDefault(); + if (detail == null) + { + stationinfo.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟瀛愯〃锛�"; + stationinfo.location_state = LocationStateEnum.Abnormal.ToString(); + 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*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault(); + } + else + { + inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault(); + } + #endregion + + + #region 鏍规嵁搴撳瓨鏌ユ壘鍙叆搴撶┖璐т綅 + if (inventory != null) + { + var station = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode); + if (/*CompeletedNum <= 15 ||*/ station.area == "1") + { + TargetLocation = stationinfoRepository.Find(x => x.column == station.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderByDescending(x => x.line).FirstOrDefault(); + } + else + { + TargetLocation = stationinfoRepository.Find(x => x.line == station.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault(); + } + if (TargetLocation != null) return TargetLocation; + } + #endregion + + + + var area1 = string.IsNullOrEmpty(mesinfo.area) ? GetArea(mesinfo.quantity, e) : mesinfo.area; + + 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(); + } + else + { + //if (50 < mesinfo.quantity && mesinfo.quantity <= 180 && e < 1100) + // TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); + //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); + + + 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 (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) + // TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "4" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault(); + } + + #region + + //鏍规嵁璁㈠崟鐐夊彿/宸ュ崟鍙�/绫诲瀷 + //if (mesinfo.quantity >= 180) + //{ + // //鏌ヨ搴撳瓨璁板綍涓槸鍚﹀瓨鍦ㄥ悓绫诲瀷/宸ュ崟/鐐夊彿鐨勮褰� 濡傛湁鍒欐斁缃悓涓�琛岋紝鏃犲垯瀵绘壘鏂板簱浣� + // var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First(); + // var inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID && x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First(); + // if (inventory != null) + // { + // //int line = Convert.ToInt16(inventory.stationCode.Split("-")[0]); + // var line = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode).line; + // TargetLocation = stationinfoRepository.Find(x => x.line == line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault(); + // if (TargetLocation == null && CompeletedNum <= 15) + // { + // TargetLocation = stationinfoRepository.Find(x => x.area == "1" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); + // } + // } + // else + // { + // TargetLocation = stationinfoRepository.Find(x => x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault(); + + // } //} + #endregion + + if (TargetLocation == null) + { + throw new Exception("搴撲綅宸叉弧"); + } 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; + List<string> target = new List<string>() { "W01001003", "W01001002", "W01001001" }; + var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�"); + if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒"); + 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(); + 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凡婊�"); + } + return TargetLocation; + } /// <summary> /// 鏍规嵁璁㈠崟鏁伴噺杩斿洖搴撳尯(鏆傛椂寮冪敤) //鏇存崲涓哄簱浣嶇被鍨嬪尮閰� /// </summary> /// <param name="quantity"></param> /// <returns></returns> - private string GetArea(int quantity) + private static string GetArea(int quantity, float e) { - if (quantity >= 50 && quantity < 180) - return "2"; - else if (quantity >= 180 && quantity < 180) - return "3"; - else if (quantity >= 180 && quantity < 220) + if (e < 1100) + { + if (quantity <= 180) + return "2"; + else /*if (quantity <= 225)*/ + return "3"; + } + else + { return "4"; - return null; + } + + //if (quantity > 50 && quantity <= 180 && e < 1100) + // return "2"; + //else if (quantity > 180 && quantity <= 225 && e < 1100) + // return "3"; + //else if (quantity > 50 && e > 1100) + // return "4"; + //return null; } } } -- Gitblit v1.9.3