Browse Source

提交学生更新信息

CrazyIter 5 years ago
parent
commit
bf37ed7ed3

+ 11 - 0
TEAMModelOS.SDK/Context/Attributes/Azure/CosmosDBAttribute.cs

@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Context.Attributes.Azure
+{
+    [AttributeUsage(AttributeTargets.Class)]
+    public class CosmosDBAttribute: Attribute
+    {
+    }
+}

+ 21 - 0
TEAMModelOS.SDK/Helper/Common/ReflectorExtensions/ReflectorExtensions.cs

@@ -1,6 +1,9 @@
 using AspectCore.Extensions.Reflection;
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using System.Reflection;
+using System.Reflection.Metadata;
 
 namespace TEAMModelOS.SDK.Helper.Common.ReflectorExtensions
 {
@@ -31,5 +34,23 @@ namespace TEAMModelOS.SDK.Helper.Common.ReflectorExtensions
             var value = chReflector.GetValue(null) as T;
             return value;
         }
+
+        /// <summary>
+        /// 获取T类型属性标记的类集合
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <returns></returns>
+        public static IEnumerable<Type> GetAllTypeAsAttribute<T>() {
+
+
+            Assembly assembly =typeof(T).Assembly;
+            var typesWithMyAttribute =
+              from t in assembly.GetTypes()
+              let attributes = t.GetCustomAttributes(typeof(T), true)
+              where attributes != null && attributes.Length > 0
+              select new { Type = t, Attributes = attributes.Cast<T>() };
+
+            return typesWithMyAttribute;
+        }
     }
 }

+ 10 - 4
TEAMModelOS.SDK/Module/AzureCosmosDB/Implements/AzureCosmosDBRepository.cs

@@ -20,6 +20,7 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using Microsoft.Azure.CosmosDB.BulkExecutor.BulkDelete;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using System.Text;
+using TEAMModelOS.SDK.Helper.Common.ReflectorExtensions;
 
 namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
 { /// <summary>
@@ -41,7 +42,6 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
 
         private DocumentClient CosmosClient { get; set; }
         private DocumentCollection CosmosCollection { get; set; }
-
         private string Database { get; set; }
         private int CollectionThroughput { get; set; }
         public AzureCosmosDBRepository(AzureCosmosDBOptions options)
@@ -70,20 +70,26 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
                 CollectionThroughput = options.CollectionThroughput;
                 CosmosClient.CreateDatabaseIfNotExistsAsync(new Database { Id = Database });
                 // _connectionString = options.ConnectionString;
+
+                //获取数据库所有的表
+                FeedResponse<DocumentCollection> collections = CosmosClient.ReadDocumentCollectionFeedAsync(UriFactory.CreateDatabaseUri(Database)).GetAwaiter().GetResult();
+                //collections
+               // IEnumerable<Type> types=   ReflectorExtensions.GetAllTypeAsAttribute<CosmosDBAttribute>();
+
             }
             catch (DocumentClientException de)
             {
                 Exception baseException = de.GetBaseException();
-                Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
+                //Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
             }
             catch (Exception e)
             {
                 Exception baseException = e.GetBaseException();
-                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
+               //Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
             }
             finally
             {
-                Console.WriteLine("End of demo, press any key to exit.");
+              //  Console.WriteLine("End of demo, press any key to exit.");
                 //  Console.ReadKey();
             }
 

+ 1 - 0
TEAMModelOS.Service/Models/Core/Classroom.cs

@@ -6,6 +6,7 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 
 namespace TEAMModelOS.Service.Models.Core
 {
+    [CosmosDBAttribute]
    public class Classroom
     {
         public Classroom()

+ 4 - 2
TEAMModelOS/Controllers/Core/StudentController.cs

@@ -44,6 +44,7 @@ namespace TEAMModelOS.Controllers.Syllabus
                 periodCode = request.@params.classroom.periodCode,
                 schoolCode = request.@params.classroom.schoolCode,
             };
+            request.@params.id = classroom.schoolCode + request.@params.studentId;
             request.@params.classroom = classroom;
             Student data = await azureCosmosDBRepository.Save<Student>(request.@params);
             return builder.Data(data).build();
@@ -81,8 +82,9 @@ namespace TEAMModelOS.Controllers.Syllabus
                 {
                     long createDate = DateTimeOffset.UtcNow.Ticks;
                     dictInfo.TryGetValue(key, out List<Student> sts);
-                    List<long>  ids= IdWorker.getIdsByCount(sts.Count);
+                   
                     sts.ForEach(x => {
+
                         Student student = new Student
                         {
                             schoolCode = classrooms[0].schoolCode,
@@ -126,7 +128,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             return builder.Data(data).build();
         }
         [HttpPost("UpdateAllStudent")]
-        public async Task<BaseJosnRPCResponse> DeleteALlStudentInfo(JosnRPCRequest<Dictionary<string, Dictionary<string, object>>> request)
+        public async Task<BaseJosnRPCResponse> UpdateAllStudent(JosnRPCRequest<Dictionary<string, Dictionary<string, object>>> request)
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             bool find = request.@params.TryGetValue("find", out Dictionary<string, object> findObj);