tangdi 3 лет назад
Родитель
Сommit
838b1bc98c

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

@@ -365,7 +365,7 @@ 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库数据到mongoDB中
-            //await DbSnapShot(input.tenantId, input.factoryId, bangid);
+            await DbSnapShot(input.tenantId, input.factoryId, bangid);
 
             //通过订单行的产品代码获取物料BOM数据
             //FilterDefinition<ic_bom> filter = Builders<ic_bom>.Filter.In(s => s.bom_number, sentrys.Select(m => m.bom_number).ToList());
@@ -400,7 +400,7 @@ namespace Business.ResourceExamineManagement
             List<mo_ic_item> icitemlist = _ic_item.GetManyByCondition(p => itemIds.Contains(p.mysql_id) && !p.IsDeleted).Result;
 
             //物料库存
-            var stocklist = _ic_item_stock.GetManyByCondition(p => p.factory_id == param.factoryId && itemIds.Contains(p.icitem_id)).Result;
+            var stocklist = _ic_item_stock.GetManyByCondition(p => p.factory_id == param.factoryId && p.bang_id == bangid && itemIds.Contains(p.icitem_id)).Result;
 
             //物料提前期
             leadTimeList = GetLeadTime(itemIds, input.tenantId, input.factoryId);//提前期列表
@@ -507,6 +507,7 @@ namespace Business.ResourceExamineManagement
                 //设置当前计算bangid
                 icitemStokc.ForEach(item => { item.bang_id = bangid; });
                 var moIcitemStokc = ObjectMapper.Map<List<ic_item_stock>, List<mo_ic_item_stock>>(icitemStokc);
+                moIcitemStokc.ForEach(item => { item.id = help.NextId(); });
                 //插入数据
                 await _ic_item_stock.InsertMany(moIcitemStokc);
             }
@@ -516,6 +517,7 @@ namespace Business.ResourceExamineManagement
             {
                 mes_mooccupy.ForEach(item => { item.bang_id = bangid; });
                 var moMes_mooccupy = ObjectMapper.Map<List<mes_mooccupy>, List<mo_mes_mooccupy>>(mes_mooccupy);
+                moMes_mooccupy.ForEach(item => { item.id = help.NextId(); });
                 await _mes_mooccupy.InsertMany(moMes_mooccupy);
             }
             //工单主表
@@ -524,6 +526,7 @@ namespace Business.ResourceExamineManagement
             {
                 mes_morder.ForEach(item => { item.bang_id = bangid; });
                 var moMes_morder = ObjectMapper.Map<List<mes_morder>, List<mo_mes_morder>>(mes_morder);
+                moMes_morder.ForEach(item => { item.id = help.NextId(); });
                 await _mes_morder.InsertMany(moMes_morder);
             }
             //工单子表
@@ -532,6 +535,7 @@ namespace Business.ResourceExamineManagement
             {
                 mes_moentry.ForEach(item => { item.bang_id = bangid; });
                 var moMes_moentry = ObjectMapper.Map<List<mes_moentry>, List<mo_mes_moentry>>(mes_moentry);
+                moMes_moentry.ForEach(item => { item.id = help.NextId(); });
                 await _mes_moentry.InsertMany(moMes_moentry);
             }
 
@@ -542,6 +546,7 @@ namespace Business.ResourceExamineManagement
             {
                 srm_po_main.ForEach(item => { item.bang_id = bangid; });
                 var moSrm_po_main = ObjectMapper.Map<List<srm_po_main>, List<mo_srm_po_main>>(srm_po_main);
+                moSrm_po_main.ForEach(item => { item.id = help.NextId(); });
                 await _srm_po_main.InsertMany(moSrm_po_main);
             }
 
@@ -551,6 +556,7 @@ namespace Business.ResourceExamineManagement
             {
                 srm_po_list.ForEach(item => { item.bang_id = bangid; });
                 var moSrm_po_list = ObjectMapper.Map<List<srm_po_list>, List<mo_srm_po_list>>(srm_po_list);
+                moSrm_po_list.ForEach(item => { item.id = help.NextId(); });
                 await _srm_po_list.InsertMany(moSrm_po_list);
             }
 
@@ -560,6 +566,7 @@ namespace Business.ResourceExamineManagement
             {
                 srm_po_occupy.ForEach(item => { item.bang_id = bangid; });
                 var moSrm_po_occupy = ObjectMapper.Map<List<srm_po_occupy>, List<mo_srm_po_occupy>>(srm_po_occupy);
+                moSrm_po_occupy.ForEach(item => { item.id = help.NextId(); });
                 await _srm_po_occupy.InsertMany(moSrm_po_occupy);
             }
 
@@ -569,6 +576,7 @@ namespace Business.ResourceExamineManagement
             {
                 ic_factory_details.ForEach(item => { item.bang_id = bangid; });
                 var moIc_factory_details = ObjectMapper.Map<List<ic_factory_details>, List<mo_ic_factory_details>>(ic_factory_details);
+                moIc_factory_details.ForEach(item => { item.id = help.NextId(); });
                 await _ic_factory_details.InsertMany(moIc_factory_details);
             }
 
@@ -578,6 +586,7 @@ namespace Business.ResourceExamineManagement
             {
                 ic_plan.ForEach(item => { item.bang_id = bangid; });
                 var moIc_plan = ObjectMapper.Map<List<ic_plan>, List<mo_ic_plan>>(ic_plan);
+                moIc_plan.ForEach(item => { item.id = help.NextId(); });
                 await _ic_plan.InsertMany(moIc_plan);
             }
 
