Browse Source

优化代码、新增代码,

Li 3 years ago
parent
commit
8c3f0e26b5

+ 99 - 354
TEAMModelBI/Controllers/BIHome/HomeStatisController.cs

@@ -280,35 +280,14 @@ namespace TEAMModelBI.Controllers.BIHome
                     sticsDist.distName = itemStandrds.distName;
                     sticsDist.standard = itemStandrds.standard;
 
-                    //
+                    //查询区级下的学校ID
                     string sqlTxt = $"select c.id from c where c.standard='{itemStandrds.standard}'";
                     List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, sqlTxt, "Base");
 
-                    //List<string> schoolIds = new List<string>();
-                    //int schoolCount = 0;
-
-                    //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrds.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                    //{
-                    //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                    //    {
-                    //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                    //        while (accounts.MoveNext())
-                    //        {
-                    //            JsonElement account = accounts.Current;
-                    //            schoolIds.Add(account.GetProperty("id").GetString());
-                    //            schoolCount += 1;
-                    //        }
-                    //    }
-                    //}
-
                     sticsDist.schoolCount = schoolIds.Count;
 
                     int teacherCount = 0;  //教师数量
                     int studentCount = 0;  //学生数量
-                    List<string> teacherIds = new List<string>();
-
-                    List<string> studentIds = new List<string>();
 
                     //查询学校下面的教师人数
                     foreach (var itemSchool in schoolIds)
@@ -317,40 +296,9 @@ namespace TEAMModelBI.Controllers.BIHome
                         string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
                         teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher","Base");
 
-                        //string sqlTeacherTxt = $"select distinct value(c) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
-                        //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: sqlTeacherTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                        //{
-                        //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                        //    {
-                        //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        //        while (accounts.MoveNext())
-                        //        {
-                        //            //JsonElement account = accounts.Current;
-                        //            //teacherIds.Add(account.GetProperty("id").GetString());
-                        //            teacherCount += 1;
-                        //        }
-                        //    }
-                        //}
-
                         //查询全部学生人数
                         string sqlS = $"select count(c.id) as totals from c";
                         teacherCount += await CommonFind.FindTotals(cosmosClient, sqlS, "Student", $"Base-{itemSchool}");
-
-                        //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
-                        //{
-                        //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                        //    {
-                        //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        //        while (accounts.MoveNext())
-                        //        {
-                        //            //JsonElement account = accounts.Current;
-                        //            //studentIds.Add(account.GetProperty("id").GetString());
-                        //            studentCount += 1;
-                        //        }
-                        //    }
-                        //}
                     }
 
                     sticsDist.teacherCount = teacherCount;
@@ -410,66 +358,8 @@ namespace TEAMModelBI.Controllers.BIHome
                         stuCount += await CommonFind.FindTotals(cosmosClient, sqlS, "Student", $"Base-{itemSchool}");
                     }
                 }
-                return Ok(new { state = 200, schoolCount = citySchoolCount, teacherCount = teachCount, tudentCount = stuCount });
-
-
-                //List<string> teacherIds = new List<string>();
-                //List<string> studentIds = new List<string>();
 
-                //foreach (var tempSatndard in areaStandard)
-                //{
-                //    List<string> schoolIds = new List<string>();
-                //    await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{tempSatndard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                //    {
-                //        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                //        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                //        {
-                //            var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                //            while (accounts.MoveNext())
-                //            {
-                //                JsonElement account = accounts.Current;
-                //                schoolIds.Add(account.GetProperty("id").GetString()); 
-                //                citySchoolCount += 1;
-                //            }
-                //        }
-                //    }
-
-                //    //查询学校下面的教师人数
-                //    foreach (var itemSchool in schoolIds)
-                //    {
-                //        //查询全部教师人数
-                //        await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join a1 in c.schools where a1.schoolId='{itemSchool}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                //        {
-                //            using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                //            if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                //            {
-                //                var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                //                while (accounts.MoveNext())
-                //                {
-                //                    JsonElement account = accounts.Current;
-                //                    teacherIds.Add(account.GetProperty("id").GetString());
-                //                }
-                //            }
-                //        }
-
-                //        //查询全部学生人数
-                //        await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
-                //        {
-                //            using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                //            if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                //            {
-                //                var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                //                while (accounts.MoveNext())
-                //                {
-                //                    JsonElement account = accounts.Current;
-                //                    studentIds.Add(account.GetProperty("id").GetString());
-                //                }
-                //            }
-                //        }
-                //    }
-                //}
-
-                //return Ok(new { state = 200, schoolCount = citySchoolCount, teacherCount = teacherIds.Count, tudentCount = studentIds.Count });
+                return Ok(new { state = 200, schoolCount = citySchoolCount, teacherCount = teachCount, tudentCount = stuCount });
             }
             catch (Exception ex)
             {
@@ -521,21 +411,7 @@ namespace TEAMModelBI.Controllers.BIHome
                         string sqlSc = $"select c.id from c where c.standard='{itemStandard.standard}'";
                         List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, sqlSc, "Base");
                         tempCode.schoolCount += schoolIds.Count;
-                        //List<string> schoolIds = new List<string>();
-                        //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandard.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                        //{
-                        //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                        //    {
-                        //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        //        while (accounts.MoveNext())
-                        //        {
-                        //            JsonElement account = accounts.Current;
-                        //            schoolIds.Add(account.GetProperty("id").GetString());
-                        //            tempCode.schoolCount += 1;
-                        //        }
-                        //    }
-                        //}
+
                         if (schoolIds.Count > 0)
                         {
                             foreach (var itemSchool in schoolIds)
@@ -544,37 +420,9 @@ namespace TEAMModelBI.Controllers.BIHome
                                 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");
 
-                                //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join a1 in c.schools where a1.schoolId='{itemSchool}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                                //{
-                                //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                                //    {
-                                //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                //        while (accounts.MoveNext())
-                                //        {
-                                //            JsonElement account = accounts.Current;
-                                //            tempCode.teacherCount += 1;
-                                //        }
-                                //    }
-                                //}
-
                                 //查询学校学生人数
                                 string sqlStu = $"select count(c.id) as totals from c";
                                 tempCode.studentCount += await CommonFind.FindTotals(cosmosClient, sqlStu, "Student", $"Base-{itemSchool}");
-
-                                //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
-                                //{
-                                //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                                //    {
-                                //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                //        while (accounts.MoveNext())
-                                //        {
-                                //            JsonElement account = accounts.Current;
-                                //            tempCode.studentCount += 1;
-                                //        }
-                                //    }
-                                //}
                             }
                         }
 
@@ -596,21 +444,7 @@ namespace TEAMModelBI.Controllers.BIHome
                         string sqlSc = $"select c.id from c where c.standard='{itemStandard.standard}'";
                         List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, sqlSc, "Base");
                         tempProvinceStics.schoolCount += schoolIds.Count;
