Procházet zdrojové kódy

处理统计查询方法

Li před 2 roky
rodič
revize
5e6d8ac48c

+ 26 - 26
TEAMModelBI/Controllers/BIHome/HomeStatisController.cs

@@ -242,11 +242,11 @@ namespace TEAMModelBI.Controllers.BIHome
                     foreach (var itemSchool in schoolIds)
                     foreach (var itemSchool in schoolIds)
                     {
                     {
                         //查询全部教师人数
                         //查询全部教师人数
-                        string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
+                        string sqlT = $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
                         teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT, "Base");
                         teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT, "Base");
 
 
                         //查询全部学生人数
                         //查询全部学生人数
-                        string sqlS = $"select count(c.id) as totals from c";
+                        string sqlS = $"select value(count(c.id)) from c";
                         teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlS, $"Base-{itemSchool}");
                         teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlS, $"Base-{itemSchool}");
                     }
                     }
 
 
@@ -302,12 +302,12 @@ namespace TEAMModelBI.Controllers.BIHome
                     foreach (var itemSchool in schoolIds)
                     foreach (var itemSchool in schoolIds)
                     {
                     {
                         //查询全部教师人数
                         //查询全部教师人数
-                        string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
+                        string sqlT = $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
                         teachCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT,  "Base");
                         teachCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT,  "Base");
 
 
                         //查询全部学生人数
                         //查询全部学生人数
-                        string sqlS = $"select count(c.id) as totals from c";
-                        stuCount += await CommonFind.FindTotals(cosmosClient, sqlS, "Student", $"Base-{itemSchool}");
+                        string sqlS = $"select value(count(c.id)) from c";
+                        stuCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlS, $"Base-{itemSchool}");
                     }
                     }
                 }
                 }
 
 
@@ -373,12 +373,12 @@ namespace TEAMModelBI.Controllers.BIHome
                             foreach (var itemSchool in schoolIds)
                             foreach (var itemSchool in schoolIds)
                             {
                             {
                                 //查询学校教师人数
                                 //查询学校教师人数
-                                string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
-                                tempCode.teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher", "Base");
+                                string sqlT = $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
+                                tempCode.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT,  "Base");
 
 
                                 //查询学校学生人数
                                 //查询学校学生人数
-                                string sqlStu = $"select count(c.id) as totals from c";
-                                tempCode.studentCount += await CommonFind.FindTotals(cosmosClient, sqlStu, "Student", $"Base-{itemSchool}");
+                                string sqlStu = $"select value(count(c.id)) from c";
+                                tempCode.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlStu, $"Base-{itemSchool}");
                             }
                             }
                         }
                         }
 
 
@@ -406,12 +406,12 @@ namespace TEAMModelBI.Controllers.BIHome
                             foreach (var itemSchool in schoolIds)
                             foreach (var itemSchool in schoolIds)
                             {
                             {
                                 //查询学校教师人数
                                 //查询学校教师人数
-                                string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
-                                tempProvinceStics.teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher", "Base");
+                                string sqlT = $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
+                                tempProvinceStics.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT,  "Base");
 
 
                                 //查询学校学生人数
                                 //查询学校学生人数
-                                string sqlStu = "select count(c.id) as totals from c";
-                                tempProvinceStics.studentCount += await CommonFind.FindTotals(cosmosClient, sqlStu, "Student", $"Base-{itemSchool}");
+                                string sqlStu = "select value(count(c.id)) from c";
+                                tempProvinceStics.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlStu, $"Base-{itemSchool}");
 
 
                             }
                             }
                         }
                         }
