CrazyIter_Bin 1 年之前
父节点
当前提交
d8a1465db5

+ 1 - 1
TEAMModelOS.SDK/DI/AzureCosmos/AzureCosmosExtensions.cs

@@ -185,7 +185,7 @@ namespace TEAMModelOS.SDK.DI
                     {
                     {
                         continuationToken = item.GetContinuationToken();
                         continuationToken = item.GetContinuationToken();
                     }
                     }
-                    RU = item.RU();
+                    RU += item.RU();
                     if (pageSize.HasValue && pageSize.Value >= 0 && list.Count >= pageSize)
                     if (pageSize.HasValue && pageSize.Value >= 0 && list.Count >= pageSize)
                     {
                     {
                         break;
                         break;

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/School/CourseBase.cs

@@ -32,7 +32,7 @@ namespace TEAMModelOS.SDK.Models
         "creatorId": "1595321354",
         "creatorId": "1595321354",
         "school": "hbcn",
         "school": "hbcn",
         "color": "red", //用于标记课程表的排课颜色
         "color": "red", //用于标记课程表的排课颜色
-        "gradeId": 2, //年级
+        "grades": [0,1,2], //年级
         "status": 1
         "status": 1
     }
     }
      */
      */

+ 12 - 0
TEAMModelOS.SDK/Models/Cosmos/School/ExamImport.cs

@@ -151,10 +151,19 @@ namespace TEAMModelOS.SDK.Models.Cosmos.School
         /// 日常考核类型,需要将考核时间碎片化,如德育。
         /// 日常考核类型,需要将考核时间碎片化,如德育。
         /// </summary>
         /// </summary>
         public long time { get; set; }
         public long time { get; set; }
+        public string date { get; set; }
+        //学生入学年
+        public int stuYear { get; set; }
     }
     }
     public class ItemVlaue
     public class ItemVlaue
     {
     {
+        /// <summary>
+        /// 细项名称
+        /// </summary>
         public string code { get; set; }
         public string code { get; set; }
+        /// <summary>
+        /// 细项分数
+        /// </summary>
         public double value { get; set; }
         public double value { get; set; }
     }
     }
     /// <summary>
     /// <summary>
@@ -233,6 +242,9 @@ namespace TEAMModelOS.SDK.Models.Cosmos.School
         /// 小题得分,下标0顺序开始 第一题....N
         /// 小题得分,下标0顺序开始 第一题....N
         /// </summary>
         /// </summary>
         public List<double> scores { get; set; }
         public List<double> scores { get; set; }
+        /// <summary>
+        /// 德育细项
+        /// </summary>
         public List<ItemVlaue> items { get; set; }
         public List<ItemVlaue> items { get; set; }
         /// <summary>
         /// <summary>
         /// 日常考核类型,需要将考核时间碎片化,如德育。
         /// 日常考核类型,需要将考核时间碎片化,如德育。

+ 5 - 1
TEAMModelOS.SDK/Models/Cosmos/Student/OverallEducation.cs

@@ -128,7 +128,11 @@ namespace TEAMModelOS.SDK.Models
     /// 考核项目数据
     /// 考核项目数据
     /// </summary>
     /// </summary>
     public class ItemScore
     public class ItemScore
-    {
+    {  
+        /// <summary>
+        /// 项目id,科目id  ,选填
+        /// </summary>
+        public string id { get; set; }
         /// <summary>
         /// <summary>
         /// 项目名称
         /// 项目名称
         /// </summary>
         /// </summary>

+ 23 - 5
TEAMModelOS/Controllers/Both/CourseBaseController.cs

@@ -124,7 +124,7 @@ namespace TEAMModelOS.Controllers.Both
                             List<CourseBase> courseBases = _courses.ToObject<List<CourseBase>>();
                             List<CourseBase> courseBases = _courses.ToObject<List<CourseBase>>();
                             //1.检查导入的课程名称是否有效
                             //1.检查导入的课程名称是否有效
                             StringBuilder sqlName = new StringBuilder(" select  value c from c ");
                             StringBuilder sqlName = new StringBuilder(" select  value c from c ");
-                            sqlName.Append($" where c.name in {string.Join(",",courseBases.Select(z=>$"'{z.name}'"))}    and  c.period.id='{_periodId}' ");
+                            sqlName.Append($" where c.name in( {string.Join(",", courseBases.Select(z => $"'{z.name}'"))} )   and  c.period.id='{_periodId}' ");
                             string tbname =  Constant.School;
                             string tbname =  Constant.School;
                             List<CourseBase> courseBasesDB = new List<CourseBase>();
                             List<CourseBase> courseBasesDB = new List<CourseBase>();
                             await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
                             await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
@@ -154,8 +154,25 @@ namespace TEAMModelOS.Controllers.Both
                                         {
                                         {
                                             item.subject.name = subject.name;
                                             item.subject.name = subject.name;
                                         }
                                         }
+                                        else
+                                        {
+                                            return Ok(new { code = 1, msg = "科目不存在", course = item });
+                                        }
                                     }
                                     }