@@ -587,6 +596,7 @@ namespace Business.ResourceExamineManagement
             {
                 ic_item_pur.ForEach(item => { item.bang_id = bangid; });
                 var moIc_item_pur = ObjectMapper.Map<List<ic_item_pur>, List<mo_ic_item_pur>>(ic_item_pur);
+                moIc_item_pur.ForEach(item => { item.id = help.NextId(); });
                 await _ic_item_pur.InsertMany(moIc_item_pur);
             }
         }

+ 21 - 9
MicroServices/Business/Business.Application/SyncDataManagement/SyncMySQLDataAppService.cs

@@ -118,6 +118,8 @@ namespace Business.SyncDataManagement
         /// </summary>
         private readonly IMongoDB<mo_mes_tech_process> _mes_tech_process;
         private IRepository<mes_tech_process, long> _mysql_mes_tech_process;
+
+        SnowFlake help = new SnowFlake();
         #endregion
 
         /// <summary>
@@ -182,6 +184,7 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _ic_bom.Delete(p=>p.mysql_id != -1);
                 var moIcBoms = ObjectMapper.Map<List<ic_bom>, List<mo_ic_bom>>(icBoms);
+                moIcBoms.ForEach(s => s.id = help.NextId());
                 //插入数据
                  _ic_bom.InsertMany(moIcBoms);
             }
@@ -193,8 +196,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _ic_bom_child.Delete(p => p.mysql_id != -1);
                 var moIcbom_childs = ObjectMapper.Map<List<ic_bom_child>, List<mo_ic_bom_child>>(icbom_childs);
+                moIcbom_childs.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _ic_bom_child.InsertMany(moIcbom_childs);
+                _ic_bom_child.InsertMany(moIcbom_childs);
             }
 
             //同步物料数据
@@ -204,8 +208,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _ic_item.Delete(p => p.mysql_id != -1);
                 var moIcItems = ObjectMapper.Map<List<ic_item>, List<mo_ic_item>>(icItems);
+                moIcItems.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _ic_item.InsertMany(moIcItems);
+                _ic_item.InsertMany(moIcItems);
             }
 
             //同步替代群组数据
@@ -215,8 +220,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _ic_substitute.Delete(p => p.mysql_id != -1);
                 var moSubtitutes = ObjectMapper.Map<List<ic_substitute>, List<mo_ic_substitute>>(subtitutes);
+                moSubtitutes.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _ic_substitute.InsertMany(moSubtitutes);
+                _ic_substitute.InsertMany(moSubtitutes);
             }
 
             //同步物料替代多群组数据
@@ -226,8 +232,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _ic_substitute_all.Delete(p => p.mysql_id != -1);
                 var moSubAlls = ObjectMapper.Map<List<ic_substitute_all>, List<mo_ic_substitute_all>>(subAlls);
+                moSubAlls.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _ic_substitute_all.InsertMany(moSubAlls);
+                _ic_substitute_all.InsertMany(moSubAlls);
             }
 
             //同步物料替代多群组明细数据
@@ -237,8 +244,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _ic_substitute_all_dtl.Delete(p => p.mysql_id != -1);
                 var moSubAllDtls = ObjectMapper.Map<List<ic_substitute_all_dtl>, List<mo_ic_substitute_all_dtl>>(subAllDtls);
+                moSubAllDtls.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _ic_substitute_all_dtl.InsertMany(moSubAllDtls);
+                _ic_substitute_all_dtl.InsertMany(moSubAllDtls);
             }
 
             //同步供应商数据
@@ -248,8 +256,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _srm_supplier.Delete(p => p.mysql_id != -1);
                 var moSuppliers = ObjectMapper.Map<List<srm_supplier>, List<mo_srm_supplier>>(suppliers);
+                moSuppliers.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _srm_supplier.InsertMany(moSuppliers);
+                _srm_supplier.InsertMany(moSuppliers);
             }
 
             //同步工艺路径数据
@@ -259,8 +268,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _mes_technique.Delete(p => p.mysql_id != -1);
                 var moTechs = ObjectMapper.Map<List<mes_technique>, List<mo_mes_technique>>(techs);
+                moTechs.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _mes_technique.InsertMany(moTechs);
+                _mes_technique.InsertMany(moTechs);
             }
 
             //同步工序数据
@@ -270,8 +280,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _mes_process.Delete(p => p.mysql_id != -1);
                 var moProcesses = ObjectMapper.Map<List<mes_process>, List<mo_mes_process>>(processes);
+                moProcesses.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _mes_process.InsertMany(moProcesses);
+                _mes_process.InsertMany(moProcesses);
             }
 
             //同步工艺关联工序数据
@@ -281,8 +292,9 @@ namespace Business.SyncDataManagement
                 //先清空表数据
                  _mes_tech_process.Delete(p => p.mysql_id != -1);
                 var moTech_procs = ObjectMapper.Map<List<mes_tech_process>, List<mo_mes_tech_process>>(tech_procs);
+                moTech_procs.ForEach(s => s.id = help.NextId());
                 //插入数据
-                 _mes_tech_process.InsertMany(moTech_procs);
+                _mes_tech_process.InsertMany(moTech_procs);
             }
         }
     }

+ 7 - 0
MicroServices/Business/Bussiness.MongoModel/Base/MoBaseEntity.cs

@@ -26,6 +26,13 @@ namespace Bussiness.MongoModel
             mysql_id = snow.NextId();
         }
 
+        /// <summary>
+        /// id
+        /// </summary>
+        [Comment("id")]
+        [BsonRepresentation(MongoDB.Bson.BsonType.Int64)]
+        public virtual long id { get; set; }
+
         /// <summary>
         /// mysql表id
         /// </summary>