Bläddra i källkod

长周期物料安全库存数量调整,部分查询条件去重

Murphy 2 år sedan
förälder
incheckning
a36668116d

+ 323 - 202
MicroServices/Business/Business.Application/ReplenishmentManagement/ReplenishmentAppService.cs

@@ -1058,7 +1058,7 @@ namespace Business.Replenishment
             }
             planList = planList.OrderBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
             //获取BOM用于分解到原材料
-            var boms = _ic_bom.GetListAsync(a => planList.Select(p => p.SAPItemNumber).ToList().Contains(a.item_number) && a.factory_id == input.factory_id).Result;
+            var boms = _ic_bom.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Distinct().ToList().Contains(a.item_number) && a.factory_id == input.factory_id).Result;
             var planItemList = planList.Select(a => a.SAPItemNumber).Distinct().ToList();
             var bomItemList=boms.Select(a=>a.item_number).Distinct().ToList();
             var expectedList = planItemList.Except(bomItemList).ToList();
@@ -1877,7 +1877,7 @@ namespace Business.Replenishment
             //中间件汇总,比如A成品10、11、12月都需要中间件C,B成品11、12月都需要中间件C,那么中间件C需要每个月汇总平均分到4周
             Dictionary<string, decimal?> subProductItem = new Dictionary<string, decimal?>();
             Dictionary<string, BomChildExamineDto> subProductItemModel = new Dictionary<string, BomChildExamineDto>();
-            var ropList = planList.Where(t => shipPlanList.Select(s => s.SAPItemNumber).ToList().Contains(t.number)).Select(t => t.number).Distinct().ToList();
+            var ropList = planList.Where(t => shipPlanList.Select(s => s.SAPItemNumber).Distinct().ToList().Contains(t.number)).Select(t => t.number).Distinct().ToList();
             var itemMasterList = _itemMaster.Select(t => ropList.Contains(t.ItemNum) && t.Domain == input.factory_id.ToString());
             Dictionary<string, decimal> minordsalesQty = new Dictionary<string, decimal>();
             List<mes_morder> moList = new List<mes_morder>();
@@ -1914,7 +1914,7 @@ namespace Business.Replenishment
                             a.moentry_sys_etime == GetNextMonday().AddDays(28 + 7).AddDays(-days) ||
                             a.moentry_sys_etime == GetNextMonday().AddDays(28 + 14).AddDays(-days) ||
                             a.moentry_sys_etime == GetNextMonday().AddDays(28 + 21).AddDays(-days)));
-                            if(MonthMo != null)
+                            if (MonthMo != null)
                             {
                                 MonthMo.morder_production_number += Math.Ceiling(itemQty.GetValueOrDefault() / 4);
                                 MonthMo.need_number += Math.Ceiling(itemQty.GetValueOrDefault() / 4);
@@ -2045,45 +2045,79 @@ namespace Business.Replenishment
                                     moentryList.Add(mes_Moentry);
                                 }
                             }
-
-                            if(k==3)
+                            if (k == 3)
                             {
-                                var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
-                                if (itemMaster != null && itemMaster.MinOrd > 0)
+
+                                var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 7).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 14).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 21).AddDays(-days)));
+                                if (MonthMoTotal != null)
                                 {
-                                    var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 7).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 14).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 21).AddDays(-days)));
-                                    if (MonthMoTotal != null)
+                                    if (MonthMoTotal.need_number > 0)
                                     {
-                                        //考虑生产批量的计算逻辑
-                                        decimal productQty;
-                                        bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
-                                        if (exist)
+                                        var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
+                                        if (itemMaster != null && itemMaster.MinOrd > 0)
                                         {
-                                            //不需要生产
-                                            if (MonthMoTotal.need_number <= productQty)
+                                            //考虑生产批量的计算逻辑
+                                            decimal productQty;
+                                            bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
+                                            if (exist)
                                             {
-                                                minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
-                                                moList.Remove(MonthMoTotal);
-                                                moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
-                                                weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                                //不需要生产
+                                                if (MonthMoTotal.need_number <= productQty)
+                                                {
+                                                    minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
+                                                    moList.Remove(MonthMoTotal);
+                                                    moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
+                                                    weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                                }
+                                                else
+                                                {
+                                                    //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
+                                                    if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
+                                                    {
+                                                        decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
+                                                        minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
+                                                        MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
+                                                        MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-days);
+                                                        moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(14).Year;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(14).Month;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(14), 1);
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(14).Year}-{GetNextMonday().AddDays(28).AddDays(14).Month.ToString("00")}";
+                                                        if (item.area == "国内" || item.area == "中国")
+                                                        {
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                        }
+                                                        else
+                                                        {
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                        }
+                                                    }
+                                                }
                                             }
                                             else
                                             {
-                                                //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
-                                                if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
+                                                if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
                                                 {
-                                                    decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
-                                                    minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
+                                                    minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
+                                                    MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
                                                     MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-days);
-                                                    moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number= Math.Ceiling(itemMaster.MinOrd);
-                                                    moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number= Math.Ceiling(itemMaster.MinOrd);
+                                                    moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
+                                                    moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
                                                     weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
                                                     weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
                                                     weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
@@ -2103,62 +2137,63 @@ namespace Business.Replenishment
                                                     }
                                                 }
                                             }
