Bladeren bron

update .优质课例,推荐课例,今日课例

CrazyIter_Bin 3 jaren geleden
bovenliggende
commit
6dfd257a99

+ 5 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/LessonRecord.cs

@@ -71,7 +71,7 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         public int discuss { get; set; }
         /// <summary>
-        ///选填  科技互动次数,大于1则是优课,苏格拉底获取
+        ///选填  科技互动次数, 
         /// </summary>
         public int techCount { get; set; }
         /// <summary>
@@ -113,6 +113,10 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         public List<int> tech { get; set; } = new List<int>();
         public int status { get; set; } = 0;
+        /// <summary>
+        /// 专家好课,默认0, 1 是好课
+        /// </summary>
+        public int excellent { get; set; } = 0;
     }
 
     public class LessonActivityInfo

+ 156 - 13
TEAMModelOS/Controllers/Both/LessonRecordController.cs

@@ -12,6 +12,7 @@ using System.Linq;
 using System.Net;
 using System.Text;
 using System.Text.Json;
+using System.Text.Json.Nodes;
 using System.Threading.Tasks;
 using TEAMModelOS.Filter;
 using TEAMModelOS.Models;
@@ -274,15 +275,13 @@ namespace TEAMModelOS.Controllers
             }
             return Ok(new { count=count });
         }
-
-
         /// <summary>
         /// 获取开课记录
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-       // [AuthToken(Roles = "teacher,admin")]
+        // [AuthToken(Roles = "teacher,admin")]
         [HttpPost("get-lesson-record")]
         [Authorize(Roles = "IES")]
         public async Task<IActionResult> GetLessonRecord(JsonElement request)
@@ -319,7 +318,7 @@ namespace TEAMModelOS.Controllers
             AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
             string tbname = "";
             string code = "";
-            if (_scope.GetString().Equals("school") )
+            if (_scope.GetString().Equals("school"))
             {
                 if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
                 if (!string.IsNullOrEmpty($"{_school}"))
@@ -340,7 +339,8 @@ namespace TEAMModelOS.Controllers
                     code = $"LessonRecord-{_tmdid}";
                     tbname = "Teacher";
                 }
-                else {
+                else
+                {
                     return BadRequest();
                 }
             }
@@ -349,7 +349,8 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
             List<LessonRecord> lessonRecords = new List<LessonRecord>();
-            try {
+            try
+            {
                 cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>-1 or IS_DEFINED(c.status) = false ) and  ");
                 await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
                    .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,
@@ -366,7 +367,109 @@ namespace TEAMModelOS.Controllers
                         break;
                     }
                 }
