Пример #1
0
        /// <summary>
        /// 转换托盘抵达分拣口报文-PDA。
        /// </summary>
        /// <param name="xml">托盘抵达分拣口报文。</param>
        /// <param name="dbContext">数据库上下文。</param>
        /// <returns>成功解析的实体。</returns>
        public static AST_PalletArrived_PDA ConvertRequestPDA(string xml, GeelyPtlEntities dbContext)
        {
            XDocument xDocument      = XDocument.Parse(xml);
            XElement  serviceElement = xDocument.Descendants("Service").First();
            XElement  dataElement    = serviceElement.Descendants("Data").First();
            XElement  requestElement = dataElement.Descendants("Request").First();
            XElement  arrivedElement = requestElement.Descendants("ASSEMBLE").First();

            AST_PalletArrived_PDA astPalletArrived = new AST_PalletArrived_PDA();

            astPalletArrived.ProjectCode = arrivedElement.Element("ProjectCode").Value;
            astPalletArrived.WbsId       = arrivedElement.Element("PS_POSID").Value;
            astPalletArrived.ProjectStep = arrivedElement.Element("StageCode").Value;

            string batchCode = arrivedElement.Element("BatchCode").Value;

            if (!dbContext.AST_LesTask_PDAs.Any(lt => lt.BatchCode == batchCode))
            {
                throw new InterfaceDataException("该批次的任务未下发:" + batchCode);
            }

            astPalletArrived.BatchCode = batchCode;

            string      cfgChannelCode = arrivedElement.Element("ChannelCode").Value;
            CFG_Channel cfgChannel     = dbContext.CFG_Channels
                                         .FirstOrDefault(c => c.Code == cfgChannelCode);

            if (cfgChannel == null)
            {
                throw new InterfaceDataException("无效的分拣巷道:" + cfgChannelCode);
            }

            astPalletArrived.CFG_ChannelId = cfgChannel.Id;

            string     cfgPalletCode = arrivedElement.Element("PalletCode").Value;
            CFG_Pallet cfgPallet     = dbContext.CFG_Pallets
                                       .FirstOrDefault(c => c.Code == cfgPalletCode);

            if (cfgPallet == null)
            {
                throw new InterfaceDataException("无效的托盘编码:" + cfgPalletCode);
            }

            cfgPallet.PalletType = arrivedElement.Element("PalletType").Value;

            astPalletArrived.CFG_PalletId = cfgPallet.Id;
            astPalletArrived.PickBillIds  = arrivedElement.Element("PickBillIDs").Value;
            astPalletArrived.ArrivedTime  = DateTime.Now;

            return(astPalletArrived);
        }
