|
@@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Http;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
using Azure.Cosmos;
|
|
|
using System.Text;
|
|
|
-using TEAMModelOS.SDK.DI;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using Azure.Messaging.ServiceBus;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
@@ -27,7 +26,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
-
|
|
|
+
|
|
|
[Route("item")]
|
|
|
[ApiController]
|
|
|
public class ItemController : ControllerBase
|
|
@@ -41,7 +40,7 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
|
public IConfiguration _configuration { get; set; }
|
|
|
public ItemController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
|
|
|
- AzureRedisFactory azureRedis,AzureServiceBusFactory serviceBus, IConfiguration configuration)
|
|
|
+ AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_snowflakeId = snowflakeId;
|
|
@@ -64,7 +63,8 @@ namespace TEAMModelOS.Controllers
|
|
|
#if !DEBUG
|
|
|
[Authorize(Roles = "IES")]
|
|
|
#endif
|
|
|
- public async Task<IActionResult> CondCount(JsonElement request) {
|
|
|
+ public async Task<IActionResult> CondCount(JsonElement request)
|
|
|
+ {
|
|
|
try
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
@@ -80,7 +80,8 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
itemCond = value.ToString().ToObject<ItemCond>();
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
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='{periodId}' 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-{schoolCode}") }))
|
|
@@ -111,10 +112,11 @@ namespace TEAMModelOS.Controllers
|
|
|
else if (!string.IsNullOrEmpty($"{schoolCode}"))
|
|
|
{
|
|
|
List<ItemCond> itemConds = new List<ItemCond>();
|
|
|
- School school =await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolCode}", new PartitionKey("Base"));
|
|
|
+ School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolCode}", new PartitionKey("Base"));
|
|
|
List<string> nocachePeriods = new List<string>();
|
|
|
- foreach (var period in school.period) {
|
|
|
- var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ItemCond:{schoolCode}", $"{period.id}");
|
|
|
+ foreach (var period in school.period)
|
|
|
+ {
|
|
|
+ var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ItemCond:{schoolCode}", $"{period.id}");
|
|
|
ItemCond itemCond = null;
|
|
|
if (value != default && !value.IsNullOrEmpty)
|
|
|
{
|
|
@@ -122,14 +124,15 @@ namespace TEAMModelOS.Controllers
|
|
|
itemCond = value.ToString().ToObject<ItemCond>();
|
|
|
itemConds.Add(itemCond);
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
nocachePeriods.Add(period.id);
|
|
|
}
|
|
|
}
|
|
|
string nocachePeriodsql = "";
|
|
|
if (nocachePeriods.IsNotEmpty())
|
|
|
- {
|
|
|
- string sql = string.Join(',', nocachePeriods.Select(x => $"'{x}'"));
|
|
|
+ {
|
|
|
+ string sql = string.Join(',', nocachePeriods.Select(x => $"'{x}'"));
|
|
|
nocachePeriodsql = $" and c.periodId in ({sql})";
|
|
|
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 {nocachePeriodsql}";
|
|
@@ -175,7 +178,8 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
itemCond = value.ToString().ToObject<ItemCond>();
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
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-{tmdid}") }))
|
|
@@ -185,7 +189,8 @@ namespace TEAMModelOS.Controllers
|
|
|
itemCond = new ItemCond() { id = $"{tmdid}", code = $"ItemCond", pk = "ItemCond", ttl = -1, count = items.Count };
|
|
|
items.ForEach(z =>
|
|
|
{
|
|
|
- if (!string.IsNullOrEmpty(z.type)) {
|
|
|
+ if (!string.IsNullOrEmpty(z.type))
|
|
|
+ {
|
|
|
ItemService.CountItemCond(z, null, itemCond);
|
|
|
}
|
|
|
});
|
|
@@ -225,102 +230,225 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
|
|
|
itemInfos = items.ToObject<List<ItemInfo>>();
|
|
|
- foreach (var itemInfo in itemInfos) {
|
|
|
- itemInfo.ttl = -1;
|
|
|
- itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
|
|
|
- await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
|
|
|
- if (option.ToString().Equals("insert"))
|
|
|
+ if (itemInfos.IsNotEmpty())
|
|
|
+ {
|
|
|
+ IEnumerable<string> ids = itemInfos.Where(x => !string.IsNullOrWhiteSpace(x.id)).Select(x => x.id);
|
|
|
+ List<ItemInfo> dbIDs = new List<ItemInfo>();
|
|
|
+ if (ids!=null && ids.Count()>0)
|
|
|
{
|
|
|
- itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- if (!itemInfo.code.Contains("Item"))
|
|
|
+ string scope = itemInfos[0].scope.Equals("school") ? Constant.School : Constant.Teacher;
|
|
|
+ string code = !itemInfos[0].code.Contains("Item") ? $"Item-" + itemInfos[0].code : itemInfos[0].code;
|
|
|
+ string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))} )";
|
|
|
+ var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, scope).GetList<ItemInfo>(sql, code);
|
|
|
+ if (result.list.IsNotEmpty())
|
|
|
{
|
|
|
- itemInfo.code = "Item-" + itemInfo.code;
|
|
|
+ dbIDs= result.list;
|
|
|
}
|
|
|
- var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
- if (response.Status == 200)
|
|
|
+ }
|
|
|
+ {
|
|
|
+ //处理数据库没有的数据
|
|
|
+ var notinDB = itemInfos.ExceptBy(dbIDs.Select(x=>x.id),x=>x.id);
|
|
|
+ if (notinDB!=null && notinDB.Count()>0)
|
|
|
{
|
|
|
- return Ok();
|
|
|
+ foreach (var itemInfo in notinDB)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ itemInfo.ttl = -1;
|
|
|
+ itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
|
|
|
+ await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
|
|
|
+ itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ if (!itemInfo.code.Contains("Item"))
|
|
|
+ {
|
|
|
+ itemInfo.code = "Item-" + itemInfo.code;
|
|
|
+ }
|
|
|
+ if (itemInfo.scope.Equals("private"))
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
+ {
|
|
|
+ if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed= $"{itemInfo.code.Replace("Item-", "")}", scope= "private" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
+ {
|
|
|
+ if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed=$"{itemInfo.periodId}", scope = "school" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{_option.Location},题目批量保存报错:,{ex.Message}\n{ex.StackTrace}\n{itemInfo.ToJsonString()}", GroupNames.成都开发測試群組);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
+ }
|
|
|
+ {
|
|
|
+ //处理更新的
|
|
|
+ var dbs = dbIDs.Select(x => x.id);
|
|
|
+ var inDB = itemInfos.Where(x => dbs.Contains(x.id));
|
|
|
+ foreach (var itemInfo in inDB) {
|
|
|
+ itemInfo.ttl = -1;
|
|
|
+ itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
|
|
|
+ await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
|
|
|
+
|
|
|
+ itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
if (itemInfo.scope.Equals("private"))
|
|
|
{
|
|
|
+ if (!itemInfo.code.Contains("Item"))
|
|
|
+ {
|
|
|
+ itemInfo.code = "Item-" + itemInfo.code;
|
|
|
+ }
|
|
|
if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
{
|
|
|
if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
|
|
|
{
|
|
|
- dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}",filed= $"{itemInfo.code.Replace("Item-", "")}", scope= "private" });
|
|
|
+ dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.code.Replace("Item-", "")}", scope = "private" });
|
|
|
+ }
|
|
|
+ //ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ ItemInfo olditemInfo = dbIDs.Find(x => x.id.Equals(itemInfo.id) && x.code.Equals(itemInfo.code));
|
|
|
+ if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{olditemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.code.Replace("Item-", "")}", scope = "private" });
|
|
|
}
|
|
|
}
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ 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;
|
|
|
+ }
|
|
|
if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
{
|
|
|
if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
|
|
|
{
|
|
|
- dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}",filed=$"{itemInfo.periodId}", scope = "school" });
|
|
|
+ dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.periodId}", scope = "school" });
|
|
|
+ }
|
|
|
+ // ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ ItemInfo olditemInfo = dbIDs.Find(x=>x.id.Equals(itemInfo.id) && x.code.Equals(itemInfo.code));
|
|
|
+ if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.periodId}", scope = "school" });
|
|
|
}
|
|
|
}
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
-
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ /*
|
|
|
+ foreach (var itemInfo in itemInfos)
|
|
|
{
|
|
|
- itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- if (itemInfo.scope.Equals("private"))
|
|
|
+ itemInfo.ttl = -1;
|
|
|
+ itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
|
|
|
+ await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
|
|
|
+ if (option.ToString().Equals("insert"))
|
|
|
{
|
|
|
+ itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
if (!itemInfo.code.Contains("Item"))
|
|
|
{
|
|
|
itemInfo.code = "Item-" + itemInfo.code;
|
|
|
}
|
|
|
- if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
+ var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ if (response.Status == 200)
|
|
|
{
|
|
|
- if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (itemInfo.scope.Equals("private"))
|
|
|
{
|
|
|
- dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.code.Replace("Item-", "")}", scope = "private" });
|
|
|
+ if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
+ {
|
|
|
+ if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed= $"{itemInfo.code.Replace("Item-", "")}", scope= "private" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
}
|
|
|
- ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
- if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}"))
|
|
|
+ else
|
|
|
{
|
|
|
- dict.Add($"{olditemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.code.Replace("Item-", "")}", scope = "private" });
|
|
|
+ if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
+ {
|
|
|
+ if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed=$"{itemInfo.periodId}", scope = "school" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
-
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (!itemInfo.code.Contains("Item"))
|
|
|
+ itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ if (itemInfo.scope.Equals("private"))
|
|
|
{
|
|
|
- itemInfo.code = "Item-" + itemInfo.code;
|
|
|
+ if (!itemInfo.code.Contains("Item"))
|
|
|
+ {
|
|
|
+ itemInfo.code = "Item-" + itemInfo.code;
|
|
|
+ }
|
|
|
+ if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
+ {
|
|
|
+ if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.code.Replace("Item-", "")}", scope = "private" });
|
|
|
+ }
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{olditemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.code.Replace("Item-", "")}", scope = "private" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+
|
|
|
}
|
|
|
- if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
+ else
|
|
|
{
|
|
|
- if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
|
|
|
+ if (!itemInfo.code.Contains("Item"))
|
|
|
{
|
|
|
- dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.periodId}", scope = "school" });
|
|
|
+ itemInfo.code = "Item-" + itemInfo.code;
|
|
|
}
|
|
|
- ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
- if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}"))
|
|
|
+ if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
{
|
|
|
- dict.Add($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.periodId}", scope = "school" });
|
|
|
+ if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.periodId}", scope = "school" });
|
|
|
+ }
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
+ if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}"))
|
|
|
+ {
|
|
|
+ dict.Add($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.periodId}", scope = "school" });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
|
|
|
}
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
+ */
|
|
|
+ var itemCondDtos = dict.Select(x => x.Value).ToList();
|
|
|
+ var str = itemCondDtos.ToJsonString();
|
|
|
+ var messageBlobItemCond = new ServiceBusMessage(str);
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
+ return Ok(new { itemInfos });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return BadRequest();
|
|
|
}
|
|
|
- var itemCondDtos= dict.Select(x => x.Value).ToList();
|
|
|
- var str = itemCondDtos.ToJsonString();
|
|
|
- var messageBlobItemCond = new ServiceBusMessage(str);
|
|
|
- await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
- return Ok(new { itemInfos });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -329,7 +457,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("upsert")]
|
|
|
[AuthToken(Roles = "teacher,admin,student")]
|
|
@@ -350,7 +478,7 @@ namespace TEAMModelOS.Controllers
|
|
|
ItemInfo itemInfo;
|
|
|
itemInfo = item.ToObject<ItemInfo>();
|
|
|
itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
|
|
|
-
|
|
|
+
|
|
|
await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
|
|
|
if (option.ToString().Equals("insert"))
|
|
|
{
|
|
@@ -362,7 +490,7 @@ namespace TEAMModelOS.Controllers
|
|
|
var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
- return Ok(new { code=409,msg="题目已经存在"});
|
|
|
+ return Ok(new { code = 409, msg = "题目已经存在" });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -387,7 +515,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -449,7 +577,7 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
//获取题目摘要信息
|
|
|
/// </summary>
|
|
@@ -561,16 +689,19 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
|
|
|
var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
|
|
|
- List<string> ids= new List<string>();
|
|
|
+ List<string> ids = new List<string>();
|
|
|
request.TryGetProperty("id", out JsonElement _id);
|
|
|
- if (_id.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrWhiteSpace(_id.GetString())) {
|
|
|
+ if (_id.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrWhiteSpace(_id.GetString()))
|
|
|
+ {
|
|
|
ids.Add(_id.GetString());
|
|
|
}
|
|
|
request.TryGetProperty("ids", out JsonElement _ids);
|
|
|
- if (_ids.ValueKind.Equals(JsonValueKind.Array)) {
|
|
|
+ if (_ids.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ {
|
|
|
var __ids = _ids.ToObject<List<string>>();
|
|
|
- var ds= __ids.Where(z => !string.IsNullOrWhiteSpace(z));
|
|
|
- if (ds.Any()) {
|
|
|
+ var ds = __ids.Where(z => !string.IsNullOrWhiteSpace(z));
|
|
|
+ if (ds.Any())
|
|
|
+ {
|
|
|
ids.AddRange(ds);
|
|
|
}
|
|
|
}
|
|
@@ -612,7 +743,7 @@ namespace TEAMModelOS.Controllers
|
|
|
codes.Add(new { id, code = response.Status });
|
|
|
}
|
|
|
}
|
|
|
- return Ok(new { code =200, codes });
|
|
|
+ return Ok(new { code = 200, codes });
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
@@ -637,7 +768,8 @@ namespace TEAMModelOS.Controllers
|
|
|
#if !DEBUG
|
|
|
[Authorize(Roles = "IES")]
|
|
|
#endif
|
|
|
- public async Task<IActionResult> Research(JsonElement request) {
|
|
|
+ public async Task<IActionResult> Research(JsonElement request)
|
|
|
+ {
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
StringBuilder sql = new StringBuilder();
|
|
|
sql.Append("select distinct c.id,c.code,c.repairResource, c.periodId,c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime," +
|
|
@@ -647,23 +779,27 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!request.TryGetProperty("researchKey", out JsonElement researchKey)) return BadRequest();
|
|
|
request.TryGetProperty("orOpt", out JsonElement _orOpt);
|
|
|
string _researchKey = Regex.Replace($"{researchKey}", "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
|
|
|
- var keys = Regex.Split(_researchKey, "\\s+", RegexOptions.IgnoreCase).Where(y=>!string.IsNullOrWhiteSpace(y));
|
|
|
- if (keys.Count() ==0) {
|
|
|
+ var keys = Regex.Split(_researchKey, "\\s+", RegexOptions.IgnoreCase).Where(y => !string.IsNullOrWhiteSpace(y));
|
|
|
+ if (keys.Count() ==0)
|
|
|
+ {
|
|
|
return BadRequest();
|
|
|
}
|
|
|
else if (keys.Count() == 1)
|
|
|
{
|
|
|
sql.Append($" and contains(c.question,'{keys.First()}')");
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
string join = " and ";
|
|
|
- if (_orOpt.ValueKind.Equals(JsonValueKind.True)) {
|
|
|
+ if (_orOpt.ValueKind.Equals(JsonValueKind.True))
|
|
|
+ {
|
|
|
join = " or ";
|
|
|
}
|
|
|
sql.Append($" and ( {string.Join(join, keys.Select(x => $" contains(c.question,'{x}') "))})");
|
|
|
}
|
|
|
request.TryGetProperty("type", out JsonElement type);
|
|
|
- if (!string.IsNullOrWhiteSpace($"{type}")) {
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{type}"))
|
|
|
+ {
|
|
|
sql.Append($" and c.type='{type}' ");
|
|
|
}
|
|
|
request.TryGetProperty("level", out JsonElement level);
|
|
@@ -691,11 +827,11 @@ namespace TEAMModelOS.Controllers
|
|
|
pageCount = pcount;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
List<object> items = new List<object>();
|
|
|
if (scope.ToString().Equals("private"))
|
|
|
{
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
|
@@ -728,7 +864,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
//需要处理 图片中的 base64
|
|
|
- return Ok(new { items , continuationToken });
|
|
|
+ return Ok(new { items, continuationToken });
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 根据条件随机挑选一个题目
|
|
@@ -755,16 +891,16 @@ namespace TEAMModelOS.Controllers
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
if (request.TryGetProperty("periodId", out JsonElement periodId))
|
|
|
{
|
|
|
- sql=$"{sql} and c.periodId='{periodId}'" ;
|
|
|
+ sql=$"{sql} and c.periodId='{periodId}'";
|
|
|
}
|
|
|
if (request.TryGetProperty("subjectId", out JsonElement subjectId))
|
|
|
{
|
|
|
- sql = $"{sql} and c.subjectId='{subjectId}'";
|
|
|
+ sql = $"{sql} and c.subjectId='{subjectId}'";
|
|
|
}
|
|
|
if (request.TryGetProperty("level", out JsonElement level))
|
|
|
{
|
|
|
sql = $"{sql} and c.level={level}";
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
if (request.TryGetProperty("type", out JsonElement type))
|
|
|
{
|
|
@@ -777,7 +913,8 @@ namespace TEAMModelOS.Controllers
|
|
|
if (request.TryGetProperty("gradeIds", out JsonElement _gradeIds) && _gradeIds.ValueKind.Equals(JsonValueKind.Array))
|
|
|
{
|
|
|
List<string> gradeIds = _gradeIds.ToObject<List<string>>();
|
|
|
- if (gradeIds.IsNotEmpty()) {
|
|
|
+ if (gradeIds.IsNotEmpty())
|
|
|
+ {
|
|
|
sql = $"{sql} and g in ({string.Join(",", gradeIds.Select(x => $"'{x}'"))})";
|
|
|
sql= sql.Replace("joingradeIds", " join g in c.gradeIds");
|
|
|
}
|
|
@@ -791,8 +928,8 @@ namespace TEAMModelOS.Controllers
|
|
|
sql= sql.Replace("joinknowledge", " join k in c.knowledge");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
if (request.TryGetProperty("pid", out JsonElement pd))
|
|
|
{
|
|
|
if (pd.ValueKind != JsonValueKind.Null)
|
|
@@ -813,7 +950,7 @@ namespace TEAMModelOS.Controllers
|
|
|
sql = $"{sql} and c.id not in ({string.Join(",", notinIds.Select(x => $"'{x}'"))})";
|
|
|
}
|
|
|
}
|
|
|
- string sqlstr = sql.ToString().Replace("joingradeIds", " ").Replace("joinknowledge"," " );
|
|
|
+ string sqlstr = sql.ToString().Replace("joingradeIds", " ").Replace("joinknowledge", " ");
|
|
|
if (sqlstr.EndsWith("1=1") || !sqlstr.Contains("and"))
|
|
|
{
|
|
|
return Ok(new { itemInfo = itemInfo });
|
|
@@ -825,14 +962,19 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
items.Add(item);
|
|
|
}
|
|
|
- if (notinIds.IsNotEmpty()) {
|
|
|
+ if (notinIds.IsNotEmpty())
|
|
|
+ {
|
|
|
items = items.Except(notinIds).ToList();
|
|
|
}
|
|
|
- string id= items.OrderBy(x => Guid.NewGuid().ToString()).Take(1).FirstOrDefault();
|
|
|
- if (!string.IsNullOrWhiteSpace(id)) {
|
|
|
- try {
|
|
|
+ string id = items.OrderBy(x => Guid.NewGuid().ToString()).Take(1).FirstOrDefault();
|
|
|
+ if (!string.IsNullOrWhiteSpace(id))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(id, new PartitionKey($"Item-{code}"));
|
|
|
- } catch (Exception ex) {
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
itemInfo = null;
|
|
|
}
|
|
|
}
|
|
@@ -861,7 +1003,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return Ok(new { itemInfo= itemInfo });
|
|
|
+ return Ok(new { itemInfo = itemInfo });
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
@@ -882,27 +1024,29 @@ namespace TEAMModelOS.Controllers
|
|
|
#if !DEBUG
|
|
|
[Authorize(Roles = "IES")]
|
|
|
#endif
|
|
|
- public async Task<IActionResult> FindIds(JsonElement request) {
|
|
|
+ public async Task<IActionResult> FindIds(JsonElement request)
|
|
|
+ {
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
if (!request.TryGetProperty("ids", out JsonElement _ids)) return BadRequest();
|
|
|
string tbname = $"{scope}".Equals("school") ? Constant.School : Constant.Teacher;
|
|
|
- List<ItemInfo> items= new List<ItemInfo>();
|
|
|
+ List<ItemInfo> items = new List<ItemInfo>();
|
|
|
List<string> ids = _ids.ToObject<List<string>>();
|
|
|
if (ids.IsNotEmpty())
|
|
|
{
|
|
|
string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(z => $"'{z}'"))})";
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<ItemInfo>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Item-{code}") }))
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<ItemInfo>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Item-{code}") }))
|
|
|
{
|
|
|
items.Add(item);
|
|
|
}
|
|
|
return Ok(new { items });
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
return Ok(new { items });
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -924,7 +1068,7 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
/* if (!request.TryGetProperty("@CURRPAGE", out JsonElement page)) return BadRequest();
|
|
|
if (!request.TryGetProperty("@PAGESIZE", out JsonElement size)) return BadRequest();*/
|
|
|
-
|
|
|
+
|
|
|
if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
/*var emobj = request.EnumerateObject();
|
|
@@ -939,7 +1083,8 @@ namespace TEAMModelOS.Controllers
|
|
|
}*/
|
|
|
/* dict.Add("@CURRPAGE", page.GetInt32());
|
|
|
dict.Add("@PAGESIZE", size.GetInt32());*/
|
|
|
- if (request.TryGetProperty("@DESC", out JsonElement desc)) {
|
|
|
+ if (request.TryGetProperty("@DESC", out JsonElement desc))
|
|
|
+ {
|
|
|
dict.Add("@DESC", desc.ToString());
|
|
|
}
|
|
|
if (request.TryGetProperty("@ASC", out JsonElement asc))
|
|
@@ -1268,7 +1413,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
if (!string.IsNullOrWhiteSpace(item.pid))
|
|
|
{
|
|
|
- if (item.scope .Equals("school"))
|
|
|
+ if (item.scope.Equals("school"))
|
|
|
{
|
|
|
var iteme = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
|
|
|
if (iteme != null)
|
|
@@ -1277,7 +1422,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- else if (item.scope .Equals("private"))
|
|
|
+ else if (item.scope.Equals("private"))
|
|
|
{
|
|
|
var iteme = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
|
|
|
if (iteme != null)
|