-                var tmdids= lessonRecords.Select(x => x.tmdid).ToHashSet();
+                var tmdids = lessonRecords.Select(x => x.tmdid).ToHashSet();
+                if (tmdids != null && tmdids.Count > 0)
+                {
+                    List<IdNameCode> codes = new List<IdNameCode>();
+                    string sqltmd = $"select c.id,c.name,c.picture from c where c.id in ({string.Join(",", tmdids.Select(x => $"'{x}'"))})";
+                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<IdNameCode>(queryText: sqltmd, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
+                    {
+                        codes.Add(item);
+                    }
+                    if (codes.IsNotEmpty())
+                    {
+                        lessonRecords.ForEach(x => {
+                            var tmd = codes.Find(z => z.id.Equals(x.tmdid));
+                            if (tmd != null)
+                            {
+                                x.tmdname = tmd.name;
+                                x.tmdpicture = tmd.picture;
+                            }
+                        });
+                    }
+                }
+                return Ok(new { currCount = lessonRecords.Count, continuationToken, lessonRecords });
+            }
+            catch (Exception ex)
+            {
+                continuationToken = null;
+                return Ok(new { currCount = 0, continuationToken = continuationToken, lessonRecords });
+            }
+        }
+
+        /// <summary>
+        /// 获取开课记录
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+       // [AuthToken(Roles = "teacher,admin")]
+        [HttpPost("get-other-lesson-record")]
+        [Authorize(Roles = "IES")]
+        public async Task<IActionResult> GetOtherLessonRecord(JsonElement request)
+        {
+            if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
+            string tbname = "";
+            string code = "";
+            if (_scope.GetString().Equals("school") )
+            {
+                if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
+                if (!string.IsNullOrEmpty($"{_school}"))
+                {
+                    code = $"LessonRecord-{_school}";
+                    tbname = "School";
+                }
+                else
+                {
+                    return BadRequest();
+                }
+            }
+            else if ($"{_scope}".Equals("private"))
+            {
+                if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
+                if (!string.IsNullOrEmpty($"{_tmdid}"))
+                {
+                    code = $"LessonRecord-{_tmdid}";
+                    tbname = "Teacher";
+                }
+                else {
+                    return BadRequest();
+                }
+            }
+            else
+            {
+                return BadRequest();
+            }
+            request.TryGetProperty("periodId", out JsonElement _periodId);
+            //优质课程
+            var excellent = new JsonObject
+            {
+                ["excellent"] = true,
+                ["periodId"] = $"{_periodId}",
+            }.ToJsonString().ToObject<JsonElement>();
+            //专家好客
+            var doubleGreen = new JsonObject
+            {
+                ["doubleGreen"] = true,
+                ["periodId"] = $"{_periodId}",
+            }.ToJsonString().ToObject<JsonElement>();
+            //今日课程
+            var today = new JsonObject
+            {
+                ["today"] = true,
+                ["periodId"] = $"{_periodId}",
+            }.ToJsonString().ToObject<JsonElement>();
+            List<LessonRecord> excellentRcd =await GetOtherLessonCond(excellent,   code,   tbname);
+            List<LessonRecord> doubleGreenRcd = await GetOtherLessonCond(doubleGreen, code, tbname);
+            List<LessonRecord> todayRcd = await GetOtherLessonCond(today, code, tbname);
+            try {
+                var tmdids_excellent = excellentRcd.Select(x => x.tmdid);
+                var tmdids_doubleGreen = excellentRcd.Select(x => x.tmdid);
+                var tmdids_today = excellentRcd.Select(x => x.tmdid);
+                List<string> tmdids=new List<string>();
+                tmdids.AddRange(tmdids_excellent);
+                tmdids.AddRange(tmdids_doubleGreen);
+                tmdids.AddRange(tmdids_today);
                 if (tmdids != null && tmdids.Count > 0) {
                     List< IdNameCode > codes= new List<IdNameCode> ();  
                     string sqltmd = $"select c.id,c.name,c.picture from c where c.id in ({string.Join(",", tmdids.Select(x => $"'{x}'"))})";
@@ -374,22 +477,60 @@ namespace TEAMModelOS.Controllers
                         codes.Add(item);
                     }
                     if (codes.IsNotEmpty()) {
-                        lessonRecords.ForEach(x => {
+                        excellentRcd.ForEach(x => {
                             var tmd=  codes.Find(z => z.id.Equals(x.tmdid));
                             if (tmd != null) {
                                 x.tmdname = tmd.name;
                                 x.tmdpicture= tmd.picture;
                             }
                         });
+                        doubleGreenRcd.ForEach(x => {
+                            var tmd = codes.Find(z => z.id.Equals(x.tmdid));
+                            if (tmd != null)
+                            {
+                                x.tmdname = tmd.name;
+                                x.tmdpicture = tmd.picture;
+                            }
+                        });
+                        todayRcd.ForEach(x => {
+                            var tmd = codes.Find(z => z.id.Equals(x.tmdid));
+                            if (tmd != null)
+                            {
+                                x.tmdname = tmd.name;
+                                x.tmdpicture = tmd.picture;
+                            }
+                        });
                     }
                 }
-                return Ok(new { currCount=lessonRecords.Count, continuationToken, lessonRecords });
+                return Ok(new { excellentRcd , doubleGreenRcd, todayRcd });
             } catch (Exception ex) {
-                continuationToken = null;
-                return Ok(new { currCount=0, continuationToken = continuationToken, lessonRecords });
+                return Ok(new { excellentRcd, doubleGreenRcd, todayRcd });
             }
         }
 
+        private async Task<List<LessonRecord>> GetOtherLessonCond(JsonElement request,string code ,string tbname ) {
+            StringBuilder sql = new StringBuilder();
+            sql.Append("select value(c) from c ");
+            Dictionary<string, object> dict = GetLessonCond(request);
+            AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
+            List<LessonRecord> lessonRecords = new List<LessonRecord>();
+            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>-1 or IS_DEFINED(c.status) = false ) and  ");
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
+               .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition,
+               requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+            {
+                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())
+                    {
+                        lessonRecords.Add(obj.ToObject<LessonRecord>());
+                    }
+                }
+            }
+            return lessonRecords;
+        }
+
         private Dictionary<string, object> GetLessonCond(JsonElement request)
         {
             Dictionary<string, object> dict = new Dictionary<string, object>();
@@ -431,12 +572,14 @@ namespace TEAMModelOS.Controllers
             {
                 dict.Add(">=.discuss", 1);
             }
-
+            if (request.TryGetProperty("excellent", out JsonElement excellent) && excellent.GetBoolean())
+            {
+                dict.Add(">=.excellent", 1);
+            }
             if (request.TryGetProperty("name", out JsonElement name) && !string.IsNullOrWhiteSpace($"{name}"))
             {
                 dict.Add("$.name", name);
             }
-
             if (request.TryGetProperty("today", out JsonElement today) && today.GetBoolean())
             {
                 DateTime dateTimeA= Convert.ToDateTime(DateTimeOffset.UtcNow.ToString("D"));

+ 5 - 1
TEAMModelOS/Controllers/Teacher/InitController.cs

@@ -440,7 +440,11 @@ namespace TEAMModelOS.Controllers
                             code = $"ItemCond-{school_code}",
                             ttl = -1,
                         };
-                        await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<ItemCond>(itemCond, new PartitionKey($"ItemCond-{school_code}"));
+                        try {
+                            await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<ItemCond>(itemCond, new PartitionKey($"ItemCond-{school_code}"));
+                        } catch (CosmosException ex) when(ex.Status==409) {
+                            continue;
+                        }
                     }
                 }
                 dynamic currArea = new ExpandoObject();