-                        //List<string> schoolIds = new List<string>();
-                        //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandard.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                        //{
-                        //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                        //    {
-                        //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        //        while (accounts.MoveNext())
-                        //        {
-                        //            JsonElement account = accounts.Current;
-                        //            schoolIds.Add(account.GetProperty("id").GetString());
-                        //            tempProvinceStics.schoolCount += 1;
-                        //        }
-                        //    }
-                        //}
+                        
                         if (schoolIds.Count > 0)
                         {
                             foreach (var itemSchool in schoolIds)
@@ -619,37 +453,10 @@ namespace TEAMModelBI.Controllers.BIHome
                                 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");
 
-                                //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join a1 in c.schools where a1.schoolId='{itemSchool}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                                //{
-                                //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                                //    {
-                                //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                //        while (accounts.MoveNext())
-                                //        {
-                                //            JsonElement account = accounts.Current;
-                                //            tempProvinceStics.teacherCount += 1;
-                                //        }
-                                //    }
-                                //}
-
                                 //查询学校学生人数
                                 string sqlStu = "select count(c.id) as totals from c";
                                 tempProvinceStics.studentCount += await CommonFind.FindTotals(cosmosClient, sqlStu, "Student", $"Base-{itemSchool}");
 
-                                //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
-                                //{
-                                //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                                //    {
-                                //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                //        while (accounts.MoveNext())
-                                //        {
-                                //            JsonElement account = accounts.Current;
-                                //            tempProvinceStics.studentCount += 1;
-                                //        }
-                                //    }
-                                //}
                             }
                         }
 
@@ -701,19 +508,6 @@ namespace TEAMModelBI.Controllers.BIHome
                         string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
                         tempCode.schoolCount += await CommonFind.FindTotals(cosmosClient, sqlTxt, "School", "Base");
 
-                        //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrd.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                        //{
-                        //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                        //    {
-                        //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        //        while (accounts.MoveNext())
-                        //        {
-                        //            JsonElement account = accounts.Current;
-                        //            tempCode.schoolCount += 1;
-                        //        }
-                        //    }
-                        //}
                         var tempModel = citySchools.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
                         if (tempModel != null)
                         {
@@ -728,22 +522,6 @@ namespace TEAMModelBI.Controllers.BIHome
                         string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
                         citySchool.schoolCount += await CommonFind.FindTotals(cosmosClient, sqlTxt, "School", "Base");
 
-                        //List<string> schoolIds = new List<string>();
-                        //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrd.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                        //{
-                        //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                        //    {
-                        //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                        //        while (accounts.MoveNext())
-                        //        {
-                        //            JsonElement account = accounts.Current;
-                        //            schoolIds.Add(account.GetProperty("id").GetString());
-                        //            citySchool.schoolCount += 1;
-                        //        }
-                        //    }
-                        //}
-
                         citySchools.Add(citySchool);
                     }
                 }
@@ -796,22 +574,6 @@ namespace TEAMModelBI.Controllers.BIHome
                     List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient,sqlTxt, "Base");
                     districtStics.schoolCount += schoolIds.Count;
 
-                    //List<string> schoolIds = new List<string>();
-                    ////查询区域学校数量
-                    //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrd.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                    //{
-                    //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                    //    {
-                    //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                    //        while (accounts.MoveNext())
-                    //        {
-                    //            JsonElement account = accounts.Current;
-                    //            schoolIds.Add(account.GetProperty("id").GetString());
-                    //            districtStics.schoolCount += 1;
-                    //        }
-                    //    }
-                    //}
 
                     if (schoolIds.Count > 0) 
                     {
@@ -821,38 +583,10 @@ namespace TEAMModelBI.Controllers.BIHome
                             string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
                             districtStics.teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher", "Base");
 
-                            //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join a1 in c.schools where a1.schoolId='{itemSchool}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                            //{
-                            //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                            //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                            //    {
-                            //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                            //        while (accounts.MoveNext())
-                            //        {
-                            //            JsonElement account = accounts.Current;
-                            //            districtStics.teacherCount += 1;
-                            //        }
-                            //    }
-                            //}
-
                             //查询学校学生人数
-
                             string sqlS = $"select count(c.id) as totals from c ";
                             districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, sqlS, "Student", $"Base-{itemSchool}");
 
-                            //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
-                            //{
-                            //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                            //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                            //    {
-                            //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                            //        while (accounts.MoveNext())
-                            //        {
-                            //            JsonElement account = accounts.Current;
-                            //            districtStics.studentCount += 1;
-                            //        }
-                            //    }
-                            //}
                         }                        
                     }
                     districtSticss.Add(districtStics);
@@ -880,7 +614,6 @@ namespace TEAMModelBI.Controllers.BIHome
             try
             {
                 var cosmosClient = _azureCosmos.GetCosmosClient();
-
                 List<AllCityStics> tempAllCityStics = new List<AllCityStics>();
                 //查询省份区域
                 await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select c.name,c.cityCode,c.cityName,c.standard from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
@@ -902,22 +635,24 @@ namespace TEAMModelBI.Controllers.BIHome
                     var tempCode = sticsCitys.Find(x => (x.cityCode) == (itemStandrd.cityCode));
                     if (tempCode != null)
                     {
-                        List<string> schoolIds = new List<string>();
+                        List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.standard='{itemStandrd.standard}'", "Base");
+                        tempCode.schoolCount += schoolIds.Count;
 
-                        await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrd.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                        {
-                            using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                            if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                            {
-                                var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                while (accounts.MoveNext())
-                                {
-                                    JsonElement account = accounts.Current;
-                                    schoolIds.Add(account.GetProperty("id").GetString());
-                                    tempCode.schoolCount += 1;
-                                }
-                            }
-                        }
+                        //List<string> schoolIds = new List<string>();
+                        //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrd.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                        //{
+                        //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                        //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                        //    {
+                        //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                        //        while (accounts.MoveNext())
+                        //        {
+                        //            JsonElement account = accounts.Current;
+                        //            schoolIds.Add(account.GetProperty("id").GetString());
+                        //            tempCode.schoolCount += 1;
+                        //        }
+                        //    }
+                        //}
 
                         var tempModel = sticsCitys.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
                         if (tempModel != null)
@@ -935,34 +670,38 @@ namespace TEAMModelBI.Controllers.BIHome
                             foreach (var itemSchool in schoolIds) 
                             {
                                 //查询学校教师人数
-                                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join a1 in c.schools where a1.schoolId='{itemSchool}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                                {
-                                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                                    {
-                                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                        while (accounts.MoveNext())
-                                        {
-                                            JsonElement account = accounts.Current;
-                                            districtStics.teacherCount += 1;
-                                        }
-                                    }
-                                }
+                                districtStics.teacherCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'", "Teacher", "Base");
+
+                                //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join a1 in c.schools where a1.schoolId='{itemSchool}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                                //{
+                                //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                                //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                //    {
+                                //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                                //        while (accounts.MoveNext())
+                                //        {
+                                //            JsonElement account = accounts.Current;
+                                //            districtStics.teacherCount += 1;
+                                //        }
+                                //    }
+                                //}
 
                                 //查询学校学生人数
-                                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
-                                {
-                                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                                    {
-                                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                        while (accounts.MoveNext())
-                                        {
-                                            JsonElement account = accounts.Current;
-                                            districtStics.studentCount += 1;
-                                        }
-                                    }
-                                }
+                                districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Student", $"Base-{itemSchool}");
+
+                                //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
+                                //{
+                                //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                                //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                //    {
+                                //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                                //        while (accounts.MoveNext())
+                                //        {
+                                //            JsonElement account = accounts.Current;
+                                //            districtStics.studentCount += 1;
+                                //        }
+                                //    }
+                                //}
                             }
                         }
 
