二段Linq Groupby操作

2018-06-22 04:35:07来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

var messages = list.GroupBy(p=>p.RefOrderNo,(k,v)=> new {OrderNo = k,SkuInfo = v})
                    .Select(p =>
                    {
                        var item = p.SkuInfo.FirstOrDefault();
                        return new ReplaceLabelSkuMessage
                        {
                            OrderNo = p.OrderNo,
                            Operation = new WMS.Message.Operation
                            {
                                Operator = item.CreateBy,
                                OperateTime = item.CreateOn
                            },
                            ReplaceLabelSkuDetail = p.SkuInfo.Select(s => new ReplaceLabelSkuDetail
                            {
                                SKU = s.SKU,
                                Weight = s.Weight,
                                Lenght = s.Lenght,
                                Width = s.Width,
                                Height = s.Height
                            }).ToList()
                        };                        
                    });
var request = deliveryList.GroupBy(g => g.DeliveryNo)
                    .Select(delivery =>
                    {
                        var item = delivery.FirstOrDefault();
                        var yewuRequest = new DeliveryTicketShipOutMessage
                        {
                            DeliveryTicketNo = item.DeliveryNo,
                            DeliveryType = TMS.Message.DeliveryTicket.DeliveryType.Logistics,
                            WarehouseCode = item.YewuWarehouseCode,
                            ShipOutWarehouse = item.YewuWarehouseCode,

                            SkuContainers = delivery.GroupBy(g => g.ContainerCode).Select(container =>
                            {
                                var containerLine = container.FirstOrDefault();
                                return new LogisticsDeliveryShipOutCustomerAsnContainerRequest
                                {
                                    ContainerId = containerLine.ContainerCode,
                                    customerOrderType = TMS.Message.Common.CutomerOrderType.First,
                                    TargetWarehouseCode = containerLine.TargetWarehouseCode,
                                    CustomerAsnId = containerLine.CustomerAsnId,
                                    PalletId = containerLine.PalletId,
                                    Weight = new Weight { Value = containerLine.Weight, Unit = WeightUnit.G },
                                    Size = new Packing() { Length = containerLine.Length, Width = containerLine.Width, Height = containerLine.Height, Unit = LengthUnit.CM },

                                    Lines = container.GroupBy(l => l.SKU).Select(line =>
                                    {
                                        return new LogisticsDeliveryShipOutCustomerAsnContainerLineRequest
                                        {
                                            SKU = line.Key,
                                            Quantity = line.Sum(s => s.PackingQty),
                                            AccountNo = line.FirstOrDefault().CustomerCode
                                        };
                                    }).ToList(),

                                    Bags = container.Where(p => p.BagCode.Length > 0).GroupBy(g => g.BagCode).Select(bag =>
                                    {
                                        var bagid = bag.Key;
                                        return new LogisticsDeliveryShipOutCustomerAsnContainerBagRequest
                                        {
                                            BagId = bagid,
                                            Lines = bag.Select(bagline => new LogisticsDeliveryShipOutCustomerAsnContainerBagLineRequest
                                            {
                                                SKU = bagline.SKU,
                                                Quantity = bagline.PackingQty,
                                                AccountNo = bag.FirstOrDefault().CustomerCode
                                            }).ToList()
                                        };
                                    }).ToList()
                                };
                            }).ToList(),
                            OperateBy = item.CreateBy,
                            OperateOn = item.CreateOn
                        };

                        return yewuRequest;
                    }).ToList();

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:走进 .Net 单元测试

下一篇:c#多态之抽象类与虚方法的异同点~