|
@@ -14,6 +14,8 @@ using Microsoft.AspNetCore.Http;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
using Azure.Cosmos;
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
+using System.Text;
|
|
|
+using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -48,6 +50,7 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
if (string.IsNullOrEmpty(x.id)) {
|
|
|
x.id = _snowflakeId.NextId()+"";
|
|
|
+ x.code = typeof(ItemInfo).Name + "-" + x.code;
|
|
|
};
|
|
|
x.createTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
|
|
|
});
|
|
@@ -61,6 +64,7 @@ namespace TEAMModelOS.Controllers
|
|
|
if (string.IsNullOrEmpty(request.id))
|
|
|
{
|
|
|
request.id = _snowflakeId.NextId() + "";
|
|
|
+ request.code = typeof(ItemInfo).Name + "-" + request.code;
|
|
|
};
|
|
|
request.createTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
|
|
|
return Ok(await _azureCosmos.SaveOrUpdate(request));
|
|
@@ -77,9 +81,15 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ sql.Append("select c.id, c.question,c.usageCount,c.level,c.field,c.points,c.type,c.option,c.createTime from c ");
|
|
|
if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("@CURRPAGE", out JsonElement page)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("@PAGESIZE", out JsonElement size)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("@DESC", out JsonElement desc)) return BadRequest();
|
|
|
List<object> summary = new List<object>();
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select c.id, c.question,c.usageCount,c.level,c.field,c.points,c.type,c.option,c.createTime from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ItemInfo-{code}") }))
|
|
|
+ AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(requert,sql);
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ItemInfo-{code}") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
|
@@ -92,24 +102,26 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return Ok(new { summary });
|
|
|
- /*ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
+
|
|
|
+ ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
- var emobj = request.EnumerateObject();
|
|
|
+ /*var emobj = requert.EnumerateObject();
|
|
|
while (emobj.MoveNext())
|
|
|
{
|
|
|
dict[emobj.Current.Name] = emobj.Current.Value;
|
|
|
}
|
|
|
+ //if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
List<string> props = new List<string> {
|
|
|
"question", "id", "code", "usageCount",
|
|
|
"level","field","points","type","option","createTime"
|
|
|
- };
|
|
|
+ };
|
|
|
List<ItemInfo> items = new List<ItemInfo>();
|
|
|
- if (dict.Keys.Count > 0) {
|
|
|
- items = await _azureCosmos.FindByDict<ItemInfo>(request, propertys: props);
|
|
|
- }
|
|
|
-
|
|
|
- return builder.Data(items).Extend(new Dictionary<string, object> { { "props", props } }).build();*/
|
|
|
+ if (dict.Keys.Count > 0)
|
|
|
+ {
|
|
|
+ items = await _azureCosmos.FindByDict<ItemInfo>(requert, propertys: props);
|
|
|
+ }*/
|
|
|
+ return Ok(new { summary });
|
|
|
+ //return builder.Data(items).Extend(new Dictionary<string, object> { { "props", props } }).build();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 手动挑题
|
|
@@ -166,9 +178,15 @@ namespace TEAMModelOS.Controllers
|
|
|
public async Task<IActionResult> Find(JsonElement requert)
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ sql.Append("select c.id, c.question,c.usageCount,c.level,c.field,c.points,c.type,c.option,c.createTime,c.answer,c.explain,c.children,c.score,c.order,c.gradeCode from c ");
|
|
|
if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("@CURRPAGE", out JsonElement page)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("@PAGESIZE", out JsonElement size)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("@DESC", out JsonElement desc)) return BadRequest();
|
|
|
+ AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(requert, sql);
|
|
|
List<object> items = new List<object>();
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select c.id, c.question,c.usageCount,c.level,c.field,c.points,c.type,c.option,c.createTime from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ItemInfo-{code}") }))
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ItemInfo-{code}") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
|
@@ -181,13 +199,15 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
+ /* List<ItemInfo> items = new List<ItemInfo>();
|
|
|
+ if (StringHelper.getKeyCount(requert) > 0)
|
|
|
+ {
|
|
|
+ items = await _azureCosmos.FindByDict<ItemInfo>(requert);
|
|
|
+ }*/
|
|
|
return Ok(new { items });
|
|
|
- /*ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
- List<ItemInfo> items =new List<ItemInfo>();
|
|
|
- if (StringHelper.getKeyCount(request) > 0) {
|
|
|
- items = await _azureCosmos.FindByDict<ItemInfo>(request);
|
|
|
- }
|
|
|
- return builder.Data(items).build();*/
|
|
|
+ //return builder.Data(items).build();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|