Przeglądaj źródła

mongodb帮助类调整

heteng 3 lat temu
rodzic
commit
91283be7a6

+ 44 - 28
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -30,7 +30,6 @@ using System.ComponentModel;
 using System.Reflection.Emit;
 using NUglify.Helpers;
 using Microsoft.AspNetCore.SignalR.Protocol;
-using XCZ.Extensions;
 using System.ComponentModel.Design;
 using Volo.Abp.Validation.StringValues;
 using System.Runtime.CompilerServices;
@@ -207,33 +206,49 @@ namespace Business.ResourceExamineManagement
         /// <returns></returns>
         public async Task test()
         {
-            //多条插入
-            List<mes_technique> infos = new List<mes_technique>();
-            mes_technique info;
-            for (int i = 0; i < 3; i++)
-            {
-                info = new mes_technique();
-                info.GenerateNewId();
-                info.tech_name = "多条" + i;
-                info.level = i;
-                infos.Add(info);
-            }
-            await _mes_technique.InsertMany(infos);
-
-            var info2 = _mes_technique.GetAll().Result;
-            var a = new PschedDto();
-            a.count = info2.Count;
-
-            //获取数据
-            var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
-
-            //更新数据
-            info1.tech_name = "更新***";
-            var rlt = await _mes_technique.UpdateOne(info1, info1.Id);
+            ////多条插入
+            //List<mes_technique> infos = new List<mes_technique>();
+            //mes_technique info;
+            //for (int i = 0; i < 3; i++)
+            //{
+            //    info = new mes_technique();
+            //    info.GenerateNewId();
+            //    info.tech_name = "多条" + i;
+            //    info.level = i;
+            //    infos.Add(info);
+            //}
+            //await _mes_technique.InsertMany(infos);
+
+            //var info2 = _mes_technique.GetAll().Result;
+            //var a = new PschedDto();
+            //a.count = info2.Count;
+
+            ////获取数据
+            //var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
+
+            ////更新数据
+            //info1.tech_name = "更新***";
+            //var rlt = await _mes_technique.UpdateOne(info1, info1.Id);
+
+            ////根据条件查询数据
+            //Expression<Func<mes_technique, bool>> filter = x => x.Id == (long)1732376973889097728 && x.tech_name == "多条0";
+            //var info3 = await _mes_technique.GetManyByCondition(filter);
+
+            ////删除数据
+            ////根据id删除数据
+            ////await _ic_item_stock.DeleteByIds(136123);
+
+            ////根据id删除表数据
+            //List<long> aa= new List<long>();
+            //aa.Add(136126);
+            //aa.Add(136127);
+            //aa.Add(136128);
+            //FilterDefinition<ic_item_stock> filter = Builders<ic_item_stock>.Filter.In(s => s.icitem_id, aa);
+            //await _ic_item_stock.DeleteManyByIds(filter);
+            
+            //根据条件删除数据
+            await _ic_item_stock.DeleteManyByCondition(p=>p.icitem_name == "111");
 
-            //根据条件查询数据
-            Expression<Func<mes_technique, bool>> filter = x => x.Id == (long)1732376973889097728 && x.tech_name == "多条0";
-            var info3 = await _mes_technique.GetManyByCondition(filter);
         }
 
         /// <summary>
@@ -244,8 +259,9 @@ namespace Business.ResourceExamineManagement
         /// <exception cref="NotImplementedException"></exception>
         public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
         {
+            await test();
             //数据库快照-同步mysql库数据到mongoDB中
-            await SyncData(input.factoryId);
+            //await SyncData(input.factoryId);
             //生成当前计算bangid
             //SnowFlake snow = new SnowFlake();
             //long bangid = snow.NextId();

+ 19 - 0
MicroServices/Business/Business.Core/MongoDBHelper/IMongoDB.cs

@@ -63,5 +63,24 @@ namespace Business.Core.MongoDBHelper
         /// </summary>
         /// <returns></returns>
         Task<List<T>> GetManyByIds(FilterDefinition<T> filter);
+
+        /// <summary>
+        /// 根据id删除数据
+        /// </summary>
+        /// <returns></returns>
+        Task DeleteByIds(long id);
+
+        /// <summary>
+        /// 根据条件删除数据
+        /// </summary>
+        /// <returns></returns>
+        Task DeleteManyByIds(FilterDefinition<T> filter);
+
+        /// <summary>
+        /// 根据条件删除数据
+        /// </summary>
+        /// <returns></returns>
+        Task DeleteManyByCondition(Expression<Func<T, bool>> filter);
+
     }
 }

+ 26 - 0
MicroServices/Business/Business.Core/MongoDBHelper/MongoDBTools.cs

@@ -114,5 +114,31 @@ namespace Business.Core.MongoDBHelper
             return mongoCollection.Find(filter).ToListAsync();
         }
 
+        /// <summary>
+        /// 根据id删除数据
+        /// </summary>
+        /// <returns></returns>
+        public Task DeleteByIds(long id)
+        {
+            return mongoCollection.DeleteOneAsync(p => p.Id == id);
+        }
+
+        /// <summary>
+        /// 根据条件删除数据
+        /// </summary>
+        /// <returns></returns>
+        public Task DeleteManyByIds(FilterDefinition<T> filter)
+        {
+            return mongoCollection.DeleteManyAsync(filter);
+        }
+
+        /// <summary>
+        /// 根据条件删除数据
+        /// </summary>
+        /// <returns></returns>
+        public Task DeleteManyByCondition(Expression<Func<T, bool>> filter)
+        {
+            return mongoCollection.DeleteManyAsync<T>(filter);
+        }
     }
 }