|
@@ -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; }
|