@@ -466,8 +466,8 @@ namespace TEAMModelBI.Controllers.BIHome
                     if (tempCode != null)
                     if (tempCode != null)
                     {
                     {
                         //string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
                         //string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
-                        string sqlTxt = $"select count(c.id) totals from c where c.areaId='{itemStandrd.areaId}' and c.standard='{itemStandrd.standard}'";
-                        tempCode.schoolCount += await CommonFind.FindTotals(cosmosClient, sqlTxt, "School", "Base");
+                        string sqlTxt = $"select value(count(c.id)) from c where c.areaId='{itemStandrd.areaId}' and c.standard='{itemStandrd.standard}'";
+                        tempCode.schoolCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", sqlTxt,  "Base");
 
 
                         var tempModel = citySchools.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
                         var tempModel = citySchools.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
                         if (tempModel != null)
                         if (tempModel != null)
@@ -481,8 +481,8 @@ namespace TEAMModelBI.Controllers.BIHome
                         citySchool.cityName = itemStandrd.cityName;
                         citySchool.cityName = itemStandrd.cityName;
 
 
                         //string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
                         //string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
-                        string sqlTxt = $"select count(c.id) totals from c where c.areaId='{itemStandrd.areaId}' and c.standard='{itemStandrd.standard}'";
-                        citySchool.schoolCount += await CommonFind.FindTotals(cosmosClient, sqlTxt, "School", "Base");
+                        string sqlTxt = $"select value(count(c.id)) from c where c.areaId='{itemStandrd.areaId}' and c.standard='{itemStandrd.standard}'";
+                        citySchool.schoolCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", sqlTxt,  "Base");
 
 
                         citySchools.Add(citySchool);
                         citySchools.Add(citySchool);
                     }
                     }
@@ -548,14 +548,14 @@ namespace TEAMModelBI.Controllers.BIHome
                         foreach (var itemSchool in schoolIds)
                         foreach (var itemSchool in schoolIds)
                         {
                         {
                             //查询学校教师人数
                             //查询学校教师人数
-                            string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
+                            string sqlT = $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
                             //string sqlT = $"select count(c.id) as totals from c  where c.code='Teacher-{itemSchool}' and contains(c.roles,'teacher')";
                             //string sqlT = $"select count(c.id) as totals from c  where c.code='Teacher-{itemSchool}' and contains(c.roles,'teacher')";
 
 
-                            districtStics.teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher", "Base");
+                            districtStics.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT, "Base");
 
 
                             //查询学校学生人数
                             //查询学校学生人数
-                            string sqlS = $"select count(c.id) as totals from c ";
-                            districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, sqlS, "Student", $"Base-{itemSchool}");
+                            string sqlS = $"select value(count(c.id)) from c ";
+                            districtStics.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlS, $"Base-{itemSchool}");
 
 
                         }                        
                         }                        
                     }
                     }
@@ -631,10 +631,10 @@ namespace TEAMModelBI.Controllers.BIHome
                             foreach (var itemSchool in schoolIds) 
                             foreach (var itemSchool in schoolIds) 
                             {
                             {
                                 //查询学校教师人数
                                 //查询学校教师人数
-                                districtStics.teacherCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'", "Teacher", "Base");
+                                districtStics.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'", "Base");
 
 
                                 //查询学校学生人数
                                 //查询学校学生人数
-                                districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Student", $"Base-{itemSchool}");
+                                districtStics.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", "select value( count(c.id)) from c", $"Base-{itemSchool}");
                             }
                             }
                         }
                         }
 
 
@@ -665,10 +665,10 @@ namespace TEAMModelBI.Controllers.BIHome
                             foreach (var itemSchool in schoolIds)
                             foreach (var itemSchool in schoolIds)
                             {
                             {
                                 //查询学校教师人数
                                 //查询学校教师人数
-                                districtStics.teacherCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'", "Teacher", "Base");
+                                districtStics.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'",  "Base");
 
 
                                 //查询学校学生人数
                                 //查询学校学生人数
-                                districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c", "Student","Base");
+                                districtStics.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", $"select value(count(c.id)) from c", "Base");
                             }
                             }
                             tempDistrictStics.Add(districtStics);
                             tempDistrictStics.Add(districtStics);
                         }
                         }
@@ -765,7 +765,7 @@ namespace TEAMModelBI.Controllers.BIHome
 
 
 
 
                 //查询学校空间和学校Id
                 //查询学校空间和学校Id
-                totalSize = await CommonFind.FindTotals(cosmosClient, "select sum(c.size) as totals from c", "School", "Base");
+                totalSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(sum(c.size)) from c", "Base");
                 schoolId = await CommonFind.FindSchoolIds(cosmosClient, "select c.id,c.size from c", "Base");
                 schoolId = await CommonFind.FindSchoolIds(cosmosClient, "select c.id,c.size from c", "Base");
 
 
                 //查询学校已使用空间大小
                 //查询学校已使用空间大小

