Quellcode durchsuchen

Merge branch 'master' of http://123.60.180.165:4647/ZZYDOP/DOPCore

heteng vor 3 Jahren
Ursprung
Commit
88abb24acd

+ 6 - 7
MicroServices/Business/Business.Application/ResourceExamineManagement/MorderAppService.cs

@@ -234,7 +234,8 @@ namespace Business.ResourceExamineManagement
                 //已占用数据
                 var Sumqty = mooccupies.Count > 0 ? mooccupies.Sum(x => x.moo_qty) : 0.00m;
                 //判断此工单剩余可占用数量
-                if (item.morder_production_number - item.inventory_number - Sumqty > 0)
+                var Sum = item.morder_production_number.GetValueOrDefault() - item.inventory_number.GetValueOrDefault() - Sumqty.GetValueOrDefault();
+                if (Sum > 0)
                 {
                     #region 注释
                     //if (Sumqty > 0 || item.inventory_number > 0)
@@ -266,10 +267,9 @@ namespace Business.ResourceExamineManagement
                     //        {
                     //            bom_number = item.bom_number,
                     //            version = version,
-                    //            packages = (int)Quantity.GetValueOrDefault(),
+                    //            packages = (int)Quantity,
                     //            tenantId = item.tenant_id,
                     //            factoryId = item.factory_id.GetValueOrDefault()
-
                     //        };
                     //        var EndProductiveDate = _productExamineAppService.ProductiveExamine(EndprodExamine);
                     //        var EndDay = ProductiveDate.Result / (60 * 10);
@@ -279,11 +279,10 @@ namespace Business.ResourceExamineManagement
                     //}
 
                     #endregion
-                    var Sum = item.morder_production_number - item.inventory_number - Sumqty;
                     //工单可占用数量-需求数量小于0时 占用工单全部可占用数量
                     if (Sum - Quantity <= 0)
                     {
-                        QuantityNumber = Sum.GetValueOrDefault();
+                        QuantityNumber = Sum;
                     }
                     else
                     {
@@ -297,7 +296,7 @@ namespace Business.ResourceExamineManagement
                     {
                         break;
                     }
-                    Quantity = Quantity - Sum.GetValueOrDefault();
+                    Quantity = Quantity - Sum;
                 }
 
             }
@@ -404,7 +403,7 @@ namespace Business.ResourceExamineManagement
             mes_Mooccupy.mysql_id = snowFlake.NextId();
             mes_Mooccupy.bang_id = bang_id;
             mes_Mooccupy.moo_id_type = MorderEnum.Zyjc_Type;
-            mes_Mooccupy.moo_id_billid = seorderentry.seorder_id;//销售订单ID
+            mes_Mooccupy.moo_id_billid = seorderentry.Id;//销售子表ID
             mes_Mooccupy.fbill_no = seorderentry.bill_no;//销售订单号
             mes_Mooccupy.fentry_id = seorderentry.entry_seq.Value;//销售订单行
             mes_Mooccupy.fitem_name = ic_item.name;//物料名称

+ 48 - 12
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -174,7 +174,7 @@ namespace Business.ResourceExamineManagement
         /// </summary>
         private readonly MorderAppService _morderAppService;
 
-        
+
         /// <summary>
         /// 预处理
         /// </summary>
@@ -305,7 +305,7 @@ namespace Business.ResourceExamineManagement
             param.sorderId = input.sorderId;
             param.tenantId = input.tenantId;
             param.factoryId = input.factoryId;
-            
+
 
             //资源检查结果
             PschedDto rtn = new PschedDto();
@@ -327,6 +327,10 @@ namespace Business.ResourceExamineManagement
             //获取订单行数据
             List<crm_seorderentry> sentrys = await _mysql_crm_seorderentry.GetListAsync(p => p.tenant_id == input.tenantId && p.factory_id == input.factoryId && p.seorder_id == input.sorderId && !p.IsDeleted);
 
+            //删除同步Mysql后旧数据
+            await DeleteMySqlOldData(sentrys);
+
+
             //数据库快照-同步mysql库数据到mongoDB中
             await DbSnapShot(input.tenantId, input.factoryId, bangid);
 
@@ -372,7 +376,7 @@ namespace Business.ResourceExamineManagement
 
             _CalcBomViewAppService.param = param;
             _CalcBomViewAppService.planList = planList;
