소스 검색

Merge remote-tracking branch 'origin/develop3.0' into develop3.0

osbert 4 년 전
부모
커밋
ad1caefdd0

+ 126 - 118
TEAMModelFunction/MonitorCosmosDB.cs

@@ -16,13 +16,13 @@ namespace TEAMModelFunction
 {
     public class MonitorCosmosDB
     {
-        private readonly IHttpClientFactory _clientFactory;
         private readonly AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
 
-        public MonitorCosmosDB( IHttpClientFactory clientFactory,AzureCosmosFactory azureCosmos)
+        public MonitorCosmosDB( IHttpClientFactory clientFactory,AzureCosmosFactory azureCosmos,DingDing dingDing)
         {
-            _clientFactory = clientFactory;
             _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
     }
 
         [FunctionName("School")]
@@ -31,79 +31,30 @@ namespace TEAMModelFunction
             collectionName: "Common",
             ConnectionStringSetting = "CosmosConnection",
             LeaseCollectionName = "leases")]IReadOnlyList<Document> input, ILogger log)
-        {          
-                if (input != null && input.Count > 0)
-                {
-                    log.LogInformation("Documents modified " + input.Count);
-                    log.LogInformation("First document Id " + input[0].Id);
-                }
-            //input[0]
-            var client = _azureCosmos.GetCosmosClient();
-            List<ExamInfo> exams = new List<ExamInfo>();
-            string pk = input[0].GetPropertyValue<string>("pk");
-            if (!string.IsNullOrEmpty(pk) &&  pk.Equals("Exam")) {
-                string code = input[0].GetPropertyValue<string>("code");
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.id = '{input[0].Id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
+        {
+            try {
+                var client = _azureCosmos.GetCosmosClient();
+                List<ExamInfo> exams = new List<ExamInfo>();
+                string pk = input[0].GetPropertyValue<string>("pk");
+                if (!string.IsNullOrEmpty(pk) && pk.Equals("Exam", StringComparison.OrdinalIgnoreCase))
                 {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    string code = input[0].GetPropertyValue<string>("code");
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.id = '{input[0].Id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
                     {
-                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                         {
+                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                            {
 
-                            exams.Add(obj.ToObject<ExamInfo>());
-                        }
-                    }
-                }
-                for (int i = 0; i < exams.Count; i++)
-                {
-                    /*if (exams[i].startTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) < 0 
-                        && exams[i].endTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) > 0 )
-                    {*/
-                    if (exams[i].progress.Equals("going")) { 
-
-                        //await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exams[i], exams[i].id.ToString(), new Azure.Cosmos.PartitionKey($"{exams[i].code}"));
-                        for (int j = 0;j< exams[i].subjects.Count;j++) {
-                            for (int k = 0; k < exams[i].targetClassIds.Count; k++) {                         
-                                ExamClassResult result = new ExamClassResult();
-                                result.code = "ExamClassResult-" + exams[i].school;
-                                result.examId = exams[i].id;
-                                result.id = Guid.NewGuid().ToString();
-                                result.subjectId = exams[i].subjects[j].id;
-                                result.year = exams[i].year;
-                                result.ttl = -1;
-                                result.scope = exams[i].scope;
-                                result.pk = typeof(ExamClassResult).Name;
-                                result.info.id = exams[i].targetClassIds[k];
-                                var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(exams[i].targetClassIds[k], new Azure.Cosmos.PartitionKey($"Class-{exams[i].school}"));
-                                if (sresponse.Status == 200)
-                                {
-                                    using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
-                                    Classroom classroom = json.ToObject<Classroom>();
-                                    result.info.name = classroom.name;
-                                    List<List<string>> ans = new List<List<string>>();
-                                    List<double> ansPoint = new List<double>();
-                                    foreach (double p in exams[i].papers[j].point) {
-                                        ans.Add(new List<string>());
-                                        ansPoint.Add(0);
-                                    }
-                                    foreach (StudentSimple stu in classroom.students) {
-                                        result.studentIds.Add(stu.id);
-                                        result.studentAnswers.Add(ans);
-                                        result.studentScores.Add(ansPoint);
-                                    }
-                                }                               
-                                result.progress = exams[i].progress;
-                                result.school = exams[i].school;
-                                await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
-
+                                exams.Add(obj.ToObject<ExamInfo>());
                             }
                         }
                     }
-                    if (exams[i].progress.Equals("finish"))
-                    {                       
+                    for (int i = 0; i < exams.Count; i++)
+                    {
                         List<ExamClassResult> examClassResults = new List<ExamClassResult>();
-                        await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{exams[i].id}'"))
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{exams[i].id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{code}") }))
                         {
                             using var json = await JsonDocument.ParseAsync(item.ContentStream);
                             if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
@@ -114,66 +65,123 @@ namespace TEAMModelFunction
                                 }
                             }
                         }
-                        for (int j = 0; j < exams[i].subjects.Count; j++)
+                        /*if (exams[i].startTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) < 0 
+                            && exams[i].endTime.CompareTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) > 0 )
+                        {*/
+                        if (examClassResults.Count < 0)
                         {
-                            ExamResult result = new ExamResult();
-                            result.ttl = -1;
-                            result.pk = typeof(ExamResult).Name;
-                            result.code = "ExamResult-" + exams[i].school;
-                            result.school = exams[i].school;
-                            result.id = Guid.NewGuid().ToString();
-                            result.examId = exams[i].id;
-                            result.subjectId = exams[i].subjects[j].id;
-                            result.year = exams[i].year;
-                            result.paper = exams[i].papers[j];
-                            result.point = exams[i].papers[j].point;
-                            result.scope = exams[i].scope;
-                            result.name = exams[i].name;
-                            //result.time
-
-                            //人数总和
-                            int Count = 0;
-                            int m = 0;
-                            List<ClassRange> classRanges = new List<ClassRange>();
-                            foreach (ExamClassResult classResult in examClassResults)
+                            if (exams[i].progress.Equals("going", StringComparison.OrdinalIgnoreCase))
                             {
-                                //处理班级信息
-                                ClassRange range = new ClassRange();
-                                range.id = classResult.info.id;
-                                range.name = classResult.info.name;
-                                List<int> ran = new List<int>();
-                                int stuCount = classResult.studentIds.Count;
-                                Count += stuCount;
-                                if (m == 0)
-                                {
-                                    ran.Add(0);
-                                    ran.Add(stuCount - 1);
-                                }
-                                else
-                                {
-                                    ran.Add(Count - stuCount);
-                                    ran.Add(Count - 1);
-                                }
-                                m++;
-                                range.range = ran;
-                                classRanges.Add(range);
-                                //处理学生ID
-                                foreach (string id in classResult.studentIds)
+
+                                //await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exams[i], exams[i].id.ToString(), new Azure.Cosmos.PartitionKey($"{exams[i].code}"));
+                                for (int j = 0; j < exams[i].subjects.Count; j++)
                                 {
-                                    result.studentIds.Add(id);
+                                    for (int k = 0; k < exams[i].targetClassIds.Count; k++)
+                                    {
+                                        ExamClassResult result = new ExamClassResult();
+                                        result.code = "ExamClassResult-" + exams[i].school;
+                                        result.examId = exams[i].id;
+                                        result.id = Guid.NewGuid().ToString();
+                                        result.subjectId = exams[i].subjects[j].id;
+                                        result.year = exams[i].year;
+                                        result.ttl = -1;
+                                        result.scope = exams[i].scope;
+                                        result.pk = typeof(ExamClassResult).Name;
+                                        result.info.id = exams[i].targetClassIds[k];
+                                        var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(exams[i].targetClassIds[k], new Azure.Cosmos.PartitionKey($"Class-{exams[i].school}"));
+                                        if (sresponse.Status == 200)
+                                        {
+                                            using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
+                                            Classroom classroom = json.ToObject<Classroom>();
+                                            result.info.name = classroom.name;
+                                            List<List<string>> ans = new List<List<string>>();
+                                            List<double> ansPoint = new List<double>();
+                                            foreach (double p in exams[i].papers[j].point)
+                                            {
+                                                ans.Add(new List<string>());
+                                                ansPoint.Add(0);
+                                            }
+                                            foreach (StudentSimple stu in classroom.students)
+                                            {
+                                                result.studentIds.Add(stu.id);
+                                                result.studentAnswers.Add(ans);
+                                                result.studentScores.Add(ansPoint);
+                                            }
+                                        }
+                                        result.progress = exams[i].progress;
+                                        result.school = exams[i].school;
+                                        await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
+
+                                    }
                                 }
-                                foreach (List<double> scores in classResult.studentScores)
+                            }
+                        }
+                        if (exams[i].progress.Equals("finish", StringComparison.OrdinalIgnoreCase))
+                        {
+                            for (int j = 0; j < exams[i].subjects.Count; j++)
+                            {
+                                ExamResult result = new ExamResult();
+                                result.ttl = -1;
+                                result.pk = typeof(ExamResult).Name;
+                                result.code = "ExamResult-" + exams[i].school;
+                                result.school = exams[i].school;
+                                result.id = Guid.NewGuid().ToString();
+                                result.examId = exams[i].id;
+                                result.subjectId = exams[i].subjects[j].id;
+                                result.year = exams[i].year;
+                                result.paper = exams[i].papers[j];
+                                result.point = exams[i].papers[j].point;
+                                result.scope = exams[i].scope;
+                                result.name = exams[i].name;
+                                //result.time
+
+                                //人数总和
+                                int Count = 0;
+                                int m = 0;
+                                List<ClassRange> classRanges = new List<ClassRange>();
+                                foreach (ExamClassResult classResult in examClassResults)
                                 {
-                                    result.studentScores.Add(scores);
+                                    //处理班级信息
+                                    ClassRange range = new ClassRange();
+                                    range.id = classResult.info.id;
+                                    range.name = classResult.info.name;
+                                    List<int> ran = new List<int>();
+                                    int stuCount = classResult.studentIds.Count;
+                                    Count += stuCount;
+                                    if (m == 0)
+                                    {
+                                        ran.Add(0);
+                                        ran.Add(stuCount - 1);
+                                    }
+                                    else
+                                    {
+                                        ran.Add(Count - stuCount);
+                                        ran.Add(Count - 1);
+                                    }
+                                    m++;
+                                    range.range = ran;
+                                    classRanges.Add(range);
+                                    //处理学生ID
+                                    foreach (string id in classResult.studentIds)
+                                    {
+                                        result.studentIds.Add(id);
+                                    }
+                                    foreach (List<double> scores in classResult.studentScores)
+                                    {
+                                        result.studentScores.Add(scores);
+                                    }
                                 }
+                                result.classes = classRanges;
+                                await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{result.school}"));
                             }
-                            result.classes = classRanges;
-                            await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{result.school}"));
                         }
                     }
-
                 }
-            }           
+            } catch (Exception e) {
+                await _dingDing.SendBotMsg($"CosmosDB_common,School()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return;
+            }
+                     
         }
     }
 }

+ 82 - 38
TEAMModelFunction/ServiceBusTopic.cs

@@ -11,62 +11,106 @@ using TEAMModelOS.SDK.Extension;
 
 namespace TEAMModelFunction
 {
-    public   class ServiceBusTopic
+    public  class ServiceBusTopic
     {
         private readonly AzureCosmosFactory _azureCosmos;
-        public ServiceBusTopic(  AzureCosmosFactory azureCosmos)
+        private readonly DingDing _dingDing;
+        public ServiceBusTopic(  AzureCosmosFactory azureCosmos, DingDing dingDing)
         {
             _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
         }
         [FunctionName("ServiceBusTopic")]
-        public async Task Run([ServiceBusTrigger("test_topic_ActiveTask", "test_topic_ReciveTask", Connection = "ConnectionBusName")] string mySbMsg, ILogger log)
+        public async Task ExamBus([ServiceBusTrigger("active-task", "active-exam-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
         {
-            log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
-            Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
-            var client = _azureCosmos.GetCosmosClient();
-            keyValuePairs.TryGetValue("id", out object id);
-            keyValuePairs.TryGetValue("name", out object name);
-            keyValuePairs.TryGetValue("code", out object code);
-            //keyValuePairs.TryGetValue("status", out object progress);
-            if (name.ToString().Equals("ExamInfo")) {
-                ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
-                if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) < 0) {
-                    exam.progress = "going";
-                } else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) > 0) {
-                    exam.progress = "finish";
-                }               
-                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
-            } else if (name.ToString().Equals("Survey")) {
-                Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
-                if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) < 0)
+            try
+            {
+                Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                keyValuePairs.TryGetValue("id", out object id);
+                keyValuePairs.TryGetValue("name", out object name);
+                keyValuePairs.TryGetValue("code", out object code);
+                //keyValuePairs.TryGetValue("status", out object progress);
+                if (name.ToString().Equals("ExamInfo", StringComparison.OrdinalIgnoreCase))
                 {
-                    survey.progress = "going";
+                    ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
+                    if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) < 0)
+                    {
+                        exam.progress = "going";
+                    }
+                    else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) > 0)
+                    {
+                        exam.progress = "finish";
+                    }
+                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
                 }
