CrazyIter_Bin 3 years ago
parent
commit
29de6f4d58

+ 50 - 16
TEAMModelFunction/MonitorServicesBus.cs

@@ -375,7 +375,7 @@ namespace TEAMModelFunction
                 //TODO学习活动
                 //await FixActivity(client, stuListChange, "Learn");
                 //TODO作业活动
-                // await FixActivity(client, stuListChange, "Homework");
+                await StuListService.FixActivity(client,_dingDing, stuListChange, "Homework");
 
                 if (stuListChange.type==null||!stuListChange.type.Equals("research")) {
                     //课程名单变动修改学生课程关联信息
@@ -393,30 +393,64 @@ namespace TEAMModelFunction
         {
             try
             {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{msg}", GroupNames.醍摩豆服務運維群組);
                 var jsonMsg = JsonDocument.Parse(msg);
-                ItemCondDto itemCondDto = msg.ToObject<ItemCondDto>();
-                var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"{itemCondDto.key}", $"{itemCondDto.filed}");
-                ItemCond itemCond = null;
-                var client = _azureCosmos.GetCosmosClient();
-                string containerId = itemCondDto.scope.Equals("private") ? "Teacher" : "School";
-                if (value != default && !value.IsNullOrEmpty)
+                if (jsonMsg.RootElement.ValueKind.Equals(JsonValueKind.Array))
                 {
+                    List<ItemCondDto> itemCondDtos = msg.ToObject<List<ItemCondDto>>();
+                    foreach (var itemCondDto in itemCondDtos)
+                    {
+                        var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"{itemCondDto.key}", $"{itemCondDto.filed}");
+                        ItemCond itemCond = null;
+                        var client = _azureCosmos.GetCosmosClient();
+                        string containerId = itemCondDto.scope.Equals("private") ? "Teacher" : "School";
+                        if (value != default && !value.IsNullOrEmpty)
+                        {
 
-                    itemCond = value.ToString().ToObject<ItemCond>();
+                            itemCond = value.ToString().ToObject<ItemCond>();
+                        }
+                        else
+                        {
+                            try
+                            {
+                                itemCond = await client.GetContainer(Constant.TEAMModelOS, containerId).ReadItemAsync<ItemCond>(itemCondDto.filed, new PartitionKey($"{itemCondDto.key}"));
+                            }
+                            catch (CosmosException)
+                            {
+                                itemCond = new ItemCond() { id = itemCondDto.filed, code = $"{itemCondDto.key}", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
+                            };
+                        }
+                        ItemService.CountItemCond(itemCondDto.newItem, itemCondDto.odlItem, itemCond);
+                        await client.GetContainer(Constant.TEAMModelOS, containerId).UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
+                        await _azureRedis.GetRedisClient(8).HashSetAsync($"{itemCondDto.key}", $"{itemCondDto.filed}", itemCond.ToJsonString());
+                    }
                 }
                 else {
-                    try
+                    ItemCondDto itemCondDto = msg.ToObject< ItemCondDto>();
+                    var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"{itemCondDto.key}", $"{itemCondDto.filed}");
+                    ItemCond itemCond = null;
+                    var client = _azureCosmos.GetCosmosClient();
+                    string containerId = itemCondDto.scope.Equals("private") ? "Teacher" : "School";
+                    if (value != default && !value.IsNullOrEmpty)
                     {
-                        itemCond = await client.GetContainer(Constant.TEAMModelOS, containerId).ReadItemAsync<ItemCond>(itemCondDto.filed, new PartitionKey($"{itemCondDto.key}"));
+
+                        itemCond = value.ToString().ToObject<ItemCond>();
                     }
-                    catch (CosmosException)
+                    else
                     {
-                        itemCond = new ItemCond() { id = itemCondDto.filed, code = $"{itemCondDto.key}", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
-                    };
+                        try
+                        {
+                            itemCond = await client.GetContainer(Constant.TEAMModelOS, containerId).ReadItemAsync<ItemCond>(itemCondDto.filed, new PartitionKey($"{itemCondDto.key}"));
+                        }
+                        catch (CosmosException)
+                        {
+                            itemCond = new ItemCond() { id = itemCondDto.filed, code = $"{itemCondDto.key}", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
+                        };
+                    }
+                    ItemService.CountItemCond(itemCondDto.newItem, itemCondDto.odlItem, itemCond);
+                    await client.GetContainer(Constant.TEAMModelOS, containerId).UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
+                    await _azureRedis.GetRedisClient(8).HashSetAsync($"{itemCondDto.key}", $"{itemCondDto.filed}", itemCond.ToJsonString());
                 }
-                ItemService.CountItemCond(itemCondDto.newItem, itemCondDto.odlItem, itemCond);
-                await client.GetContainer(Constant.TEAMModelOS, containerId).UpsertItemAsync<ItemCond>(itemCond, new PartitionKey(itemCond.code));
-                await _azureRedis.GetRedisClient(8).HashSetAsync($"{itemCondDto.key}",$"{itemCondDto.filed}", itemCond.ToJsonString());
             }
             catch (CosmosException ex )
             {

+ 91 - 7
TEAMModelOS/Controllers/Item/ItemController.cs

@@ -87,18 +87,101 @@ namespace TEAMModelOS.Controllers
                 return Ok(new { itemConds = new List<ItemCond>() {  } });
             }
         }
