Пример #1
0
 private void IterateMrpShipPlan(List<MrpShipPlan> shipPlanList, MrpShipPlan mrpShipPlan, int i)
 {
     if (mrpShipPlan.OrderType == Sconit.CodeMaster.OrderType.Distribution)
     {
         if (mrpShipPlan.SourceType == Sconit.CodeMaster.MrpSourceType.Order)
         {
             mrpShipPlan.OrderNo = this.genericMgr.FindById<OrderDetail>(mrpShipPlan.SourceId).OrderNo;
         }
         shipPlanList.Add(mrpShipPlan);
     }
     else
     {
         var newShipPlans = this.genericMgr.FindAll<MrpShipPlan>
             (@"from MrpShipPlan as m where Id=? ", new object[] { mrpShipPlan.SourceId });
         if (newShipPlans == null || newShipPlans.Count() == 0)
         {
             if (mrpShipPlan.SourceType == Sconit.CodeMaster.MrpSourceType.Order)
             {
                 mrpShipPlan.OrderNo = this.genericMgr.FindById<OrderDetail>(mrpShipPlan.SourceId).OrderNo;
             }
             mrpShipPlan.ItemDescription = itemMgr.GetCacheItem(mrpShipPlan.Item).Description;
             shipPlanList.Add(mrpShipPlan);
         }
         else
         {
             foreach (var newShipPlan in newShipPlans)
             {
                 newShipPlan.ItemDescription = itemMgr.GetCacheItem(newShipPlan.Item).Description;
                 if (newShipPlan.OrderType == Sconit.CodeMaster.OrderType.Distribution
                     || newShipPlan.OrderType == Sconit.CodeMaster.OrderType.Production
                     || newShipPlan.OrderType == Sconit.CodeMaster.OrderType.SubContract)
                 {
                     if (newShipPlan.SourceType == Sconit.CodeMaster.MrpSourceType.Order)
                     {
                         newShipPlan.OrderNo = this.genericMgr.FindById<OrderDetail>(newShipPlan.SourceId).OrderNo;
                     }
                     shipPlanList.Add(newShipPlan);
                 }
                 else
                 {
                     i++;
                     if (i < 10)
                     {
                         IterateMrpShipPlan(shipPlanList, newShipPlan, i);
                     }
                 }
             }
         }
     }
 }