-                else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) > 0)
+            } catch (Exception ex) {
+                await _dingDing.SendBotMsg($"ServiceBus,ExamBus()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return;
+            }
+                              
+        }
+        public async Task VoteBus([ServiceBusTrigger("active-task", "active-vote-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
+        {
+            try {
+                Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                keyValuePairs.TryGetValue("id", out object id);
+                keyValuePairs.TryGetValue("name", out object name);
+                keyValuePairs.TryGetValue("code", out object code);
+                //keyValuePairs.TryGetValue("status", out object progress);
+                if (name.ToString().Equals("Vote", StringComparison.OrdinalIgnoreCase))
                 {
-                    survey.progress = "finish";
+                    Vote vote;
+                    var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
+                    if (sresponse.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
+                        vote = json.ToObject<Vote>();
+                        if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) < 0)
+                        {
+                            vote.progress = "going";
+                        }
+                        else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) > 0)
+                        {
+                            vote.progress = "finish";
+                        }
+                        await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
+                    }
                 }
-                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
-            } else if (name.ToString().Equals("Vote")) {
-                Vote vote;
-                var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
-                if (sresponse.Status == 200)
+            } catch (Exception ex){
+                await _dingDing.SendBotMsg($"ServiceBus,VoteBus()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return;
+            }
+                         
+        }
+        public async Task SurveyBus([ServiceBusTrigger("active-task", "active-survey-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
+        {
+            try {
+                Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                keyValuePairs.TryGetValue("id", out object id);
+                keyValuePairs.TryGetValue("name", out object name);
+                keyValuePairs.TryGetValue("code", out object code);
+                //keyValuePairs.TryGetValue("status", out object progress);
+                if (name.ToString().Equals("Survey", StringComparison.OrdinalIgnoreCase))
                 {
-                    using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
-                    vote = json.ToObject<Vote>();
-                    if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) < 0)
+                    Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
+                    if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) < 0)
                     {
-                        vote.progress = "going";
+                        survey.progress = "going";
                     }
-                    else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) > 0)
+                    else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) > 0)
                     {
-                        vote.progress = "finish";
+                        survey.progress = "finish";
                     }
