黄贺彬 7 bulan lalu
induk
melakukan
a9e572f701

+ 6 - 4
HTEX.DataETL/Controllers/LessonRecordController.cs

@@ -262,6 +262,7 @@ namespace HTEX.DataETL.Controllers
 
                                      studentSemester.lessons.Add(new StuLessonLite
                                      {
+                                         id=lessonLocal.lessonRecord.id,
                                          tmdid=lessonLocal.lessonRecord.tmdid,
                                          sid= lessonLocal.lessonRecord.subjectId,
                                          cid= lessonLocal.lessonRecord.courseId,
@@ -295,12 +296,13 @@ namespace HTEX.DataETL.Controllers
             string studentsPath = $"{lessonBasePath}\\students";
             foreach (var stu in students) 
             {
-                string path = $"{studentsPath}\\{stu.school}\\{stu.studyYear}\\{stu.semesterId}";
-                if (!Directory.Exists(path)) 
+                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(stu, new PartitionKey(stu.code));
+                //  string path = $"{studentsPath}\\{stu.school}\\{stu.studyYear}\\{stu.semesterId}";
+                // if (!Directory.Exists(path)) 
                 {
-                    Directory.CreateDirectory(path);
+                   // Directory.CreateDirectory(path);
                 }
-                await System.IO.File.WriteAllTextAsync($"{path}\\{stu.stuid}.json", stu.ToJsonString());
+               // await System.IO.File.WriteAllTextAsync($"{path}\\{stu.stuid}.json", stu.ToJsonString());
             }
             string schoolsPath = $"{lessonBasePath}\\schools";
             await System.IO.File.WriteAllTextAsync($"{schoolsPath}\\school.json", schools.ToJsonString());

+ 54 - 43
TEAMModelOS.Extension/HTEX.Lib/ETL/Lesson/LessonETLService.cs

@@ -7,6 +7,7 @@ using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
 using MathNet.Numerics;
 using MathNet.Numerics.Distributions;
 using Microsoft.Azure.Cosmos;
+using Microsoft.Azure.Cosmos.Linq;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
 using OfficeOpenXml;
@@ -93,60 +94,70 @@ namespace HTEX.Lib.ETL.Lesson
                 {
                     string? periodId = !string.IsNullOrWhiteSpace(lessonLocal.lessonRecord.periodId) ? lessonLocal.lessonRecord.periodId : school.period.FirstOrDefault()?.id;
                     var period = school.period.Find(x => x.id.Equals(periodId));
-                    var semester = SchoolService.GetSemester(period, lessonLocal.lessonRecord.startTime);
-                    string pre_id = $"{semester.studyYear}-{semester.currSemester.id}";
-                    string code = $"StudentSemesterRecord-{school.id}";
-                    foreach (var studentLessonData in studentLessonDatas)
+                    if (period!=null) 
                     {
-                        StudentSemesterRecord studentSemester = null;// students.Find(x => x.stuid.Equals(studentLessonData.id) &&x.id.Equals($"{pre_id}-{studentLessonData.id}") && x.code.Equals(code));
-                        if (studentSemester==null)
+                        var semester = SchoolService.GetSemester(period, lessonLocal.lessonRecord.startTime);
+                        string pre_id = $"{semester.studyYear}-{semester.currSemester.id}";
+                        string code = $"StudentSemesterRecord-{school.id}";
+                        foreach (var studentLessonData in studentLessonDatas)
                         {
-                            studentSemester= new StudentSemesterRecord
+                            StudentSemesterRecord studentSemester = null;
+                            ResponseMessage responseMessage = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync($"{pre_id}-{studentLessonData.id}", new PartitionKey(code));
+                            if (responseMessage.IsSuccessStatusCode)
                             {
-                                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,
-                            };
-                          //  students.Add(studentSemester);
-                        }
-                        StuLesson lesson = new StuLesson()
-                        {
-                            id= lessonLocal.lessonRecord.id,
-                            time= lessonLocal.lessonRecord.startTime,
-                            attend=0
-                        };
-                        if (studentLessonData.cooperation>0 || studentLessonData.achieve>0|| studentLessonData.attitude>0 || studentLessonData.cowork>0 ||  studentLessonData.appraise>0)
-                        {
-                            lesson.attend=1;
-                            studentSemester.lessons.Add(new StuLessonLite
+                                studentSemester= JsonDocument.Parse(responseMessage.Content).ToObject<StudentSemesterRecord>();
+                            }
+                            else
                             {
-                                tmdid=lessonLocal.lessonRecord.tmdid,
-                                sid= lessonLocal.lessonRecord.subjectId,
-                                cid= lessonLocal.lessonRecord.courseId,
-                                hrate=studentLessonData.cooperation,
-                                crate=studentLessonData.achieve,
-                                trate=studentLessonData.attitude,
-                                xrate=studentLessonData.cowork,
-                                prate=studentLessonData.appraise
-                            });
-                        }
-                        else
-                        {
-                            if (studentLessonData.attend==1)
+                                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,
+                                };
+                            }
+                            studentSemester.les.Find(x => x.id.Equals(lessonLocal.lessonRecord.id));
+
+                            StuLesson lesson = new StuLesson()
+                            {
+                                id= lessonLocal.lessonRecord.id,
+                                time= lessonLocal.lessonRecord.startTime,
+                                attend=0
+                            };
+                            if (studentLessonData.cooperation>0 || studentLessonData.achieve>0|| studentLessonData.attitude>0 || studentLessonData.cowork>0 ||  studentLessonData.appraise>0)
                             {
                                 lesson.attend=1;
+                                studentSemester.lessons.Add(new StuLessonLite
+                                {
+                                    
+                                    tmdid=lessonLocal.lessonRecord.tmdid,
+                                    sid= lessonLocal.lessonRecord.subjectId,
+                                    cid= lessonLocal.lessonRecord.courseId,
+                                    hrate=studentLessonData.cooperation,
+                                    crate=studentLessonData.achieve,
+                                    trate=studentLessonData.attitude,
+                                    xrate=studentLessonData.cowork,
+                                    prate=studentLessonData.appraise
+                                });
                             }
                             else
                             {
-                                lesson.attend=0;
+                                if (studentLessonData.attend==1)
+                                {
+                                    lesson.attend=1;
+                                }
+                                else
+                                {
+                                    lesson.attend=0;
+                                }
                             }
+                            studentSemester.les.Add(lesson);
                         }
-                        studentSemester.les.Add(lesson);
                     }
                 }
             }

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/StudentScoreRecord.cs

@@ -95,7 +95,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
     public class StuLessonLite 
     {
        
-      
+      public string id { get; set; }
         /// <summary>
         /// 上课教师
         /// </summary>