|
@@ -151,7 +151,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- {"code":"册别code:0baf00db-0768-4b62-a8f7-280f6bcebf71","scope":"school"}
|
|
|
+ {"volumeId":"册别id:0baf00db-0768-4b62-a8f7-280f6bcebf71","scope":"school","volumeCode":"册别分区键"}
|
|
|
*/
|
|
|
/// <summary>
|
|
|
/// 查找课纲
|
|
@@ -163,33 +163,55 @@ namespace TEAMModelOS.Controllers
|
|
|
public async Task<IActionResult> Find(JsonElement request)
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("volumeId", out JsonElement volumeId)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("volumeCode", out JsonElement volumeCode)) return BadRequest();
|
|
|
if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
-
|
|
|
+ Volume volume = null;
|
|
|
List<SyllabusTreeNode> treeNodes = new List<SyllabusTreeNode>();
|
|
|
+ List<SyllabusTreeNode> redt = new List<SyllabusTreeNode>();
|
|
|
try {
|
|
|
if (scope.ToString().Equals("school"))
|
|
|
{
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c ",
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{code}") }))
|
|
|
+ volume = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Volume>($"{volumeId}", new PartitionKey($"{volumeCode}"));
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c ",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{volumeId}") }))
|
|
|
{
|
|
|
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};
|
|
|
treeNodes.Add(tree);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ volume = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Volume>($"{volumeId}", new PartitionKey($"{volumeCode}"));
|
|
|
await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c ",
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{code}") }))
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{volumeId}") }))
|
|
|
{
|
|
|
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 };
|
|
|
treeNodes.Add(tree);
|
|
|
}
|
|
|
}
|
|
|
- return Ok(new { tree= treeNodes });
|
|
|
+ if (volume.syllabusIds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ volume.syllabusIds.ForEach(x =>
|
|
|
+ {
|
|
|
+ for (int index = 0; index < treeNodes.Count; index++)
|
|
|
+ {
|
|
|
+ if (treeNodes[index].id == x)
|
|
|
+ {
|
|
|
+ redt.Add(treeNodes[index]);
|
|
|
+ treeNodes.RemoveAt(index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ redt.AddRange(treeNodes);
|
|
|
+ return Ok(new { tree = redt });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { tree = treeNodes });
|
|
|
+ }
|
|
|
+
|
|
|
} catch (Exception ex) {
|
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},common/syllabus/find-id\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
return Ok(new { tree= treeNodes });
|
|
@@ -209,19 +231,25 @@ namespace TEAMModelOS.Controllers
|
|
|
[HttpPost("delete")]
|
|
|
public async Task<IActionResult> Delete(JsonElement request)
|
|
|
{
|
|
|
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
- if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- if (scope.ToString().Equals("school"))
|
|
|
+ try
|
|
|
{
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Syllabus-{code}"));
|
|
|
- return Ok(new { code = response.Status });
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ if (scope.ToString().Equals("school"))
|
|
|
+ {
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Syllabus-{code}"));
|
|
|
+ return Ok(new { code = response.Status });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Syllabus-{code}"));
|
|
|
+ return Ok(new { code = response.Status });
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Syllabus-{code}"));
|
|
|
- return Ok(new { code = response.Status });
|
|
|
+ catch {
|
|
|
+ return Ok(new { code = 404});
|
|
|
}
|
|
|
}
|
|
|
}
|