|
@@ -478,7 +478,8 @@ namespace TEAMModelOS.SDK
|
|
|
/// <param name="schoolId"></param>
|
|
|
/// <param name="students"></param>
|
|
|
/// <returns></returns>
|
|
|
- private static (Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear, string guardian, string gName, string gPhone,string imei, List<StudentGuardian> guardians)> studs,
|
|
|
+ private static (Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear,
|
|
|
+ string guardian, string gName, string gPhone,string imei, List<StudentGuardian> guardians,string gender)> studs,
|
|
|
Dictionary<string, (string className, string periodId, int year, string no)> classInfo,
|
|
|
Dictionary<string, List<(string id, string no)>> classStudNo,
|
|
|
List<string> errorYear,
|
|
@@ -487,8 +488,10 @@ namespace TEAMModelOS.SDK
|
|
|
//批量匯入 檢查輸入數據 確認座號 確認教室(創建教室) 確認學生存不存在或是要不要更新
|
|
|
|
|
|
//存放輸入的學生資訊 key:stud id value:學生詳細資料
|
|
|
- Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear, string guardian, string gName, string gPhone, string imei, List<StudentGuardian> guardians) > dicStuds =
|
|
|
- new Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear, string guardian, string gName, string gPhone, string imei, List<StudentGuardian> guardians)>();
|
|
|
+ Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear,
|
|
|
+ string guardian, string gName, string gPhone, string imei, List<StudentGuardian> guardians,string gender) > dicStuds =
|
|
|
+ new Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear,
|
|
|
+ string guardian, string gName, string gPhone, string imei, List<StudentGuardian> guardians,string gender)>();
|
|
|
|
|
|
//存放教室資訊用 key:classNo value:className
|
|
|
Dictionary<string, (string className, string periodId, int year, string classNo)> dicClassInfo = new Dictionary<string, (string className, string periodId, int year, string classNo)>();
|
|
@@ -524,7 +527,9 @@ namespace TEAMModelOS.SDK
|
|
|
dicStuds.Remove(id);
|
|
|
}
|
|
|
|
|
|
- (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear, string guardian, string gName, string gPhone, string imei, List<StudentGuardian> guardians) studentInfo = (null, null, 0, null, null, null, null, null, 0, null, null, null, null, null) ;
|
|
|
+ (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear,
|
|
|
+ string guardian, string gName, string gPhone, string imei, List<StudentGuardian> guardians, string gender) studentInfo =
|
|
|
+ (null, null, 0, null, null, null, null, null, 0, null, null, null, null, null,null) ;
|
|
|
|
|
|
if (student.TryGetProperty("name", out var tmpName) && !string.IsNullOrWhiteSpace(tmpName.GetString())) studentInfo.name = tmpName.GetString();
|
|
|
|
|
@@ -590,6 +595,7 @@ namespace TEAMModelOS.SDK
|
|
|
studentInfo.guardians = guardians;
|
|
|
}
|
|
|
if (student.TryGetProperty("imei", out var tmpImei) && !string.IsNullOrWhiteSpace($"{tmpImei}")) studentInfo.imei = tmpImei.GetString();
|
|
|
+ if (student.TryGetProperty("gender", out var tmpgender) && !string.IsNullOrWhiteSpace($"{tmpgender}")) studentInfo.gender = tmpgender.GetString();
|
|
|
//將最後結果加到字典內
|
|
|
dicStuds.Add(id, studentInfo);
|
|
|
}
|
|
@@ -766,7 +772,9 @@ namespace TEAMModelOS.SDK
|
|
|
writerNew.WriteString("pw", stud.Value.pw);
|
|
|
if (string.IsNullOrWhiteSpace(stud.Value.name)) writerNew.WriteNull("name");
|
|
|
else writerNew.WriteString("name", stud.Value.name);
|
|
|
- writerNew.WriteString("gender", "M");
|
|
|
+ if (string.IsNullOrWhiteSpace(stud.Value.gender)) writerNew.WriteNull("gender");
|
|
|
+ else writerNew.WriteString("gender", stud.Value.gender);
|
|
|
+
|
|
|
writerNew.WriteNull("picture");
|
|
|
writerNew.WriteNull("mail");
|
|
|
writerNew.WriteNull("mobile");
|
|
@@ -846,6 +854,10 @@ namespace TEAMModelOS.SDK
|
|
|
{
|
|
|
student.no = stud.Value.no;
|
|
|
}
|
|
|
+ if (!string.IsNullOrWhiteSpace(stud.Value.gender))
|
|
|
+ {
|
|
|
+ student.gender = stud.Value.gender;
|
|
|
+ }
|
|
|
if (!string.IsNullOrWhiteSpace(stud.Value.classNo))
|
|
|
{
|
|
|
student.classId = classId;
|
|
@@ -862,11 +874,37 @@ namespace TEAMModelOS.SDK
|
|
|
}
|
|
|
tmpStudInfo.picture = student.picture;
|
|
|
if (!string.IsNullOrWhiteSpace(stud.Value.gPhone)) {
|
|
|
- var guardian = student.guardians.Find(x => !string.IsNullOrWhiteSpace(x.mobile) && x.mobile.Equals(stud.Value.gPhone));
|
|
|
- if (guardian != null)
|
|
|
+ List<Guardian> guardians = new List<Guardian>();
|
|
|
+ string sql = $"select distinct value (c) from c where c.mobile='{stud.Value.gPhone}' ";
|
|
|
+ await foreach (var item in cosmosContainer.GetItemQueryIterator<Guardian>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Guardian") })) {
|
|
|
+ guardians.Add(item);
|
|
|
+ }
|
|
|
+ if (guardians.Any())
|
|
|
{
|
|
|
- guardian.name = stud.Value.gName;
|
|
|
- guardian.relation = stud.Value.guardian;
|
|
|
+ guardians.ForEach(async x => {
|
|
|
+ GuardianStudent guardianStudent = x.students.Find(s => s.id.Equals(stud.Key) && s.code.Equals(schoolId));
|
|
|
+ if (guardianStudent == null) {
|
|
|
+ x.students.Add(new GuardianStudent { type=2,id=stud.Key,code=schoolId,name=stud.Value.name });
|
|
|
+ }
|
|
|
+ await cosmosContainer.ReplaceItemAsync(x, x.id, new PartitionKey(x.code));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Guardian guardian = new Guardian {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ code= "Base-Guardian",
|
|
|
+ pk= "Guardian",
|
|
|
+ mobile=stud.Value.gPhone,
|
|
|
+ name = stud.Value.gName,
|
|
|
+ students = new List<GuardianStudent> { new GuardianStudent { type = 2, id = stud.Key, code = schoolId, name = stud.Value.name } }
|
|
|
+ };
|
|
|
+ await cosmosContainer.CreateItemAsync(guardian, new PartitionKey(guardian.code));
|
|
|
+ }
|
|
|
+ var studentGuardian = student.guardians.Find(x => !string.IsNullOrWhiteSpace(x.mobile) && x.mobile.Equals(stud.Value.gPhone));
|
|
|
+ if (studentGuardian != null)
|
|
|
+ {
|
|
|
+ studentGuardian.name = stud.Value.gName;
|
|
|
+ studentGuardian.relation = stud.Value.guardian;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1066,6 +1104,39 @@ namespace TEAMModelOS.SDK
|
|
|
writer.WriteEndObject();
|
|
|
}
|
|
|
writer.WriteEndArray();
|
|
|
+
|
|
|
+ foreach (var studentGuardian in studCreateInfo.guardians) {
|
|
|
+ List<Guardian> guardians = new List<Guardian>();
|
|
|
+ string sql = $"select distinct value (c) from c where c.mobile='{studentGuardian.mobile}' ";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Student).GetItemQueryIterator<Guardian>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Guardian") }))
|
|
|
+ {
|
|
|
+ guardians.Add(item);
|
|
|
+ }
|
|
|
+ if (guardians.Any())
|
|
|
+ {
|
|
|
+ guardians.ForEach(async x => {
|
|
|
+ GuardianStudent guardianStudent = x.students.Find(s => s.id.Equals(studCreateInfo.id) && s.code.Equals(schoolId));
|
|
|
+ if (guardianStudent == null)
|
|
|
+ {
|
|
|
+ x.students.Add(new GuardianStudent { type = 2, id = studCreateInfo.id, code = schoolId, name = studCreateInfo.name });
|
|
|
+ }
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(x, x.id, new PartitionKey(x.code));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Guardian guardian = new Guardian
|
|
|
+ {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ code = "Base-Guardian",
|
|
|
+ pk = "Guardian",
|
|
|
+ mobile = studentGuardian.mobile,
|
|
|
+ name = studentGuardian.name,
|
|
|
+ students = new List<GuardianStudent> { new GuardianStudent { type = 2, id = studCreateInfo.id, code = schoolId, name = studCreateInfo.name } }
|
|
|
+ };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemAsync(guardian, new PartitionKey(guardian.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1834,7 +1905,8 @@ namespace TEAMModelOS.SDK
|
|
|
/// <param name="schoolId"></param>
|
|
|
/// <param name="students"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static async Task<(List<object> studs, Dictionary<string, List<string>> classDuplNos, List<string> nonexistentIds, List<string> errorIds, Dictionary<string, List<string>> errorNos, List<string> errorClassId)>
|
|
|
+ public static async Task<(List<object> studs, Dictionary<string, List<string>> classDuplNos, List<string> nonexistentIds, List<string> errorIds,
|
|
|
+ Dictionary<string, List<string>> errorNos, List<string> errorClassId)>
|
|
|
updateStudents(AzureCosmosFactory _azureCosmos, DingDing _dingDing, Option _option, string schoolId, JsonElement.ArrayEnumerator students)
|
|
|
{
|
|
|
try
|
|
@@ -1843,10 +1915,12 @@ namespace TEAMModelOS.SDK
|
|
|
|
|
|
//Key:id Value:學生基本資訊
|
|
|
var studentInfos
|
|
|
- = new Dictionary<string, (string salt, string pw, string name, int year, string picture, string gender, string mail, string mobile, string classId, string no, string periodId, string irs,string imei, List<StudentGuardian> guardians)>();
|
|
|
+ = new Dictionary<string, (string salt, string pw, string name, int year, string picture, string gender, string mail, string mobile,
|
|
|
+ string classId, string no, string periodId, string irs,string imei, List<StudentGuardian> guardians)>();
|
|
|
//用於進行座號是否重複查詢時使用
|
|
|
var classStuds
|
|
|
- = new Dictionary<string, List<(string id, string salt, string pw, string name, int year, string picture, string gender, string mail, string mobile, string classId, string no, string periodId)>>();
|
|
|
+ = new Dictionary<string, List<(string id, string salt, string pw, string name, int year, string picture, string gender, string mail, string mobile,
|
|
|
+ string classId, string no, string periodId)>>();
|
|
|
//紀錄教室"輸入"的學生座號是否有重複
|
|
|
var impClassDuplNo = new Dictionary<string, List<string>>();
|
|
|
//紀錄不存在的學生id
|
|
@@ -2183,8 +2257,74 @@ namespace TEAMModelOS.SDK
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ var stu = account.Deserialize<Student>();
|
|
|
+ if (stu.guardians.IsNotEmpty() && studentInfos[id].guardians!=null)
|
|
|
+ {
|
|
|
+ var mobiles = stu.guardians.Select(m => m.mobile);
|
|
|
+ var except = mobiles.Except(studentInfos[id].guardians.Select(x => x.mobile));
|
|
|
+ if (except.Any()) {
|
|
|
+ //清除移除的监护人
|
|
|
+ List<Guardian> guardians = new List<Guardian>();
|
|
|
+ string sql = $"select distinct value (c) from c where c.mobile in ({string.Join(",", except.Select(z => $"'{z}'"))} )";
|
|
|
+ await foreach (var guard in cosmosContainer.GetItemQueryIterator<Guardian>(queryText: sql,
|
|
|
+ requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Guardian") }))
|
|
|
+ {
|
|
|
+ guard.students.RemoveAll(s => s.id.Equals(id) && s.code.Equals(schoolId));
|
|
|
+ guardians.Add(guard);
|
|
|
+ }
|
|
|
+ guardians.ForEach(async x => {
|
|
|
+ if (x.students.IsNotEmpty())
|
|
|
+ {
|
|
|
+ try{await cosmosContainer.ReplaceItemAsync(x, x.id, new PartitionKey(x.code)); } catch {}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ await cosmosContainer.DeleteItemStreamAsync(x.id, new PartitionKey(x.code));
|
|
|
+ }
|
|
|
+ catch{
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
if (studentInfos[id].guardians.IsNotEmpty())
|
|
|
{
|
|
|
+
|
|
|
+ foreach (var gtudentGuardian in studentInfos[id].guardians)
|
|
|
+ {
|
|
|
+ List<Guardian> guardians = new List<Guardian>();
|
|
|
+ string sql = $"select distinct value (c) from c where c.mobile='{gtudentGuardian.mobile}' ";
|
|
|
+ await foreach (var guard in cosmosContainer.GetItemQueryIterator<Guardian>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Guardian") }))
|
|
|
+ {
|
|
|
+ guardians.Add(guard);
|
|
|
+ }
|
|
|
+ if (guardians.Any())
|
|
|
+ {
|
|
|
+ guardians.ForEach(async x => {
|
|
|
+ GuardianStudent guardianStudent = x.students.Find(s => s.id.Equals(id) && s.code.Equals(schoolId));
|
|
|
+ if (guardianStudent == null)
|
|
|
+ {
|
|
|
+ x.students.Add(new GuardianStudent { type = 2, id = id, code = schoolId, name = studentInfos[id].name });
|
|
|
+ }
|
|
|
+ try { await cosmosContainer.ReplaceItemAsync(x, x.id, new PartitionKey(x.code)); } catch { }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Guardian guardian = new Guardian
|
|
|
+ {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ code = "Base-Guardian",
|
|
|
+ pk = "Guardian",
|
|
|
+ mobile = gtudentGuardian.mobile,
|
|
|
+ name = gtudentGuardian.name,
|
|
|
+ students = new List<GuardianStudent> { new GuardianStudent { type = 2, id = id, code = schoolId, name = studentInfos[id].name } }
|
|
|
+ };
|
|
|
+ try { await cosmosContainer.CreateItemAsync(guardian, new PartitionKey(guardian.code)); } catch { }
|
|
|
+ }
|
|
|
+ }
|
|
|
writer.WriteStartArray("guardians");
|
|
|
|
|
|
foreach (var guardian in studentInfos[id].guardians)
|
|
@@ -2199,6 +2339,8 @@ namespace TEAMModelOS.SDK
|
|
|
writer.WriteEndObject();
|
|
|
}
|
|
|
writer.WriteEndArray();
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|