@@ -977,21 +716,24 @@ namespace TEAMModelBI.Controllers.BIHome
                         citySchool.cityCode = itemStandrd.cityCode;
                         citySchool.cityName = itemStandrd.cityName;
 
-                        List<string> schoolIds = new List<string>();
-                        await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrd.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                        {
-                            using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                            if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                            {
-                                var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                while (accounts.MoveNext())
-                                {
-                                    JsonElement account = accounts.Current;
-                                    schoolIds.Add(account.GetProperty("id").GetString());
-                                    citySchool.schoolCount += 1;
-                                }
-                            }
-                        }
+                        List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.standard='{itemStandrd.standard}'","Base");
+                        citySchool.schoolCount += schoolIds.Count;
+
+                        //List<string> schoolIds = new List<string>();
+                        //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.standard='{itemStandrd.standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                        //{
+                        //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                        //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                        //    {
+                        //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                        //        while (accounts.MoveNext())
+                        //        {
+                        //            JsonElement account = accounts.Current;
+                        //            schoolIds.Add(account.GetProperty("id").GetString());
+                        //            citySchool.schoolCount += 1;
+                        //        }
+                        //    }
+                        //}
 
                         List<DistrictStics> tempDistrictStics = new List<DistrictStics>();
                         if (schoolIds.Count > 0)
@@ -1003,34 +745,38 @@ namespace TEAMModelBI.Controllers.BIHome
                             foreach (var itemSchool in schoolIds)
                             {
                                 //查询学校教师人数
-                                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join a1 in c.schools where a1.schoolId='{itemSchool}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                                {
-                                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                                    {
-                                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                        while (accounts.MoveNext())
-                                        {
-                                            JsonElement account = accounts.Current;
-                                            districtStics.teacherCount += 1;
-                                        }
-                                    }
-                                }
+                                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");
+
+                                //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join a1 in c.schools where a1.schoolId='{itemSchool}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                                //{
+                                //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                                //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                //    {
+                                //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                                //        while (accounts.MoveNext())
+                                //        {
+                                //            JsonElement account = accounts.Current;
+                                //            districtStics.teacherCount += 1;
+                                //        }
+                                //    }
+                                //}
 
                                 //查询学校学生人数
-                                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
-                                {
-                                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                                    {
-                                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                                        while (accounts.MoveNext())
-                                        {
-                                            JsonElement account = accounts.Current;
-                                            districtStics.studentCount += 1;
-                                        }
-                                    }
-                                }
+                                districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c", "Student","Base");
+
+                                //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{itemSchool}") }))
+                                //{
+                                //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                                //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                //    {
+                                //        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                                //        while (accounts.MoveNext())
+                                //        {
+                                //            JsonElement account = accounts.Current;
+                                //            districtStics.studentCount += 1;
+                                //        }
+                                //    }
+                                //}
                             }
                             tempDistrictStics.Add(districtStics);
                         }
@@ -1038,7 +784,6 @@ namespace TEAMModelBI.Controllers.BIHome
                         citySchool.districtSticss = tempDistrictStics;
                         sticsCitys.Add(citySchool);
                     }
-
                 }
 
                 return Ok(new { state = 200, sticsCitys });

+ 6 - 2
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -262,7 +262,7 @@ namespace TEAMModelBI.Controllers.BISchool
                             {
                                 id = createSchoolInfo.id,
                                 name = bischool.name,
-                                size = bischool.size,
+                                size = bischool.size == 0 ? 100 : bischool.size,
                                 code = "Base",
                                 campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
                                 region = bischool.region,
@@ -277,8 +277,10 @@ namespace TEAMModelBI.Controllers.BISchool
                                 ttl = -1,
                                 areaId = bischool.areaId,
                                 schoolCode = createSchoolInfo.id,
-                                period = PresetSchoolPeriod(bischool.period,foundSchools.lang,campusId)
+                                period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
+                                scale = bischool.size >= 300 ? 500 : 0
                             };
+
                             stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
                             //创建学校
                             await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
@@ -560,6 +562,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 if (!jsonElement.TryGetProperty("period", out JsonElement period)) return BadRequest();
                 if (!jsonElement.TryGetProperty("picture", out JsonElement picture)) return BadRequest();
                 if (!jsonElement.TryGetProperty("size", out JsonElement size)) return BadRequest();
+                if (!jsonElement.TryGetProperty("scale", out JsonElement scale)) return BadRequest();
                 if (!jsonElement.TryGetProperty("assistId", out JsonElement _assistId)) return BadRequest();
                 if (!jsonElement.TryGetProperty("tmdId", out JsonElement _tmdId)) return BadRequest();
                 if (!jsonElement.TryGetProperty("tmdName", out JsonElement _tmdName)) return BadRequest();
@@ -582,6 +585,7 @@ namespace TEAMModelBI.Controllers.BISchool
 
                     tempShool.period = periods;
                     tempShool.size = !string.IsNullOrEmpty($"{size}") ? int.Parse($"{size}") : tempShool.size;
+                    tempShool.scale = !string.IsNullOrEmpty($"{scale}") ? int.Parse($"{scale}") : tempShool.scale;
                     tempShool.picture = $"{picture}";
                     //修改学校
                     await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempShool, tempShool.id, new PartitionKey("Base"));

+ 115 - 0
TEAMModelBI/Controllers/BISchool/ProductController.cs

