|
@@ -93,7 +93,6 @@ namespace TEAMModelOS.Controllers
|
|
|
//只有ClassNo可以比對
|
|
|
var retUpsert = await upsertStudents(schoolId.GetString(), request.GetProperty("students").EnumerateArray());
|
|
|
//var objClassDuplNos = retUpsert.classDuplNos.Select(o=>new {o.Key,new { id = o.Value.Select(o => o.id), no = o.Value.Select(o=>o.no) } });
|
|
|
- var objClassDuplNos = retUpsert.classDuplNos.Select(o => new { classNo = o.Key });
|
|
|
return this.Ok(new { code = $"Base-{schoolId.GetString()}", students = retUpsert.studs, retUpsert.classDuplNos, retUpsert.errorIds });
|
|
|
case "read":
|
|
|
//讀取該間學校所有的學生資訊
|
|
@@ -226,7 +225,7 @@ namespace TEAMModelOS.Controllers
|
|
|
return (dicStuds, dicClassInfo, dicClassStudNo, errorYear, duplId);
|
|
|
}
|
|
|
|
|
|
- private async Task<(List<object> studs, Dictionary<string ,List<(string id,string no)>> classDuplNos, List<string> errorIds)> upsertStudents(
|
|
|
+ private async Task<(List<object> studs, Dictionary<string ,List<string>> classDuplNos, List<string> errorIds)> upsertStudents(
|
|
|
string schoolId,
|
|
|
JsonElement.ArrayEnumerator students)
|
|
|
|
|
@@ -282,7 +281,9 @@ namespace TEAMModelOS.Controllers
|
|
|
//建立學生或是更新學生,並且要確認座號是否重複
|
|
|
//每間教室的全部座號 欲更新的教室座號
|
|
|
//先新建帳號若出現409則進行資料更新
|
|
|
- Dictionary<string, List<(string id, string no)>> duplNos = new Dictionary<string, List<(string id, string no)>>();
|
|
|
+
|
|
|
+ //紀錄有重複做號的id
|
|
|
+ Dictionary<string, List<string>> duplNos = new Dictionary<string, List<string>>();
|
|
|
List<string> errorIds = new List<string>();
|
|
|
List<object> retStuds = new List<object>();
|
|
|
|
|
@@ -301,14 +302,14 @@ namespace TEAMModelOS.Controllers
|
|
|
classId = classNoId[stud.Value.classNo].classId;
|
|
|
(string id, string no) existNoInfo = (null, null);
|
|
|
//檢查要更新的座號是否已存在於雲端座號(已被其他同學使用)
|
|
|
- classStudNos[classId].ForEach(
|
|
|
+ classStudNos[stud.Value.classNo].ForEach(
|
|
|
o =>
|
|
|
{
|
|
|
if (o.no.Equals(stud.Value.no) && !o.id.Equals(stud.Key))
|
|
|
{
|
|
|
existNoInfo = (o.id, o.no);
|
|
|
- if (duplNos.ContainsKey(stud.Value.classNo)) duplNos[stud.Value.classNo].Add(o);
|
|
|
- else duplNos.Add(stud.Value.classNo, new List<(string id, string no)>() { o });
|
|
|
+ if (duplNos.ContainsKey(stud.Value.classNo)) duplNos[stud.Value.classNo].Add(stud.Key);
|
|
|
+ else duplNos.Add(stud.Value.classNo, new List<string>() { stud.Key });
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -318,20 +319,14 @@ namespace TEAMModelOS.Controllers
|
|
|
isContinue = true;
|
|
|
//TODO:同ID同NO下的檢查會有問題
|
|
|
//輪巡所有匯入的學生資料,並檢查匯入的座號。
|
|
|
- sortedImpData.classStudNo[classId].ForEach(
|
|
|
+ sortedImpData.classStudNo[stud.Value.classNo].ForEach(
|
|
|
o =>
|
|
|
{
|
|
|
- //雲端id跟匯入id一樣 且no一樣,故該筆資料不能更新no
|
|
|
- //if (o.id.Equals(existNoInfo.id) && o.no.Equals(existNoInfo.no))
|
|
|
- //{
|
|
|
- // duplNos.Add(o.no);
|
|
|
- // return;
|
|
|
- //}
|
|
|
if (o.id.Equals(existNoInfo.id) && !o.no.Equals(existNoInfo.no))
|
|
|
{
|
|
|
//可以更新該座號
|
|
|
isContinue = false;
|
|
|
- duplNos[stud.Value.classNo].Remove((existNoInfo.id, existNoInfo.no));
|
|
|
+ duplNos[stud.Value.classNo].Remove(stud.Key);
|
|
|
return;
|
|
|
}
|
|
|
});
|
|
@@ -480,7 +475,7 @@ namespace TEAMModelOS.Controllers
|
|
|
tmpStudInfo.periodId
|
|
|
});
|
|
|
}
|
|
|
- return (retStuds, duplNos.Where(o => o.Value.Count != 0).ToDictionary(o => o.Key, o => o.Value), errorIds);
|
|
|
+ return (retStuds, duplNos.Where(o => o.Value.Count != 0).ToDictionary(o=>o.Key,o=>o.Value), errorIds);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -777,15 +772,17 @@ namespace TEAMModelOS.Controllers
|
|
|
private async Task<List<object>> getAllStudent(string schoolId)
|
|
|
{
|
|
|
try
|
|
|
- { //TODO : 進階查詢選項調整
|
|
|
+ {
|
|
|
+ //TODO : 進階查詢選項調整、部分地方可用並行處理
|
|
|
//以學校學生角度去抓資料
|
|
|
-
|
|
|
- Dictionary<string, List<(string id, string name, string pic, string year, string no)>> dicClassStud = new Dictionary<string, List<(string id, string name, string pic, string year, string no)>>();
|
|
|
-
|
|
|
+ Dictionary<string, List<(string id, string name, string pic, string year, string no)>> dicClassStuds = new Dictionary<string, List<(string id, string name, string pic, string year, string no)>>();
|
|
|
+ List<(string id, string name, string pic, string year, string no)> notJoinClassStuds = new List<(string id, string name, string pic, string year, string no)>();
|
|
|
+
|
|
|
string queryText = $"SELECT c.id, c.name, c.picture, c.year, c.classId, c.no FROM c WHERE c.code = 'Base-{schoolId}'";
|
|
|
|
|
|
//回傳用ContinuationToken
|
|
|
string continuationToken = string.Empty;
|
|
|
+ var container = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student");
|
|
|
|
|
|
//進行學生資料的查詢 TEAMModelOS-Student
|
|
|
await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student")
|
|
@@ -804,10 +801,24 @@ namespace TEAMModelOS.Controllers
|
|
|
while (accounts.MoveNext())
|
|
|
{
|
|
|
JsonElement acc = accounts.Current;
|
|
|
+
|
|
|
string classId = acc.GetProperty("classId").GetString();
|
|
|
- if(dicClassStud.ContainsKey(classId))
|
|
|
+
|
|
|
+ if (string.IsNullOrWhiteSpace(classId))
|
|
|
+ {
|
|
|
+ notJoinClassStuds.Add(
|
|
|
+ (
|
|
|
+ acc.GetProperty("id").GetString(),
|
|
|
+ acc.GetProperty("name").GetString(),
|
|
|
+ acc.GetProperty("picture").GetString(),
|
|
|
+ acc.GetProperty("year").GetString(),
|
|
|
+ acc.GetProperty("no").GetString()
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else if(dicClassStuds.ContainsKey(classId))
|
|
|
{
|
|
|
- dicClassStud[classId].Add(
|
|
|
+ dicClassStuds[classId].Add(
|
|
|
(
|
|
|
acc.GetProperty("id").GetString(),
|
|
|
acc.GetProperty("name").GetString(),
|
|
@@ -819,7 +830,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dicClassStud.Add(classId,
|
|
|
+ dicClassStuds.Add(classId,
|
|
|
new List<(string id, string name, string pic, string year, string no)>()
|
|
|
{
|
|
|
(
|
|
@@ -840,10 +851,10 @@ namespace TEAMModelOS.Controllers
|
|
|
List<object> ret = new List<object>();
|
|
|
|
|
|
//查教室的資訊,用以取得gradeId,periodId資訊。
|
|
|
- var classInfos = await getClassInfoUseId(schoolId, dicClassStud.Keys.ToList());
|
|
|
+ var classInfos = await getClassInfoUseId(schoolId, dicClassStuds.Keys.ToList());
|
|
|
|
|
|
//輪循所有教室學生的資料
|
|
|
- foreach (var classStud in dicClassStud)
|
|
|
+ foreach (var classStud in dicClassStuds)
|
|
|
{
|
|
|
string classId = null, classNo = null, className = null, gradeId = null, periodId = null;
|
|
|
|
|
@@ -872,6 +883,23 @@ namespace TEAMModelOS.Controllers
|
|
|
});
|
|
|
ret.AddRange(tmp);
|
|
|
}
|
|
|
+
|
|
|
+ //彙整沒有加入教室的學生
|
|
|
+ notJoinClassStuds.ForEach(o=> ret.Add(
|
|
|
+ new
|
|
|
+ {
|
|
|
+ o.id,
|
|
|
+ o.name,
|
|
|
+ o.pic,
|
|
|
+ o.year,
|
|
|
+ o.no,
|
|
|
+ classId = (string)null,
|
|
|
+ classNo = (string)null,
|
|
|
+ className = (string)null,
|
|
|
+ gradeId = (string)null,
|
|
|
+ periodId = (string)null
|
|
|
+ }));
|
|
|
+
|
|
|
return ret;
|
|
|
}
|
|
|
catch (CosmosException ex)
|
|
@@ -1813,6 +1841,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
JsonElement account = accounts.Current;
|
|
|
string id = account.GetProperty("id").GetString();
|
|
|
+ nonexistentIds.Remove(id);
|
|
|
//舊的座號,基本上不會重複,但可能會是空的
|
|
|
string no = account.GetProperty("no").GetString();
|
|
|
|