Ver Fonte

Merge branch 'dev' of http://123.60.180.165:4647/ZZYDOP/DOPCore into dev

# Conflicts:
#	MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs
tangdi há 2 anos atrás
pai
commit
3a8ddeecb4

+ 1 - 1
MicroServices/Business/Business.Application/DOP/SyncDOPAppService.cs

@@ -243,7 +243,7 @@ namespace Business.DOP
                 //工厂库存
                 var itemSap = ItemInvList.Find(b => b.MATNR == a.ItemNumber);
                 if(itemSap!=null)
-                    a.FactoryInv =itemSap.LABST.ToDecimal();
+                    a.FactoryInv =itemSap.LABST;
                 //国科库存
                 var platformInventoryGK=  platformInvList.Find(b => b.SpecificationModel == a.Model && b.Code== "HW0002");
                 if (platformInventoryGK != null)

+ 190 - 206
MicroServices/Business/Business.Application/ReplenishmentManagement/ReplenishmentAppService.cs

@@ -457,8 +457,7 @@ namespace Business.Replenishment
             var DMSItemList = _DMS_IN_ITEMMAPPING.Select(a => sapItemList.Contains(a.CfnERPCode));
             var gkhwStock = _DMS_IN_LOCDETAIL.Select(a => (a.DealerCode == "RQ000005" || a.DealerCode == "RQ000002"));
 
-            var sapInvList = _SAPInv.Select(a => a.WERKS == input.factory_id.ToString() && 
-            sapItemList.Contains(a.MATNR) && a.SOBKZ.ToUpper() == "O" && (a.LGORT== "5008" || a.LGORT== "5009" || a.LGORT== "5010" || a.LGORT== "8000" || a.LGORT == "8001"|| a.LGORT == "8002" || a.LGORT == "8003"|| a.LGORT == "8004"|| a.LGORT == "8005"));
+            var sapInvList = _SAPInv.Select(a => a.WERKS == input.factory_id.ToString() && sapItemList.Contains(a.MATNR) && (a.SOBKZ.ToUpper() == "O"));
             // 获取某年某月的起始日期和结束日期
             DateTime start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
             DateTime end = start.AddMonths(1).AddDays(-1);
@@ -512,7 +511,7 @@ namespace Business.Replenishment
                 var prodLine = prodLines.Where(x => x.Part == yearDemands[i].SAPItemNumber).OrderBy(x => x.Sequence).FirstOrDefault();
                 //不同库位库存数量
                 //5008成品线边库,8001成品合格库,8000成品待检
-                var locationList = locations.Where(x => x.ItemNum == yearDemands[i].SAPItemNumber && (x.Location == "5008" || x.Location == "8000" || x.Location == "8001")).ToList();
+                var locationList = locations.Where(x => x.ItemNum == yearDemands[i].SAPItemNumber && (x.Location == "5008" || x.Location == "5009"|| x.Location == "5010" || x.Location == "8000" || x.Location == "8001"|| x.Location == "8002"|| x.Location == "8002"|| x.Location == "8003"|| x.Location == "8004"|| x.Location == "8005")).ToList();
                 //平台数据
                 decimal? hwStock = 0;
                 if (DMSItemList.Find(d => d.CfnERPCode == yearDemands[i].SAPItemNumber) != null)
@@ -552,7 +551,7 @@ namespace Business.Replenishment
                 decimal? InSterilizationQty = 0.00m;
                 if (sapInvList.Count > 0 && sapInvList.Any(a => a.MATNR == yearDemands[i].SAPItemNumber))
                 {
-                    InSterilizationQty = sapInvList.Where(a => a.MATNR == yearDemands[i].SAPItemNumber).Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
+                    InSterilizationQty = sapInvList.Where(a => a.MATNR == yearDemands[i].SAPItemNumber && a.SOBKZ.ToUpper()=="O").Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
                 }
                 var locationSum = (locationList.Count == 0 ? 0 : locationList.Sum(x => x.AvailStatusQty.GetValueOrDefault() + x.Assay.GetValueOrDefault())) + gkStock + hwStock + (ship.Count == 0 ? 0 : ship.Sum(x => x.QtyToShip)) + itemInProduct + InSterilizationQty;
                 //前面N个月的生产数量
@@ -707,8 +706,7 @@ namespace Business.Replenishment
             shipList.OrderBy(a => a.PlanMonth);
             var shipItemList= shipList.Select(a=>a.SAPItemNumber).Distinct().ToList();
             var ropPlan = _replenishmentROPWeekPlan.GetListAsync(x => shipItemList.Contains(x.number) && planMons.Contains(x.planmonth) && !x.IsDeleted && x.factory_id == input.factory_id).Result;
-            var sapInvList = _SAPInv.Select(a => a.WERKS == input.factory_id.ToString() &&
-            shipItemList.Contains(a.MATNR) && a.SOBKZ.ToUpper() == "O" && (a.LGORT == "5008" || a.LGORT == "5009" || a.LGORT == "5010" || a.LGORT == "8000" || a.LGORT == "8001" || a.LGORT == "8002" || a.LGORT == "8003" || a.LGORT == "8004" || a.LGORT == "8005"));
+            var sapInvList = _SAPInv.Select(a => a.WERKS == input.factory_id.ToString() && shipItemList.Contains(a.MATNR) && (a.SOBKZ.ToUpper() == "O"));
             foreach (var item in shipList)
             {
                 var ropItem = ropPlan.Find(x => x.number == item.SAPItemNumber);
@@ -806,9 +804,9 @@ namespace Business.Replenishment
                         plan.Inventory2 = 0;
                     }
                     decimal InSterilizationQty = 0.00m;
-                    if (sapInvList.Count > 0 && sapInvList.Any(a => a.MATNR == item.SAPItemNumber))
+                    if (sapInvList.Count > 0 && sapInvList.Any(a => a.MATNR == item.SAPItemNumber && a.SOBKZ.ToUpper() == "O"))
                     {
-                        InSterilizationQty = sapInvList.Where(a => a.MATNR == item.SAPItemNumber).Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
+                        InSterilizationQty = sapInvList.Where(a => a.MATNR == item.SAPItemNumber && a.SOBKZ.ToUpper()=="O").Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
                     }
                     plan.DuringSterilization = InSterilizationQty;
                     plan.InProduction = InProdcutQty.Find(a => a.ItemNumber == item.SAPItemNumber).Qty;
