|
@@ -129,7 +129,7 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <param name="students"></param>
|
|
|
/// <returns></returns>
|
|
|
private (Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int gradeIndex)> studs,
|
|
|
- Dictionary<string, (string className, string periodId, int gradeIndex, int year)> classInfo,
|
|
|
+ Dictionary<string, (string className, string periodId, int gradeIndex, int year, string no )> classInfo,
|
|
|
Dictionary<string, List<(string id, string no)>> classStudNo,
|
|
|
List<string> errorYear,
|
|
|
List<string> duplId) doSortImpStuds(string schoolId, JsonElement.ArrayEnumerator students)
|
|
@@ -140,7 +140,7 @@ namespace TEAMModelOS.Controllers
|
|
|
Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int gradeIndex)> dicStuds = new Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int gradeIndex)>();
|
|
|
|
|
|
//存放教室資訊用 key:classNo value:className
|
|
|
- Dictionary<string, (string className, string periodId, int gradeIndex,int year)> dicClassInfo = new Dictionary<string, (string className, string periodId, int gradeIndex, int year)>();
|
|
|
+ Dictionary<string, (string className, string periodId, int gradeIndex,int year,string no)> dicClassInfo = new Dictionary<string, (string className, string periodId, int gradeIndex, int year,string no)>();
|
|
|
//存放欲加入該間教室的學生座號清單 key:classNo value:no list
|
|
|
Dictionary<string, List<(string id, string no)>> dicClassStudNo = new Dictionary<string, List<(string id, string no)>>();
|
|
|
//存放輸入id重複
|
|
@@ -220,8 +220,8 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
|
|
|
studentInfo.className = tmpClassName.GetString();
|
|
|
- if (!dicClassInfo.ContainsKey(tmpClassNo.GetString()))
|
|
|
- { dicClassInfo.Add(tmpClassNo.GetString(), (tmpClassName.GetString(), studentInfo.periodId, studentInfo.gradeIndex, year)); }
|
|
|
+ if (!dicClassInfo.ContainsKey($"{studentInfo.periodId}_{year}_{tmpClassNo.GetString()}"))
|
|
|
+ { dicClassInfo.Add($"{studentInfo.periodId}_{year}_{tmpClassNo.GetString()}", (tmpClassName.GetString(), studentInfo.periodId, studentInfo.gradeIndex, year, tmpClassNo.GetString())); }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -246,9 +246,9 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
var sortedImpData = doSortImpStuds(schoolId, students);
|
|
|
|
|
|
- List<string> classNos = sortedImpData.classInfo.Select(o => o.Key).ToList();
|
|
|
+ //var classNos = sortedImpData.classInfo.Select(o => new {key= o.Key, periodId=o.Value.periodId,index= o.Value.gradeIndex,year = o.Value.year }).ToList();
|
|
|
//抓到教室資訊
|
|
|
- var classInfos = await getClassInfoUseNo(schoolId, classNos);
|
|
|
+ var classInfos = await getClassInfoUseNo(schoolId, sortedImpData.classInfo);
|
|
|
//取出已存在教室的classId,後面查座號要用。
|
|
|
|
|
|
List<Task> tasks = new List<Task>();
|
|
@@ -259,22 +259,30 @@ namespace TEAMModelOS.Controllers
|
|
|
Dictionary<string, (string classId, string className, string periodId, string gradeId, int year)> classNoId = new Dictionary<string, (string classId, string className, string periodId, string gradeId, int year)>();
|
|
|
foreach (var classInfo in classInfos)
|
|
|
{
|
|
|
- string classGradeId = (classInfo.Value.TryGetProperty("gradeId", out JsonElement classGradeIdJson)) ? classGradeIdJson.GetString() : null;
|
|
|
- int classYear = (classInfo.Value.TryGetProperty("year", out JsonElement classYearJson)) ? classYearJson.GetInt32() : 0;
|
|
|
+ string classGradeId = classInfo.Value.gradeId;
|
|
|
+ int classYear = classInfo.Value.year;
|
|
|
classNoId.Add(classInfo.Key,
|
|
|
- (classInfo.Value.GetProperty("id").GetString(), classInfo.Value.GetProperty("name").GetString(), classInfo.Value.GetProperty("periodId").GetString(), classGradeId, classYear));
|
|
|
+ (classInfo.Value.id, classInfo.Value.name, classInfo.Value.periodId, classGradeId, classYear));
|
|
|
tasks.Add(
|
|
|
Task.Run(
|
|
|
async () =>
|
|
|
{
|
|
|
//(id,no)
|
|
|
- var studNo = await checkStudNo(schoolId, classInfo.Value.GetProperty("id").GetString());
|
|
|
+ var studNo = await checkStudNo(schoolId, classInfo.Value.id);
|
|
|
classStudNos.Add(classInfo.Key, studNo);
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
//這邊整理出不存在的教室,之後創建新教室用(比對classNo)。
|
|
|
- var nonexistentClassNo = classNos.Except(classInfos.Select(o => o.Key).ToList());
|
|
|
+ //var nonexistentClassNo = classNos.Except(classInfos.Select(o => o.Key).ToList());
|
|
|
+ List<string> exsitkey = new List<string>();
|
|
|
+ foreach (var classInfo in classInfos)
|
|
|
+ {
|
|
|
+ //$"{studentInfo.periodId}_{year}_{tmpClassNo.GetString()}"
|
|
|
+ var key = $"{classInfo.Value.periodId}_{classInfo.Value.year}_{classInfo.Value.no}";
|
|
|
+ exsitkey.Add(key);
|
|
|
+ }
|
|
|
+ var nonexistentClassNo = exsitkey.Except(sortedImpData.classInfo.Select(o => o.Key).ToList());
|
|
|
if (nonexistentClassNo.Count() != 0)
|
|
|
{
|
|
|
var gradesInfo = await getGrades(schoolId);
|
|
@@ -1186,29 +1194,20 @@ namespace TEAMModelOS.Controllers
|
|
|
/// 取得教室資訊,使用classNo進行查詢。
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- private async Task<Dictionary<string, JsonElement>> getClassInfoUseNo(string schoolId, List<string> classNos)
|
|
|
+ private async Task<Dictionary<string, Class>> getClassInfoUseNo(string schoolId, Dictionary<string, (string className, string periodId, int gradeIndex, int year,string no)> classNos)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ Dictionary<string, Class> dicClassInfo = new Dictionary<string, Class>();
|
|
|
if (!(classNos == null || classNos.Count == 0))
|
|
|
{
|
|
|
- string queryText = $"SELECT * FROM c WHERE c.code = 'Class-{schoolId}' AND c.no IN ({string.Join(",", classNos.Select(o => $"'{o}'"))})";
|
|
|
-
|
|
|
- Dictionary<string, JsonElement> dicClassInfo = new Dictionary<string, JsonElement>();
|
|
|
-
|
|
|
- await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
|
|
|
- .GetItemQueryStreamIterator(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+
|
|
|
+ foreach (var key in classNos.Keys) {
|
|
|
+ string queryText = $"SELECT * FROM c WHERE c.code = 'Class-{schoolId}' AND c.no='{classNos[key].no}' and c.year={classNos[key].year} and c.periodId='{classNos[key].periodId}' ";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
|
|
|
+ .GetItemQueryIterator<Class>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
|
|
|
{
|
|
|
- var classInfos = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (classInfos.MoveNext())
|
|
|
- {
|
|
|
- JsonElement account = classInfos.Current;
|
|
|
- string no = account.GetProperty("no").GetString();
|
|
|
- dicClassInfo.Add(no, account.Clone());
|
|
|
- }
|
|
|
+ dicClassInfo[item.id] = item;
|
|
|
}
|
|
|
}
|
|
|
return dicClassInfo;
|