-                                    else { 
+                                    else {
+                                        return Ok(new { code = 1, msg = "科目不存在", course = item });
+                                    }
+                                    if (!string.IsNullOrWhiteSpace(item.major?.id))
+                                    {
+                                        var major = period.majors.Find(x => x.id.Equals(item.major.id));
+                                        if (major != null)
+                                        {
+                                            item.major.name = major.name;
+                                        }
+                                        else
+                                        {
+                                            return Ok(new { code = 2, msg = "专业不存在", course = item });
+                                        }
                                     }
                                     }
                                     var dbcoursebase = courseBasesDB.Find(x => x.name.Equals(item.name));
                                     var dbcoursebase = courseBasesDB.Find(x => x.name.Equals(item.name));
                                     if (dbcoursebase != null)
                                     if (dbcoursebase != null)
@@ -167,6 +184,7 @@ namespace TEAMModelOS.Controllers.Both
                                         item.no = string.IsNullOrWhiteSpace(item.no) ? dbcoursebase.no : item.no;
                                         item.no = string.IsNullOrWhiteSpace(item.no) ? dbcoursebase.no : item.no;
                                         item.grades = !item.grades.Any() ? dbcoursebase.grades : item.grades;
                                         item.grades = !item.grades.Any() ? dbcoursebase.grades : item.grades;
                                     }
                                     }
+                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(item,new PartitionKey(item.code));
                                 }
                                 }
                             }
                             }
                             return Ok(new { course = courseBases });
                             return Ok(new { course = courseBases });
@@ -646,7 +664,7 @@ namespace TEAMModelOS.Controllers.Both
                                 {
                                 {
                                     groupLists.Add(item);
                                     groupLists.Add(item);
                                 }
                                 }
-                                teachInvalidImports = courseCheckImports.ExceptBy(groupLists.Select(x => x.name), z => z.list);
+                                teachInvalidImports = teachList.ExceptBy(groupLists.Select(x => x.name), z => z.list);
                                 //保留课程名称存在的及醍摩豆ID有效的排课信息
                                 //保留课程名称存在的及醍摩豆ID有效的排课信息
                                 if (teachInvalidImports != null && teachInvalidImports.Any())
                                 if (teachInvalidImports != null && teachInvalidImports.Any())
                                 {
                                 {
@@ -911,7 +929,7 @@ namespace TEAMModelOS.Controllers.Both
                                                 groupId=groupId,
                                                 groupId=groupId,
                                                 type=item.type,
                                                 type=item.type,
                                                 teacherId=teacherId,
                                                 teacherId=teacherId,
-                                                times= new List<ScheduleTime> { scheduleTime },
+                                                times = scheduleTime!=null ? new List<ScheduleTime> { scheduleTime }: new List<ScheduleTime> {  },
                                                 school=school,
                                                 school=school,
                                            }
                                            }
                                         }
                                         }
@@ -928,7 +946,7 @@ namespace TEAMModelOS.Controllers.Both
                                             groupId = groupId,
                                             groupId = groupId,
                                             type = item.type,
                                             type = item.type,
                                             teacherId = teacherId,
                                             teacherId = teacherId,
-                                            times = new List<ScheduleTime> { scheduleTime },
+                                            times = scheduleTime!=null ? new List<ScheduleTime> { scheduleTime }: new List<ScheduleTime> {  },
                                             school = school,
                                             school = school,
                                         });
                                         });
                                     }
                                     }

+ 8 - 3
TEAMModelOS/Controllers/Both/GroupListController.cs