@@ -0,0 +1,115 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Options;
+using System.Collections.Generic;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
+
+namespace TEAMModelBI.Controllers.BISchool
+{
+    [Route("product")]
+    [ApiController]
+    public class ProductController : ControllerBase
+    {
+
+        //数据容器
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly AzureStorageFactory _azureStorage;
+        //钉钉提示信息
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly IConfiguration _configuration;
+
+
+        public ProductController(AzureCosmosFactory azureCosmos,AzureStorageFactory azureStorage,DingDing dingDing,IOptionsSnapshot<Option> option,IConfiguration configuration) 
+        {
+            _azureCosmos = azureCosmos;
+            _azureStorage= azureStorage;
+            _dingDing= dingDing;
+            _option = option?.Value;
+            _configuration = configuration;        
+        }
+
+        /// <summary>
+        /// 依据学校ID查询产品信息
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("get-school")]
+        public async Task<IActionResult> GetSchoolSum(JsonElement jsonElement)
+        {
+            if (!jsonElement.TryGetProperty("schoolCode", out JsonElement schoolCode)) return BadRequest();
+            var clientContainer = _azureCosmos.GetCosmosClient();
+
+            List<SchoolProductSerial> serials = new List<SchoolProductSerial>(); //软体
+            List<SchoolProductService> services = new List<SchoolProductService>(); //服务
+            List<SchoolProductHard> hards = new List<SchoolProductHard>(); //硬体
+
+            SchoolProductSum productSum = new SchoolProductSum(); //产品状态
+            List<SchoolProductSumProdInfo> prodinfo = new List<SchoolProductSumProdInfo>(); //学校的产品信息
+            List<SchoolProductSumData> serialRecord = new List<SchoolProductSumData>(); //软体购买记录
+            List<SchoolProductSumData> serviceRecord = new List<SchoolProductSumData>(); //服务购买记录
+            List<SchoolProductSumDataHard> hardRecord = new List<SchoolProductSumDataHard>(); //硬体购买记录
+
+
+            //取产品的数量
+            var response = await clientContainer.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolCode.ToString(), new PartitionKey($"ProductSum"));
+            if (response.Status == 200)
+            {
+                using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                productSum = json.ToObject<SchoolProductSum>();
+                prodinfo = productSum.prodinfo;
+                serialRecord = productSum.serial;
+                serviceRecord = productSum.service;
+                hardRecord = productSum.hard;
+            }
+
+            //软体
+            await foreach (var item in clientContainer.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: "SELECT * FROM c WHERE c.dataType='serial'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{schoolCode}") }))
+            {
+                using var json = await JsonDocument.ParseAsync(item.ContentStream);                
+                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                {
+                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                    {
+                        serials.Add(obj.ToObject<SchoolProductSerial>());
+                    }
+                }
+            }
+
+            //服务
+            await foreach (var item in clientContainer.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: "SELECT * FROM c WHERE c.dataType='service'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{schoolCode}") }))
+            {
+                using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                {
+                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                    {
+                        services.Add(obj.ToObject<SchoolProductService>());
+                    }
+                }
+            }
+
+            //硬体
+            await foreach (var item in clientContainer.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: "SELECT * FROM c WHERE c.dataType='hard'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{schoolCode}") }))
+            {
+                using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                {
+                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                    {
+                        hards.Add(obj.ToObject<SchoolProductHard>());
+                    }
+                }
+            }
+
+            return Ok(new { state = 200, serials, services, hards, productSum });
+        }
+    }
+}

+ 50 - 18
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -10,6 +10,7 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelBI.Filter;
 using TEAMModelBI.Tool;
+using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
@@ -217,43 +218,74 @@ namespace TEAMModelBI.Controllers.BISchool
         [ProducesDefaultResponseType]
         [AuthToken(Roles = "assist")]
         [HttpPost("upd-school")]
-        public async Task<IActionResult> UpdSchool(ReplaceSchool replaceSchool)
+        public async Task<IActionResult> UpdSchool(School school)
         {
             try
             {
                 School schoolInfo = new School();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
-
-                School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(replaceSchool.school.id, new PartitionKey("Base"));
-                if (tempShool != null)
+                string _auth = HttpContext.GetXAuth("AuthToken");
+                //var (tmdId, tmdName) = HttpJwtAnalysis.JwtXAuth(_auth, _option);
+                var (tmdId, tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(_auth, _option);
+                var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school.id, new PartitionKey($"Base"));
+                if (response.Status == 200)
                 {
+                    string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{school.id}'";
                     List<Teacher> teachers = new List<Teacher>();
-                    string sqltxt = $"select distinct value(c) from c join a1 in c.schools where a1.schoolId='{replaceSchool.school.id}'";
-                    await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
                     {
                         teachers.Add(item);
                     }
-
                     foreach (var item in teachers)
                     {
-                        Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(replaceSchool.school.id));
+                        Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(school.id));
                         if (teacherSchool != null)
                         {
-                            teacherSchool.name = replaceSchool.school.name;
-                            teacherSchool.picture = replaceSchool.school.picture;
-                            teacherSchool.areaId = replaceSchool.school.areaId;
+                            teacherSchool.name = school.name;
+                            teacherSchool.picture = school.picture;
+                            teacherSchool.areaId = school.areaId;
                         }
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey("Base"));
+                        await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
                     }
-
-                    schoolInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(replaceSchool.school, replaceSchool.school.id, new PartitionKey("Base"));
-
+                    schoolInfo = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<School>(school,school.id, new PartitionKey($"Base"));
+                    
                     //保存操作记录
-                    await _azureStorage.SaveLog("school-update", $"{replaceSchool.tmdName}【{replaceSchool.tmdId}】修改学校信息,学校和ID:{replaceSchool.school.name}【{replaceSchool.school.id}】", _dingDing, httpContext: HttpContext);
-
-                    return Ok(new { state = 200, schoolInfo });
+                    await _azureStorage.SaveLog("school-update", $"{tmdName}【{tmdId}】修改学校信息,学校和ID:{school.name}【{school.id}】", _dingDing, httpContext: HttpContext);
                 }
                 else return Ok(new { state = 400, message = "请求错误!" });
