|
@@ -57,13 +57,15 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
request.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
- if (!request.TryGetProperty("schoolCode", out JsonElement schoolCode)) return BadRequest();
|
|
|
- if (periodId.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrEmpty(periodId.GetString()))
|
|
|
+ request.TryGetProperty("schoolCode", out JsonElement schoolCode);
|
|
|
+ request.TryGetProperty("tmdid", out JsonElement tmdid);
|
|
|
+ if (!string.IsNullOrEmpty($"{periodId}") && !string.IsNullOrEmpty($"{schoolCode}"))
|
|
|
{
|
|
|
ItemCond itemCond = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemCond>($"{periodId}", new PartitionKey($"ItemCond-{schoolCode}"));
|
|
|
return Ok(new { itemConds = new List<ItemCond>() { itemCond } });
|
|
|
}
|
|
|
- else {
|
|
|
+ else if (!string.IsNullOrEmpty($"{schoolCode}"))
|
|
|
+ {
|
|
|
List<ItemCond> items = new List<ItemCond>();
|
|
|
var queryslt = $"SELECT value(c) FROM c ";
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemCond>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ItemCond-{schoolCode}") }))
|
|
@@ -72,9 +74,17 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
return Ok(new { itemConds = items });
|
|
|
}
|
|
|
+ else if (!string.IsNullOrEmpty($"{tmdid}"))
|
|
|
+ {
|
|
|
+ ItemCond itemCond = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemCond>($"{tmdid}", new PartitionKey($"ItemCond"));
|
|
|
+ return Ok(new { itemConds = new List<ItemCond>() { itemCond } });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { itemConds = new List<ItemCond>() { } });
|
|
|
+ }
|
|
|
} catch (Exception ex) {
|
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/cond-count()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
- return BadRequest();
|
|
|
+ return Ok(new { itemConds = new List<ItemCond>() { } });
|
|
|
}
|
|
|
}
|
|
|
[ProducesDefaultResponseType]
|
|
@@ -104,11 +114,9 @@ namespace TEAMModelOS.Controllers
|
|
|
if (option.ToString().Equals("insert"))
|
|
|
{
|
|
|
itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- //DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
if (!itemInfo.code.Contains("Item"))
|
|
|
{
|
|
|
itemInfo.code = "Item-" + itemInfo.code;
|
|
|
- // itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
}
|
|
|
var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
if (response.Status == 200)
|
|
@@ -119,19 +127,29 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
if (itemInfo.scope.Equals("private"))
|
|
|
{
|
|
|
- itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ string condId = itemInfo.code.Replace("Item-","");
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ itemCond = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemCond>(condId, new PartitionKey("ItemCond"));
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ itemCond = new ItemCond() { id = condId, code = $"ItemCond", pk = "ItemCond", ttl = -1, count = 0 };
|
|
|
+ };
|
|
|
+ ItemService.CountItemCond(itemInfo, null, itemCond);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// itemInfo.periodId
|
|
|
- itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
ItemCond itemCond = null;
|
|
|
try {
|
|
|
-
|
|
|
itemCond = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemCond>(itemInfo.periodId, new PartitionKey($"ItemCond-{itemInfo.code.Replace("Item-", "")}"));
|
|
|
} catch (Exception ) {
|
|
|
itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-{itemInfo.code.Replace("Item-", "")}", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
|
|
|
-
|
|
|
};
|
|
|
ItemService.CountItemCond(itemInfo, null, itemCond);
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
@@ -147,21 +165,23 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
itemInfo.code = "Item-" + itemInfo.code;
|
|
|
}
|
|
|
+ string condId = itemInfo.code.Replace("Item-", "");
|
|
|
itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
//更新题目数量
|
|
|
- //ItemCond itemCond = null;
|
|
|
- //try
|
|
|
- //{
|
|
|
-
|
|
|
- // itemCond = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemCond>(itemInfo.periodId, new PartitionKey($"ItemCond-{itemInfo.code.Replace("Item-", "")}"));
|
|
|
- //}
|
|
|
- //catch (Exception)
|
|
|
- //{
|
|
|
- // itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-{itemInfo.code.Replace("Item-", "")}", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
|
|
|
-
|
|
|
- //};
|
|
|
- //ItemService.CountItemCond(itemInfo, olditemInfo, itemCond);
|
|
|
- //await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ itemCond = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemCond>(condId, new PartitionKey("ItemCond"));
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ itemCond = new ItemCond() { id = condId, code = $"ItemCond", pk = "ItemCond", ttl = -1, count = 0};
|
|
|
+
|
|
|
+ };
|
|
|
+ ItemService.CountItemCond(itemInfo, olditemInfo, itemCond);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -310,7 +330,6 @@ namespace TEAMModelOS.Controllers
|
|
|
if (scope.ToString().Equals("school"))
|
|
|
{
|
|
|
ItemInfo itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
- var response = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
|
//更新题目数量
|
|
|
ItemCond itemCond = null;
|
|
|
try
|
|
@@ -325,10 +344,28 @@ namespace TEAMModelOS.Controllers
|
|
|
};
|
|
|
ItemService.CountItemCond(null, itemInfo, itemCond);
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
|
+ var response = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
|
return Ok(new { code = response.Status });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>($"{id}", new PartitionKey($"{code}"));
|
|
|
+ //更新题目数量
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ string condId = code.ToString().Replace("Item-", "");
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ itemCond = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemCond>(condId, new PartitionKey("ItemCond"));
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ itemCond = new ItemCond() { id = condId, code = $"ItemCond", pk = "ItemCond", ttl = -1, count = 0 };
|
|
|
+
|
|
|
+ };
|
|
|
+ ItemService.CountItemCond(null, olditemInfo, itemCond);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
|
|
|
var response = await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
|
return Ok(new { code = response.Status });
|
|
|
}
|