|
@@ -48,7 +48,21 @@ namespace TEAMModelOS.Controllers
|
|
|
_serviceBus = serviceBus;
|
|
|
_configuration = configuration;
|
|
|
}
|
|
|
-
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("cond-count")]
|
|
|
+ public async Task<IActionResult> CondCount(JsonElement request) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ if (!request.TryGetProperty("periodId", out JsonElement periodId)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("schoolCode", out JsonElement schoolCode)) return BadRequest();
|
|
|
+ ItemCond itemCond = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemCond>($"{periodId}", new PartitionKey($"ItemCond-{schoolCode}"));
|
|
|
+ return Ok(new { itemCond });
|
|
|
+ } catch (Exception ex) {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},item/cond-count()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("upsert")]
|
|
|
public async Task<IActionResult> Upsert(JsonElement request)
|
|
@@ -97,6 +111,16 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
// itemInfo.periodId
|
|
|
itemInfo = await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+ itemCond = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemCond>(itemInfo.periodId, new PartitionKey($"ItemCond-{itemInfo.code.Replace("Item-", "")}"));
|
|
|
+ } catch (Exception ex) {
|
|
|
+ itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, conds = new Dictionary<string, List<CondCount>>() };
|
|
|
+
|
|
|
+ };
|
|
|
+ ItemService.CountItemCond(itemInfo, null, itemCond);
|
|
|
+ await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -108,7 +132,6 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!itemInfo.code.Contains("Item"))
|
|
|
{
|
|
|
itemInfo.code = "Item-" + itemInfo.code;
|
|
|
- // itemInfo = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
}
|
|
|
itemInfo = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
|
|
@@ -118,10 +141,23 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!itemInfo.code.Contains("Item"))
|
|
|
{
|
|
|
itemInfo.code = "Item-" + itemInfo.code;
|
|
|
- //itemInfo = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
}
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemInfo>( itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
itemInfo = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ //更新题目数量
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
|
|
|
+ itemCond = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemCond>(itemInfo.periodId, new PartitionKey($"ItemCond-{itemInfo.code.Replace("Item-", "")}"));
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, conds = new Dictionary<string, List<CondCount>>() };
|
|
|
+
|
|
|
+ };
|
|
|
+ ItemService.CountItemCond(itemInfo, olditemInfo, itemCond);
|
|
|
+ await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -246,7 +282,22 @@ namespace TEAMModelOS.Controllers
|
|
|
await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
if (scope.ToString().Equals("school"))
|
|
|
{
|
|
|
+ ItemInfo itemInfo = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemInfo>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
|
+ //更新题目数量
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ itemCond = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemCond>(itemInfo.periodId, new PartitionKey($"ItemCond-{itemInfo.code.Replace("Item-", "")}"));
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, conds = new Dictionary<string, List<CondCount>>() };
|
|
|
+
|
|
|
+ };
|
|
|
+ ItemService.CountItemCond(null, itemInfo, itemCond);
|
|
|
+ await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
|
return Ok(new { code = response.Status });
|
|
|
}
|
|
|
else
|
|
@@ -254,11 +305,12 @@ namespace TEAMModelOS.Controllers
|
|
|
var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
|
return Ok(new { code = response.Status });
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"OS,{_option.Location},item/FindSummary()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},item/delete()\n{e.Message},{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
return BadRequest();
|
|
|
}
|
|
|
|