|
@@ -128,8 +128,8 @@ namespace TEAMModelOS.Controllers
|
|
/// <param name="schoolId"></param>
|
|
/// <param name="schoolId"></param>
|
|
/// <param name="students"></param>
|
|
/// <param name="students"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- private (Dictionary<string, (string name, string no, string year, string salt, string pw, string classNo, string className)> studs,
|
|
|
|
- Dictionary<string, string> classInfo,
|
|
|
|
|
|
+ private (Dictionary<string, (string name, string no, string year, string salt, string pw, string classNo, string className, string periodId, int gradeIndex)> studs,
|
|
|
|
+ Dictionary<string, (string className, string periodId, int gradeIndex)> classInfo,
|
|
Dictionary<string, List<(string id, string no)>> classStudNo,
|
|
Dictionary<string, List<(string id, string no)>> classStudNo,
|
|
List<string> errorYear,
|
|
List<string> errorYear,
|
|
List<string> duplId) doSortImpStuds(string schoolId, JsonElement.ArrayEnumerator students)
|
|
List<string> duplId) doSortImpStuds(string schoolId, JsonElement.ArrayEnumerator students)
|
|
@@ -137,13 +137,10 @@ namespace TEAMModelOS.Controllers
|
|
//批量匯入 檢查輸入數據 確認座號 確認教室(創建教室) 確認學生存不存在或是要不要更新
|
|
//批量匯入 檢查輸入數據 確認座號 確認教室(創建教室) 確認學生存不存在或是要不要更新
|
|
|
|
|
|
//存放輸入的學生資訊 key:stud id value:學生詳細資料
|
|
//存放輸入的學生資訊 key:stud id value:學生詳細資料
|
|
- Dictionary<string, (string name, string no, string year, string salt, string pw, string classNo, string className)> dicStuds = new Dictionary<string, (string name, string no, string year, string salt, string pw, string classNo, string className)>();
|
|
|
|
-
|
|
|
|
- ////欲加入的教室no
|
|
|
|
- //List<string> wantJoinClassNo = new List<string>();
|
|
|
|
|
|
+ Dictionary<string, (string name, string no, string year, string salt, string pw, string classNo, string className, string periodId, int gradeIndex)> dicStuds = new Dictionary<string, (string name, string no, string year, string salt, string pw, string classNo, string className, string periodId, int gradeIndex)>();
|
|
|
|
|
|
//存放教室資訊用 key:classNo value:className
|
|
//存放教室資訊用 key:classNo value:className
|
|
- Dictionary<string, string> dicClassInfo = new Dictionary<string, string>();
|
|
|
|
|
|
+ Dictionary<string, (string className, string periodId, int gradeIndex)> dicClassInfo = new Dictionary<string, (string className, string periodId, int gradeIndex)>();
|
|
//存放欲加入該間教室的學生座號清單 key:classNo value:no list
|
|
//存放欲加入該間教室的學生座號清單 key:classNo value:no list
|
|
Dictionary<string, List<(string id, string no)>> dicClassStudNo = new Dictionary<string, List<(string id, string no)>>();
|
|
Dictionary<string, List<(string id, string no)>> dicClassStudNo = new Dictionary<string, List<(string id, string no)>>();
|
|
//存放輸入id重複
|
|
//存放輸入id重複
|
|
@@ -176,7 +173,7 @@ namespace TEAMModelOS.Controllers
|
|
dicStuds.Remove(id);
|
|
dicStuds.Remove(id);
|
|
}
|
|
}
|
|
|
|
|
|
- (string name, string no, string year, string salt, string pw, string classNo, string className) studentInfo = (null, null, null, null, null, null, null);
|
|
|
|
|
|
+ (string name, string no, string year, string salt, string pw, string classNo, string className, string periodId, int gradeIndex) studentInfo = (null, null, null, null, null, null, null, null, -1);
|
|
|
|
|
|
if (student.TryGetProperty("name", out var tmpName) && !string.IsNullOrWhiteSpace(tmpName.GetString())) studentInfo.name = tmpName.GetString();
|
|
if (student.TryGetProperty("name", out var tmpName) && !string.IsNullOrWhiteSpace(tmpName.GetString())) studentInfo.name = tmpName.GetString();
|
|
|
|
|
|
@@ -195,6 +192,9 @@ namespace TEAMModelOS.Controllers
|
|
? Utils.HashedPassword(tmpPw.GetString(), studentInfo.salt)
|
|
? Utils.HashedPassword(tmpPw.GetString(), studentInfo.salt)
|
|
: Utils.HashedPassword(id, studentInfo.salt);
|
|
: Utils.HashedPassword(id, studentInfo.salt);
|
|
|
|
|
|
|
|
+ if (student.TryGetProperty("periodId", out var tmpPeriodId) && !string.IsNullOrWhiteSpace(tmpPeriodId.GetString())) studentInfo.periodId = tmpPeriodId.GetString();
|
|
|
|
+ if (student.TryGetProperty("gradeIndex", out var tmpGradeIndex)) studentInfo.gradeIndex = tmpGradeIndex.GetInt32();
|
|
|
|
+
|
|
|
|
|
|
if (student.TryGetProperty("classNo", out var tmpClassNo) && !string.IsNullOrWhiteSpace(tmpClassNo.GetString()))
|
|
if (student.TryGetProperty("classNo", out var tmpClassNo) && !string.IsNullOrWhiteSpace(tmpClassNo.GetString()))
|
|
{
|
|
{
|
|
@@ -214,10 +214,11 @@ namespace TEAMModelOS.Controllers
|
|
if (student.TryGetProperty("className", out var tmpClassName) && !string.IsNullOrWhiteSpace(tmpClassName.GetString()))
|
|
if (student.TryGetProperty("className", out var tmpClassName) && !string.IsNullOrWhiteSpace(tmpClassName.GetString()))
|
|
{
|
|
{
|
|
studentInfo.className = tmpClassName.GetString();
|
|
studentInfo.className = tmpClassName.GetString();
|
|
- if (!dicClassInfo.ContainsKey(tmpClassNo.GetString())) dicClassInfo.Add(tmpClassNo.GetString(), tmpClassName.GetString());
|
|
|
|
|
|
+ if (!dicClassInfo.ContainsKey(tmpClassNo.GetString()))
|
|
|
|
+ { dicClassInfo.Add(tmpClassNo.GetString(), (tmpClassName.GetString(), studentInfo.periodId, studentInfo.gradeIndex)); }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
//將最後結果加到字典內
|
|
//將最後結果加到字典內
|
|
dicStuds.Add(id, studentInfo);
|
|
dicStuds.Add(id, studentInfo);
|
|
}
|
|
}
|
|
@@ -265,12 +266,34 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
|
|
|
|
//這邊整理出不存在的教室,之後創建新教室用(比對classNo)。
|
|
//這邊整理出不存在的教室,之後創建新教室用(比對classNo)。
|
|
- var nonexistentClass = classNos.Except(classInfos.Select(o => o.Key).ToList());
|
|
|
|
- foreach (var item in nonexistentClass)
|
|
|
|
|
|
+ var nonexistentClassNo = classNos.Except(classInfos.Select(o => o.Key).ToList());
|
|
|
|
+ if (nonexistentClassNo.Count() != 0)
|
|
{
|
|
{
|
|
- var (classId, classNo, className) = await createClassInfo(schoolId, null, sortedImpData.classInfo[item], item);
|
|
|
|
- classStudNos.Add(classNo, new List<(string id, string no)>());
|
|
|
|
- classNoId.Add(classNo, (classId, null, null, null));
|
|
|
|
|
|
+ var gradesInfo = await getGrades(schoolId);
|
|
|
|
+ foreach (var item in nonexistentClassNo)
|
|
|
|
+ {
|
|
|
|
+ string gradeId = string.Empty;
|
|
|
|
+ string periodId = string.Empty;
|
|
|
|
+ //確認該學段存在及輸入的年級index正確(-1後大於等於0)
|
|
|
|
+ if (gradesInfo.ContainsKey(sortedImpData.classInfo[item].periodId) && sortedImpData.classInfo[item].gradeIndex - 1>=0)
|
|
|
|
+ {
|
|
|
|
+ periodId = sortedImpData.classInfo[item].periodId;
|
|
|
|
+ gradeId = gradesInfo[sortedImpData.classInfo[item].periodId][sortedImpData.classInfo[item].gradeIndex - 1].gradeId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //建立新教室
|
|
|
|
+ (string classId, string classNo, string className, string periodId, string gradeId) retCreateClassInfo =
|
|
|
|
+ await createClassInfo(
|
|
|
|
+ schoolId,
|
|
|
|
+ null,
|
|
|
|
+ sortedImpData.classInfo[item].className,
|
|
|
|
+ item,
|
|
|
|
+ periodId,
|
|
|
|
+ gradeId);
|
|
|
|
+
|
|
|
|
+ classStudNos.Add(retCreateClassInfo.classNo, new List<(string id, string no)>());
|
|
|
|
+ classNoId.Add(retCreateClassInfo.classNo, (retCreateClassInfo.classId, retCreateClassInfo.className, periodId, gradeId));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
var taskWhenAll = Task.WhenAll(tasks);
|
|
var taskWhenAll = Task.WhenAll(tasks);
|
|
@@ -556,7 +579,7 @@ namespace TEAMModelOS.Controllers
|
|
/// <param name="className"></param>
|
|
/// <param name="className"></param>
|
|
/// <param name="students"></param>
|
|
/// <param name="students"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- private async Task<(string classId, string classNo, string className)> createClassInfo(string schoolId, string classId, string className, string classNo)
|
|
|
|
|
|
+ private async Task<(string classId, string classNo, string className, string periodId, string gradeId)> createClassInfo(string schoolId, string classId, string className, string classNo, string periodId, string gradeId)
|
|
{
|
|
{
|
|
//組Class JSON
|
|
//組Class JSON
|
|
try
|
|
try
|
|
@@ -587,8 +610,12 @@ namespace TEAMModelOS.Controllers
|
|
writer.WriteNull("name");
|
|
writer.WriteNull("name");
|
|
writer.WriteEndObject();
|
|
writer.WriteEndObject();
|
|
|
|
|
|
- writer.WriteNull("gradeId");
|
|
|
|
- writer.WriteNull("periodId");
|
|
|
|
|
|
+ if (string.IsNullOrWhiteSpace(gradeId)) writer.WriteNull("gradeId");
|
|
|
|
+ else writer.WriteString("gradeId", gradeId);
|
|
|
|
+
|
|
|
|
+ if (string.IsNullOrWhiteSpace(periodId)) writer.WriteNull("periodId");
|
|
|
|
+ else writer.WriteString("periodId", periodId);
|
|
|
|
+
|
|
writer.WriteNull("sn");
|
|
writer.WriteNull("sn");
|
|
writer.WriteString("style", "smart");
|
|
writer.WriteString("style", "smart");
|
|
writer.WriteString("openType", "1");
|
|
writer.WriteString("openType", "1");
|
|
@@ -601,7 +628,7 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/createClassInfo()\nStatus:{ret.Status}\nSchoolId:{schoolId},ClassId:{classId}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/createClassInfo()\nStatus:{ret.Status}\nSchoolId:{schoolId},ClassId:{classId}", GroupNames.醍摩豆服務運維群組);
|
|
}
|
|
}
|
|
- return (cId, classNo, className);
|
|
|
|
|
|
+ return (cId, classNo, className, periodId, gradeId);
|
|
}
|
|
}
|
|
catch (CosmosException ex)
|
|
catch (CosmosException ex)
|
|
{
|
|
{
|
|
@@ -611,7 +638,7 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/createClassInfo()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/createClassInfo()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
}
|
|
}
|
|
- return (null,null,null);
|
|
|
|
|
|
+ return (null, null, null, null, null);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -1623,6 +1650,56 @@ namespace TEAMModelOS.Controllers
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 取得年級資訊
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="schoolId"></param>
|
|
|
|
+ /// <returns>Key:periodId Vaule:list gradeInfo</returns>
|
|
|
|
+ private async Task<Dictionary<string, List<(string gradeId, string gradeName)>>> getGrades(string schoolId)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ //Key:學制 Value:年級資訊list
|
|
|
|
+ Dictionary<string, List<(string gradeId, string gradeName)>> dicPeriod = new Dictionary<string, List<(string gradeId, string gradeName)>>();
|
|
|
|
+
|
|
|
|
+ var response = await _azureCosmos
|
|
|
|
+ .GetCosmosClient()
|
|
|
|
+ .GetContainer("TEAMModelOS", "School")
|
|
|
|
+ .ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
|
|
|
|
+
|
|
|
|
+ if (response.Status != (int)HttpStatusCode.OK) return null;
|
|
|
|
+
|
|
|
|
+ using Stream stream = response.ContentStream;
|
|
|
|
+ var jsonDoc = await JsonDocument.ParseAsync(stream);
|
|
|
|
+ var emumObject = jsonDoc.RootElement.EnumerateObject();
|
|
|
|
+ var period = jsonDoc.RootElement.GetProperty("period").EnumerateArray();
|
|
|
|
+
|
|
|
|
+ while (period.MoveNext())
|
|
|
|
+ {
|
|
|
|
+ JsonElement jsonPeriod = period.Current;
|
|
|
|
+ var periodId = jsonPeriod.GetProperty("id").GetString();
|
|
|
|
+ var grades = jsonPeriod.GetProperty("grades").EnumerateArray();
|
|
|
|
+
|
|
|
|
+ List<(string gradeId, string gradeName)> gradeInfos = new List<(string gradeId, string gradeName)>();
|
|
|
|
+
|
|
|
|
+ while (grades.MoveNext())
|
|
|
|
+ {
|
|
|
|
+ JsonElement grade = grades.Current;
|
|
|
|
+ var gradeId = grade.GetProperty("id").GetString();
|
|
|
|
+ var gradeName = grade.GetProperty("name").GetString();
|
|
|
|
+ gradeInfos.Add((gradeId, gradeName));
|
|
|
|
+ }
|
|
|
|
+ dicPeriod.Add(periodId, gradeInfos);
|
|
|
|
+ }
|
|
|
|
+ return dicPeriod;
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex)
|
|
|
|
+ {
|
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/getGrades()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private struct studCreateInfo
|
|
private struct studCreateInfo
|
|
{
|
|
{
|
|
public studCreateInfo(string id, string name, string gender, string year, string pw, string classId, string no)
|
|
public studCreateInfo(string id, string name, string gender, string year, string pw, string classId, string no)
|