@@ -330,12 +330,16 @@ namespace TEAMModelOS.Controllers
                         await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: classsql.ToString(),
                         await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: classsql.ToString(),
                             requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
                             requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
                         {
                         {
+                            int scount=0;
                             HashSet<string> groupNames = new HashSet<string>();
                             HashSet<string> groupNames = new HashSet<string>();
-                            string gpsql = $"SELECT distinct c.groupId,c.groupName FROM c where  c.classId='{item.id}'and c.groupName <>null";
+                            string gpsql = $"SELECT distinct c.groupId,c.groupName FROM c where  c.classId='{item.id}' ";
                             await foreach (var gp in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: gpsql,
                             await foreach (var gp in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: gpsql,
                                 requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{schoolId}") }))
                                 requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{schoolId}") }))
                             {
                             {
-                                groupNames.Add(gp.groupName);
+                                if (!string.IsNullOrWhiteSpace(gp.groupName)) {
+                                    groupNames.Add(gp.groupName);
+                                }
+                                scount += 1;
                             }
                             }
                             ///行政班(学生搜寻classId动态返回)class
                             ///行政班(学生搜寻classId动态返回)class
                             GroupListGrp group = new GroupListGrp
                             GroupListGrp group = new GroupListGrp
@@ -349,7 +353,8 @@ namespace TEAMModelOS.Controllers
                                 type = "class",
                                 type = "class",
                                 year = item.year,
                                 year = item.year,
                                 expire=0,
                                 expire=0,
-                                groupName = groupNames
+                                groupName = groupNames,
+                                scount= scount
                             };
                             };
                             groupLists.Add(group);
                             groupLists.Add(group);
                         }
                         }

+ 212 - 77
TEAMModelOS/Controllers/School/ImportExamController.cs

@@ -16,6 +16,7 @@ using System.ComponentModel;
 using System.Linq;
 using System.Linq;
 using System.Runtime.Intrinsics.Arm;
 using System.Runtime.Intrinsics.Arm;
 using System.Text.Json;
 using System.Text.Json;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using TEAMModelOS.Filter;
 using TEAMModelOS.Filter;
 using TEAMModelOS.Models;
 using TEAMModelOS.Models;
