|
@@ -14,6 +14,7 @@ using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using Azure.Cosmos;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -33,7 +34,80 @@ namespace TEAMModelOS.Controllers
|
|
|
_azureCosmos = azureCosmos;
|
|
|
}
|
|
|
|
|
|
- // TODO 代码优化
|
|
|
+ /*
|
|
|
+ {
|
|
|
+ "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": []
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量保存或更新课纲
|
|
@@ -78,6 +152,20 @@ 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"))
|
|
|
+ {
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Volume-{code}"));
|
|
|
+ return Ok(new { code = response.Status });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Volume-{code}"));
|
|
|
+ return Ok(new { code = response.Status });
|
|
|
+ }
|
|
|
return Ok();
|
|
|
//Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
//var emobj = request.EnumerateObject();
|
|
@@ -136,12 +224,10 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
List<Tnode> nodes = new List<Tnode>();
|
|
|
Syllabus syllabus = new Syllabus();
|
|
|
-
|
|
|
TreeToList(request.trees, nodes);
|
|
|
- // List<SyllabusNode> nods = nodes.ToJson().FromJson<List<SyllabusNode>>() ;
|
|
|
syllabus.children = nodes;
|
|
|
syllabus.id = !string.IsNullOrEmpty(request.id) ? request.id : Guid.NewGuid().ToString() ;
|
|
|
- syllabus.code = request.code;
|
|
|
+ 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));
|
|
@@ -162,7 +248,6 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
return nodes;
|
|
|
}
|
|
|
-
|
|
|
|
|
|
private List<Tnode> TreeToList(List<SyllabusTree> trees, List<Tnode> nodes)
|
|
|
{
|