CrazyIter_Bin преди 3 години
родител
ревизия
7d1b1d46a3

+ 152 - 23
TEAMModelFunction/MonitorServicesBus.cs

@@ -781,48 +781,103 @@ namespace TEAMModelFunction
         /// <returns></returns>
         /// <returns></returns>
         [FunctionName("LessonRecordEvent")]
         [FunctionName("LessonRecordEvent")]
         public async Task LessonRecordFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-event", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
         public async Task LessonRecordFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-event", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
+
+
             
             
+
             JsonElement  data =  msg.ToObject<JsonElement>();
             JsonElement  data =  msg.ToObject<JsonElement>();
-            if (!data.TryGetProperty("lesson_id", out JsonElement _lessonId)) return;
-            if (!data.TryGetProperty("tmdid", out JsonElement _tmdid)) return ;
-            if (!data.TryGetProperty("scope", out JsonElement _scope)) return ;
-            if (!data.TryGetProperty("grant_types", out JsonElement _grant_types)) return ;
-            data.TryGetProperty("school", out JsonElement _school);
+            string scope = "";
+            string tmdid = "";
+            string lessonId;
+            string school ;
+            string tbname;
+            string code;
+            string blobname;
+            List<LessonUpdate> updates = new List<LessonUpdate>();
+            //更新课堂记录
+            if (data.TryGetProperty("lesson_id", out JsonElement _lessonId) && !string.IsNullOrEmpty($"{_lessonId}"))
+            {
+                if (!data.TryGetProperty("tmdid", out JsonElement _tmdid)) return;
+                if (!data.TryGetProperty("scope", out JsonElement _scope)) return;
+                if (!data.TryGetProperty("grant_types", out JsonElement _grant_types)) return;
+                data.TryGetProperty("school", out JsonElement _school);
+                school = $"{_school}";
+                scope = $"{_scope}";
+                tmdid = $"{_tmdid}";
+                lessonId = $"{_lessonId}";
+                updates = _grant_types.ToObject<List<LessonUpdate>>();
+                
+            }//创建课堂记录
+            else if (data.TryGetProperty("id", out JsonElement _id) && !string.IsNullOrEmpty($"{_id}")
+                && data.TryGetProperty("tmdid", out JsonElement _tmdid) && !string.IsNullOrEmpty($"{_tmdid}")
+                && data.TryGetProperty("scope", out JsonElement _scope) && !string.IsNullOrEmpty($"{_scope}"))
+            {
+                data.TryGetProperty("school", out JsonElement _school);
+                school = $"{_school}";
+                scope = $"{_scope}";
+                tmdid = $"{_tmdid}";
+                lessonId = $"{_id}";
+                updates.Add(new LessonUpdate { grant_type= "create" });
+            }//删除课堂记录
+            else if (data.TryGetProperty("delete_id", out JsonElement _delete_id) && !string.IsNullOrEmpty($"{_delete_id}")
+                && data.TryGetProperty("tmdid", out JsonElement _dtmdid) && !string.IsNullOrEmpty($"{_dtmdid}")
+                && data.TryGetProperty("scope", out JsonElement _dscope) && !string.IsNullOrEmpty($"{_dscope}")
+                && data.TryGetProperty("opt", out JsonElement _opt) && !string.IsNullOrEmpty($"{_opt}"))
+            {
+                data.TryGetProperty("school", out JsonElement _dschool);
+                school = $"{_dschool}";
+                if ($"{_opt}".Equals("delete"))
+                {
+                    scope = $"{_dscope}";
+                    tmdid = $"{_dtmdid}";
+                    lessonId = $"{_delete_id}";
+                    updates.Add(new LessonUpdate { grant_type = "delete" });
+                }
+                else { return; }
+            }
+            else {
+                return;
+            }
+           
             var client = _azureCosmos.GetCosmosClient();
             var client = _azureCosmos.GetCosmosClient();
