Forráskód Böngészése

update 课例条件筛选。

CrazyIter_Bin 3 éve
szülő
commit
40b2c9048b

+ 9 - 3
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1173,7 +1173,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     List<GroupListDto> groupLists = groups?.FindAll(x => !string.IsNullOrEmpty(x.periodId) && x.year > 0 && !string.IsNullOrEmpty(x.school));
                                     if (groupLists.IsNotEmpty() && !string.IsNullOrWhiteSpace(lessonRecord.periodId))
                                     {
-                                        try {
+                                        try
+                                        {
                                             var gplist = groupLists.FindAll(x => lessonRecord.groupIds.Contains(x.id));
                                             School schoolObj = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(lessonRecord.school, new PartitionKey("Base"));
                                             //年级算法
@@ -1215,8 +1216,13 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                                     grades.Add($"{grade}");
                                                 }
                                             }
-                                        } catch (CosmosException ex) when (ex.Status == 404) { 
-                                            
+                                        }
+                                        catch (CosmosException ex) when (ex.Status == 404)
+                                        {
+
+                                        }
+                                        catch (Exception ex) {
+                                            await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-处理课堂记录的-年级处理异常{ex.Message}\n{ex.StackTrace}\n{lessonRecord.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                                         }
                                     }
                                     lessonRecord.grade= grades.ToList();

+ 43 - 4
TEAMModelOS/Controllers/Both/LessonRecordController.cs

@@ -367,7 +367,7 @@ namespace TEAMModelOS.Controllers
             }
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
             StringBuilder sql = new StringBuilder();
-            sql.Append("select value(c) from c ");
+            sql.Append("select distinct value(c) from c ");
             int pageCount = 10;
             Dictionary<string, object> dict = GetLessonCond(request);
             if (request.TryGetProperty("pageCount", out JsonElement _pageCount))
@@ -398,6 +398,7 @@ namespace TEAMModelOS.Controllers
             string tbname = "";
             string code = "";
             string school = null;
+            List<string> autoTch = new List<string>();
             if (_scope.GetString().Equals("school"))
             {
                 if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
@@ -406,6 +407,28 @@ namespace TEAMModelOS.Controllers
                     code = $"LessonRecord-{_school}";
                     tbname = "School";
                     school = $"{_school}";
+                    List<string> ids = new List<string>();
+                    //只查询某个老师的课例
+                    if (request.TryGetProperty("tmdid", out JsonElement tmdid) && !string.IsNullOrWhiteSpace($"{tmdid}"))
+                    {
+                        ids.Add($"{tmdid}");
+                    }
+                    else {
+                        string sqltch = "select distinct value(c.id) from c ";
+                        await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
+                            .GetItemQueryIterator<string>(queryText: sqltch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{_school}") }))
+                        {
+                            ids.Add(item);
+                        }
+                    }
+                    if (ids.Any()) {
+                        string sqlTechbase = $"select distinct value(c.id) from c  where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})  and (array_contains(c.lessonShow,'student') or array_contains(c.lessonShow,'all')) ";
+                        await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
+                           .GetItemQueryIterator<string>(queryText: sqlTechbase, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
+                        {
+                            autoTch.Add(item);
+                        }
+                    }
                 }
                 else
                 {
@@ -419,6 +442,17 @@ namespace TEAMModelOS.Controllers
                 {
                     code = $"LessonRecord-{_tmdid}";
                     tbname = "Teacher";
+                    List<string> ids = new List<string>();
+                    ids.Add($"{_tmdid}");
+                    if (ids.Any())
+                    {
+                        string sqlTechbase = $"select distinct value(c.id) from c  where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})  and (array_contains(c.lessonShow,'student') or array_contains(c.lessonShow,'all')) ";
+                        await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
+                           .GetItemQueryIterator<string>(queryText: sqlTechbase, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
+                        {
+                            autoTch.Add(item);
+                        }
+                    }
                 }
                 else
                 {
@@ -433,9 +467,14 @@ namespace TEAMModelOS.Controllers
             try
             {
                 string sqlShow = "";
-                //if (roles.Count == 1 && roles.Contains("student") ) {
-                //    sqlShow = " and (array_contains(c.show,'student') or array_contains(c.show,'all')) ";
-                //}
+                if (roles.Count == 1 && roles.Contains("student"))
+                {
+                    string autoSql = "";
+                    if (autoTch.Any()) {
+                        autoSql = $" or c.tmdid in ({string.Join(",",autoTch.Select(x=>$"'{x}'"))})";
+                    }
+                    sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all')  {autoSql} ) ";
+                }
                 cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow} and  ");
                 await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
                    .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,