CrazyIter_Bin il y a 4 ans
Parent
commit
5f96513ab6

+ 1 - 5
TEAMModelOS.SDK/Models/Cosmos/Common/Volume.cs

@@ -72,11 +72,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         //public int resourceCount { get; set; }
         //public int itemCount { get; set; }
         /// <summary>
-        /// 发布层级 类型 school  teacher
-        /// </summary>
-        public string owner { get; set; }
-        /// <summary>
-        /// 学校编码或教师tmdid
+        /// 学校编码
         /// </summary>
         [Required(ErrorMessage = "school 必须设置")]
         public string school { get; set; }

+ 109 - 114
TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

@@ -35,80 +35,90 @@ namespace TEAMModelOS.Controllers
             _azureCosmos = azureCosmos;
         }
 
-    /*
-    {
-      "id": "hbcn108774752059002880",
-      "code": "Syllabus-hbcn",
-      "trees": [
-          {
-              "id": "111111-111-44E7-8DD9-A6CB6D0D52F2",
-              "pid": "hbcn108515325535981568",
-              "title": "第一章",
-              "order": 0,
-              "type": 1,
-              "children": [
-                  {
-                      "id": "22222-111-447E-8A52-BFCD63E61D33",
-                      "pid": "111111-111-44E7-8DD9-A6CB6D0D52F2",
-                      "title": "第一节333",
-                      "order": 0,
-                      "type": 1,
-                      "children": [
-                          {
-                              "id": "3333-111-447E-8A52-BFCD63E61D33",
-                              "pid": "22222-111-447E-8A52-BFCD63E61D33",
-                              "title": "第一节333",
-                              "order": 0,
-                              "type": 1
-                          },
-                          {
-                              "id": "4444-111-447E-8A52-BFCD63E61D33",
-                              "pid": "22222-111-447E-8A52-BFCD63E61D33",
-                              "title": "第一节333",
-                              "order": 0,
-                              "type": 1
-                          }
-                      ]
-                  }
-              ]
-          },
-          {
-              "id": "111111-222-44E7-8DD9-A6CB6D0D52F2",
-              "pid": "hbcn108515325535981568",
-              "title": "第一章",
-              "order": 0,
-              "type": 1,
-              "children": [
-                  {
-                      "id": "22222-222-447E-8A52-BFCD63E61D33",
-                      "pid": "111111-222-44E7-8DD9-A6CB6D0D52F2",
-                      "title": "第一节333",
-                      "order": 0,
-                      "type": 1,
-                      "children": [
-                          {
-                              "id": "3333-222-447E-8A52-BFCD63E61D33",
-                              "pid": "22222-222-447E-8A52-BFCD63E61D33",
-                              "title": "第一节333",
-                              "order": 0,
-                              "type": 1
-                          }
-                      ]
-                  },
-                  {
-                      "id": "5555-222-447E-8A52-BFCD63E61D33",
-                      "pid": "111111-222-44E7-8DD9-A6CB6D0D52F2",
-                      "title": "第一节333",
-                      "order": 0,
-                      "type": 1,
-                      "children": []
-                  }
-              ]
-          }
-      ]
-    }
+        /*
+        {
+          "id": "hbcn108774752059002880",
+          "code": "Syllabus-hbcn",
+          "trees": [
+              {
+                  "id": "111111-111-44E7-8DD9-A6CB6D0D52F2",
+                  "pid": "hbcn108515325535981568",
+                  "title": "第一章",
+                  "order": 0,
+                  "type": 1,
+                  "rnodes":[
+                      {
+                            "type":"item/paper/res/link"//试题 ,试卷,内容资源,外部链接(只有link,和name)
+                            "title":"",
+                            "id":"关联资源的id",
+                            "code":"关联资源的code",
+                            "link":["https;//www.xxx.com/xxx.json"],
+                            ""
+                      }
+                   ],
+                  "children": [
+                      {
+                          "id": "22222-111-447E-8A52-BFCD63E61D33",
+                          "pid": "111111-111-44E7-8DD9-A6CB6D0D52F2",
+                          "title": "第一节333",
+                          "order": 0,
+                          "type": 1,
+                          "children": [
+                              {
+                                  "id": "3333-111-447E-8A52-BFCD63E61D33",
+                                  "pid": "22222-111-447E-8A52-BFCD63E61D33",
+                                  "title": "第一节333",
+                                  "order": 0,
+                                  "type": 1
+                              },
+                              {
+                                  "id": "4444-111-447E-8A52-BFCD63E61D33",
+                                  "pid": "22222-111-447E-8A52-BFCD63E61D33",
+                                  "title": "第一节333",
+                                  "order": 0,
+                                  "type": 1
+                              }
+                          ]
+                      }
+                  ]
+              },
+              {
+                  "id": "111111-222-44E7-8DD9-A6CB6D0D52F2",
+                  "pid": "hbcn108515325535981568",
+                  "title": "第一章",
+                  "order": 0,
+                  "type": 1,
+                  "children": [
+                      {
+                          "id": "22222-222-447E-8A52-BFCD63E61D33",
+                          "pid": "111111-222-44E7-8DD9-A6CB6D0D52F2",
+                          "title": "第一节333",
+                          "order": 0,
+                          "type": 1,
+                          "children": [
+                              {
+                                  "id": "3333-222-447E-8A52-BFCD63E61D33",
+                                  "pid": "22222-222-447E-8A52-BFCD63E61D33",
+                                  "title": "第一节333",
+                                  "order": 0,
+                                  "type": 1
+                              }
+                          ]
+                      },
+                      {
+                          "id": "5555-222-447E-8A52-BFCD63E61D33",
+                          "pid": "111111-222-44E7-8DD9-A6CB6D0D52F2",
+                          "title": "第一节333",
+                          "order": 0,
+                          "type": 1,
+                          "children": []
+                      }
+                  ]
+              }
+          ]
+        }
 
-          */
+              */
 
         /// <summary>
         /// 批量保存或更新课纲