@@ -841,7 +839,7 @@ namespace Business.Replenishment
                 {
                     var planList = productionMasters.Select(a => a.PlanMonth).ToList();
                     await _productionMasterPlan.DeleteAsync(a => planList.Contains(a.PlanMonth) && a.factory_id == input.factory_id);
-                    await _productionMasterPlan.InsertManyAsync(productionMasters);
+                    await _businessDbContext.BulkInsertAsync(productionMasters);
                     await unitOfWork.CompleteAsync();
                 }
                 catch (Exception e)
@@ -1032,7 +1030,7 @@ namespace Business.Replenishment
             {
                 //库存合计 + 在制 + 灭菌中 (InvMaster没有过滤灭菌中状态可能已经算在可用库存中了)
                 //5008成品线边库,8001成品合格库,8000成品待检
-                if (item.Location == "5008" || item.Location == "8000" || item.Location == "8001")
+                if (item.Location == "5008"|| item.Location == "5009"|| item.Location == "5010" || item.Location == "8000" || item.Location == "8001"|| item.Location == "8002"|| item.Location == "8003"|| item.Location == "8004"|| item.Location == "8005")
                 {
                     if (dictItemStock.ContainsKey(item.ItemNum))
                     {
@@ -1790,148 +1788,145 @@ namespace Business.Replenishment
                 weekTime = weekTime.AddDays(7 * k);
                 string kMonth = $"{weekTime.Year}-{weekTime.Month.ToString("00")}";
                 var monthWeekPlan = planList.Where(a => a.planmonth == kMonth).ToList();
-                var ropList = planList.Select(t => t.number).Distinct().ToList();
+                var ropList = planList.Where(t=>shipPlanList.Select(s => s.SAPItemNumber).ToList().Contains(t.number)).Select(t => t.number).Distinct().ToList();
                 foreach (var itemSeq in ropList)
                 {
-                    if (shipPlanList.Select(s => s.SAPItemNumber).ToList().Contains(itemSeq))
+                    var monthPlanItem = monthPlan.Find(x => x.ItemNumber == itemSeq);
+                    //瑞奇国科海王
+                    var monthPlanTotal = monthWeekPlan.Where(x => x.number == itemSeq).ToList();
+                    if (monthPlanTotal != null && monthPlanTotal.Count > 0)
                     {
-                        var monthPlanItem = monthPlan.Find(x => x.ItemNumber == itemSeq);
-                        //瑞奇国科海王
-                        var monthPlanTotal = monthWeekPlan.Where(x => x.number == itemSeq).ToList();
-                        if (monthPlanTotal != null && monthPlanTotal.Count > 0)
+                        var item = monthPlanTotal[0];
+                        //瑞奇补货计划!Y5 + 瑞奇补货计划!Z5 + 国科补货计划!Y5 + 国科补货计划!Z5 + 海王补货计划!Y4 + 海王补货计划!Z4
+                        var itemQty = monthPlanTotal.Sum(a => a.montheop1) + monthPlanTotal.Sum(a => a.montheop2);
+                        //每次都是发布12周,每个月4周,不用判断存不存在(退市的可能没有)
+                        int days = 15;
+                        if (item.area != "国内" && item.area != "中国")
                         {
-                            var item = monthPlanTotal[0];
-                            //瑞奇补货计划!Y5 + 瑞奇补货计划!Z5 + 国科补货计划!Y5 + 国科补货计划!Z5 + 海王补货计划!Y4 + 海王补货计划!Z4
-                            var itemQty = monthPlanTotal.Sum(a => a.montheop1) + monthPlanTotal.Sum(a => a.montheop2);
-                            //每次都是发布12周,每个月4周,不用判断存不存在(退市的可能没有)
-                            int days = 15;
-                            if (item.area != "国内" && item.area != "中国")
+                            days = 8;
+                        }
+                        if (itemQty > 0)
+                        {
+                            var bom = bomList.Find(b => b.item_number == itemSeq);
+                            var ic_item = itemList.Find(b => b.number == itemSeq);
+                            mes_morder mes_Morder = new mes_morder();
+                            mes_Morder.GenerateNewId(help.NextId());
+                            mes_Morder.morder_type = MorderEnum.JhMorder;
+                            mes_Morder.work_order_type = MorderEnum.CgMorder;
+                            mes_Morder.morder_state = "";
+                            mes_Morder.morder_no = Guid.NewGuid().ToString();
+                            mes_Morder.fms_number = ic_item.fms_number;
+                            mes_Morder.bom_number = bom.bom_number;
+                            mes_Morder.fmodel = ic_item.model;
+                            mes_Morder.moentry_startup_status = 0;
+                            mes_Morder.tenant_id = input.tenant_id;
+                            mes_Morder.factory_id = input.factory_id;
+                            mes_Morder.company_id = input.company_id;
+                            mes_Morder.org_id = input.org_id;
+                            mes_Morder.product_code = ic_item.number;
+                            mes_Morder.product_name = ic_item.name;
+                            mes_Morder.morder_date = DateTime.Now.Date.AddDays(1);
+                            mes_Morder.moentry_prd = null;
+                            mes_Morder.moentry_prdname = null;
+                            mes_Morder.moentry_wrkc = null;
+                            mes_Morder.moentry_wrkcname = null;
+                            mes_Morder.picking_qty = 0;
+                            mes_Morder.unit = ic_item.unit;
+                            mes_Morder.morder_production_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4);
+                            mes_Morder.need_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4);
+                            //成品半成品取周一为入库时间开始往前推
+                            mes_Morder.moentry_sys_stime = weekTime.AddDays(-ProductTime(routingOps, ic_item.number, input.factory_id.ToString(), mes_Morder.need_number.GetValueOrDefault()) - days);
+                            mes_Morder.moentry_sys_etime = weekTime.AddDays(-days);
+                            mes_Morder.remaining_number = 0;
+                            mes_Morder.create_time = DateTime.Now;
+                            mes_Morder.bang_id = bang_id;
+                            //生成工单子表数据
+                            mes_moentry mes_Moentry = new mes_moentry();
+                            mes_Moentry.GenerateNewId(help.NextId());
+                            mes_Moentry.moentry_moid = mes_Morder.Id;
+                            mes_Moentry.moentry_mono = mes_Morder.morder_no;
+                            mes_Moentry.unit = ic_item.unit;
+                            mes_Moentry.morder_production_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4); ;
+                            mes_Moentry.need_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4); ;
+                            mes_Moentry.remaining_number = 0;
+                            mes_Moentry.tenant_id = input.tenant_id;
+                            mes_Moentry.factory_id = input.factory_id;
+                            mes_Moentry.company_id = input.company_id;
+                            mes_Moentry.org_id = input.org_id;
+                            mes_Moentry.create_time = DateTime.Now;
+                            mes_Moentry.bang_id = bang_id;
+
+                            ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
+                            weekItem.Priority = 1;
+                            weekItem.Area = item.area;
+                            weekItem.PlanStartDate = mes_Morder.moentry_sys_stime.GetValueOrDefault();
+                            weekItem.Week = $"WK{GetWeekOfYear(mes_Morder.moentry_sys_stime.Value).ToString("00")}";
+                            weekItem.OrderNO = Guid.NewGuid().ToString();
+                            weekItem.ProductionOrder = mes_Morder.morder_no;
+                            weekItem.SAPOrderNO = "";
+                            weekItem.OrderType = "量产";
+                            weekItem.ProductionBatch = "";
+                            weekItem.ProductionStatus = "";
+                            weekItem.ProdLine = item.ProdLine;
+                            weekItem.ProdRange = item.ProdRange;
+                            weekItem.Line = monthPlanItem?.WorkshopLine;
+                            weekItem.ItemNumber = item.number;
+                            weekItem.Model = item.model;
+                            weekItem.Languages = item.Languages;
+                            weekItem.Qty = mes_Morder.morder_production_number.Value;
+                            weekItem.ItemStatus = "";
+                            weekItem.PlanKittingDate = DateTime.Now;
+                            weekItem.Year = weekTime.Year;
+                            weekItem.Month = weekTime.Month;
+                            weekItem.WeekSeq = WeekOfMonth(weekTime, 1);
+                            weekItem.PlanMonth = kMonth;
+                            weekItem.tenant_id = input.tenant_id;
+                            weekItem.factory_id = input.factory_id;
+                            weekItem.company_id = input.company_id;
+                            weekItem.org_id = input.org_id;
+                            weekItem.create_time = DateTime.Now;
+                            weekItem.DistributionChannel = item.distributionchannel;
+                            weekItem.IsReplenishmentModel = "N";
+                            if (item.area == "国内" || item.area == "中国")
                             {
-                                days = 8;
+                                weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
+                                weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(days);
                             }
-                            if (itemQty > 0)
+                            else
                             {
-                                var bom = bomList.Find(b => b.item_number == itemSeq);
-                                var ic_item = itemList.Find(b => b.number == itemSeq);
-                                mes_morder mes_Morder = new mes_morder();
-                                mes_Morder.GenerateNewId(help.NextId());
-                                mes_Morder.morder_type = MorderEnum.JhMorder;
-                                mes_Morder.work_order_type = MorderEnum.CgMorder;
-                                mes_Morder.morder_state = "";
-                                mes_Morder.morder_no = Guid.NewGuid().ToString();
-                                mes_Morder.fms_number = ic_item.fms_number;
-                                mes_Morder.bom_number = bom.bom_number;
-                                mes_Morder.fmodel = ic_item.model;
-                                mes_Morder.moentry_startup_status = 0;
-                                mes_Morder.tenant_id = input.tenant_id;
-                                mes_Morder.factory_id = input.factory_id;
-                                mes_Morder.company_id = input.company_id;
-                                mes_Morder.org_id = input.org_id;
-                                mes_Morder.product_code = ic_item.number;
-                                mes_Morder.product_name = ic_item.name;
-                                mes_Morder.morder_date = DateTime.Now.Date.AddDays(1);
-                                mes_Morder.moentry_prd = null;
-                                mes_Morder.moentry_prdname = null;
-                                mes_Morder.moentry_wrkc = null;
-                                mes_Morder.moentry_wrkcname = null;
-                                mes_Morder.picking_qty = 0;
-                                mes_Morder.unit = ic_item.unit;
-                                mes_Morder.morder_production_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4);
-                                mes_Morder.need_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4);
-                                //成品半成品取周一为入库时间开始往前推
-                                mes_Morder.moentry_sys_stime = weekTime.AddDays(-ProductTime(routingOps, ic_item.number, input.factory_id.ToString(), mes_Morder.need_number.GetValueOrDefault()) - days);
-                                mes_Morder.moentry_sys_etime = weekTime.AddDays(-days);
-                                mes_Morder.remaining_number = 0;
-                                mes_Morder.create_time = DateTime.Now;
-                                mes_Morder.bang_id = bang_id;
-                                //生成工单子表数据
-                                mes_moentry mes_Moentry = new mes_moentry();
-                                mes_Moentry.GenerateNewId(help.NextId());
-                                mes_Moentry.moentry_moid = mes_Morder.Id;
-                                mes_Moentry.moentry_mono = mes_Morder.morder_no;
-                                mes_Moentry.unit = ic_item.unit;
-                                mes_Moentry.morder_production_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4); ;
-                                mes_Moentry.need_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4); ;
-                                mes_Moentry.remaining_number = 0;
-                                mes_Moentry.tenant_id = input.tenant_id;
-                                mes_Moentry.factory_id = input.factory_id;
-                                mes_Moentry.company_id = input.company_id;
-                                mes_Moentry.org_id = input.org_id;
-                                mes_Moentry.create_time = DateTime.Now;
-                                mes_Moentry.bang_id = bang_id;
-
-                                ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
-                                weekItem.Priority = 1;
-                                weekItem.Area = item.area;
-                                weekItem.PlanStartDate = mes_Morder.moentry_sys_stime.GetValueOrDefault();
-                                weekItem.Week = $"WK{GetWeekOfYear(mes_Morder.moentry_sys_stime.Value).ToString("00")}";
-                                weekItem.OrderNO = Guid.NewGuid().ToString();
-                                weekItem.ProductionOrder = mes_Morder.morder_no;
-                                weekItem.SAPOrderNO = "";
-                                weekItem.OrderType = "量产";
-                                weekItem.ProductionBatch = "";
-                                weekItem.ProductionStatus = "";
-                                weekItem.ProdLine = item.ProdLine;
-                                weekItem.ProdRange = item.ProdRange;
-                                weekItem.Line = monthPlanItem?.WorkshopLine;
-                                weekItem.ItemNumber = item.number;
-                                weekItem.Model = item.model;
-                                weekItem.Languages = item.Languages;
-                                weekItem.Qty = mes_Morder.morder_production_number.Value;
-                                weekItem.ItemStatus = "";
-                                weekItem.PlanKittingDate = DateTime.Now;
-                                weekItem.Year = weekTime.Year;
-                                weekItem.Month = weekTime.Month;
-                                weekItem.WeekSeq = WeekOfMonth(weekTime, 1);
-                                weekItem.PlanMonth = kMonth;
-                                weekItem.tenant_id = input.tenant_id;
-                                weekItem.factory_id = input.factory_id;
-                                weekItem.company_id = input.company_id;
-                                weekItem.org_id = input.org_id;
-                                weekItem.create_time = DateTime.Now;
-                                weekItem.DistributionChannel = item.distributionchannel;
-                                weekItem.IsReplenishmentModel = "N";
-                                if (item.area == "国内" || item.area == "中国")
-                                {
-                                    weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
-                                    weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(days);
-                                }
-                                else
-                                {
-                                    weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
-                                    weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(days);
-                                }
-                                weekItem.AssembleHours = 0;
-                                weekItem.HeatSealHours = 0;
-                                weekItem.PackageHours = 0;
-                                weekItem.TotalHours = 0;
-                                //Q2023/11/15的需求同一周有相同物料的工单不继续生成,不考虑数量的偏差
-                                if(!weekProductPlanList.Any(a=>a.ItemNumber==item.number && a.Week== weekItem.Week))
+                                weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
+                                weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(days);
+                            }
+                            weekItem.AssembleHours = 0;
+                            weekItem.HeatSealHours = 0;
+                            weekItem.PackageHours = 0;
+                            weekItem.TotalHours = 0;
+                            //Q2023/11/15的需求同一周有相同物料的工单不继续生成,不考虑数量的偏差
+                            if (!weekProductPlanList.Any(a => a.ItemNumber == item.number && a.Week == weekItem.Week))
+                            {
+                                weekPlan.Add(weekItem);
+                                moList.Add(mes_Morder);
+                                moentryList.Add(mes_Moentry);
+
+                                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 = itemQty.GetValueOrDefault();
+                                CaclMaterialShortage(returnlist);
+                                foreach (var r in returnlist)
                                 {
-                                    weekPlan.Add(weekItem);
-                                    moList.Add(mes_Morder);
-                                    moentryList.Add(mes_Moentry);
-
-                                    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 = itemQty.GetValueOrDefault();
-                                    CaclMaterialShortage(returnlist);
-                                    foreach (var r in returnlist)
+                                    if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
                                     {
-                                        if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
+                                        if (subProductItem.ContainsKey(r.item_number))
                                         {
-                                            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);
-                                            }
+                                            subProductItem[r.item_number] += r.needCount;
+                                        }
+                                        else
+                                        {
+                                            subProductItem.Add(r.item_number, r.needCount);
+                                            subProductItemModel.Add(r.item_number, r);
                                         }
                                     }
                                 }
