소스 검색

优化个人课堂记录统计,修改关联学校报错的原因

Li 3 년 전
부모
커밋
2e62de756f

+ 25 - 9
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -8,6 +8,7 @@ using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net.Http;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
@@ -16,6 +17,7 @@ using TEAMModelBI.Tool;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.Models;
+using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
@@ -35,8 +37,9 @@ namespace TEAMModelBI.Controllers.BISchool
         private readonly AzureRedisFactory _azureRedis;
         private readonly IConfiguration _configuration;
         private readonly NotificationService _notificationService;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
 
-        public SchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, AzureRedisFactory azureRedis, IConfiguration configuration, NotificationService notificationService)
+        public SchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, AzureRedisFactory azureRedis, IConfiguration configuration, NotificationService notificationService, CoreAPIHttpService coreAPIHttpService)
         {
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
@@ -45,6 +48,7 @@ namespace TEAMModelBI.Controllers.BISchool
             _azureRedis = azureRedis;
             _configuration = configuration;
             _notificationService = notificationService;
+            _coreAPIHttpService = coreAPIHttpService;
         }
 
         /// <summary>
@@ -499,15 +503,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 {
                     dic.Add("userId", $"{userId}");
                 }
-                if (!string.IsNullOrEmpty($"{tmdId}"))
-                {
-                    dic.Add("tmdId", $"{tmdId}");
-                }
 
-                if (string.IsNullOrEmpty($"{userId}") && string.IsNullOrEmpty($"{tmdId}"))
-                {
-                    return BadRequest();
-                }
                 Dictionary<string, List<string>> noSchools = new();
                 List<DingDingUserInfo> ddUserInfoList = await table.FindListByDict<DingDingUserInfo>(dic);
                 List<DingDingUserInfo> updUsers = new();
