|
@@ -254,25 +254,47 @@ namespace TEAMModelOS.Controllers
|
|
|
try {
|
|
|
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
|
|
|
{
|
|
|
+ List<Syllabus> delSyllabus = new List<Syllabus>();
|
|
|
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}'",
|
|
|
- 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;
|
|
|
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
|
|
|
{
|
|
@@ -355,14 +378,15 @@ namespace TEAMModelOS.Controllers
|
|
|
share.agree = -1;
|
|
|
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 {
|