@@ -1977,7 +1972,7 @@ namespace Business.Replenishment
                     }
                     else if (middleItem > 0)
                     {
-                        itemQty = Math.Ceiling(Math.Ceiling(itemQty.GetValueOrDefault() / middleItem) * middleItem);
+                        itemQty = Math.Ceiling(Math.Ceiling(itemQty.GetValueOrDefault()/ (3*middleItem)) * middleItem);
                     }
                     if(!weeksubPlanList.Any(a=>a.ItemNumber== subProductItemModel[key].item_number && a.PlanMonth== kMonth))
                     {
@@ -2264,8 +2259,9 @@ namespace Business.Replenishment
                 priority++;
             }
             _workOrdMaster.Update(workMasters);
-            await _mysql_mes_morder.UpdateManyAsync(mes_Morders);
-            await _replenishmentWeekPlan.UpdateManyAsync(weekPlan);
+            await _businessDbContext.BulkUpdateAsync(mes_Morders);
+            await _businessDbContext.BulkUpdateAsync(weekPlan);
+      
             return "OK";
         }
 
@@ -2366,7 +2362,7 @@ namespace Business.Replenishment
             }
             if (updateList.Count > 0)
             {
-                await _replenishmentWeekPlan.UpdateManyAsync(updateList);
+                await _businessDbContext.BulkUpdateAsync(updateList);
                 List<WorkOrdMaster> itemUpdate = new List<WorkOrdMaster>();
                 List<WorkOrdDetail> itemDetailUpdate = new List<WorkOrdDetail>();
                 List<WorkOrdRouting> itemRoutingUpdate = new List<WorkOrdRouting>();
@@ -2415,8 +2411,8 @@ namespace Business.Replenishment
                 _workOrdMaster.Update(itemUpdate);
                 _workOrdDetail.Update(itemDetailUpdate);
                 _workOrdRouting.Update(itemRoutingUpdate);
-                await _mysql_mes_morder.UpdateManyAsync(itemMesmorderList);
-                await _mysql_mes_moentry.UpdateManyAsync(itemMesmorderEntryList);
+                await _businessDbContext.BulkUpdateAsync(itemMesmorderList);
+                await _businessDbContext.BulkUpdateAsync(itemMesmorderEntryList);
             }
 
             //补货
