Explorar el Código

Merge branch 'PL/develop-BI' into develop

Li hace 2 años
padre
commit
e03689ba45

+ 28 - 4
TEAMModelBI/Controllers/BITable/TableDingDingInfoController.cs

@@ -28,6 +28,7 @@ using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.Context.BI;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Context.Constant;
 
 namespace TEAMModelBI.Controllers.BITable
 {
@@ -349,6 +350,7 @@ namespace TEAMModelBI.Controllers.BITable
                 jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
                 if (!jsonElement.TryGetProperty("permissions", out JsonElement _permissions)) return BadRequest();
                 if (!jsonElement.TryGetProperty("roles", out JsonElement _roles)) return BadRequest();
+                if (!jsonElement.TryGetProperty("isDisable", out JsonElement _isDisable)) return BadRequest();
                 //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
 
                 var tableClient = _azureStorage.GetCloudTableClient();
@@ -360,6 +362,17 @@ namespace TEAMModelBI.Controllers.BITable
                 //    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
                 //}
 
+                long isDisable = 0;
+                try
+                {
+                    isDisable = long.Parse($"{_isDisable}");
+                    if (isDisable != 1 || isDisable != 0)
+                        return Ok(new { state = RespondCode.ParamsError, msg = "禁用参数错误" });                    
+                }
+                catch
+                {
+                    return Ok(new { state = RespondCode.ParamsError, msg = "禁用参数错误" });
+                }
                 var table = tableClient.GetTableReference("BIDDUserInfo");
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
 
@@ -392,7 +405,7 @@ namespace TEAMModelBI.Controllers.BITable
                    
                     item.roles = listroles.Count > 0 ? string.Join(",", listroles) : "assist";
                     item.permissions = string.Join(",", listper);
-
+                    item.isDisable = isDisable;
                     ddUserInfo.Add(item);
 
                     roles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(",")) : new List<string>();
@@ -509,7 +522,6 @@ namespace TEAMModelBI.Controllers.BITable
             }
         }
 
-
         /// <summary>
         /// 通过醍摩豆账户信息 设置BI后台管理员   //已对接
         /// </summary>
@@ -1283,6 +1295,7 @@ namespace TEAMModelBI.Controllers.BITable
 
             //获取部门人员信息
             IDingTalkClient userListClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
+            long joinDate =  DateTimeOffset.UtcNow.AddDays(-91).ToUnixTimeMilliseconds();
 
             //获取部门用户
             OapiV2UserListRequest reqUserList = new()
