瀏覽代碼

解决题目数量统计

CrazyIter_Bin 4 年之前
父節點
當前提交
fdfa56d963

+ 26 - 23
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -15,8 +15,8 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
-using TEAMModelOS.TEAMModelFunction;
 using System.Linq;
+using TEAMModelOS.Services.Common;
 
 namespace TEAMModelFunction
 {
@@ -400,29 +400,32 @@ namespace TEAMModelFunction
             [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
             ILogger log)
         {
-            var client = _azureCosmos.GetCosmosClient();
-            List<ItemInfo> items = new List<ItemInfo>();
-            var queryslt = $"SELECT  value(c) FROM c ";
-            
-            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-hbcn") }))
-            {
-                
-                items.Add(item);
-            }
-            List<ItemCond> itemConds = new List<ItemCond>();
-            items.GroupBy(x => x.periodId).ToList().ForEach( x=> {
-                ItemCond cond = new ItemCond() { id=x.Key,code=$"ItemCond-hbcn" ,pk= "ItemCond" ,ttl=-1};
-                x.ToList().ForEach(y => {
-                   ItemService.CountItemCond(y, null, cond);
+            try {
+                var client = _azureCosmos.GetCosmosClient();
+                List<ItemInfo> items = new List<ItemInfo>();
+                var queryslt = $"SELECT  value(c) FROM c ";
+
+                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-hbcn") }))
+                {
+
+                    items.Add(item);
+                }
+                List<ItemCond> itemConds = new List<ItemCond>();
+                items.GroupBy(x => x.periodId).ToList().ForEach(x => {
+                    ItemCond cond = new ItemCond() { id = x.Key, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
+                    x.ToList().ForEach(y => {
+                        ItemService.CountItemCond(y, null, cond);
+                    });
+
+                    itemConds.Add(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 });
+                itemConds.ForEach(async cond =>
+                {
+                    await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ItemCond>(cond, new PartitionKey(cond.code));
+                });
+                return new OkObjectResult(new { itemConds });
+            } catch (Exception ex) { await _dingDing.SendBotMsg($"TEAMModelFunction,ActivityHttpTrigger,fix-itemcond()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組); }
+            return new OkObjectResult(new { });
         }
         /// <summary>
         /// 设置问卷调查未初始化学生列表的业务

+ 181 - 8
TEAMModelOS.SDK/Models/Cosmos/Common/ItemCond.cs

@@ -5,20 +5,193 @@ using System.Text;
 namespace TEAMModelOS.SDK.Models
 {
     /// <summary>
-    /// 题目集合
+    /// 题目数量统计
     /// </summary>
     public class ItemCond : CosmosEntity
     {
-        public ItemCond() {
+        public ItemCond()
+        {
             pk = "ItemCond";
         }
+        public int count { get; set; }
+        public List<GradeCount> grades { get; set; } = new List<GradeCount>();
+
+        public List<SubjectCount> subjects { get; set; } = new List<SubjectCount>();
         //key  学段id-科目id
-        public Dictionary<string, List<CondCount>> conds { get; set; } = new Dictionary<string, List<CondCount>>();
+      //  public Dictionary<string, List<CondCount>> subjects { get; set; } = new Dictionary<string, List<CondCount>>();
+    }
+    //public class CondCount {
+    //    public KeyValuePair<string, int> grade { get; set; } = new KeyValuePair<string, int>();
+    //    public Dictionary<string, int> type { get; set; } = new Dictionary<string, int>();
+    //    public Dictionary<int, int> level { get; set; } = new Dictionary<int, int>();
+    //    public Dictionary<int, int> field { get; set; } = new Dictionary<int, int>();
+    //}
+
+    public class SubjectCount
+    {
+        public string id { get; set; }
+        public Dictionary<string, Dictionary<string, Dictionary<string, int>>> types { get; set; } = new Dictionary<string, Dictionary<string, Dictionary<string, int>>>()
+        {
+            {
+                "compose",new Dictionary<string, Dictionary<string, int>>
+                {
+                    { 
+                        "level",new Dictionary<string, int> 
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        } 
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            },
+            {
+                "single",new Dictionary<string, Dictionary<string, int>>
+                {
+                    {
+                        "level",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        }
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            },
+            {
+                "multiple",new Dictionary<string, Dictionary<string, int>>
+                {
+                    {
+                        "level",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        }
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            },
+            {
+                "sortmultiple",new Dictionary<string, Dictionary<string, int>>
+                {
+                    {
+                        "level",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        }
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            },
+            {
+                "judge",new Dictionary<string, Dictionary<string, int>>
+                {
+                    {
+                        "level",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        }
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            },
+            {
+                "complete",new Dictionary<string, Dictionary<string, int>>
+                {
+                    {
+                        "level",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        }
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            },
+            {
+                "subjective",new Dictionary<string, Dictionary<string, int>>
+                {
+                    {
+                        "level",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        }
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            },
+            {
+                "connector",new Dictionary<string, Dictionary<string, int>>
+                {
+                    {
+                        "level",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        }
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            },
+            {
+                "correct",new Dictionary<string, Dictionary<string, int>>
+                {
+                    {
+                        "level",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                        }
+                    },
+                    {
+                        "field",new Dictionary<string, int>
+                        {
+                            { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                        }
+                    }
+                }
+            }
+        };
     }
-    public class CondCount {
-        public KeyValuePair<string, int> grade { get; set; } = new KeyValuePair<string, int>();
-        public Dictionary<string, int> type { get; set; } = new Dictionary<string, int>();
-        public Dictionary<int, int> level { get; set; } = new Dictionary<int, int>();
-        public Dictionary<int, int> field { get; set; } = new Dictionary<int, int>();
+
+
+    public class GradeCount
+    {
+        public string id { get; set; }
+        public int count { get; set; }
     }
 }

+ 52 - 56
TEAMModelOS.SDK/Models/Service/ItemService.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.Models;
 
-namespace TEAMModelOS.TEAMModelFunction
+namespace TEAMModelOS.Services.Common
 {
     public static class ItemService
     {
@@ -14,13 +14,14 @@ namespace TEAMModelOS.TEAMModelFunction
         /// <param name="newItem"></param>
         /// <param name="odlItem"></param>
         /// <param name="cond"></param>
-        public static void CountItemCond(ItemInfo newItem, ItemInfo odlItem, ItemCond cond) {
+        public static void CountItemCond(ItemInfo newItem, ItemInfo odlItem, ItemCond cond)
+        {
             //检查两个对象是否是同一条记录
             if (newItem != null && odlItem == null)
             {
                 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);
+                UpdateItemCond(cond, true, newKey, grade, newItem.type, newItem.level, newItem.field.HasValue ? newItem.field.Value : 0);
             }
             else if (newItem != null && odlItem != null)
             {
@@ -43,16 +44,19 @@ namespace TEAMModelOS.TEAMModelFunction
                 List<string> oldGrade = odlItem.gradeIds;
                 UpdateItemCond(cond, false, oldKey, oldGrade, odlItem.type, odlItem.level, odlItem.field.HasValue ? odlItem.field.Value : 0);
             }
-            else {
-               // throw new Exception();
+            else
+            {
+                // throw new Exception();
             }
         }
         /// <summary>
         /// opt=false  减  true 增
+        /// key  科目id
+        /// 
         /// </summary>
         /// <param name="cond"></param>
         /// <param name="opt"></param>
-        public static void UpdateItemCond(ItemCond cond, bool opt,string key,List<string> grade,string type,int level,int field)
+        public static void UpdateItemCond(ItemCond cond, bool opt, string key, List<string> grade, string type, int level, int field)
         {
             int count = 0;
             if (opt)
@@ -64,64 +68,56 @@ namespace TEAMModelOS.TEAMModelFunction
                 //未计入的则默认0
                 count = -1;
             }
-            if (cond.conds.ContainsKey(key))
+            grade.ForEach(x => {
+                bool none = true;
+                for (int index = 0; index < cond.grades.Count; index++)
+                {
+                    if (x == cond.grades[index].id)
+                    {
+                        cond.grades[index].count = cond.grades[index].count + count;
+                        none = false;
+                        break;
+                    }
+                }
+                if (none)
+                {
+                    cond.grades.Add(new GradeCount { id = x, count = count });
+                }
+            });
+            cond.count = cond.grades.Select(x=>x.count).Sum();
+            SubjectCount subject = cond.subjects.Where(x => x.id == key).FirstOrDefault();
+            if (subject == null)
             {
-                foreach (var x in grade)
+                cond.subjects.Add(new SubjectCount() { id=key});
+            }
+            cond.subjects.Where(x => x.id == key).ToList().ForEach(y => {
+                if (!y.types.ContainsKey(type))
                 {
-                    var exCondCount= cond.conds[key].Where(y => y.grade.Key.Equals(x)).FirstOrDefault();
-                    if (exCondCount != null)
+                    var dict = new Dictionary<string, Dictionary<string, int>>
                     {
-                        exCondCount.grade= new KeyValuePair<string, int> (x, exCondCount.grade.Value + count);
-                        if (exCondCount.type.ContainsKey(type))
                         {
-                            exCondCount.type[type] = exCondCount.type[type] + count;
-                        }
-                        else {
-                            exCondCount.type.Add(type, count);
-                        }
-                        if (exCondCount.level.ContainsKey(level))
-                        {
-                            exCondCount.level[level] = exCondCount.level[level] + count;
-                        }
-                        else
+                            "level",new Dictionary<string, int>
+                            {
+                                { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }
+                            }
+                        },
                         {
-                            exCondCount.level.Add(level, count);
+                            "field",new Dictionary<string, int>
+                            {
+                                { "1",0},{ "2",0}, { "3", 0 }, { "4", 0 }, { "5", 0 }, { "6", 0 }
+                            }
                         }
-                        if (exCondCount.field.ContainsKey(field))
-                        {
-                            exCondCount.field[field] = exCondCount.field[field] + count;
-                        }
-                        else
-                        {
-                            exCondCount.field.Add(field, count);
-                        }
-                    }
-                    else {
-                        CondCount condCount = new CondCount
-                        {
-                            grade = new KeyValuePair<string, int>(x, count),
-                            type = new Dictionary<string, int> { { type, count } },
-                            field = new Dictionary<int, int> { { field, count } },
-                            level = new Dictionary<int, int> { { level, count } }
-                        };
-                        cond.conds[key].Add(condCount);
-                    }
-                }
-            }
-            else {
-                List<CondCount> conds = new List<CondCount>();
-                foreach (var x in grade) {
-                    CondCount condCount = new CondCount {
-                        grade = new KeyValuePair<string, int>(x, count),
-                        type = new Dictionary<string, int> { { type, count } },
-                        field = new Dictionary<int, int> { { field, count } },
-                        level= new Dictionary<int, int> { { level, count } }
                     };
-                    conds.Add(condCount);
+                    dict["level"][$"{level}"] = count;
+                    dict["field"][$"{field}"] = count;
+                    y.types.Add(type, dict);
                 }
-                cond.conds.Add(key, conds);
-            }
+                else
+                {
+                    y.types[type]["level"][$"{level}"] = y.types[type]["level"][$"{level}"] + count;
+                    y.types[type]["field"][$"{level}"] = y.types[type]["field"][$"{field}"] + count;
+                }
+            });
         }
-
     }
 }

+ 4 - 4
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -631,7 +631,7 @@ namespace TEAMModelOS.Controllers.Core
                                     exsit = true;
                                 }
                             }
-                            else if (scope.GetString().Equals("teacher"))
+                            else if (scope.GetString().Equals("private"))
                             {
                                 await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Bloblog>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
                                 {
@@ -668,7 +668,7 @@ namespace TEAMModelOS.Controllers.Core
                             {
                                 await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(blob, new Azure.Cosmos.PartitionKey(blob.code));
                             }
-                            else if (scope.GetString().Equals("teacher"))
+                            else if (scope.GetString().Equals("private"))
                             {
                                 await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(blob, new Azure.Cosmos.PartitionKey(blob.code));
                             }
@@ -682,7 +682,7 @@ namespace TEAMModelOS.Controllers.Core
                     {
                         await client.GetContainer("TEAMModelOS", "School").DeleteItemsAsync<Bloblog>(id, $"Bloblog-{name}");
                     }
-                    else if (scope.GetString().Equals("teacher"))
+                    else if (scope.GetString().Equals("private"))
                     {
                         await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemsAsync<Bloblog>(id, $"Bloblog-{name}");
                     }
@@ -697,6 +697,6 @@ namespace TEAMModelOS.Controllers.Core
             return Ok(new { status = 200 });
         }
 
-
+        
     }
 }

+ 3 - 3
TEAMModelOS/Controllers/Item/ItemController.cs

@@ -133,7 +133,7 @@ namespace TEAMModelOS.Controllers
 
                                 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>>() };
+                                itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
 
                             };
                             ItemService.CountItemCond(itemInfo, null, itemCond);
@@ -170,7 +170,7 @@ namespace TEAMModelOS.Controllers
                         }
                         catch (Exception ex)
                         {
-                            itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, conds = new Dictionary<string, List<CondCount>>() };
+                            itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(),subjects= new List<SubjectCount>() };
 
                         };
                         ItemService.CountItemCond(itemInfo, olditemInfo, itemCond);
@@ -310,7 +310,7 @@ namespace TEAMModelOS.Controllers
                     }
                     catch (Exception ex)
                     {
-                        itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, conds = new Dictionary<string, List<CondCount>>() };
+                        itemCond = new ItemCond() { id = itemInfo.periodId, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
 
                     };
                     ItemService.CountItemCond(null, itemInfo, itemCond);

+ 30 - 7
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -15,6 +15,7 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.Services.Common;
 
 namespace TEAMModelOS.Controllers.XTest
 {
@@ -80,15 +81,37 @@ namespace TEAMModelOS.Controllers.XTest
         [ProducesDefaultResponseType]
         [HttpGet("test-redis")]
         public async Task<IActionResult> TestRedis( ) {
-            var client = _azureCosmos.GetCosmosClient();
-            int count = 0;
-            string sql = $" SELECT value(count(serial))  FROM c join serial in c.serial where c.id ='hbcn'  and  c.pk='Product' and serial.prodCode='3222C6D2' ";
-            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<int>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") }))
+
+
+            try
             {
-                count = item;
-                break;
+                var client = _azureCosmos.GetCosmosClient();
+                List<ItemInfo> items = new List<ItemInfo>();
+                var queryslt = $"SELECT  value(c) FROM c ";
+
+                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-hbcn") }))
+                {
+
+                    items.Add(item);
+                }
+                List<ItemCond> itemConds = new List<ItemCond>();
+                items.GroupBy(x => x.periodId).ToList().ForEach(x => {
+                    ItemCond cond = new ItemCond() { id = x.Key, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = 0, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
+                    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   Ok(new { itemConds });
             }
-            return Ok(count) ;
+            catch (Exception ex) { await _dingDing.SendBotMsg($"TEAMModelFunction,ActivityHttpTrigger,fix-itemcond()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組); }
+            return  Ok(new { });
+            
         }
         /// <summary>
         /// 删除

+ 0 - 127
TEAMModelOS/Services/Common/ItemService.cs

@@ -1,127 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using TEAMModelOS.SDK.Models;
-
-namespace TEAMModelOS.Services.Common
-{
-    public static class ItemService
-    {
-        /// <summary>
-        /// 计算题目的条件数量变化
-        /// </summary>
-        /// <param name="newItem"></param>
-        /// <param name="odlItem"></param>
-        /// <param name="cond"></param>
-        public static void CountItemCond(ItemInfo newItem, ItemInfo odlItem, ItemCond cond) {
-            //检查两个对象是否是同一条记录
-            if (newItem != null && odlItem == null)
-            {
-                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);
-            }
-            else if (newItem != null && odlItem != null)
-            {
-                //更新时 需要保证两个题的 id code 一致
-                if (newItem.id == odlItem.id && newItem.code == odlItem.code)
-                {
-                    //先增加
-                    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.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.subjectId}";
-                List<string> oldGrade = odlItem.gradeIds;
-                UpdateItemCond(cond, false, oldKey, oldGrade, odlItem.type, odlItem.level, odlItem.field.HasValue ? odlItem.field.Value : 0);
-            }
-            else {
-               // throw new Exception();
-            }
-        }
-        /// <summary>
-        /// opt=false  减  true 增
-        /// </summary>
-        /// <param name="cond"></param>
-        /// <param name="opt"></param>
-        public static void UpdateItemCond(ItemCond cond, bool opt,string key,List<string> grade,string type,int level,int field)
-        {
-            int count = 0;
-            if (opt)
-            {
-                count = 1;
-            }
-            else
-            {
-                //未计入的则默认0
-                count = -1;
-            }
-            if (cond.conds.ContainsKey(key))
-            {
-                foreach (var x in grade)
-                {
-                    var exCondCount= cond.conds[key].Where(x => x.grade.Key.Equals(x)).FirstOrDefault();
-                    if (exCondCount != null)
-                    {
-                        exCondCount.grade= new KeyValuePair<string, int> (x, exCondCount.grade.Value + count);
-                        if (exCondCount.type.ContainsKey(type))
-                        {
-                            exCondCount.type[type] = exCondCount.type[type] + count;
-                        }
-                        else {
-                            exCondCount.type.Add(type, count);
-                        }
-                        if (exCondCount.level.ContainsKey(level))
-                        {
-                            exCondCount.level[level] = exCondCount.level[level] + count;
-                        }
-                        else
-                        {
-                            exCondCount.level.Add(level, count);
-                        }
-                        if (exCondCount.field.ContainsKey(field))
-                        {
-                            exCondCount.field[field] = exCondCount.field[field] + count;
-                        }
-                        else
-                        {
-                            exCondCount.field.Add(field, count);
-                        }
-                    }
-                    else {
-                        CondCount condCount = new CondCount
-                        {
-                            grade = new KeyValuePair<string, int>(x, count),
-                            type = new Dictionary<string, int> { { type, count } },
-                            field = new Dictionary<int, int> { { field, count } },
-                            level = new Dictionary<int, int> { { level, count } }
-                        };
-                        cond.conds[key].Add(condCount);
-                    }
-                }
-            }
-            else {
-                List<CondCount> conds = new List<CondCount>();
-                foreach (var x in grade) {
-                    CondCount condCount = new CondCount {
-                        grade = new KeyValuePair<string, int>(x, count),
-                        type = new Dictionary<string, int> { { type, count } },
-                        field = new Dictionary<int, int> { { field, count } },
-                        level= new Dictionary<int, int> { { level, count } }
-                    };
-                    conds.Add(condCount);
-                }
-                cond.conds.Add(key, conds);
-            }
-        }
-
-    }
-}