@@ -2447,7 +2443,7 @@ namespace Business.Replenishment
             });
             if (weekPlanAdd.Count > 0)
             {
-                await _replenishmentWeekPlan.UpdateManyAsync(weekPlanAdd);
+                await _businessDbContext.BulkInsertAsync(weekPlanAdd);
                 List<WorkOrdMaster> itemUpdate = new List<WorkOrdMaster>();
                 List<WorkOrdDetail> itemDetailUpdate = new List<WorkOrdDetail>();
                 List<WorkOrdRouting> itemRoutingUpdate = new List<WorkOrdRouting>();
@@ -2496,8 +2492,8 @@ namespace Business.Replenishment
                 _workOrdMaster.Update(itemUpdate);
                 _workOrdDetail.Update(itemDetailUpdate);
                 _workOrdRouting.Update(itemRoutingUpdate);
-                await _mysql_mes_morder.UpdateManyAsync(itemMesmorderList);
-                await _mysql_mes_moentry.UpdateManyAsync(itemMesmorderEntryList);
+                await _businessDbContext.BulkUpdateAsync(itemMesmorderList);
+                await _businessDbContext.BulkUpdateAsync(itemMesmorderEntryList);
             }
 
             //DOP运行资源检查每个原材料SKU的可用库存,当可用库存<=修正后ROP时,自动生成月度采购申请(Purchase request,PR46年月日4位流水号)=EOP;可用库存为没有被其他SO和PO占用的(合格原材料库存+在途库存);
@@ -2674,13 +2670,12 @@ namespace Business.Replenishment
                     }
                 }
             });
-            //await _mysql_srm_pr_main.DeleteManyAsync(prDeleteList);
-            await _mysql_srm_pr_main.UpdateManyAsync(prUpdateList);
+            await _businessDbContext.BulkUpdateAsync(prUpdateList);
             prList.ForEach(a =>
             {
                 a.GenerateNewId(help.NextId());
             });
-            await _mysql_srm_pr_main.InsertManyAsync(prList);
+            await _businessDbContext.BulkInsertAsync(prList);
             return "OK";
         }
 
