浏览代码

调整题目

CrazyIter_Bin 3 年之前
父节点
当前提交
92dc67481b
共有 1 个文件被更改,包括 41 次插入17 次删除
  1. 41 17
      TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

+ 41 - 17
TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

@@ -254,25 +254,47 @@ namespace TEAMModelOS.Controllers
             try {
             try {
                 if (scope.ToString().Equals("school"))
                 if (scope.ToString().Equals("school"))
                 {
                 {
-                      volume = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Volume>($"{volumeId}", new PartitionKey($"{volumeCode}"));
-                      await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c where c.volumeId='{volumeId}'",
-
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{volume.school}") }))
+                    List<Syllabus> delSyllabus = new List<Syllabus>();
+                    volume = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Volume>($"{volumeId}", new PartitionKey($"{volumeCode}"));
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c where c.volumeId='{volumeId}'",
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{volume.school}") }))
                     {
                     {
-                        List<SyllabusTree> trees = SyllabusService.ListToTree(item.children);
-                        SyllabusTreeNode tree = new SyllabusTreeNode() { id = item.id, scope =item.scope, trees = trees ,volumeId=item.volumeId,auth=item.auth,codeval=volume.school};
-                        treeNodes.Add(tree);
+                        if (item.children.IsEmpty())
+                        {
+                            delSyllabus.Add(item);
+                        }
+                        else {
+                            List<SyllabusTree> trees = SyllabusService.ListToTree(item.children);
+                            SyllabusTreeNode tree = new SyllabusTreeNode() { id = item.id, scope = item.scope, trees = trees, volumeId = item.volumeId, auth = item.auth, codeval = volume.school };
+                            treeNodes.Add(tree);
+                        }
+                    }
+                    if (delSyllabus.IsNotEmpty()) {
+                        await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<Syllabus>(delSyllabus.Select(x => x.id).ToList(), $"Syllabus-{volume.school}");
                     }
                     }
+                  
                 }
                 }
                 else
                 else
                 {
                 {
+                    List<Syllabus> delSyllabus = new List<Syllabus>();
                     volume = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Volume>($"{volumeId}", new PartitionKey($"{volumeCode}"));
                     volume = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Volume>($"{volumeId}", new PartitionKey($"{volumeCode}"));
                     await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c where c.volumeId='{volumeId}'",
                     await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c where c.volumeId='{volumeId}'",
-                     requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{volume.creatorId}") }))
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{volume.creatorId}") }))
+                    {
+                        if (item.children.IsEmpty())
+                        {
+                            delSyllabus.Add(item);
+                        }
+                        else
+                        {
+                            List<SyllabusTree> trees = SyllabusService.ListToTree(item.children);
+                            SyllabusTreeNode tree = new SyllabusTreeNode() { id = item.id, scope = item.scope, trees = trees, volumeId = item.volumeId, auth = item.auth, codeval = volume.creatorId };
+                            treeNodes.Add(tree);
+                        }
+                    }
+                    if (delSyllabus.IsNotEmpty())
                     {
                     {
-                        List<SyllabusTree> trees = SyllabusService.ListToTree(item.children);
-                        SyllabusTreeNode tree = new SyllabusTreeNode() { id = item.id, scope = item.scope, trees = trees, volumeId = item.volumeId, auth = item.auth,codeval=volume.creatorId };
-                        treeNodes.Add(tree);
+                        await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemsAsync<Syllabus>(delSyllabus.Select(x => x.id).ToList(), $"Syllabus-{volume.creatorId}");
                     }
                     }
                 }
                 }
                 //对课纲树形结构排序
                 //对课纲树形结构排序
@@ -333,14 +355,15 @@ namespace TEAMModelOS.Controllers
                                 share.agree = -1;
                                 share.agree = -1;
                                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Share>(share, syllabus.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
                                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Share>(share, syllabus.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
                             }
                             }
-                            catch (Exception ex)
+                            catch (Exception)
                             {
                             {
+                                continue;
                                 ///仅用于处理查不到该数据的问题
                                 ///仅用于处理查不到该数据的问题
                             }
                             }
                         }
                         }
                     }
                     }
-                    var response = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Syllabus-{code}"));
-                    return Ok(new { code = response.Status });
+                    var response = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemAsync<Syllabus>(id.ToString(), new PartitionKey($"Syllabus-{code}"));
+                    return Ok(new { code = 200 });
                 }
                 }
                 else
                 else
                 {
                 {
@@ -355,14 +378,15 @@ namespace TEAMModelOS.Controllers
                                 share.agree = -1;
                                 share.agree = -1;
                                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Share>(share, syllabus.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
                                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Share>(share, syllabus.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
                             }
                             }
-                            catch (Exception ex)
+                            catch (Exception)
                             {
                             {
+                                continue;
                                 ///仅用于处理查不到该数据的问题
                                 ///仅用于处理查不到该数据的问题
                             }
                             }
                         }
                         }
                     }
                     }
-                    var response = await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Syllabus-{code}"));
-                    return Ok(new { code = response.Status });
+                    var response = await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Syllabus>(id.ToString(), new PartitionKey($"Syllabus-{code}"));
+                    return Ok(new { code = 200 });
                 }
                 }
             }
             }
             catch {
             catch {