|
@@ -32,19 +32,21 @@ namespace TEAMModelOS.Controllers
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
private readonly DingDing _dingDing;
|
|
private readonly DingDing _dingDing;
|
|
private readonly Option _option;
|
|
private readonly Option _option;
|
|
- public ItemController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
|
|
|
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
|
+ public ItemController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage)
|
|
{
|
|
{
|
|
_azureCosmos = azureCosmos;
|
|
_azureCosmos = azureCosmos;
|
|
_snowflakeId = snowflakeId;
|
|
_snowflakeId = snowflakeId;
|
|
_dingDing = dingDing;
|
|
_dingDing = dingDing;
|
|
_option = option?.Value;
|
|
_option = option?.Value;
|
|
|
|
+ _azureStorage = azureStorage;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
[HttpPost("upsert")]
|
|
[HttpPost("upsert")]
|
|
public async Task<IActionResult> Upsert(JsonElement request)
|
|
public async Task<IActionResult> Upsert(JsonElement request)
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+
|
|
/* if (string.IsNullOrEmpty(request.id))
|
|
/* if (string.IsNullOrEmpty(request.id))
|
|
{
|
|
{
|
|
request.id = _snowflakeId.NextId() + "";
|
|
request.id = _snowflakeId.NextId() + "";
|
|
@@ -55,9 +57,12 @@ namespace TEAMModelOS.Controllers
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
if (!request.TryGetProperty("itemInfo", out JsonElement item)) return BadRequest();
|
|
if (!request.TryGetProperty("itemInfo", out JsonElement item)) return BadRequest();
|
|
if (!request.TryGetProperty("option", out JsonElement option)) return BadRequest();
|
|
if (!request.TryGetProperty("option", out JsonElement option)) return BadRequest();
|
|
- try {
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
ItemInfo itemInfo;
|
|
ItemInfo itemInfo;
|
|
- itemInfo = item.ToObject<ItemInfo>();
|
|
|
|
|
|
+ itemInfo = item.ToObject<ItemInfo>();
|
|
|
|
+ itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
|
|
|
|
+
|
|
if (option.ToString().Equals("insert"))
|
|
if (option.ToString().Equals("insert"))
|
|
{
|
|
{
|
|
itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
@@ -110,11 +115,13 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return Ok(new { itemInfo });
|
|
return Ok(new { itemInfo });
|
|
- } catch (Exception ex) {
|
|
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/upsert()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/upsert()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
//获取题目摘要信息
|
|
//获取题目摘要信息
|
|
@@ -126,7 +133,8 @@ namespace TEAMModelOS.Controllers
|
|
[HttpPost("find-summary")]
|
|
[HttpPost("find-summary")]
|
|
public async Task<IActionResult> FindSummary(JsonElement requert)
|
|
public async Task<IActionResult> FindSummary(JsonElement requert)
|
|
{
|
|
{
|
|
- try {
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
StringBuilder sql = new StringBuilder();
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.Append("select c.id, c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime from c ");
|
|
sql.Append("select c.id, c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime from c ");
|
|
@@ -193,12 +201,14 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return Ok(new { summary });
|
|
return Ok(new { summary });
|
|
- } catch (Exception ex) {
|
|
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/FindSummary()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/FindSummary()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 删除
|
|
/// 删除
|
|
@@ -210,7 +220,8 @@ namespace TEAMModelOS.Controllers
|
|
[HttpPost("delete")]
|
|
[HttpPost("delete")]
|
|
public async Task<IActionResult> Delete(JsonElement request)
|
|
public async Task<IActionResult> Delete(JsonElement request)
|
|
{
|
|
{
|
|
- try {
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
@@ -220,21 +231,24 @@ namespace TEAMModelOS.Controllers
|
|
var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
return Ok(new { code = response.Status });
|
|
return Ok(new { code = response.Status });
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
return Ok(new { code = response.Status });
|
|
return Ok(new { code = response.Status });
|
|
}
|
|
}
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/FindSummary()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/FindSummary()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
|
|
- /* ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
|
- IdPk idPk = await _azureCosmos.DeleteAsync<ItemInfo>( request );
|
|
|
|
- return Ok(idPk);*/
|
|
|
|
|
|
+ /* ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
|
+ IdPk idPk = await _azureCosmos.DeleteAsync<ItemInfo>( request );
|
|
|
|
+ return Ok(idPk);*/
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 手动挑题
|
|
/// 手动挑题
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -245,7 +259,8 @@ namespace TEAMModelOS.Controllers
|
|
[HttpPost("find")]
|
|
[HttpPost("find")]
|
|
public async Task<IActionResult> Find(JsonElement requert)
|
|
public async Task<IActionResult> Find(JsonElement requert)
|
|
{
|
|
{
|
|
- try {
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
StringBuilder sql = new StringBuilder();
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.Append("select c.id,c.code,c.repairResource, c.periodId,c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime,c.answer,c.explain,c.children,c.score,c.gradeIds,c.subjectId,c.blob,c.scope from c ");
|
|
sql.Append("select c.id,c.code,c.repairResource, c.periodId,c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime,c.answer,c.explain,c.children,c.score,c.gradeIds,c.subjectId,c.blob,c.scope from c ");
|
|
@@ -293,16 +308,17 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
dict.Add("gradeIds[*]", gradeIds);
|
|
dict.Add("gradeIds[*]", gradeIds);
|
|
}
|
|
}
|
|
- if (requert.TryGetProperty("pid",out JsonElement pd))
|
|
|
|
|
|
+ if (requert.TryGetProperty("pid", out JsonElement pd))
|
|
{
|
|
{
|
|
if (pd.ValueKind != JsonValueKind.Null)
|
|
if (pd.ValueKind != JsonValueKind.Null)
|
|
{
|
|
{
|
|
dict.Add("pid", pd.ToString());
|
|
dict.Add("pid", pd.ToString());
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
dict.Add("pid", null);
|
|
dict.Add("pid", null);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
|
|
AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
|
|
List<object> items = new List<object>();
|
|
List<object> items = new List<object>();
|
|
@@ -345,11 +361,12 @@ namespace TEAMModelOS.Controllers
|
|
return Ok(new { items });
|
|
return Ok(new { items });
|
|
//return builder.Data(items).build();
|
|
//return builder.Data(items).build();
|
|
}
|
|
}
|
|
- catch (Exception e) {
|
|
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/Find()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/Find()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
return BadRequest(e.StackTrace);
|
|
return BadRequest(e.StackTrace);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -367,7 +384,8 @@ namespace TEAMModelOS.Controllers
|
|
if (!requert.TryGetProperty("ids", out JsonElement id)) return BadRequest();
|
|
if (!requert.TryGetProperty("ids", out JsonElement id)) return BadRequest();
|
|
//List<string> ids = new List<string>();
|
|
//List<string> ids = new List<string>();
|
|
string info = "";
|
|
string info = "";
|
|
- for (int i = 0; i < id.GetArrayLength(); i++) {
|
|
|
|
|
|
+ for (int i = 0; i < id.GetArrayLength(); i++)
|
|
|
|
+ {
|
|
//ids.Add(id[i].ToJsonString());
|
|
//ids.Add(id[i].ToJsonString());
|
|
info += id[i].ToJsonString() + ",";
|
|
info += id[i].ToJsonString() + ",";
|
|
}
|
|
}
|
|
@@ -387,7 +405,7 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
|
|
|
|
return Ok(new { items });
|
|
return Ok(new { items });
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -398,7 +416,8 @@ namespace TEAMModelOS.Controllers
|
|
[HttpPost("Automatic")]
|
|
[HttpPost("Automatic")]
|
|
public async Task<IActionResult> Automatic(List<Compose> request)
|
|
public async Task<IActionResult> Automatic(List<Compose> request)
|
|
{
|
|
{
|
|
- try {
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
//ResponseBuilder builder = ResponseBuilder.custom();
|
|
//ResponseBuilder builder = ResponseBuilder.custom();
|
|
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
|
|
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
@@ -610,21 +629,24 @@ namespace TEAMModelOS.Controllers
|
|
itemInfos.Remove(itemInfo);
|
|
itemInfos.Remove(itemInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
List<ItemInfo> restItem = new List<ItemInfo>();
|
|
List<ItemInfo> restItem = new List<ItemInfo>();
|
|
//处理综合题问题
|
|
//处理综合题问题
|
|
- foreach (var item in retnInfos) {
|
|
|
|
|
|
+ foreach (var item in retnInfos)
|
|
|
|
+ {
|
|
if (!string.IsNullOrWhiteSpace(item.pid))
|
|
if (!string.IsNullOrWhiteSpace(item.pid))
|
|
{
|
|
{
|
|
if (item.scope == "school")
|
|
if (item.scope == "school")
|
|
{
|
|
{
|
|
var iteme = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
|
|
var iteme = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
|
|
- if (iteme != null) {
|
|
|
|
|
|
+ if (iteme != null)
|
|
|
|
+ {
|
|
restItem.Add(iteme.Value);
|
|
restItem.Add(iteme.Value);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
- else if (item.scope == "private") {
|
|
|
|
|
|
+ else if (item.scope == "private")
|
|
|
|
+ {
|
|
var iteme = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
|
|
var iteme = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
|
|
if (iteme != null)
|
|
if (iteme != null)
|
|
{
|
|
{
|
|
@@ -632,7 +654,8 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
restItem.Add(item);
|
|
restItem.Add(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -665,11 +688,13 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
//return builder.Data(list).build();
|
|
//return builder.Data(list).build();
|
|
return Ok(list);
|
|
return Ok(list);
|
|
- } catch (Exception e) {
|
|
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/Automatic()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/Automatic()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|