@@ -3067,55 +3062,28 @@ namespace Business.Replenishment
         public List<EOPDto> CalcStock(List<string> itemNumbers,InputDto input)
         {
             List<EOPDto> itemQty = new List<EOPDto>();
-            var itemList=_mysql_ic_item.GetListAsync(a => itemNumbers.Contains(a.number) && a.factory_id == input.factory_id  && !a.IsDeleted).Result;
-            //获取成品库存、灭菌库存、在制库存(会从SAP同步的库存表更新到LocationDetail、ic_item表中)
             var locations = _invMaster.Select(p => p.Domain == input.factory_id.ToString() && itemNumbers.Contains(p.ItemNum) && p.IsActive);
-            var pooccupylist=_mysql_srm_po_occupy.GetListAsync(a => a.state == 1 && !a.IsDeleted && a.factory_id == input.factory_id ).Result;
-            var poList = _mysql_srm_po_list.GetListAsync(a=> pooccupylist.Select(p=>p.polist_id).ToList().Contains(a.Id) && pooccupylist.Select(p => p.polist_row).ToList().Contains(a.polist_row) && a.factory_id == input.factory_id  && !a.IsDeleted).Result;
-            var molist=_mysql_mes_morder.GetListAsync(a => itemNumbers.Contains(a.product_code) && a.factory_id == input.factory_id  && !a.IsDeleted).Result;
-            var proccupylist=_mysql_srm_pr_main_occupy.GetListAsync(a=> molist.Select(p=>p.morder_no).ToList().Contains(a.morder_mo) && a.factory_id == input.factory_id  && !a.IsDeleted).Result;
-
-            //TODO:完善占用逻辑
-            //srm_pr_main pr = new srm_pr_main();
-            //pr.state = 1;
-            //srm_po_main po = new srm_po_main();
-            ////po.state.GetValueOrDefault() != 3;
-            //srm_po_occupy srm_Po_Occupy = new srm_po_occupy();
-            ////srm_Po_Occupy.polist_id = pr.Id;po.id;
-
+            var sapInvList = _SAPInv.Select(a => a.WERKS == input.factory_id.ToString() && itemNumbers.Contains(a.MATNR) && (a.SOBKZ.ToUpper() == "O"));
+            var stockOccupyList = _mysql_ic_item_stockoccupy.GetListAsync(a=> itemNumbers.Contains(a.icitem_number) && a.factory_id == input.factory_id  && !a.IsDeleted).Result;
             itemNumbers.ForEach(a =>
             {
                 EOPDto eOPDto=new EOPDto();
                 eOPDto.ItemNumber = a;
                 decimal stockqty = 0;
-                if (locations.Find(s => s.ItemNum == a && (s.Location == "5008" || s.Location == "8000" || s.Location == "8001")) !=null)
+                if (locations.Any(s => s.ItemNum == a))
                 {
-                    stockqty = locations.Find(s => s.ItemNum == a && (s.Location == "5008" || s.Location == "8000" || s.Location == "8001")).AvailStatusQty.GetValueOrDefault();
+                    stockqty = locations.Where(s => s.ItemNum == a).Sum(x => x.AvailStatusQty.GetValueOrDefault());
                 }
-                decimal poOccupyQty = 0;
-                for(int i=0;i<pooccupylist.Count;i++)
+                decimal InSterilizationQty = 0;
+                if (sapInvList.Count > 0 && sapInvList.Any(s => s.MATNR ==a))
                 {
-                    for(int j=0;j<poList.Count;j++)
-                    {
-                        if (pooccupylist[i].polist_id== poList[j].Id && pooccupylist[i].polist_row == poList[j].polist_row && poList[j].ItemNum==a)
-                        {
-                            poOccupyQty += pooccupylist[i].qty.Value;
-                        }
-                    }
+                    InSterilizationQty = sapInvList.Where(s => s.MATNR == a && s.SOBKZ.ToUpper() == "O").Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
                 }
+                stockqty += InSterilizationQty;
 
-                decimal prOccupyQty = 0;
-                for (int i = 0; i < proccupylist.Count; i++)
-                {
-                    for (int j = 0; j < molist.Count; j++)
-                    {
-                        if (proccupylist[i].morder_mo == molist[j].morder_no  && molist[j].product_code == a)
-                        {
-                            prOccupyQty += proccupylist[i].qty.Value;
-                        }
-                    }
-                }
-                eOPDto.Qty = stockqty - poOccupyQty - prOccupyQty;
+                var occupyQty=stockOccupyList.Where(s => s.icitem_number == a).Sum(s => s.quantity);
+                stockqty -= occupyQty;
+                eOPDto.Qty = stockqty;
                 itemQty.Add(eOPDto);
             });
             return itemQty;
@@ -3746,13 +3714,11 @@ namespace Business.Replenishment
                 {
                     var moSrm_po_main = ObjectMapper.Map<List<srm_po_main>, List<mo_srm_po_main>>(srm_po_main);
                     moSrm_po_main.ForEach(item => { item.GenerateNewId(help.NextId()); item.bang_id = bangid; });
-                    //await _srm_po_main.InsertManyAsync(moSrm_po_main);
                     await MongoHelper<mo_srm_po_main>.InsertManyAsync(moSrm_po_main);
                     //订单明细--根据在途PO过滤出有效的Po_list
                     srm_po_list = srm_po_list.Where(s => srm_po_main.Select(x => x.Id).Contains(s.po_id.GetValueOrDefault())).ToList();
                     var moSrm_po_list = ObjectMapper.Map<List<srm_po_list>, List<mo_srm_po_list>>(srm_po_list);
                     moSrm_po_list.ForEach(item => { item.GenerateNewId(help.NextId()); item.bang_id = bangid; });
-                    //await _srm_po_list.InsertManyAsync(moSrm_po_list);
                     await MongoHelper<mo_srm_po_list>.InsertManyAsync(moSrm_po_list);
                 }
                 //采购订单明细占用详情
@@ -3761,7 +3727,6 @@ namespace Business.Replenishment
                 {
                     var moSrm_po_occupy = ObjectMapper.Map<List<srm_po_occupy>, List<mo_srm_po_occupy>>(srm_po_occupy);
                     moSrm_po_occupy.ForEach(item => { item.GenerateNewId(help.NextId()); item.bang_id = bangid; });
-                    //await _srm_po_occupy.InsertManyAsync(moSrm_po_occupy);
                     await MongoHelper<mo_srm_po_occupy>.InsertManyAsync(moSrm_po_occupy);
                 }
             }