+        [ProducesDefaultResponseType]
+        [HttpPost("upsert-all")]
+        public async Task<IActionResult> UpsertAll(JsonElement request)
+        {
+
+            var client = _azureCosmos.GetCosmosClient();
+            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>();
+                List<ItemInfo> itemInfos = items.ToObject<List<ItemInfo>>();
+                foreach (var itemInfo in itemInfos) {
+                    itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
+                    var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"item/{itemInfo.id}", name = $"{itemInfo.code}" }.ToJsonString());
+                    messageBlob.ApplicationProperties.Add("name", "BlobRoot");
+                    var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
+                    if (option.ToString().Equals("insert"))
+                    {
+                        itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        if (!itemInfo.code.Contains("Item"))
+                        {
+                            itemInfo.code = "Item-" + itemInfo.code;
+                        }
+                        var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+                        if (response.Status == 200)
+                        {
+                            return Ok();
+                        }
+                        else
+                        {
+                            if (itemInfo.scope.Equals("private"))
+                            {
+                                ItemCondDto itemCondDto = new ItemCondDto { newItem = itemInfo, key = "ItemCond", filed = itemInfo.code.Replace("Item-", ""), scope = "private" };
+                                itemCondDtos.Add(itemCondDto);
+                                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" };
+                                itemCondDtos.Add(itemCondDto);
+                                 await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
+
+                            }
+                        }
+                    }
+                    else
+                    {
+                        itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        if (itemInfo.scope.Equals("private"))
+                        {
+                            if (!itemInfo.code.Contains("Item"))
+                            {
+                                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" };
+                            itemCondDtos.Add(itemCondDto);
+                            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;
+                            }
+                            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);
+                            await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+
+                        }
+                    }
+                }
+                var messageBlobItemCond = new ServiceBusMessage(itemCondDtos.ToJsonString());
+                await _serviceBus.GetServiceBusClient().SendMessageAsync("itemcond", messageBlobItemCond);
+                return Ok(new {   });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},item/upsert()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+
+        
         [ProducesDefaultResponseType]
         [HttpPost("upsert")]
         public async Task<IActionResult> Upsert(JsonElement request)
         {
 
-            /*            if (string.IsNullOrEmpty(request.id))
-                        {
-                            request.id = _snowflakeId.NextId() + "";
-                            request.code = typeof(ItemInfo).Name + "-" + request.code;
-                        };
-                        request.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                        return Ok(await _azureCosmos.SaveOrUpdate(request));*/
             var client = _azureCosmos.GetCosmosClient();
             if (!request.TryGetProperty("itemInfo", out JsonElement item)) return BadRequest();
             if (!request.TryGetProperty("option", out JsonElement option)) return BadRequest();
@@ -182,6 +265,7 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
         }
+        
         /// <summary>
         //获取题目摘要信息
         /// </summary>

+ 10 - 1
TEAMModelOS/Controllers/Research/AbilityStatisticsController.cs

@@ -1559,7 +1559,7 @@ namespace TEAMModelOS.Controllers.Research
                 List<Ability> hadSubs = new List<Ability>();
                 ///订阅的学习记录
                 List<AbilitySub> rcdSubs = new List<AbilitySub>();
-
+                List<Ability> currencyAb = new List<Ability>();
                 //tmdid
                 if (!request.TryGetProperty("tmdid", out JsonElement tmdid)) return Ok(new { error = 400 });
                 //学校编码
@@ -1582,6 +1582,9 @@ namespace TEAMModelOS.Controllers.Research
                            .GetItemQueryIterator<Ability>(queryText: $"select value(c) from c where c.status = 1 ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
                     {
                         notSub.Add(item);
+                        if (item.currency == 2) {
+                            currencyAb.Add(item);
+                        }
                     }
                     await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
                             .GetItemQueryIterator<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{school}-{tmdid}") }))
@@ -1596,6 +1599,12 @@ namespace TEAMModelOS.Controllers.Research
                     }
                 }
                 else { return Ok(new { error = 400 }); };
+                foreach (var item in currencyAb) {
+                    var had = hadSubs.Where(x => x.id.Equals(item.id)).FirstOrDefault();
+                    if (had == null) {
+                        hadSubs.Add(item);
+                    }
+                }
                 return Ok(new { rcdSubs, hadSubs });
             }
             catch (Exception ex)

+ 3 - 3
TEAMModelOS/TEAMModelOS.csproj

@@ -37,9 +37,9 @@
     <SpaRoot>ClientApp\</SpaRoot>
     <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
     <UserSecretsId>078b5d89-7d90-4f6a-88fc-7d96025990a8</UserSecretsId>
-    <Version>5.2110.11</Version>
-    <AssemblyVersion>5.2110.11.1</AssemblyVersion>
-    <FileVersion>5.2110.11.1</FileVersion>
+    <Version>5.2110.13</Version>
+    <AssemblyVersion>5.2110.13.1</AssemblyVersion>
+    <FileVersion>5.2110.13.1</FileVersion>
     <Description>TEAMModelOS(IES5)</Description>
     <PackageReleaseNotes>版本说明</PackageReleaseNotes>
   </PropertyGroup>