using Azure.Cosmos; using System; using System.Collections.Generic; using System.Text; using System.Text.Json; using System.Threading.Tasks; using TEAMModelOS.SDK.DI; using TEAMModelOS.SDK.Extension; using TEAMModelOS.SDK.Helper.Common.DateTimeHelper; using TEAMModelOS.SDK.Models.Cosmos.Common; namespace TEAMModelOS.SDK.Models.Service { public class LessonService { /// /// /// /// /// /// /// public static LessonDis DisLessonCount( LessonRecord oldRecord, LessonRecord newRecord ) { //P分数量加减 LessonDis lessonDis = new LessonDis(); if (oldRecord.pScore >= 70) { if (newRecord.pScore < 70) { lessonDis. disPCount = -1; } } else { if (newRecord.pScore >= 70) { lessonDis.disPCount = 1; } } //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) { if (newRecord.tScore < 70 || newRecord.pScore < 70) { lessonDis.disDCount = -1; } } else { if (newRecord.tScore >= 70 && newRecord.pScore >= 70) { lessonDis.disDCount = 1; } } return lessonDis; } public static async Task FixLessonCount(CosmosClient client, DingDing _dingDing, LessonRecord data) { try { int day = DateTimeOffset.FromUnixTimeMilliseconds(data.startTime).DayOfYear; int year = DateTimeOffset.FromUnixTimeMilliseconds(data.startTime).Year; int days = DateTimeHelper.getDays(year); //int years = DateTimeOffset.UtcNow.DayOfYear; string tbname = string.Empty; string code = string.Empty; if (data.scope.Equals("school")) { code = $"LessonCount-{data.school}"; tbname = "School"; } else { code = $"LessonCount"; tbname = "Teacher"; } var response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(data.id.ToString(), new PartitionKey(code)); if (response.Status == 200) { using var json = await JsonDocument.ParseAsync(response.ContentStream); LessonCount count = json.ToObject(); if (count.courseIds.Count > 0) { if (!count.courseIds.Contains(data.courseId)) { count.courseIds.Add(data.courseId); count.beginCount[day] += 1; } } await client.GetContainer("TEAMModelOS", tbname).ReplaceItemAsync(count, count.id, new PartitionKey(code)); } else { LessonCount count = new LessonCount { id = data.tmdid, code = code, year = year }; double[] da = new double[days]; List list = new List(da); list[day] += 1; count.beginCount.AddRange(list); count.courseIds.Add(data.courseId); await client.GetContainer("TEAMModelOS", "tbname").CreateItemAsync(count, new PartitionKey(code)); } } catch (Exception ex) { await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-LessonCount-FixLessonCount\n{ex.Message}{ex.StackTrace}{data.ToJsonString()}", GroupNames.醍摩豆服務運維群組); } } } }