@@ -3772,17 +3737,21 @@ namespace Business.Replenishment
             {
                 var moSrm_pr_main = ObjectMapper.Map<List<srm_pr_main>, List<mo_srm_pr_main>>(srm_pr_main);
                 moSrm_pr_main.ForEach(item => { item.GenerateNewId(help.NextId()); item.bang_id = bangid; });
-                //await _srm_pr_main.InsertManyAsync(moSrm_pr_main);
                 await MongoHelper<mo_srm_pr_main>.InsertManyAsync(moSrm_pr_main);
 
                 //采购申请占用详情
-                var srm_pr_occupy=_businessDbContext.srm_po_occupy.Where(x => x.company_id == companyId && x.factory_id == factoryId && srm_pr_main.Select(c => c.Id).Contains(x.polist_id.Value)).ToList();
-                //var srm_pr_occupy = _mysql_srm_po_occupy.GetListAsync(x => x.company_id == companyId && x.factory_id == factoryId && srm_pr_main.Select(c => c.Id).Contains(x.polist_id.GetValueOrDefault())).Result;
+                var occupyList = _businessDbContext.srm_po_occupy.Join(_businessDbContext.srm_pr_main.Where(x => x.company_id == companyId && x.factory_id == factoryId && x.state != 0 && itemIds.ToArray().Any(a => a == x.icitem_id.GetValueOrDefault())), p => p.polist_id, pr => pr.Id, (p, pr) => new { p, pr }).ToList();
+                List<srm_po_occupy> srm_pr_occupy = new List<srm_po_occupy>();
+                for (int i = 0; i < occupyList.Count; i++)
+                {
+                    srm_pr_occupy.Add(occupyList[i].p);
+                }
+                //var srm_pr_occupy=_businessDbContext.srm_po_occupy.Where(x => x.company_id == companyId && x.factory_id == factoryId && srm_pr_main.Select(c => c.Id).Contains(x.polist_id.Value)).ToList();
+                //var srm_pr_occupy = _mysql_srm_po_occupy.GetListAsync(x => x.company_id == companyId && x.factory_id == factoryId && srm_pr_main.Select(c => c.Id).Any(a=>a==x.polist_id.GetValueOrDefault())).Result;
                 if (srm_pr_occupy.Count > 0)
                 {
                     var moSrm_pr_occupy = ObjectMapper.Map<List<srm_po_occupy>, List<mo_srm_po_occupy>>(srm_pr_occupy);
                     moSrm_pr_occupy.ForEach(item => { item.GenerateNewId(help.NextId()); item.bang_id = bangid; });
-                    //await _srm_po_occupy.InsertManyAsync(moSrm_pr_occupy);
                     await MongoHelper<mo_srm_po_occupy>.InsertManyAsync(moSrm_pr_occupy);
                 }
             }
@@ -3795,7 +3764,7 @@ namespace Business.Replenishment
         public async Task ClearSnapShot(long bangid)
         {
             //清除物料库存数据
-            await _ic_item_stock.DeleteAsync(p => p.bang_id == bangid);
+            await MongoHelper<mo_ic_item_stock>.DeleteManyAsync(p => p.bang_id == bangid);
 
             //清除工单占用记录表
             //await _mes_mooccupy.DeleteAsync(p => p.bang_id == bangid);
@@ -3807,16 +3776,16 @@ namespace Business.Replenishment
             //await _mes_moentry.Delete(p => p.bang_id == bangid);
 
             //清除采购订单
-            await _srm_po_main.DeleteAsync(p => p.bang_id == bangid);
+            await MongoHelper<mo_srm_po_main>.DeleteManyAsync(p => p.bang_id == bangid);
 
             //清除采购订单明细
-            await _srm_po_list.DeleteAsync(p => p.bang_id == bangid);
+            await MongoHelper<mo_srm_po_list>.DeleteManyAsync(p => p.bang_id == bangid);
 
             //清除采购订单占用详情
             //await _srm_po_occupy.DeleteAsync(p => p.bang_id == bangid);
 
             //清除PR
-            await _srm_pr_main.DeleteAsync(p => p.bang_id == bangid);
+            await MongoHelper<mo_srm_pr_main>.DeleteManyAsync(p => p.bang_id == bangid);
         }
 
 
@@ -4098,8 +4067,6 @@ namespace Business.Replenishment
             if (addList.Any())
             {
                 _businessDbContext.BulkInsert(addList);
-
-                //await _mysql_b_bom_pretreatment.InsertManyAsync(addList);
             }
         }
 
@@ -4116,9 +4083,14 @@ namespace Business.Replenishment
                 input.year = DateTime.Now.Year;
                 input.month = DateTime.Now.Month;
             }
+            if (DateTime.Now.Month >= 10)
+            {
+                input.year = DateTime.Now.AddYears(1).Year;
+                input.month = DateTime.Now.Month;
+            }
             var ropParam = GetROPParam(input.factory_id.ToString());
             //获取滚动未来六个月数据
-            var monthlist = GetPlanMonth(6);
+            var monthlist = GetYearPlanMonth(input.year);
             var productList = _replenishmentAnnualProduction.GetListAsync(a => monthlist.Contains(a.PlanMonth) && !a.IsDeleted && a.factory_id == input.factory_id).Result.OrderBy(s=>s.OrderNum).ToList();
             var itemList= productList.Select(a=>a.SAPItemNumber).Distinct().ToList();
             var planList=_mysql_ic_item.GetListAsync(a=>itemList.Contains(a.number) && a.factory_id==input.factory_id && !a.IsDeleted).Result.ToList();
@@ -4479,6 +4451,18 @@ namespace Business.Replenishment
             }
             return result;
         }
+
+        public List<string> GetYearPlanMonth(int year)
+        {
+            List<string> result = new List<string>();
+            for (int i = 0; i < 12; i++)
+            {
+                var months = Convert.ToDateTime($"{year}-01-01");
+                months = months.AddMonths(i);
+                result.Add($"{months.Year}-{months.Month.ToString("00")}");
+            }
+            return result;
+        }
         /// <summary>
         /// 获取前面几个月PlanMonth
         /// </summary>

+ 2 - 2
MicroServices/Business/Business.Application/ResourceExamineManagement/CalcBomViewAppService.cs

@@ -1628,7 +1628,7 @@ namespace Business.ResourceExamineManagement
             srm_Pr.icitem_id = returnlist.item_id;//物料id
             srm_Pr.icitem_name = returnlist.item_name;//物料名称
             srm_Pr.num = returnlist.num;