-            string tbname = null;
-            string code = null;
-            string blobname = null;
-            if ($"{_scope}".Equals("school") && !string.IsNullOrEmpty($"{_school}"))
+            
+            if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
             {
             {
-                blobname = $"{_school}";
-                code = $"LessonRecord-{_school}";
+                blobname = $"{school}";
+                code = $"LessonRecord-{school}";
                 tbname = "School";
                 tbname = "School";
             }
             }
-            else if ($"{_scope}".Equals("private"))
+            else if ($"{scope}".Equals("private"))
             {
             {
-                blobname = $"{_tmdid}";
-                code = $"LessonRecord-{_tmdid}";
+                blobname = $"{tmdid}";
+                code = $"LessonRecord-{tmdid}";
                 tbname = "Teacher";
                 tbname = "Teacher";
             }
             }
             else
             else
             {
             {
                 return;
                 return;
             }
             }
+            LessonDis lessonDis = new LessonDis();
             List<LessonUpdate> msgs = new List<LessonUpdate>();
             List<LessonUpdate> msgs = new List<LessonUpdate>();
             try
             try
             {
             {
-                LessonRecord lessonRecord = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<LessonRecord>($"{_lessonId}", new PartitionKey(code));
+                LessonRecord lessonRecord  = null;
+                Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
+                if (response.Status == 200) {
+                    var doc = JsonDocument.Parse(response.ContentStream);
+                    lessonRecord= doc.RootElement.ToObject<LessonRecord>();
+                }
+                else {
+                    lessonRecord = null;
+                }
                 LessonRecord oldlessonRecord= lessonRecord;
                 LessonRecord oldlessonRecord= lessonRecord;
-               
-                if (_grant_types.ValueKind.Equals(JsonValueKind.Array))
-                {
-                    List<LessonUpdate> updates = _grant_types.ToObject<List<LessonUpdate>>();
+                if (updates.IsNotEmpty()) {
                     foreach (LessonUpdate update in updates)
                     foreach (LessonUpdate update in updates)
                     {
                     {
                         switch (update.grant_type)
                         switch (update.grant_type)
                         {
                         {
                             //更新课堂时长
                             //更新课堂时长
-                            case  "up-duration":
+                            case "up-duration":
                                 var duration = double.Parse($"{update.data}");
                                 var duration = double.Parse($"{update.data}");
                                 lessonRecord.duration = duration;
                                 lessonRecord.duration = duration;
                                 msgs.Add(update);
                                 msgs.Add(update);
@@ -864,14 +919,88 @@ namespace TEAMModelFunction
                                 //var activityInfos = ActivityInfoblobDownload.Content.ToObjectFromJson<List<LessonActivityInfo>>();
                                 //var activityInfos = ActivityInfoblobDownload.Content.ToObjectFromJson<List<LessonActivityInfo>>();
                                 msgs.Add(update);
                                 msgs.Add(update);
                                 break;
                                 break;
+                            case "delete":
+                                //BlobDownloadResult ActivityInfoblobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/{_lessonId}/IES/ActivityInfo.json").DownloadContentAsync();
+                                //var activityInfos = ActivityInfoblobDownload.Content.ToObjectFromJson<List<LessonActivityInfo>>();
+                                try
+                                {
+                                    await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemAsync<LessonRecord>(lessonId, new PartitionKey(code));
+                                    msgs.Add(update);
+                                }
+                                catch (CosmosException ex) {
+                                    msgs.Add(update);
+                                }
+                                break;
+                            case "create":
+                                oldlessonRecord = null;
+                                //处理课堂选用的课程信息
+                                if (!string.IsNullOrEmpty(lessonRecord.courseId))
+                                {
+                                    Course course = null;
+                                    try
+                                    {
+                                        course = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Course>(lessonRecord.courseId, new PartitionKey($"Course-{lessonRecord.school}"));
+                                    }
+                                    catch (CosmosException ex) when (ex.Status != 404)
+                                    {
+                                        try
+                                        {
+                                            course = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Course>(lessonRecord.courseId, new PartitionKey($"Course-{lessonRecord.tmdid}"));
+                                        }
+                                        catch (CosmosException e) when (e.Status != 404)
+                                        {
+                                            course = null;
+                                        }
+                                    }
+                                    if (course != null)
+                                    {
+                                        lessonRecord.periodId = course.period?.id;
+                                        lessonRecord.subjectId = course.subject?.id;
+                                    }
+                                }
+                                //处理课堂选用的名单
+                                if (lessonRecord.groupIds.IsNotEmpty())
+                                {
+                                    HashSet<string> grades = new HashSet<string>();
+                                    List<GroupListDto> groups = await GroupListService.GetGroupListListids(client, _dingDing, lessonRecord.groupIds, lessonRecord.school);
+                                    List<GroupListDto> groupLists = groups.FindAll(x => !string.IsNullOrEmpty(x.periodId) && x.year > 0 && !string.IsNullOrEmpty(x.school));
+                                    if (groupLists.IsNotEmpty() && !string.IsNullOrEmpty(lessonRecord.periodId))
+                                    {
+                                        School schoolObj = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(lessonRecord.school, new PartitionKey("Base"));
+
+                                        //年级算法
+                                        int? Count = schoolObj.period.Find(x => x.id.Equals(lessonRecord.periodId)).grades?.Count;
+                                        if (Count.HasValue)
+                                        {
+                                            int Month = DateTimeOffset.UtcNow.Month;
+                                            int Year = DateTimeOffset.UtcNow.Year;
+                                            foreach (int year in groupLists.Select(x => x.year))
+                                            {
+                                                int grade;
+                                                if (Month >= 1 && Month <= 6)
+                                                {
+                                                    grade = (Year - year + 1) / Count.Value;
+                                                }
+                                                else
+                                                {
+                                                    grade = (Year - year) / Count.Value;
+                                                }
+                                                grades.Add($"{grade}");
+                                            }
+                                        }
+                                    }
+                                    lessonRecord.grade.AddRange(grades);
+                                }
+                                msgs.Add(update);
+                                break;
                             default:
                             default:
                                 break;
                                 break;
                         }
                         }
                     }
                     }
                     //计算课堂更新前后的差值
                     //计算课堂更新前后的差值
-                    LessonDis lessonDis= LessonService.DisLessonCount(oldlessonRecord, lessonRecord);
-                    await LessonService.FixLessonCount(client, _dingDing, lessonRecord,lessonDis);
-                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord,$"{_lessonId}", new PartitionKey(code));
+                    lessonDis = LessonService.DisLessonCount(oldlessonRecord, lessonRecord, lessonDis);
+                    await LessonService.FixLessonCount(client, _dingDing, lessonRecord, lessonDis);
+                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, lessonId, new PartitionKey(code));
                 }
                 }
             }
             }
             catch (Exception ex)
             catch (Exception ex)

