Sfoglia il codice sorgente

修改合并接口。修复数据接口。

CrazyIter_Bin 3 anni fa
parent
commit
726ff1f889

+ 0 - 93
TEAMModelOS.SDK/Models/Cosmos/Common/Knowledge.cs

@@ -1,93 +0,0 @@
-using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Text;
-using System.Text.Json.Serialization;
-using TEAMModelOS.SDK.Context.Attributes.Azure;
-using TEAMModelOS.SDK.DI;
-
-namespace TEAMModelOS.SDK.Models
-{
-    /// <summary>
-    ///Teaching materials 教学材料 --- 知识点,知识块
-    /// </summary>    
-    public class Knowledge: CosmosEntity
-    {
-        public Knowledge()
-        {
-            pk = "Knowledge";
-            points = new List<string>();
-        }
-        
-        /// <summary>
-        /// 标记为知识块,0=知识块 ,1 知识点
-        /// </summary>        
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public int type { get; set; } = 0;
-        /// <summary>
-        /// 名称
-        /// </summary>
-        
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public string name { get; set; }
-        /// <summary>
-        /// 描述
-        /// </summary>
-        
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public string alias { get; set; }
-
-        /// <summary>
-        /// 学科
-        /// </summary>
-        ///[Required(ErrorMessage = "{0} 必须填写")]
-        
-        public string subjectId { get; set; }
-
-       
-
-
-        
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public int order { get; set; }
-
-        /// <summary>
-        /// 删除状态0 删除 1 有效
-        /// </summary>
-        
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public int status { get; set; } = 1;
-
-        /// <summary>
-        /// 知识点 id
-        /// </summary>
-        
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public List<string> points { get; set; }
-
-
-        /// <summary>
-        ///  来自于标准表 Rowkey
-        /// </summary>
-        
-/*        [Required(ErrorMessage = "{0} 必须填写")]
-        public string knowledgeId { get; set; }*/
-
-        /// <summary>
-        /// 0 标准,1自建,2.....
-        /// </summary>
-
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public int source { get; set; }
-
-        /// <summary>
-        /// 学段 私有的没有学段
-        /// </summary>
-        ///[Required(ErrorMessage = "{0} 必须填写")]
-        
-        public string periodId { get; set; }
-/*        public int ownCount { get; set; }
-        public int openCount { get; set; }*/
-    }
-}

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/School/Knowledge.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Text;
 
