CrazyIter_Bin 4 éve
szülő
commit
e8513e44f3

+ 12 - 5
TEAMModelFunction/TriggerSurvey.cs

@@ -133,8 +133,10 @@ namespace TEAMModelFunction
                             };
                             await _azureStorage.Save<ChangeRecord>(changeRecord);
                         }
+                        await _dingDing.SendBotMsg($"问卷调查{tdata.id}将于:{tdata.etime}完成并结算!", GroupNames.成都开发測試群組);
                         break;
                     case "finish":
+                        await _dingDing.SendBotMsg($"问卷调查{tdata.id}开始结算{tdata.etime}!", GroupNames.成都开发測試群組);
                         var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Survey:Record:{survey.id}");
                         List<dynamic> recs = new List<dynamic>();
                         foreach (var rcd in records)
@@ -147,7 +149,7 @@ namespace TEAMModelFunction
                         await _azureStorage.UploadFileByContainer(survey.owner, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
                         //结算每道题的答题情况
                         var ContainerClient =  _azureStorage.GetBlobContainerClient(survey.owner);
-                           
+                        List<Task<string>> tasks = new List<Task<string>>();
                         //获取
                         try {
                             List<string> items = await ContainerClient.List($"survey/{survey.id}/urecord");
@@ -198,8 +200,9 @@ namespace TEAMModelFunction
                                         }
                                     }
                                 }
-                                await _azureStorage.UploadFileByContainer(survey.owner, question.ToJsonString(), "survey", url);
+                                tasks.Add(  _azureStorage.UploadFileByContainer(survey.owner, question.ToJsonString(), "survey", url));
                             }
+                            await Task.WhenAll(tasks);
                         } catch (Exception ex) {
                             await _dingDing.SendBotMsg($"问卷调查问题结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
                         }
@@ -208,7 +211,12 @@ namespace TEAMModelFunction
                             survey.recordUrl = $"/survey/{survey.id}/record.json";
                             await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Survey>(survey, survey.id, new Azure.Cosmos.PartitionKey(survey.code));
                         }
-                        // await Task.WhenAll(tasks);
+                        else {
+                            _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
+                            _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
+                            break;
+                        }
+                        
                         //更新结束状态
                         data.progress = "finish";
                         if (survey.scope == "school")
@@ -219,8 +227,7 @@ namespace TEAMModelFunction
                         {
                             await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
                         }
-                        _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
-                        _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
+                        
                         break;
                 }
             }

+ 7 - 4
TEAMModelFunction/TriggerVote.cs

@@ -135,8 +135,10 @@ namespace TEAMModelFunction
                             };
                             await _azureStorage.Save<ChangeRecord>(changeRecord);
                         }
+                        await _dingDing.SendBotMsg($"投票活动{tdata.id}将于:{tdata.etime}完成并结算!", GroupNames.成都开发測試群組);
                         break;
                     case "finish":
+                        await _dingDing.SendBotMsg($"投票活动{tdata.id}开始结算{tdata.etime}!", GroupNames.成都开发測試群組);
                         //获取投票活动的所有投票记录
                         var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Vote:Record:{vote.id}");
                         //获取投票活动的选项及投票数
@@ -172,9 +174,11 @@ namespace TEAMModelFunction
                             vote.recordUrl = url;
                             await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Vote>(vote, vote.id, new Azure.Cosmos.PartitionKey(vote.code));
                         }
-                        else { 
+                        else {
                             //异动,且已经有结算记录则不必再继续。
-                            //break; 
+                            _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
+                            _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
+                            break; 
                         }
                         await Task.WhenAll(tasks);
                         data.progress = "finish";
@@ -187,8 +191,7 @@ namespace TEAMModelFunction
                         {
                             await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
                         }
-                        _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
-                        _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
+                        
                         break;
                 }
             }

+ 1 - 1
TEAMModelOS/Controllers/Teacher/TeacherCommonController.cs