+ 14 - 3
TEAMModelOS.SDK/Models/Cosmos/Common/LessonRecord.cs

@@ -94,6 +94,12 @@ namespace TEAMModelOS.SDK.Models
         /// 不填  ["混合学习","语文教研"]课例类别,tag标签,IES5维护
         /// 不填  ["混合学习","语文教研"]课例类别,tag标签,IES5维护
         /// </summary>
         /// </summary>
         public List<string> category { get; set; } = new List<string>();
         public List<string> category { get; set; } = new List<string>();
+        public int hasVideo { get; set; }
+        /// <summary>
+        /// 
+        /// 科技互动详细次数。[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]
+        /// </summary>
+        public List<int> tech { get; set; } = new List<int>();
     }
     }
 
 
     public class LessonActivityInfo
     public class LessonActivityInfo
@@ -150,17 +156,22 @@ namespace TEAMModelOS.SDK.Models
     /// </summary>
     /// </summary>
     public class LessonDis
     public class LessonDis
     {
     {
+        /// <summary>
+        /// 开课数量差
+        /// </summary>
+        public int record { get; set; } = 0;
+
         /// <summary>
         /// <summary>
         /// T分数量差
         /// T分数量差
         /// </summary>
         /// </summary>
-        public int disTCount { get; set; }
+        public int disTCount { get; set; } = 0;
         /// <summary>
         /// <summary>
         /// P分数量差
         /// P分数量差
         /// </summary>
         /// </summary>
-        public int disPCount { get; set; }
+        public int disPCount { get; set; } = 0;
         /// <summary>
         /// <summary>
         /// 双绿灯数量差
         /// 双绿灯数量差
         /// </summary>
         /// </summary>
-        public int disDCount { get; set; }
+        public int disDCount { get; set; } = 0;
     }
     }
 }
 }

