|
@@ -87,18 +87,101 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok(new { itemConds = new List<ItemCond>() { } });
|
|
|
}
|
|
|
}
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("upsert-all")]
|
|
|
+ public async Task<IActionResult> UpsertAll(JsonElement request)
|
|
|
+ {
|
|
|
+
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ if (!request.TryGetProperty("itemInfos", out JsonElement items)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("option", out JsonElement option)) return BadRequest();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ List<ItemCondDto> itemCondDtos = new List<ItemCondDto>();
|
|
|
+ List<ItemInfo> itemInfos = items.ToObject<List<ItemInfo>>();
|
|
|
+ foreach (var itemInfo in itemInfos) {
|
|
|
+ itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
|
|
|
+ var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"item/{itemInfo.id}", name = $"{itemInfo.code}" }.ToJsonString());
|
|
|
+ messageBlob.ApplicationProperties.Add("name", "BlobRoot");
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
+ if (option.ToString().Equals("insert"))
|
|
|
+ {
|
|
|
+ itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ if (!itemInfo.code.Contains("Item"))
|
|
|
+ {
|
|
|
+ itemInfo.code = "Item-" + itemInfo.code;
|
|
|
+ }
|
|
|
+ var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (itemInfo.scope.Equals("private"))
|
|
|
+ {
|
|
|
+ ItemCondDto itemCondDto = new ItemCondDto { newItem = itemInfo, key = "ItemCond", filed = itemInfo.code.Replace("Item-", ""), scope = "private" };
|
|
|
+ itemCondDtos.Add(itemCondDto);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ItemCondDto itemCondDto = new ItemCondDto { newItem = itemInfo, key = $"ItemCond-{itemInfo.code.Replace("Item-", "")}", filed = itemInfo.periodId, scope = "school" };
|
|
|
+ itemCondDtos.Add(itemCondDto);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ if (itemInfo.scope.Equals("private"))
|
|
|
+ {
|
|
|
+ if (!itemInfo.code.Contains("Item"))
|
|
|
+ {
|
|
|
+ itemInfo.code = "Item-" + itemInfo.code;
|
|
|
+ }
|
|
|
+ string condId = itemInfo.code.Replace("Item-", "");
|
|
|
+
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ ItemCondDto itemCondDto = new ItemCondDto { newItem = itemInfo, odlItem = olditemInfo, key = "ItemCond", filed = itemInfo.code.Replace("Item-", ""), scope = "private" };
|
|
|
+ itemCondDtos.Add(itemCondDto);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!itemInfo.code.Contains("Item"))
|
|
|
+ {
|
|
|
+ itemInfo.code = "Item-" + itemInfo.code;
|
|
|
+ }
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ ItemCondDto itemCondDto = new ItemCondDto { newItem = itemInfo, odlItem = olditemInfo, key = $"ItemCond-{itemInfo.code.Replace("Item-", "")}", filed = itemInfo.periodId, scope = "school" };
|
|
|
+ itemCondDtos.Add(itemCondDto);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var messageBlobItemCond = new ServiceBusMessage(itemCondDtos.ToJsonString());
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync("itemcond", messageBlobItemCond);
|
|
|
+ return Ok(new { });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},item/upsert()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("upsert")]
|
|
|
public async Task<IActionResult> Upsert(JsonElement request)
|
|
|
{
|
|
|
|
|
|
- /* if (string.IsNullOrEmpty(request.id))
|
|
|
- {
|
|
|
- request.id = _snowflakeId.NextId() + "";
|
|
|
- request.code = typeof(ItemInfo).Name + "-" + request.code;
|
|
|
- };
|
|
|
- request.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- return Ok(await _azureCosmos.SaveOrUpdate(request));*/
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
if (!request.TryGetProperty("itemInfo", out JsonElement item)) return BadRequest();
|
|
|
if (!request.TryGetProperty("option", out JsonElement option)) return BadRequest();
|
|
@@ -182,6 +265,7 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
//获取题目摘要信息
|
|
|
/// </summary>
|