+
+                return Ok(new { state = 200, schoolInfo });
+
+                //School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(replaceSchool.school.id, new PartitionKey("Base"));
+                //if (tempShool != null)
+                //{
+                //    List<Teacher> teachers = new List<Teacher>();
+                //    string sqltxt = $"select distinct value(c) from c join a1 in c.schools where a1.schoolId='{replaceSchool.school.id}'";
+                //    await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+                //    {
+                //        teachers.Add(item);
+                //    }
+
+                //    foreach (var item in teachers)
+                //    {
+                //        Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(replaceSchool.school.id));
+                //        if (teacherSchool != null)
+                //        {
+                //            teacherSchool.name = replaceSchool.school.name;
+                //            teacherSchool.picture = replaceSchool.school.picture;
+                //            teacherSchool.areaId = replaceSchool.school.areaId;
+                //        }
+                //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey("Base"));
+                //    }
+
+                //    schoolInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(replaceSchool.school, replaceSchool.school.id, new PartitionKey("Base"));
+
+                //    //保存操作记录
+                //    await _azureStorage.SaveLog("school-update", $"{replaceSchool.tmdName}【{replaceSchool.tmdId}】修改学校信息,学校和ID:{replaceSchool.school.name}【{replaceSchool.school.id}】", _dingDing, httpContext: HttpContext);
+
+                //    return Ok(new { state = 200, schoolInfo });
+                //}
+                //else return Ok(new { state = 400, message = "请求错误!" });
             }
             catch (Exception ex)
             {

+ 32 - 6
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -39,6 +39,7 @@ using System.Security.Cryptography;
 using System.Runtime.InteropServices;
 using System.Runtime.CompilerServices;
 using System.IdentityModel.Tokens.Jwt;
+using TEAMModelBI.Tool.Extension;
 
 namespace TEAMModelBI.Controllers.BITest
 {
@@ -774,27 +775,52 @@ namespace TEAMModelBI.Controllers.BITest
             return Ok(new { state = 200, day });
             
         }
-
+        [ProducesDefaultResponseType]
         [HttpPost("get-xauth")]
-        public async Task<IActionResult> GetXAuth() 
+        public async Task<IActionResult> GetXAuth(JsonElement jsonElement) 
         {
             string authHeader = this.Request.Headers["Authorization"];//Header中的token
             string _auth = HttpContext.GetXAuth("AuthToken");
+
+            //var (id, name, pic, did, dname, dpic) = HttpJwtAnalysis.GetAuthTokenInfo(HttpContext);
+
+
+            var (tmdId, tmdName) = HttpJwtAnalysis.JwtXAuth(_auth, _option);
+            //var (tmdId, tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(_auth, _option);
+
+            // var (id, name) = httpXAuth(_auth, _option);
+
+            //string id = null;
+            //string name = null;
+
+            //if (!string.IsNullOrWhiteSpace(_auth) && JwtAuthExtension.ValidateApiToken(_auth, _option.JwtSecretKey))
+            //{
+            //    var jwt = new JwtSecurityTokenHandler().ReadJwtToken(_auth);
+            //    id = jwt.Payload.Sub;
+            //    name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
+            //}
+
+            return Ok(new { state = 200, tmdId, tmdName });
+
+        }
+
+
+        public (string id, string name) httpXAuth(string auth,Option option)
+        {
             string id = null;
             string name = null;
 
-            if (!string.IsNullOrWhiteSpace(_auth) && JwtAuthExtension.ValidateApiToken(_auth, _option.JwtSecretKey))
+            if (!string.IsNullOrWhiteSpace(auth) && JwtAuthExtension.ValidateApiToken(auth, option.JwtSecretKey))
             {
-                var jwt = new JwtSecurityTokenHandler().ReadJwtToken(_auth);
+                var jwt = new JwtSecurityTokenHandler().ReadJwtToken(auth);
                 id = jwt.Payload.Sub;
                 name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
             }
-            return Ok(new { state = 200, id, name });
 
+            return (id, name);
         }
 
 
-
         public class strend
         {
             public int id { get; set; }

+ 0 - 4
TEAMModelBI/Controllers/Census/LessonSticsController.cs

@@ -136,7 +136,6 @@ namespace TEAMModelBI.Controllers.Census
                 foreach (var itemId in schoolIds)
                 {
                     School school = new();
-
                     var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
                     if (response.Status == 200)
                     {
@@ -184,7 +183,6 @@ namespace TEAMModelBI.Controllers.Census
                 foreach (string schoolId in schoolIds)
                 {
                     School school = new();
-
                     var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
                     if (response.Status == 200)
                     {
@@ -195,7 +193,6 @@ namespace TEAMModelBI.Controllers.Census
                     SchoolLen schoolLen = new SchoolLen() { id = schoolId, name = school != null ? school.name : schoolId };
 
                     List<List<double>> begin = new();
-
                     await foreach (var lcount in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessonCount>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{schoolId}-{years}") }))
                     {
                         begin.Add(lcount.beginCount);
@@ -209,7 +206,6 @@ namespace TEAMModelBI.Controllers.Census
             else
             {
                 List<List<double>> begin = new();
-
                 await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessonCount>(queryText: "select value(c) from c where c.pk='LessonCount'", requestOptions: new QueryRequestOptions() { }))
                 {
                     begin.Add(item.beginCount);

+ 13 - 15
TEAMModelBI/Controllers/Census/PaperController.cs

@@ -195,8 +195,6 @@ namespace TEAMModelBI.Controllers.BISchool
                     foreach (var temp in endList1)
                     {                        
                         string sqlTxt = $"SELECT  COUNT(c.id) AS totals FROM c WHERE c.createTime >= {temp.start} and c.createTime <= {temp.end} and c.pk='Paper'";
-
-
                         long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt, new List<string>() { "School", "Teacher" });
 
                         yearCount.Add(temp.yearMonth, totals);
@@ -206,7 +204,6 @@ namespace TEAMModelBI.Controllers.BISchool
                 }
                 return Ok(new { state = 200, schoolYears });
             }
-
         }
 
         /// <summary>
@@ -243,20 +240,21 @@ namespace TEAMModelBI.Controllers.BISchool
 
                     string sqlTxt = $"select count(c.id) AS totals from c where c.createTime >={start} and c.createTime <={end}";
 
-                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText:sqlTxt.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{schoolId}")}))
-                    {
-                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
-                        {
-                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                            {
-                                schoolPaper.totals += obj.GetProperty("totals").GetInt64();
-                            }
-                        }
-                    }
+                    schoolPaper.totals += await CommonFind.FindTotals(cosmosClient, sqlTxt, "School", $"Paper-{schoolId}");
 
-                    //schoolPaper.totals = await CommonFind.FindTotals(cosmosClient, sqlTxt, new List<string>() { "School" });
+                    //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText:sqlTxt.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{schoolId}")}))
+                    //{
+                    //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    //    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
+                    //    {
+                    //        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                    //        {
+                    //            schoolPaper.totals += obj.GetProperty("totals").GetInt64();
+                    //        }
+                    //    }
+                    //}
 
+                    //schoolPaper.totals = await CommonFind.FindTotals(cosmosClient, sqlTxt, new List<string>() { "School" });
                     schoolPapers.Add(schoolPaper);
                 }
 

+ 72 - 19
TEAMModelBI/Controllers/Census/ProductStatisController.cs

@@ -25,8 +25,15 @@ namespace TEAMModelBI.Controllers.Census
         private readonly DingDing _dingDing;
         private readonly Option _option;
 
-        //服务产品
-        private readonly Dictionary<string, string> prodict = new Dictionary<string, string>() { { "YMPCVCIM", "学情分析模组" }, { "IPDYZYLC", "智慧学校管理服务" }, { "3CLYJ6NP", "AClass ONE智慧学伴" }, { "IPALJ6NY", "数据储存服务空间" }, { "VABAJ6NV", "卷卡合一阅卷系统" } };
+        /// <summary>
+        /// 软体产品
+        /// </summary>
+        private readonly Dictionary<string, string> _serials = new Dictionary<string, string>() { { "3222NIYD", "ezStation 2" }, { "J223IZ6M", "HiTeach STD" }, { "3222C6D2", "HiTeach TBL" }, { "J223IZAM", "HiTeach PRO" }, { "J2236ZCX", "HiTeach Lite" }, { "3222DNG2", "HiTeach Mobile" }, { "3222IAVN", "HiTeach Premium" }, { "BYJ6LZ6Z", "HiTeach5" } };
+
+        /// <summary>
+        /// 服务产品
+        /// </summary>
+        private readonly Dictionary<string, string> _services = new Dictionary<string, string>() { { "YMPCVCIM", "学情分析模组" }, { "IPDYZYLC", "智慧学校管理服务" }, { "3CLYJ6NP", "AClass ONE智慧学伴" }, { "IPALJ6NY", "数据储存服务空间" }, { "VABAJ6NV", "卷卡合一阅卷系统" } };
 
         public ProductStatisController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option) 
         {
@@ -45,18 +52,40 @@ namespace TEAMModelBI.Controllers.Census
         {
             var cosmosClient = _azureCosmos.GetCosmosClient();
             List<ProductStatis> productStatis = new List<ProductStatis>();
-            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT c.prodinfo,c.service FROM c",requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ProductSum") }))
+            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT c.serial,c.service FROM c",requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ProductSum") }))
             {
                 using var json = await JsonDocument.ParseAsync(item.ContentStream);
                 if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                 {
                     foreach (var itemCount in json.RootElement.GetProperty("Documents").EnumerateArray())
                     {
+                        ////所有的产品
+                        //List<SchoolProductSumProdInfo> prodInfo = itemCount.GetProperty("prodinfo").ToObject<List<SchoolProductSumProdInfo>>();
+                        //foreach (var tempProdInfo in prodInfo)
+                        //{
+                        //    ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(tempProdInfo.prodCode));
+                        //    if (!string.IsNullOrEmpty($"{tempPerod}"))
+                        //    {
+                        //        tempPerod.Count += 1;
+                        //    }
+                        //    else
+                        //    {
+                        //        ProductStatis tempProd = new ProductStatis()
+                        //        {
+                        //            prodCode = tempProdInfo.prodCode,
+                        //            prodName = tempProdInfo.prodName,
+                        //            //dataType = tempProdInfo.dataType,
+                        //            Count = 1,
+                        //        };
+                        //        productStatis.Add(tempProd);
+                        //    }
+                        //}
+
                         //软体产品
-                        List<SchoolProductSumProdInfo> prodInfo = itemCount.GetProperty("prodinfo").ToObject<List<SchoolProductSumProdInfo>>();
-                        foreach (var tempProdInfo in prodInfo)
+                        List<SchoolProductSumData> tempSerials = itemCount.GetProperty("serial").ToObject<List<SchoolProductSumData>>();
+                        foreach (var serial in tempSerials)
                         {
-                            ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(tempProdInfo.prodCode));
+                            ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(serial.prodCode));
                             if (!string.IsNullOrEmpty($"{tempPerod}"))
                             {
                                 tempPerod.Count += 1;
@@ -65,15 +94,16 @@ namespace TEAMModelBI.Controllers.Census
                             {
                                 ProductStatis tempProd = new ProductStatis()
                                 {
-                                    prodCode = tempProdInfo.prodCode,
-                                    prodName = tempProdInfo.prodName,
-                                    //dataType = tempProdInfo.dataType,
+                                    prodCode = serial.prodCode,
+                                    prodName = _serials[serial.prodCode],
+                                    //dataType = "",
                                     Count = 1,
                                 };
                                 productStatis.Add(tempProd);
                             }
                         }
 
+
                         //服务产品
                         List<SchoolProductSumData> service = itemCount.GetProperty("service").ToObject<List<SchoolProductSumData>>();
                         foreach (var ser in service)
@@ -88,7 +118,7 @@ namespace TEAMModelBI.Controllers.Census
                                 ProductStatis tempProd = new ProductStatis()
                                 {
                                     prodCode = ser.prodCode,
-                                    prodName = prodict[ser.prodCode],
+                                    prodName = _services[ser.prodCode],
                                     //dataType = "",
                                     Count = 1,
                                 };
@@ -158,16 +188,38 @@ namespace TEAMModelBI.Controllers.Census
 
                 List<ProductStatis> productStatis = new();
 
-                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT c.prodinfo,c.service FROM c where c.id='{scid}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ProductSum") }))
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT c.serial,c.service FROM c where c.id='{scid}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ProductSum") }))
                 {
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
                     foreach (var itemCount in json.RootElement.GetProperty("Documents").EnumerateArray())
                     {
-                        //软件
-                        List<SchoolProductSumProdInfo> prodInfo = itemCount.GetProperty("prodinfo").ToObject<List<SchoolProductSumProdInfo>>();
-                        foreach (var tempProdInfo in prodInfo)
+                        ////所有的产品信息
+                        //List<SchoolProductSumProdInfo> prodInfo = itemCount.GetProperty("prodinfo").ToObject<List<SchoolProductSumProdInfo>>();
+                        //foreach (var tempProdInfo in prodInfo)
+                        //{
+                        //    ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(tempProdInfo.prodCode));
+                        //    if (!string.IsNullOrEmpty($"{tempPerod}"))
+                        //    {
+                        //        tempPerod.Count += 1;
+                        //    }
+                        //    else
+                        //    {
+                        //        ProductStatis tempProd = new ProductStatis()
+                        //        {
+                        //            prodCode = tempProdInfo.prodCode,
+                        //            prodName = tempProdInfo.prodName,
+                        //            //dataType = tempProdInfo.dataType,
+                        //            Count = 1,
+                        //        };
+                        //        productStatis.Add(tempProd);
+                        //    }
+                        //}
+
+                        //软体产品
+                        List<SchoolProductSumData> tempSerials = itemCount.GetProperty("serial").ToObject<List<SchoolProductSumData>>();
+                        foreach (var serial in tempSerials)
                         {
-                            ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(tempProdInfo.prodCode));
+                            ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(serial.prodCode));
                             if (!string.IsNullOrEmpty($"{tempPerod}"))
                             {
                                 tempPerod.Count += 1;
@@ -176,14 +228,15 @@ namespace TEAMModelBI.Controllers.Census
                             {
                                 ProductStatis tempProd = new ProductStatis()
                                 {
-                                    prodCode = tempProdInfo.prodCode,
-                                    prodName = tempProdInfo.prodName,
-                                    //dataType = tempProdInfo.dataType,
+                                    prodCode = serial.prodCode,
+                                    prodName = _serials[serial.prodCode],
+                                    //dataType = "",
                                     Count = 1,
                                 };
                                 productStatis.Add(tempProd);
                             }
                         }
+
                         //服务产品
                         List<SchoolProductSumData> service = itemCount.GetProperty("service").ToObject<List<SchoolProductSumData>>();
                         foreach (var ser in service)
@@ -198,7 +251,7 @@ namespace TEAMModelBI.Controllers.Census
                                 ProductStatis tempProd = new ProductStatis()
                                 {
                                     prodCode = ser.prodCode,
-                                    prodName = prodict[ser.prodCode],
+                                    prodName = _services[ser.prodCode],
                                     //dataType = "",
                                     Count = 1,
                                 };

+ 1 - 28
TEAMModelBI/Controllers/DingDingStruc/DDStructController.cs

@@ -76,7 +76,6 @@ namespace TEAMModelBI.Controllers.DingDingStruc
             OapiOrgUnionBranchGetRequest req = new OapiOrgUnionBranchGetRequest();
             OapiOrgUnionBranchGetResponse rsp = client.Execute(req, tokenResponse.AccessToken);
 
-
             return Ok(new { Result = rsp.Result, Body = rsp.Body, RequestId = rsp.RequestId, SubErrCode = rsp.SubErrCode, Success = rsp.Success });
         }
 
@@ -577,33 +576,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 await _dingDing.SendBotMsg($"BI,{_option.Location},dd/get-dduserinfo \n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
                 return BadRequest();
             }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public record DeptStruc
-        {
-            /// <summary>
-            /// 部门ID
-            /// </summary>
-            public long deptId { get; set; }
-
-            /// <summary>
-            /// 父级部门
-            /// </summary>
-            public long parentId { get; set; }
-
-            /// <summary>
-            /// 部门名称
-            /// </summary>
-            public string name { get; set; }
-
-            public List<DeptStruc> depts { get; set; }
-
-            public List<DDUserInfoAndTMD> tmddd { get; set; }
-        }
-
+        }      
 
         /// <summary>
         /// 返回钉钉和能查询到醍摩豆信息

+ 0 - 3
TEAMModelBI/Controllers/DingDingStruc/TableDingDingInfoController.cs

@@ -39,7 +39,6 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         private readonly DingDing _dingDing;
         private readonly Option _option;
         private readonly IHttpClientFactory _http;
-        public readonly string mobel = "组织员工";
 
         public TableDingDingInfoController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, IHttpClientFactory http)
         {
@@ -67,7 +66,6 @@ namespace TEAMModelBI.Controllers.DingDingStruc
 
                 string appKey = _configuration["DingDingAuth:appKey"];
                 string appSecret = _configuration["DingDingAuth:appSecret"];
-
                 string divide = _configuration["CustomParam:SiteScope"];
 
                 HttpClient httpClient = _http.CreateClient();
@@ -818,7 +816,6 @@ namespace TEAMModelBI.Controllers.DingDingStruc
             return ddUserInfos;
         }
 
