Prechádzať zdrojové kódy

[API-Student]將DB資料庫指向正式位置。

Mickey 4 rokov pred
rodič
commit
11d00ad4a9

+ 22 - 22
TEAMModelOS/Controllers/School/StudentController.cs

@@ -192,7 +192,7 @@ namespace TEAMModelOS.Controllers
             Dictionary<string, string> classInfo = new Dictionary<string, string>();
             try
             {
-                var container = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student");
+                var container = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student");
                 while (students.MoveNext())
                 {
                     JsonElement current = students.Current;
@@ -384,7 +384,7 @@ namespace TEAMModelOS.Controllers
                 writer.WriteEndObject();
                 writer.Flush();
 
-                var ret = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "School").CreateItemStreamAsync(memoryStream, new PartitionKey($"Class-{schoolId}"));
+                var ret = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemStreamAsync(memoryStream, new PartitionKey($"Class-{schoolId}"));
                 if (ret.Status != (int)HttpStatusCode.Created)
                 {
                     await _dingDing.SendBotMsg($"OS,{_option.Location},Student/createClassInfo()\nStatus:{ret.Status}\nSchoolId:{schoolId},ClassId:{classId}", GroupNames.醍摩豆服務運維群組);
@@ -463,7 +463,7 @@ namespace TEAMModelOS.Controllers
                 //回傳用ContinuationToken
                 string continuationToken = string.Empty;
                 //進行學生資料的查詢
-                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student")
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student")
                    .GetItemQueryStreamIterator(
                        queryText: queryText,
                        continuationToken: token,
@@ -489,7 +489,7 @@ namespace TEAMModelOS.Controllers
                 List<object> ret = new List<object>();
                 //查教室資訊,使用上面的學生id並透過子查詢查詢。
                 queryText = $"SELECT c.id, c.name, c.gradeId, c.students FROM c JOIN (SELECT VALUE t FROM t IN c.students WHERE t.id IN ({string.Join(",", listStudent.Select(o => $"'{o.id}'"))}))";
-                await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "School")
+                await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
                    .GetItemQueryStreamIterator(
                    queryText: queryText,
                    //continuationToken: token,
@@ -572,7 +572,7 @@ namespace TEAMModelOS.Controllers
                 string continuationToken = string.Empty;
 
                 //進行學生資料的查詢 TEAMModelOS-Student
-                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student")
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student")
                    .GetItemQueryStreamIterator(
                        queryText: queryText,
                        requestOptions: new QueryRequestOptions()
@@ -596,7 +596,7 @@ namespace TEAMModelOS.Controllers
                 List<object> ret = new List<object>();
                 //查教室資訊,使用上面的學生id並透過子查詢查詢。
                 queryText = $"SELECT c.id, c.students, c.gradeId , c.periodId FROM c WHERE c.code = 'Class-{schoolId}'";
-                await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "School")
+                await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
                    .GetItemQueryStreamIterator(
                    queryText: queryText,
                    //continuationToken: token,
@@ -700,7 +700,7 @@ namespace TEAMModelOS.Controllers
                 string queryText = $"SELECT DISTINCT VALUE c FROM c JOIN (SELECT VALUE t FROM t IN c.students WHERE t.id IN ({string.Join(",", ids.Select(o => $"'{o}'"))}))";
                 List<object> listStudent = new List<object>();
 
-                await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "School")
+                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);
@@ -739,7 +739,7 @@ namespace TEAMModelOS.Controllers
                 if (!string.IsNullOrWhiteSpace(classId)) queryText += $" AND c.id = '{classId}'";
                 Dictionary<string, JsonElement> listStudent = new Dictionary<string, JsonElement>();
 
-                await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "School")
+                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);
@@ -777,7 +777,7 @@ namespace TEAMModelOS.Controllers
             {
                 var exceptions = new List<Exception>();
 
-                var container = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student");
+                var container = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student");
                 while (students.MoveNext())
                 {
                     string id = string.Empty;
@@ -847,7 +847,7 @@ namespace TEAMModelOS.Controllers
                 {
                     //使用子查詢來查詢students欄位裡面是否有相符的學生
                     var queryText = $"SELECT VALUE c FROM c JOIN (SELECT VALUE t FROM t IN c.students WHERE t.id IN ({string.Join(",", studs.Select(o => $"'{o}'"))}))";
-                    await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "School")
+                    await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
                                     .GetItemQueryStreamIterator(
                                         queryText: queryText,
                                         requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
@@ -903,7 +903,7 @@ namespace TEAMModelOS.Controllers
 
                                 var ret = await _azureCosmos
                                     .GetCosmosClient()
-                                    .GetContainer("TEAMModelOSTemp", "School")
+                                    .GetContainer("TEAMModelOS", "School")
                                     .ReplaceItemStreamAsync(memoryStream, id, new PartitionKey($"Class-{schoolId}"));
                                 if (ret.Status != (int)HttpStatusCode.OK)
                                 {
@@ -961,7 +961,7 @@ namespace TEAMModelOS.Controllers
                     //查該教室的學生
                     using var response = await _azureCosmos
                         .GetCosmosClient()
-                        .GetContainer("TEAMModelOSTemp", "School")
+                        .GetContainer("TEAMModelOS", "School")
                         .ReadItemStreamAsync(importItem.Key, new PartitionKey($"Class-{schoolId}"));
                     {
                         //組出新的JSON
@@ -1073,7 +1073,7 @@ namespace TEAMModelOS.Controllers
 
                         var ret = await _azureCosmos
                                         .GetCosmosClient()
-                                        .GetContainer("TEAMModelOSTemp", "School")
+                                        .GetContainer("TEAMModelOS", "School")
                                         .UpsertItemStreamAsync(memoryStream, new PartitionKey($"Class-{schoolId}"));
 
                         retClassStud.Add(classId, (periodId, gradeId, importItem.Value.Select(o => o.id).ToList()));
@@ -1106,7 +1106,7 @@ namespace TEAMModelOS.Controllers
 
                     Dictionary<string, JsonElement> dicClassInfo = new Dictionary<string, JsonElement>();
 
-                    await foreach (Response item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "School")
+                    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);
@@ -1212,7 +1212,7 @@ namespace TEAMModelOS.Controllers
                 //將資料更新到資料庫
                 if (studentsInfos.Count != 0)
                 {
-                    CosmosContainer cosmosContainer = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student");
+                    CosmosContainer cosmosContainer = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student");
                     //查學生的基本資料
                     string queryText = $"SELECT * FROM c WHERE c.pk = 'Base' AND c.id IN ({string.Join(",", studentsInfos.Select(o => $"'{o.Key}'"))})";
 
@@ -1487,7 +1487,7 @@ namespace TEAMModelOS.Controllers
                             {
                                 var ret = await _azureCosmos
                                     .GetCosmosClient()
-                                    .GetContainer("TEAMModelOSTemp", "School")
+                                    .GetContainer("TEAMModelOS", "School")
                                     .ReplaceItemStreamAsync(memoryStream, classId, new PartitionKey($"Class-{schoolId}"));
                             }
                             catch (CosmosException ex)
@@ -1578,7 +1578,7 @@ namespace TEAMModelOS.Controllers
                             {
                                 var ret = await _azureCosmos
                                     .GetCosmosClient()
-                                    .GetContainer("TEAMModelOSTemp", "School")
+                                    .GetContainer("TEAMModelOS", "School")
                                     .ReplaceItemStreamAsync(memoryStream, classId, new PartitionKey($"Class-{schoolId}"));
                             }
                             catch (CosmosException ex)
@@ -1621,7 +1621,7 @@ namespace TEAMModelOS.Controllers
             var exceptions = new List<Exception>();
             try
             {
-                var container = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student");
+                var container = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student");
 
                 Parallel.ForEach(userStudents, async item =>
                 {
@@ -1686,7 +1686,7 @@ namespace TEAMModelOS.Controllers
                     }
                 }
 
-                CosmosContainer cosmosContainer = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Student");
+                CosmosContainer cosmosContainer = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student");
                 //查學生的基本資料
                 string queryText = $"SELECT * FROM c WHERE c.pk = 'Base' AND c.id IN ({string.Join(",", studentsInfo.Select(o => $"'{o.Key}'"))})";
 
@@ -1779,7 +1779,7 @@ namespace TEAMModelOS.Controllers
             bool classExistFlg = false;
             List<object> courses = new List<object>();
 
-            var response = await client.GetContainer("TEAMModelOSTemp", "Student").ReadItemStreamAsync(id.GetString(), new PartitionKey($"Base-{school_code.ToString().ToLower()}"));
+            var response = await client.GetContainer("TEAMModelOS", "Student").ReadItemStreamAsync(id.GetString(), new PartitionKey($"Base-{school_code.ToString().ToLower()}"));
             if (response.Status == 200)
             {
                 var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -1798,7 +1798,7 @@ namespace TEAMModelOS.Controllers
                     (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(blobPath, BlobContainerSasPermissions.Read);
                     //所屬班級資訊
                     var query = $"SELECT c.code, c.id, c.name, c.periodId, c.gradeId FROM c JOIN cs IN c.students WHERE cs.id = '{id}'";
-                    await foreach (var item in client.GetContainer("TEAMModelOSTemp", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_code}") }))
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_code}") }))
                     {
                         var jsoncm = await JsonDocument.ParseAsync(item.ContentStream);
                         if (jsoncm.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
@@ -1815,7 +1815,7 @@ namespace TEAMModelOS.Controllers
                     {
                         string classId = classinfo.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 client.GetContainer("TEAMModelOSTemp", "School").GetItemQueryStreamIterator(queryText: queryc, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{school_code}") }))
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: queryc, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{school_code}") }))
                         {
                             using var jsoncm = await JsonDocument.ParseAsync(item.ContentStream);
                             if (jsoncm.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)