Просмотр исходного кода

update 个人课例的分区键改为LessonRecord

CrazyIter_Bin 3 лет назад
Родитель
Сommit
ebb37bef1a

+ 3 - 3
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -881,7 +881,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             else if ($"{scope}".Equals("private"))
             {
                 blobname = $"{tmdid}";
-                code = $"LessonRecord-{tmdid}";
+                code = $"LessonRecord";
                 tbname = "Teacher";
             }
             else
@@ -1248,7 +1248,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                                 ids.Add(item);
                                             }
                                             //包含收藏的本人的个人课例
-                                            string favorite_count_sql = $"select value(c.id) from  c where c.fromCode='LessonRecord-{tmdid}' and c.scope='private' ";
+                                            string favorite_count_sql = $"select value(c.id) from  c where c.type='LessonRecord'    and c.scope='private' ";
                                             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<string>(
                                                 queryText: favorite_count_sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Favorite-{tmdid}") }))
                                             {
@@ -1406,7 +1406,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                     }
                     else if ($"{scope}".Equals("private"))
                     {
-                        code = $"LessonRecord-{tmdid}";
+                        code = $"LessonRecord";
                         tbname = "Teacher";
                     }
                     else

+ 3 - 3
TEAMModelOS.FunctionV4/TEAMModelOS.FunctionV4.csproj

@@ -5,9 +5,9 @@
 		<OutputType>Exe</OutputType>
 		<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
 		<SignAssembly>true</SignAssembly>
-		<AssemblyVersion>5.2204.20.1</AssemblyVersion>
-		<FileVersion>5.2204.20.1</FileVersion>
-		<Version>5.2204.20</Version>
+		<AssemblyVersion>5.2204.21.1</AssemblyVersion>
+		<FileVersion>5.2204.21.1</FileVersion>
+		<Version>5.2204.21</Version>
 		<PackageId>TEAMModelOS.FunctionV4</PackageId>
 		<Authors>teammodel</Authors>
 		<Company>醍摩豆(成都)信息技术有限公司</Company>

+ 1 - 1
TEAMModelOS/Controllers/Analysis/ClassAnalysisController.cs

@@ -251,7 +251,7 @@ namespace TEAMModelOS.Controllers.Analysis
                 {
                     queryClass = $"select value(c) from c where c.tmdid = '{tmdId}'";
                     tId = tmdId.GetString();
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<LessonRecord>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{tmdId}") }))
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<LessonRecord>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord") }))
                     {
                         records.Add(item);
 

+ 22 - 13
TEAMModelOS/Controllers/Both/LessonRecordController.cs

@@ -84,7 +84,7 @@ namespace TEAMModelOS.Controllers
             else if ($"{_scope}".Equals("private"))
             {
 
-                code = $"LessonRecord-{_tmdid}";
+                code = $"LessonRecord";
                 tbname = "Teacher";
             }
             else
@@ -192,7 +192,7 @@ namespace TEAMModelOS.Controllers
                     }
                     else if ($"{_dscope}".Equals("private"))
                     {
-                        code = $"LessonRecord-{_dtmdid}";
+                        code = $"LessonRecord";
                         tbname = "Teacher";
                     }
                     else
@@ -253,6 +253,7 @@ namespace TEAMModelOS.Controllers
             string code = "";
             string school = null;
             List<string> autoTch = new List<string>();
+            string sqlPrivate = "";
             if (_scope.GetString().Equals("school"))
             {
                 if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
@@ -296,7 +297,8 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
                 if (!string.IsNullOrEmpty($"{_tmdid}"))
                 {
-                    code = $"LessonRecord-{_tmdid}";
+                    code = $"LessonRecord";
+                    sqlPrivate = $" and c.tmdid='{_tmdid}'";
                     tbname = "Teacher";
                     List<string> ids = new List<string>();
                     ids.Add($"{_tmdid}");
@@ -331,7 +333,8 @@ namespace TEAMModelOS.Controllers
                 }
                 sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all')  {autoSql} ) ";
             }
-            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) and  array_length(c.groupIds)>0 {sqlShow}  and  ");
+            
+            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) and  array_length(c.groupIds)>0 {sqlPrivate} {sqlShow}  and  ");
             List<LessonRecord> records = new List<LessonRecord>();
             await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<LessonRecord>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
             {
@@ -418,6 +421,7 @@ namespace TEAMModelOS.Controllers
             string tbname = "";
             string code = "";
             string school = null;
+            string sqlPrivate = "";
             List<string> autoTch = new List<string>();
             if (_scope.GetString().Equals("school"))
             {
@@ -460,7 +464,9 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
                 if (!string.IsNullOrEmpty($"{_tmdid}"))
                 {
-                    code = $"LessonRecord-{_tmdid}";
+                    
+                    sqlPrivate = $" and c.tmdid='{_tmdid}'";
+                    code = $"LessonRecord";
                     tbname = "Teacher";
                     List<string> ids = new List<string>();
                     ids.Add($"{_tmdid}");
@@ -495,7 +501,7 @@ namespace TEAMModelOS.Controllers
                     }
                     sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all')  {autoSql} ) ";
                 }
-                cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) and  array_length(c.groupIds)>0  {sqlShow} and  ");
+                cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) and  array_length(c.groupIds)>0 {sqlPrivate}  {sqlShow} and  ");
                 await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
                    .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,
                    requestOptions: new QueryRequestOptions() { MaxItemCount = pageCount, PartitionKey = new PartitionKey(code) }))