-
         public record ddUserInfo
         {
             public string partitionKey { get; set; }

+ 9 - 3
TEAMModelBI/Controllers/LoginController.cs

@@ -483,9 +483,12 @@ namespace TEAMModelBI.Controllers
                         {
                             roles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(",")) : new List<string>();
                             permissions = !string.IsNullOrEmpty($"{item.permissions}") ? new List<string>(item.permissions.Split(",")) : new List<string>();
-                            id_token = JwtAuthExtension.CreateAuthToken(_option.HostName, item.tmdId?.ToString(), item.tmdName?.ToString(), item.picture?.ToString(), _option.JwtSecretKey, Website: "BI", scope: $"assist", roles: roles?.ToArray(), permissions: permissions?.ToArray(), ddsub: item.RowKey?.ToString());
 
-                            //id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, item.tmdId?.ToString(), item.tmdName?.ToString(), item.picture?.ToString(), item.RowKey?.ToString(), item.name?.ToString(), item.avatar?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire:3);
+                            ///在IES5 添加
+                            //id_token = JwtAuthExtension.CreateAuthToken(_option.HostName, item.tmdId?.ToString(), item.tmdName?.ToString(), item.picture?.ToString(), _option.JwtSecretKey, Website: "BI", scope: $"assist", roles: roles?.ToArray(), permissions: permissions?.ToArray(), ddsub: item.RowKey?.ToString());
+
+                            //自己写的
+                            id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, item.tmdId?.ToString(), item.tmdName?.ToString(), item.picture?.ToString(), item.RowKey?.ToString(), item.name?.ToString(), item.avatar?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire:3);
 
                             (osblob_uri, osblob_sas) = roles.Contains("assist") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
                         }
