|
@@ -1895,44 +1895,67 @@ namespace TEAMModelOS.Controllers
|
|
|
try
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
+ var schoolClient = client.GetContainer("TEAMModelOS", "School");
|
|
|
+ var teacherClient = client.GetContainer("TEAMModelOS", "Teacher");
|
|
|
+ var studentClient = client.GetContainer("TEAMModelOS", "Student");
|
|
|
//參數取得
|
|
|
if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
if (!request.TryGetProperty("pw", out JsonElement pw)) return BadRequest();
|
|
|
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "Student").ReadItemStreamAsync(id.GetString(), new PartitionKey($"Base-{school_code.GetString().ToLower()}"));
|
|
|
+ var response = await studentClient.ReadItemStreamAsync(id.GetString(), new PartitionKey($"Base-{school_code.GetString().ToLower()}"));
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
var rjson = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
rjson.RootElement.TryGetProperty("salt", out JsonElement salt);
|
|
|
rjson.RootElement.TryGetProperty("pw", out JsonElement dbpw);
|
|
|
rjson.RootElement.TryGetProperty("name", out JsonElement name);
|
|
|
- rjson.RootElement.TryGetProperty("picture", out JsonElement picture);
|
|
|
+ rjson.RootElement.TryGetProperty("picture", out JsonElement picture);
|
|
|
+ rjson.RootElement.TryGetProperty("classId", out JsonElement classId);
|
|
|
+ rjson.RootElement.TryGetProperty("no", out JsonElement no);
|
|
|
+ rjson.RootElement.TryGetProperty("groupId", out JsonElement groupId);
|
|
|
+ rjson.RootElement.TryGetProperty("groupName", out JsonElement groupName);
|
|
|
|
|
|
var HashedPW = Utils.HashedPassword(pw.ToString(), salt.ToString());
|
|
|
if (HashedPW.Equals(dbpw.GetString()))
|
|
|
{
|
|
|
- string classid = string.Empty;
|
|
|
+ //班級課程
|
|
|
object classinfo = null;
|
|
|
List<object> courses = new List<object>();
|
|
|
- //去學校找出所屬校本預設班級信息
|
|
|
- var query = $"SELECT c.code, c.id, c.name, c.periodId, c.gradeId FROM c JOIN cs IN c.students WHERE cs.id = '{id}'";
|
|
|
- var school = client.GetContainer("TEAMModelOS", "School");
|
|
|
- await foreach (var item in school.GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_code}") }))
|
|
|
+ ////校本
|
|
|
+ //取得所屬預設班級信息
|
|
|
+ if (!classId.ValueKind.Equals(JsonValueKind.Null) && classId.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ var query = $"SELECT c.code, c.id, c.name, c.periodId, c.gradeId FROM c WHERE c.id = '{classId.GetString()}'";
|
|
|
+ await foreach (var item in schoolClient.GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ classinfo = obj.ToObject<object>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //取得該學生跑班課名單ID
|
|
|
+ List<string> stulistidsSch = new List<string>();
|
|
|
+ var querysl = $"SELECT c.id FROM c JOIN students IN c.students WHERE students.id = '{id.GetString()}' AND students.code = 'Base-{school_code}'";
|
|
|
+ await foreach (var item in schoolClient.GetItemQueryStreamIterator(queryText: querysl, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{school_code}") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
{
|
|
|
foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- classid = obj.GetProperty("id").GetString();
|
|
|
- classinfo = obj.ToObject<object>();
|
|
|
+ stulistidsSch.Add(obj.GetProperty("id").ToString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //找出所屬班級的課程列表
|
|
|
- var queryc = $"SELECT VALUE cc.course FROM c JOIN cc IN c.courses WHERE c.id = '{classid}'";
|
|
|
- await foreach (var item in school.GetItemQueryStreamIterator(queryText: queryc, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{school_code}") }))
|
|
|
+ //取得該學生的學校課程名單
|
|
|
+ var queryc = $"SELECT DISTINCT c.id, c.name, schedule.class, schedule.time, schedule.notice, c.scope FROM c JOIN schedule IN c.schedule WHERE (schedule.class.id = '{classId}' AND schedule.stulist = null) OR (ARRAY_CONTAINS({JsonSerializer.Serialize(stulistidsSch)}, schedule.stulist, true))";
|
|
|
+ await foreach (var item in schoolClient.GetItemQueryStreamIterator(queryText: queryc, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school_code}") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
@@ -1943,10 +1966,71 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ ////個人
|
|
|
+ //取得該學生跑班課名單ID
|
|
|
+ Dictionary<string, Dictionary<string, string>> stulistidsTea = new Dictionary<string, Dictionary<string, string>>();
|
|
|
+ var queryslt = $"SELECT c.id, c.course.id as courseId, c.course.code as courseCode FROM c JOIN students IN c.students WHERE students.id = '{id.GetString()}' AND students.code = 'Base-{school_code}'";
|
|
|
+ await foreach (var item in teacherClient.GetItemQueryStreamIterator(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("StuList") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ string courseCode = obj.GetProperty("courseCode").ToString();
|
|
|
+ string courseId = obj.GetProperty("courseId").ToString();
|
|
|
+ string stulistId = obj.GetProperty("id").ToString();
|
|
|
+ if (!stulistidsTea.ContainsKey(courseCode))
|
|
|
+ {
|
|
|
+ Dictionary<string, string> pCourseIdDic = new Dictionary<string, string>();
|
|
|
+ pCourseIdDic.Add(courseId, stulistId);
|
|
|
+ stulistidsTea.Add(courseCode, pCourseIdDic);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(!stulistidsTea[courseCode].ContainsKey(courseId))
|
|
|
+ {
|
|
|
+ stulistidsTea[courseCode].Add(courseId, stulistId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //取得該學生的老師個人課程名單
|
|
|
+ foreach (KeyValuePair<string, Dictionary<string, string>> item in stulistidsTea)
|
|
|
+ {
|
|
|
+ string courseCode = item.Key;
|
|
|
+ Dictionary<string, string> courseIdDic = item.Value;
|
|
|
+ string stucourseWhere = string.Empty;
|
|
|
+ foreach (KeyValuePair<string, string> itemDic in courseIdDic) {
|
|
|
+ string courseId = itemDic.Key;
|
|
|
+ string stuListId = itemDic.Value;
|
|
|
+ if(!string.IsNullOrWhiteSpace(stucourseWhere))
|
|
|
+ {
|
|
|
+ stucourseWhere += " OR ";
|
|
|
+ }
|
|
|
+ stucourseWhere += $"( c.id = '{courseId}' AND schedule.stulist = '{stuListId}' )";
|
|
|
+ }
|
|
|
+ var querycst = $"SELECT DISTINCT c.id, c.name, schedule.class, schedule.time, schedule.notice, c.scope FROM c JOIN schedule IN c.schedule WHERE {stucourseWhere}";
|
|
|
+ await foreach (var itemcs in teacherClient.GetItemQueryStreamIterator(queryText: querycst, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{courseCode}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(itemcs.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ courses.Add(obj.ToObject<object>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// BLOB(學校,唯讀)
|
|
|
var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(school_code.GetString().ToLower(), BlobContainerSasPermissions.Read);
|
|
|
+
|
|
|
//換取AuthToken,提供給前端
|
|
|
var auth_token = JwtAuthExtension.CreateAuthToken(_option.HostName, id.GetString(), name.GetString(), picture.GetString(), _option.JwtSecretKey, schoolID: school_code.GetString(), roles: new[] { "student" });
|
|
|
+
|
|
|
return Ok(new { error = 0, auth_token, blob_uri, blob_sas, classinfo, courses });
|
|
|
}
|
|
|
else
|