@@ -518,6 +514,26 @@ namespace TEAMModelBI.Controllers.BISchool
                     {
                         if (schoolIds.Count > 0)
                         {
+                            if (string.IsNullOrEmpty(ddInfo.tmdId)) 
+                            {
+                                List<string> moblie = new() { $"{ddInfo.mobile}" };
+
+                                var content = new StringContent(moblie.ToJsonString(), Encoding.UTF8, "application/json");
+                                string json = await _coreAPIHttpService.GetUserInfos(content);
+                                if (!string.IsNullOrEmpty(json))
+                                {
+                                    List<JsonElement> json_id = json.ToObject<List<JsonElement>>();
+                                    foreach (var tmd in json_id)
+                                    {
+                                        ddInfo.tmdId = tmd.GetProperty("id").ToString();
+                                        ddInfo.tmdName = tmd.GetProperty("name").ToString();
+                                        ddInfo.tmdMobile = tmd.GetProperty("mobile").ToString();
+                                        ddInfo.picture = tmd.GetProperty("picture").ToString();
+                                        ddInfo.mail = tmd.GetProperty("mail").ToString();
+                                    }
+                                }
+                                else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
+                            }
                             List<string> noSchool = await SchoolWay.SchoolAdviser(cosmosClient, ddInfo, schoolIds, $"{busy}");
                             if (noSchool.Count > 0)
                             {

+ 13 - 7
TEAMModelBI/Controllers/Census/ActivitySticsController.cs

@@ -382,8 +382,8 @@ namespace TEAMModelBI.Controllers.Census
                     standard += 1;
                 else basics += 1;
 
-                string sqlTxt = $"select value(c) from c where c.code='LessonRecord-{school}'";
-                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school}") }))
+                string sqlTxtSchool = $"select value(c) from c where c.code='LessonRecord-{school}'";
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>(queryText: sqlTxtSchool, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school}") }))
                 {
                     records.Add(item);
                 }
@@ -443,17 +443,18 @@ namespace TEAMModelBI.Controllers.Census
             }
 
             List<string> tecIds = await CommonFind.FindRolesId(cosmosClient, scIds);
-            
+
             //查询去下面所有学校教师课例
             foreach (var tecId in tecIds)
             {
-                string sqlTxt = $"select value(c) from c";
-                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{tecId}") }))
+                string sqlTxt = $"select value(c) from c where c.id='{tecId}'";
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord") }))
                 {
                     records.Add(item);
                 }
             }
 
+
             //课例统计
             if (records.Count > 0)
             {
@@ -497,6 +498,7 @@ namespace TEAMModelBI.Controllers.Census
             long allLess = 0;     //所有课例
             int tecCount = 0;    //教师数量
             int scCount = 0;    //学校数量
+            int stuCount = 0;   //学生数量
 
             int basics = 0; //基础版数
             int standard = 0; //标准版数
@@ -504,6 +506,10 @@ namespace TEAMModelBI.Controllers.Census
             long resourceCount = 0; //累计资源
             long totalTime = 0; //总学时
 
+            scCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals form c ", "School", "Base");
+            tecCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals form c ", "Teacher", "Base");
+            stuCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals form c ", "Student", "Base");
+
             foreach (var area in areaInfos) 
             {
                 List<RecSchool> recSchools = new();
@@ -511,7 +517,7 @@ namespace TEAMModelBI.Controllers.Census
                 {
                     recSchools.Add(school);
                 }
-                scCount += recSchools.Count;
+                //scCount += recSchools.Count;
                 recSchools.ForEach(x => { if (x.type == 2) heCount += 1; else if (x.type == 1) geCount += 1; else oeCount += 1; });
                 allSize += recSchools.Select(s => s.size).Sum();
                 area.schoolCount = recSchools.Count;
@@ -522,7 +528,7 @@ namespace TEAMModelBI.Controllers.Census
                 major += tempm;
                 int tempCount = await CommonFind.GetPeopleNumber(cosmosClient, "School", recSchools?.Select(x => x.id).ToList(), "Teacher");
 
-                tecCount += tempCount;
+                //tecCount += tempCount;
                 //查教师
                 area.techCount = tempCount;
                 //查询学生

+ 7 - 5
TEAMModelBI/Controllers/Census/LessonSticsController.cs

@@ -67,7 +67,9 @@ namespace TEAMModelBI.Controllers.Census
                         school = json.ToObject<School>();
                     }
 
-                    SchoolLen schoolLen = new() { id = itemId, name = school.name != null ? school.name : itemId };
+                    SchoolLen schoolLen = new() { id = itemId, name =
+                        
+                        school.name != null ? school.name : itemId };
 
                     //string sqlTxt = $"SELECT COUNT(c.id) AS totals FROM c WHERE c.code='LessonRecord-{itemId}'";
                     sqlTxt.Append($" WHERE c.code='LessonRecord-{itemId}'");
@@ -90,7 +92,7 @@ namespace TEAMModelBI.Controllers.Census
                     sqlTxt.Append($" and c.startTime >= {start} and c.startTime <= {end}");
                 }
 
-                totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School" });
+                totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School","Teacher" });
             }
 
             return Ok(new { state = 200, totals });
@@ -107,7 +109,7 @@ namespace TEAMModelBI.Controllers.Census
             {
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 string lessonSql = $"select COUNT(c.id) AS totals from c where c.pk='LessonRecord'";
-                long total = await CommonFind.FindTotals(cosmosClient, lessonSql, new List<string>() { "School" });
+                long total = await CommonFind.FindTotals(cosmosClient, lessonSql, new List<string>() { "School","Teacher" });
 
                 return Ok(new { state = 200, total });
             }
@@ -354,8 +356,8 @@ namespace TEAMModelBI.Controllers.Census
             tecIds = await CommonFind.FindRolesId(cosmosClient, schools);
             foreach (var tecId in tecIds)
             {
-                string sqlTxt = $"select value(c) from c";
-                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{tecId}") }))
+                string sqlTxt = $"select value(c) from c where c.id='{tecId}'";
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord") }))
                 {
                     records.Add(item);
                 }

+ 2 - 1
TEAMModelBI/Tool/CosmosBank/LessonStatisWay.cs

@@ -39,7 +39,8 @@ namespace TEAMModelBI.Tool.CosmosBank
             {
                 foreach (string sc in scIds)
                 {
-                    await foreach (var itemTeac in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{sc}") }))
+                    string sqlTecTxt = $"select count(c.id) from c where c.id='{sc}'";
+                    await foreach (var itemTeac in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord") }))
                     {
                         using var json = await JsonDocument.ParseAsync(itemTeac.ContentStream);
                         if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)