CrazyIter_Bin před 3 roky
rodič
revize
f3fd9bc493

+ 27 - 2
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -967,6 +967,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                 //如果有更新 则去读取/{_lessonId}/IES/base.json
                                 try
                                 {
+                                    await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} 收到更新", GroupNames.成都开发測試群組);
                                     BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{_lessonId}/IES/base.json").DownloadContentAsync();
                                     LessonBase lessonBase = baseblobDownload.Content.ToObjectFromJson<LessonBase>();
                                     if (lessonBase != null  && lessonBase.summary!=null)
@@ -987,6 +988,26 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                         lessonRecord.examCount = lessonBase.summary.examCount;
                                         lessonRecord.totalInteractPoint = lessonBase.summary.totalInteractPoint;
                                     }
+                                    long? size = await  _azureStorage.GetBlobContainerClient(blobname).GetBlobsSize($"records/{_lessonId}");
+                                    Bloblog bloblog = new Bloblog
+                                    {
+                                        id = lessonRecord.id,
+                                        code = $"Bloblog-{blobname}",
+                                        name = lessonRecord.name,
+                                        pk = "Bloblog",
+                                        time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                        type = "records",
+                                        url = $"records/{_lessonId}",
+                                        subjectId = new List<string> { lessonRecord.subjectId },
+                                        periodId = new List<string> { lessonRecord.periodId },
+                                        size = size.HasValue ? size.Value : 0,
+                                    };
+                                    await client.GetContainer(Constant.TEAMModelOS,tbname).UpsertItemAsync(bloblog);
+                                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
+                                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
+                                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                                    await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} 更新完成", GroupNames.成都开发測試群組);
                                     msgs.Add(update);
                                 }
                                 catch (RequestFailedException ex) when (ex.Status == 404)
@@ -1027,6 +1048,12 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                 try
                                 {
                                     await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemAsync<LessonRecord>(lessonId, new PartitionKey(code));
+                                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobname, new List<string> { $"records/{_lessonId}" });
+                                    await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemStreamAsync(lessonRecord.id,new PartitionKey ($"Bloblog-{blobname}"));
+                                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
+                                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
+                                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                                     msgs.Add(update);
                                 }
                                 catch (CosmosException)
@@ -1124,8 +1151,6 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                 }
                                 msgs.Add(update);
                                 break;
-                           
-                                
                             default:
                                 break;
                         }

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/Bloblog.cs

@@ -18,7 +18,7 @@ namespace TEAMModelOS.SDK.Models
         public List<string> subjectId { get; set; } = new List<string>() { "" };
         public List<string> gradeId { get; set; } = new List<string>() { "" };
         /// <summary>
-        /// audio 音频,video 视频 ,doc文档,image图片,other 其他,res教材,thum缩略图,avatar 头像
+        /// audio 音频,video 视频 ,doc文档,image图片,other 其他,res教材,thum缩略图,avatar 头像,课堂记录records
         /// </summary>
         public string type { get; set; }
 

+ 1 - 0
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -130,6 +130,7 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 var messageChange = new ServiceBusMessage(msg);
                 messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
+                await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} 更新事件", GroupNames.成都开发測試群組);
                 await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
                 return Ok(new { status = 200 });
             }

+ 202 - 0
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -30,6 +30,7 @@ using Microsoft.Extensions.Configuration;
 using TEAMModelOS.Models;
 using System.Text.RegularExpressions;
 using TEAMModelOS.SDK.Services;
+using Azure.Messaging.ServiceBus;
 
 namespace TEAMModelOS.Controllers
 {
@@ -1825,6 +1826,207 @@ namespace TEAMModelOS.Controllers
             }
             return Ok(schools);
         }