-            if (plan_date != null && !IsStraight)
+            if (plan_date != null)
             {
                 //-1为提前一天准备
                 srm_Pr.pr_sarrive_date = plan_date.GetValueOrDefault().AddDays(-1 - (int)(Math.Ceiling(plan.clean_leadtime.GetValueOrDefault())));
@@ -1646,7 +1646,7 @@ namespace Business.ResourceExamineManagement
             }
             sRMPR.totalLeadTime = (int)Math.Ceiling(supplier.lead_time.GetValueOrDefault());
             srm_Pr.pr_sysprice = supplier.order_price;//系统价格(含税)
-            srm_Pr.pr_orderprice = qty * supplier.order_price;//订单价格(含税)
+            srm_Pr.pr_orderprice = lack_qty * supplier.order_price;//订单价格(含税)
             srm_Pr.pr_price = supplier.netpurchase_price;//采购净价(不含税)
             srm_Pr.pr_rate = supplier.taxrate;//税率
             srm_Pr.pr_unit = returnlist.unit;//单位

+ 27 - 14
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -852,16 +852,16 @@ namespace Business.ResourceExamineManagement
                     }*/
                     if (_CalcBomViewAppService.mordersInsertList.Any())
                     {
-                        await _mes_morder.InsertManyAsync(_CalcBomViewAppService.mordersInsertList);
+                        await MongoHelper<mo_mes_morder>.InsertManyAsync(_CalcBomViewAppService.mordersInsertList);
                     }  
                     if (prmainlist.Any())
                     {
-                        await _srm_pr_main.InsertManyAsync(prmainlist);
+                        await MongoHelper<mo_srm_pr_main>.InsertManyAsync(prmainlist);
                     }
                     if (_CalcBomViewAppService.mooccupyAllInsertList.Any())
                     {
                         _CalcBomViewAppService.mooccupyAllInsertList.ForEach(s => { s.tenant_id = param.company_id.GetValueOrDefault(); s.company_id = param.company_id; s.factory_id = param.factoryId; });
-                        await _mes_mooccupy.InsertManyAsync(_CalcBomViewAppService.mooccupyAllInsertList);
+                        await MongoHelper<mo_mes_mooccupy>.InsertManyAsync(_CalcBomViewAppService.mooccupyAllInsertList);
                         /*var moOccupy = ObjectMapper.Map<List<mo_mes_mooccupy>, List<mes_mooccupy>>(_CalcBomViewAppService.mooccupyAllInsertList);
                         _businessDbContext.BulkInsert(moOccupy);*/
                         rtn.mooccupyAllList = _CalcBomViewAppService.mooccupyAllInsertList;
@@ -869,14 +869,14 @@ namespace Business.ResourceExamineManagement
                     if (_CalcBomViewAppService.moentriesInsertList.Any())
                     {
                         _CalcBomViewAppService.moentriesInsertList.ForEach(s => { s.tenant_id = param.company_id.GetValueOrDefault(); s.company_id = param.company_id; s.factory_id = param.factoryId; });
-                        await _mes_moentry.InsertManyAsync(_CalcBomViewAppService.moentriesInsertList);
+                        await MongoHelper<mo_mes_moentry>.InsertManyAsync(_CalcBomViewAppService.moentriesInsertList);
                         /*var mesmoentrys = ObjectMapper.Map<List<mo_mes_moentry>, List<mes_moentry>>(_CalcBomViewAppService.moentriesInsertList);
                         _businessDbContext.BulkInsert(mesmoentrys);*/
                     }
                     if (_CalcBomViewAppService.orderList.Any())
                     {
                         _CalcBomViewAppService.orderList.ForEach(s => { s.tenant_id = param.company_id.GetValueOrDefault(); s.company_id = param.company_id; s.factory_id = param.factoryId; });
-                        await _mes_oorder.InsertManyAsync(_CalcBomViewAppService.orderList);
+                        await MongoHelper<mo_mes_oorder>.InsertManyAsync(_CalcBomViewAppService.orderList);
                         /*var ooders = ObjectMapper.Map<List<mo_mes_oorder>, List<mes_oorder>>(_CalcBomViewAppService.orderList);
                         _businessDbContext.BulkInsert(ooders);*/
                         rtn.order_list = _CalcBomViewAppService.orderList;
@@ -884,12 +884,12 @@ namespace Business.ResourceExamineManagement
                     if (_CalcBomViewAppService.newStockOccList.Any())
                     {
                         _CalcBomViewAppService.newStockOccList.ForEach(s => { s.GenerateNewId(help.NextId()); s.tenant_id = param.company_id.GetValueOrDefault(); s.company_id = param.company_id; s.factory_id = param.factoryId; });
-                        await _ic_item_stockoccupy.InsertManyAsync(_CalcBomViewAppService.newStockOccList);
+                        await MongoHelper<mo_ic_item_stockoccupy>.InsertManyAsync(_CalcBomViewAppService.newStockOccList);
                     }
                     if (_CalcBomViewAppService.srm_Po_OccupiesInsert.Any())
                     {
                         _CalcBomViewAppService.srm_Po_OccupiesInsert.ForEach(s => { s.GenerateNewId(help.NextId()); s.tenant_id = param.company_id.GetValueOrDefault(); s.company_id = param.company_id; s.factory_id = param.factoryId; });
-                        await _srm_po_occupy.InsertManyAsync(_CalcBomViewAppService.srm_Po_OccupiesInsert);
+                        await MongoHelper<mo_srm_po_occupy>.InsertManyAsync(_CalcBomViewAppService.srm_Po_OccupiesInsert);
                         /*var poOccupies = ObjectMapper.Map<List<mo_srm_po_occupy>, List<srm_po_occupy>>(_CalcBomViewAppService.srm_Po_OccupiesInsert);
                         _businessDbContext.BulkInsert(poOccupies);*/
                     }
@@ -1020,7 +1020,6 @@ namespace Business.ResourceExamineManagement
                     }
                     if (bomExamineList.Any())
                     {
-                        //await _mysql_bom_child_examine.InsertManyAsync(bomExamineList);
                         _businessBangDbContext.BulkInsert(bomExamineList.OrderBy(s => s.num_order).ToList());
                     }
                     if (mooccupyList.Any())
@@ -1160,7 +1159,15 @@ namespace Business.ResourceExamineManagement
             List<srm_pr_main> alllist = _mysql_srm_pr_main.GetListAsync(s => s.company_id.ToString() == companyid && s.pr_ssend_date >= starttime && s.pr_ssend_date <= endtime && s.state == 1).Result;
             List<ic_item> ic_Items = _mysql_ic_item.GetListAsync(s => s.company_id.ToString() == companyid && alllist.Select(c => c.icitem_id).Distinct().Contains(s.Id)).Result;
 
-            var occupylist = _mysql_srm_po_occupy.GetListAsync(s => alllist.Select(c => c.Id).Contains(s.polist_id.GetValueOrDefault()) && s.company_id.ToString() == companyid && s.IsDeleted == false).Result;
+
+            var occupyListLINQ = _businessDbContext.srm_po_occupy.Where(x=>x.company_id.ToString()== companyid &&!x.IsDeleted).Join(_businessDbContext.srm_pr_main.Where(s => s.company_id.ToString() == companyid && s.pr_ssend_date >= starttime && s.pr_ssend_date <= endtime && s.state == 1), p => p.polist_id, pr => pr.Id, (p, pr) => new { p, pr }).ToList();
+            List<srm_po_occupy> occupylist = new List<srm_po_occupy>();
+            for (int i = 0; i < occupyListLINQ.Count; i++)
+            {
+                occupylist.Add(occupyListLINQ[i].p);
+            }
+
+            //var occupylist = _mysql_srm_po_occupy.GetListAsync(s => alllist.Select(c => c.Id).Contains(s.polist_id.GetValueOrDefault()) && s.company_id.ToString() == companyid && s.IsDeleted == false).Result;
             var purList = _mysql_srm_purchase.GetListAsync(x => x.company_id.ToString() == companyid).Result;
             List<srm_pr_main> insetAllList = new List<srm_pr_main>();
             List<srm_pr_main> updateAllList = new List<srm_pr_main>();
@@ -2124,11 +2131,19 @@ namespace Business.ResourceExamineManagement
                 moSrm_pr_main.ForEach(item => { item.GenerateNewId(help.NextId()); item.bang_id = bangid; });
                 await MongoHelper<mo_srm_pr_main>.InsertManyAsync(moSrm_pr_main);
 
+
+                var occupyListLINQ = _businessDbContext.srm_po_occupy.Where(x => x.company_id == companyId && x.factory_id == factoryId && !x.IsDeleted).Join(_businessDbContext.srm_pr_main.Where(x => x.company_id == companyId && x.factory_id == factoryId && x.state != 0 && itemIds.Contains(x.icitem_id.GetValueOrDefault())), p => p.polist_id, pr => pr.Id, (p, pr) => new { p, pr }).ToList();
+                List<srm_po_occupy> occupylist = new List<srm_po_occupy>();
+                for (int i = 0; i < occupyListLINQ.Count; i++)
+                {
+                    occupylist.Add(occupyListLINQ[i].p);
+                }
+
                 //采购申请占用详情
-                var srm_pr_occupy = _mysql_srm_po_occupy.GetListAsync(x => x.company_id == companyId && x.factory_id == factoryId && srm_pr_main.Select(c => c.Id).Contains(x.polist_id.GetValueOrDefault())).Result;
-                if (srm_pr_occupy.Count > 0)
+                //var srm_pr_occupy = _mysql_srm_po_occupy.GetListAsync(x => x.company_id == companyId && x.factory_id == factoryId && srm_pr_main.Select(c => c.Id).Contains(x.polist_id.GetValueOrDefault())).Result;
+                if (occupylist.Count > 0)
                 {
-                    var moSrm_pr_occupy = ObjectMapper.Map<List<srm_po_occupy>, List<mo_srm_po_occupy>>(srm_pr_occupy);
+                    var moSrm_pr_occupy = ObjectMapper.Map<List<srm_po_occupy>, List<mo_srm_po_occupy>>(occupylist);
                     moSrm_pr_occupy.ForEach(item => { item.GenerateNewId(help.NextId()); item.bang_id = bangid; });
                     await MongoHelper<mo_srm_po_occupy>.InsertManyAsync(moSrm_pr_occupy);
                 }
@@ -3751,8 +3766,6 @@ namespace Business.ResourceExamineManagement
             if (addList.Any())
             {
                 _businessDbContext.BulkInsert(addList);
-
-                //await _mysql_b_bom_pretreatment.InsertManyAsync(addList);
             }
         }
 