+ 1 - 1
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -447,7 +447,7 @@ namespace TEAMModelBI.Controllers.BISchool
                     }
                     }
 
 
                     school.assists = await CommonFind.FindSchoolRoles(cosmosClient, school.id, "assist");
                     school.assists = await CommonFind.FindSchoolRoles(cosmosClient, school.id, "assist");
-                    school.lessonCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c ", "School", $"LessonRecord-{school.id}");
+                    school.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c ", $"LessonRecord-{school.id}");
                 });
                 });
 
 
                 return Ok(new { state = 200, continuationToken, schoolAssists, });
                 return Ok(new { state = 200, continuationToken, schoolAssists, });

+ 3 - 5
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -352,7 +352,6 @@ namespace TEAMModelBI.Controllers.BISchool
                     //schoolAssists.Add(itemSchool);
                     //schoolAssists.Add(itemSchool);
                     schoolAssists = itemSchool;
                     schoolAssists = itemSchool;
                     //school = itemSchool;
                     //school = itemSchool;
-
                 }
                 }
 
 
                 if (schoolAssists.id != null)
                 if (schoolAssists.id != null)
@@ -376,8 +375,7 @@ namespace TEAMModelBI.Controllers.BISchool
                     }
                     }
 
 
                     schoolAssists.assists = await CommonFind.FindSchoolRoles(cosmosClient, schoolAssists.id, "assist");
                     schoolAssists.assists = await CommonFind.FindSchoolRoles(cosmosClient, schoolAssists.id, "assist");
-                    schoolAssists.lessonCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c ", "School", $"LessonRecord-{schoolAssists.id}");
-
+                    schoolAssists.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c ", $"LessonRecord-{schoolAssists.id}");
 
 
                     return Ok(new { state = 200, schoolAssists });
                     return Ok(new { state = 200, schoolAssists });
                 }
                 }
@@ -1235,9 +1233,9 @@ namespace TEAMModelBI.Controllers.BISchool
             //查询学校
             //查询学校
             if (!string.IsNullOrEmpty($"{schoolId}"))
             if (!string.IsNullOrEmpty($"{schoolId}"))
             {
             {
-                allSize = await CommonFind.FindTotals(cosmosClient, $"SELECT c.size as totals FROM c where c.id='{schoolId}'", "School", "Base");
+                allSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"SELECT value(c.size) FROM c where c.id='{schoolId}'",  "Base");
 
 
-                teacherSpace = await CommonFind.FindTotals(cosmosClient, $"SELECT sum(c.size) as totals FROM c", "School", $"Teacher-{schoolId}");
+                teacherSpace = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"SELECT value(sum(c.size)) FROM c", $"Teacher-{schoolId}");
 
 
                 long blobsize = 0;
                 long blobsize = 0;
                 RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{schoolId}");
                 RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{schoolId}");

+ 2 - 2
TEAMModelBI/Controllers/Census/BlobLogController.cs

@@ -49,7 +49,7 @@ namespace TEAMModelBI.Controllers.Census
             var cosmosClient = _azureCosmos.GetCosmosClient();
             var cosmosClient = _azureCosmos.GetCosmosClient();
             if ($"{site}".Equals(BIConst.Global))
             if ($"{site}".Equals(BIConst.Global))
                 cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
                 cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
-            StringBuilder sqlSize = new($"select sum(c.size) as totals from c ");
+            StringBuilder sqlSize = new($"select value(sum(c.size)) from c ");
             long useSize = 0;  //使用大小
             long useSize = 0;  //使用大小
             List<RecBlobFile> blobFiles = new();
             List<RecBlobFile> blobFiles = new();
 
 
@@ -120,7 +120,7 @@ namespace TEAMModelBI.Controllers.Census
             }
             }
 
 
             var typeCount = blobFiles.GroupBy(m => new { m.type }).Select(y => new { key = y.Key.type, value = y.Count() }).ToList();
             var typeCount = blobFiles.GroupBy(m => new { m.type }).Select(y => new { key = y.Key.type, value = y.Count() }).ToList();
