CrazyIter_Bin 4 лет назад
Родитель
Сommit
fc3cde97af

+ 1 - 1
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -411,7 +411,7 @@ namespace TEAMModelFunction
             }
             List<ItemCond> itemConds = new List<ItemCond>();
             items.GroupBy(x => x.periodId).ToList().ForEach( x=> {
-                ItemCond cond = new ItemCond() { id=x.Key,code=$"ItemCond-hbcn" };
+                ItemCond cond = new ItemCond() { id=x.Key,code=$"ItemCond-hbcn" ,pk= "ItemCond" ,ttl=-1};
                 x.ToList().ForEach(y => {
                    ItemService.CountItemCond(y, null, cond);
                 });

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/Syllabus.cs

@@ -20,7 +20,7 @@ namespace TEAMModelOS.SDK.Models
         [Required(ErrorMessage = "{0} 必须填写")]
         public List<Tnode> children { get; set; }
         public string volumeId { get; set; }
-        public List<SyllabusAuth> auth { get; set; }
+        public List<SyllabusAuth> auth { get; set; } = new List<SyllabusAuth>();
         public string scope { get; set; }
 }
 

+ 57 - 5
TEAMModelOS/Controllers/Item/ItemController.cs

@@ -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();
             }
 

+ 2 - 1
TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

@@ -65,9 +65,10 @@ namespace TEAMModelOS.Controllers
         [HttpPost("upsert-tree")]
         public async Task<IActionResult> SaveOrUpdateAsTree(List<SyllabusTreeNode> request)
         {
+            long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             foreach (SyllabusTreeNode syllabusTree in request) {
                 List<Tnode> nodes = new List<Tnode>();
-                SyllabusService.TreeToList(syllabusTree.trees, nodes);
+                SyllabusService.TreeToList(syllabusTree.trees, nodes, now);
                 if (!string.IsNullOrEmpty(syllabusTree.id))
                 {
                     Syllabus syllabus = null;

+ 3 - 3
TEAMModelOS/Services/Common/SyllabusService.cs

@@ -40,7 +40,7 @@ namespace TEAMModelOS.Services.Common
         }
 
 
-        public static List<Tnode> TreeToList(List<SyllabusTree> trees, List<Tnode> nodes)
+        public static List<Tnode> TreeToList(List<SyllabusTree> trees, List<Tnode> nodes,long now)
         {
             int index = 0;
             foreach (SyllabusTree tr in trees)
@@ -65,7 +65,7 @@ namespace TEAMModelOS.Services.Common
                     rnodes = x.rnodes,
                     cids= cids,
                     creatorId=x.creatorId,
-                    updateTime=x.updateTime
+                    updateTime= now
                 };
                 list.Add(node);
             });
@@ -75,7 +75,7 @@ namespace TEAMModelOS.Services.Common
             {
                 if (null != tree.children && tree.children.Count > 0)
                 {
-                    TreeToList(tree.children, nodes);
+                    TreeToList(tree.children, nodes,now);
                 }
             }
             return nodes;