@@ -599,7 +605,7 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
                 if (!string.IsNullOrEmpty($"{_tmdid}"))
                 {
-                    code = $"LessonRecord-{_tmdid}";
+                    code = $"LessonRecord";
                     tbname = "Teacher";
                 }
                 else
@@ -636,6 +642,7 @@ namespace TEAMModelOS.Controllers
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
             string tbname = "";
             string code = "";
+            string sqlPrivate = "";
             if (_scope.GetString().Equals("school") )
             {
                 if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
@@ -654,7 +661,8 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
                 if (!string.IsNullOrEmpty($"{_tmdid}"))
                 {
-                    code = $"LessonRecord-{_tmdid}";
+                    sqlPrivate = $" and c.tmdid='{_tmdid}'";
+                    code = $"LessonRecord";
                     tbname = "Teacher";
                 }
                 else {
@@ -690,9 +698,10 @@ namespace TEAMModelOS.Controllers
                 ["today"] = true,
                 ["periodId"] = $"{_periodId}",
             }.ToJsonString().ToObject<JsonElement>();
-            List<LessonRecord> excellentRcd =await GetOtherLessonCond(excellent,   code,   tbname);
-            List<LessonRecord> doubleGreenRcd = await GetOtherLessonCond(doubleGreen, code, tbname);
-            List<LessonRecord> todayRcd = await GetOtherLessonCond(today, code, tbname);
+         
+            List<LessonRecord> excellentRcd =await GetOtherLessonCond(excellent,   code,   tbname, sqlPrivate);
+            List<LessonRecord> doubleGreenRcd = await GetOtherLessonCond(doubleGreen, code, tbname, sqlPrivate);
+            List<LessonRecord> todayRcd = await GetOtherLessonCond(today, code, tbname, sqlPrivate);
             try {
                 var tmdids_excellent = excellentRcd.Select(x => x.tmdid);
                 var tmdids_doubleGreen = excellentRcd.Select(x => x.tmdid);
@@ -739,13 +748,13 @@ namespace TEAMModelOS.Controllers
             }
         }
 
-        private async Task<List<LessonRecord>> GetOtherLessonCond(JsonElement request,string code ,string tbname ) {
+        private async Task<List<LessonRecord>> GetOtherLessonCond(JsonElement request,string code ,string tbname,string sqlPrivate) {
             StringBuilder sql = new StringBuilder();
             sql.Append("select value(c) from c ");
             Dictionary<string, object> dict = GetLessonCond(request);
             AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
             List<LessonRecord> lessonRecords = new List<LessonRecord>();
-            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>404 or IS_DEFINED(c.status) = false ) and  ");
+            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false )  and  array_length(c.groupIds)>0 {sqlPrivate}  and  ");
             await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
                .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition,
                requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))

