コード例 #1
0
        /// <summary>
        /// 按巷道查询当前PDA任务。
        /// </summary>
        /// <param name="cfgChannelId">巷道的主键。</param>
        /// <param name="dPtlPalletLastArriveTime">PTL托盘最后到达时间。</param>
        private AssortingKanbanTaskInfo QueryPDACurrentTaskInfo(int cfgChannelId, DateTime dPtlPalletLastArriveTime)
        {
            AssortingKanbanTaskInfo result = new AssortingKanbanTaskInfo();

            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    DateTime minTime = DateTime.Today;
                    DateTime maxTime = minTime.AddDays(1);

                    AST_PalletTask_PDA astPalletTask = null;
                    if (dPtlPalletLastArriveTime == DateTime.MinValue)
                    {
                        astPalletTask = dbContext.AST_PalletTask_PDAs
                                        .Where(pt => pt.CFG_ChannelId == cfgChannelId && pt.PickStatus != PickStatus.Finished && pt.CreateTime > minTime && pt.CreateTime < maxTime)
                                        .OrderByDescending(pt => pt.Id)
                                        .FirstOrDefault();
                    }
                    else
                    {
                        astPalletTask = dbContext.AST_PalletTask_PDAs
                                        .Where(pt => pt.CFG_ChannelId == cfgChannelId && pt.PickStatus != PickStatus.Finished && pt.CreateTime > minTime && pt.CreateTime <maxTime &&
                                                                                                                                                                           pt.CreateTime> dPtlPalletLastArriveTime)
                                        .OrderByDescending(pt => pt.Id)
                                        .FirstOrDefault();
                    }

                    //AST_PalletTask_PDA astPalletTask = dbContext.AST_PalletTask_PDAs
                    //                                   .Where(pt => pt.CFG_ChannelId == cfgChannelId && pt.PickStatus != PickStatus.Finished && pt.CreateTime > minTime && pt.CreateTime < maxTime)
                    //                                   .OrderByDescending(pt => pt.Id)
                    //                                   .FirstOrDefault();

                    //AST_CartTask astCartTask = dbContext.AST_CartTaskItems
                    //                               .Where(cti => cti.AST_CartTask.CFG_ChannelId == cfgChannelId && cti.AssortingStatus != AssortingStatus.Finished)
                    //                               .Select(cti => cti.AST_CartTask)
                    //                               .FirstOrDefault();

                    if (astPalletTask == null)
                    {
                        result = null;
                        return(result);
                    }

                    string currentBatchCode = astPalletTask.BatchCode;

                    if (!string.IsNullOrEmpty(currentBatchCode))
                    {
                        AST_LesTask_PDA currentBatchFirstAstLesTask = dbContext.AST_LesTask_PDAs
                                                                      .Where(lt => lt.CFG_ChannelId == cfgChannelId && lt.BatchCode == currentBatchCode && lt.CFG_PalletId == astPalletTask.CFG_PalletId)
                                                                      .OrderByDescending(lt => lt.Id).FirstOrDefault();

                        result.CurrentBatchInfo.PickType = ConverterPickTypeToText(currentBatchFirstAstLesTask.WbsId); //PDA手持机拣料
                        //result.CurrentBatchInfo.PickType = currentBatchFirstAstLesTask.WbsId; //PDA手持机拣料
                        //result.CurrentBatchInfo.PickType = 2; //PDA手持机拣料
                        result.CurrentBatchInfo.ProjectCode         = currentBatchFirstAstLesTask.ProjectCode;
                        result.CurrentBatchInfo.ProjectStep         = currentBatchFirstAstLesTask.ProjectStep;
                        result.CurrentBatchInfo.BatchCode           = currentBatchFirstAstLesTask.BatchCode;
                        result.CurrentBatchInfo.FinishedPalletCount = dbContext.AST_PalletTask_PDAs
                                                                      .Count(pr => pr.CFG_ChannelId == cfgChannelId && pr.BatchCode == currentBatchCode && pr.PickStatus == PickStatus.Finished);
                        //result.CurrentBatchInfo.FinishedPalletCount = 0;
                        result.CurrentBatchInfo.TotalPalletCount = dbContext.AST_LesTask_PDAs
                                                                   .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_PDA> astPalletTaskItems = astPalletTask.AST_PalletTaskItem_PDAs
                                                                               .OrderBy(pti => pti.FromPalletPosition)
                                                                               .ToList();
                            foreach (AST_PalletTaskItem_PDA 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.QueryPDACurrentTaskInfo", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine
                           + message + Environment.NewLine
                           + Environment.NewLine);
            }

            return(result);
        }
コード例 #2
0
        /// <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);
        }