@@ -120,9 +130,18 @@ namespace TEAMModelOS.Controllers
         [HttpPost("upsert-tree")]
         public async Task<IActionResult> SaveOrUpdateAsTree(SyllabusTreeNode request)
         {
-           var node = await SaveOrUpdateToTree(request);
-            ////return builder.Data(treess).build();
-            return Ok(node );
+            List<Tnode> nodes = new List<Tnode>();
+            Syllabus syllabus = new Syllabus();
+            SyllabusService.TreeToList(request.trees, nodes);
+            syllabus.children = nodes;
+            syllabus.id = !string.IsNullOrEmpty(request.id) ? request.id : Guid.NewGuid().ToString();
+            syllabus.code = $"Syllabus-{request.code}";
+            syllabus.pk = "Syllabus";
+            syllabus.ttl = -1;
+            await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync<Syllabus>(syllabus, new Azure.Cosmos.PartitionKey(syllabus.code));
+            List<SyllabusTree> trees = SyllabusService.ListToTree(nodes);
+            request.trees = trees;
+            return Ok(request);
         }
 
         // TODO 代码优化
@@ -144,6 +163,19 @@ namespace TEAMModelOS.Controllers
 
         // TODO 代码优化
 
+        /// <summary>
+        /// 查找课纲 
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("find-id")]
+        public async Task<IActionResult> Find(JsonElement request)
+        {
+            return Ok();
+        }
+        // TODO 代码优化
+
         /// <summary>
         /// 删除课纲
         /// </summary>
@@ -197,45 +229,8 @@ namespace TEAMModelOS.Controllers
 
         }
 
-        // TODO 代码优化
-
-        /// <summary>
-        /// 查找课纲 
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("find")]
-        public async Task<IActionResult> Find(JsonElement request)
-        {
-            return Ok();
-            //ResponseBuilder builder = ResponseBuilder.custom();
-            //Dictionary<string, object> dict = new Dictionary<string, object>();
-            //var emobj = request.EnumerateObject();
-            //while (emobj.MoveNext())
-            //{
-            //    dict[emobj.Current.Name] = emobj.Current.Value;
-            //}
-            //List<SyllabusTree> treess = await Find(dict);
-            ////return builder.Data(treess).build();
-            //return Ok(treess);
-        }
 