@@ -68,66 +69,140 @@ namespace TEAMModelOS.Controllers
         //[Authorize(Roles = "IES")]
         //[Authorize(Roles = "IES")]
         [AuthToken(Roles = "teacher,admin,business")]
         [AuthToken(Roles = "teacher,admin,business")]
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
-        public async Task<IActionResult> ReadExcelVirtue([FromForm] IFormFile file, [FromForm] string periodId) {
+        public async Task<IActionResult> ReadExcelVirtue([FromForm] IFormFile[] file, [FromForm] string periodId) {
+            var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
             List<KeyValuePair<string, List<string>>> error = new List<KeyValuePair<string, List<string>>>();
             List<KeyValuePair<string, List<string>>> error = new List<KeyValuePair<string, List<string>>>();
             List<KeyValuePair<string, List<string>>> warn = new List<KeyValuePair<string, List<string>>>();
             List<KeyValuePair<string, List<string>>> warn = new List<KeyValuePair<string, List<string>>>();
-            var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
+            List<VirtueImport> virtueImports = new List<VirtueImport> { };
+            //德育数据导入
+            School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new Azure.Cosmos.PartitionKey("Base"));
+            Period period = schoolBase.period.Find(x => x.id.Equals(periodId));
+            HashSet<Student> rightStudents = new HashSet<Student>();
+            List<Class> classes = new List<Class>();
+            List<Dictionary<string, object>> students = new List<Dictionary<string, object>>();
             ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
             ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
-            List<VirtueImport> virtueImports = new List<VirtueImport> {  };
-            using (ExcelPackage package = new ExcelPackage(file.OpenReadStream())) {
-                ExcelWorksheets sheet = package.Workbook.Worksheets;
-                //德育数据导入
-                School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new Azure.Cosmos.PartitionKey("Base"));
-                Period period = schoolBase.period.Find(x => x.id.Equals(periodId));
-                var daily_sheets = sheet.Where(z => !z.Name.Equals("栏位说明"));
-                HashSet<IdNameCode> rightStudents = new HashSet<IdNameCode>();
-                List<Class> classes = new List<Class>();
-                foreach (var daily_sheet in daily_sheets)
+            foreach (var f in file) {
+                using (ExcelPackage package = new ExcelPackage(f.OpenReadStream()))
                 {
                 {
-                    if (DateTimeOffset.TryParse(daily_sheet.Name, out DateTimeOffset sheetNameTime))
+                    ExcelWorksheets sheet = package.Workbook.Worksheets;
+                    var daily_sheets = sheet.Where(z => !z.Name.Equals("栏位说明"));
+                    foreach (var daily_sheet in daily_sheets)
                     {
                     {
-
                         var data = GetSubSheetData(daily_sheet, error);
                         var data = GetSubSheetData(daily_sheet, error);
-                        Dictionary<string, object> dailyData = new Dictionary<string, object> { { "subject", "德育" }, { "students", data.students } };
-                        ImportExamSubject importExamDaily = dailyData.ToJsonString().ToObject<ImportExamSubject>();
-                        var subject = period.subjects.Find(z => z.name.Equals(importExamDaily.subject));
-                        if (subject != null)
-                        {
-                            List<ResultImportStudent> examImportStudents = new List<ResultImportStudent>();
-                            //学生
-                            await ExamImportStudent(importExamDaily.students, rightStudents, school, period, examImportStudents, error, warn, classes, daily_sheet.Name);
-                            var semesterData=  SchoolService.GetSemester(period, sheetNameTime.ToUnixTimeMilliseconds());
-                            var group = examImportStudents.GroupBy(x => x.classId).Select(y => new { key = y.Key,list= y.ToList()} );
-                            foreach (var groupData in group) {
-                                VirtueImport virtueImport = new VirtueImport
+                        students.AddRange(data.students);
+                    }
+                }
+            }
+            Dictionary<string, object> dailyData = new Dictionary<string, object> { { "subject", "德育" }, { "students", students } };
+            ImportExamSubject importExamDaily = dailyData.ToJsonString().ToObject<ImportExamSubject>();
+            var subject = period.subjects.Find(z => z.name.Equals(importExamDaily.subject));
+            if (subject != null)
+            {
+                List<ResultImportStudent> examImportStudents = new List<ResultImportStudent>();
+                //学生
+                await ExamImportStudent(importExamDaily.students, rightStudents, school, period, examImportStudents, error, warn, classes,"");
+                List<KeyValuePair<string , (Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester)>> semesterDatas = new List<KeyValuePair<string, (Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester)>>();  
+                importExamDaily.students.GroupBy(x => x.time).Select(y => y.Key).ToList().ForEach(time => {
+                    var semesterData = SchoolService.GetSemester(period, time: time);
+                    semesterDatas.Add(new KeyValuePair<string, (Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester)>(time, semesterData));
+                });
+                var group = examImportStudents.GroupBy(x => new { classId = x.classId, date = x.date }).Select(y => new { key = y.Key, list = y.ToList() });
+                List<string> ids = new List<string>();
+                foreach (var groupData in group)
+                {
+                    var semesterData = semesterDatas.Find(x => x.Key.Equals(groupData.key.date)).Value;
+                    string id = $"{groupData.key.date}-{semesterData.currSemester.id}-{groupData.key.classId}";
+                    ids.Add(id);
+                }
+                if (ids.Any()) {
+                    string idsql = $"select value c from c where c.id in ({string.Join(",",ids.Select(z=>$"'{z}'"))}) ";
+                    var reuslt=  await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<VirtueImport>(idsql, $"VirtueImport-{school}");
+                    if (reuslt.list.IsNotEmpty()) { virtueImports.AddRange(reuslt.list); }
+                }
+                HashSet<VirtueImport> changeDataVirtueImports = new HashSet<VirtueImport>();
+                foreach (var groupData in group) {
+                    var semesterData = semesterDatas.Find(x => x.Key.Equals(groupData.key.date)).Value;
+                    string id = $"{groupData.key.date}-{semesterData.currSemester.id}-{groupData.key.classId}";
+                    string code = $"VirtueImport-{school}";
+                    var virtueImport = virtueImports.Find(x => x.id.Equals(id));
+                    if (virtueImport != null)
+                    {
+                        groupData.list.ForEach(z => {
+                            var student = virtueImport.students.Find(x => x.id.Equals(z.id) && x.date.Equals(z.date) && x.classId.Equals(z.classId) );
+                            if (student != null)
+                            {
+                                bool hasChange=false;
+                                //此处分数直接覆盖
+                                if (student.items.Count == z.items.Count)
                                 {
                                 {
-                                    time = sheetNameTime.ToUnixTimeMilliseconds(),
-                                    id = $"{semesterData.studyYear}-{semesterData.currSemester.id}-{groupData.key}",
-                                    code = $"VirtueImport-{school}",
-                                    pk = "VirtueImport",
-                                    ttl = -1,
-                                    semesterId = semesterData.currSemester.id,
-                                    periodId = period.id,
-                                    type = "日常",
-                                    school = school,
-                                    year = semesterData.studyYear,
-                                    classId=groupData.key,
-                                    students = groupData.list,
-                                    name=$"{semesterData.studyYear}-{semesterData.currSemester.name}"
-                                };
-                                virtueImports.Add(virtueImport);
+                                    
+                                    //为节约导入的RU成本开销检查导入分数是否有差异.
+                                    foreach (var item in z.items)
+                                    {
+                                        var noChangeData  = student.items.Find(x => x.code.Equals(item.code) && x.value==item.value );
+                                        //
+                                        if (noChangeData == null)
+                                        {
+                                            hasChange = true;
+                                            break;
+                                        }
+                                    }
+                                }
+                                else {
+                                    //两个的数量不同则是属于要修改的。
+                                    hasChange = true;
+                                }
+                                if (hasChange) {
+                                    student.items = z.items;
+                                    student.classId = z.classId;
+                                    student.date = z.date;
+                                    student.id = z.id;
+                                    student.stuYear = z.stuYear;
+                                    changeDataVirtueImports.Add(virtueImport);
+                                }
                             }
                             }
-                        }
-                        else
+                            else {
+                                changeDataVirtueImports.Add(virtueImport);
+                                virtueImport.students.Add(z);
+                            }
+                        });
+                    }
+                    else {
+                        virtueImport = new VirtueImport
                         {
                         {
-                            error.Add(new KeyValuePair<string, List<string>>("subject_invalid", new List<string> { importExamDaily.subject }));// 科目不存在
-                        }
+                            id = id,
+                            time = semesterData.date.ToUnixTimeMilliseconds(),
+                            code = code,
+                            pk = "VirtueImport",
+                            ttl = -1,
+                            semesterId = semesterData.currSemester.id,
+                            periodId = period.id,
+                            type = "日常",
+                            school = school,
+                            year = semesterData.studyYear,
+                            classId = groupData.key.classId,
+                            students = groupData.list,
+                            name = $"{semesterData.studyYear}-{semesterData.currSemester.name}-{groupData.key.date}"
+                        };
+                        changeDataVirtueImports.Add(virtueImport);
+                        virtueImports.Add(virtueImport);
                     }
                     }
-                    else { 
-                     
+                }
+                if (changeDataVirtueImports.Any())
+                {
+                    double ru = 0;
+                    //196条数据产生RU:2341.739999999998 
+                    foreach (var virtueImport in changeDataVirtueImports) {
+                        Azure.Cosmos.ItemResponse<VirtueImport> a =  await  _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).UpsertItemAsync<VirtueImport>(virtueImport, new Azure.Cosmos.PartitionKey(virtueImport.code));
+                        a.GetRawResponse().Headers.TryGetValue("x-ms-request-charge", out var value);
+                        ru=ru+ Convert.ToDouble(value);
                     }
                     }
                 }
                 }
             }
             }