+
+        /// <summary>
+        /// 给学校空间设置1024T,按区域。
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("fix-school-subjects-type")]
+        public async Task<IActionResult> FixSchoolSubjectsType(JsonElement json)
+        {
+            string sql = " SELECT distinct value(c)  FROM c join p in  c. period join s in p.subjects where s.type=0 ";
+            List<School> schools = new List<School>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<School>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
+            {
+                schools.Add(item);
+            }
+            schools.ForEach(x => {
+                x.period.ForEach(p => {
+                    p.subjects.ForEach(s => {
+                        if (s.type == 0)
+                        {
+                            s.type = 1;
+                        }
+                    });
+                });
+            });
+            foreach (var item in schools)
+            {
+                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
+            }
+            return Ok(schools);
+        }
+
+
+        /// <summary>
+        /// 给学校空间设置1024T,按区域。
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("fix-school-lesson-record")]
+        public async Task<IActionResult> FixSchoolLessonRecord(JsonElement json)
+        {
+            var client = _azureCosmos.GetCosmosClient();
+            string sql = " SELECT distinct value(c)  FROM c  where c.pk='LessonRecord' ";
+            List<LessonRecord> lessonRecords = new List<LessonRecord>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<LessonRecord>(queryText: sql,requestOptions:new QueryRequestOptions { }))
+            {
+                lessonRecords.Add(item);
+            }
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<LessonRecord>(queryText: sql, requestOptions: new QueryRequestOptions { }))
+            {
+                lessonRecords.Add(item);
+            }
+            foreach (var lessonRecord in lessonRecords) {
+                LessonRecord old = lessonRecord.ToJsonString().ToObject<LessonRecord>();
+                Course course = null;
+                try
+                {
+                    var cresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(lessonRecord.courseId, new PartitionKey($"Course-{lessonRecord.school}"));
+                    if (cresponse.Status == 200)
+                    {
+                        using var cJson = await JsonDocument.ParseAsync(cresponse.ContentStream);
+                        course = cJson.ToObject<Course>();
+                    }
+                    else
+                    {
+                        var sresponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(lessonRecord.courseId, new PartitionKey($"Course-{lessonRecord.tmdid}"));
+                        if (sresponse.Status == 200)
+                        {
+                            using var cJson = await JsonDocument.ParseAsync(sresponse.ContentStream);
+                            course = cJson.ToObject<Course>();
+                        }
+                        else
+                        {
+                            course = null;
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-查询课程-CosmosDB异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                }
+                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.IsNullOrWhiteSpace(lessonRecord.periodId))
+                    {
+                        try
+                        {
+                            School schoolObj = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(lessonRecord.school, new PartitionKey("Base"));
+                            //年级算法
+                            var period = schoolObj.period.Find(x => x.id.Equals(lessonRecord.periodId));
+                            int? Count = period?.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}");
+                                }
+                            }
+                        }
+                        catch (CosmosException ex) when (ex.Status == 404)
+                        {
+
+                        }
+                    }
+
+                    string scope = lessonRecord.scope;
+                    string tmdid =lessonRecord.tmdid;
+                    string lessonId=lessonRecord.id;
+                    string school=lessonRecord.school;
+                    string tbname="";
+                    string code;
+                    string blobname="";
+                    lessonRecord.grade.AddRange(grades);
+                    if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
+                    {
+                        blobname = $"{school}";
+                        code = $"LessonRecord-{school}";
+                        tbname = "School";
+                    }
+                    else if ($"{scope}".Equals("private"))
+                    {
+                        blobname = $"{tmdid}";
+                        code = $"LessonRecord-{tmdid}";
+                        tbname = "Teacher";
+                    }
+                    //如果有更新 则去读取/{_lessonId}/IES/base.json
+                    try
+                    {
+                        BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{lessonId}/IES/base.json").DownloadContentAsync();
+                        LessonBase lessonBase = baseblobDownload.Content.ToObjectFromJson<LessonBase>();
+                        if (lessonBase != null && lessonBase.summary != null)
+                        {
+                            lessonRecord.attendCount = lessonBase.summary.attendCount;
+                            lessonRecord.clientCount = lessonBase.summary.clientCount;
+                            lessonRecord.attendRate = lessonBase.summary.attendRate;
+                            lessonRecord.groupCount = lessonBase.summary.groupCount;
+                            lessonRecord.collateTaskCount = lessonBase.summary.collateTaskCount;
+                            lessonRecord.collateCount = lessonBase.summary.collateCount;
+                            lessonRecord.pushCount = lessonBase.summary.pushCount;
+                            lessonRecord.totalPoint = lessonBase.summary.totalPoint;
+                            lessonRecord.examQuizCount = lessonBase.summary.examQuizCount;
+                            lessonRecord.interactionCount = lessonBase.summary.interactionCount;
+                            lessonRecord.examPointRate = lessonBase.summary.examPointRate;
+                            lessonRecord.clientInteractionCount = lessonBase.summary.clientInteractionCount;
+                            lessonRecord.clientInteractionAverge = lessonBase.summary.clientInteractionAverge;
+                            lessonRecord.examCount = lessonBase.summary.examCount;
+                            lessonRecord.totalInteractPoint = lessonBase.summary.totalInteractPoint;
+                        }
+                        long? size = await _azureStorage.GetBlobContainerClient(blobname).GetBlobsSize($"records/{lessonId}");
+                        Bloblog bloblog = new Bloblog
+                        {
+                            id = lessonRecord.id,
+                            code = $"Bloblog-{blobname}",
+                            name = lessonRecord.name,
+                            pk = "Bloblog",
+                            time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                            type = "records",
+                            url = $"records/{lessonId}",
+                            subjectId = new List<string> { lessonRecord.subjectId },
+                            periodId = new List<string> { lessonRecord.periodId },
+                            size = size.HasValue ? size.Value : 0,
+                        };
+                        await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(bloblog);
+                        var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = "records", name = $"{blobname}" }.ToJsonString()); ;
+                        messageBlob.ApplicationProperties.Add("name", "BlobRoot");
+                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                        await _dingDing.SendBotMsg($"{_option.Location},课堂id:{lessonId} 更新完成", GroupNames.成都开发測試群組);
+                    }
+                    catch (RequestFailedException ex) when (ex.Status == 404)
+                    {
+                    }
+                    catch (Exception ex)
+                    {
+                        await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}课程读取base.json,{lessonId}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                    }
+                }
+            }
+            return Ok(new { lessonRecords });
+        }
         public record CorrectStu
         {
             public string id { get; set; }