-                                        }
-                                        else
-                                        {
-                                            if(MonthMoTotal.need_number< Math.Ceiling(itemMaster.MinOrd))
+                                            var planBOM = boms.Find(b => b.item_number == itemSeq);
+                                            var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
+                                            var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
+                                            returnlist = returnlist.OrderBy(s => s.num_order).ToList();
+                                            var level1Dto = returnlist[0];
+                                            level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
+                                            CaclMaterialShortage(returnlist);
+                                            foreach (var r in returnlist)
                                             {
-                                                minordsalesQty[itemSeq] += Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
-                                                MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
-                                                MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-days);
-                                                moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
-                                                moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(14).Year;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(14).Month;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(14), 1);
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(14).Year}-{GetNextMonday().AddDays(28).AddDays(14).Month.ToString("00")}";
-                                                if (item.area == "国内" || item.area == "中国")
+                                                if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
                                                 {
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
-                                                }
-                                                else
-                                                {
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                    if (subProductItem.ContainsKey(r.item_number))
+                                                    {
+                                                        subProductItem[r.item_number] += r.needCount;
+                                                    }
+                                                    else
+                                                    {
+                                                        subProductItem.Add(r.item_number, r.needCount);
+                                                        subProductItemModel.Add(r.item_number, r);
+                                                    }
                                                 }
                                             }
                                         }
-                                        var planBOM = boms.Find(b => b.item_number ==itemSeq);
-                                        var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
-                                        var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
-                                        returnlist = returnlist.OrderBy(s => s.num_order).ToList();
-                                        var level1Dto = returnlist[0];
-                                        level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
-                                        CaclMaterialShortage(returnlist);
-                                        foreach (var r in returnlist)
+                                        else
                                         {
-                                            if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
+                                            var planBOM = boms.Find(b => b.item_number == itemSeq);
+                                            var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
+                                            var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
+                                            returnlist = returnlist.OrderBy(s => s.num_order).ToList();
+                                            var level1Dto = returnlist[0];
+                                            level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
+                                            CaclMaterialShortage(returnlist);
+                                            foreach (var r in returnlist)
                                             {
-                                                if (subProductItem.ContainsKey(r.item_number))
-                                                {
-                                                    subProductItem[r.item_number] += r.needCount;
-                                                }
-                                                else
+                                                if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
                                                 {
-                                                    subProductItem.Add(r.item_number, r.needCount);
-                                                    subProductItemModel.Add(r.item_number, r);
+                                                    if (subProductItem.ContainsKey(r.item_number))
+                                                    {
+                                                        subProductItem[r.item_number] += r.needCount;
+                                                    }
+                                                    else
+                                                    {
+                                                        subProductItem.Add(r.item_number, r.needCount);
+                                                        subProductItemModel.Add(r.item_number, r);
+                                                    }
                                                 }
                                             }
                                         }
                                     }
+                                    else
+                                    {
+                                        moList.Remove(MonthMoTotal);
+                                        moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
+                                        weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                    }
                                 }
+
                             }
                         }
                         else if (k <= 7)