-            var areaSize = await CommonFind.FindTotals(cosmosClient, sqlSize.ToString(), "School", "Base");
+            var areaSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", sqlSize.ToString(), "Base");
 
 
             return Ok(new { state = 200, areaSize, useSize, recCount= blobFiles.Count, typeCount });
             return Ok(new { state = 200, areaSize, useSize, recCount= blobFiles.Count, typeCount });
 
 

+ 4 - 5
TEAMModelBI/Controllers/Census/PaperController.cs

@@ -261,9 +261,9 @@ namespace TEAMModelBI.Controllers.Census
 
 
                     SchoolPaper schoolPaper = new SchoolPaper() { id = schoolId, name = school != null ? school.name : schoolId };
                     SchoolPaper schoolPaper = new SchoolPaper() { id = schoolId, name = school != null ? school.name : schoolId };
 
 
-                    string sqlTxt = $"select count(c.id) AS totals from c where c.createTime >={start} and c.createTime <={end}";
+                    string sqlTxt = $"select value(count(c.id)) from c where c.createTime >={start} and c.createTime <={end}";
 
 
-                    schoolPaper.totals += await CommonFind.FindTotals(cosmosClient, sqlTxt, "School", $"Paper-{schoolId}");
+                    schoolPaper.totals += await CommonFind.GetSqlValueCount(cosmosClient, "School", sqlTxt, $"Paper-{schoolId}");
 
 
                     //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText:sqlTxt.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{schoolId}")}))
                     //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText:sqlTxt.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{schoolId}")}))
                     //{
                     //{
@@ -285,9 +285,8 @@ namespace TEAMModelBI.Controllers.Census
             }
             }
             else
             else
             {
             {
-                string sqlTxt = $"SELECT COUNT(c.id) AS totals FROM c where c.pk='Paper' and c.createTime >= {start} and c.createTime <= {end}";
-
-                totals = await CommonFind.FindTotals(cosmosClient, sqlTxt, new List<string>() { "School" });
+                string sqlTxt = $"SELECT value(count(c.id)) FROM c where c.pk='Paper' and c.createTime >= {start} and c.createTime <= {end}";
+                totals = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School" }, sqlTxt);
             }
             }
 
 
             return Ok(new { state = 200, totals });
             return Ok(new { state = 200, totals });

+ 14 - 14
TEAMModelBI/Controllers/Census/ProductStatisController.cs

@@ -332,15 +332,15 @@ namespace TEAMModelBI.Controllers.Census
                         }
                         }
                     }
                     }
 
 