@@ -71,7 +71,7 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("tch-find-activity")]
-        [AuthToken(Roles = "teacher")]
+        //[AuthToken(Roles = "teacher")]
         public async Task<IActionResult> FindTch(JsonElement requert)
         {
             var (id, _, _, school) = HttpContext.GetAuthTokenInfo();

+ 2 - 2
TEAMModelOS/Services/Common/ActivityStudentService.cs

@@ -331,10 +331,10 @@ namespace TEAMModelOS.Services.Common
             string tgSql = "";
             if (!string.IsNullOrWhiteSpace(joinSqlClasses))
             {
-                tgSql = $"and ({andSqlTmdids} or  {andSqlClasses } )";
+                tgSql = $" and ({andSqlTmdids} or  {andSqlClasses } )";
             }
             else {
-                tgSql = $"and {andSqlTmdids}";
+                tgSql = $" and {andSqlTmdids}";
             }
             //科目
             string joinSqlSubjects = "";

+ 104 - 97
TEAMModelOS/Services/Common/ActivityTeacherService.cs

@@ -35,51 +35,48 @@ namespace TEAMModelOS.Services.Common
         /// <returns></returns>
         public static async Task<(List<ActivityData> datas, string continuationToken)> FindAsTch(JsonElement requert, string school, AzureCosmosFactory _azureCosmos, AzureRedisFactory _azureRedis)
         {
+
+            if (string.IsNullOrWhiteSpace(school))
+            {
+                school = requert.GetProperty("school").GetString();
+            }
             //开始时间,默认最近三十天
             var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
-
-
-            if (!requert.TryGetProperty("stime", out JsonElement stime))
+            if (requert.TryGetProperty("stime", out JsonElement stime))
             {
-                if (stime.TryGetInt64(out long data))
+                if (!stime.ValueKind.Equals(JsonValueKind.Undefined) && !stime.ValueKind.Equals(JsonValueKind.Null) && stime.TryGetInt64(out long data))
                 {
                     stimestamp = data;
                 }
             }
-
+            string stimesql = $" c.startTime >= {stimestamp}  ";
+            //默认当前时间,  未开始的不能查询
+            var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            string etimesql = $" and c.startTime <= {etimestamp}   ";
             var progresssql = "";
-            if (!requert.TryGetProperty("progress", out JsonElement progress))
+            if (requert.TryGetProperty("progress", out JsonElement progress))
             {
 
                 if (!progress.ValueKind.Equals(JsonValueKind.Undefined) && !progress.ValueKind.Equals(JsonValueKind.Null) && progress.ValueKind.Equals(JsonValueKind.String))
                 {
-                    progresssql = $" and c.progress='{progresssql}' ";
+                    progresssql = $" and c.progress='{progress}' ";
                 }
             }
             var typesql = "";
-            if (!requert.TryGetProperty("type", out JsonElement type))
+            if (requert.TryGetProperty("type", out JsonElement type))
             {
 
                 if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
                 {
-                    typesql = $" and c.type='{typesql}' ";
+                    typesql = $" and c.type='{type}' ";
                 }
             }
-            //默认当前时间,  未开始的不能查询
-            var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-            //if (!requert.TryGetProperty("etime", out JsonElement etime))
-            //{
-            //    if (etime.TryGetInt64(out long data))
-            //    {
-            //        etimestamp = data;
-            //    };
-            //};
-            string continuationToken = null;
+            string continuationTokenSchool = null;
             //默认不指定返回大小
             int? topcout = null;
-            if (!requert.TryGetProperty("count", out JsonElement jcount))
+            if (requert.TryGetProperty("count", out JsonElement jcount))
             {
-                if (jcount.TryGetInt32(out int data))
+                if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
                 {
                     topcout = data;
                 }
@@ -91,28 +88,44 @@ namespace TEAMModelOS.Services.Common
                 iscontinuation = true;
             }
             //如果指定了返回大小
-            if (!requert.TryGetProperty("continuationToken", out JsonElement continuation))
+            if (requert.TryGetProperty("continuationTokenSchool", out JsonElement continuationSchool))
             {
-                //指定了cancellationToken 表示需要进行分页
-                if (!continuation.ValueKind.Equals(JsonValueKind.Null) && continuation.ValueKind.Equals(JsonValueKind.String))
+                //指定了cancellationToken continuationSchool
+                if (!continuationSchool.ValueKind.Equals(JsonValueKind.Null) && continuationSchool.ValueKind.Equals(JsonValueKind.String))
                 {
-                    continuationToken = continuation.GetString();
-                    
+                    continuationTokenSchool = continuationSchool.GetString();
+
                 }
             }
             //班级
+            string joinSqlClasses = "";
+            string andSqlClasses = "";
             List<string> classes = null;
-            if (!requert.TryGetProperty("classes", out JsonElement jclasses))
+            if (requert.TryGetProperty("classes", out JsonElement jclasses))
             {
                 if (jclasses.ValueKind is JsonValueKind.Array)
                 {
                     classes = jclasses.ToObject<List<string>>();
+                    if (classes.IsNotEmpty())
+                    {
+                        joinSqlClasses = " join A1 in c.classes ";
+                        List<string> sqlList = new List<string>();
+                        classes.ForEach(x => { sqlList.Add($" '{x}' "); });
+                        string sql = string.Join(" , ", sqlList);
+                        andSqlClasses = $"   A1 in ({sql}) ";
+                    }
                 }
             }
-            //班级
+            string tgSql = "";
+            if (!string.IsNullOrWhiteSpace(joinSqlClasses))
+            {
+                tgSql = $" and    {andSqlClasses }  ";
+            }
+            
+            //科目
             string joinSqlSubjects = "";
             string andSqlSubjects = "";
-            if (!requert.TryGetProperty("subjects", out JsonElement jsubjects))
+            if (requert.TryGetProperty("subjects", out JsonElement jsubjects))
             {
                 if (jsubjects.ValueKind is JsonValueKind.Array)
                 {
@@ -123,45 +136,39 @@ namespace TEAMModelOS.Services.Common
                         List<string> sqlList = new List<string>();
                         subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
                         string sql = string.Join(" , ", sqlList);
-                        andSqlSubjects = $" and A2 in ('{sql}') ";
+                        andSqlSubjects = $" and A2 in ({sql}) ";
                     }
                 }
             }
-            string query = null;
-            if (classes.IsNotEmpty())
-            {
-                List<string> sqlList = new List<string>();
-                classes.ForEach(x => { sqlList.Add($" '{x}' "); });
-                string sql = string.Join(" , ", sqlList);
-                query = $" SELECT distinct  value c   FROM c   JOIN A0 IN c.classes join A1 in c.tmdids {joinSqlSubjects}  where c.startTime >= {stimestamp} and c.startTime <= {etimestamp} and  c.pk='Activity' {typesql} {progresssql}  {andSqlSubjects}  and   (A0 in('{sql}') or A1 ='{school} ') ";
-            }
-            else
-            {
-                query = $" SELECT distinct  value c   FROM c    join A1 in c.tmdids  {joinSqlSubjects}  where c.startTime >= {stimestamp} and c.startTime <= {etimestamp}  and c.pk='Activity' {typesql} {progresssql}  {andSqlSubjects}  and   A1 ='{school}' ";
-            }
 
             List<ActivityData> datas = new List<ActivityData>();
             var client = _azureCosmos.GetCosmosClient();
+
             //班主任 ,任课教师只需要查询两种校园活动 和班级活动 ,  不查询私人教室创建的活动。  
-            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(query, continuationToken: continuationToken, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-{school}") }))
+            if (!string.IsNullOrWhiteSpace(school))
             {
-                using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                string querySchool = $" SELECT distinct  value c   FROM c {joinSqlClasses} {joinSqlSubjects}  where {stimesql}  {etimesql} and c.pk='Activity' {progresssql}  {typesql}  {andSqlSubjects}  {tgSql}";
+                //查询数据归属学校的
+                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(querySchool, continuationToken: continuationTokenSchool, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-{school}") }))
                 {
-                    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)
                     {
-                        datas.Add(obj.ToObject<ActivityData>());
-                    }
-                    //如果需要分页则跳出
-                    if (iscontinuation)
-                    {
-                        continuationToken = item.GetContinuationToken();
-                        break;
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            datas.Add(obj.ToObject<ActivityData>());
+                        }
+                        //如果需要分页则跳出
+                        if (iscontinuation)
+                        {
+                            continuationTokenSchool = item.GetContinuationToken();
+                            break;
+                        }
                     }
                 }
             }
             bool tips = false;
-            if (!requert.TryGetProperty("tips", out JsonElement jtips))
+            if (requert.TryGetProperty("tips", out JsonElement jtips))
             {
                 if (!jtips.ValueKind.Equals(JsonValueKind.Null) && !jtips.ValueKind.Equals(JsonValueKind.True))
                 {
@@ -170,50 +177,50 @@ namespace TEAMModelOS.Services.Common
             }
             if (tips)
             {
-                DoActivityTips activityTips;
-                dynamic res = default;
-                foreach (var data in datas)
-                {
-                    //处理参与度,
-                    switch (data.type)
-                    {
-                        //投票
-                        case "vote":
-                            activityTips = DoVoteTips;
-                            //msgid, //0不能投票,1可以投票,2不在时间范围内,3周期内的可投票数不足
-                            //voteCount 可用投票数
-                            res = activityTips(data, _azureCosmos, school, _azureRedis);
-                            break;
-                        //问卷
-                        case "survey":
-                            //msgid 0 已作答, 1未作答,2,未完成
-                            activityTips = DoSurveyTips;
-                            res = activityTips(data, _azureCosmos, school, _azureRedis);
-                            break;
-                        //评测
-                        case "exam":
-                            //msgid 0 已作答, 1未作答,2,未完成, 用时间控制 相关发布状态,并且展示相应的结果
-                            activityTips = DoExamTips;
-                            res = activityTips(data, _azureCosmos, school, _azureRedis);
-                            break;
-                        //学习活动
-                        case "learn":
-                            //msgid 0 已完成, 1未开始,2,未完成
-                            activityTips = DoLearnTips;
-                            res = activityTips(data, _azureCosmos, school, _azureRedis);
-                            break;
-                        //作业活动
-                        case "homework":
-                            //msgid 0 已作答, 1未作答,2,未完成,3已批改,且有错误,4已批改,已完成
-                            //index:0,1,5 错误题序
-                            activityTips = DoHomeworkTips;
-                            res = activityTips(data, _azureCosmos, school, _azureRedis);
-                            break;
-                        default: break;
-                    }
-                }
+                //DoActivityTips activityTips;
+                // dynamic res = default;
+                //foreach (var data in datas)
+                //{
+                //    //处理参与度,
+                //    switch (data.type)
+                //    {
+                //        //投票
+                //        case "vote":
+                //            activityTips = DoVoteTips;
+                //            //msgid, //0不能投票,1可以投票,2不在时间范围内,3周期内的可投票数不足
+                //            //voteCount 可用投票数
+                //            res = activityTips(data, _azureCosmos, school, _azureRedis);
+                //            break;
+                //        //问卷
+                //        case "survey":
+                //            //msgid 0 已作答, 1未作答,2,未完成
+                //            activityTips = DoSurveyTips;
+                //            res = activityTips(data, _azureCosmos, school, _azureRedis);
+                //            break;
+                //        //评测
+                //        case "exam":
+                //            //msgid 0 已作答, 1未作答,2,未完成, 用时间控制 相关发布状态,并且展示相应的结果
+                //            activityTips = DoExamTips;
+                //            res = activityTips(data, _azureCosmos, school, _azureRedis);
+                //            break;
+                //        //学习活动
+                //        case "learn":
+                //            //msgid 0 已完成, 1未开始,2,未完成
+                //            activityTips = DoLearnTips;
+                //            res = activityTips(data, _azureCosmos, school, _azureRedis);
+                //            break;
+                //        //作业活动
+                //        case "homework":
+                //            //msgid 0 已作答, 1未作答,2,未完成,3已批改,且有错误,4已批改,已完成
+                //            //index:0,1,5 错误题序
+                //            activityTips = DoHomeworkTips;
+                //            res = activityTips(data, _azureCosmos, school, _azureRedis);
+                //            break;
+                //        default: break;
+                //    }
+                //}
             }
-            return (datas, continuationToken);
+            return (datas, continuationTokenSchool);
         }
 
         private async static Task<dynamic> DoVoteTips(ActivityData commonData, AzureCosmosFactory _azureCosmos, string userid, AzureRedisFactory _azureRedis)