@@ -2323,36 +2358,70 @@ namespace Business.Replenishment
                             }
                             if (k == 7)
                             {
-                                var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
-                                if (itemMaster != null && itemMaster.MinOrd > 0)
+                                var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 28).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 35).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 42).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 49).AddDays(-days)));
+                                if (MonthMoTotal != null)
                                 {
-                                    var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 28).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 35).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 42).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 49).AddDays(-days)));
-                                    if (MonthMoTotal != null)
+                                    if (MonthMoTotal.need_number > 0)
                                     {
-                                        //考虑生产批量的计算逻辑
-                                        decimal productQty;
-                                        bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
-                                        if (exist)
+                                        var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
+                                        if (itemMaster != null && itemMaster.MinOrd > 0)
                                         {
-                                            //不需要生产
-                                            if (MonthMoTotal.need_number <= productQty)
+                                            //考虑生产批量的计算逻辑
+                                            decimal productQty;
+                                            bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
+                                            if (exist)
                                             {
-                                                minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
-                                                moList.Remove(MonthMoTotal);
-                                                moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
-                                                weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                                //不需要生产
+                                                if (MonthMoTotal.need_number <= productQty)
+                                                {
+                                                    minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
+                                                    moList.Remove(MonthMoTotal);
+                                                    moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
+                                                    weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                                }
+                                                else
+                                                {
+                                                    //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
+                                                    if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
+                                                    {
+                                                        decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
+                                                        minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
+                                                        MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
+                                                        MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-days);
+                                                        moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(42).Year;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(42).Month;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(42), 1);
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(42).Year}-{GetNextMonday().AddDays(28).AddDays(42).Month.ToString("00")}";
+                                                        if (item.area == "国内" || item.area == "中国")
+                                                        {
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                        }
+                                                        else
+                                                        {
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                        }
+                                                    }
+                                                }
                                             }
                                             else
                                             {
-                                                //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
-                                                if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
+                                                if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
                                                 {
-                                                    decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
-                                                    minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
+                                                    minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
+                                                    MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
@@ -2378,61 +2447,61 @@ namespace Business.Replenishment
                                                     }
                                                 }
                                             }
-                                        }
-                                        else
-                                        {
-                                            if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
+                                            var planBOM = boms.Find(b => b.item_number == itemSeq);
+                                            var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
+                                            var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
+                                            returnlist = returnlist.OrderBy(s => s.num_order).ToList();
+                                            var level1Dto = returnlist[0];
+                                            level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
+                                            CaclMaterialShortage(returnlist);
+                                            foreach (var r in returnlist)
                                             {
-                                                minordsalesQty[itemSeq] += Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
-                                                MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
-                                                MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-days);
-                                                moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
-                                                moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(42).Year;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(42).Month;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(42), 1);
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(42).Year}-{GetNextMonday().AddDays(28).AddDays(42).Month.ToString("00")}";
-                                                if (item.area == "国内" || item.area == "中国")
-                                                {
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
-                                                }
-                                                else
+                                                if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
                                                 {
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                    if (subProductItem.ContainsKey(r.item_number))
+                                                    {
+                                                        subProductItem[r.item_number] += r.needCount;
+                                                    }
+                                                    else
+                                                    {
+                                                        subProductItem.Add(r.item_number, r.needCount);
+                                                        subProductItemModel.Add(r.item_number, r);
+                                                    }
                                                 }
                                             }
                                         }
-                                        var planBOM = boms.Find(b => b.item_number == itemSeq);
-                                        var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
-                                        var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
-                                        returnlist = returnlist.OrderBy(s => s.num_order).ToList();
-                                        var level1Dto = returnlist[0];
-                                        level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
-                                        CaclMaterialShortage(returnlist);
-                                        foreach (var r in returnlist)
+                                        else
                                         {
-                                            if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
+                                            var planBOM = boms.Find(b => b.item_number == itemSeq);
+                                            var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
+                                            var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
+                                            returnlist = returnlist.OrderBy(s => s.num_order).ToList();
+                                            var level1Dto = returnlist[0];
+                                            level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
+                                            CaclMaterialShortage(returnlist);
+                                            foreach (var r in returnlist)
                                             {
-                                                if (subProductItem.ContainsKey(r.item_number))
-                                                {
-                                                    subProductItem[r.item_number] += r.needCount;
-                                                }
-                                                else
+                                                if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
                                                 {
-                                                    subProductItem.Add(r.item_number, r.needCount);
-                                                    subProductItemModel.Add(r.item_number, r);
+                                                    if (subProductItem.ContainsKey(r.item_number))
+                                                    {
+                                                        subProductItem[r.item_number] += r.needCount;
+                                                    }
+                                                    else
+                                                    {
+                                                        subProductItem.Add(r.item_number, r.needCount);
+                                                        subProductItemModel.Add(r.item_number, r);
+                                                    }
                                                 }
                                             }
                                         }
                                     }
