/// <summary> /// 如果长时间无法交互,则自动交互。 /// </summary> void AutoPressByDeviceErrorAsync(long capturedCurrentAsmTaskItemId, Ptl900U ptl900U, Display900UItem display900UItem) { ThreadPool.QueueUserWorkItem(_ => { DateTime beginSleepTime = DateTime.Now; while (this.CurrentAsmTaskItemId == capturedCurrentAsmTaskItemId && ptl900U.InError != false && (DateTime.Now - beginSleepTime) < this.autoPressTimeout) { Thread.Sleep(1); } if (this.CurrentAsmTaskItemId == capturedCurrentAsmTaskItemId && ptl900U.InError != false) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems .First(ti => ti.Id == capturedCurrentAsmTaskItemId); ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem; ASM_AssembleIndication asmAssembleIndication = asmAssembleIndicationItem.ASM_AssembleIndication; CFG_Cart cfgCart = asmTaskItem.CFG_Cart; Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 长时间无法交互,自动交互:" + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + ", " + asmAssembleIndicationItem.MaterialCode + ", " + asmAssembleIndicationItem.MaterialName + ", " + cfgCart.Name + ", " + asmTaskItem.CartPosition + Environment.NewLine); } } catch { } ptl900U.Clear(true); Ptl900UPressedEventArgs ptl900UPressedEventArgs = new Ptl900UPressedEventArgs(); ptl900UPressedEventArgs.ResultByItem.Add(display900UItem, display900UItem.Count); this.ptl900U_Pressed(ptl900U, ptl900UPressedEventArgs, true); } }); }
/// <summary> /// 生成装配指引任务。 /// </summary> /// <param name="asmAssembleIndication">从接口解析还未持久化的车身抵达记录。</param> /// <param name="dbContext">数据上下文。</param> public static void Generate(ASM_AssembleIndication asmAssembleIndication, GeelyPtlEntities dbContext) { List <ASM_AssembleIndicationItem> asmAssembleIndicationItems = asmAssembleIndication.ASM_AssembleIndicationItems .OrderBy(aii => aii.AssembleSequence) .ToList(); List <CFG_Cart> dockedCfgCarts = dbContext.CFG_WorkStationCurrentCarts .Where(wscc => wscc.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId && (wscc.CFG_Cart.CartStatus == CartStatus.ArrivedAtWorkStation || wscc.CFG_Cart.CartStatus == CartStatus.Indicating)) .OrderBy(wscc => wscc.DockedTime) .Select(wscc => wscc.CFG_Cart) .Distinct() .ToList(); List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = new List <CFG_CartCurrentMaterial>(); foreach (CFG_Cart cfgCart in dockedCfgCarts) { cfgCartCurrentMaterials.AddRange(cfgCart.CFG_CartCurrentMaterials.Where(ccm => ccm.AST_CartTaskItemId != null && ccm.Quantity > 0)); } ASM_Task asmTask = new ASM_Task(); asmTask.ASM_AssembleIndication = asmAssembleIndication; asmTask.AssembleStatus = AssembleStatus.New; dbContext.ASM_Tasks.Add(asmTask); Dictionary <string, int> lockedQuantityByMaterialCode = new Dictionary <string, int>(); foreach (ASM_AssembleIndicationItem asmAssembleIndicationItem in asmAssembleIndicationItems) { string materialCode = asmAssembleIndicationItem.MaterialCode; string projectCode = asmAssembleIndicationItem.ProjectCode; string projectStep = asmAssembleIndicationItem.ProjectStep; string batchCode = asmAssembleIndicationItem.BatchCode; int lockedQuantity = 0; if (lockedQuantityByMaterialCode.ContainsKey(materialCode)) { lockedQuantity = lockedQuantityByMaterialCode[materialCode]; } else { lockedQuantityByMaterialCode.Add(materialCode, lockedQuantity); } List <CFG_CartCurrentMaterial> sameMaterialCfgCartCurrentMaterials = cfgCartCurrentMaterials .Where(ccm => ccm.MaterialCode == materialCode && string.Equals(ccm.ProjectCode, projectCode, StringComparison.OrdinalIgnoreCase) && string.Equals(ccm.ProjectStep, projectStep, StringComparison.OrdinalIgnoreCase)) .OrderBy(ccm => ccm.Position) .ToList(); //替代料 foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials .Where(ccm => ccm.MaterialCode == materialCode)) { if (!sameMaterialCfgCartCurrentMaterials.Contains(cfgCartCurrentMaterial)) { List <AST_LesTaskItem> astLesTaskItems = cfgCartCurrentMaterial .AST_CartTaskItem .AST_PalletTaskItem .AST_LesTaskItems .ToList(); foreach (AST_LesTaskItem astLesTaskItem in astLesTaskItems) { if (astLesTaskItem.AST_LesTask.ProjectCode.EndsWith(projectCode) && astLesTaskItem.AST_LesTask.ProjectStep.EndsWith(projectStep)) { sameMaterialCfgCartCurrentMaterials.Add(cfgCartCurrentMaterial); break; } } } } //如果给出了批次,则应用限制 if (!string.IsNullOrEmpty(batchCode)) { for (int i = sameMaterialCfgCartCurrentMaterials.Count - 1; i >= 0; i--) { if (sameMaterialCfgCartCurrentMaterials[i].BatchCode != batchCode) { sameMaterialCfgCartCurrentMaterials.RemoveAt(i); } } } //如果料不够,一个原始装配明细可能被拆分到不同库位,生成多个指引明细 int currentAsmAssembleIndicationItemAssignedQuantity = 0; while (currentAsmAssembleIndicationItemAssignedQuantity < asmAssembleIndicationItem.ToAssembleQuantity) { //找到第一个未被完全锁定的库位 CFG_CartCurrentMaterial cfgCartCurrentMaterial = null; //针对单个储位的未完成明细数量 int unfinishedQuantity = 0; int temporaryLockedQuantity = lockedQuantity; foreach (CFG_CartCurrentMaterial temporaryCfgCartCurrentMaterial in sameMaterialCfgCartCurrentMaterials) { //未完成的任务也会锁定库存 List <ASM_TaskItem> unfinishedAsmTaskItems = dbContext.ASM_TaskItems .Where(ti => ti.CFG_CartId == temporaryCfgCartCurrentMaterial.CFG_CartId && ti.CartPosition == temporaryCfgCartCurrentMaterial.Position && ti.AssembleStatus != AssembleStatus.Finished) .ToList(); unfinishedQuantity = 0; foreach (ASM_TaskItem unfinishedAsmTaskItem in unfinishedAsmTaskItems) { unfinishedQuantity += unfinishedAsmTaskItem.ToAssembleQuantity; if (unfinishedAsmTaskItem.AssembledQuantity != null) { unfinishedQuantity -= unfinishedAsmTaskItem.AssembledQuantity.Value; } } if (temporaryLockedQuantity < temporaryCfgCartCurrentMaterial.Quantity - unfinishedQuantity) { cfgCartCurrentMaterial = temporaryCfgCartCurrentMaterial; break; } else { temporaryLockedQuantity -= temporaryCfgCartCurrentMaterial.Quantity.Value - unfinishedQuantity; if (temporaryLockedQuantity < 0) { temporaryLockedQuantity = 0; } } } if (cfgCartCurrentMaterial == null) { int unfinishedAsmTaskItemsQuantity = dbContext.ASM_TaskItems .Where(ti => ti.ASM_Task.ASM_AssembleIndication.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId && ti.ASM_AssembleIndicationItem.MaterialCode == asmAssembleIndicationItem.MaterialCode && ti.AssembleStatus != AssembleStatus.Finished) .Select(ti => ti.ToAssembleQuantity) .ToList() .Sum(); List <string> storageDetails = dbContext.CFG_CartCurrentMaterials .Where(ccm => ccm.BatchCode == asmAssembleIndicationItem.BatchCode && ccm.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId && ccm.MaterialCode == asmAssembleIndicationItem.MaterialCode && ccm.Quantity > 0) .ToList() .Select(ccm => ccm.CFG_Cart.Name + " 储位 " + ccm.Position + " 存量 " + ccm.Quantity + " (" + ccm.ProjectCode + ", " + ccm.ProjectStep + ")") .ToList(); List <string> dockedCfgCartNames = dockedCfgCarts .Select(c => c.Name) .ToList(); int lesPickedQuantity = dbContext.AST_LesTaskItems .Where(lti => lti.MaterialCode == asmAssembleIndicationItem.MaterialCode && lti.AST_LesTask.BatchCode == asmAssembleIndicationItem.BatchCode) .Select(lti => lti.ToPickQuantity) .ToList() .Sum(); List <string> mesAssembledItems = dbContext.ASM_AssembleIndicationItems .Include(aii => aii.ASM_AssembleIndication) .Where(aii => aii.MaterialCode == asmAssembleIndicationItem.MaterialCode && aii.BatchCode == asmAssembleIndicationItem.BatchCode) .ToList() .Select(aii => aii.ASM_AssembleIndication.ProductSequence + "," + aii.AssembledQuantity) .ToList(); string message = "线边库存不足:" + materialCode + "。" + Environment.NewLine + "需求数量:" + asmAssembleIndicationItem.ToAssembleQuantity + Environment.NewLine; if (unfinishedAsmTaskItemsQuantity > 0) { message += "前车未完:" + unfinishedAsmTaskItemsQuantity + Environment.NewLine; } if (storageDetails.Count > 0) { message += "料车存量:" + Environment.NewLine; message += string.Join(Environment.NewLine, storageDetails) + Environment.NewLine; } if (dockedCfgCartNames.Count > 0) { message += "停靠料车:" + string.Join(", ", dockedCfgCartNames) + Environment.NewLine; } message += "LES 出库数量:" + lesPickedQuantity + Environment.NewLine; if (mesAssembledItems.Count > 0) { message += "MES 使用情况:" + Environment.NewLine; message += string.Join(Environment.NewLine, mesAssembledItems) + Environment.NewLine; } throw new Exception(message); } int remainQuantity = cfgCartCurrentMaterial.Quantity.Value - unfinishedQuantity - temporaryLockedQuantity; int toAssembleQuantity = asmAssembleIndicationItem.ToAssembleQuantity - currentAsmAssembleIndicationItemAssignedQuantity; toAssembleQuantity = Math.Min(remainQuantity, toAssembleQuantity); ASM_TaskItem asmTaskItem = new ASM_TaskItem(); asmTaskItem.ASM_Task = asmTask; asmTaskItem.ASM_AssembleIndicationItem = asmAssembleIndicationItem; asmTaskItem.Gzz = asmAssembleIndicationItem.Gzz; asmTaskItem.CFG_CartId = cfgCartCurrentMaterial.CFG_CartId; asmTaskItem.CartPosition = cfgCartCurrentMaterial.Position; asmTaskItem.AssembleSequence = asmAssembleIndicationItem.AssembleSequence; asmTaskItem.ToAssembleQuantity = toAssembleQuantity; asmTaskItem.Qtxbs = asmAssembleIndicationItem.Qtxbs; asmTaskItem.AssembleStatus = AssembleStatus.New; dbContext.ASM_TaskItems.Add(asmTaskItem); lockedQuantity += toAssembleQuantity; lockedQuantityByMaterialCode[materialCode] = lockedQuantity; currentAsmAssembleIndicationItemAssignedQuantity += toAssembleQuantity; } } }
/// <summary> /// 按发布器表示短拣。 /// </summary> void ptl900UPublisher_Pressed(object sender, Ptl900UPressedEventArgs e) { while (true) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems .First(ti => ti.Id == this.CurrentAsmTaskItemId.Value); ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem; ASM_AssembleIndication asmAssembleIndication = asmAssembleIndicationItem.ASM_AssembleIndication; List <ASM_TaskItem> otherAsmTaskItems = asmAssembleIndicationItem.ASM_TaskItems .Where(ti => ti.Id != asmTaskItem.Id) .ToList(); CFG_Cart cfgCart = asmTaskItem.CFG_Cart; KeyValuePair <Display900UItem, ushort> display900UitemAndResult = e.ResultByItem.First(); asmTaskItem.AssembledQuantity = display900UitemAndResult.Value; asmTaskItem.AssembledTime = DateTime.Now; asmTaskItem.AssembleStatus = AssembleStatus.Finished; if (asmAssembleIndicationItem.AssembledQuantity == null) { asmAssembleIndicationItem.AssembledQuantity = 0; } asmAssembleIndicationItem.AssembledQuantity += display900UitemAndResult.Value - display900UitemAndResult.Key.Count; asmAssembleIndicationItem.AssembledTime = DateTime.Now; if (otherAsmTaskItems.All(ti => ti.AssembleStatus == AssembleStatus.Finished)) { asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Finished; } dbContext.SaveChanges(); CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId); Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher(); Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition); Ptl900U ptl900ULight = cartPtl.GetPtl900ULight(); ptl900U.Pressed -= this.ptl900U_Pressed; ptl900U.Clear(true); ptl900UPublisher.Pressed -= this.ptl900UPublisher_Pressed; ptl900ULight.Clear(); this.CurrentAsmTaskItemId = null; Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 短拣:" + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + ", " + asmAssembleIndicationItem.MaterialCode + ", " + asmAssembleIndicationItem.MaterialName + ", " + cfgCart.Name + ", " + asmTaskItem.CartPosition + Environment.NewLine); } break; } catch (Exception ex) { string message = ex.Message; DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException; if (dbEntityValidationException != null) { foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors) { foreach (DbValidationError validationError in validationResult.ValidationErrors) { message += Environment.NewLine + validationError.ErrorMessage; } } } message += Environment.NewLine + ex.StackTrace; Logger.Log("IndicatingExecutor.ptl900UPublisher_Pressed", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); Thread.Sleep(1000); } } }
void ptl900U_Pressed(object sender, Ptl900UPressedEventArgs e, bool pickAll) { while (true) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems .First(ti => ti.Id == this.CurrentAsmTaskItemId.Value); ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem; ASM_AssembleIndication asmAssembleIndication = asmAssembleIndicationItem.ASM_AssembleIndication; List <ASM_TaskItem> otherAsmTaskItems = asmAssembleIndicationItem.ASM_TaskItems .Where(ti => ti.Id != asmTaskItem.Id) .ToList(); CFG_Cart cfgCart = asmTaskItem.CFG_Cart; List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials .OrderBy(ccm => ccm.Position) .ToList(); CFG_CartCurrentMaterial cfgCartCurrentMaterial = cfgCartCurrentMaterials.First(ccm => ccm.Position == asmTaskItem.CartPosition); CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts .FirstOrDefault(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.CFG_CartId == cfgCart.Id); if (asmTaskItem.AssembledQuantity == null) { asmTaskItem.AssembledQuantity = 0; } int pickedCount = 1; if (pickAll) { pickedCount = asmTaskItem.ToAssembleQuantity - asmTaskItem.AssembledQuantity.Value; } asmTaskItem.AssembledQuantity += pickedCount; asmTaskItem.AssembledTime = DateTime.Now; if (asmAssembleIndicationItem.AssembledQuantity == null) { asmAssembleIndicationItem.AssembledQuantity = 0; } asmAssembleIndicationItem.AssembledQuantity += pickedCount; asmAssembleIndicationItem.AssembledTime = DateTime.Now; bool currentItemFinished = asmTaskItem.AssembledQuantity == asmTaskItem.ToAssembleQuantity; if (currentItemFinished) { asmTaskItem.AssembleStatus = AssembleStatus.Finished; if (otherAsmTaskItems.All(ti => ti.AssembleStatus == AssembleStatus.Finished)) { asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Finished; } } if (cfgCartCurrentMaterial.Quantity != null && cfgCartCurrentMaterial.Quantity > 0) { cfgCartCurrentMaterial.Quantity -= pickedCount; } //料车上物料消耗完则施放料车并通知 AGV 回收,再尝试补充一辆料车 if (cfgCartCurrentMaterials.All(ccm => ccm.Quantity == null || ccm.Quantity == 0)) { cfgCart.CartStatus = CartStatus.Free; foreach (CFG_CartCurrentMaterial innerCfgCartCurrentMaterial in cfgCartCurrentMaterials) { innerCfgCartCurrentMaterial.AST_CartTaskItemId = null; innerCfgCartCurrentMaterial.ProjectCode = null; innerCfgCartCurrentMaterial.WbsId = null; innerCfgCartCurrentMaterial.ProjectStep = null; innerCfgCartCurrentMaterial.CFG_WorkStationId = null; innerCfgCartCurrentMaterial.BatchCode = null; innerCfgCartCurrentMaterial.CFG_ChannelId = null; innerCfgCartCurrentMaterial.CFG_PalletId = null; innerCfgCartCurrentMaterial.BoxCode = null; innerCfgCartCurrentMaterial.FromPalletPosition = null; innerCfgCartCurrentMaterial.MaterialCode = null; innerCfgCartCurrentMaterial.MaterialName = null; innerCfgCartCurrentMaterial.MaterialBarcode = null; innerCfgCartCurrentMaterial.Quantity = null; innerCfgCartCurrentMaterial.AssortedTime = null; innerCfgCartCurrentMaterial.CFG_EmployeeId = null; if (innerCfgCartCurrentMaterial.Usability != CartPositionUsability.DisableByOffLineDevice) { innerCfgCartCurrentMaterial.Usability = CartPositionUsability.Enable; } } if (cfgWorkStationCurrentCart != null) { //通知 AGV 回收当前车,尝试空满切换下一辆车 DST_AgvSwitch dstAgvSwitch = dbContext.DST_AgvSwitchs.FirstOrDefault(t => t.isOpen); if (dstAgvSwitch != null) { int nCurPosition = cfgWorkStationCurrentCart.Position; string sWorkStationCode = cfgWorkStationCurrentCart.CFG_WorkStation.Code; if (nCurPosition <= 4) //内侧 { //如果对应外侧没有正在执行的物料超市配送任务,才生成里侧的线边配送任务 string sOutPosition = sWorkStationCode + "-" + (nCurPosition + 4); DST_DistributeTask outDistributeTask = dbContext.DST_DistributeTasks.FirstOrDefault(t => t.DistributeReqTypes == DistributeReqTypes.MaterialMarketDistribute && t.endPosition.Equals(sOutPosition) && t.sendErrorCount < 5 && t.arriveTime == null); if (outDistributeTask == null) { CFG_WorkStationCurrentCart cfgOutWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts .FirstOrDefault(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.Position == nCurPosition + 4 && wscc.CFG_CartId != null); if (cfgOutWorkStationCurrentCart != null) { //生成料架转换任务 List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductCartSwitchTask(cfgCart); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } else { //生成线边自动清线配送任务 List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductAreaAutoClearTask(sWorkStationCode, nCurPosition.ToString(), cfgCart.Code); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } } } else //外侧 { //如果对应里侧没有正在执行的空满转换任务,才生成外侧的线边配送任务 string sInPosition = sWorkStationCode + "-" + (nCurPosition - 4); DST_DistributeTask inDistributeTask = dbContext.DST_DistributeTasks.FirstOrDefault(t => t.DistributeReqTypes == DistributeReqTypes.ProductCartSwitch && t.startPosition.Equals(sInPosition) && t.sendErrorCount < 5 && t.arriveTime == null); if (inDistributeTask == null) { //生成线边配送任务 string sTaskSendType = "自动"; List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductAreaDistributeTask(sWorkStationCode, nCurPosition.ToString(), cfgCart.Code, sTaskSendType, true, dbContext); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } } } else { //解除停靠 cfgWorkStationCurrentCart.CFG_CartId = null; cfgWorkStationCurrentCart.DockedTime = null; } } //尝试发起下一车的拉料任务 CFG_Cart nextCfgCart = dbContext.CFG_Carts .FirstOrDefault(c => c.CartStatus == CartStatus.ArrivedAtBufferArea && c.CFG_CartCurrentMaterials.Any(ccm => ccm.CFG_WorkStationId == this.CFG_WorkStationId && ccm.Quantity > 0)); if (nextCfgCart != null) { nextCfgCart.CartStatus = CartStatus.NeedToWorkStation; CFG_CartCurrentMaterial firstCfgCartFirstCartCurrentMaterial = nextCfgCart.CFG_CartCurrentMaterials .First(ccm => ccm.Quantity > 0); FND_Task fndTask = new FND_Task(); fndTask.ProjectCode = firstCfgCartFirstCartCurrentMaterial.ProjectCode; fndTask.ProjectStep = firstCfgCartFirstCartCurrentMaterial.ProjectStep; fndTask.BatchCode = firstCfgCartFirstCartCurrentMaterial.BatchCode; fndTask.MaxNeedArrivedTime = DateTime.Now.AddHours(1); fndTask.RequestTime = DateTime.Now; fndTask.CFG_WorkStationId = firstCfgCartFirstCartCurrentMaterial.CFG_WorkStationId.Value; fndTask.CFG_CartId = nextCfgCart.Id; fndTask.LightColor = (byte)LightColor.Off; fndTask.FindingStatus = FindingStatus.New; dbContext.FND_Tasks.Add(fndTask); } } dbContext.SaveChanges(); CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId); Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher(); Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition); Ptl900U ptl900ULight = cartPtl.GetPtl900ULight(); if (currentItemFinished) { Display900UItem cartPublisherDisplay900UItem = new Display900UItem(); cartPublisherDisplay900UItem.Name = "抵达工位 " + cfgWorkStation.Name; cartPublisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0} 阶段:{1} 批次:{2}", cfgCartCurrentMaterial.ProjectCode, cfgCartCurrentMaterial.ProjectStep, cfgCartCurrentMaterial.BatchCode); if (cfgWorkStationCurrentCart != null) { cartPublisherDisplay900UItem.Count = (ushort)cfgWorkStationCurrentCart.Position; } cartPublisherDisplay900UItem.Unit = "位"; ptl900UPublisher.Pressed -= this.ptl900UPublisher_Pressed; ptl900UPublisher.Clear(true); ptl900UPublisher.Lock(); ptl900UPublisher.Display(cartPublisherDisplay900UItem, LightColor.Off); ptl900U.Pressed -= this.ptl900U_Pressed; ptl900ULight.Clear(); this.CurrentAsmTaskItemId = null; } else { Display900UItem publisherDisplay900UItem = new Display900UItem(); publisherDisplay900UItem.Name = asmAssembleIndicationItem.MaterialName; publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0},{1} 车号:{2} 量产工位:{3}", asmAssembleIndicationItem.ProjectCode, asmAssembleIndicationItem.ProjectStep, asmAssembleIndication.ProductSequence, asmAssembleIndicationItem.Gzz); publisherDisplay900UItem.LongSubLocation = asmTaskItem.ToAssembleQuantity.ToString(CultureInfo.InvariantCulture); publisherDisplay900UItem.Count = (ushort)asmTaskItem.AssembledQuantity.Value; Display900UItem display900UItem = new Display900UItem(); display900UItem.Count = (ushort)(asmTaskItem.ToAssembleQuantity - asmTaskItem.AssembledQuantity.Value); LightMode lightMode = new LightMode(); lightMode.Color = LightColor.Green; if (asmAssembleIndicationItem.Qtxbs == "1") { lightMode.Color = LightColor.Magenta; lightMode.Ratio = LightOnOffRatio.RatioP1V1; lightMode.Period = LightOnOffPeriod.Period500; } ptl900UPublisher.Clear(true); //ptl900UPublisher.Unlock(); ptl900UPublisher.Lock(); ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off, true); ptl900U.Display(display900UItem, lightMode, true); //如果长时间无法交互,则自动交互 this.AutoPressByDeviceErrorAsync(this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem); } string logMessage = (pickAll ? " 拣选所有:" : " 拣选一个:") + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + ", " + asmAssembleIndicationItem.MaterialCode + ", " + asmAssembleIndicationItem.MaterialName + ", " + cfgCart.Name + ", " + asmTaskItem.CartPosition; if (currentItemFinished) { logMessage += ", 明细完成"; } Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + logMessage + Environment.NewLine); } break; } catch (Exception ex) { string message = ex.Message; DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException; if (dbEntityValidationException != null) { foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors) { foreach (DbValidationError validationError in validationResult.ValidationErrors) { message += Environment.NewLine + validationError.ErrorMessage; } } } message += Environment.NewLine + ex.StackTrace; Logger.Log("IndicatingExecutor.ptl900U_Pressed", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); Thread.Sleep(1000); } } }
/// <summary> /// 如果新底盘抵达,则自动完成之前的。 /// </summary> void AutoPressByNewCarArrivedAsync(long capturedCurrentAsmTaskId, long capturedCurrentAsmTaskItemId, Ptl900U ptl900U, Display900UItem display900UItem) { ThreadPool.QueueUserWorkItem(_ => { Thread.CurrentThread.Name = "IndicatingExecutor.AutoPressByNewCarArrivedAsync_" + this.CFG_WorkStationId; while (true) { if (this.CurrentAsmTaskItemId != capturedCurrentAsmTaskItemId) { break; } try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { bool hasOtherTask = dbContext.ASM_Tasks .Any(t => t.ASM_AssembleIndication.CFG_WorkStationId == this.CFG_WorkStationId && t.AssembleStatus != AssembleStatus.Finished && t.Id != capturedCurrentAsmTaskId); if (hasOtherTask && this.CurrentAsmTaskItemId == capturedCurrentAsmTaskItemId) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems .First(ti => ti.Id == capturedCurrentAsmTaskItemId); ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem; ASM_AssembleIndication asmAssembleIndication = asmAssembleIndicationItem.ASM_AssembleIndication; CFG_Cart cfgCart = asmTaskItem.CFG_Cart; Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 新底盘抵达,自动完成之前的:" + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + ", " + asmAssembleIndicationItem.MaterialCode + ", " + asmAssembleIndicationItem.MaterialName + ", " + cfgCart.Name + ", " + asmTaskItem.CartPosition + Environment.NewLine); ptl900U.Clear(true); Ptl900UPressedEventArgs ptl900UPressedEventArgs = new Ptl900UPressedEventArgs(); ptl900UPressedEventArgs.ResultByItem.Add(display900UItem, display900UItem.Count); this.ptl900U_Pressed(ptl900U, ptl900UPressedEventArgs, true); break; } } } catch (Exception ex) { string message = ex.Message; DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException; if (dbEntityValidationException != null) { foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors) { foreach (DbValidationError validationError in validationResult.ValidationErrors) { message += Environment.NewLine + validationError.ErrorMessage; } } } message += Environment.NewLine + ex.StackTrace; Logger.Log("IndicatingExecutor.AutoPressByNewCarArrivedAsync", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); } finally { Thread.Sleep(1000); } } }); }
void threadStart(object notUsed) { while (true) { //加载线程推动新明细,按钮交互推进明细的进度 if (this.CurrentAsmTaskId != null && this.CurrentAsmTaskItemId == null) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); ASM_Task asmTask = dbContext.ASM_Tasks .First(t => t.Id == this.CurrentAsmTaskId.Value); //因为 IndicatingExecutorLoader 加载和 IndicatingExecutor 是不同线程,所以再次核对状态 if (asmTask.AssembleStatus == AssembleStatus.Finished) { this.CurrentAsmTaskId = null; continue; } ASM_AssembleIndication asmAssembleIndication = asmTask.ASM_AssembleIndication; ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems .OrderBy(ti => ti.Gzz) .ThenBy(ti => ti.AssembleSequence) .FirstOrDefault(ti => ti.ASM_TaskId == asmTask.Id && ti.AssembleStatus != AssembleStatus.Finished); if (asmTaskItem == null) { asmTask.AssembleStatus = AssembleStatus.Finished; asmAssembleIndication.AssembleStatus = asmTask.AssembleStatus; #region 当前装配可以提交 List <ASM_AssembleIndicationItem> asmAssembleIndicatonItems = asmAssembleIndication.ASM_AssembleIndicationItems .ToList(); ASM_AssembleResult asmAssembleResult = new ASM_AssembleResult(); asmAssembleResult.ASM_AssembleIndicationId = asmAssembleIndication.Id; asmAssembleResult.FactoryCode = asmAssembleIndication.FactoryCode; asmAssembleResult.ProductionLineCode = asmAssembleIndication.ProductionLineCode; asmAssembleResult.CFG_WorkStationId = asmAssembleIndication.CFG_WorkStationId; asmAssembleResult.GzzList = asmAssembleIndication.GzzList; asmAssembleResult.MONumber = asmAssembleIndication.MONumber; asmAssembleResult.ProductSequence = asmAssembleIndication.ProductSequence; asmAssembleResult.BeginTime = asmTask.ASM_TaskItems.OrderBy(ati => ati.AssembledTime).First().AssembledTime.Value; asmAssembleResult.EndTime = asmTask.ASM_TaskItems.OrderBy(ati => ati.AssembledTime).Last().AssembledTime.Value; dbContext.ASM_AssembleResults.Add(asmAssembleResult); ASM_AssembleResultMessage asmAssembleResultMessage = new ASM_AssembleResultMessage(); asmAssembleResultMessage.ASM_AssembleResult = asmAssembleResult; asmAssembleResultMessage.SentSuccessful = false; dbContext.ASM_AssembleResultMessages.Add(asmAssembleResultMessage); foreach (ASM_AssembleIndicationItem asmAssembleIndicationItem in asmAssembleIndicatonItems) { List <ASM_TaskItem> asmTaskItems = asmAssembleIndicationItem.ASM_TaskItems .ToList(); ASM_TaskItem lastAsmTaskItem = asmTaskItems.Last(); ASM_AssembleResultItem asmAssembleResultItem = new ASM_AssembleResultItem(); asmAssembleResultItem.ASM_AssembleResult = asmAssembleResult; asmAssembleResultItem.CFG_CartId = lastAsmTaskItem.CFG_CartId; asmAssembleResultItem.CartPosition = lastAsmTaskItem.CartPosition; asmAssembleResultItem.Gzz = asmAssembleIndicationItem.Gzz; asmAssembleResultItem.MaterialCode = asmAssembleIndicationItem.MaterialCode; asmAssembleResultItem.MaterialName = asmAssembleIndicationItem.MaterialName; asmAssembleResultItem.AssembleSequence = asmAssembleIndicationItem.AssembleSequence; asmAssembleResultItem.ToAssembleQuantity = asmAssembleIndicationItem.ToAssembleQuantity; asmAssembleResultItem.AssembledQuantity = asmTaskItems.Sum(ti => ti.AssembledQuantity.Value); asmAssembleResultItem.PickedTime = lastAsmTaskItem.AssembledTime.Value; asmAssembleResultItem.ProjectCode = asmAssembleIndicationItem.ProjectCode; asmAssembleResultItem.ProjectStep = asmAssembleIndicationItem.ProjectStep; dbContext.ASM_AssembleResultItems.Add(asmAssembleResultItem); } #endregion dbContext.SaveChanges(); this.CurrentAsmTaskId = null; Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 装配任务完成:" + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + Environment.NewLine); } else { ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem; CFG_Cart cfgCart = asmTaskItem.CFG_Cart; //先更新数据库 asmTask.AssembleStatus = AssembleStatus.Assembling; asmTaskItem.AssembleStatus = AssembleStatus.Assembling; asmAssembleIndication.AssembleStatus = AssembleStatus.Assembling; asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Assembling; cfgCart.CartStatus = CartStatus.Indicating; dbContext.SaveChanges(); //再控制设备 CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId); Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher(); Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition); Ptl900U ptl900ULight = cartPtl.GetPtl900ULight(); Display900UItem publisherDisplay900UItem = new Display900UItem(); publisherDisplay900UItem.Name = asmAssembleIndicationItem.MaterialName; publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0},{1} 车号:{2} 量产工位:{3}", asmAssembleIndicationItem.ProjectCode, asmAssembleIndicationItem.ProjectStep, asmAssembleIndication.ProductSequence, asmAssembleIndicationItem.Gzz); publisherDisplay900UItem.LongSubLocation = asmTaskItem.ToAssembleQuantity.ToString(CultureInfo.InvariantCulture); publisherDisplay900UItem.Count = 0; Display900UItem display900UItem = new Display900UItem(); display900UItem.Count = (ushort)asmTaskItem.ToAssembleQuantity; LightMode lightMode = new LightMode(); lightMode.Color = LightColor.Green; if (asmAssembleIndicationItem.Qtxbs == "1") { lightMode.Color = LightColor.Magenta; lightMode.Ratio = LightOnOffRatio.RatioP1V1; lightMode.Period = LightOnOffPeriod.Period500; } //ptl900UPublisher.Pressed += this.ptl900UPublisher_Pressed; ptl900UPublisher.Clear(true); //ptl900UPublisher.Unlock(); ptl900UPublisher.Lock(); ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off, true); ptl900U.Pressed += this.ptl900U_Pressed; ptl900U.Unlock(); ptl900U.Display(display900UItem, lightMode, true); ptl900ULight.Clear(); ptl900ULight.Display(new Display900UItem(), lightMode, false); this.CurrentAsmTaskItemId = asmTaskItem.Id; Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 点亮装配明细:" + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + ", " + asmAssembleIndicationItem.MaterialCode + ", " + asmAssembleIndicationItem.MaterialName + ", " + cfgCart.Name + ", " + asmTaskItem.CartPosition + Environment.NewLine); //如果新底盘抵达,则自动完成之前的 this.AutoPressByNewCarArrivedAsync(this.CurrentAsmTaskId.Value, this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem); //如果长时间无法交互,则自动交互 this.AutoPressByDeviceErrorAsync(this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem); } } } catch (Exception ex) { string message = ex.Message; DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException; if (dbEntityValidationException != null) { foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors) { foreach (DbValidationError validationError in validationResult.ValidationErrors) { message += Environment.NewLine + validationError.ErrorMessage; } } } message += Environment.NewLine + ex.StackTrace; Logger.Log("IndicatingExecutor.threadStart", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); Thread.Sleep(1000); } } Thread.Sleep(1); } }