|
@@ -49,6 +49,7 @@ using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
|
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
|
using TEAMModelOS.SDK.Models.Service.BI;
|
|
|
using TEAMModelOS.SDK.Services;
|
|
@@ -96,12 +97,161 @@ namespace TEAMModelOS.Controllers
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("transform-lessonrecord-overalleducation")]
|
|
|
public async Task<IActionResult> TransformLessonrecordOveralleducation(JsonElement json) {
|
|
|
- string msg = json.ToString();
|
|
|
- var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
- var messageChange = new ServiceBusMessage(msg);
|
|
|
- messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
|
|
|
- //await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} 更新事件,{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
- await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
|
|
|
+ //string msg = json.ToString();
|
|
|
+ //var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ //var messageChange = new ServiceBusMessage(msg);
|
|
|
+ //messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
|
|
|
+ //await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
|
|
|
+ string sql = "select value c from c where c.pk='StudentScoreRecord' and c.userType='student' and c.school<>null and c.school<>'' ";
|
|
|
+ List<StudentScoreRecord> studentScores = new List<StudentScoreRecord>();
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<StudentScoreRecord>(sql)) {
|
|
|
+ studentScores.Add(item);
|
|
|
+ }
|
|
|
+ var group = studentScores.GroupBy(z => z.school);
|
|
|
+ string schoolSql = $"select value c from c where c.id in ({string.Join(",",group.Select(x=>$"'{x.Key}'"))})";
|
|
|
+ var resultScool= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(schoolSql,"Base");
|
|
|
+ foreach(var item in group)
|
|
|
+ {
|
|
|
+ var list = item.ToList();
|
|
|
+ var stuids = list.Select(z => z.stuid);
|
|
|
+ string studentSql = $"select value c from c where c.id in ({string.Join(",", stuids.Select(x => $"'{x}'"))})";
|
|
|
+ var resultStuden = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(studentSql, $"Base-{item.Key}");
|
|
|
+
|
|
|
+ foreach (var sturecord in list) {
|
|
|
+ HashSet<OverallEducation> overallEducations = new HashSet<OverallEducation>();
|
|
|
+ var studentBase = resultStuden.list.Find(x => x.id.Equals(sturecord.stuid, StringComparison.OrdinalIgnoreCase));
|
|
|
+ var schoolBase = resultScool.list.Find(x => x.id.Equals(sturecord.school, StringComparison.OrdinalIgnoreCase));
|
|
|
+ if (studentBase == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ var period = schoolBase.period.Find(x => x.id.Equals($"{studentBase.periodId}"));
|
|
|
+ foreach (var record in sturecord.lessonRecords) {
|
|
|
+ if (record.time > 1000000000000) {
|
|
|
+ (Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester) dataSemester = SchoolService.GetSemester(period, record.time);
|
|
|
+ string oid = $"{dataSemester.studyYear}-{dataSemester.currSemester.id}-{sturecord.stuid}";
|
|
|
+ string ocode = $"OverallEducation-{sturecord.school}";
|
|
|
+ OverallEducation overallEducation = overallEducations.Where(o => o.id.Equals(oid, StringComparison.OrdinalIgnoreCase) && o.code.Equals(ocode, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
|
|
+ if (overallEducation != null)
|
|
|
+ {
|
|
|
+ var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(record.lessonId));
|
|
|
+ if (hasrecord != null)
|
|
|
+ {
|
|
|
+ hasrecord.gscore = record.gscore;
|
|
|
+ hasrecord.pscore = record.pscore;
|
|
|
+ hasrecord.tscore = record.tscore;
|
|
|
+ hasrecord.tmdid = record.tmdid;
|
|
|
+ hasrecord.school = record.school;
|
|
|
+ hasrecord.scope = record.scope;
|
|
|
+ hasrecord.lessonId = record.lessonId;
|
|
|
+ hasrecord.courseId = record.courseId;
|
|
|
+ hasrecord.periodId = record.periodId;
|
|
|
+ hasrecord.subjectId = record.subjectId;
|
|
|
+ hasrecord.time = record.time;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ overallEducation.lessonScore.Add(
|
|
|
+ new StudentLessonRecord
|
|
|
+ {
|
|
|
+ gscore = record.gscore,
|
|
|
+ pscore = record.pscore,
|
|
|
+ tscore = record.tscore,
|
|
|
+ tmdid = record.tmdid,
|
|
|
+ school = record.school,
|
|
|
+ scope = record.scope,
|
|
|
+ lessonId = record.lessonId,
|
|
|
+ courseId = record.courseId,
|
|
|
+ periodId = record.periodId,
|
|
|
+ subjectId = record.subjectId,
|
|
|
+ time = record.time
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync(oid, new PartitionKey(ocode));
|
|
|
+ if (response.Status != 200)
|
|
|
+ {
|
|
|
+ overallEducation = new OverallEducation
|
|
|
+ {
|
|
|
+ id = oid,
|
|
|
+ code = $"OverallEducation-{sturecord.school}",
|
|
|
+ pk = "OverallEducation",
|
|
|
+ ttl = -1,
|
|
|
+ name = studentBase.name,
|
|
|
+ classId = studentBase?.classId,
|
|
|
+ schoolCode = $"{sturecord.school}",
|
|
|
+ semesterId = dataSemester.currSemester.id,
|
|
|
+ year = dataSemester.studyYear,
|
|
|
+ periodId = $"{period.id}",
|
|
|
+ stuYear = studentBase.year,
|
|
|
+ studentId = studentBase.id,
|
|
|
+ lessonScore = new List<StudentLessonRecord>
|
|
|
+ {
|
|
|
+ new StudentLessonRecord
|
|
|
+ {
|
|
|
+ gscore = record.gscore,
|
|
|
+ pscore = record.pscore,
|
|
|
+ tscore = record.tscore,
|
|
|
+ tmdid = record.tmdid,
|
|
|
+ school = record.school,
|
|
|
+ scope = record.scope,
|
|
|
+ lessonId = record.lessonId,
|
|
|
+ courseId = record.courseId,
|
|
|
+ periodId = record.periodId,
|
|
|
+ subjectId = record.subjectId,
|
|
|
+ time= record.time
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ overallEducation = JsonDocument.Parse(response.Content).RootElement.ToObject<OverallEducation>();
|
|
|
+ var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(record.lessonId));
|
|
|
+ if (hasrecord != null)
|
|
|
+ {
|
|
|
+ hasrecord.gscore = record.gscore;
|
|
|
+ hasrecord.pscore = record.pscore;
|
|
|
+ hasrecord.tscore = record.tscore;
|
|
|
+ hasrecord.tmdid = record.tmdid;
|
|
|
+ hasrecord.school = record.school;
|
|
|
+ hasrecord.scope = record.scope;
|
|
|
+ hasrecord.lessonId = record.lessonId;
|
|
|
+ hasrecord.courseId = record.courseId;
|
|
|
+ hasrecord.periodId = record.periodId;
|
|
|
+ hasrecord.subjectId = record.subjectId;
|
|
|
+ hasrecord.time = record.time;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ overallEducation.lessonScore.Add(
|
|
|
+ new StudentLessonRecord
|
|
|
+ {
|
|
|
+ gscore = record.gscore,
|
|
|
+ pscore = record.pscore,
|
|
|
+ tscore = record.tscore,
|
|
|
+ tmdid = record.tmdid,
|
|
|
+ school = record.school,
|
|
|
+ scope = record.scope,
|
|
|
+ lessonId = record.lessonId,
|
|
|
+ courseId = record.courseId,
|
|
|
+ periodId = record.periodId,
|
|
|
+ subjectId = record.subjectId,
|
|
|
+ time = record.time
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ overallEducations.Add(overallEducation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var overallEducation in overallEducations) {
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(overallEducation, partitionKey: new PartitionKey(overallEducation.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return Ok();
|
|
|
}
|
|
|
|