+                                    else
+                                    {
+                                        moList.Remove(MonthMoTotal);
+                                        moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
+                                        weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                    }
                                 }
                             }
                         }
@@ -2576,36 +2645,70 @@ namespace Business.Replenishment
                             }
                             if (k == 11)
                             {
-                                var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
-                                if (itemMaster != null && itemMaster.MinOrd > 0)
+                                var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 56).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 63).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 70).AddDays(-days) ||
+                                a.moentry_sys_etime == GetNextMonday().AddDays(28 + 77).AddDays(-days)));
+                                if (MonthMoTotal != null)
                                 {
-                                    var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 56).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 63).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 70).AddDays(-days) ||
-                                    a.moentry_sys_etime == GetNextMonday().AddDays(28 + 77).AddDays(-days)));
-                                    if (MonthMoTotal != null)
+                                    if (MonthMoTotal.need_number > 0)
                                     {
-                                        //考虑生产批量的计算逻辑
-                                        decimal productQty;
-                                        bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
-                                        if (exist)
+                                        var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
+                                        if (itemMaster != null && itemMaster.MinOrd > 0)
                                         {
-                                            //不需要生产
-                                            if (MonthMoTotal.need_number <= productQty)
+                                            //考虑生产批量的计算逻辑
+                                            decimal productQty;
+                                            bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
+                                            if (exist)
                                             {
-                                                minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
-                                                moList.Remove(MonthMoTotal);
-                                                moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
-                                                weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                                //不需要生产
+                                                if (MonthMoTotal.need_number <= productQty)
+                                                {
+                                                    minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
+                                                    moList.Remove(MonthMoTotal);
+                                                    moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
+                                                    weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                                }
+                                                else
+                                                {
+                                                    //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
+                                                    if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
+                                                    {
+                                                        decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
+                                                        minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
+                                                        MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
+                                                        MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-days);
+                                                        moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(70).Year;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(70).Month;
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(70), 1);
+                                                        weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(70).Year}-{GetNextMonday().AddDays(28).AddDays(70).Month.ToString("00")}";
+                                                        if (item.area == "国内" || item.area == "中国")
+                                                        {
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                        }
+                                                        else
+                                                        {
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
+                                                            weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                        }
+                                                    }
+                                                }
                                             }
                                             else
                                             {
-                                                //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
-                                                if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
+                                                if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
                                                 {
-                                                    decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
-                                                    minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
+                                                    minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
+                                                    MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
                                                     MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
@@ -2631,61 +2734,61 @@ namespace Business.Replenishment
                                                     }
                                                 }
                                             }
-                                        }
-                                        else
-                                        {
-                                            if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
+                                            var planBOM = boms.Find(b => b.item_number == itemSeq);
+                                            var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
+                                            var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
+                                            returnlist = returnlist.OrderBy(s => s.num_order).ToList();
+                                            var level1Dto = returnlist[0];
+                                            level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
+                                            CaclMaterialShortage(returnlist);
+                                            foreach (var r in returnlist)
                                             {
-                                                minordsalesQty[itemSeq] += Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
-                                                MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
-                                                MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-days);
-                                                moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
-                                                moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(70).Year;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(70).Month;
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(70), 1);
-                                                weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(70).Year}-{GetNextMonday().AddDays(28).AddDays(70).Month.ToString("00")}";
-                                                if (item.area == "国内" || item.area == "中国")
+                                                if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
                                                 {
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
-                                                }
-                                                else
-                                                {
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
-                                                    weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
+                                                    if (subProductItem.ContainsKey(r.item_number))
+                                                    {
+                                                        subProductItem[r.item_number] += r.needCount;
+                                                    }
+                                                    else
+                                                    {
+                                                        subProductItem.Add(r.item_number, r.needCount);
+                                                        subProductItemModel.Add(r.item_number, r);
+                                                    }
                                                 }
                                             }
                                         }
