|
@@ -130,7 +130,9 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(request.id))
|
|
|
{
|
|
|
- request.code = typeof(Volume).Name + "-" + request.code;
|
|
|
+ request.ttl = -1;
|
|
|
+ request.pk = typeof(Volume).Name;
|
|
|
+ //request.code = typeof(Volume).Name + "-" + request.code;
|
|
|
if (request.type == 0)
|
|
|
{
|
|
|
List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
@@ -147,6 +149,9 @@ namespace TEAMModelOS.Controllers
|
|
|
string key = request.code + _snowflakeId.NextId();
|
|
|
request.id = key;
|
|
|
request.volumeCode = key;
|
|
|
+ string code = request.code;
|
|
|
+ request.code = typeof(Volume).Name + "-" + request.code;
|
|
|
+ request = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey($"Volume-{code}"));
|
|
|
}
|
|
|
else if (request.type == 1)
|
|
|
{
|
|
@@ -164,6 +169,9 @@ namespace TEAMModelOS.Controllers
|
|
|
string key = "dynamic" + request.TEAMModelId.Replace("#", "") + _snowflakeId.NextId();
|
|
|
request.id = key;
|
|
|
request.volumeCode = key;
|
|
|
+ string code = request.code;
|
|
|
+ request.code = typeof(Volume).Name + "-" + request.code;
|
|
|
+ request = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(request, new PartitionKey($"{code}"));
|
|
|
}
|
|
|
else if (request.type == 2)
|
|
|
{
|
|
@@ -173,6 +181,8 @@ namespace TEAMModelOS.Controllers
|
|
|
request.id = key;
|
|
|
request.volumeCode = key;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -191,6 +201,7 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok(new { V = "已存在!", error = ResponseCode.DATA_EXIST });
|
|
|
}
|
|
|
}
|
|
|
+ request = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
}
|
|
|
else if (request.type == 1)
|
|
|
{
|
|
@@ -211,16 +222,18 @@ namespace TEAMModelOS.Controllers
|
|
|
else if (request.type == 2)
|
|
|
{
|
|
|
}
|
|
|
+ request = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+ //request = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
}
|
|
|
- List<Volume> volumes = new List<Volume>
|
|
|
+ /* List<Volume> volumes = new List<Volume>
|
|
|
{
|
|
|
request
|
|
|
};
|
|
|
|
|
|
- List<Volume> volume = await _azureCosmos.SaveOrUpdateAll<Volume>(volumes);
|
|
|
- return Ok(new { volume });
|
|
|
+ List<Volume> volume = await _azureCosmos.SaveOrUpdateAll<Volume>(volumes);*/
|
|
|
+ return Ok(new { request });
|
|
|
}
|
|
|
|
|
|
|
|
@@ -269,13 +282,66 @@ namespace TEAMModelOS.Controllers
|
|
|
[HttpPost("find")]
|
|
|
public async Task<IActionResult> Find(JsonElement request)
|
|
|
{
|
|
|
- ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
- List<Volume> volumes ;
|
|
|
+ /*ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
+ List<Volume> volumes ;*/
|
|
|
+ List<Syllabus> syllabuses = new List<Syllabus>();
|
|
|
+ List<Volume> volumes = new List<Volume>();
|
|
|
if (request.TryGetProperty("code", out JsonElement code))
|
|
|
{
|
|
|
-
|
|
|
- List<Syllabus> syllabuses = await _azureCosmos.FindByDict<Syllabus>(new Dictionary<string, object> { { "code", "Syllabus-"+code.ToString() } });
|
|
|
- volumes = await _azureCosmos.FindByDict<Volume>(request);
|
|
|
+
|
|
|
+ request.TryGetProperty("type", out JsonElement type);
|
|
|
+ if (type.GetInt32() == 1)
|
|
|
+ {
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id,c.children 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 c.id, c.volumeName, c.volumeCode,c.children from c ", 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>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.children 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").GetItemQueryStreamIterator(queryText: $"select c.id, c.volumeName, c.volumeCode from c ", 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>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //List<Syllabus> syllabuses = await _azureCosmos.FindByDict<Syllabus>(new Dictionary<string, object> { { "code", "Syllabus-"+code.ToString() } });
|
|
|
+ //课纲
|
|
|
+ //volumes = await _azureCosmos.FindByDict<Volume>(request);
|
|
|
//处理单个册别下面的资源和题目
|
|
|
volumes.ForEach(v => {
|
|
|
|
|
@@ -283,7 +349,7 @@ namespace TEAMModelOS.Controllers
|
|
|
HashSet<string> iCount = new HashSet<string>();
|
|
|
|
|
|
syllabuses.ForEach(s => {
|
|
|
- if (v.volumeCode.Equals(s.code)) {
|
|
|
+ if (v.volumeCode.Equals(s.id)) {
|
|
|
s.children.ForEach(c => {
|
|
|
if (c.resources.IsNotEmpty())
|
|
|
{
|