-namespace TEAMModelOS.SDK.Models.Cosmos
+namespace TEAMModelOS.SDK.Models
 {
     /// <summary>
     ///Teaching materials 教学材料 --- 知识点,知识块

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/School/Room.cs

@@ -2,7 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 
-namespace TEAMModelOS.SDK.Models.Cosmos
+namespace TEAMModelOS.SDK.Models
 {
     /// <summary>
     /// 教室,只存在于学校。

+ 5 - 7
TEAMModelOS/Controllers/Knowledge/KnowledgesController.cs

@@ -4,8 +4,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using TEAMModelOS.Models;
-using TEAMModelOS.SDK;
-using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using System.Text.Json;
 using TEAMModelOS.SDK.Helper.Common.StringHelper;
@@ -77,12 +75,12 @@ namespace TEAMModelOS.Controllers
          */
         [ProducesDefaultResponseType]
         [HttpPost("upsert")]
-        public async Task<IActionResult> Upsert(TEAMModelOS.SDK.Models.Cosmos.Knowledge knowledge) {
+        public async Task<IActionResult> Upsert(Knowledge knowledge) {
             var client = _azureCosmos.GetCosmosClient();
             knowledge.code = $"Knowledge-{knowledge.owner}-{knowledge.subjectId}";
             StringBuilder sql = new StringBuilder($"select value(c) from c where c.periodId = '{knowledge.periodId}'");
-            TEAMModelOS.SDK.Models.Cosmos.Knowledge old = null;
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<TEAMModelOS.SDK.Models.Cosmos.Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{ knowledge.code}") }))
+            Knowledge old = null;
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{ knowledge.code}") }))
             {
                 old = item;
                 break;
@@ -187,8 +185,8 @@ namespace TEAMModelOS.Controllers
             if (periodId.ValueKind.Equals(JsonValueKind.String)) {
                 sql.Append($" where c.periodId = '{periodId}'");
             }
-            List<TEAMModelOS.SDK.Models.Cosmos.Knowledge> knowledges = new List<SDK.Models.Cosmos.Knowledge>() ;
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<TEAMModelOS.SDK.Models.Cosmos.Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+            List<Knowledge> knowledges = new List<Knowledge>() ;
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
             {
                 knowledges.Add(item);
             }

+ 6 - 1
TEAMModelOS/Controllers/School/SchoolTeacherController.cs

@@ -240,7 +240,8 @@ namespace TEAMModelOS.Controllers
                     obj.TryGetProperty("id", out JsonElement id);
                     obj.TryGetProperty("name", out JsonElement name);
                     obj.TryGetProperty("picture", out JsonElement picture);
-                    ids.Add(new TmdInfo { id=$"{id}",name=$"{name}" });
+                    TmdInfo tmd = new TmdInfo { id = $"{id}", name = $"{name}" };
+                    ids.Add(tmd);
                     //老師個人資料
                     var tresponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey("Base"));
                     if(tresponse.Status == 200)
@@ -254,11 +255,15 @@ namespace TEAMModelOS.Controllers
                             if (school.status.Equals("invite") && grant_type.ToString().Equals("invite"))
                             {
                                 keys.Add(new KeyValuePair<string, int>($"{id}", 1));
+                                //移除不能发送通知的部分
+                                ids.Remove(tmd);
                                 continue;
                             }
                             if (school.status.Equals("join") && grant_type.ToString().Equals("invite"))
                             {
                                 keys.Add(new KeyValuePair<string, int>($"{id}", 2));
+                                //移除不能发送通知的部分
+                                ids.Remove(tmd);
                                 continue;
                             }
                             school.status = grant_type.GetString();

+ 223 - 0
TEAMModelOS/Controllers/XTest/BusinessController.cs

@@ -0,0 +1,223 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+using StackExchange.Redis;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Json;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.Services.Common;
+
+namespace TEAMModelOS.Controllers.XTest
+{
+    [Route("business")]
+    [ApiController]
+    public class BusinessController : ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        public BusinessController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, DingDing dingDing)
+        {
+            _azureCosmos = azureCosmos;
+        }
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        //[ProducesDefaultResponseType]
+        //[HttpPost("get-schools")]
+        //public async Task<IActionResult> GetSchools(JsonElement request) {
+        //    var client = _azureCosmos.GetCosmosClient();
+        //    string sql = $"select c.id as code,c.name,c.picture from c ";
+        //    List<dynamic> dynamics = new List<dynamic>();
+        //    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
+        //    {
+        //        dynamics.Add(item);
+        //    }
+        //    return Ok(new { schools= dynamics,status=200});
+        //}
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-school-info")]
+        public async Task<IActionResult> GetSchoolInfo(JsonElement request)
+        {
+            
+            if (!request.TryGetProperty("id", out JsonElement _code))
+            {
+                return BadRequest();
+            }
+            var client = _azureCosmos.GetCosmosClient();
+            try
+            {
+               // string sql = $"select c.id ,c.code ,c.name from c ";
+                School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_code}", partitionKey: new PartitionKey("Base"));
+                //List<dynamic> knowledges = new List<dynamic>();
+                //var sbjs= school.period.SelectMany(x => x.subjects);
+                //List<Subject> subjects = new List<Subject>();
+                //if (sbjs != null) {
+                //    subjects.AddRange(sbjs);
+                //}
+                //foreach (var sub in subjects) {
+                //    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>(requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Knowledge-{school.id}-{sub.id}") }))
+                //    {
+                //        knowledges.Add(item);
+                //    }
+                //}
+                //List<dynamic> exams = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Exam-{school.id}") }))
+                //{
+                //    exams.Add(item);
+                //}
+                //List<dynamic> votes = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Vote-{school.id}") }))
+                //{
+                //    votes.Add(item);
+                //}
+                //List<dynamic> surveys = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Survey-{school.id}") }))
+                //{
+                //    surveys.Add(item);
+                //}
+                //List<dynamic> courses = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Course-{school.id}") }))
+                //{
+                //    courses.Add(item);
+                //}
+                //List<dynamic> classes = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>( requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Class-{school.id}") }))
+                //{
+                //    classes.Add(item);
+                //}
+                //List<dynamic> stulist = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>( requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"StuList-{school.id}") }))
+                //{
+                //    stulist.Add(item);
+                //}
+                //List<dynamic> rooms = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>( requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Room-{school.id}") }))
+                //{
+                //    rooms.Add(item);
+                //}
+                //List<dynamic> volumes = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>( requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Volume-{school.id}") }))
+                //{
+                //    volumes.Add(item);
+                //}
+                return Ok(new {id= school.id,name=school.name, picture=school.picture });
+            }
+            catch (CosmosException ex)
+            {
+                return Ok(new { status = ex.Status });
+
+            }
+            catch (Exception _) {
+                return Ok(new { status = 500 });
+            }
+        }
+        [ProducesDefaultResponseType]
+        [HttpPost("get-student-info")]
+        public async Task<IActionResult> GetStudentInfo(JsonElement request) {
+            if (!request.TryGetProperty("id", out JsonElement _id))
+            {
+                return BadRequest();
+            }
+            if (!request.TryGetProperty("code", out JsonElement _code))
+            {
+                return BadRequest();
+            }
+            var client = _azureCosmos.GetCosmosClient();
+            try
+            {
+                Student student = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>($"{_id}", partitionKey: new PartitionKey($"Base-{_code}"));
+                
+                return Ok(new { id = student.id, name = student.name, picture = student.picture });
+            }
+            catch (CosmosException ex)
+            {
+                return Ok(new { status = ex.Status });
+
+            }
+            catch (Exception _)
+            {
+                return Ok(new { status = 500 });
+            }
+        }
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-teacher-info")]
+        public async Task<IActionResult> GetTeacherInfo(JsonElement request)
+        {
+
+            if (!request.TryGetProperty("id", out JsonElement _code))
+            {
+                return BadRequest();
+            }
+            var client = _azureCosmos.GetCosmosClient();
+            try
+            {
+                //string sql = $"select c.id ,c.code ,c.name from c ";
+                Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{_code}", partitionKey: new PartitionKey("Base"));
+                //List<dynamic> exams = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Exam-{teacher.id}") }))
+                //{
+                //    exams.Add(item);
+                //}
+                //List<dynamic> votes = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Vote-{teacher.id}") }))
+                //{
+                //    votes.Add(item);
+                //}
+                //List<dynamic> surveys = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Survey-{teacher.id}") }))
+                //{
+                //    surveys.Add(item);
+                //}
+                //List<dynamic> courses = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Course-{teacher.id}") }))
+                //{
+                //    courses.Add(item);
+                //}
+                //List<dynamic> stulist = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>(requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"StuList-{teacher.id}") }))
+                //{
+                //    stulist.Add(item);
+                //}
+                //List<dynamic> volumes = new List<dynamic>();
+                //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>(requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Volume-{teacher.id}") }))
+                //{
+                //    volumes.Add(item);
+                //}
+                return Ok(new { id = teacher.id, name = teacher.name, picture = teacher.picture });
+            }
+            catch (CosmosException ex)
+            {
+                return Ok(new { status = ex.Status });
+
+            }
+            catch (Exception _)
+            {
+                return Ok(new { status = 500 });
+            }
+        }
+    }
+}

+ 101 - 89
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -60,119 +60,131 @@ namespace TEAMModelOS.Controllers
         //[AuthToken(Roles = "teacher")]
         [HttpPost("fix-item")]
         public async Task<IActionResult> FixItem(JsonElement data) {
+
             var client = _azureCosmos.GetCosmosClient();
-            List<ItemInfo> items = new List<ItemInfo>();
-            var queryslt = $"SELECT  value(c) FROM c where  c.pid = null ";
-            List<ItemInfo> noPeriodId = new List<ItemInfo>();
-            List<ItemInfo> noSubjectId = new List<ItemInfo>();
-            List<ItemInfo> noGradeIds = new List<ItemInfo>();
-            School school=  await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>("hbcn", partitionKey: new PartitionKey("Base"));
+            List<School> schools = new List<School>();
+            await foreach (var item in   client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText:"SELECT  value(c) FROM c", requestOptions: new QueryRequestOptions { PartitionKey= new PartitionKey("Base") })){
+                schools.Add(item);
+            }
             Random random = new Random();
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-hbcn") }))
-            {
-                if (string.IsNullOrEmpty(item.periodId))
-                {
-                    noPeriodId.Add(item);
-                }
-                if (string.IsNullOrEmpty(item.subjectId))
-                {
-                    noSubjectId.Add(item);
-                }
-                if (!item.gradeIds.IsNotEmpty())
+            foreach (var school in schools) {
+                List<ItemInfo> items = new List<ItemInfo>();
+                var queryslt = $"SELECT  value(c) FROM c where  c.pid = null ";
+                List<ItemInfo> noPeriodId = new List<ItemInfo>();
+                List<ItemInfo> noSubjectId = new List<ItemInfo>();
+                List<ItemInfo> noGradeIds = new List<ItemInfo>();
+               
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{school.id}") }))
                 {
-                    noGradeIds.Add(item);
-                }
-                bool errorData = false;
-                foreach (var x in item.gradeIds) {
-                    if (string.IsNullOrEmpty(x)) {
-                        errorData = true;
+                    if (string.IsNullOrEmpty(item.periodId))
+                    {
+                        noPeriodId.Add(item);
                     }
-                }
-                if (errorData) {
-                    List<string> grds = new List<string>();
-                    item.gradeIds.ForEach(x => {
+                    if (string.IsNullOrEmpty(item.subjectId))
+                    {
+                        noSubjectId.Add(item);
+                    }
+                    if (!item.gradeIds.IsNotEmpty())
+                    {
+                        noGradeIds.Add(item);
+                    }
+                    bool errorData = false;
+                    foreach (var x in item.gradeIds)
+                    {
                         if (string.IsNullOrEmpty(x))
                         {
-                            grds.Add($"{random.Next(0, 5)}");
-                        }
-                        else {
-                            grds.Add(x);
+                            errorData = true;
                         }
-                    });
-                    item.gradeIds = grds;
-                    await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<ItemInfo>(item, item.id, new PartitionKey(item.code));
+                    }
+                    if (errorData)
+                    {
+                        List<string> grds = new List<string>();
+                        item.gradeIds.ForEach(x => {
+                            if (string.IsNullOrEmpty(x))
+                            {
+                                grds.Add($"{random.Next(0, 5)}");
+                            }
+                            else
+                            {
+                                grds.Add(x);
+                            }
+                        });
+                        item.gradeIds = grds;
+                        await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<ItemInfo>(item, item.id, new PartitionKey(item.code));
+                    }
+                    items.Add(item);
                 }
-                items.Add(item);
-            }
-            List<ItemInfo> unMatch = new List<ItemInfo>();
-            foreach (var item in items)
-            {
-                bool match = false;
-                school.period.ForEach(x =>
+                List<ItemInfo> unMatch = new List<ItemInfo>();
+                foreach (var item in items)
                 {
-                    if (item.periodId.Equals(x.id))
+                    bool match = false;
+                    school.period.ForEach(x =>
                     {
-                        if (x.subjects.Select(y => y.id).Contains(item.subjectId))
+                        if (item.periodId.Equals(x.id))
                         {
-                            match = true;
+                            if (x.subjects.Select(y => y.id).Contains(item.subjectId))
+                            {
+                                match = true;
+                            }
                         }
+                    });
+                    if (!match)
+                    {
+                        unMatch.Add(item);
                     }
-                });
-                if (!match)
-                {
-                    unMatch.Add(item);
                 }
-            }
-            if (noGradeIds.IsNotEmpty()) {
-                var ids = noGradeIds.Select(x => x.id);
-                await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<ItemInfo>(ids.ToList(), $"Item-hbcn");
-                foreach(var rm in noGradeIds)
+                if (noGradeIds.IsNotEmpty())
                 {
-                    items.Remove(rm);
+                    var ids = noGradeIds.Select(x => x.id);
+                    await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<ItemInfo>(ids.ToList(), $"Item-{school.id}");
+                    foreach (var rm in noGradeIds)
+                    {
+                        items.Remove(rm);
+                    }
                 }
-            }
-            if (noPeriodId.IsNotEmpty())
-            {
-                var ids = noPeriodId.Select(x => x.id);
-                await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<ItemInfo>(ids.ToList(), $"Item-hbcn");
-                foreach (var rm in noPeriodId)
+                if (noPeriodId.IsNotEmpty())
                 {
-                    items.Remove(rm);
+                    var ids = noPeriodId.Select(x => x.id);
+                    await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<ItemInfo>(ids.ToList(), $"Item-{school.id}");
+                    foreach (var rm in noPeriodId)
+                    {
+                        items.Remove(rm);
+                    }
                 }
-            }
-            if (noSubjectId.IsNotEmpty())
-            {
-                var ids = noSubjectId.Select(x => x.id);
-                await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<ItemInfo>(ids.ToList(), $"Item-hbcn");
-                foreach (var rm in noSubjectId)
+                if (noSubjectId.IsNotEmpty())
                 {
-                    items.Remove(rm);
+                    var ids = noSubjectId.Select(x => x.id);
+                    await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<ItemInfo>(ids.ToList(), $"Item-{school.id}");
+                    foreach (var rm in noSubjectId)
+                    {
+                        items.Remove(rm);
+                    }
                 }
-            }
-            if (unMatch.IsNotEmpty())
-            {
-                var ids = unMatch.Select(x => x.id);
-                await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<ItemInfo>(ids.ToList(), $"Item-hbcn");
-                foreach (var rm in unMatch)
+                if (unMatch.IsNotEmpty())
                 {
-                    items.Remove(rm);
+                    var ids = unMatch.Select(x => x.id);
+                    await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<ItemInfo>(ids.ToList(), $"Item-{school.id}");
+                    foreach (var rm in unMatch)
+                    {
+                        items.Remove(rm);
+                    }
                 }
-            }
-            List<ItemCond> itemConds = new List<ItemCond>();
-            items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList().ForEach(z =>
-            {
-                ItemCond cond = new ItemCond() { id = z.key, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = z.list.Count, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
-                z.list.ForEach(y =>
+                List<ItemCond> itemConds = new List<ItemCond>();
+                items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList().ForEach(z =>
                 {
-                    ItemService.CountItemCond(y, null, cond);
+                    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);
+                    });
+                    itemConds.Add(cond);
                 });
-                itemConds.Add(cond);
-            });
-            itemConds.ForEach(async cond =>
-            {
-                await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(cond, new PartitionKey(cond.code));
-            });
-            return Ok(new { noGradeIds, itemConds });
+                itemConds.ForEach(async cond =>
+                {
+                    await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(cond, new PartitionKey(cond.code));
+                });
+            }
+            return Ok(new {  });
         }