+ 2 - 2
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -95,7 +95,7 @@ namespace TEAMModelOS.Controllers.Client
             else if ($"{_scope}".Equals("private"))
             {
                
-                code = $"LessonRecord-{_tmdid}";
+                code = $"LessonRecord";
                 tbname = "Teacher";
             }
             else {
@@ -152,7 +152,7 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 if (lessonRecord.scope.Equals("private"))
                 {
-                    lessonRecord.code = $"LessonRecord-{lessonRecord.tmdid}";
+                    lessonRecord.code = $"LessonRecord";
                     tbname = "Teacher";
                 }
                 if (tbname == null) {

+ 129 - 11
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -1391,10 +1391,12 @@ namespace TEAMModelOS.Controllers
         [HttpPost("add-area-school-admin")]
         public async Task<IActionResult> AddAreaSchoolAdmin(JsonElement data)
         {
+            List<School> errorSchool = new List<School>();
             var client = _azureCosmos.GetCosmosClient();
             List<string> tmdids = data.GetProperty("tmdids").ToObject<List<string>>();
             data.TryGetProperty("areaId", out JsonElement areaId);
             data.TryGetProperty("schoolIds", out JsonElement schoolIds);
+            data.TryGetProperty("addSchool", out JsonElement addSchool);
             data.TryGetProperty("areaAdmin", out JsonElement areaAdmin);
             List<string> ids = new List<string>();
             string idsSql = "";
@@ -1403,12 +1405,87 @@ namespace TEAMModelOS.Controllers
                 ids = schoolIds.ToObject<List<string>>();
                 if (ids.IsNotEmpty())
                 {
-                    idsSql = $" or  c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
+                    idsSql = $"    c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
                 }
             }
-            string areaIdsql = string.IsNullOrWhiteSpace($"{areaId}") ? "-0000000" : $"{areaId}";
-            string sql = $"select distinct value(c) from c where c.areaId='{areaIdsql}'  {idsSql}";
             List<School> schools = new List<School>();
+            if (addSchool.ValueKind.Equals(JsonValueKind.Array))
+            {
+                List<School> codes = new();
+                codes = addSchool.ToObject<List<School>>();
+                List<School> schoolsNew = new List<School>();
+                string _areaId = null;
+                if (!string.IsNullOrWhiteSpace($"{areaId}"))
+                {
+                    _areaId = $"{areaId}";
+                }
+                int scale = 0;
+                data.TryGetProperty("scale", out JsonElement _scale);
+                if (!string.IsNullOrWhiteSpace($"{_scale}"))
+                {
+                    int.TryParse($"{_scale}", out scale);
+                }
+                int size = 0;
+                data.TryGetProperty("size", out JsonElement _size);
+                if (!string.IsNullOrWhiteSpace($"{_size}"))
+                {
+                    int.TryParse($"{_size}", out size);
+                }
+               
+                codes.ForEach(x => {
+                    string campusId = Guid.NewGuid().ToString();
+                    List<Period> periods = new List<Period>();
+                    periods.Add(new Period
+                    {
+                        id = Guid.NewGuid().ToString(),
+                        name = x.name,
+                        campusId = campusId,
+                        semesterCount = 2,
+                        gradeCount = 1,
+                        grades = new List<string> { "一年级" },
+                        subjectCount = 1,
+                        subjects = new List<Subject> { new Subject { name = "预设学科", id = Guid.NewGuid().ToString() } },
+                        semesters = new List<Semester>
+                        {
+                            new Semester { name = "上学期", start = 1, month = 9, day = 1, id = Guid.NewGuid().ToString() },
+                            new Semester { name = "下学期", start = 0, month = 3, day = 1, id = Guid.NewGuid().ToString() }
+                        },
+                    });
+                    School school = new School
+                    {
+                        id = x.id,
+                        name = x.name,
+                        size = size,
+                        code = "Base",
+                        campuses = new List<Campus> { new Campus { name = x.name, id = campusId } },
+                        region = "中国",
+                        province = x.province,
+                        city = $"{x.city}",
+                        timeZone = new SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
+                        type = 1,
+                        pk = "School",
+                        ttl = -1,
+                        schoolCode = x.id,
+                        dist = $"{x.dist}",
+                        period = periods,
+                        areaId = String.IsNullOrWhiteSpace($"{areaId}") ? null: $"{areaId}",
+                        standard = $"standard2"
+                    };
+                    schoolsNew.Add(school);
+                });
+                foreach (var sch in schoolsNew) {
+                    try
+                    {
+                       await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.School).CreateItemAsync(sch,new PartitionKey("Base"));
+                        schools.Add(sch);
+                    }
+                    catch (CosmosException ex ){
+                        errorSchool.Add(sch);
+                    }
+                }
+            }
+            string areaIdsql = string.IsNullOrWhiteSpace($"{areaId}") ? "-0000000" : $"{areaId}";
+            string sql = $"select distinct value(c) from c where    {idsSql}";
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<School>(
                 queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
             {
@@ -1442,6 +1519,29 @@ namespace TEAMModelOS.Controllers
                 }
                 foreach (var school in schools)
                 {
+                    if (!string.IsNullOrWhiteSpace($"{areaId}")) {
+                        school.areaId= $"{areaId}";
+                    }
+                    data.TryGetProperty("scale", out JsonElement _scale);
+                    if (!string.IsNullOrWhiteSpace($"{_scale}"))
+                    {
+                        int  scale = 0;
+                        int.TryParse($"{_scale}",out scale);
+                        if (scale > 0) {
+                            school.scale = scale;
+                        }
+                    }
+                    data.TryGetProperty("size", out JsonElement _size);
+                    if (!string.IsNullOrWhiteSpace($"{_size}"))
+                    {
+                        int size = 0;
+                        int.TryParse($"{_size}", out size);
+                        if (size > 0)
+                        {
+                            school.size = size;
+                        }
+                    }
+                    await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(school, school.id, new PartitionKey("Base"));
                     Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(tmdid, new PartitionKey($"Teacher-{school.id}"));
                     if (response.Status == 200)
                     {
@@ -1510,7 +1610,7 @@ namespace TEAMModelOS.Controllers
                 await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(teacher, tmdid, new PartitionKey($"Base"));
                 teachers.Add(teacher);
             }
-            return Ok(new { teachers, schoolsTeachers });
+            return Ok(new { teachers, schoolsTeachers, errorSchool });
         }
 
         /// <summary>
@@ -1957,14 +2057,32 @@ namespace TEAMModelOS.Controllers
                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<School>(item, item.id, new PartitionKey(item.code));
             }
             return Ok(schoolsSet);
+        }    /// <summary>
+             /// 修复学校课例及blob计算
+             /// </summary>
+             /// <param name="jsonElement"></param>
+             /// <returns></returns>
+        [HttpPost("fix-teacher-private-lesson-record")]
+        public async Task<IActionResult> FixTeacherPrivateLessonRecord(JsonElement json)
+        {
+            var client = _azureCosmos.GetCosmosClient();
+            string sql = " SELECT distinct value(c)  FROM c  where c.pk='LessonRecord'  ";
+            List<LessonRecord> lessonRecords = new List<LessonRecord>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<LessonRecord>(queryText: sql, requestOptions: new QueryRequestOptions {}))
+            {
+                item.code = "LessonRecord";
+                await  _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(item,new PartitionKey (item.code));
+                lessonRecords.Add(item);
+            }
+            return Ok(lessonRecords);
         }
 