-                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
+                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
                 }
             }
-                
-
+            catch (Exception ex){
+                await _dingDing.SendBotMsg($"ServiceBus,VoteBus()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return;
+            }                       
         }
     }
 }

+ 3 - 3
TEAMModelFunction/local.settings.json

@@ -3,9 +3,9 @@
   "Values": {
     "AzureWebJobsStorage": "UseDevelopmentStorage=true",
     "FUNCTIONS_WORKER_RUNTIME": "dotnet",
-    "ConnectionBusName": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
+    "ConnectionBusName": "Endpoint=sb://coreiotservicebuscnpro.servicebus.chinacloudapi.cn/;SharedAccessKeyName=TEAMModelOS;SharedAccessKey=llRPBMDJG9w1Nnifj+pGhV0g4H2REcq0PjvX2qqpcOg=",
     "CosmosConnection": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;",
-    "ScanModel": "TEAMModelOS" ,
-    "Database":  "TEAMModelOS" 
+    "ScanModel": "TEAMModelOS",
+    "Database": "TEAMModelOS"
   }  
 }

+ 2 - 2
TEAMModelOS.SDK/Context/Constant/Constants.cs

@@ -22,10 +22,10 @@ namespace TEAMModelOS.SDK.Context.Constant.Common
         /// <summary>
         /// 主题
         /// </summary>
