Pārlūkot izejas kodu

晚上mongoDB帮助类

heteng 3 gadi atpakaļ
vecāks
revīzija
ded6934dc9

+ 37 - 24
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -23,6 +23,8 @@ using Volo.Abp.ObjectMapping;
 using Volo.Abp.Application.Services;
 using ZstdSharp.Unsafe;
 using System.Transactions;
+using NUglify.JavaScript.Syntax;
+using System.Linq.Expressions;
 
 namespace Business.ResourceExamineManagement
 {
@@ -112,6 +114,41 @@ namespace Business.ResourceExamineManagement
             //_mysql_ic_bom_child = mysql_ic_bom_child;
         }
 
+        /// <summary>
+        /// mongoDB示例方法,后期删除
+        /// </summary>
+        /// <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);
+
+            //根据条件查询数据
+            Expression<Func<mes_technique, bool>> filter = x => x.Id == (long)1732376973889097728 && x.tech_name == "多条0";
+            var info3 = await _mes_technique.GetManyByCondition(filter);
+        }
+
         /// <summary>
         /// 资源检查
         /// </summary>
@@ -120,30 +157,6 @@ namespace Business.ResourceExamineManagement
         /// <exception cref="NotImplementedException"></exception>
         public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
         {
-            ////多条插入
-            //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;
-            //return a;
-
-            ////获取数据
-            //var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
-
-            ////更新数据
-            //info1.tech_name = "更新***";
-            //var rlt =await _mes_technique.UpdateOne(info1, info1.Id);
             return null;
             throw new NotImplementedException();
 

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

@@ -1,7 +1,9 @@
 using MongoDB.Driver;
+using MongoDB.Driver.Linq;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Linq.Expressions;
 using System.Reflection.Metadata;
 using System.Text;
 using System.Threading.Tasks;
@@ -49,5 +51,11 @@ namespace Business.Core.MongoDBHelper
         /// <param name="id"></param>
         /// <returns></returns>
         Task<T> GetOneByID(long id);
+
+        /// <summary>
+        /// 根据条件获取数据
+        /// </summary>
+        /// <returns></returns>
+        Task<List<T>> GetManyByCondition(Expression<Func<T, bool>> filter);
     }
 }

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

@@ -6,6 +6,7 @@ using MongoDB.Driver.Linq;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Linq.Expressions;
 using System.Text;
 using System.Threading.Tasks;
 using Volo.Abp.Domain.Entities;
@@ -95,5 +96,14 @@ namespace Business.Core.MongoDBHelper
             return mongoCollection.Find(p => p.Id == id).FirstOrDefaultAsync();
         }
 
+        /// <summary>
+        /// 根据条件获取数据
+        /// </summary>
+        /// <returns></returns>
+        public Task<List<T>> GetManyByCondition(Expression<Func<T, bool>> filter) 
+        {
+            return mongoCollection.Find(filter).ToListAsync();
+        }
+
     }
 }