+ 60 - 35
TEAMModelOS.SDK/Models/Service/LessonService.cs

@@ -20,54 +20,79 @@ namespace TEAMModelOS.SDK.Models.Service
         /// <param name="_dingDing"></param>
         /// <param name="_dingDing"></param>
         /// <param name="data"></param>
         /// <param name="data"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public static LessonDis DisLessonCount( LessonRecord oldRecord, LessonRecord newRecord ) {
-            //P分数量加减
-
-            LessonDis lessonDis = new LessonDis();
-            if (oldRecord.pScore >= 70)
+        public static LessonDis DisLessonCount( LessonRecord oldRecord, LessonRecord newRecord, LessonDis lessonDis) {
+            //创建课堂的情况
+            if (oldRecord == null && newRecord != null)
             {
             {
-                if (newRecord.pScore < 70)
-                {
-                    lessonDis. disPCount = -1;
-                }
+                lessonDis.record = 1;
             }
             }
-            else
-            {
-                if (newRecord.pScore >= 70)
+            //删除数据的情况
+            else if (oldRecord != null && newRecord == null){
+                lessonDis.record = -1;
+                //P分数量加减
+                if (oldRecord.pScore >= 70)
                 {
                 {
-                    lessonDis.disPCount = 1;
+                    lessonDis.disPCount = -1;
                 }
                 }
-            }
-            //T分数量加减
-           
-            if (oldRecord.tScore >= 70)
-            {
-                if (newRecord.tScore < 70)
+                //T分数量加减
+                if (oldRecord.tScore >= 70)
                 {
                 {
                     lessonDis.disTCount = -1;
                     lessonDis.disTCount = -1;
                 }
                 }
+                if (oldRecord.tScore >= 70 && oldRecord.pScore >= 70) {
+                    lessonDis.disTCount = -1;
+                }
             }
             }
-            else
-            {
-                if (newRecord.tScore >= 70)
+            //无效操作
+            else if (oldRecord == null && newRecord == null){
+            //前后操作都有值,则表示更新
+            }else {
+                //P分数量加减
+                if (oldRecord.pScore >= 70)
                 {
                 {
-                    lessonDis.disTCount = 1;
+                    if (newRecord.pScore < 70)
+                    {
+                        lessonDis.disPCount = -1;
+                    }
                 }
                 }
-            }
-            //双绿灯数量
-            
-            if (oldRecord.tScore >= 70 && oldRecord.pScore >= 70)
-            {
-                if (newRecord.tScore < 70 || newRecord.pScore < 70)
+                else
                 {
                 {
-                    lessonDis.disDCount = -1;
+                    if (newRecord.pScore >= 70)
+                    {
+                        lessonDis.disPCount = 1;
+                    }
                 }
                 }
-            }
-            else
-            {
-                if (newRecord.tScore >= 70 && newRecord.pScore >= 70)
+                //T分数量加减
+
+                if (oldRecord.tScore >= 70)
+                {
+                    if (newRecord.tScore < 70)
+                    {
+                        lessonDis.disTCount = -1;
+                    }
+                }
+                else
+                {
+                    if (newRecord.tScore >= 70)
+                    {
+                        lessonDis.disTCount = 1;
+                    }
+                }
+                //双绿灯数量
+
+                if (oldRecord.tScore >= 70 && oldRecord.pScore >= 70)
                 {
                 {
-                    lessonDis.disDCount = 1;
+                    if (newRecord.tScore < 70 || newRecord.pScore < 70)
+                    {
+                        lessonDis.disDCount = -1;
+                    }
+                }
+                else
+                {
+                    if (newRecord.tScore >= 70 && newRecord.pScore >= 70)
+                    {
+                        lessonDis.disDCount = 1;
+                    }
                 }
                 }
             }
             }
             return lessonDis;
             return lessonDis;

+ 5 - 59
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -126,8 +126,6 @@ namespace TEAMModelOS.Controllers.Client
             {
             {
                 return BadRequest();
                 return BadRequest();
             }
             }
-            
-           
         }
         }
         
         
         /// <summary>
         /// <summary>
