/// <summary> /// 查询当前任务。 /// </summary> /// <param name="cfgChannelId">巷道的主键。</param> public AndroidPdaTaskInfo QueryCurrentTaskInfo(int cfgChannelId) { AssortingExecutor assortingExecutor = AssortingExecutorLoader.Instance.GetByChannelId(cfgChannelId); AndroidPdaTaskInfo result = new AndroidPdaTaskInfo(); result.CFG_ChannelId = cfgChannelId; using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { if (assortingExecutor.CurrentCfgCartId != null) { CFG_Cart cfgCart = dbContext.CFG_Carts .First(c => c.Id == assortingExecutor.CurrentCfgCartId.Value); result.CFG_CartId = cfgCart.Id; result.CartName = cfgCart.Name; result.CartOnLine = cfgCart.OnLine; } if (assortingExecutor.CurrentAstCartTaskItemId == null) { if (assortingExecutor.CurrentAstPalletTaskItemId != null) { AST_PalletTaskItem currentAstPalletTaskItem = dbContext.AST_PalletTaskItems .First(pti => pti.Id == assortingExecutor.CurrentAstPalletTaskItemId.Value); List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = dbContext.CFG_CartCurrentMaterials .Where(ccm => ccm.CFG_CartId == assortingExecutor.CurrentCfgCartId.Value) .ToList(); foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials) { if (cfgCartCurrentMaterial.AST_CartTaskItemId == null) { //整层大件需要同层的两个空库位 if (currentAstPalletTaskItem.IsBig) { if ((cfgCartCurrentMaterial.Position == 1 && cfgCartCurrentMaterials[1].Usability != CartPositionUsability.Enable) || (cfgCartCurrentMaterial.Position == 2 && cfgCartCurrentMaterials[0].Usability != CartPositionUsability.Enable) || (cfgCartCurrentMaterial.Position == 3 && cfgCartCurrentMaterials[3].Usability != CartPositionUsability.Enable) || (cfgCartCurrentMaterial.Position == 4 && cfgCartCurrentMaterials[2].Usability != CartPositionUsability.Enable) || (cfgCartCurrentMaterial.Position == 5 && cfgCartCurrentMaterials[5].Usability != CartPositionUsability.Enable) || (cfgCartCurrentMaterial.Position == 6 && cfgCartCurrentMaterials[4].Usability != CartPositionUsability.Enable) || (cfgCartCurrentMaterial.Position == 7 && cfgCartCurrentMaterials[7].Usability != CartPositionUsability.Enable) || (cfgCartCurrentMaterial.Position == 8 && cfgCartCurrentMaterials[6].Usability != CartPositionUsability.Enable)) { continue; } } result.CartPositions.Add(cfgCartCurrentMaterial.Position); } } } } else { AST_CartTaskItem astCartTaskItem = dbContext.AST_CartTaskItems .First(cti => cti.Id == assortingExecutor.CurrentAstCartTaskItemId.Value); result.CartPositions.Add(astCartTaskItem.CartPosition); result.PickedQuantity = astCartTaskItem.AssortedQuantity; result.AssortingStatus = astCartTaskItem.AssortingStatus; } if (assortingExecutor.CurrentAstPalletTaskItemId != null) { AST_PalletTaskItem astPalletTaskItem = dbContext.AST_PalletTaskItems .First(pti => pti.Id == assortingExecutor.CurrentAstPalletTaskItemId.Value); result.MaterialCode = astPalletTaskItem.MaterialCode; result.MaterialName = astPalletTaskItem.MaterialName; result.ToPickQuantity = astPalletTaskItem.ToPickQuantity; } } return(result); }
/// <summary> /// 按托合并原始分拣任务。 /// </summary> /// <param name="astPalletArrived">从接口解析还未持久化的托盘抵达记录。</param> /// <param name="dbContext">数据上下文。</param> public static void Generate(AST_PalletArrived astPalletArrived, GeelyPtlEntities dbContext) { List <AST_LesTask> astLesTasks = dbContext.AST_LesTasks .Where(lt => lt.BatchCode == astPalletArrived.BatchCode && lt.CFG_PalletId == astPalletArrived.CFG_PalletId && lt.CFG_ChannelId == astPalletArrived.CFG_ChannelId && astPalletArrived.PickBillIds.Contains(lt.BillCode) && !lt.TaskGenerated) .ToList(); if (astLesTasks.Count > 0) { AST_LesTask mainAstLesTask = astLesTasks.First(); AST_PalletTask astPalletTask = new AST_PalletTask(); astPalletTask.CFG_PalletId = astPalletArrived.CFG_PalletId; astPalletTask.BatchCode = mainAstLesTask.BatchCode; astPalletTask.PickBillIds = astPalletArrived.PickBillIds; astPalletTask.ProjectCode = astPalletArrived.ProjectCode; astPalletTask.WbsId = mainAstLesTask.WbsId; astPalletTask.ProjectStep = astPalletArrived.ProjectStep; astPalletTask.CFG_ChannelId = astPalletArrived.CFG_ChannelId; astPalletTask.PickStatus = PickStatus.New; astPalletTask.CreateTime = DateTime.Now; dbContext.AST_PalletTasks.Add(astPalletTask); //提取当前目标工位、当前批次、当前巷道、当前托盘未合并的原始任务 List <int> cfgWorkStationIds = astLesTasks .Select(lt => lt.CFG_WorkStationId) .Distinct() .ToList(); foreach (int cfgWorkStationId in cfgWorkStationIds) { ILookup <int, AST_LesTask> astLesTaskLookupByFromPalletPosition = astLesTasks .Where(lt => lt.CFG_WorkStationId == cfgWorkStationId) .OrderBy(lt => lt.FromPalletPosition) .ToLookup(lt => lt.FromPalletPosition); //明细的合并,特殊件单独拣 foreach (IGrouping <int, AST_LesTask> astLesTaskGroupingByFromPalletPosition in astLesTaskLookupByFromPalletPosition) { int fromPalletPosition = astLesTaskGroupingByFromPalletPosition.Key; AST_LesTask mainAstLesTaskByWorkStation = astLesTaskGroupingByFromPalletPosition.First(); List <AST_LesTaskItem> normalAstLesTaskItems = new List <AST_LesTaskItem>(); List <AST_LesTaskItem> specialAstLesTaskItems = new List <AST_LesTaskItem>(); foreach (AST_LesTask astLesTask in astLesTaskGroupingByFromPalletPosition) { normalAstLesTaskItems.AddRange(astLesTask.AST_LesTaskItems.Where(lti => !lti.IsSpecial)); specialAstLesTaskItems.AddRange(astLesTask.AST_LesTaskItems.Where(lti => lti.IsSpecial)); } //普通件 if (normalAstLesTaskItems.Count > 0) { AST_LesTaskItem mainAstLesTaskItem = normalAstLesTaskItems.First(); int totalNormalQuantity = normalAstLesTaskItems.Sum(lti => lti.ToPickQuantity); AST_PalletTaskItem astPalletTaskItem = new AST_PalletTaskItem(); astPalletTaskItem.AST_PalletTask = astPalletTask; astPalletTaskItem.CFG_WorkStationId = cfgWorkStationId; astPalletTaskItem.BoxCode = mainAstLesTaskByWorkStation.BoxCode; astPalletTaskItem.FromPalletPosition = fromPalletPosition; astPalletTaskItem.MaterialCode = mainAstLesTaskItem.MaterialCode; astPalletTaskItem.MaterialName = mainAstLesTaskItem.MaterialName; astPalletTaskItem.MaterialBarcode = mainAstLesTaskItem.MaterialBarcode; astPalletTaskItem.ToPickQuantity = totalNormalQuantity; astPalletTaskItem.MaxQuantityInSingleCartPosition = mainAstLesTaskItem.MaxQuantityInSingleCartPosition; astPalletTaskItem.IsSpecial = false; astPalletTaskItem.IsBig = mainAstLesTaskItem.IsBig; astPalletTaskItem.PickStatus = PickStatus.New; dbContext.AST_PalletTaskItems.Add(astPalletTaskItem); foreach (AST_LesTaskItem normalAstLesTaskItem in normalAstLesTaskItems) { normalAstLesTaskItem.AST_PalletTaskItem = astPalletTaskItem; } } //特殊件 foreach (AST_LesTaskItem astLesTaskItem in specialAstLesTaskItems) { AST_PalletTaskItem astPalletTaskItem = new AST_PalletTaskItem(); astPalletTaskItem.AST_PalletTask = astPalletTask; astPalletTaskItem.CFG_WorkStationId = cfgWorkStationId; astPalletTaskItem.BoxCode = mainAstLesTaskByWorkStation.BoxCode; astPalletTaskItem.FromPalletPosition = fromPalletPosition; astPalletTaskItem.MaterialCode = astLesTaskItem.MaterialCode; astPalletTaskItem.MaterialName = astLesTaskItem.MaterialName; astPalletTaskItem.MaterialBarcode = astLesTaskItem.MaterialBarcode; astPalletTaskItem.ToPickQuantity = astLesTaskItem.ToPickQuantity; astPalletTaskItem.MaxQuantityInSingleCartPosition = astLesTaskItem.MaxQuantityInSingleCartPosition; astPalletTaskItem.IsSpecial = true; astPalletTaskItem.IsBig = astLesTaskItem.IsBig; astPalletTaskItem.PickStatus = PickStatus.New; dbContext.AST_PalletTaskItems.Add(astPalletTaskItem); astLesTaskItem.AST_PalletTaskItem = astPalletTaskItem; } //标记已合并按托任务 foreach (AST_LesTask astLesTask in astLesTaskGroupingByFromPalletPosition) { astLesTask.TaskGenerated = true; } } } } }
/// <summary> /// 按巷道查询当前任务。 /// </summary> /// <param name="cfgChannelId">巷道的主键。</param> public AssortingKanbanTaskInfo QueryCurrentTaskInfo(int cfgChannelId) { AssortingKanbanTaskInfo result = new AssortingKanbanTaskInfo(); try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { AST_PalletTask astPalletTask = dbContext.AST_PalletTasks .FirstOrDefault(pt => pt.CFG_ChannelId == cfgChannelId && pt.PickStatus != PickStatus.Finished); //新增PDA拣料显示 if (astPalletTask == null) { AST_PalletTask lastPalletTask = dbContext.AST_PalletTasks.Where(t => t.CFG_ChannelId == cfgChannelId).OrderByDescending(t => t.CreateTime).FirstOrDefault(); DateTime dPtlPalletLastArriveTime = DateTime.MinValue; if (lastPalletTask != null) { dPtlPalletLastArriveTime = lastPalletTask.CreateTime; } result = QueryPDACurrentTaskInfo(cfgChannelId, dPtlPalletLastArriveTime); if (result != null) { return(result); } result = new AssortingKanbanTaskInfo(); } AST_CartTask astCartTask = dbContext.AST_CartTaskItems .Where(cti => cti.AST_CartTask.CFG_ChannelId == cfgChannelId && cti.AssortingStatus != AssortingStatus.Finished) .Select(cti => cti.AST_CartTask) .FirstOrDefault(); string currentBatchCode; if (astPalletTask == null) { currentBatchCode = dbContext.AST_LesTasks .Where(lt => lt.CFG_ChannelId == cfgChannelId && !lt.TaskGenerated) .Select(lt => lt.BatchCode) .FirstOrDefault(); } else { currentBatchCode = astPalletTask.BatchCode; } if (!string.IsNullOrEmpty(currentBatchCode)) { AST_LesTask currentBatchFirstAstLesTask = new AST_LesTask(); if (astPalletTask == null) { currentBatchFirstAstLesTask = dbContext.AST_LesTasks.First(lt => lt.BatchCode == currentBatchCode); } else { currentBatchFirstAstLesTask = dbContext.AST_LesTasks.First(lt => lt.BatchCode == currentBatchCode && lt.CFG_PalletId == astPalletTask.CFG_PalletId); } string projectCode = currentBatchFirstAstLesTask.ProjectCode; string projectStep = currentBatchFirstAstLesTask.ProjectStep; string[] codes = projectCode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] steps = projectStep.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (codes.Length > 1 && codes[0] == codes[1]) { projectCode = codes[0]; } if (steps.Length > 1 && steps[0] == steps[1]) { projectStep = steps[0]; } result.CurrentBatchInfo.PickType = "P"; //PTL料架拣料 //result.CurrentBatchInfo.PickType = 1; //PTL料架拣料 result.CurrentBatchInfo.ProjectCode = projectCode; result.CurrentBatchInfo.ProjectStep = projectStep; result.CurrentBatchInfo.BatchCode = currentBatchFirstAstLesTask.BatchCode; result.CurrentBatchInfo.FinishedPalletCount = dbContext.AST_PalletResults .Count(pr => pr.CFG_ChannelId == cfgChannelId && pr.BatchCode == currentBatchCode); result.CurrentBatchInfo.TotalPalletCount = dbContext.AST_LesTasks .Where(lt => lt.CFG_ChannelId == cfgChannelId && lt.BatchCode == currentBatchCode) .Select(lt => lt.CFG_PalletId) .Distinct() .Count(); //以下 4 个汇总界面不展示 result.CurrentBatchInfo.FinishedMaterialTypeCount = 0; result.CurrentBatchInfo.TotalMaterialTypeCount = 0; result.CurrentBatchInfo.FinishedMaterialCount = 0; result.CurrentBatchInfo.TotalMaterialCount = 0; List <CFG_ChannelCurrentCart> cfgChannelCurrentCarts = dbContext.CFG_ChannelCurrentCarts .Where(ccc => ccc.CFG_ChannelId == cfgChannelId) .OrderBy(ccc => ccc.Position) .ToList(); foreach (CFG_ChannelCurrentCart cfgChannelCurrentCart in cfgChannelCurrentCarts) { CFG_ChannelCurrentCartDto cfgChannelCurrentCartDto = new CFG_ChannelCurrentCartDto(); cfgChannelCurrentCartDto.CFG_ChannelCurrentCartId = cfgChannelCurrentCart.Id; cfgChannelCurrentCartDto.CFG_ChannelId = cfgChannelCurrentCart.CFG_ChannelId; cfgChannelCurrentCartDto.Position = cfgChannelCurrentCart.Position; cfgChannelCurrentCartDto.CFG_CartId = cfgChannelCurrentCart.CFG_CartId; if (cfgChannelCurrentCart.CFG_Cart != null) { cfgChannelCurrentCartDto.CartCode = cfgChannelCurrentCart.CFG_Cart.Code; cfgChannelCurrentCartDto.CartName = cfgChannelCurrentCart.CFG_Cart.Name; } } if (astPalletTask != null) { AST_PalletTaskDto astPalletTaskDto = new AST_PalletTaskDto(); astPalletTaskDto.AST_PalletTaskId = astPalletTask.Id; astPalletTaskDto.CFG_PalletId = astPalletTask.CFG_PalletId; astPalletTaskDto.PalletCode = astPalletTask.CFG_Pallet.Code; astPalletTaskDto.PalletType = astPalletTask.CFG_Pallet.PalletType; astPalletTaskDto.PalletRotationStatus = astPalletTask.CFG_Pallet.PalletRotationStatus; List <AST_PalletTaskItem> astPalletTaskItems = astPalletTask.AST_PalletTaskItems .OrderBy(pti => pti.FromPalletPosition) .ToList(); astPalletTaskItems.Sort(new PalletTaskSortComparer()); //正在拣选的排在最前面 foreach (AST_PalletTaskItem astPalletTaskItem in astPalletTaskItems) { AST_PalletTaskItemDto astPalletTaskItemDto = new AST_PalletTaskItemDto(); astPalletTaskItemDto.AST_PalletTaskItemId = astPalletTaskItem.Id; astPalletTaskItemDto.FromPalletPosition = astPalletTaskItem.FromPalletPosition; astPalletTaskItemDto.WorkStationCode = astPalletTaskItem.CFG_WorkStation.Code; astPalletTaskItemDto.MaterialCode = astPalletTaskItem.MaterialCode; astPalletTaskItemDto.MaterialName = astPalletTaskItem.MaterialName; astPalletTaskItemDto.MaterialBarcode = astPalletTaskItem.MaterialBarcode; astPalletTaskItemDto.ToPickQuantity = astPalletTaskItem.ToPickQuantity; astPalletTaskItemDto.IsSpecial = astPalletTaskItem.IsSpecial; astPalletTaskItemDto.IsBig = astPalletTaskItem.IsBig; astPalletTaskItemDto.PickStatus = astPalletTaskItem.PickStatus; astPalletTaskItemDto.PickedQuantity = astPalletTaskItem.PickedQuantity; astPalletTaskDto.Items.Add(astPalletTaskItemDto); } result.CurrentPalletTask = astPalletTaskDto; } if (astCartTask != null) { AST_CartTaskDto astCartTaskDto = new AST_CartTaskDto(); astCartTaskDto.AST_CartTaskId = astCartTask.Id; astCartTaskDto.CFG_CartId = astCartTask.CFG_CartId; astCartTaskDto.CartCode = astCartTask.CFG_Cart.Code; astCartTaskDto.CartName = astCartTask.CFG_Cart.Name; List <AST_CartTaskItem> astCartTaskItems = astCartTask.AST_CartTaskItems .OrderBy(cti => cti.CartPosition) .ToList(); foreach (AST_CartTaskItem astCartTaskItem in astCartTaskItems) { AST_PalletTaskItem astPalletTaskItem = astCartTaskItem.AST_PalletTaskItem; AST_CartTaskItemDto astCartTaskItemDto = new AST_CartTaskItemDto(); astCartTaskItemDto.AST_CartTaskItemId = astCartTaskItem.Id; astCartTaskItemDto.CartPosition = astCartTaskItem.CartPosition; astCartTaskItemDto.WorkStationCode = astCartTask.CFG_WorkStation.Code; astCartTaskItemDto.MaterialCode = astPalletTaskItem.MaterialCode; astCartTaskItemDto.MaterialName = astPalletTaskItem.MaterialName; astCartTaskItemDto.MaterialBarcode = astPalletTaskItem.MaterialBarcode; astCartTaskItemDto.MaxQuantityInSingleCartPosition = astPalletTaskItem.MaxQuantityInSingleCartPosition; astCartTaskItemDto.IsSpecial = astPalletTaskItem.IsSpecial; astCartTaskItemDto.IsBig = astPalletTaskItem.IsBig; astCartTaskItemDto.AssortingStatus = astCartTaskItem.AssortingStatus; astCartTaskItemDto.PickedQuantity = astCartTaskItem.AssortedQuantity; astCartTaskDto.Items.Add(astCartTaskItemDto); } result.CurrentCartTask = astCartTaskDto; } } } } 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("ForAssortingKanbanService.QueryCurrentTaskInfo", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); } return(result); }