+ 5 - 5
MicroServices/Business/Business.Application/SystemJobManagement/SystemJobAppService.cs

@@ -780,7 +780,7 @@ namespace Business.SystemJobManagement
             }
             _businessDbContext.BulkInsert(ItemsAdd);
             _businessDbContext.BulkInsert(stockAdd);
-            _businessDbContext.ic_item.UpdateRange(ItemsUpd);
+            _businessDbContext.BulkUpdate(ItemsUpd);
         }
 
         public void SyncBom()
@@ -923,7 +923,7 @@ namespace Business.SystemJobManagement
                 }
                 _businessDbContext.BulkInsert(ItemsAdd);
                 _businessDbContext.BulkInsert(childItemsAdd);
-                _businessDbContext.ic_bom_child.UpdateRange(childItemsUpd);
+                _businessDbContext.BulkUpdate(childItemsUpd);
             }
         }
 
@@ -945,7 +945,7 @@ namespace Business.SystemJobManagement
         {
             try
             {
-                Thread.Sleep(120000);
+                Thread.Sleep(100);
             }
             catch (Exception ex)
             {
@@ -1033,8 +1033,8 @@ namespace Business.SystemJobManagement
                         }
                     }
                 }
-                await _mysql_mes_morder.UpdateManyAsync(updateList);
-                await _mysql_mes_moentry.UpdateManyAsync(updateMoentryList);
+                await _businessDbContext.BulkUpdateAsync(updateList);
+                await _businessDbContext.BulkUpdateAsync(updateMoentryList);
             }
             catch (Exception e)
             {

+ 3 - 3
MicroServices/Business/Business.Domain/StructuredDB/WMS/SAPInv.cs

@@ -42,19 +42,19 @@ namespace Business.StructuredDB.WMS
         /// 非限制库存量
         /// </summary>
         [Comment("非限制库存量")]
-        public string LABST { get; set; }
+        public decimal LABST { get; set; }
 
         /// <summary>
         /// 质检库存
         /// </summary>
         [Comment("质检库存")]
-        public string INSME { get; set; }
+        public decimal INSME { get; set; }
 
         /// <summary>
         /// 冻结库存
         /// </summary>
         [Comment("冻结库存")]
-        public string SPEME { get; set; }
+        public decimal SPEME { get; set; }
 
         /// <summary>
         /// 库存标识 K/O

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

@@ -9,7 +9,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-	 <PackageReference Include="Huffey.Quartz.MUI" Version="1.0.3" />
+	 <PackageReference Include="Huffey.Quartz.MUI" Version="1.0.4" />
 	 <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" />
     <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.3" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.5">