@@ -164,68 +162,16 @@ namespace TEAMModelOS.Controllers.Client
                     lessonRecord.startTime=DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                     lessonRecord.startTime=DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                 }
                 }
                 lessonRecord.pk = "LessonRecord";
                 lessonRecord.pk = "LessonRecord";
-
-                //处理课堂选用的课程信息
-                if (!string.IsNullOrEmpty(lessonRecord.courseId))
-                {
-                    Course course = null;
-                    try
-                    {
-                        course = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Course>(lessonRecord.courseId, new PartitionKey($"Course-{lessonRecord.school}"));
-                    }
-                    catch (CosmosException ex) when (ex.Status != 404) {
-                        try
-                        {
-                            course = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Course>(lessonRecord.courseId, new PartitionKey($"Course-{lessonRecord.tmdid}"));
-                        }
-                        catch (CosmosException e) when (e.Status != 404) {
-                            course = null;
-                        }
-                    }
-                    if (course != null)
-                    {
-                        lessonRecord.periodId = course.period?.id;
-                        lessonRecord.subjectId = course.subject?.id;
-                    }
-                }
                 //处理课堂选用的名单
                 //处理课堂选用的名单
                 try {
                 try {
-                    if (lessonRecord.groupIds.IsNotEmpty())
-                    {
-                        HashSet<string> grades = new HashSet<string>();
-                        List<GroupListDto> groups = await GroupListService.GetGroupListListids(client, _dingDing, lessonRecord.groupIds, lessonRecord.school);
-                        List<GroupListDto> groupLists = groups.FindAll(x => !string.IsNullOrEmpty(x.periodId) && x.year > 0 && !string.IsNullOrEmpty(x.school));
-                        if (groupLists.IsNotEmpty() && !string.IsNullOrEmpty(lessonRecord.periodId))
-                        {
-                            School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(lessonRecord.school, new PartitionKey("Base"));
-
-                            //年级算法
-                            int? Count = school.period.Find(x => x.id.Equals(lessonRecord.periodId)).grades?.Count;
-                            if (Count.HasValue)
-                            {
-                                int Month = DateTimeOffset.UtcNow.Month;
-                                int Year = DateTimeOffset.UtcNow.Year;
-                                foreach (int year in groupLists.Select(x => x.year))
-                                {
-                                    int grade;
-                                    if (Month >= 1 && Month <= 6)
-                                    {
-                                        grade = (Year - year + 1) / Count.Value;
-                                    }
-                                    else
-                                    {
-                                        grade = (Year - year) / Count.Value;
-                                    }
-                                    grades.Add($"{grade}");
-                                }
-                            }
-                        }
-                        lessonRecord.grade.AddRange(grades);
-                    }
                     await client.GetContainer(Constant.TEAMModelOS, tbname).CreateItemAsync(lessonRecord, new PartitionKey(lessonRecord.code));
                     await client.GetContainer(Constant.TEAMModelOS, tbname).CreateItemAsync(lessonRecord, new PartitionKey(lessonRecord.code));
+                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                    var messageChange = new ServiceBusMessage(lessonRecord.ToJsonString());
+                    messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
+                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
                     return Ok(new { status = 200 });
                     return Ok(new { status = 200 });
                 } catch (Exception ex) {
                 } catch (Exception ex) {
-                    await _dingDing.SendBotMsg($"IES5,{_option.Location}, hiteach/create-lesson-record:SetTeacherSubject()\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.成都开发測試群組);
+                    await _dingDing.SendBotMsg($"IES5,{_option.Location}, hiteach/create-lesson-record:()\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.成都开发測試群組);
                     return BadRequest();
                     return BadRequest();
                 }
                 }
             }
             }