-                    long tempBuySerc = await CommonFind.FindTotals(cosmosClient, "select count(c.id) as totals from c where c.dataType='service' and c.pk='Product'", "School", $"Product-{scId}");
-                    long tempBuySeri = await CommonFind.FindTotals(cosmosClient, "select count(c.id) as totals from c where c.dataType='serial' and c.pk='Product'", "School", $"Product-{scId}");
+                    long tempBuySerc = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c where c.dataType='service' and c.pk='Product'", $"Product-{scId}");
+                    long tempBuySeri = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c where c.dataType='serial' and c.pk='Product'", $"Product-{scId}");
 
 
-                    string sqlTxt = "select count(c.id) as totals from c where c.pk='Product' and c.dataType='{0}' and c.regDate>={1} and c.regDate<={2}";
-                    long tempLastYearSerc = await CommonFind.FindTotals(cosmosClient, string.Format(sqlTxt, "service", lastYearStart, lastYearEnd), "School", $"Product-{scId}");  //计算去年购买的服务数量
-                    long tempyearSerc = await CommonFind.FindTotals(cosmosClient, string.Format(sqlTxt, "service", yearStart, yearEnd), "School", $"Product-{scId}");    //今年购买的服务数量
+                    string sqlTxt = "select value(count(c.id)) from c where c.pk='Product' and c.dataType='{0}' and c.regDate>={1} and c.regDate<={2}";
+                    long tempLastYearSerc = await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(sqlTxt, "service", lastYearStart, lastYearEnd), $"Product-{scId}");  //计算去年购买的服务数量
+                    long tempyearSerc = await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(sqlTxt, "service", yearStart, yearEnd),  $"Product-{scId}");    //今年购买的服务数量
 
 
-                    long tempLastYearSeri = await CommonFind.FindTotals(cosmosClient, string.Format(sqlTxt, "serial", lastYearStart, lastYearEnd), "School", $"Product-{scId}");  //计算去年购买的软体数量
-                    long tempYearSeri = await CommonFind.FindTotals(cosmosClient, string.Format(sqlTxt, "serial", yearStart, yearEnd), "School", $"Product-{scId}");    //今年购买的软体数量
+                    long tempLastYearSeri = await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(sqlTxt, "serial", lastYearStart, lastYearEnd), $"Product-{scId}");  //计算去年购买的软体数量
+                    long tempYearSeri = await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(sqlTxt, "serial", yearStart, yearEnd), $"Product-{scId}");    //今年购买的软体数量
 
 
                     schoolAnalys.Add(new RecSchoolAnalys { id = school.id, name = school.name, picture = school.picture, size = school.size, scale = school.scale, buySerc = tempBuySerc, lastYearSerc = tempLastYearSerc, yearSerc = tempyearSerc, buySeri = tempBuySeri, lastYearSeri = tempLastYearSeri, yearSeri = tempYearSeri });
                     schoolAnalys.Add(new RecSchoolAnalys { id = school.id, name = school.name, picture = school.picture, size = school.size, scale = school.scale, buySerc = tempBuySerc, lastYearSerc = tempLastYearSerc, yearSerc = tempyearSerc, buySeri = tempBuySeri, lastYearSeri = tempLastYearSeri, yearSeri = tempYearSeri });
 
 
@@ -449,15 +449,15 @@ namespace TEAMModelBI.Controllers.Census
                     }
                     }
                 }
                 }
 
 
-                long tempBuySerc = await CommonFind.FindTotals(cosmosClient, "select count(c.id) as totals from c where c.dataType='service' and c.pk='Product'", "School", $"Product-{scId}");
-                long  tempBuySeri = await CommonFind.FindTotals(cosmosClient, "select count(c.id) as totals from c where c.dataType='serial' and c.pk='Product'", "School", $"Product-{scId}");
+                long tempBuySerc = await CommonFind.GetSqlValueCount(cosmosClient, "select value(count(c.id)) from c where c.dataType='service' and c.pk='Product'", "School", $"Product-{scId}");
+                long  tempBuySeri = await CommonFind.GetSqlValueCount(cosmosClient, "select value(count(c.id)) from c where c.dataType='serial' and c.pk='Product'", "School", $"Product-{scId}");
 
 
-                string sqlTxt = "select count(c.id) as totals from c where c.pk='Product' and c.dataType='{0}' and c.regDate>={1} and c.regDate<={2}";
-                long  tempLastYearSerc = await CommonFind.FindTotals(cosmosClient, string.Format(sqlTxt, "service", lastYearStart, lastYearEnd), "School", $"Product-{scId}");  //计算去年购买的服务数量
-                long tempyearSerc = await CommonFind.FindTotals(cosmosClient, string.Format(sqlTxt, "service", yearStart, yearEnd), "School", $"Product-{scId}");    //今年购买的服务数量
+                string sqlTxt = "select value(count(c.id)) from c where c.pk='Product' and c.dataType='{0}' and c.regDate>={1} and c.regDate<={2}";
+                long  tempLastYearSerc = await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(sqlTxt, "service", lastYearStart, lastYearEnd), $"Product-{scId}");  //计算去年购买的服务数量
+                long tempyearSerc = await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(sqlTxt, "service", yearStart, yearEnd), $"Product-{scId}");    //今年购买的服务数量
 
 
-                long tempLastYearSeri = await CommonFind.FindTotals(cosmosClient, string.Format(sqlTxt, "serial", lastYearStart, lastYearEnd), "School", $"Product-{scId}");  //计算去年购买的软体数量
-                long tempYearSeri = await CommonFind.FindTotals(cosmosClient, string.Format(sqlTxt, "serial", yearStart, yearEnd), "School", $"Product-{scId}");    //今年购买的软体数量
+                long tempLastYearSeri = await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(sqlTxt, "serial", lastYearStart, lastYearEnd),  $"Product-{scId}");  //计算去年购买的软体数量
+                long tempYearSeri = await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(sqlTxt, "serial", yearStart, yearEnd), $"Product-{scId}");    //今年购买的软体数量
 
 
                 schoolAnalys.Add(new RecSchoolAnalys { id = school.id, name = school.name, picture = school.picture, size = school.size, scale = school.scale, buySerc = tempBuySerc, lastYearSerc = tempLastYearSerc, yearSerc = tempyearSerc, buySeri = tempBuySeri, lastYearSeri = tempLastYearSeri, yearSeri = tempYearSeri });
                 schoolAnalys.Add(new RecSchoolAnalys { id = school.id, name = school.name, picture = school.picture, size = school.size, scale = school.scale, buySerc = tempBuySerc, lastYearSerc = tempLastYearSerc, yearSerc = tempyearSerc, buySeri = tempBuySeri, lastYearSeri = tempLastYearSeri, yearSeri = tempYearSeri });
 
 