+            else
+            {
+                error.Add(new KeyValuePair<string, List<string>>("subject_invalid", new List<string> { importExamDaily.subject }));// 科目不存在
+            }
             return Ok(new { virtueImports, error,warn});
             return Ok(new { virtueImports, error,warn});
         }
         }
         // [AuthToken(Roles = "teacher,admin")]
         // [AuthToken(Roles = "teacher,admin")]
@@ -288,7 +363,8 @@ namespace TEAMModelOS.Controllers
                 Period period = schoolBase.period.Find(x => x.id.Equals(importExam.periodId));
                 Period period = schoolBase.period.Find(x => x.id.Equals(importExam.periodId));
                 if (validData.isVaild)
                 if (validData.isVaild)
                 {
                 {
-                    string sql = $"select value c from c where c.name ='{importExam.name}'";
+                    var semesterData = SchoolService.GetSemester(period, time: importExam.time);
+                    string sql = $"select value c from c where c.name ='{importExam.name}' and c.periodId='{period.id}' and c.semesterId ='{semesterData.currSemester.id}' ";
                     var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamImport>(sql, $"ExamImport-{importExam.school}", pageSize: 1);
                     var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamImport>(sql, $"ExamImport-{importExam.school}", pageSize: 1);
                    
                    
                     if (string.IsNullOrEmpty(result.continuationToken))
                     if (string.IsNullOrEmpty(result.continuationToken))
@@ -299,31 +375,27 @@ namespace TEAMModelOS.Controllers
                     {
                     {
                         examImport = result.list[0];
                         examImport = result.list[0];
                         warn.Add(new KeyValuePair<string, List<string>>("name_update", new List<string> { importExam.name }));//同名评测数据更新
                         warn.Add(new KeyValuePair<string, List<string>>("name_update", new List<string> { importExam.name }));//同名评测数据更新
-
                     }
                     }
                     if (examImport == null)
                     if (examImport == null)
                     {
                     {
-                        examImport = new ExamImport { name = importExam.name, type = importExam.type, school = importExam.school,periodId=period.id,code= $"ExamImport-{importExam.school}",pk= "ExamImport", };
+                        examImport = new ExamImport { year= semesterData.studyYear,name = importExam.name, type = importExam.type, school = importExam.school,periodId=period.id,code= $"ExamImport-{importExam.school}",pk= "ExamImport", };
                         if (DateTimeOffset.TryParse(importExam.time, out DateTimeOffset dateTime))
                         if (DateTimeOffset.TryParse(importExam.time, out DateTimeOffset dateTime))
                         {
                         {
                             examImport.time = dateTime.ToUnixTimeMilliseconds();
                             examImport.time = dateTime.ToUnixTimeMilliseconds();
-                            var semesterData= SchoolService.GetSemester(period, examImport.time);
+                           
                             examImport.semesterId = semesterData.currSemester.id;
                             examImport.semesterId = semesterData.currSemester.id;
-                            examImport.id = $"{semesterData.studyYear}-{ShaHashHelper.GetSHA1(examImport.name)}";
+                            examImport.id = $"{semesterData.studyYear}-{ShaHashHelper.GetSHA1($"{period.id}-{semesterData.currSemester.id}-{examImport.name}")}";
                         }
                         }
                         else
                         else
                         {
                         {
                             error.Add(new KeyValuePair<string, List<string>>("time_format", new List<string> { importExam.time }));//  时间格式错误
                             error.Add(new KeyValuePair<string, List<string>>("time_format", new List<string> { importExam.time }));//  时间格式错误
                         }
                         }
                     }
                     }
-
-                  
-
                     if (period != null)
                     if (period != null)
                     {
                     {
                         //用于处理多学科,不需要重复查询学习基础信息
                         //用于处理多学科,不需要重复查询学习基础信息
                         //id  学生id  code 行政班id  name  学生姓名
                         //id  学生id  code 行政班id  name  学生姓名
-                        HashSet<IdNameCode> rightStudents = new HashSet<IdNameCode>();
+                        HashSet<Student> rightStudents = new HashSet<Student>();
                         List<Class> classes = new List<Class>();
                         List<Class> classes = new List<Class>();
                         foreach (var item in importExam.subjects)
                         foreach (var item in importExam.subjects)
                         {
                         {
@@ -332,9 +404,40 @@ namespace TEAMModelOS.Controllers
                             {
                             {
                                 List<ResultImportStudent> examImportStudents = new List<ResultImportStudent>();
                                 List<ResultImportStudent> examImportStudents = new List<ResultImportStudent>();
                                 //学生
                                 //学生
-                               await  ExamImportStudent(item.students, rightStudents, school, period, examImportStudents, error, warn, classes, item.subject);
-
-                                examImport.subjects.Add(new ExamImportSubject { id = subject.id, name = subject.name, students = examImportStudents, }) ;
+                                await  ExamImportStudent(item.students, rightStudents, school, period, examImportStudents, error, warn, classes, item.subject);
+                                //配分
+                                List<ExamImportItem> examImportItems = new List<ExamImportItem>();
+                                foreach (var itemItem in item.items)
+                                {
+                                    string[] ps = Regex.Split(itemItem.point, "\\.|\\.|\\、|\\:|\\:|\\,|\\,|\\;|\\;");
+                                    var points = ps.Distinct().ToHashSet();
+                                    ExamImportItem examImportItem = new ExamImportItem() { 
+                                        point=points,
+                                        index=itemItem.index,
+                                        filed=itemItem.filed,
+                                        type=itemItem.type,
+                                        score=itemItem.score,
+                                    };
+                                    examImportItems.Add(examImportItem);
+                                }
+                                var examImportSubject= examImport.subjects.Find(x => x.id.Equals(subject.id));
+                                if (examImportSubject != null)
+                                {
+                                    examImportSubject.name = subject.name;
+                                    foreach (var stu in examImportStudents) {
+                                        var student =  examImportSubject.students.Find(x => x.id.Equals(stu.id));
+                                        if (student != null)
+                                        {
+                                            student = stu;
+                                        }
+                                        else {
+                                            examImportSubject.students.Add(stu);
+                                        }
+                                    }
+                                }
+                                else {
+                                    examImport.subjects.Add(new ExamImportSubject { id = subject.id, name = subject.name, students = examImportStudents, items = examImportItems });
+                                }
                             }
                             }
                             else
                             else
                             {
                             {
@@ -363,11 +466,12 @@ namespace TEAMModelOS.Controllers
                         errorData.Add(new KeyValuePair<string, HashSet<string>>(x.Key,x.Value.ToHashSet()));
                         errorData.Add(new KeyValuePair<string, HashSet<string>>(x.Key,x.Value.ToHashSet()));
                     }
                     }
                 });
                 });
+                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).UpsertItemAsync(examImport, new Azure.Cosmos.PartitionKey(examImport.code));
                 return Ok(new { code = 400, error = errorData, examImport });
                 return Ok(new { code = 400, error = errorData, examImport });
             } 
             } 
         }
         }
 
 
