|
@@ -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)
|