Пример #2
0
        protected List<MrpShipPlan> GetProductPlanInList(MrpPlanMaster mrpPlanMaster, DateTime startTime, DateTime endTime, IList<MrpFlowDetail> mrpFlowDetailList = null)
        {
            var shipPlanList = new List<MrpShipPlan>();
            //改成存储过程
            shipPlanList = GetProductPlanInList(mrpPlanMaster.PlanVersion, null) ?? new List<MrpShipPlan>();
            shipPlanList = shipPlanList.Where(p => p.StartTime >= startTime && p.StartTime < endTime).ToList();
            return shipPlanList;

            //订单 //todo 状态为Cancel的处理方法,订单类型为Production
            var activeOrderDic = this.genericMgr.FindAll<ActiveOrder>
                (@" from ActiveOrder where SnapTime =? and ResourceGroup =? and IsIndepentDemand=? ",
                new object[] { mrpPlanMaster.SnapTime, mrpPlanMaster.ResourceGroup, false })
                .GroupBy(p => p.Flow, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g);
            shipPlanList.AddRange(from p in activeOrderDic.SelectMany(p => p.Value)
                                  select new MrpShipPlan
                                  {
                                      Flow = p.Flow,
                                      Item = p.Item,
                                      LocationFrom = p.LocationFrom,
                                      LocationTo = p.LocationTo,
                                      StartTime = p.StartTime,
                                      WindowTime = p.WindowTime,
                                      SourceId = p.OrderDetId,
                                      SourceType = CodeMaster.MrpSourceType.Order,
                                      OrderType = p.OrderType,
                                      Qty = p.DemandQty,
                                      SourceFlow = p.Flow,
                                      SourceParty = p.PartyFrom,
                                      ParentItem = p.Item
                                  });

            //计划,订单覆盖计划
            if (mrpPlanMaster.ResourceGroup == CodeMaster.ResourceGroup.FI)
            {
                var shiftPlanList = this.genericMgr.FindAll<MrpFiShiftPlan>
                    (" from MrpFiShiftPlan where PlanVersion = ? and StartTime >=? and StartTime<=? ",
                    new object[] { mrpPlanMaster.PlanVersion, startTime, endTime });
                foreach (var plan in shiftPlanList)
                {
                    var activeOrderCount = (activeOrderDic.ValueOrDefault(plan.ProductLine) ?? new List<ActiveOrder>())
                        .Count(p => p.StartTime.Date == plan.PlanDate.Date && p.Shift == plan.Shift);
                    if (activeOrderCount == 0)
                    {
                        MrpShipPlan mrpShipPlan = new MrpShipPlan();
                        mrpShipPlan.Bom = plan.Bom;
                        mrpShipPlan.Flow = plan.ProductLine;
                        mrpShipPlan.Item = plan.Item;
                        mrpShipPlan.LocationFrom = plan.LocationFrom;
                        mrpShipPlan.LocationTo = plan.LocationTo;
                        mrpShipPlan.Bom = plan.Bom;
                        mrpShipPlan.StartTime = plan.StartTime;
                        mrpShipPlan.WindowTime = plan.WindowTime;
                        mrpShipPlan.SourceId = plan.Id;
                        mrpShipPlan.SourceType = CodeMaster.MrpSourceType.FiShift;
                        mrpShipPlan.OrderType = CodeMaster.OrderType.Production;
                        mrpShipPlan.Qty = plan.Qty;
                        mrpShipPlan.SourceFlow = plan.ProductLine;
                        mrpShipPlan.SourceParty = GetCacheLocation(mrpShipPlan.LocationFrom).Region;
                        mrpShipPlan.ParentItem = plan.Item;
                        shipPlanList.Add(mrpShipPlan);
                    }
                }
            }
            else if (mrpPlanMaster.ResourceGroup == CodeMaster.ResourceGroup.EX)
            {
                var exShiftPlanList = this.genericMgr.FindAll<MrpExItemPlan>
                    (" from MrpExItemPlan where PlanVersion = ? and PlanDate >=? and PlanDate<=? ",
                    new object[] { mrpPlanMaster.PlanVersion, startTime, endTime });
                var shipPlans = (from p in exShiftPlanList
                                 group p by new
                                 {
                                     Flow = p.ProductLine,
                                     Item = p.Item,
                                     PlanDate = p.PlanDate,
                                 } into g
                                 select new MrpShipPlan
                                 {
                                     //Bom = g.Key.Bom,
                                     Flow = g.Key.Flow,
                                     Item = g.Key.Item,
                                     //LocationFrom = g.Key.LocationFrom,
                                     //LocationTo = g.Key.LocationTo,
                                     StartTime = g.Key.PlanDate,
                                     WindowTime = g.Key.PlanDate.AddDays(1),
                                     SourceId = g.Min(q => q.Id),
                                     SourceType = CodeMaster.MrpSourceType.ExDay,
                                     OrderType = CodeMaster.OrderType.Production,
                                     Qty = g.Sum(q => q.Qty),
                                     SourceFlow = g.Key.Flow,
                                     //SourceParty = GetCacheLocation(g.Key.LocationFrom).Region,
                                     ParentItem = g.Key.Item
                                 }).ToList();
                var mrpFlowDetails = new List<MrpFlowDetail>();
                if (mrpFlowDetailList == null)
                {
                    mrpFlowDetails = this.genericMgr.FindAll<MrpFlowDetail>
                        (@" from MrpFlowDetail as m where m.SnapTime = ? and m.ResourceGroup=? ",
                        new object[] { mrpPlanMaster.SnapTime, mrpPlanMaster.ResourceGroup }).ToList();
                }
                else
                {
                    mrpFlowDetails = mrpFlowDetailList.Where(p => p.ResourceGroup == mrpPlanMaster.ResourceGroup).ToList();
                }
                foreach (var shipPlan in shipPlans)
                {
                    var flowDetail = mrpFlowDetails.FirstOrDefault(f => f.Flow == shipPlan.Flow && f.Item == shipPlan.Item
                        && f.StartDate <= shipPlan.StartTime && f.EndDate > shipPlan.StartTime);
                    if (flowDetail == null)
                    {
                        flowDetail = mrpFlowDetails.FirstOrDefault(f => f.Flow == shipPlan.Flow);
                    }
                    shipPlan.Bom = flowDetail.Bom;
                    shipPlan.LocationFrom = flowDetail.LocationFrom;
                    shipPlan.LocationTo = flowDetail.LocationTo;
                    shipPlan.SourceParty = flowDetail.PartyFrom;
                }
                shipPlanList.AddRange(shipPlans);
            }
            else if (mrpPlanMaster.ResourceGroup == CodeMaster.ResourceGroup.MI)
            {
                var shiftPlanDic = this.genericMgr.FindEntityWithNativeSql<MrpMiShiftPlan>
                   (@"select a.* from MRP_MrpMiShiftPlan a join MRP_MrpMiDateIndex b 
                    on a.CreateDate = b.CreateDate and a.ProductLine = b.ProductLine and a.PlanDate = b.PlanDate 
                    where b.PlanDate >=? and b.PlanDate<=? and b.IsActive=? ", new object[] { startTime, endTime, true })
                .GroupBy(p => p.PlanDate, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g.ToList());

                var mrpMiPlanDic = this.genericMgr.FindAll<MrpMiPlan>
                (" from MrpMiPlan where PlanVersion = ? and PlanDate >=? and PlanDate<=? ",
                   new object[] { mrpPlanMaster.PlanVersion, startTime, endTime })
                .GroupBy(p => p.PlanDate, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g.ToList());

                //优先级:订单>班产计划>日计划
                DateTime currentDate = startTime;
                while (currentDate < endTime)
                {
                    currentDate = currentDate.AddDays(1);
                    var shiftPlans = shiftPlanDic.ValueOrDefault(currentDate);
                    if (shiftPlans != null)
                    {
                        foreach (var plan in shiftPlans)
                        {
                            var activeOrderCount = (activeOrderDic.ValueOrDefault(plan.ProductLine) ?? new List<ActiveOrder>())
                             .Count(p => p.StartTime.Date == plan.PlanDate.Date && p.Shift == plan.Shift);
                            if (activeOrderCount == 0)
                            {
                                MrpShipPlan mrpShipPlan = new MrpShipPlan();
                                mrpShipPlan.Bom = plan.Bom;
                                mrpShipPlan.Flow = plan.ProductLine;
                                mrpShipPlan.Item = plan.Item;
                                mrpShipPlan.LocationFrom = plan.LocationFrom;
                                mrpShipPlan.LocationTo = plan.LocationTo;
                                mrpShipPlan.StartTime = plan.StartTime;
                                mrpShipPlan.WindowTime = plan.WindowTime;
                                mrpShipPlan.SourceId = plan.Id;
                                mrpShipPlan.SourceType = CodeMaster.MrpSourceType.MiShift;
                                mrpShipPlan.OrderType = CodeMaster.OrderType.Production;
                                mrpShipPlan.Qty = plan.TotalQty;
                                mrpShipPlan.SourceFlow = plan.ProductLine;
                                mrpShipPlan.SourceParty = GetCacheLocation(mrpShipPlan.LocationFrom).Region;
                                mrpShipPlan.Item = plan.Item;
                                shipPlanList.Add(mrpShipPlan);
                            }
                        }
                    }
                    else
                    {
                        var miPlans = mrpMiPlanDic.ValueOrDefault(currentDate) ?? new List<MrpMiPlan>();
                        foreach (var plan in miPlans)
                        {
                            MrpShipPlan mrpShipPlan = new MrpShipPlan();
                            mrpShipPlan.Bom = plan.Bom;
                            mrpShipPlan.Flow = plan.ProductLine;
                            mrpShipPlan.Item = plan.Item;
                            mrpShipPlan.LocationFrom = plan.LocationFrom;
                            mrpShipPlan.LocationTo = plan.LocationTo;
                            mrpShipPlan.StartTime = plan.PlanDate;
                            mrpShipPlan.WindowTime = plan.PlanDate.AddDays(1);
                            mrpShipPlan.SourceId = plan.Id;
                            mrpShipPlan.SourceType = CodeMaster.MrpSourceType.MiShift;
                            mrpShipPlan.OrderType = CodeMaster.OrderType.Production;
                            mrpShipPlan.Qty = plan.TotalQty;
                            mrpShipPlan.SourceFlow = plan.ProductLine;
                            mrpShipPlan.SourceParty = GetCacheLocation(mrpShipPlan.LocationFrom).Region;
                            mrpShipPlan.Item = plan.Item;
                            shipPlanList.Add(mrpShipPlan);
                        }
                    }
                }
            }
            return shipPlanList;
        }