|
@@ -222,10 +222,69 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("servicebus")]
|
|
|
- public async Task<IActionResult> Servicebus(ItemCondDto jsonMsg)
|
|
|
+ public async Task<IActionResult> Servicebus(ItemCondDto jsonMsg1)
|
|
|
{
|
|
|
- var messageBlob = new ServiceBusMessage(jsonMsg.ToJsonString());
|
|
|
- await _serviceBus.GetServiceBusClient().SendMessageAsync("itemcond", messageBlob);
|
|
|
+ string msg = "[{\"key\":\"xnygxx\",\"filed\":\"fc476b99-c871-4469-aaae-de951c44ae11\",\"scope\":\"school\"}]";
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ List<ItemCondDto> itemCondDtos = msg.ToObject<List<ItemCondDto>>();
|
|
|
+ foreach (var itemCondDto in itemCondDtos)
|
|
|
+ {
|
|
|
+ if (itemCondDto.scope.Equals("school"))
|
|
|
+ {
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ List<ItemInfo> items = new List<ItemInfo>();
|
|
|
+ var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where c.periodId='{itemCondDto.filed}' and c.pid= null ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{itemCondDto.key}") }))
|
|
|
+ {
|
|
|
+ items.Add(item);
|
|
|
+ }
|
|
|
+ itemCond = new ItemCond()
|
|
|
+ {
|
|
|
+ id = $"{itemCondDto.filed}",
|
|
|
+ code = $"ItemCond-{itemCondDto.key}",
|
|
|
+ pk = "ItemCond",
|
|
|
+ ttl = -1,
|
|
|
+ count = items.Count,
|
|
|
+ grades = new List<GradeCount>(),
|
|
|
+ subjects = new List<SubjectCount>()
|
|
|
+ };
|
|
|
+ items.ForEach(z =>
|
|
|
+ {
|
|
|
+ ItemService.CountItemCond(z, null, itemCond);
|
|
|
+ });
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:{itemCondDto.key}", $"{itemCondDto.filed}", itemCond.ToJsonString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ List<ItemInfo> items = new List<ItemInfo>();
|
|
|
+ var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where c.pid= null ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{itemCondDto.filed}") }))
|
|
|
+ {
|
|
|
+ items.Add(item);
|
|
|
+ }
|
|
|
+ itemCond = new ItemCond() { id = $"{itemCondDto.filed}", code = $"ItemCond", pk = "ItemCond", ttl = -1, count = items.Count };
|
|
|
+ items.ForEach(z =>
|
|
|
+ {
|
|
|
+ ItemService.CountItemCond(z, null, itemCond);
|
|
|
+ });
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:ItemCond", $"{itemCondDto.filed}", itemCond.ToJsonString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
return Ok();
|
|
|
}
|
|
|
|