CrazyIter_Bin 2 gadi atpakaļ
vecāks
revīzija
fc1cfd78ad

+ 4 - 2
TEAMModelOS.SDK/Models/Service/Common/SyllabusService.cs

@@ -28,7 +28,7 @@ namespace TEAMModelOS.SDK.Services
         /// <param name="pid"></param>
         /// <param name="pid"></param>
         /// <param name="newNodes"></param>
         /// <param name="newNodes"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public async static Task<(List<List<IdCode>> idCodes, List<SyllabusTreeNode> tree)> ImportSyllabus(List<List<string>> nodes,string volumeId,string scope ,string code,string creatorId ,string creatorName, AzureCosmosFactory azureCosmos, bool ignoreCharacter = true) { 
+        public async static Task<(List<List<IdCode>> idCodes, List<SyllabusTreeNode> tree)> ImportSyllabus(List<List<string>> nodes,string volumeId,string scope ,string code,string creatorId ,string creatorName,string grant_type, AzureCosmosFactory azureCosmos, bool ignoreCharacter = true) { 
             HashSet<Syllabus> syllabuses= new HashSet<Syllabus>();
             HashSet<Syllabus> syllabuses= new HashSet<Syllabus>();
             string tbname = scope.Equals("school", StringComparison.OrdinalIgnoreCase) ? Constant.School : Constant.Teacher;
             string tbname = scope.Equals("school", StringComparison.OrdinalIgnoreCase) ? Constant.School : Constant.Teacher;
             await foreach (var item in azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c where c.volumeId='{volumeId}'",
             await foreach (var item in azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c where c.volumeId='{volumeId}'",
@@ -142,7 +142,9 @@ namespace TEAMModelOS.SDK.Services
                     volume.syllabusIds.Add(chapter.id);
                     volume.syllabusIds.Add(chapter.id);
                     volumeChange = true;
                     volumeChange = true;
                 }
                 }
-                await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(chapter);
+                if (!string.IsNullOrWhiteSpace(grant_type) && grant_type.Equals("upsert")) {
+                    await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(chapter);
+                }
                 List<SyllabusTree> trees = SyllabusService.ListToTree(chapter.children);
                 List<SyllabusTree> trees = SyllabusService.ListToTree(chapter.children);
                 SyllabusTreeNode tree = new SyllabusTreeNode() { id = chapter.id, scope = chapter.scope, trees = trees, volumeId = chapter.volumeId, auth = chapter.auth, codeval = code };
                 SyllabusTreeNode tree = new SyllabusTreeNode() { id = chapter.id, scope = chapter.scope, trees = trees, volumeId = chapter.volumeId, auth = chapter.auth, codeval = code };
                 treeNodes.Add(tree);
                 treeNodes.Add(tree);

+ 3 - 1
TEAMModelOS/Controllers/Both/SyllabusController.cs

@@ -66,11 +66,13 @@ namespace TEAMModelOS.Controllers
             if (!request.TryGetProperty("volumeId", out JsonElement _volumeId)) return BadRequest();
             if (!request.TryGetProperty("volumeId", out JsonElement _volumeId)) return BadRequest();
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
             if (!request.TryGetProperty("code", out JsonElement _code)) return BadRequest();
             if (!request.TryGetProperty("code", out JsonElement _code)) return BadRequest();
+            //操作类型  preview  upsert
+            if (!request.TryGetProperty("grant_type", out JsonElement _grant_type)) return BadRequest();
             bool ignoreCharacter = false;
             bool ignoreCharacter = false;
             if (request.TryGetProperty("ignoreCharacter", out JsonElement _ignoreCharacter)) {
             if (request.TryGetProperty("ignoreCharacter", out JsonElement _ignoreCharacter)) {
                 ignoreCharacter = _ignoreCharacter.ValueKind.Equals(JsonValueKind.True)?true:false;
                 ignoreCharacter = _ignoreCharacter.ValueKind.Equals(JsonValueKind.True)?true:false;
             }
             }
-            (List<List<IdCode>> idCodes, List<SyllabusTreeNode> tree) data =  await  SyllabusService.ImportSyllabus(nodes, $"{_volumeId}", $"{_scope}", $"{_code}", userid, name,_azureCosmos,ignoreCharacter);
+            (List<List<IdCode>> idCodes, List<SyllabusTreeNode> tree) data =  await  SyllabusService.ImportSyllabus(nodes, $"{_volumeId}", $"{_scope}", $"{_code}", userid, name,$"{_grant_type}",_azureCosmos,ignoreCharacter);
             return Ok(new {codes= data.idCodes, data.tree });
             return Ok(new {codes= data.idCodes, data.tree });
         }
         }
         /// <summary>
         /// <summary>