-                                        var planBOM = boms.Find(b => b.item_number == itemSeq);
-                                        var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
-                                        var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
-                                        returnlist = returnlist.OrderBy(s => s.num_order).ToList();
-                                        var level1Dto = returnlist[0];
-                                        level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
-                                        CaclMaterialShortage(returnlist);
-                                        foreach (var r in returnlist)
+                                        else
                                         {
-                                            if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
+                                            var planBOM = boms.Find(b => b.item_number == itemSeq);
+                                            var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
+                                            var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
+                                            returnlist = returnlist.OrderBy(s => s.num_order).ToList();
+                                            var level1Dto = returnlist[0];
+                                            level1Dto.needCount = MonthMoTotal.need_number.GetValueOrDefault();
+                                            CaclMaterialShortage(returnlist);
+                                            foreach (var r in returnlist)
                                             {
-                                                if (subProductItem.ContainsKey(r.item_number))
-                                                {
-                                                    subProductItem[r.item_number] += r.needCount;
-                                                }
-                                                else
+                                                if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
                                                 {
-                                                    subProductItem.Add(r.item_number, r.needCount);
-                                                    subProductItemModel.Add(r.item_number, r);
+                                                    if (subProductItem.ContainsKey(r.item_number))
+                                                    {
+                                                        subProductItem[r.item_number] += r.needCount;
+                                                    }
+                                                    else
+                                                    {
+                                                        subProductItem.Add(r.item_number, r.needCount);
+                                                        subProductItemModel.Add(r.item_number, r);
+                                                    }
                                                 }
                                             }
                                         }
                                     }
+                                    else
+                                    {
+                                        moList.Remove(MonthMoTotal);
+                                        moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
+                                        weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
+                                    }
                                 }
                             }
                         }
@@ -5116,6 +5219,7 @@ namespace Business.Replenishment
             var safeItemQty = _itemMaster.Select(a => a.PurMfg == "L" && a.SafetyStk > 0 &&a.IsActive);
             if(safeItemQty.Count>0)
             {
+                var itemStock = CalcStock(safeItemQty.Select(m => m.ItemNum).Distinct().ToList(), input);
                 var safelist = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "M5", productList.Count(), "", 1);
                 for(int i=0;i<safeItemQty.Count;i++)
                 {
@@ -5144,6 +5248,23 @@ namespace Business.Replenishment
                     mes_Morder.moentry_wrkcname = null;
                     mes_Morder.picking_qty = 0;
                     mes_Morder.unit = safeItemQty[i].UM;
+                    var itemStockQty = itemStock.Find(a => a.ItemNumber == safeItemQty[i].ItemNum);
+                    if (itemStockQty!=null)
+                    {
+                        if(itemStockQty.Qty< safeItemQty[i].SafetyStk)
+                        {
+                            mes_Morder.morder_production_number = safeItemQty[i].SafetyStk- itemStockQty.Qty;
+                            mes_Morder.need_number = safeItemQty[i].SafetyStk - itemStockQty.Qty;
+                        }else
+                        {
+                            //超过安全库存不用考虑
+                            continue;
+                        }
+                    }else
+                    {
+                        mes_Morder.morder_production_number = safeItemQty[i].SafetyStk;
+                        mes_Morder.need_number = safeItemQty[i].SafetyStk;
+                    }
                     mes_Morder.morder_production_number = safeItemQty[i].SafetyStk;
                     mes_Morder.need_number = safeItemQty[i].SafetyStk;
                     mes_Morder.remaining_number = 0;

+ 1 - 0
MicroServices/Business/Business.Host/Business.Host.csproj

@@ -43,6 +43,7 @@
 
   <ItemGroup>
     <Folder Include="DataSeeder\" />
+    <Folder Include="Logs\" />
     <Folder Include="wwwroot\" />
   </ItemGroup>