+ 21 - 21
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -88,10 +88,10 @@ namespace TEAMModelBI.Controllers.Census
             var (lastTermStart, lastTermEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastterm");   //计算上学期开始/结束时间
             var (lastTermStart, lastTermEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastterm");   //计算上学期开始/结束时间
             var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");   //计算本学期开始/结束时间
             var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");   //计算本学期开始/结束时间
 
 
-            schoolCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "School", "Base");  //所有学校数量
-            tecCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Teacher", "Base");  //所有教师数量
-            stuCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Student", "Base");    //所有学生数量
-            allClassCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Class'", new List<string>() { "School" }); //所有班级数量
+            schoolCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c", "Base");  //所有学校数量
+            tecCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", "select value(count(c.id)) from c", "Base");  //所有教师数量
+            stuCount = await CommonFind.GetSqlValueCount(cosmosClient, "Student", "select value(count(c.id)) from c", "Base");    //所有学生数量
+            allClassCount = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School" }, "select count(c.id) totals from c where c.pk = 'Class'"); //所有班级数量
             roomCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Room'", new List<string>() { "School" }); //所有教室数量
             roomCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Room'", new List<string>() { "School" }); //所有教室数量
             wisdomRoomCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Room' and c.serial != null", new List<string>() { "School" }); //智慧教室数量
             wisdomRoomCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c where c.pk = 'Room' and c.serial != null", new List<string>() { "School" }); //智慧教室数量
 
 
@@ -178,9 +178,9 @@ namespace TEAMModelBI.Controllers.Census
             var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
             var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
             var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year");         //计算今年开始/结束时间
             var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year");         //计算今年开始/结束时间
 
 
-            string unifySqlTxt = "select count(c.id) as totals from c";
-            string unifyTimeSql = "select count(c.id) as totals from c where c.startTime>={0} and c.startTime<={1}";
-            string blobTimeSql = "select count(c.id) as totals from c where c.time>={0} and c.time<={1}";
+            string unifySqlTxt = "select value(count(c.id)) from c";
+            string unifyTimeSql = "select value(count(c.id)) from c where c.startTime>={0} and c.startTime<={1}";
+            string blobTimeSql = "select value(count(c.id)) from c where c.time>={0} and c.time<={1}";
             List<RecSchoolDate> recSchoolDates = new();
             List<RecSchoolDate> recSchoolDates = new();
 
 
             foreach (var itemId in schoolIds)
             foreach (var itemId in schoolIds)
@@ -192,23 +192,23 @@ namespace TEAMModelBI.Controllers.Census
                     using var json = await JsonDocument.ParseAsync(response.ContentStream);
                     using var json = await JsonDocument.ParseAsync(response.ContentStream);
                     school = json.ToObject<School>();
                     school = json.ToObject<School>();
                 }
                 }