@@ -664,7 +667,10 @@ namespace TEAMModelBI.Controllers
                         }
                         else return Ok(new { state = responseMessage.StatusCode });
                     }
-                    id_token = JwtAuthExtension.CreateAuthToken(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), _option.JwtSecretKey,Website: "BI", scope: $"assist", roles: roles?.ToArray(), permissions: permissions?.ToArray(), ddsub: itemUser.RowKey?.ToString());
+                    ////在IES5 的基础上增加参数
+                    //id_token = JwtAuthExtension.CreateAuthToken(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), _option.JwtSecretKey,Website: "BI", scope: $"assist", roles: roles?.ToArray(), permissions: permissions?.ToArray(), ddsub: itemUser.RowKey?.ToString());
+                    //自己写的
+                    id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), itemUser.RowKey?.ToString(), itemUser.name?.ToString(), itemUser.avatar?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
                 }
 
                 var (osblob_uri, osblob_sas) = roles.Contains("assist") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);

+ 0 - 4
TEAMModelBI/Controllers/OperateRecord/OperateLogController.cs

@@ -68,8 +68,6 @@ namespace TEAMModelBI.Controllers.OperateRecord
             }
         }
 
-
-
         /// <summary>
         /// 删除操作记录
         /// </summary>
@@ -151,7 +149,5 @@ namespace TEAMModelBI.Controllers.OperateRecord
         }
 
 
-
-
     }
 }

+ 68 - 0
TEAMModelBI/Controllers/QueryTool/SchoolController.cs

@@ -0,0 +1,68 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using System.Text;
+using TEAMModelOS.SDK.Models;
+using Azure.Cosmos;
+using System.Collections.Generic;
+using TEAMModelOS.SDK.Extension;
+
+namespace TEAMModelBI.Controllers.DataTool
+{
+    [Route("school")]
+    [ApiController]
+    public class SchoolController : ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        public SchoolController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option) 
+        {
+            _azureCosmos = azureCosmos;
+            _azureStorage = azureStorage;
+            _dingDing = dingDing;
+            _option = option?.Value;        
+        }
+
+        /// <summary>
+        /// 查询学校
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("get-school")]
+        public async Task<IActionResult> GetSchool(JsonElement jsonElement) 
+        {
+            jsonElement.TryGetProperty("schoolId", out JsonElement schoolId);
+            var clientCosmosDB = _azureCosmos.GetCosmosClient();
+            StringBuilder sqlTxt = new StringBuilder("select * from c");
+            if (!string.IsNullOrEmpty($"{schoolId}")) 
+            {
+                sqlTxt.Append($" where c.id='{schoolId}'");
+            }
+
+            List<School> schools = new();
+
+            await foreach (var item in clientCosmosDB.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            {
+                using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                {
+                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                    {
+                        schools.Add(obj.ToObject<School>());
+                    }
+                }
+            }
+
+            return Ok(new { state = 200, schools });
+        }
+
+
+
+
+    }
+}

+ 62 - 0
TEAMModelBI/Filter/ApiTokenAttribute.cs