-            _CalcBomViewAppService.leadTimeList= leadTimeList;
+            _CalcBomViewAppService.leadTimeList = leadTimeList;
             _CalcBomViewAppService.supplierList = supplierList;
             foreach (var item in sentrys)
             {
@@ -396,7 +400,7 @@ namespace Business.ResourceExamineManagement
                 //计算
                 _CalcBomViewAppService.CalcView(getBomList, bangid, item.qty.Value, input, item.plan_date, sklist, item, icitemlist);
 
-                
+
 
                 //TODO:最晚开始时间
                 var curFacDtl = leadTimeList.FirstOrDefault(p => p.item_id == childBom.icitem_id);
@@ -408,8 +412,6 @@ namespace Business.ResourceExamineManagement
                 dtl.substitutes = getBomList;
                 //添加订单行开工信息
                 examines.Add(dtl);
-                //生成工单 TODO:0=产品数量
-                //GenerateMorder(o, 0);
             }
             if (_CalcBomViewAppService.mooccupyAllList.Any())
             {
@@ -430,6 +432,7 @@ namespace Business.ResourceExamineManagement
             //清空快照数据
             await ClearSnapShot(bangid);
             return JsonConvert.SerializeObject(rtn);
+
         }
 
         /// <summary>
@@ -462,6 +465,33 @@ namespace Business.ResourceExamineManagement
                 GetIcBomData(curBoms, bomlist, bomchildlist);
             }
         }
+        /// <summary>
+        /// 删除旧订单行数据
+        /// </summary>
+        /// <param name="tenantId"></param>
+        /// <param name="factoryId"></param>
+        /// <param name="soentry_id"></param>
+        /// <returns></returns>
+        public async Task DeleteMySqlOldData(List<crm_seorderentry> soentry_id)
+        {
+            //删除工单相关表数据
+            var mes_moentry = _mysql_mes_moentry.GetListAsync(x => soentry_id.Select(p => p.Id).Contains(x.soentry_id.Value)).Result;
+
+            var mes_morder = _mysql_mes_morder.GetListAsync(x => mes_moentry.Select(p => p.moentry_moid).ToList().Contains(x.Id)).Result;
+            if (mes_moentry.Count > 0)
+            {
+                await _mysql_mes_moentry.DeleteManyAsync(mes_moentry);
+            }
+            if (mes_morder.Count > 0)
+            {
+                await _mysql_mes_morder.DeleteManyAsync(mes_morder);
+            }
+            var mysql_mes_mooccupy = _mysql_mes_mooccupy.GetListAsync(x => soentry_id.Select(p => p.Id).Contains(x.moo_id_billid.Value)).Result;
+            if (mysql_mes_mooccupy.Count > 0)
+            {
+                await _mysql_mes_mooccupy.DeleteManyAsync(mysql_mes_mooccupy);
+            }
+        }
 
         /// <summary>
         /// 数据库快照
@@ -580,10 +610,16 @@ namespace Business.ResourceExamineManagement
             ProjectionDefinitionBuilder<mo_ic_factory_details> project = new ProjectionDefinitionBuilder<mo_ic_factory_details>();
             return _ic_factory_details.Find(p => icItemIds.Contains(p.icitem_id) && p.factory_id == factoryid && p.tenant_id == tenantId && !p.IsDeleted,
                 project.Include(p => p.icitem_id).Include(p => p.production_leadtime).Include(p => p.stock_leadtime).
-                Include(p => p.transportation_leadtime).Include(p => p.order_leadtime).Include(p=>p.minorderqty)).Result.
-                Select(x => new ICItemLeadTimeDto { item_id = x.icitem_id, transportation_leadtime = x.transportation_leadtime, 
-                                                    stock_leadtime = x.stock_leadtime, production_leadtime = x.production_leadtime, 
-                                                    order_leadtime = x.order_leadtime,minorderqty=x.minorderqty }).AsQueryable<ICItemLeadTimeDto>().ToList();
+                Include(p => p.transportation_leadtime).Include(p => p.order_leadtime).Include(p => p.minorderqty)).Result.
+                Select(x => new ICItemLeadTimeDto
+                {
+                    item_id = x.icitem_id,
+                    transportation_leadtime = x.transportation_leadtime,
+                    stock_leadtime = x.stock_leadtime,
+                    production_leadtime = x.production_leadtime,
+                    order_leadtime = x.order_leadtime,
+                    minorderqty = x.minorderqty
+                }).AsQueryable<ICItemLeadTimeDto>().ToList();
         }
 
         //根据物料id获取物料供应商
@@ -872,7 +908,7 @@ namespace Business.ResourceExamineManagement
                 return sRMPR;
                 //throw new NotImplementedException("未找到物料ic_factory_details或ic_item_pur或ic_plan信息!");
             }
-            
+
             srm_Pr.GenerateNewId();
             srm_Pr.pr_billno = getOrderNum("PR");//pr单号
             srm_Pr.pr_mono = "";//关联工单号
@@ -908,7 +944,7 @@ namespace Business.ResourceExamineManagement
             srm_Pr.bang_id = bangId;
             //_srm_pr_main.InsertOne(srm_Pr);
             decimal? totalLeadTime = leadTime.transportation_leadtime + leadTime.stock_leadtime + leadTime.production_leadtime + leadTime.order_leadtime;
-            
+
             sRMPR.srm_Pr_Main = srm_Pr;
             sRMPR.lastStartTmie = deliveryDate.AddDays((double)totalLeadTime * -1);//减去提前期
             return sRMPR;