-        public static   string TopicName = "test_topic_ActiveTask";
+        public static readonly string TopicName = "active-task";
         /// <summary>
         /// 订阅
         /// </summary>
-        public static   string SubName = "test_topic_ReciveTask";
+        public static readonly string SubName = "active-recive-task";
     }
 }

+ 2 - 2
TEAMModelOS/ClientApp/src/api/learnActivity.js

@@ -269,7 +269,7 @@ export default {
     /*
      * 查询单个学生作答信息
      */
-    FindOneStudent: function (data) {
-        return post('/api/Exam/findByIdPk', data)
+    FindAllStudent: function (data) {
+        return post('/school/exam/find-summary-record', data)
     }
 }

+ 33 - 63
TEAMModelOS/ClientApp/src/components/learnactivity/GradeList.vue

@@ -14,7 +14,7 @@
             </div>
         </div>
         <div class="content" >
-            <!--<Loading :top="200"  type="1" style="text-align:center"></Loading>-->
+            <Loading :top="200"  type="1" style="text-align:center" v-show="dataLoading"></Loading>
             <div class="left-box">
                 <div class="student-box">
                     <div class="search-box dark-iview-select ">
@@ -226,37 +226,40 @@
             },
             //获取学生测验数据
             getStudentData() {
-
                 this.dataLoading = true
-                let requestData = {}
-                requestData.examCode = this.paperInfo.code
-                requestData.id = this.paperInfo.id
-                if (requestData.examCode !== undefined) {
-                    this.$api.learnActivity.FindSummaryRecord(requestData).then(
+                let requestData = {
+                    id: this.paperInfo.id,
+                    code: this.paperInfo.papers.code,
+                    subjectId: this.paperInfo.papers.subjectId
+                }
+                console.log('学生作答数据')
+                if (requestData.code !== undefined) {
+                    this.$api.learnActivity.FindAllStudent(requestData).then(
                         res => {
                             if (res.error == null) {
-                                let resData = []
-                                let data = []
-                                resData = res.result.data
-                                data = res.result.data.map((item) => {
-                                    return item.code
-                                })
-                                let students = {}
-                                students.studentId = data
-                                students.code = "HBCN"
-                                this.$api.learnActivity.FindStudent(students).then(
-                                    res => {
-                                        if (res.error == null) {
-                                            for (let i = 0; i < res.result.data.length; i++) {
-                                                resData[i].name = res.result.data[i].name
-                                            }
-                                            this.studentData = resData
-                                            this.getStudentInfo(-1)
-                                        }
-                                    }
-                                )
+                                console.log(res)
+                                //let resData = []
+                                //let data = []
+                                //resData = res.result.data
+                                //data = res.result.data.map((item) => {
+                                //    return item.code
+                                //})
+                                //let students = {}
+                                //students.studentId = data
+                                //students.code = "HBCN"
+                                //this.$api.learnActivity.FindStudent(students).then(
+                                //    res => {
+                                //        if (res.error == null) {
+                                //            for (let i = 0; i < res.result.data.length; i++) {
+                                //                resData[i].name = res.result.data[i].name
+                                //            }
+                                //            this.studentData = resData
+                                //            this.getStudentInfo(-1)
+                                //        }
+                                //    }
+                                //)
                                 this.dataLoading = false
-                                this.getPaperInfo()
+                                //this.getPaperInfo()
                             } else {
                                 this.dataLoading = false
                                 this.$Message.error('API ERROR!')
@@ -306,6 +309,7 @@
                         }
                     }
                     this.getStudentDataInfo(this.classList[0].id)
+                    this.getStudentData()
                 } else {
                     this.$Message.warning('班级信息有误!')
                 }
@@ -323,12 +327,6 @@
                                 if (res.error == null) {
                                     console.log(res)
                                     this.studentData = res.classrooms[0].students
-                                    //this.paperData = res.result.data[0]
-                                    //let data = res.result.data[0].item
-                                    //this.paperData.item = []
-                                    //for (let i = 0; i < data.length; i++) {
-                                    //    this.paperData.item.push(data[i])
-                                    //}
                                 } else {
                                     this.$Message.error('API ERROR!')
                                 }
@@ -337,38 +335,10 @@
                     }
                 }
             },
-            //获取学校基本信息
-            getSchoolBaseInfo() {
-                //this.$store.dispatch('schoolBaseInfo/getSchoolBaseData').then(
-                //    (res) => {
-                //        console.log(this.$store.state)
-                //        if (res.code == 2) {
-                //            alert('数据为空!')
-                //        }
-                //    },
-                //    (err) => {
-                //        this.$Message.error('API error!')
-                //    }
-                //)
-                //this.$store.dispatch('schoolBaseInfo/getClassroom').then(
-                //    (res) => {
-                //        if (res.code == 2) {
-                //            alert('数据为空!')
-                //        } else {
-                //           
-
-                //        }
-                //    },
-                //    (err) => {
-                //        this.$Message.error('API error!')
-                //    }
-                //)
-            },
     },
         mounted() {
-            this.getSchoolBaseInfo()
             this.getClassData()
-            //this.getStudentData()
+            this.getStudentData()
             console.log('修改测试内容')
             console.log(this.paperInfo)
         },

