CrazyIter_Bin 6 meses atrás
pai
commit
6f1f60b902

+ 50 - 3
HTEX.DataETL/Controllers/LessonRecordController.cs

@@ -4,6 +4,7 @@ using MathNet.Numerics.Distributions;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Azure.Cosmos;
 using StackExchange.Redis;
+using System.Collections.Generic;
 using System.Text.Json;
 using System.Xml;
 using TEAMModelOS.SDK;
@@ -199,7 +200,6 @@ namespace HTEX.DataETL.Controllers
             var runtimePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
             XmlDocument xmlDocument = new XmlDocument();
             xmlDocument.Load($"{runtimePath}\\summary.xml");
-            List<StudentSemesterRecord> students = new List<StudentSemesterRecord>();
             List<School> schools = new List<School>();
            // await Parallel.ForEachAsync(filesLessons, async (fileLesson, _) =>
             List<string> localIds = new List<string>();
@@ -229,7 +229,7 @@ namespace HTEX.DataETL.Controllers
                     lessonLocals.Add(item);
                     index++;
                 });
-                int n = 0;
+                
                 var  schoolGroup =   lessonLocals.Where(x=>!string.IsNullOrWhiteSpace(x.lessonRecord?.school)).GroupBy(x => x.lessonRecord?.school).Select(x => new { key=x.Key ,list=x.ToList()});
                 string schoolSql = $"select value c from c where c.id in ({string.Join(",", schoolGroup.Select(x => $"'{x.key}'"))})";
                 var schoolResults= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(schoolSql, "Base");
@@ -237,12 +237,59 @@ namespace HTEX.DataETL.Controllers
                 {
                     schools.AddRange(schoolResults.list);
                 }
-
+                foreach (var group in schoolGroup) 
+                {
+                    var studentIds = group.list.SelectMany(x => x.studentLessonDatas).Where(x=>!string.IsNullOrWhiteSpace(x.id)).Select(x => x.id).Distinct();
+                    string studentSql = $"select value c from c where c.id in ({string.Join(",", studentIds.Select(x => $"'{x}'"))})";
+                    var  studentResults=  await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(studentSql, $"Base-{group.key}");
+                    if (studentResults.list.IsNotEmpty()) 
+                    {
+                        studentsBase.AddRange(studentResults.list);
+                    }
+                    string studentSemesterRecordSql = $"select value c from c where c.stuid in ({string.Join(",", studentIds.Select(x => $"'{x}'"))}) and c.studyYear>=2023";
+                    var studentSemesterRecordResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<StudentSemesterRecord>(studentSemesterRecordSql, $"StudentSemesterRecord-{group.key}");
+                    if (studentSemesterRecordResults.list.IsNotEmpty())
+                    {
+                        studentSemesterRecords.AddRange(studentSemesterRecordResults.list);
+                    }
+                    string overallEducationSql = $"select value c from c where c.studentId in ({string.Join(",", studentIds.Select(x => $"'{x}'"))}) and c.year>=2023";
+                    var overallEducationResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<OverallEducation>(overallEducationSql, $"OverallEducation-{group.key}");
+                    if (overallEducationResults.list.IsNotEmpty())
+                    {
+                        overallEducations.AddRange(overallEducationResults.list);
+                    }
+                }
+                List<(string id,string owner, List<StudentLessonData> studentLessonData)> studentLessonDatas= new List<(string id, string owner, List<StudentLessonData>)>();
+                List<(string id, string owner, List<StudentLessonItem> studentLessons,List<CodeBool> codeBools, List<StudentLessonData> studentLessonData)> lessonItems = new List<(string id, string owner, List<StudentLessonItem> studentLessons, List<CodeBool> codeBools, List<StudentLessonData> studentLessonData)>();
+                int n = 0;
                 foreach (var  item in lessonLocals) 
                 {
                     var studata = await LessonETLService.DoStudentLessonData(Constant.objectiveTypes, _azureStorage, item, _dingDing, _azureCosmos.GetCosmosClient(), "China", _azureRedis, studentSemesterRecords, overallEducations, lessonDataAnalysis, studentsBase, schools);
+                    if (studata.codeBools.FindAll(x=>x.value).IsNotEmpty()) 
+                    {
+                        string owner = item.lessonRecord.scope.Equals("school") ? item.lessonRecord.school : item.lessonRecord.tmdid;
+                        studentLessonDatas.Add((item.lessonRecord.id, owner, studata.studentLessonDatas));
+                        lessonItems.Add((item.lessonRecord.id, owner, studata.lessonItems,studata.codeBools,studata.studentLessonDatas));
+                    }
                     n++;
                 }
