|
@@ -34,8 +34,10 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly Option _option;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
public IConfiguration _configuration { get; set; }
|
|
|
- public ItemController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IConfiguration configuration)
|
|
|
+ public ItemController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
|
|
|
+ AzureRedisFactory azureRedis,AzureServiceBusFactory serviceBus, IConfiguration configuration)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_snowflakeId = snowflakeId;
|
|
@@ -44,6 +46,7 @@ namespace TEAMModelOS.Controllers
|
|
|
_azureStorage = azureStorage;
|
|
|
_serviceBus = serviceBus;
|
|
|
_configuration = configuration;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 参数{"periodId":"学段id","schoolCode":"学校编码"} 其中periodId 不填则是全部学段的。
|
|
@@ -61,49 +64,79 @@ namespace TEAMModelOS.Controllers
|
|
|
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 } });
|
|
|
-
|
|
|
- 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}") }))
|
|
|
+ var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ItemCond:{schoolCode}", $"{periodId}");
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ if (value != default && !value.IsNullOrEmpty)
|
|
|
{
|
|
|
- items.Add(item);
|
|
|
+
|
|
|
+ itemCond = value.ToString().ToObject<ItemCond>();
|
|
|
+ }
|
|
|
+ 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}") }))
|
|
|
+ {
|
|
|
+ items.Add(item);
|
|
|
+ }
|
|
|
+ itemCond = new ItemCond()
|
|
|
+ {
|
|
|
+ id = $"{periodId}",
|
|
|
+ code = $"ItemCond-{schoolCode}",
|
|
|
+ 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:{schoolCode}", $"{periodId}", itemCond.ToJsonString());
|
|
|
}
|
|
|
- ItemCond itemCond = new ItemCond() {
|
|
|
- id = $"{periodId}",
|
|
|
- code = $"ItemCond-{schoolCode}",
|
|
|
- pk = "ItemCond",
|
|
|
- ttl = -1,
|
|
|
- count = items.Count,
|
|
|
- grades = new List<GradeCount>(),
|
|
|
- subjects = new List<SubjectCount>()
|
|
|
- };
|
|
|
- items.ForEach(z =>
|
|
|
- {
|
|
|
- ItemService.CountItemCond(z, null, itemCond);
|
|
|
- });
|
|
|
return Ok(new { itemConds = new List<ItemCond>() { itemCond } });
|
|
|
}
|
|
|
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"));
|
|
|
+ List<string> nocachePeriods = new List<string>();
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+
|
|
|
+ itemCond = value.ToString().ToObject<ItemCond>();
|
|
|
+ itemConds.Add(itemCond);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ nocachePeriods.Add(period.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string nocachePeriodsql = "";
|
|
|
+ if (nocachePeriods.IsNotEmpty())
|
|
|
+ {
|
|
|
+ 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 ";
|
|
|
+ var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field,c.scope FROM c where c.pid= null {nocachePeriodsql}";
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{schoolCode}") }))
|
|
|
{
|
|
|
items.Add(item);
|
|
|
}
|
|
|
- List<ItemCond> itemConds = new List<ItemCond>();
|
|
|
- items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList().ForEach(z =>
|
|
|
- {
|
|
|
+ var list = items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList();
|
|
|
+ foreach (var z in list) {
|
|
|
ItemCond cond = new ItemCond() { id = z.key, code = $"ItemCond-{school.id}", pk = "ItemCond", ttl = -1, count = z.list.Count, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
|
|
|
z.list.ForEach(y =>
|
|
|
{
|
|
|
ItemService.CountItemCond(y, null, cond);
|
|
|
});
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:{schoolCode}", $"{z.key}", cond.ToJsonString());
|
|
|
itemConds.Add(cond);
|
|
|
- });
|
|
|
+ }
|
|
|
if (school != null) {
|
|
|
foreach (var period in school.period) {
|
|
|
var cond= itemConds.Find(x => x.id.Equals(period.id));
|
|
@@ -113,28 +146,31 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //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}") }))
|
|
|
- //{
|
|
|
- // items.Add(item);
|
|
|
- //}
|
|
|
-
|
|
|
return Ok(new { itemConds = itemConds });
|
|
|
}
|
|
|
else if (!string.IsNullOrEmpty($"{tmdid}"))
|
|
|
{
|
|
|
- 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}") }))
|
|
|
+ var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ItemCond:ItemCond", $"{tmdid}");
|
|
|
+ ItemCond itemCond = null;
|
|
|
+ if (value != default && !value.IsNullOrEmpty)
|
|
|
{
|
|
|
- items.Add(item);
|
|
|
+
|
|
|
+ itemCond = value.ToString().ToObject<ItemCond>();
|
|
|
+ }
|
|
|
+ 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}") }))
|
|
|
+ {
|
|
|
+ items.Add(item);
|
|
|
+ }
|
|
|
+ itemCond = new ItemCond() { id = $"{tmdid}", code = $"ItemCond", pk = "ItemCond", ttl = -1, count = items.Count };
|
|
|
+ items.ForEach(z =>
|
|
|
+ {
|
|
|
+ ItemService.CountItemCond(z, null, itemCond);
|
|
|
+ });
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:ItemCond", $"{tmdid}", itemCond.ToJsonString());
|
|
|
}
|
|
|
- ItemCond itemCond = new ItemCond() { id = $"{tmdid}", code = $"ItemCond", pk = "ItemCond", ttl = -1, count = items.Count };
|
|
|
- items.ForEach(z =>
|
|
|
- {
|
|
|
- ItemService.CountItemCond(z, null, itemCond);
|
|
|
- });
|
|
|
- //ItemCond itemCond = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemCond>($"{tmdid}", new PartitionKey($"ItemCond"));
|
|
|
return Ok(new { itemConds = new List<ItemCond>() { itemCond } });
|
|
|
}
|
|
|
else
|
|
@@ -155,14 +191,14 @@ namespace TEAMModelOS.Controllers
|
|
|
[HttpPost("upsert-all")]
|
|
|
public async Task<IActionResult> UpsertAll(JsonElement request)
|
|
|
{
|
|
|
- // var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
|
|
|
+ var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
List<ItemInfo> itemInfos = null;
|
|
|
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>();
|
|
|
+ Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
|
|
|
itemInfos = items.ToObject<List<ItemInfo>>();
|
|
|
foreach (var itemInfo in itemInfos) {
|
|
|
itemInfo.ttl = -1;
|
|
@@ -187,20 +223,25 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
if (itemInfo.scope.Equals("private"))
|
|
|
{
|
|
|
- //if (string.IsNullOrEmpty(itemInfo.pid)) {
|
|
|
- // ItemCondDto itemCondDto = new ItemCondDto { newItem = itemInfo, key = "ItemCond", filed = itemInfo.code.Replace("Item-", ""), scope = "private" };
|
|
|
- // itemCondDtos.Add(itemCondDto);
|
|
|
- //}
|
|
|
+ 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))
|
|
|
- //{
|
|
|
- // 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}"));
|
|
|
+ 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}"));
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -214,13 +255,18 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
itemInfo.code = "Item-" + itemInfo.code;
|
|
|
}
|
|
|
- //if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
- //{
|
|
|
- // 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);
|
|
|
- //}
|
|
|
+ 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}"));
|
|
|
|
|
|
}
|
|
@@ -230,21 +276,28 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
itemInfo.code = "Item-" + itemInfo.code;
|
|
|
}
|
|
|
- //if (string.IsNullOrEmpty(itemInfo.pid))
|
|
|
- //{
|
|
|
- // 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);
|
|
|
- //}
|
|
|
+ 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" });
|
|
|
+ }
|
|
|
+ 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}"));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //var str = itemCondDtos.ToJsonString();
|
|
|
- //var messageBlobItemCond = new ServiceBusMessage(str);
|
|
|
- //await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
- //await _dingDing.SendBotMsg($"OS,{_option.Location},item/upsert()\n{str}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ 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)
|
|
@@ -265,7 +318,8 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!request.TryGetProperty("option", out JsonElement option)) return BadRequest();
|
|
|
try
|
|
|
{
|
|
|
- // var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
|
|
|
+ Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
|
|
|
+ var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
|
|
|
ItemInfo itemInfo;
|
|
|
itemInfo = item.ToObject<ItemInfo>();
|
|
|
itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
|
|
@@ -289,16 +343,24 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
if (itemInfo.scope.Equals("private"))
|
|
|
{
|
|
|
- //ItemCondDto itemCondDto = new ItemCondDto { newItem = itemInfo, key = "ItemCond", filed = itemInfo.code.Replace("Item-", ""), scope = "private" };
|
|
|
- //var messageBlobItemCond = new ServiceBusMessage(itemCondDto.ToJsonString());
|
|
|
- //await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
+ 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 = 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" };
|
|
|
- //var messageBlobItemCond = new ServiceBusMessage(itemCondDto.ToJsonString());
|
|
|
- //await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
+ 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" });
|
|
|
+ }
|
|
|
+ }
|
|
|
itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
|
|
|
|
|
|
}
|
|
@@ -313,12 +375,18 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
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" };
|
|
|
- //var messageBlobItemCond = new ServiceBusMessage(itemCondDto.ToJsonString());
|
|
|
- //await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
+ 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" });
|
|
|
+ }
|
|
|
+ }
|
|
|
itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
|
|
|
|
|
|
}
|
|
@@ -328,14 +396,26 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
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" };
|
|
|
- //var messageBlobItemCond = new ServiceBusMessage(itemCondDto.ToJsonString());
|
|
|
- //await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
+ 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" });
|
|
|
+ }
|
|
|
+ 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" });
|
|
|
+ }
|
|
|
+ }
|
|
|
itemInfo = 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 { itemInfo });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -444,7 +524,8 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- //var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
|
|
|
+ Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
|
|
|
+ var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
@@ -458,22 +539,33 @@ namespace TEAMModelOS.Controllers
|
|
|
await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
if (scope.ToString().Equals("school"))
|
|
|
{
|
|
|
- //ItemInfo itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
- //ItemCondDto itemCondDto = new ItemCondDto { odlItem = itemInfo, key = $"ItemCond-{itemInfo.code.Replace("Item-", "")}", filed = itemInfo.periodId, scope = "school" };
|
|
|
- //var messageBlobItemCond = new ServiceBusMessage(itemCondDto.ToJsonString());
|
|
|
- //await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>($"{id}", new PartitionKey($"{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" });
|
|
|
+ }
|
|
|
+ var itemCondDtos = dict.Select(x => x.Value).ToList();
|
|
|
+ var str = itemCondDtos.ToJsonString();
|
|
|
+ var messageBlobItemCond = new ServiceBusMessage(str);
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
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}"));
|
|
|
- //ItemCondDto itemCondDto = new ItemCondDto { odlItem = olditemInfo, key = "ItemCond", filed = olditemInfo.code.Replace("Item-", ""), scope = "private" };
|
|
|
- //var messageBlobItemCond = new ServiceBusMessage(itemCondDto.ToJsonString());
|
|
|
- //await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
+ ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>($"{id}", new PartitionKey($"{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" });
|
|
|
+ }
|
|
|
+ var itemCondDtos = dict.Select(x => x.Value).ToList();
|
|
|
+ var str = itemCondDtos.ToJsonString();
|
|
|
+ var messageBlobItemCond = new ServiceBusMessage(str);
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
|
|
|
var response = await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
|
return Ok(new { code = response.Status });
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|