Browse Source

优化新增学段接口。

Li 2 years ago
parent
commit
7a9e96e041
1 changed files with 15 additions and 5 deletions
  1. 15 5
      TEAMModelBI/Controllers/BISchool/SchoolController.cs

+ 15 - 5
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -2199,7 +2199,7 @@ namespace TEAMModelBI.Controllers.BISchool
 
 
         /// <summary>
-        /// 添加没有学段的学校
+        /// 添加学段的学校
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
@@ -2208,11 +2208,14 @@ namespace TEAMModelBI.Controllers.BISchool
         public async Task<IActionResult> SetAllScPeriod(JsonElement jsonElement)
         {
             jsonElement.TryGetProperty("Language", out JsonElement Language);
+            jsonElement.TryGetProperty("scId", out JsonElement scId);
+            jsonElement.TryGetProperty("periodName", out JsonElement periodName);
             var cosmosClient = _azureCosmos.GetCosmosClient();
             var builder = $"{_environment.ContentRootPath}/JsonFile/Preset/LangSchoolConfig.json";
             StreamReader streamReader = new(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
             StringBuilder stringBuilder = new();
             string text;
+            string scName = "默认学段";
             while ((text = streamReader.ReadLine()) != null)
             {
                 stringBuilder.Append(text.ToString());
@@ -2233,20 +2236,27 @@ namespace TEAMModelBI.Controllers.BISchool
             }
             string campusId = Guid.NewGuid().ToString();
 
-            string noPeriodScSql = $"SELECT value(c) FROM c where c.code='Base' and c.period=[]";
+            StringBuilder noPeriodScSql = new("SELECT value(c) FROM c ");
             List<School> allSc = new();
 
-            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(noPeriodScSql,requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
+            if (!string.IsNullOrEmpty($"{scId}"))
+                noPeriodScSql.Append($" where c.id='{scId}'");
+            else
+                noPeriodScSql.Append($" where c.code='Base' and c.period=[]");
+
+            if (!string.IsNullOrEmpty($"{periodName}"))
+                scName = $"{periodName}";
+
+            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(noPeriodScSql.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
             {
                 allSc.Add(item);
             }
-
             foreach (var school in allSc)
             {
                 school.period.Add(new Period
                 {
                     id = Guid.NewGuid().ToString(),
-                    name = "默认学段",
+                    name = scName,
                     campusId = campusId,
                     semesters = new List<Semester>() { new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
                         new Semester { name = schoolConfig.semester[1].term, start = schoolConfig.semester[1].start, month = schoolConfig.semester[1].month, day = schoolConfig.semester[1].day, id = Guid.NewGuid().ToString() } },