-                tecCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where ARRAY_CONTAINS(c.roles,'teacher',true) and c.status = 'join'", "School", $"Teacher-{itemId}");
-                stuCount += await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "Student", $"Base-{itemId}");
-                classCount += await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "School", $"Class-{itemId}");
-                roomCount += await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "School", $"Room-{itemId}");
+                tecCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c where ARRAY_CONTAINS(c.roles,'teacher',true) and c.status = 'join'", $"Teacher-{itemId}");
+                stuCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", unifySqlTxt, $"Base-{itemId}");
+                classCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", unifySqlTxt, $"Class-{itemId}");
+                roomCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", unifySqlTxt, $"Room-{itemId}");
                 //学校所有课例
                 //学校所有课例
-                int tempLessCount   = await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "School", $"LessonRecord-{itemId}");
-                lastWeekLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql,lastWeekStart,lastWeekEnd), "School", $"LessonRecord-{itemId}");
-                weekLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, weekStart, weekEnd), "School", $"LessonRecord-{itemId}");
-                lastTermLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, lastTermStart, lastTermEnd), "School", $"LessonRecord-{itemId}");
-                termLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, termStart, termEnd), "School", $"LessonRecord-{itemId}");
-                lastYearLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, lastYearStart, lastYearEnd), "School", $"LessonRecord-{itemId}");
-                yearLessCount += await CommonFind.FindTotals(cosmosClient, string.Format(unifyTimeSql, yearStart, yearEnd), "School", $"LessonRecord-{itemId}");
+                int tempLessCount   = await CommonFind.GetSqlValueCount(cosmosClient, "School", unifySqlTxt,  $"LessonRecord-{itemId}");
+                lastWeekLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, lastWeekStart, lastWeekEnd), $"LessonRecord-{itemId}");
+                weekLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, weekStart, weekEnd), $"LessonRecord-{itemId}");
+                lastTermLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, lastTermStart, lastTermEnd), $"LessonRecord-{itemId}");
+                termLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, termStart, termEnd), $"LessonRecord-{itemId}");
+                lastYearLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, lastYearStart, lastYearEnd), $"LessonRecord-{itemId}");
+                yearLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, yearStart, yearEnd), $"LessonRecord-{itemId}");
 
 
                 //学校资源
                 //学校资源
-                int tempBloblog = await CommonFind.FindTotals(cosmosClient, unifySqlTxt, "School", $"Bloblog-{itemId}");
-                lastYearBloblog += await CommonFind.FindTotals(cosmosClient, string.Format(blobTimeSql,lastYearStart,lastYearEnd), "School", $"Bloblog-{itemId}");
-                yearBloblog += await CommonFind.FindTotals(cosmosClient, string.Format(blobTimeSql, yearStart, yearEnd), "School", $"Bloblog-{itemId}");
+                int tempBloblog = await CommonFind.GetSqlValueCount(cosmosClient, "School", unifySqlTxt, $"Bloblog-{itemId}");
+                lastYearBloblog += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(blobTimeSql, lastYearStart, lastYearEnd), $"Bloblog-{itemId}");
+                yearBloblog += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(blobTimeSql, yearStart, yearEnd), $"Bloblog-{itemId}");
 
 
                 //学校活动
                 //学校活动
                 long tempallActivity = 0;
                 long tempallActivity = 0;

+ 0 - 27
TEAMModelBI/Tool/CommonFind.cs

@@ -40,33 +40,6 @@ namespace TEAMModelBI.Tool
             return totals;
             return totals;
         }
         }
 
 
-        /// <summary>
-        /// 查询总数带code
-        /// </summary>
-        /// <param name="cosmosClient"></param>
-        /// <param name="sqlTxt">sql语句</param>
-        /// <param name="containerId">数据库表</param>
-        /// <param name="code">数据分区键</param>
-        /// <returns>返回总数</returns>
-        public static async Task<int> FindTotals(CosmosClient cosmosClient, string sqlTxt, string containerId, string code) 
-        {
-            int totals = 0;
-
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", containerId).GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
-            {
-                using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
-                {
-                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                    {
-                        totals += obj.GetProperty("totals").GetInt32();
-                    }
-                }
-            }
-
-            return totals;
-        }
-
         /// <summary>
         /// <summary>
         /// 查询学校教师角色列表
         /// 查询学校教师角色列表
         /// </summary>
         /// </summary>