Пример #2
0
        /// <summary>
        /// 按托合并原始分拣任务-PDA。
        /// </summary>
        /// <param name="astPalletArrived">从接口解析还未持久化的托盘抵达记录。</param>
        /// <param name="dbContext">数据上下文。</param>
        public static void GeneratePDA(AST_PalletArrived_PDA astPalletArrived, GeelyPtlEntities dbContext)
        {
            List <AST_LesTask_PDA> astLesTasks = dbContext.AST_LesTask_PDAs
                                                 .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_PDA mainAstLesTask = astLesTasks.First();

                AST_PalletTask_PDA astPalletTask = new AST_PalletTask_PDA();
                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_PalletTask_PDAs.Add(astPalletTask);

                //提取当前目标工位、当前批次、当前巷道、当前托盘未合并的原始任务
                List <int> cfgWorkStationIds = astLesTasks
                                               .Select(lt => lt.CFG_WorkStationId)
                                               .Distinct()
                                               .ToList();
                foreach (int cfgWorkStationId in cfgWorkStationIds)
                {
                    ILookup <int, AST_LesTask_PDA> astLesTaskLookupByFromPalletPosition = astLesTasks
                                                                                          .Where(lt => lt.CFG_WorkStationId == cfgWorkStationId)
                                                                                          .OrderBy(lt => lt.FromPalletPosition)
                                                                                          .ToLookup(lt => lt.FromPalletPosition);

                    //明细的合并,特殊件单独拣
                    foreach (IGrouping <int, AST_LesTask_PDA> astLesTaskGroupingByFromPalletPosition in astLesTaskLookupByFromPalletPosition)
                    {
                        int             fromPalletPosition          = astLesTaskGroupingByFromPalletPosition.Key;
                        AST_LesTask_PDA mainAstLesTaskByWorkStation = astLesTaskGroupingByFromPalletPosition.First();

                        List <AST_LesTaskItem_PDA> normalAstLesTaskItems  = new List <AST_LesTaskItem_PDA>();
                        List <AST_LesTaskItem_PDA> specialAstLesTaskItems = new List <AST_LesTaskItem_PDA>();

                        foreach (AST_LesTask_PDA astLesTask in astLesTaskGroupingByFromPalletPosition)
                        {
                            normalAstLesTaskItems.AddRange(astLesTask.AST_LesTaskItem_PDAs.Where(lti => !lti.IsSpecial));
                            specialAstLesTaskItems.AddRange(astLesTask.AST_LesTaskItem_PDAs.Where(lti => lti.IsSpecial));
                        }

                        //普通件
                        if (normalAstLesTaskItems.Count > 0)
                        {
                            AST_LesTaskItem_PDA mainAstLesTaskItem = normalAstLesTaskItems.First();
                            int totalNormalQuantity = normalAstLesTaskItems.Sum(lti => lti.ToPickQuantity);

                            AST_PalletTaskItem_PDA astPalletTaskItem = new AST_PalletTaskItem_PDA();
                            astPalletTaskItem.AST_PalletTask_PDA = 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_PalletTaskItem_PDAs.Add(astPalletTaskItem);

                            foreach (AST_LesTaskItem_PDA normalAstLesTaskItem in normalAstLesTaskItems)
                            {
                                normalAstLesTaskItem.AST_PalletTaskItem_PDA = astPalletTaskItem;
                            }
                        }

                        //特殊件
                        foreach (AST_LesTaskItem_PDA astLesTaskItem in specialAstLesTaskItems)
                        {
                            AST_PalletTaskItem_PDA astPalletTaskItem = new AST_PalletTaskItem_PDA();
                            astPalletTaskItem.AST_PalletTask_PDA = 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_PalletTaskItem_PDAs.Add(astPalletTaskItem);

                            astLesTaskItem.AST_PalletTaskItem_PDA = astPalletTaskItem;
                        }

                        //标记已合并按托任务
                        foreach (AST_LesTask_PDA astLesTask in astLesTaskGroupingByFromPalletPosition)
                        {
                            astLesTask.TaskGenerated = true;
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// PDA拣料托盘抵达分拣口
        /// </summary>
        public string LesSendBoxPDA(string xml)
        {
            try { XDocument.Parse(xml); }
            catch (Exception ex) { return("ERROR:" + ex.Message); }

            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    AST_PalletArrived_PDA astPalletArrived = AST_PalletArrivedConverter.ConvertRequestPDA(xml, dbContext);
                    if (!dbContext.AST_PalletArrived_PDAs.Any(pa => pa.BatchCode == astPalletArrived.BatchCode &&
                                                              pa.CFG_PalletId == astPalletArrived.CFG_PalletId &&
                                                              pa.PickBillIds == astPalletArrived.PickBillIds))
                    {
                        AST_PalletArrivedMessage_PDA astPalletArrivedMessage = new AST_PalletArrivedMessage_PDA();
                        astPalletArrivedMessage.AST_PalletArrived_PDA = astPalletArrived;
                        astPalletArrivedMessage.ReceivedXml           = xml;
                        astPalletArrivedMessage.ReceivedTime          = DateTime.Now;

                        dbContext.AST_PalletArrived_PDAs.Add(astPalletArrived);
                        dbContext.AST_PalletArrivedMessage_PDAs.Add(astPalletArrivedMessage);

                        //托盘到达时按托合并任务
                        CFG_ChannelCurrentPallet cfgChannelCurrentPallet = dbContext.CFG_ChannelCurrentPallets
                                                                           .First(ccp => ccp.CFG_ChannelId == astPalletArrived.CFG_ChannelId);
                        cfgChannelCurrentPallet.CFG_PalletId = astPalletArrived.CFG_PalletId;
                        cfgChannelCurrentPallet.ArrivedTime  = astPalletArrived.ArrivedTime;

                        CFG_Pallet cfgPallet = astPalletArrived.CFG_Pallet;
                        cfgPallet.PalletRotationStatus = PalletRotationStatus.Normal;

                        //按托任务生成
                        AssortingTaskGenerator.GeneratePDA(astPalletArrived, dbContext);

                        dbContext.SaveChanges();
                    }
                }

                return(AST_PalletArrivedConverter.ConvertResponse(xml, true, string.Empty));
            }
            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("LesSendBoxPDA", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine +
                           xml + Environment.NewLine
                           + message + Environment.NewLine
                           + Environment.NewLine);
                return(AST_PalletArrivedConverter.ConvertResponse(xml, false, message));
            }
        }