فهرست منبع

调整学生活动列表数据写入学生Student表。

CrazyIter_Bin 4 سال پیش
والد
کامیت
3ea4ca613e

+ 11 - 6
TEAMModelFunction/TriggerExam.cs

@@ -128,7 +128,7 @@ namespace TEAMModelFunction
                         };
                         };
                         await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
                         await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
                     }
                     }
-                    (List<string> tmdids, List<Students> students) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
+                    (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
                     List<StuActivity> stuActivities = new List<StuActivity>();
                     List<StuActivity> stuActivities = new List<StuActivity>();
                     List<StuActivity> tmdActivities = new List<StuActivity>();
                     List<StuActivity> tmdActivities = new List<StuActivity>();
                     if (tmdids.IsNotEmpty())
                     if (tmdids.IsNotEmpty())
@@ -152,14 +152,14 @@ namespace TEAMModelFunction
                             });
                             });
                         });
                         });
                     }
                     }
-                    if (students.IsNotEmpty())
+                    if (studentss.IsNotEmpty())
                     {
                     {
-                        students.ForEach(x => {
+                        studentss.ForEach(x => {
                             stuActivities.Add(new StuActivity
                             stuActivities.Add(new StuActivity
                             {
                             {
                                 pk = "Activity",
                                 pk = "Activity",
                                 id = info.id,
                                 id = info.id,
-                                code = $"Activity-{info.school}-{x}",
+                                code = $"Activity-{info.school}-{x.id}",
                                 type = "survey",
                                 type = "survey",
                                 name = info.name,
                                 name = info.name,
                                 startTime = info.startTime,
                                 startTime = info.startTime,
@@ -362,9 +362,14 @@ namespace TEAMModelFunction
                     {
                     {
                         allScore += simple.point.Sum();
                         allScore += simple.point.Sum();
                     }
                     }
-                    info.sRate = allScore > 0 ? Math.Round(ascore / allScore * 100,2) : 0;
+                    double  NewsRate= allScore > 0 ? Math.Round(ascore / allScore * 100,2) : 0;
                     info.lostStu = losStu;
                     info.lostStu = losStu;
-                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
+                    if (info.sRate != NewsRate) {
+                        info.sRate = NewsRate;
+                        await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
+                    }
+                   
+                  
                     //ActivityData data;
                     //ActivityData data;
                     if (info.scope == "school")
                     if (info.scope == "school")
                     {
                     {

+ 3 - 1
TEAMModelFunction/TriggerSurvey.cs

@@ -123,6 +123,7 @@ namespace TEAMModelFunction
                         }
                         }
 
 
                         (List<string> tmdids,List<Students> students) =   await TriggerStuActivity. GetStuList(client, survey.classes, survey.school);
                         (List<string> tmdids,List<Students> students) =   await TriggerStuActivity. GetStuList(client, survey.classes, survey.school);
+                        await _dingDing.SendBotMsg($"问卷调查{tdata.id}写入学生表作为活动列表!", GroupNames.成都开发測試群組);
                         List<StuActivity> stuActivities = new List<StuActivity>();
                         List<StuActivity> stuActivities = new List<StuActivity>();
                         List<StuActivity> tmdActivities = new List<StuActivity>();
                         List<StuActivity> tmdActivities = new List<StuActivity>();
                         if (tmdids.IsNotEmpty()) {
                         if (tmdids.IsNotEmpty()) {
@@ -150,7 +151,7 @@ namespace TEAMModelFunction
                                 stuActivities.Add(new StuActivity {
                                 stuActivities.Add(new StuActivity {
                                     pk = "Activity",
                                     pk = "Activity",
                                     id = survey.id,
                                     id = survey.id,
-                                    code = $"Activity-{survey.school}-{x}",
+                                    code = $"Activity-{survey.school}-{x.id}",
                                     type = "survey",
                                     type = "survey",
                                     name = survey.name,
                                     name = survey.name,
                                     startTime = survey.startTime,
                                     startTime = survey.startTime,
@@ -164,6 +165,7 @@ namespace TEAMModelFunction
                             });
                             });
                         }
                         }
                         await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
                         await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
+                        await _dingDing.SendBotMsg($"问卷调查{tdata.id}写入完成!", GroupNames.成都开发測試群組);
                         var messageSurveyEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = tdata.code }.ToJsonString());
                         var messageSurveyEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = tdata.code }.ToJsonString());
                         messageSurveyEnd.ApplicationProperties.Add("name", "Survey");
                         messageSurveyEnd.ApplicationProperties.Add("name", "Survey");
                         if (changeRecords.Count > 0)
                         if (changeRecords.Count > 0)

+ 1 - 1
TEAMModelFunction/TriggerVote.cs

@@ -160,7 +160,7 @@ namespace TEAMModelFunction
                                 {
                                 {
                                     pk = "Activity",
                                     pk = "Activity",
                                     id = vote.id,
                                     id = vote.id,
-                                    code = $"Activity-{vote.school}-{x}",
+                                    code = $"Activity-{vote.school}-{x.id}",
                                     type = "survey",
                                     type = "survey",
                                     name = vote.name,
                                     name = vote.name,
                                     startTime = vote.startTime,
                                     startTime = vote.startTime,

+ 52 - 49
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -27,6 +27,7 @@ using TEAMModelOS.SDK.Models.Cosmos;
 using Azure.Messaging.ServiceBus;
 using Azure.Messaging.ServiceBus;
 using Azure.Storage.Sas;
 using Azure.Storage.Sas;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelFunction;
 
 
 namespace TEAMModelOS.Controllers
 namespace TEAMModelOS.Controllers
 {
 {
@@ -502,63 +503,65 @@ namespace TEAMModelOS.Controllers
         //[AuthToken(Roles = "teacher,student")]
         //[AuthToken(Roles = "teacher,student")]
         public async Task<IActionResult> StuList(JsonElement request)
         public async Task<IActionResult> StuList(JsonElement request)
         {
         {
-            List<string> classes = new List<string>();
-            if (request.TryGetProperty("classes", out JsonElement cs)) {
-                classes = cs.ToObject<List<string>>();
-            }
-            if (request.TryGetProperty("school", out JsonElement school))
+            if (!request.TryGetProperty("id", out JsonElement id))
             {
             {
-                
+                return BadRequest();
             }
             }
-            var client = _azureCosmos.GetCosmosClient();
-            List<Students> studentss = new List<Students>();
-            List<string> sqlList = new List<string>();
-            classes.ForEach(x => { sqlList.Add($" '{x}' "); });
-            string sql = string.Join(" , ", sqlList);
-            List<StuList> schList = new List<StuList>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
-                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
+            //活动分区
+            if (!request.TryGetProperty("code", out JsonElement code))
             {
             {
-                schList.Add(item);
+                return BadRequest();
             }
             }
-            List<StuList> tchLists = new List<StuList>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
-                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
+            var client = _azureCosmos.GetCosmosClient();
+            Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>($"{id}", new Azure.Cosmos.PartitionKey($"{code}"));
+           
+            (List<string> tmdids, List<Students> students) = await TriggerStuActivity.GetStuList(client, survey.classes, survey.school);
+            List<StuActivity> stuActivities = new List<StuActivity>();
+            List<StuActivity> tmdActivities = new List<StuActivity>();
+            if (tmdids.IsNotEmpty())
             {
             {
-                tchLists.Add(item);
+                tmdids.ForEach(x => {
+                    tmdActivities.Add(new StuActivity
+                    {
+                        pk = "Activity",
+                        id = survey.id,
+                        code = $"Activity-{x}",
+                        type = "survey",
+                        name = survey.name,
+                        startTime = survey.startTime,
+                        endTime = survey.endTime,
+                        scode = survey.code,
+                        scope = survey.scope,
+                        school = survey.school,
+                        creatorId = survey.creatorId,
+                        subjects = new List<string> { "" }
+
+                    });
+                });
             }
             }
-            List<Student> students = new List<Student>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
-                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
+            if (students.IsNotEmpty())
             {
             {
-                students.Add(item);
+                students.ForEach(x => {
+                    stuActivities.Add(new StuActivity
+                    {
+                        pk = "Activity",
+                        id = survey.id,
+                        code = $"Activity-{survey.school}-{x.id}",
+                        type = "survey",
+                        name = survey.name,
+                        startTime = survey.startTime,
+                        endTime = survey.endTime,
+                        scode = survey.code,
+                        scope = survey.scope,
+                        school = survey.school,
+                        creatorId = survey.creatorId,
+                        subjects = new List<string> { "" }
+                    });
+                });
             }
             }
-            List<string> tmdids = new List<string>();
-            schList.ForEach(x => {
-                if (x.students.IsNotEmpty())
-                {
-                    studentss.AddRange(x.students);
-                }
-                if (x.tmids.IsNotEmpty())
-                {
-                    tmdids.AddRange(x.tmids);
-                }
-            });
-            tchLists.ForEach(x =>
-            {
-                if (x.students.IsNotEmpty())
-                {
-                    studentss.AddRange(x.students);
-                }
-                if (x.tmids.IsNotEmpty())
-                {
-                    tmdids.AddRange(x.tmids);
-                }
-            });
-            students.ForEach(x => {
-                studentss.Add(new Students { id = x.id, code = x.code });
-            });
-            return Ok(new { tmdids, studentss });
+            await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
+             
+            return Ok(new { tmdids });
         }
         }
     }
     }
     public class QuestionRecord
     public class QuestionRecord

+ 96 - 0
TEAMModelOS/Controllers/Common/TriggerStuActivity.cs

@@ -0,0 +1,96 @@
+using Azure;
+using Azure.Cosmos;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+
+namespace TEAMModelFunction
+{
+    public class TriggerStuActivity
+    {
+
+        public static async Task<string> SaveStuActivity(CosmosClient client,List<StuActivity> stuActivities,List<StuActivity> tmdActivities) {
+            
+            if (stuActivities.IsNotEmpty()) {
+                foreach (var x in stuActivities) {
+                   await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(x,new PartitionKey (x.code));
+                }
+
+
+            }
+            if (tmdActivities.IsNotEmpty())
+            {
+                foreach (var x in tmdActivities)
+                {
+                    await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(x, new PartitionKey(x.code));
+                }
+
+            }
+            return ""; 
+        }
+         
+        public  static async Task<(List<string> tmdids,List<Students> studentss)> GetStuList(  CosmosClient client, List<string> classes,string  school) {
+
+            List<Students> studentss = new List<Students>();
+            List<string> sqlList = new List<string>();
+            classes.ForEach(x => { sqlList.Add($" '{x}' "); });
+            string sql = string.Join(" , ", sqlList);
+            List<StuList> schList = new List<StuList>();
+            List<Student> students = new List<Student>();
+            if (!string.IsNullOrEmpty(school)) {
+                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
+                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
+                {
+                    schList.Add(item);
+                }
+
+
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
+                {
+                    students.Add(item);
+                }
+            }
+            List<StuList> tchLists = new List<StuList>();
+            await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
+                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
+            {
+                tchLists.Add(item);
+            }
+            List<string> tmdids = new List<string>();
+            schList.ForEach(x => { 
+                if (x.students.IsNotEmpty()) 
+                { 
+                    studentss.AddRange(x.students);
+                }
+                if (x.tmids.IsNotEmpty())
+                {
+                    tmdids.AddRange(x.tmids);
+                }
+            });
+            tchLists.ForEach(x => 
+            {
+                if (x.students.IsNotEmpty()) { 
+                    studentss.AddRange(x.students);
+                }
+                if (x.tmids.IsNotEmpty())
+                {
+                    tmdids.AddRange(x.tmids);
+                }
+            });
+            students.ForEach(x => {
+                studentss.Add(new Students { id = x.id, code = x.code });
+            });
+            return (tmdids,studentss);
+        }
+    }
+}