소스 검색

题目条件计算数量

CrazyIter_Bin 4 년 전
부모
커밋
c4bb72948e
3개의 변경된 파일24개의 추가작업 그리고 10개의 파일을 삭제
  1. 19 5
      TEAMModelFunction/ActivityHttpTrigger.cs
  2. 4 4
      TEAMModelFunction/ItemService.cs
  3. 1 1
      TEAMModelOS.SDK/Models/Cosmos/Common/ItemCond.cs

+ 19 - 5
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -16,6 +16,7 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.TEAMModelFunction;
+using System.Linq;
 
 namespace TEAMModelFunction
 {
@@ -400,15 +401,28 @@ namespace TEAMModelFunction
             ILogger log)
         {
             var client = _azureCosmos.GetCosmosClient();
-            //List<ItemInfo> items = new List<ItemInfo>();
+            List<ItemInfo> items = new List<ItemInfo>();
             var queryslt = $"SELECT  value(c) FROM c ";
-            ItemCond cond = new ItemCond();
+            
             await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-hbcn") }))
             {
-                ItemService.CountItemCond(item,null,cond);
-                //items.Add(item);
+                
+                items.Add(item);
             }
-            return new OkObjectResult(new { cond });
+            List<ItemCond> itemConds = new List<ItemCond>();
+            items.GroupBy(x => x.periodId).ToList().ForEach( x=> {
+                ItemCond cond = new ItemCond() { id=x.Key,code=$"ItemCond-hbcn" };
+                x.ToList().ForEach(y => {
+                   ItemService.CountItemCond(y, null, cond);
+                });
+               
+                itemConds.Add(cond);
+            });
+            itemConds.ForEach(async cond =>
+            {
+                await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ItemCond>(cond, new PartitionKey(cond.code));
+            });
+            return new OkObjectResult(new { itemConds });
         }
         /// <summary>
         /// 设置问卷调查未初始化学生列表的业务

+ 4 - 4
TEAMModelFunction/ItemService.cs

@@ -18,7 +18,7 @@ namespace TEAMModelOS.TEAMModelFunction
             //检查两个对象是否是同一条记录
             if (newItem != null && odlItem == null)
             {
-                string newKey = $"{newItem.periodId}-{newItem.subjectId}";
+                string newKey = $"{newItem.subjectId}";
                 List<string> grade = newItem.gradeIds;
                 UpdateItemCond(cond, true,newKey, grade, newItem.type, newItem.level, newItem.field.HasValue?newItem.field.Value:0);
             }
@@ -28,18 +28,18 @@ namespace TEAMModelOS.TEAMModelFunction
                 if (newItem.id == odlItem.id && newItem.code == odlItem.code)
                 {
                     //先增加
-                    string newKey = $"{newItem.periodId}-{newItem.subjectId}";
+                    string newKey = $"{newItem.subjectId}";
                     List<string> newGrade = newItem.gradeIds;
                     UpdateItemCond(cond, true, newKey, newGrade, newItem.type, newItem.level, newItem.field.HasValue ? newItem.field.Value : 0);
                     //后变更删除
-                    string oldKey = $"{odlItem.periodId}-{odlItem.subjectId}";
+                    string oldKey = $"{odlItem.subjectId}";
                     List<string> oldGrade = odlItem.gradeIds;
                     UpdateItemCond(cond, false, oldKey, oldGrade, odlItem.type, odlItem.level, odlItem.field.HasValue ? odlItem.field.Value : 0);
                 }
             }
             else if (newItem == null && odlItem != null)
             {
-                string oldKey = $"{odlItem.periodId}-{odlItem.subjectId}";
+                string oldKey = $"{odlItem.subjectId}";
                 List<string> oldGrade = odlItem.gradeIds;
                 UpdateItemCond(cond, false, oldKey, oldGrade, odlItem.type, odlItem.level, odlItem.field.HasValue ? odlItem.field.Value : 0);
             }

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

@@ -13,7 +13,7 @@ namespace TEAMModelOS.SDK.Models
             pk = "ItemCond";
         }
         //key  学段id-科目id
-        public  Dictionary<string, List<CondCount>>  conds = new  Dictionary<string, List<CondCount>> ();
+        public Dictionary<string, List<CondCount>> conds { get; set; } = new Dictionary<string, List<CondCount>>();
     }
     public class CondCount {
         public KeyValuePair<string, int> grade { get; set; } = new KeyValuePair<string, int>();