-        /// <summary>
-        /// 修复学校课例及blob计算
-        /// </summary>
-        /// <param name="jsonElement"></param>
-        /// <returns></returns>
-        [HttpPost("fix-school-lesson-record")]
+            /// <summary>
+            /// 修复学校课例及blob计算
+            /// </summary>
+            /// <param name="jsonElement"></param>
+            /// <returns></returns>
+            [HttpPost("fix-school-lesson-record")]
         public async Task<IActionResult> FixSchoolLessonRecord(JsonElement json)
         {
             var client = _azureCosmos.GetCosmosClient();
@@ -2103,7 +2221,7 @@ namespace TEAMModelOS.Controllers
                 else if ($"{scope}".Equals("private"))
                 {
                     blobname = $"{tmdid}";
-                    code = $"LessonRecord-{tmdid}";
+                    code = $"LessonRecord";
                     tbname = "Teacher";
                 }
                 //如果有更新 则去读取/{_lessonId}/IES/base.json

+ 3 - 3
TEAMModelOS/TEAMModelOS.csproj

@@ -32,9 +32,9 @@
     <SpaRoot>ClientApp\</SpaRoot>
     <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
     <UserSecretsId>078b5d89-7d90-4f6a-88fc-7d96025990a8</UserSecretsId>
-    <Version>5.2204.20</Version>
-    <AssemblyVersion>5.2204.20.1</AssemblyVersion>
-    <FileVersion>5.2204.20.1</FileVersion>
+    <Version>5.2204.21</Version>
+    <AssemblyVersion>5.2204.21.1</AssemblyVersion>
+    <FileVersion>5.2204.21.1</FileVersion>
     <Description>TEAMModelOS(IES5)</Description>
     <PackageReleaseNotes>6.0版本说明</PackageReleaseNotes>
     <PackageId>TEAMModelOS</PackageId>

+ 2 - 2
TEAMModelOS/appsettings.Development.json

@@ -24,8 +24,8 @@
       "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodeltest;AccountKey=O2W2vadCqexDxWO+px+QK7y1sHwsYj8f/WwKLdOdG5RwHgW/Dupz9dDUb4c1gi6ojzQaRpFUeAAmOu4N9E+37A==;EndpointSuffix=core.chinacloudapi.cn"
     },
     "Cosmos": {
-      //"ConnectionString": "AccountEndpoint=https://teammodel.documents.azure.com:443/;AccountKey=opemBAZi0yATewIlhxDYoIEUqncT5qJh3pUBZsBkTqEkuLYTuu3VS7oaDGJlPp8ASwm5SVSrK2caJsjgmqRw9g==;"
-      "ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
+      "ConnectionString": "AccountEndpoint=https://teammodel.documents.azure.com:443/;AccountKey=opemBAZi0yATewIlhxDYoIEUqncT5qJh3pUBZsBkTqEkuLYTuu3VS7oaDGJlPp8ASwm5SVSrK2caJsjgmqRw9g==;"
+      //"ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
       //"ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
     },
     "Redis": {