+                int p = 0;
+                //XmlDocument xmlDocument = new XmlDocument();
+                //var runtimePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
+                //xmlDocument.Load($"{runtimePath}\\summary.xml");
+                await Parallel.ForEachAsync(lessonItems, async (lessonItem, cancellationToken) =>
+                {
+                    lessonItem.studentLessons = LessonETLService.ProcessStudentDataV2(lessonItem.studentLessonData, lessonDataAnalysis, lessonItem.codeBools);
+                    await LessonETLService.ExportToExcelAzureBlob(lessonItem.studentLessons, _azureStorage, lessonItem.owner, $"{lessonItem.id}/student-analysis.xlsx", xmlDocument);
+                    p++;
+                });
+                int s = 0;
+                await Parallel.ForEachAsync(studentLessonDatas, async (studentLessonData, cancellationToken) =>
+                {
+                    await _azureStorage.GetBlobContainerClient(studentLessonData.owner).UploadFileByContainer(studentLessonData.studentLessonData.ToJsonString(), "records", $"{studentLessonData.id}/student-analysis.json");
+                    s++;
+                });
+
                 int m   =0;
                 await Parallel.ForEachAsync(studentSemesterRecords, async (studentSemester, cancellationToken) => 
                 {

+ 39 - 4
TEAMModelOS.Extension/HTEX.Lib/ETL/Lesson/LessonETLService.cs

@@ -127,13 +127,13 @@ namespace HTEX.Lib.ETL.Lesson
             studentLessonDatas = LessonETLService.GetTaskData(lessonLocal.lessonBase!, lessonLocal.timeLineData!, lessonLocal.taskDatas, studentLessonDatas, lessonLocal.lessonRecord.id);
             var pickupData = LessonETLService.GetPickupData(lessonLocal.lessonBase!, lessonLocal. timeLineData!, studentLessonDatas, lessonLocal.lessonRecord.id);
             studentLessonDatas= pickupData.studentLessonDatas;
-           
             var codeBools=  GetCodeBools(studentLessonDatas);
             List<StudentLessonItem> lessonItems = new List<StudentLessonItem>();
             string owner = lessonLocal.lessonRecord.scope.Equals("school") ? lessonLocal.lessonRecord.school : lessonLocal.lessonRecord.tmdid;
             if (codeBools.FindAll(x => x.value).IsNotEmpty()) 
             {
-                try
+#if !DEBUG
+               try
                 {
 
                     bool exists = await azureStorage.GetBlobContainerClient("0-public").GetBlobClient($"/lesson/analysis/analysis-model.json").ExistsAsync();
@@ -150,7 +150,6 @@ namespace HTEX.Lib.ETL.Lesson
                         var runtimePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                         xmlDocument.Load($"{runtimePath}\\summary.xml");
                         await LessonETLService.ExportToExcelAzureBlob(lessonItems, azureStorage, owner, $"{lessonLocal.lessonRecord.id}/student-analysis.xlsx", xmlDocument);
-                        // await _dingDing.SendBotMsg($"学生课中报告已经生成:{owner},records/{lessonLocal.lessonRecord.id}/student-analysis.xlsx",GroupNames.成都开发測試群組);
                     }
                 }
                 catch (Exception ex)
@@ -161,6 +160,7 @@ namespace HTEX.Lib.ETL.Lesson
                     }
                 }
                 await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(studentLessonDatas.ToJsonString(), "records", $"{lessonLocal.lessonRecord.id}/student-analysis.json");