+ 18 - 5
TEAMModelOS/ClientApp/src/view/learnactivity/ManageEvaluation.vue

@@ -63,11 +63,12 @@
                         <span>测试科目:</span>
                         <span v-if="examPaperList.length > 0" v-for="(item,index) in examPaperList" :key="index" :class="index == currentSubjectIndex ? 'subject-item subject-item-active':'subject-item'" @click="selectSubject(index)">
                             <!--{{item.period}}
-                            <span style="margin:0px 2px;">·</span>-->
+            <span style="margin:0px 2px;">·</span>-->
                             {{item.subjectName}}
                         </span>
                     </div>
                     <div class="test-paper-detail">
+
                         <vuescroll ref="test-paper-detail" @handle-scroll="checkBackTop">
                             <!--返回顶部-->
                             <div class="back-to-top fl-col-center" title="返回顶部" v-if="showBack" @click="handleBackToTop">
@@ -76,7 +77,7 @@
                             <!--试卷题目信息-->
                             <div v-if="examPaperList.length > 0">
                                 <div v-if="examPaperList[currentSubjectIndex] !== undefined">
-                                    <TestPaper :paper="examPaperList[currentSubjectIndex].papers" style="color:#515a6e;margin-top:-10px;"  :isShowTools="isShowTools"></TestPaper>
+                                    <TestPaper :paper="examPaperList[currentSubjectIndex].papers" style="color:#515a6e;margin-top:-10px;" :isBaseInfo="isShowTools" :isShowTools="isShowTools"></TestPaper>
                                 </div>
                             </div>
                             <EmptyData v-else style="margin-top:60px;"></EmptyData>