-        private async Task ExamImportStudent(List<ImportResultStudent> importExamStudents, HashSet<IdNameCode> rightStudents,string  school,
+        private async Task ExamImportStudent(List<ImportResultStudent> importExamStudents, HashSet<Student> rightStudents,string  school,
             Period period, List<ResultImportStudent> examImportStudents, List<KeyValuePair<string, List<string>>> error,
             Period period, List<ResultImportStudent> examImportStudents, List<KeyValuePair<string, List<string>>> error,
             List<KeyValuePair<string, List<string>>> warn, List<Class> classes, string sheetName)
             List<KeyValuePair<string, List<string>>> warn, List<Class> classes, string sheetName)
         {
         {
@@ -380,8 +484,8 @@ namespace TEAMModelOS.Controllers
             if (needSearch.Any())
             if (needSearch.Any())
             {
             {
                 ///在rightStudents找不到的学生需要查询数据库。
                 ///在rightStudents找不到的学生需要查询数据库。
-                string stuidsql = $"select c.id,c.classId as code , c.name  from  c where c.id in ({string.Join(",", needSearch.Select(x => $"'{x.id}'"))}) and c.periodId='{period.id}' ";
-                var sturesult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<IdNameCode>(stuidsql, $"Base-{school}");
+                string stuidsql = $"select value c  from  c where c.id in ({string.Join(",", needSearch.Select(x => $"'{x.id}'"))}) and c.periodId='{period.id}' ";
+                var sturesult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(stuidsql, $"Base-{school}");
                 if (sturesult.list.IsNotEmpty())
                 if (sturesult.list.IsNotEmpty())
                 {
                 {
                     sturesult.list.ForEach(x => {
                     sturesult.list.ForEach(x => {
@@ -409,19 +513,25 @@ namespace TEAMModelOS.Controllers
                 if (existStudent .Any())
                 if (existStudent .Any())
                 {
                 {
                     long time = 0;
                     long time = 0;
-                    if (DateTimeOffset.TryParse(item.time, out DateTimeOffset dateTime))
+                    string date = string.Empty;
+                    DateTimeOffset dateTime = DateTimeOffset.Now;
+                     
+                    if (!string.IsNullOrWhiteSpace(item.time)  &&  DateTimeOffset.TryParse(item.time, out  dateTime))
                     {
                     {
                         time = dateTime.ToUnixTimeMilliseconds();
                         time = dateTime.ToUnixTimeMilliseconds();
+                        date = dateTime.ToString("yyyy-MM-dd");
                     }
                     }
                     examImportStudents.Add(new ResultImportStudent
                     examImportStudents.Add(new ResultImportStudent
                     {
                     {
                         id = item.id,
                         id = item.id,
                         name = existStudent.First().name,
                         name = existStudent.First().name,
-                        classId = existStudent.First().code,
+                        classId = existStudent.First().classId,
                         score = item.score,
                         score = item.score,
                         scores = item.scores,
                         scores = item.scores,
                         time = time,
                         time = time,
+                        date = date,
                         items = item.items,
                         items = item.items,
+                        stuYear = existStudent.First().year,
                     });
                     });
                 }
                 }
             }
             }
@@ -519,8 +629,8 @@ namespace TEAMModelOS.Controllers
                 }
                 }
                 if (clzz != null)
                 if (clzz != null)
                 {
                 {
-                    string stuClassIdsql = $"select c.id,c.classId as code , c.name  from  c where c.name  in ({string.Join(",", classStudents.Select(x => $"'{x.name}'"))}) and c.classId ='{clzz.id}' and c.periodId='{period.id}' ";
-                    var sturesult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<IdNameCode>(stuClassIdsql, $"Base-{school}");
+                    string stuClassIdsql = $"select value c  from  c where c.name  in ({string.Join(",", classStudents.Select(x => $"'{x.name}'"))}) and c.classId ='{clzz.id}' and c.periodId='{period.id}' ";
+                    var sturesult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(stuClassIdsql, $"Base-{school}");
                     //检查重名
                     //检查重名
                     if (sturesult.list.IsNotEmpty())
                     if (sturesult.list.IsNotEmpty())
                     {
                     {
@@ -536,19 +646,24 @@ namespace TEAMModelOS.Controllers
                             {
                             {
 
 
                                 long time = 0;
                                 long time = 0;
-                                if (DateTimeOffset.TryParse(stu.time, out DateTimeOffset dateTime))
+                                string date = string.Empty;
+                                DateTimeOffset dateTime = DateTimeOffset.Now;
+                                if (!string.IsNullOrWhiteSpace(stu.time) && DateTimeOffset.TryParse(stu.time, out   dateTime))
                                 {
                                 {
                                     time = dateTime.ToUnixTimeMilliseconds();
                                     time = dateTime.ToUnixTimeMilliseconds();
+                                    date = dateTime.ToString("yyyy-MM-dd");
                                 }
                                 }
                                 examImportStudents.Add(new ResultImportStudent
                                 examImportStudents.Add(new ResultImportStudent
                                 {
                                 {
                                     id = student[0].id,
                                     id = student[0].id,
                                     name = student[0].name,
                                     name = student[0].name,
-                                    classId = student[0].code,
+                                    classId = student[0].classId,
                                     score = stu.score,
                                     score = stu.score,
                                     scores = stu.scores,
                                     scores = stu.scores,
                                     time = time,
                                     time = time,
-                                    items = stu.items
+                                    date = date,
+                                    items = stu.items,
+                                    stuYear = student[0].year,
                                 });
                                 });
                             }
                             }
                         }
                         }
@@ -625,20 +740,38 @@ namespace TEAMModelOS.Controllers
                         double score = 0;
                         double score = 0;
                         if (double.TryParse(datas[i][j], out score))
                         if (double.TryParse(datas[i][j], out score))
                         {
                         {
-                            items.Add(new ItemVlaue() { code = titles[j].Replace("item_", ""), value = score });
+                            //德育细项分数为0 不纳入计算
+                            if (score != 0)
+                            {
+                                items.Add(new ItemVlaue() { code = titles[j].Replace("item_", ""), value = score });
+                            }
+
                         }
                         }
                         else if (string.IsNullOrWhiteSpace(datas[i][j]))
                         else if (string.IsNullOrWhiteSpace(datas[i][j]))
                         {
                         {
-                            items.Add(new ItemVlaue() { code = titles[j].Replace("item_", ""), value = score });
+                            //德育细项为空 不纳入计算
+                            //items.Add(new ItemVlaue() { code = titles[j].Replace("item_", ""), value = score });
+                        }
+                        else
+                        {
+                            error.Add(new KeyValuePair<string, List<string>>("score_invalid", new List<string> { datas[i][j] }));// 得分只能是数字
+                        }
+
+                    }
+                    else if (titles[j].Equals("time")) {
+
+                        if (!string.IsNullOrWhiteSpace(datas[i][j])  &&   DateTimeOffset.TryParse(datas[i][j], out DateTimeOffset dateTime))
+                        {
+
+                            item.Add(titles[j], dateTime.ToString("yyyy-MM-dd"));
                         }
                         }
                         else {
                         else {
-                            error.Add(new KeyValuePair<string, List<string>>("score_invalid",new List<string> { datas[i][j] }));// 得分只能是数字
+                            error.Add(new KeyValuePair<string, List<string>>("time_format", new List<string> { datas[i][j] }));// 时间格式错误
                         }
                         }
-                        
                     }
                     }
                     else
                     else
                     {
                     {
-                        if (titles[j].Equals("score")  )
+                        if (titles[j].Equals("score"))
                         {
                         {
                             if (double.TryParse(datas[i][j], out double score))
                             if (double.TryParse(datas[i][j], out double score))
                             {
                             {
@@ -648,14 +781,16 @@ namespace TEAMModelOS.Controllers
                             {
                             {
                                 item.Add(titles[j], 0);
                                 item.Add(titles[j], 0);
                             }
                             }
-                            else {
+                            else
+                            {
                                 error.Add(new KeyValuePair<string, List<string>>("score_invalid", new List<string> { datas[i][j] }));// 得分只能是数字
                                 error.Add(new KeyValuePair<string, List<string>>("score_invalid", new List<string> { datas[i][j] }));// 得分只能是数字
                             }
                             }
                         }
                         }
-                        else {
+                        else
+                        {
                             item.Add(titles[j], datas[i][j]);
                             item.Add(titles[j], datas[i][j]);
                         }
                         }
-                       
+
                     }
                     }
                 }
                 }
                 var orders = _index_order.OrderBy(x => x.Key).ToList();
                 var orders = _index_order.OrderBy(x => x.Key).ToList();