+#endif
                 if (lessonLocal.lessonRecord.scope.Equals("school")&& !string.IsNullOrWhiteSpace(lessonLocal.lessonRecord.school)  && location.Equals("China", StringComparison.OrdinalIgnoreCase))
                 {
                     School school = schools.Find(x => x.id.Equals(lessonLocal.lessonRecord.school));
@@ -175,6 +175,7 @@ namespace HTEX.Lib.ETL.Lesson
                     }
                     if (school!=null)
                     {
+#if !DEBUG
                         var sdtus = studentLessonDatas.Where(y => !studentsBase.Where(z => z.schoolId.Equals(school.id)).Select(x => x.id).Contains(y.id));
                         if (sdtus!=null && sdtus.Count()>0)
                         {
@@ -184,6 +185,7 @@ namespace HTEX.Lib.ETL.Lesson
                                 studentsBase.AddRange(result.list);
                             }
                         }
+#endif
                         string? periodId = !string.IsNullOrWhiteSpace(lessonLocal.lessonRecord.periodId) ? lessonLocal.lessonRecord.periodId : school.period.FirstOrDefault()?.id;
                         var period = school.period.Find(x => x.id.Equals(periodId));
                         if (period!=null)
@@ -196,6 +198,7 @@ namespace HTEX.Lib.ETL.Lesson
                                 StudentSemesterRecord studentSemester = studentSemesterRecords.Find(x => x.id.Equals($"{pre_id}-{studentLessonData.id}") && x.code.Equals(code));
                                 if (studentSemester==null)
                                 {
+#if !DEBUG
                                     ResponseMessage responseMessage = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync($"{pre_id}-{studentLessonData.id}", new PartitionKey(code));
                                     if (responseMessage.IsSuccessStatusCode)
                                     {
@@ -216,6 +219,20 @@ namespace HTEX.Lib.ETL.Lesson
                                             pk="StudentSemesterRecord"
                                         };
                                     }
+#else
+                                    studentSemester= new StudentSemesterRecord
+                                    {
+                                        id= $"{pre_id}-{studentLessonData.id}",
+                                        code=code,
+                                        stuid= studentLessonData.id,
+                                        userType=Constant.ScopeStudent,
+                                        school=school.id,
+                                        studyYear=semester.studyYear,
+                                        semesterId=semester.currSemester.id,
+                                        period= period?.id,
+                                        pk="StudentSemesterRecord"
+                                    };
+#endif
                                     studentSemesterRecords.Add(studentSemester);
                                 }
 
@@ -302,6 +319,7 @@ namespace HTEX.Lib.ETL.Lesson
                                     OverallEducation overallEducation = overallEducations.Find(x => x.id.Equals(oid) && x.code.Equals(ocode));
                                     if (overallEducation== null)
                                     {
+#if !DEBUG
                                         ResponseMessage oresponse = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync(oid, new PartitionKey(ocode));
                                         if (!oresponse.IsSuccessStatusCode)
                                         {
@@ -326,9 +344,26 @@ namespace HTEX.Lib.ETL.Lesson
                                         {
                                             overallEducation = JsonDocument.Parse(oresponse.Content).RootElement.ToObject<OverallEducation>();
                                         }
+#else
+                                        overallEducation = new OverallEducation
+                                        {
+                                            id =oid,
+                                            code = $"OverallEducation-{school.id}",
+                                            pk = "OverallEducation",
+                                            ttl = -1,
+                                            name = student.name,
+                                            classId = student?.classId,
+                                            schoolCode = $"{school.id}",
+                                            semesterId = semester.currSemester.id,
+                                            year = semester.studyYear,
+                                            periodId = $"{period.id}",
+                                            stuYear = student.year,
+                                            studentId = student.id,
+                                            lessonScore= new List<StudentLessonRecord>()
+                                        };
+#endif
                                         overallEducations.Add(overallEducation);
                                     }
-
                                     var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(lessonLocal.lessonRecord.id));
                                     if (hasrecord==null)
                                     {