@@ -0,0 +1,62 @@
+using Microsoft.AspNetCore.Mvc.Filters;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
+using System;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelBI.Filter
+{
+    public class ApiTokenAttribute : Attribute, IFilterFactory 
+    {
+
+        public bool IsReusable => throw new NotImplementedException();
+
+        /// <summary>
+        /// 是否开启限流策略
+        /// </summary>
+        public bool Limit { get; set; }
+
+        /// <summary>
+        /// 授权序列
+        /// </summary>
+        public string Auth { get; set; }
+
+        public IFilterMetadata CreateInstance(IServiceProvider services)
+        {
+            var option = services.GetService<IOptions<Option>>();
+            var azureRedis = services.GetService<AzureRedisFactory>();
+            return new InternalAuthTokenFilter(option, azureRedis, Auth, Limit);
+        }
+
+        private class InternalAuthTokenFilter : IResourceFilter 
+        {
+            private readonly Option _option;
+            //private readonly string _roles;
+            private readonly string _auth;
+            private readonly bool _limit;
+            private readonly AzureRedisFactory _azureRedis;
+
+
+            public InternalAuthTokenFilter(IOptions<Option> option, AzureRedisFactory azureRedis, string auth, bool limit)
+            {
+                _option = option.Value;
+                _auth = auth;
+                _limit = limit;
+                _azureRedis = azureRedis;
+            }
+
+            public void OnResourceExecuting(ResourceExecutingContext context)
+            {
+
+            }
+
+            public void OnResourceExecuted(ResourceExecutedContext context)
+            {
+
+            }
+
+        }
+
+    }
+}

+ 0 - 1
TEAMModelBI/TEAMModelBI.csproj

@@ -27,7 +27,6 @@
 	</ItemGroup>
 
 	<ItemGroup>
-		<Folder Include="Controllers\DataTool\" />
 		<Folder Include="wwwroot\" />
 	</ItemGroup>
 	<PropertyGroup>

+ 56 - 0
TEAMModelBI/Tool/Extension/HttpJwtAnalysis.cs

@@ -0,0 +1,56 @@
+using System;
+using Microsoft.AspNetCore.Http;
+using System.IdentityModel.Tokens.Jwt;
+using System.Linq;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.Extension;
+
+namespace TEAMModelBI.Tool.Extension
+{
+    public static class HttpJwtAnalysis
+    {
+        /// <summary>
+        ///  通过jwt封装的字串解析,id和名称
+        /// </summary>
+        /// <param name="auth"></param>
+        /// <param name="option"></param>
+        /// <returns></returns>
+        public static (string id, string name) JwtXAuth(string auth, Option option)
+        {
+            string id = null, name = null;
+            if (!string.IsNullOrWhiteSpace(auth) && JwtAuthExtension.ValidateApiToken(auth, option.JwtSecretKey))
+            {
+                var jwt = new JwtSecurityTokenHandler().ReadJwtToken(auth);
+                id = jwt.Payload.Sub;
+                name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
+            }
+
+            return (id, name);
+        }
+
+        /// <summary>
+        /// 通过jwt封装的字串解析
+        /// </summary>
+        /// <param name="httpContext"></param>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        public static (string id, string name, string pic, string did, string dname, string dpic) JwtXAuthBI(string auth, Option option)
+        {
+            object id = null, name = null, pic = null, did = null, dname = null, dpic = null;
+            if (!string.IsNullOrWhiteSpace(auth) && JwtAuthExtension.ValidateApiToken(auth, option.JwtSecretKey))
+            {
+                var jwt = new JwtSecurityTokenHandler().ReadJwtToken(auth);
+                id = jwt.Payload.Sub;
+                name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
+                pic = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("picture"))?.Value;
+                did = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("ddsub"))?.Value;
+                dname = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("ddname"))?.Value;
+                dpic = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("ddpicture"))?.Value;
+            }
+
+            return (id?.ToString(), name?.ToString(), pic?.ToString(), did?.ToString(), dname?.ToString(), dpic?.ToString());
+
+        }
+
+    }
+}

+ 63 - 0
TEAMModelBI/Tool/Extension/JwtAuth.cs

@@ -0,0 +1,63 @@
+using Microsoft.IdentityModel.Tokens;
+using System;
+using System.IdentityModel.Tokens.Jwt;
+using System.Text;
+
+namespace TEAMModelBI.Models.Extension
+{
+    public static class JwtAuth
+    {
+        /// <summary>
+        /// BI AuthToken
+        /// </summary>
+        /// <param name="issuser">站点</param>
+        /// <param name="id">醍摩豆ID</param>
+        /// <param name="name">醍摩豆名称</param>
+        /// <param name="picture">醍摩豆头像</param>
+        /// <param name="did">钉钉</param>
+        /// <param name="dname"></param>
+        /// <param name="dpicture"></param>
+        /// <param name="salt"></param>
+        /// <param name="scope"></param>
+        /// <param name="Website"></param>
+        /// <param name="unitid"></param>
+        /// <param name="roles"></param>
+        /// <param name="permissions"></param>
+        /// <param name="schools"></param>
+        /// <param name="expire"></param>
+        /// <returns></returns>
+        public static string CreateAuthTokenBI(string issuser, string id, string name, string picture, string did, string dname, string dpicture, string salt, string scope, string Website, string unitid = "", string[] roles = null, string[] permissions = null, string[] schools = null, int expire = 1)
+        {
+            var payload = new JwtPayload
+            {
+                { JwtRegisteredClaimNames.Iss,issuser}, //发行者
+                { JwtRegisteredClaimNames.Sub,id},   //用户ID
+                { JwtRegisteredClaimNames.Azp,unitid}, //企业简码
+                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},//到期时间
+                { "name",name},//用户显示名称
+                { "picture",picture}, // 用户头像
+                { "roles",roles}, //登陆者的角色, (admin、assist) 
+                { "permissions",permissions}, //登陆者的权限
+                { "ddsub",did } ,  //登陆者的钉钉用户id
+                { "ddname",dname } ,  //登陆者的钉钉用户名称
+                { "ddpicture",dpicture },  //登陆者的钉钉用户头像
+                { "schools",schools}, //登陆者的授权学校
+                { JwtRegisteredClaimNames.Website,Website}, // 平台站点
+            };
+
+            // 建立加密的秘钥
+            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(salt));
+            // HmacSha256 有要求必须要大于 128 bits,所以 salt 不能太短,至少要 16 字元以上
+            // https://stackoverflow.com/questions/47279947/idx10603-the-algorithm-hs256-requires-the-securitykey-keysize-to-be-greater
+            var signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);
+            var header = new JwtHeader(signingCredentials);
+            var secToken = new JwtSecurityToken(header, payload);
+            // 產出所需要的 JWT securityToken 物件,並取得序列化後的 Token 結果(字串格式)
+            var tokenHandler = new JwtSecurityTokenHandler();
+            //var securityToken = tokenHandler.CreateToken(tokenDescriptor);
+            var serializeToken = tokenHandler.WriteToken(secToken);
+            return serializeToken;
+        }
+
+    }
+}