-        private async Task<SyllabusTreeNode> SaveOrUpdateToTree(SyllabusTreeNode request)
-        {
-            List<Tnode> nodes = new List<Tnode>();
-            Syllabus syllabus = new Syllabus();
-            SyllabusService.TreeToList(request.trees, nodes);
-            syllabus.children = nodes;
-            syllabus.id = !string.IsNullOrEmpty(request.id) ? request.id : Guid.NewGuid().ToString() ;
-            syllabus.code =$"Syllabus-{request.code}" ;
-            syllabus.pk = "Syllabus";
-            syllabus.ttl = -1;
-            await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync<Syllabus>(syllabus,new Azure.Cosmos.PartitionKey(syllabus.code));
-            List<SyllabusTree> trees = SyllabusService. ListToTree(nodes);
-            request.trees = trees;
-            return request;
-        }
+     
 
         private async Task<List<Tnode>> FindByPid(Tnode data, List<Tnode> nodes, List<Tnode> nodedata)
         {

+ 71 - 47
TEAMModelOS/Controllers/Syllabus/VolumeController.cs

@@ -78,7 +78,13 @@ namespace TEAMModelOS.Controllers
             }
         }
         /*
-         
+        {
+            "periodId": "学段id",
+            "subjectId": "科目id",//
+            "status": 1,//状态
+            "code": "学校编码或者tmdid",
+            "scope": "school/private"  如果是私人课纲 则学段科目id可以为空
+        }
          */
         /// <summary>
         /// 查找册别
@@ -90,70 +96,88 @@ namespace TEAMModelOS.Controllers
         [HttpPost("find")]
 
         public async Task<IActionResult> Find(JsonElement request) {
-            List<Syllabus> syllabuses = new List<Syllabus>();
+          //  List<Syllabus> syllabuses = new List<Syllabus>();
             List<Volume> volumes = new List<Volume>();
             request.TryGetProperty("periodId", out JsonElement periodCode);
             request.TryGetProperty("subjectId", out JsonElement subjectCode);
             request.TryGetProperty("status", out JsonElement status);
             if (request.TryGetProperty("code", out JsonElement code))
             {
-                request.TryGetProperty("type", out JsonElement type);
+                request.TryGetProperty("scope", out JsonElement scope);
                 //私有课纲
-                if (type.GetInt32() == 1)
+                if (scope.GetString()== "private")
                 {
-                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{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())
-                            {
-                                syllabuses.Add(obj.ToObject<Syllabus>());
-                            }
-                        }
-                    }
-                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = {status}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{code}") }))
+                    //await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{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())
+                    //        {
+                    //            syllabuses.Add(obj.ToObject<Syllabus>());
+                    //        }
+                    //    }
+                    //}
+                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Volume>(queryText: $"select value(c) from c where c.status = {status}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{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())
-                            {
-                                volumes.Add(obj.ToObject<Volume>());
-                            }
-                        }
+                        volumes.Add(item);
+                        //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())
+                        //    {
+                        //        volumes.Add(obj.ToObject<Volume>());
+                        //    }
+                        //}
                     }
                 }
-                else {
-                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{code}") }))
+                else if(scope.GetString() == "school") {
+                    //await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{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())
+                    //        {
+                    //            syllabuses.Add(obj.ToObject<Syllabus>());
+                    //        }
+                    //    }
+                    //}
+                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Volume>(queryText: $"select value(c) from c where c.status = {status} and c.periodId = '{periodCode}' and c.subjectId = '{subjectCode}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{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())
-                            {
-                                syllabuses.Add(obj.ToObject<Syllabus>());
-                            }
-                        }
-                    }
-                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = {status} and c.periodId = '{periodCode}' and c.subjectId = '{subjectCode}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{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())
-                            {
-                                volumes.Add(obj.ToObject<Volume>());
-                            }
-                        }
+                        volumes.Add(item);
+
+                        //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())
+                        //    {
+                        //        volumes.Add(obj.ToObject<Volume>());
+                        //    }
+                        //}
                     }
                 }
              }
             else { return BadRequest(); };
-            return Ok(new { volumes });
+            return Ok(new { volumes  });
         }
 
-
+        /*
+         
+        {
+            "id": "册别id",
+            "code": "学校编码或教师id",
+            "periodId": "学段id",
+            "subjectId": "学科id",
+            "gradeId": "年级id",
+            "semesterId": "学期id",
+            "status": 1,
+            "name": "册别名",
+            "creatorId": "创建者id",
+            "school": "学校编码",
+            "scope": "school|private"
+        }
+         */
 
         /// <summary>
         /// 新增册别