@@ -102,17 +103,20 @@
     </div>
 </template>
 <script>
+    import Loading from '@/common/Loading.vue'
     import QuestionList from '@/components/learnactivity/QuestionList.vue'
     import ExamPaperAnalysis from './ExamPaperAnalysis.vue'
     import TestPaper from '@/view/evaluation/index/TestPaper.vue'
     import jsFn from '@/utils/js-fn.js'
     import ClassList from '@/components/learnactivity/ClassList.vue'
+
     export default {
         components: {
             QuestionList,
             ExamPaperAnalysis,
             TestPaper,
-            ClassList
+            ClassList,
+            Loading
         },
         data() {
             return {
@@ -190,7 +194,8 @@
                     }
                 ],
                 showPaperInfo: {},
-                startTime:''
+                startTime: '',
+                isLoadings: true
             }
         },
         methods: {
@@ -488,6 +493,7 @@
             },
             selectEvaluation(index) {
                 console.log(index)
+                this.isLoading =true
                 this.currentSubjectIndex = 0
                 this.currentBraIndex = 0
                 this.avtiveEvaluationIndex = index
@@ -519,15 +525,22 @@
                     id: this.evaluationList[this.avtiveEvaluationIndex].id,
                     code: this.evaluationList[this.avtiveEvaluationIndex].code
                 }
