|
@@ -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,227 @@ 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' and c.code<>'LessonRecord-ydzt' ";
|
|
|
+ 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 {/* PartitionKey = new PartitionKey("LessonRecord-ydzt")*/ }))
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ //}
|
|
|
+ HashSet<string> courseIds = new HashSet<string>();
|
|
|
+ lessonRecords.ForEach(item => {
|
|
|
+ if (!string.IsNullOrWhiteSpace(item.courseId)) {
|
|
|
+ courseIds.Add(item.courseId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Course> courses = new List<Course>();
|
|
|
+ if (courseIds.Any()) {
|
|
|
+ string sqlCourse = $" SELECT distinct value(c) FROM c where c.pk='Course' and c.id in ({string.Join(",", courseIds.Select(x => $"'{x}'"))}) ";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<Course>(queryText: sqlCourse, requestOptions: new QueryRequestOptions { }))
|
|
|
+ {
|
|
|
+ courses.Add(item);
|
|
|
+ }
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<Course>(queryText: sqlCourse, requestOptions: new QueryRequestOptions { }))
|
|
|
+ {
|
|
|
+ courses.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ HashSet<string> schoolIds = new HashSet<string>();
|
|
|
+ lessonRecords.ForEach(item => {
|
|
|
+ if (!string.IsNullOrWhiteSpace(item.school))
|
|
|
+ {
|
|
|
+ schoolIds.Add(item.school);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ string sqlSchool = $" SELECT distinct value(c) FROM c where c.id in ({string.Join(",", schoolIds.Select(x => $"'{x}'"))}) ";
|
|
|
+ List<School> schools = new List<School>();
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<School>(queryText: sqlSchool, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ schools.Add(item);
|
|
|
+ }
|
|
|
+ var lists = lessonRecords.Where(x => !string.IsNullOrWhiteSpace(x.school)).GroupBy(y => y.school).Select(a => new { key = a.Key, list = a.ToList() });
|
|
|
+ Dictionary<string, List<GroupListDto>> dict = new Dictionary<string, List<GroupListDto>>();
|
|
|
+ foreach (var item in lists) {
|
|
|
+ var gids= item.list.SelectMany(x => x.groupIds).Where(y=>!string.IsNullOrWhiteSpace(y));
|
|
|
+ HashSet<string> grades = new HashSet<string>();
|
|
|
+ List<GroupListDto> groups = await GroupListService.GetGroupListListids(client, _dingDing, gids.ToList(), item.key);
|
|
|
+ List<GroupListDto> groupLists = groups?.FindAll(x => !string.IsNullOrEmpty(x.periodId) && !string.IsNullOrEmpty(x.school));
|
|
|
+ dict.Add(item.key, groupLists);
|
|
|
+ }
|
|
|
+ foreach (var lessonRecord in lessonRecords) {
|
|
|
+ LessonRecord old = lessonRecord.ToJsonString().ToObject<LessonRecord>();
|
|
|
+ if (string.IsNullOrWhiteSpace(lessonRecord.courseId)) {
|
|
|
+ var course = courses.Find(x => x.id.Equals(lessonRecord.courseId));
|
|
|
+ if (course != null)
|
|
|
+ {
|
|
|
+ lessonRecord.periodId = course.period?.id;
|
|
|
+ lessonRecord.subjectId = course.subject?.id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //处理课堂选用的名单
|
|
|
+ if (lessonRecord.groupIds.IsNotEmpty() && !string.IsNullOrWhiteSpace(lessonRecord.school) && !string.IsNullOrWhiteSpace(lessonRecord.periodId))
|
|
|
+ {
|
|
|
+ HashSet<string> grades = new HashSet<string>();
|
|
|
+ List<GroupListDto> groupLists = null;
|
|
|
+ dict.TryGetValue(lessonRecord.school, out groupLists);
|
|
|
+ if (groupLists.IsNotEmpty())
|
|
|
+ {
|
|
|
+ var gplist = groupLists.FindAll(x=>lessonRecord.groupIds.Contains(x.id));
|
|
|
+ School schoolObj = schools.Find(x => x.id.Equals(lessonRecord.school));
|
|
|
+ if (schoolObj != null)
|
|
|
+ {
|
|
|
+ //年级算法
|
|
|
+ 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;
|
|
|
+ int dis = 0;
|
|
|
+ int index = -1;
|
|
|
+
|
|
|
+ foreach (int year in gplist.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= grades.ToList();
|
|
|
+ }
|
|
|
+ string scope = lessonRecord.scope;
|
|
|
+ string tmdid =lessonRecord.tmdid;
|
|
|
+ string lessonId=lessonRecord.id;
|
|
|
+ string school=lessonRecord.school;
|
|
|
+ string tbname="";
|
|
|
+ string code;
|
|
|
+ string blobname="";
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ 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.成都开发測試群組);
|
|
|
+ }
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, lessonId, new PartitionKey(lessonRecord.code));
|
|
|
+ LessonDis lessonDis = new LessonDis();
|
|
|
+ //计算课堂更新前后的差值
|
|
|
+ lessonDis = LessonService.DisLessonCount(old, lessonRecord, lessonDis);
|
|
|
+ await LessonService.FixLessonCount(client, _dingDing, lessonRecord, old, lessonDis);
|
|
|
+ }
|
|
|
+ return Ok(new { lessonRecords });
|
|
|
+ }
|
|
|
public record CorrectStu
|
|
|
{
|
|
|
public string id { get; set; }
|