@@ -1300,6 +1313,15 @@ namespace TEAMModelBI.Controllers.BITable
             {
                 foreach (var itemUser in rspV2UserList.Result.List)
                 {
+                    long isDisble = 0;
+                    if (!string.IsNullOrEmpty($"{itemUser.HiredDate}"))
+                    {
+                        if (itemUser.HiredDate < joinDate)
+                            isDisble = 1;
+                        else
+                            isDisble = 0;
+                    }
+
                     var tempInfo = ddUserInfos.Find(x => x.RowKey.Equals(itemUser.Unionid));
                     if (string.IsNullOrEmpty($"{tempInfo}"))
                     {
@@ -1335,7 +1357,8 @@ namespace TEAMModelBI.Controllers.BITable
                                     roles = user.roles,
                                     joinTime = user.joinTime,
                                     permissions = user.permissions,
-                                    schoolIds = user.schoolIds
+                                    schoolIds = user.schoolIds,
+                                    isDisable = isDisble,
                                 };
 
                                 ddUserInfos.Add(ddUserInfo);
@@ -1369,7 +1392,8 @@ namespace TEAMModelBI.Controllers.BITable
                                 roles = "",
                                 joinTime = 0,
                                 permissions = "areadata-read,areadata-upd,schooldata-read,schooldata-upd",
-                                schoolIds = ""
+                                schoolIds = "",
+                                isDisable = isDisble,
                             };
 
                             ddUserInfos.Add(ddUserInfo);

+ 19 - 11
TEAMModelBI/Controllers/Census/ActivitySticsController.cs

@@ -111,7 +111,7 @@ namespace TEAMModelBI.Controllers.Census
         [HttpPost("get-areastics")]
         public async Task<IActionResult> GetAreaStics(JsonElement jsonElement)
         {
-            if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            jsonElement.TryGetProperty("areaId", out JsonElement areaId);
             //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
             var (dayS, dayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow);
             var (weekS, weekE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
@@ -161,14 +161,25 @@ namespace TEAMModelBI.Controllers.Census
             List<AreaStudy> trains = new();
 
             AreaSetting setting = null;
-            try
-            {
-                setting = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AreaSetting>($"{areaId}", new PartitionKey("AreaSetting"));
-            }
-            catch (CosmosException)
+           
+
+            string oftenSql = "select value(count(c.id)) from c";
+            string scSql = "";
+            if (!string.IsNullOrEmpty($"{areaId}"))
             {
-                setting = null;
+                scSql = $"select value(c.id) from c where c.areaId='{areaId}'";
+                try
+                {
+                    setting = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AreaSetting>($"{areaId}", new PartitionKey("AreaSetting"));
+                }
+                catch (CosmosException)
+                {
+                    setting = null;
+                }
             }
+            else            
+                scSql = "select value(c.id) from c where c.areaId = null or c.areaId = ''";
+            
             if (setting == null)
             {
                 setting = new AreaSetting
@@ -181,10 +192,7 @@ namespace TEAMModelBI.Controllers.Census
                     lessonMinutes = 45,
                 };
             }
-
-            string oftenSql = "select value(count(c.id)) from c";
-            string scSql = $"{oftenSql} where c.areaId='{areaId}'";
-            List<string> scIds = await CommonFind.GetValueSingle(cosmosClient, "School", $"select value(c.id) from c where c.areaId='{areaId}'", "Base");
+            List<string> scIds = await CommonFind.GetValueSingle(cosmosClient, "School", scSql, "Base");
             if (scIds.Count > 0)
             {
                 string weekWhereSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";

+ 149 - 2
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -2,6 +2,7 @@
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
+using Pipelines.Sockets.Unofficial.Arenas;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -17,6 +18,9 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Service.BI;
+using static TEAMModelBI.Controllers.BINormal.AreaRelevantController;
+using static TEAMModelBI.Controllers.Census.LessonSticsController;
 
 namespace TEAMModelBI.Controllers.Census
 {
@@ -358,17 +362,159 @@ namespace TEAMModelBI.Controllers.Census
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-noarea")]
         public async Task<IActionResult> GetNoAreaCnt(JsonElement jsonElement)
         {
             var cosmosClient = _azureCosmos.GetCosmosClient();
-            List<string> scIds = new();
 
-            string scIdSql = "";
+            int tLessCnt = 0;  //课例
+            int tActCnt = 0;   //活动
+            List<string> scIds = new(); //学校id集合
+
+            string scIdSql = "select value(c.id) from c where c.areaId=null or c.areaId=''";
             await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scIdSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
             {
                 scIds.Add(item);
             }
 
+            string comSql = BICommonWay.ManyScSql("c.school", scIds);
+            string lesSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and {comSql}";
+            tLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School", "Teacher" }, lesSql);
+
+            comSql = BICommonWay.ManyScSql(" and c.school", scIds);
+            tActCnt = await ActivityWay.GetCnt(cosmosClient, condSql: comSql);
+
+            return Ok(new { state = 200, scCnt=scIds.Count(), tLessCnt, tActCnt });
+        }
+        
+        /// <summary>
+        /// 未加区的学校统计详细
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("get-noareasc")]
+        public async Task<IActionResult> GetNoAareaScCnt(JsonElement jsonElement)
+        {
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var table = tableClient.GetTableReference("BIDDUserInfo");
+
+            var (dayS, dayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow);
+            var (weekS, weekE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
+            var (monthS, monthE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "month");
+            var (termS, termE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
+
+            List<AreaAssist> areaAssists = new();  //顾问信息
+
+            int scCnt = 0; //学校人数
+            int weekScCnt = 0; //本周学校人数
+            int motnhScCnt = 0; //本月学校人数
+
+            int tchCnt = 0;   //所有区级老师
+            int weekTchCnt = 0;   //所有区级老师
+            int monthTchCnt = 0;   //所有区级老师
+
+            int stuCnt = 0;   //所有区级学生
+            int weekStuCnt = 0;   //所有区级学生
+            int monthStuCnt = 0;   //所有区级学生
+
+            int areaSize = 0;   //区级空间
+            int weekSize = 0;   //本周空间
+            int monthSize = 0;   //本月空间
+
+            int allLess = 0; //所有课例
+            int weekLess = 0;  //周课例
+            int monthLess = 0;  //月课例
+            int termLess = 0;    //学期课例
+
+            int totalTime = 0;   //累计学时
+            int allActCnt = 0;   //所有活动
+            int weekActivity = 0; //周活动数量
+            int monthActCnt = 0; //月活动数量
+            int termActivity = 0;   //学期活动
+
+            int onLineCount = 0;    //线上研修人数
+            int offlineCount = 0;   //线下研修人数
+            int classRoomCount = 0;  //课堂实录人数
+            int submitCount = 0;     //认证材料人数
+
+            int fulfilCount = 0;    //已完成
+            int carryOnCount = 0;   //进行中
+            int noCount = 0;      //未开始
+
+            HashSet<string> tchIds = new();
+            List<string> scIds = new(); //学校id集合
+
+            string scIdSql = "select value(c.id) from c where c.areaId=null or c.areaId=''";
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scIdSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+            {
+                scIds.Add(item);
+            }
+
+            string scsSql = BICommonWay.ManyScSql("c.school", scIds);
+            string cntSql = $"select value(count(c.id)) from c where {scsSql}";
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<int>(queryText: cntSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            {
+                tchCnt += item;
+            }
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<int>(queryText: cntSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            {
+                stuCnt += item;
+            }
+
+            foreach (var scId in scIds)
+            {
+                string tchIdSql = $"select value(c.id) from c where array_contains(c.roles,'assist',true) and c.pk='Teacher'";
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: tchIdSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{scId}") }))
+                {
+                    tchIds.Add(item);
+                }
+            }
+
+            List<string> noIds = new();
+            foreach (var item in tchIds)
+            {
+                List<DingDingUserInfo> ddUsers = await table.QueryWhereString<DingDingUserInfo>($"PartitionKey eq '{_option.Location}' and tmdId eq '{item}'");
+                if (ddUsers.Count > 0)
+                {
+                    foreach (var dduser in ddUsers)
+                    {
+                        AreaAssist areaAssist = new()
+                        {
+                            userId = dduser.userId,
+                            unionId = dduser.unionId,
+                            name = dduser.name,
+                            mobile = dduser.mobile,
+                            avatar = dduser.avatar,
+                            tmdId = dduser.tmdId,
+                            tmdName = dduser.tmdName,
+                            tmdMobile = dduser.tmdMobile,
+                            picture = dduser.picture,
+                            roles = dduser.roles,
+                            schoolIds = dduser.schoolIds
+                        };
+                        areaAssists.Add(areaAssist);
+                    }
+                }
+                else { noIds.Add(item); }
+            }
+
+            AreaSetting setting = new()
+            {
+                allTime = 50,
+                classTime = 5,
+                submitTime = 15,
+                onlineTime = 20,
+                offlineTime = 10,
+                lessonMinutes = 45,
+            };
+            string oftenSql = "select value(count(c.id)) from c";
+
+
+
 
 
 
@@ -377,6 +523,7 @@ namespace TEAMModelBI.Controllers.Census
             return Ok(new { state = 200 });
         }
 
+
         /// <summary>
         /// 依据Id查询School容器  数据管理工具——查询工具
         /// </summary>

+ 20 - 2
TEAMModelBI/Controllers/LoginController.cs

@@ -167,6 +167,9 @@ namespace TEAMModelBI.Controllers
 
                     foreach (var item in ddusers)
                     {
+                        if (item.isDisable == 0)
+                            return Ok(new { state = RespondCode.Forbidden, msg = "账户被禁用!请联系管理员!" });
+
                         if (string.IsNullOrEmpty(item.tmdId))
                         {
                             var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{item.mobile}" } }, _option.Location, _configuration);
@@ -229,6 +232,17 @@ namespace TEAMModelBI.Controllers
                 }
                 else
                 {
+                    long joinDate = DateTimeOffset.UtcNow.AddDays(-91).ToUnixTimeMilliseconds();
+
+                    long isDisable = 0;
+                    if (!string.IsNullOrEmpty($"{v2GetResponse.Result.HiredDate}")) 
+                    {
+                        if (v2GetResponse.Result.HiredDate < joinDate)
+                            isDisable = 1;
+                        else
+                            isDisable = 0;
+                    }
+
                     DingDingUserInfo ddUserInfo = new()
                     {
                         PartitionKey = divide,
@@ -246,7 +260,8 @@ namespace TEAMModelBI.Controllers
                         avatar = v2GetResponse.Result.Avatar,
                         isAdmin = v2GetResponse.Result.Admin,
                         roles = "assist",
-                        permissions = "abilitystandard-read,batcharea-read,batchschool-read,orgusers-read"
+                        permissions = "abilitystandard-read,batcharea-read,batchschool-read,orgusers-read",
+                        isDisable = 0
                     };
 
                     if (!string.IsNullOrEmpty($"{ddUserInfo.mobile}"))
@@ -261,7 +276,6 @@ namespace TEAMModelBI.Controllers
                             ddUserInfo.mail = coreUser.mail;
                         }
                         else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
-
                     }
                     else return Ok(new { state = 404, msg = "钉钉手机号为空" });
 
@@ -276,6 +290,10 @@ namespace TEAMModelBI.Controllers
                     //保存操作记录
                     await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{ddUserInfo.tmdName}【{ddUserInfo.tmdId}】醍摩豆账号和{ddUserInfo.name}【{ddUserInfo.RowKey}】钉钉账户绑定成功", _dingDing, httpContext: HttpContext, tid: ddUserInfo.tmdId, tname: ddUserInfo.tmdName, twebsite: Website);
 
+                    if (isDisable == 0)
+                        return Ok(new { state = RespondCode.Forbidden, msg = "账户被禁用!请联系管理员!" });
+
+
                     roles = !string.IsNullOrEmpty($"{ddUserInfo.roles}") ? new List<string>(ddUserInfo.roles.Split(",")) : new List<string>();
                     roles = roles.Where(w => !string.IsNullOrEmpty(w)).ToList();
                     permissions = !string.IsNullOrEmpty($"{ddUserInfo.permissions}") ? new List<string>(ddUserInfo.permissions.Split(",")) : new List<string>();

+ 1 - 1
TEAMModelOS.SDK/Context/Constant/RespondCode.cs

@@ -47,7 +47,7 @@ namespace TEAMModelOS.SDK.Context.Constant
         public readonly static int PaymentRequired = 402;
 
         /// <summary>
-        /// 服务器拒绝  403
+        /// 服务器拒绝/禁用  403
         /// </summary>
         public readonly static int Forbidden = 403;