+                this.isLoading = true
                 this.$api.learnActivity.FindExamInfos(requestData).then(
                     res => {
                         if (res.error == null) {
-                         this.getPaperData(res.examInfo[0])
+                            setTimeout(() => {
+                                this.isLoading = false;
+                            }, 1000);
+                            this.getPaperData(res.examInfo[0])
                         } else {
                             this$Message.error('API ERROR!')
+                            this.isLoading = false
                         }
                     },
                     res => {
+                        this.$Message.warning('暂无试卷信息!')
+                        this.isLoading = false
                     })
             },
             async getPaperData(dataInfo) {

+ 7 - 4
TEAMModelOS/Controllers/Exam/ExamController.cs

@@ -95,8 +95,10 @@ namespace TEAMModelOS.Controllers
                     }
                 }
                 request.stuCount = count;
+                long SequenceNumber = await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime);
+                request.sequenceNumber = SequenceNumber;
                 exam = await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(request, new PartitionKey($"{request.code}"));
-                await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime);
+                //await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime);
                 //request.sequenceNumber = SequenceNumber;
             }
             else
@@ -574,15 +576,16 @@ namespace TEAMModelOS.Controllers
             //var (id, school) = HttpContext.GetAuthTokenInfo();
             try {
                 if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
-                if (!requert.TryGetProperty("code", out JsonElement school_code)) return BadRequest();
+                //if (!requert.TryGetProperty("code", out JsonElement school_code)) return BadRequest();
                 if (!requert.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
+                if (!requert.TryGetProperty("school", out JsonElement school_code)) return BadRequest();
                 // 如果只有学生id则返回学生参加过的考试 只返回相关摘要信息
                 var client = _azureCosmos.GetCosmosClient();
-                string code = school_code.ToString().Substring(5);
+                //string code = school_code.ToString().Substring(5);
                 //ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{school_code}"));
                 List<object> examClassResults = new List<object>();                   
                 await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select c.id, c.code,c.info,c.studentIds,c.studentAnswers from c where c.examId = '{id}' and c.subjectId = '{subjectId}'", 
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{school_code}") }))
                     {
                         using var json = await JsonDocument.ParseAsync(item.ContentStream);
                         if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)

+ 1 - 1
TEAMModelOS/Controllers/School/ClassRoomController.cs

@@ -47,7 +47,7 @@ namespace TEAMModelOS.Controllers
             classroom = room.ToObject<Classroom>();
             var client = _azureCosmos.GetCosmosClient();
             classroom.ttl = -1;
-            classroom.pk = typeof(Classroom).Name;
+            classroom.pk = "Class";
             classroom.code = "Class-" + school_code.ToString();
             //students = await _azureCosmos.FindByDict<Student>(new Dictionary<string, object>() { { "classroomCode", classroom.id } });
             if (option.ToString().Equals("insert"))

+ 4 - 0
TEAMModelOS/Controllers/Task/SurveyController.cs

@@ -56,6 +56,7 @@ namespace TEAMModelOS.Controllers
             Survey survey;
             request.survey.ttl = -1;
             request.survey.pk = typeof(Survey).Name;
+            request.survey.school = request.survey.code;
             request.survey.code = typeof(Survey).Name + "-" + request.survey.code;
             request.survey.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             /*if (request.survey.publishModel.Equals("0"))
@@ -76,6 +77,9 @@ namespace TEAMModelOS.Controllers
                 request.survey.id = Guid.NewGuid().ToString();
                 //request.survey.status = 100;
                 request.survey.progress = "pending";
+                //await _serviceBus.GetServiceBusClient().cancelMessage(Constants.TopicName, info.sequenceNumber);
+                long SequenceNumber = await _serviceBus.GetServiceBusClient().SendLeamMessage<Survey>(Constants.TopicName, request.survey.id, request.survey.code, request.survey.startTime);
+                request.survey.sequenceNumber = SequenceNumber;
                 survey = await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(request.survey, new PartitionKey($"{request.survey.code}"));
                 /*if (request.survey.scope.Equals("school"))
                 {

+ 1 - 0
TEAMModelOS/Controllers/Task/VoteController.cs

@@ -79,6 +79,7 @@ namespace TEAMModelOS.Controllers.Learn
             Vote vote = new Vote();
             request.vote.ttl = -1;
             request.vote.pk = typeof(Vote).Name;
+            request.vote.school = request.vote.code;
             request.vote.code = typeof(Vote).Name + "-" + request.vote.code;
             request.vote.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             /*if (request.vote.publishModel.Equals("0"))