Browse Source

优化第三方企业信息,和关联第三方企业学校信息

Li 3 years ago
parent
commit
b98046e931

+ 231 - 57
TEAMModelBI/Controllers/BINormal/CompanyController.cs

@@ -19,6 +19,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Service;
 using TEAMModelOS.SDK.Models.Service;
+using TEAMModelOS.SDK.Models.Table;
 
 
 namespace TEAMModelBI.Controllers.BINormal
 namespace TEAMModelBI.Controllers.BINormal
 {
 {
@@ -47,46 +48,51 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElenent"></param>
         /// <param name="jsonElenent"></param>
         /// <returns></returns>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,rdc,assist,sales,company")]
+        //[AuthToken(Roles = "admin,rdc,assist,sales,company")]
         [HttpPost("get-info")]
         [HttpPost("get-info")]
         public async Task<IActionResult> GetInfo(JsonElement jsonElenent)
         public async Task<IActionResult> GetInfo(JsonElement jsonElenent)
         {
         {
-            jsonElenent.TryGetProperty("eid", out JsonElement eid);
-            jsonElenent.TryGetProperty("site", out JsonElement site);
-            var cosmosClient = _azureCosmos.GetCosmosClient();
-            if ($"{site}".Equals(BIConst.GlobalSite))
-                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
-            List<ReadCompany> companys = new();
-            StringBuilder sqlTxt = new("select c.id,c.pk,c.code,c.name,c.credit,c.picture,c.emall,c.mobile,c.password from c");
-            if (!string.IsNullOrEmpty($"{eid}"))
+            try
             {
             {
-                sqlTxt.Append($" where c.id='{eid}'");
-            }
+                jsonElenent.TryGetProperty("id", out JsonElement id);
+                jsonElenent.TryGetProperty("site", out JsonElement site);
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                }
 
 
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Company") }))
-            {
-                using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                var table = tableClient.GetTableReference("IESOpenApi");
+                Dictionary<string, object> keyValue = new Dictionary<string, object>() { { "PartitionKey", "Company" } };
+                if (!string.IsNullOrEmpty($"{id}")) 
                 {
                 {
-                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                    {
-                        ReadCompany readCompany = new()
-                        {
-                            id= obj.GetProperty("id").GetString(),
-                            pk = obj.GetProperty("pk").GetString(),
-                            code = obj.GetProperty("code").GetString(),
-                            name = obj.GetProperty("name").GetString(),
-                            credit = obj.GetProperty("credit").GetString(),
-                            picture = obj.GetProperty("picture").GetString(),
-                            emall = obj.GetProperty("emall").GetString(),
-                            mobile = obj.GetProperty("mobile").GetString(),
-                        };
-                        companys.Add(readCompany);
-                    }
+                    keyValue.Add("RowKey", $"{id}");
                 }
                 }
-            }
 
 
-            return Ok(new { state = 200, companys });
+                List<CompanyTable> companys = table.FindListByDictSync<CompanyTable>(keyValue);
+
+                //cosmosDB数据库
+                //List<ReadCompany> companys = new();
+                //StringBuilder sqlTxt = new("select c.id,c.pk,c.code,c.name,c.credit,c.picture,c.jti,c.secretKey,c.emall,c.mobile,c.password,c.webhookDomain,c.salt,c.createTime from c");
+                //if (!string.IsNullOrEmpty($"{id}"))
+                //{
+                //    sqlTxt.Append($" where c.id='{id}'");
+                //}
+                //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIterator<ReadCompany>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Company") }))
+                //{
+                //    companys.Add(item);
+                //}
+
+                return Ok(new { state = 200, companys });
+
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"BI,{_option.Location} , /business/get-info   \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
+                return BadRequest();
+            }
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -94,14 +100,15 @@ namespace TEAMModelBI.Controllers.BINormal
         /// </summary>
         /// </summary>
         /// <param name="appCompany"></param>
         /// <param name="appCompany"></param>
         /// <returns></returns>
         /// <returns></returns>
-        //[ProducesDefaultResponseType]
-        //[AuthToken(Roles = "admin,rdc,assist,sales,company")]
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "admin,rdc,assist,sales,company")]
         [HttpPost("set-info")]
         [HttpPost("set-info")]
-        public async Task<IActionResult> SetCompany([FromBody]Company company, [FromHeader] string site) 
+        public async Task<IActionResult> SetCompany([FromBody] CompanyTable company, [FromHeader] string site)
         {
         {
             try
             try
             {
             {
                 //var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 //var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+                var (tmdId, tmdName, pic, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 StringBuilder strMsg = new();
                 StringBuilder strMsg = new();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var tableClient = _azureStorage.GetCloudTableClient();
                 var tableClient = _azureStorage.GetCloudTableClient();
@@ -112,63 +119,230 @@ namespace TEAMModelBI.Controllers.BINormal
                     tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
                     tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
                     blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                     blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 }
                 }
+                List<CompanyTable> companys = new();
+
+                var table = tableClient.GetTableReference("IESOpenApi");
+
                 string salt = Utils.CreatSaltString(8);
                 string salt = Utils.CreatSaltString(8);
                 string type = "";
                 string type = "";
-                //新增企业信息
-                if (string.IsNullOrEmpty(company.id))
+
+                if (string.IsNullOrEmpty(company.RowKey))
                 {
                 {
-                    company.id = Guid.NewGuid().ToString();
-                    company.code = "Company";
+                    company.RowKey = Guid.NewGuid().ToString();
+                    company.PartitionKey = "Company";
                     company.salt = salt;
                     company.salt = salt;
                     company.password = string.IsNullOrWhiteSpace(company.password) ? Utils.HashedPassword("123456", salt) : Utils.HashedPassword(company.password, salt);//Password,若梦没有则是默认密码:123456
                     company.password = string.IsNullOrWhiteSpace(company.password) ? Utils.HashedPassword("123456", salt) : Utils.HashedPassword(company.password, salt);//Password,若梦没有则是默认密码:123456
                     company.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                     company.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                     company.jti = Guid.NewGuid().ToString();
                     company.jti = Guid.NewGuid().ToString();
-                    company.secretKey = JwtAuth.CreateBusinessJwtKeyBI(_option.Location, _option.JwtSecretKey, company.id, company.jti);
-                    await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<Company>(company, new PartitionKey(company.code));
-                    strMsg.Append($"{company.name}【{company.id}】新增企业基础信息。");
-                    type = "company-add";
+                    company.secretKey = JwtAuth.CreateBusinessJwtKeyBI(_option.Location, _option.JwtSecretKey, company.RowKey, company.jti);
+
+                    company = await table.SaveOrUpdate<CompanyTable>(company);
+                    companys.Add(company);
+                    strMsg.Append($"{company.name}【{company.RowKey}】新增企业基础信息。");
+                    type = "business-add";
                 }
                 }
-                //修改企业信息
-                else
+                else 
                 {
                 {
-                    var respone = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync(company.id, new PartitionKey($""));
-                    if (respone.Status == 200)
+                    List<CompanyTable> companyTables = table.FindListByDictSync<CompanyTable>(new Dictionary<string, object> { { "PartitionKey", "Company" }, { "RowKey", $"{company.RowKey}" } });
+                    if (companyTables.Count > 0)
                     {
                     {
-                        company.pk = "Company";
-                        company.code = "Company";
-                        company.ttl = -1;
+                        foreach (var item in companyTables)
+                        {
+                            item.name = company.name;
+                            item.credit = company.credit;
+                            item.picture = company.picture;
+                            //item.jti = company.jti;
+                            //item.secretKey = company.secretKey;
+                            item.emall = company.emall;
+                            item.mobile = company.mobile;
+                            //item.salt = company.salt;
+                            //item.password = company.password;
+                            item.webhookDomain = company.webhookDomain; 
+                            strMsg.Append($"{item.name}【{item.RowKey}】修改企业基础信息:{item}。");
+                            companys.Add(item);
+                        }
+
+                        companyTables = await table.SaveOrUpdateAll<CompanyTable>(companyTables);
+                        type = "business-add";
+                    }
+                    else
+                    {
+                        company.RowKey = Guid.NewGuid().ToString();
+                        company.PartitionKey = "Company";
                         company.salt = salt;
                         company.salt = salt;
                         company.password = string.IsNullOrWhiteSpace(company.password) ? Utils.HashedPassword("123456", salt) : Utils.HashedPassword(company.password, salt);//Password,若梦没有则是默认密码:123456
                         company.password = string.IsNullOrWhiteSpace(company.password) ? Utils.HashedPassword("123456", salt) : Utils.HashedPassword(company.password, salt);//Password,若梦没有则是默认密码:123456
+                        company.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        company.jti = Guid.NewGuid().ToString();
+                        company.secretKey = JwtAuth.CreateBusinessJwtKeyBI(_option.Location, _option.JwtSecretKey, company.RowKey, company.jti);
 
 
-                        company = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<Company>(company, company.id, new PartitionKey(company.code));
-                        strMsg.Append($"{company.name}【{company.id}】修改企业基础信息。");
-                        type = "company-update";
+                        company = await table.SaveOrUpdate<CompanyTable>(company);
+                        companys.Add(company);
+                        strMsg.Append($"{company.name}【{company.RowKey}】新增企业基础信息:{company}。");
+                        type = "business-add";
                     }
                     }
-                    else return Ok(new { state = 404, msg = "未找到该id相关的企业信息" });
                 }
                 }
 
 
+                ////存储在CosmosDB表
+                ////新增企业信息
+                //if (string.IsNullOrEmpty(company.id))
+                //{
+                //    company.id = Guid.NewGuid().ToString();
+                //    company.code = "Company";
+                //    company.salt = salt;
+                //    company.password = string.IsNullOrWhiteSpace(company.password) ? Utils.HashedPassword("123456", salt) : Utils.HashedPassword(company.password, salt);//Password,若梦没有则是默认密码:123456
+                //    company.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                //    company.jti = Guid.NewGuid().ToString();
+                //    company.secretKey = JwtAuth.CreateBusinessJwtKeyBI(_option.Location, _option.JwtSecretKey, company.id, company.jti);
+                //    await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<Company>(company, new PartitionKey(company.code));
+                //    strMsg.Append($"{company.name}【{company.id}】新增企业基础信息。");
+                //    type = "business-add";
+                //}
+                ////修改企业信息
+                //else
+                //{
+                //    var respone = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync(company.id, new PartitionKey($""));
+                //    if (respone.Status == 200)
+                //    {
+                //        company.pk = "Company";
+                //        company.code = "Company";
+                //        company.ttl = -1;
+                //        company.salt = salt;
+                //        company.password = string.IsNullOrWhiteSpace(company.password) ? Utils.HashedPassword("123456", salt) : Utils.HashedPassword(company.password, salt);//Password,若梦没有则是默认密码:123456
+
+                //        company = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<Company>(company, company.id, new PartitionKey(company.code));
+                //        strMsg.Append($"{company.name}【{company.id}】修改企业基础信息。");
+                //        type = "business-update";
+                //    }
+                //    else return Ok(new { state = 404, msg = "未找到该id相关的企业信息" });
+                //}
+
                 //保存操作记录
                 //保存操作记录
                 //await _azureStorage.SaveBILog(type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
                 //await _azureStorage.SaveBILog(type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
                 await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
                 await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
-                return Ok(new { state = 200, company });
+                return Ok(new { state = 200, companys });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"BI,{_option.Location} , /business/set-info   \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
+                return BadRequest();
+            }
+        }
+
+        /// <summary>
+        /// 关联企业学校
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "admin,rdc,assist,sales,company")]
+        [HttpPost("set-companyschool")]
+        public async Task<IActionResult> SetCompanySc(JsonElement jsonElement)
+        {
+            try
+            {
+                if (!jsonElement.TryGetProperty("schools", out JsonElement _schools)) return BadRequest();
+                if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                var (tmdId, tmdName, pic, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+                jsonElement.TryGetProperty("site", out JsonElement site);
+                List<RecSc> recScs = _schools.ToObject<List<RecSc>>();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
+
+                var table = tableClient.GetTableReference("IESOpenApi");
+
+                StringBuilder strMsg = new($"{tmdName}[{tmdId}]关联企业ID:{id},学校列表:");
+                List<BusinessSchool> busSchools = new();
+                foreach (var item in recScs)
+                {
+                    BusinessSchool businessSchool = new() { PartitionKey = $"BusinessSchool-{id}", RowKey = $"{item.id}", name = $"{item.name}", picture = $"{item.picture}" };
+                    busSchools.Add(businessSchool);
+                    strMsg.Append($"{item.name}[{item.id}],");
+                }
+
+                busSchools = await table.SaveOrUpdateAll<BusinessSchool>(busSchools);
+
+                //保存操作记录
+                //await _azureStorage.SaveBILog(type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "business-busschool", strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                return Ok(new { state = 200, busSchools });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"BI,{_option.Location} , /business/set-companyschool   \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
+                return BadRequest();
+            }
+        }
+
+        /// <summary>
+        /// 依据企业ID查询关联的学校
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-companyschool")]
+        public async Task<IActionResult> GetCompanySc(JsonElement jsonElement) 
+        {
+            try
+            {
+                if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
+
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
+
+                var table = tableClient.GetTableReference("IESOpenApi");
+                List<BusinessSchool> busSchools = await table.FindListByDict<BusinessSchool>(new Dictionary<string, object> { { "PartitionKey", $"BusinessSchool-{id}" } });
+
+                return Ok(new { state = 200, busSchools });
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                //await _dingDing.SendBotMsg($"BI,{_option.Location} , /company/set-info   \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"BI,{_option.Location} , /business/get-companyschool   \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
                 return BadRequest();
                 return BadRequest();
             }
             }
         }
         }
 
 
+
+
+        /// <summary>
+        /// 关联时传入的学校信息
+        /// </summary>
+        public record RecSc 
+        {
+            public string id { get; set; }
+            public string name { get; set; }
+            public string picture { get; set; }
+        }
+
+
+        /// <summary>
+        /// 显示第三方信息
+        /// </summary>
         public record ReadCompany
         public record ReadCompany
         {
         {
             public string id { get; set; }
             public string id { get; set; }
-            public string pk { get; set; }
             public string code { get; set; }
             public string code { get; set; }
             public string name { get; set; }
             public string name { get; set; }
             public string credit { get; set; }
             public string credit { get; set; }
             public string picture { get; set; }
             public string picture { get; set; }
+            public string jti { get; set; }
+            public string secretKey { get; set; }
             public string emall { get; set; }
             public string emall { get; set; }
             public string mobile { get; set; }
             public string mobile { get; set; }
+            public string salt { get; set; }
+            public string password { get; set; }
+            public string webhookDomain { get; set; }
+            public long createTime { get; set; }
         }
         }
 
 
 
 

+ 9 - 3
TEAMModelBI/Controllers/BISchool/LessonController.cs

@@ -27,6 +27,11 @@ namespace TEAMModelBI.Controllers.BISchool
             _azureRedis = azureRedis;
             _azureRedis = azureRedis;
         }
         }
 
 
+        /// <summary>
+        /// 历史记录读取
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
         [HttpPost("get-alllesson")]
         [HttpPost("get-alllesson")]
         public async Task<IActionResult> GetAllLessonRecords(JsonElement jsonElement) 
         public async Task<IActionResult> GetAllLessonRecords(JsonElement jsonElement) 
         {
         {
@@ -51,22 +56,23 @@ namespace TEAMModelBI.Controllers.BISchool
             }
             }
 
 
             //scLesson.ForEach(item =>  { TimeHelper.GetDateTime(item.startTime).Hour })
             //scLesson.ForEach(item =>  { TimeHelper.GetDateTime(item.startTime).Hour })
-
-            List<LessCnt> lessCnts = scLesson.Select(item => new LessCnt { hour = TimeHelper.GetDateTime(item.startTime).ToString("yyyyMMddHH"), cat = item.id, upload= item.upload }).ToList();
+            List<LessCnt> lessCnts = scLesson.Select(item => new LessCnt { hour = TimeHelper.GetDateTime(item.startTime).ToString("yyyyMMddHH"), cat = item.id, upload = item.upload, schoolId = item.school }).ToList();
 
 
             List<LessCnt> openCnt = lessCnts.FindAll(s => s.upload == 0).ToList();
             List<LessCnt> openCnt = lessCnts.FindAll(s => s.upload == 0).ToList();
             List<LessCnt> lessCnt = lessCnts.FindAll(s => s.upload == 1).ToList();
             List<LessCnt> lessCnt = lessCnts.FindAll(s => s.upload == 1).ToList();
 
 
             var openL = openCnt.GroupBy(g => g.hour).Select(s => new { key = s.Key, cnt = s.Count() }).ToList();
             var openL = openCnt.GroupBy(g => g.hour).Select(s => new { key = s.Key, cnt = s.Count() }).ToList();
+            var lessL = lessCnt.GroupBy(g => g.hour).Select(s => new { key = s.Key, cnt = s.Count() }).ToList();
             //openL.ForEach(f=> { })
             //openL.ForEach(f=> { })
 
 
 
 
-            return Ok(new { state = 200, openCnt, lessCnt, lessCnts });
+            return Ok(new { state = 200, openL, lessL, openCnt,  lessCnt, lessCnts });
         }
         }
 
 
         public record LessCnt 
         public record LessCnt 
         {
         {
             public string hour { get; set; }
             public string hour { get; set; }
+            public string schoolId { get; set; }
             public string cat { get; set; }
             public string cat { get; set; }
             public int upload { get; set; }
             public int upload { get; set; }
         }
         }

+ 112 - 32
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -893,6 +893,8 @@ namespace TEAMModelBI.Controllers.BISchool
             try
             try
             {
             {
                 if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
                 if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
+                List<string> schools = schoolId.ToObject<List<string>>();
+
                 jsonElement.TryGetProperty("site", out JsonElement site);
                 jsonElement.TryGetProperty("site", out JsonElement site);
                 string _auth = HttpContext.GetXAuth("AuthToken");
                 string _auth = HttpContext.GetXAuth("AuthToken");
                 var (tmdId, tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(_auth, _option);
                 var (tmdId, tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(_auth, _option);
@@ -908,44 +910,84 @@ namespace TEAMModelBI.Controllers.BISchool
                 StringBuilder msg = new();
                 StringBuilder msg = new();
                 List<DelSchoolRel> delSchoolRels = new();
                 List<DelSchoolRel> delSchoolRels = new();
 
 
-                List<string> scTchIds = new();
-                List<string> scStuIds = new();
-                string scTecSql = $"select value(c.id) from c where ARRAY_LENGTH(c.roles) > 0 and c.status = 'join'";
-                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scTecSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{schoolId}") }))
+                foreach (var tempId in schools)
                 {
                 {
-                    scTchIds.Add(item);
-                }
-
-                string scStuSql = $"select value(c.id) from c";
-                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scStuSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
-                {
-                    scStuIds.Add(item);
-                }
+                    List<string> scTchIds = new();
+                    List<string> scStuIds = new();
+                    string scTecSql = $"select value(c.id) from c where ARRAY_LENGTH(c.roles) > 0 and c.status = 'join'";
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scTecSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempId}") }))
+                    {
+                        scTchIds.Add(item);
+                    }
 
 
-                var response = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{schoolId}", new PartitionKey($"Base"));
-                if (response.Status == 204)
-                    msg.AppendLine($"{tmdName}【{tmdId}】删除学校,删除状态:{response.Status},删除ID:{schoolId}");
-                else
-                    delSchoolRels.Add(new DelSchoolRel() { id = $"{schoolId}", code = "Base", type = 1, status = response.Status });
+                    string scStuSql = $"select value(c.id) from c";
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<string>(queryText: scStuSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{tempId}") }))
+                    {
+                        scStuIds.Add(item);
+                    }
 
 
-                foreach (var item in scTchIds)
-                {
-                    var tchRespnse = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{item}", new PartitionKey($"Teacher-{schoolId}"));
-                    if (tchRespnse.Status == 204)
-                        msg.AppendLine($"删除教师,删除状态:{tchRespnse.Status},删除ID:{item}");
+                    var response = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{tempId}", new PartitionKey($"Base"));
+                    if (response.Status == 204)
+                        msg.AppendLine($"{tmdName}【{tmdId}】删除学校,删除状态:{response.Status},删除ID:{tempId}");
                     else
                     else
-                        delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Teacher-{schoolId}", type = 2, status = response.Status });
-                }
+                        delSchoolRels.Add(new DelSchoolRel() { id = $"{tempId}", code = "Base", type = 1, status = response.Status });
 
 
-                foreach (var item in scStuIds)
-                {
-                    var stuRespnse = await cosmosClient.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync($"{item}", new PartitionKey($"Base-{schoolId}"));
-                    if (stuRespnse.Status == 204)
-                        msg.AppendLine($"删除学生,删除状态:{stuRespnse.Status},删除ID:{item}");
-                    else
-                        delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Base-{schoolId}", type = 3, status = response.Status });
+                    foreach (var item in scTchIds)
+                    {
+                        var tchRespnse = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{item}", new PartitionKey($"Teacher-{tempId}"));
+                        if (tchRespnse.Status == 204)
+                            msg.AppendLine($"删除教师,删除状态:{tchRespnse.Status},删除ID:{item}");
+                        else
+                            delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Teacher-{tempId}", type = 2, status = response.Status });
+                    }
+
+                    foreach (var item in scStuIds)
+                    {
+                        var stuRespnse = await cosmosClient.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync($"{item}", new PartitionKey($"Base-{tempId}"));
+                        if (stuRespnse.Status == 204)
+                            msg.AppendLine($"删除学生,删除状态:{stuRespnse.Status},删除ID:{item}");
+                        else
+                            delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Base-{tempId}", type = 3, status = response.Status });
+                    }
                 }
                 }
 
 
+
+                //string scTecSql = $"select value(c.id) from c where ARRAY_LENGTH(c.roles) > 0 and c.status = 'join'";
+                //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scTecSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{schoolId}") }))
+                //{
+                //    scTchIds.Add(item);
+                //}
+
+                //string scStuSql = $"select value(c.id) from c";
+                //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scStuSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
+                //{
+                //    scStuIds.Add(item);
+                //}
+
+                //var response = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{schoolId}", new PartitionKey($"Base"));
+                //if (response.Status == 204)
+                //    msg.AppendLine($"{tmdName}【{tmdId}】删除学校,删除状态:{response.Status},删除ID:{schoolId}");
+                //else
+                //    delSchoolRels.Add(new DelSchoolRel() { id = $"{schoolId}", code = "Base", type = 1, status = response.Status });
+
+                //foreach (var item in scTchIds)
+                //{
+                //    var tchRespnse = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{item}", new PartitionKey($"Teacher-{schoolId}"));
+                //    if (tchRespnse.Status == 204)
+                //        msg.AppendLine($"删除教师,删除状态:{tchRespnse.Status},删除ID:{item}");
+                //    else
+                //        delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Teacher-{schoolId}", type = 2, status = response.Status });
+                //}
+
+                //foreach (var item in scStuIds)
+                //{
+                //    var stuRespnse = await cosmosClient.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync($"{item}", new PartitionKey($"Base-{schoolId}"));
+                //    if (stuRespnse.Status == 204)
+                //        msg.AppendLine($"删除学生,删除状态:{stuRespnse.Status},删除ID:{item}");
+                //    else
+                //        delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Base-{schoolId}", type = 3, status = response.Status });
+                //}
+
                 //保存操作记录
                 //保存操作记录
                 //await _azureStorage.SaveBILog("set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
                 //await _azureStorage.SaveBILog("set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
                 await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
                 await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
@@ -961,6 +1003,36 @@ namespace TEAMModelBI.Controllers.BISchool
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// 查询所有学校  第三方开放平台关联学校显示所有学校
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("get-applyschools")]
+        public async Task<IActionResult> GetApplySchools(JsonElement jsonElement) 
+        {
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            if ($"{site}".Equals(BIConst.GlobalSite))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+            }
+
+            List<ApplySchool> applySchools = new();
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ApplySchool>(queryText: "select c.id,c.code,c.name,c.picture from c",requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")}))
+            {
+                applySchools.Add(item);
+            }
+
+            return Ok(new { state = 200, applySchools });
+        }
+
+
         /// <summary>
         /// <summary>
         /// 通过学校Id查询详情   数据管理工具——查询工具
         /// 通过学校Id查询详情   数据管理工具——查询工具
         /// </summary>
         /// </summary>
@@ -1157,7 +1229,7 @@ namespace TEAMModelBI.Controllers.BISchool
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// 
+        /// 依据学校统计
         /// </summary>
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         /// <returns></returns>
@@ -1409,6 +1481,14 @@ namespace TEAMModelBI.Controllers.BISchool
         }
         }
 
 
 
 
+        public record ApplySchool
+        {
+            public string id { get; set; }
+            public string code { get; set; }
+            public string name { get; set; }
+            public string picture { get; set; }
+        }
+
         /// <summary>
         /// <summary>
         /// 未加入区域的学校
         /// 未加入区域的学校
         /// </summary>
         /// </summary>

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

@@ -924,6 +924,70 @@ namespace TEAMModelBI.Controllers.DingDingStruc
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// 后端初始化管理员
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("set-apiphoneadmin")]
+        public async Task<IActionResult> SetPhoneAdmin(JsonElement jsonElement) 
+        {
+            jsonElement.TryGetProperty("partitionKey", out JsonElement partitionKey);
+            if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
+
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+            var partKey = _option.Location;
+            if (string.IsNullOrEmpty($"{partitionKey}")) 
+            {
+                partKey = $"{partitionKey}";
+            };
+
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            if ($"{site}".Equals(BIConst.GlobalSite))
+            {
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+            }
+
+            var table = tableClient.GetTableReference("BIDDUserInfo");
+
+            var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partKey}" }, { "mobile", $"{mobile}" } });
+
+            List<string> roles = new();//角色列表
+            List<string> permissions = new();//权限列表
+            StringBuilder msg = new();
+
+            foreach (var user in tempUser)
+            {
+                if (string.IsNullOrEmpty(user.roles))
+                {
+                    user.roles = "admin,assist";
+                }
+                List<string> tempRoles = new(user.roles.Split(","));
+                if (!tempRoles.Contains("admin"))
+                {
+                    tempRoles.Add("admin");
+                }
+                user.roles = string.Join(",", tempRoles);
+                user.joinTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
+
+                if (respUser != null)
+                {
+                    roles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>();
+                }
+
+                msg.Append($"初始将{respUser.name}【{respUser.RowKey}】账号的BI管理员");
+            }
+
+            //保存操作记录
+            //await _azureStorage.SaveBILog("tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
+            await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
+            return Ok(new { state = 200, roles });
+        }
+
         /// <summary>
         /// <summary>
         /// 通过醍摩豆账户信息 设置BI后台管理员
         /// 通过醍摩豆账户信息 设置BI后台管理员
         /// </summary>
         /// </summary>

+ 19 - 0
TEAMModelBI/Tool/TimeHelper.cs

@@ -7,6 +7,11 @@ namespace TEAMModelBI.Tool
     public static class TimeHelper
     public static class TimeHelper
     {
     {
 
 
+        /// <summary>
+        /// 通过时间戳转换为时间
+        /// </summary>
+        /// <param name="timeStamp"></param>
+        /// <returns></returns>
         public static DateTimeOffset GetDateTime(long timeStamp)
         public static DateTimeOffset GetDateTime(long timeStamp)
         {
         {
             long begtime = timeStamp * 10000;
             long begtime = timeStamp * 10000;
@@ -15,7 +20,21 @@ namespace TEAMModelBI.Tool
             long time_tricks = tricks_1970 + begtime;//日志日期刻度
             long time_tricks = tricks_1970 + begtime;//日志日期刻度
             DateTimeOffset dt = new DateTime(time_tricks);//转化为DateTime
             DateTimeOffset dt = new DateTime(time_tricks);//转化为DateTime
             return dt;
             return dt;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="time"></param>
+        /// <returns></returns>
+        public static (long days, long hour) GetDateTime(string time) 
+        {
+            long days = 0, hour = 0;
+            //DateTimeOffset dateTime = new DateTime(time);
+
+
 
 
+            return (days, hour);
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 73 - 2
TEAMModelOS.SDK/Models/Cosmos/BI/Company.cs

@@ -1,12 +1,18 @@
-using System;
+using Microsoft.Azure.Cosmos.Table;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
 
 
 namespace TEAMModelOS.SDK.Models.Cosmos.BI
 namespace TEAMModelOS.SDK.Models.Cosmos.BI
 {
 {
+
+    /// <summary>
+    /// 企业基础信息存储在CosmosDB表
+    /// </summary>
     public class Company :CosmosEntity
     public class Company :CosmosEntity
     {
     {
         public Company() 
         public Company() 
@@ -51,7 +57,10 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// </summary>
         /// </summary>
         [Required(ErrorMessage = "{0} 必须填写")]
         [Required(ErrorMessage = "{0} 必须填写")]
         public string mobile { get; set; }
         public string mobile { get; set; }
-
+        /// <summary>
+        /// 密码生成秘钥
+        /// </summary>
+        public string salt { get; set; }
         /// <summary>
         /// <summary>
         /// 密码
         /// 密码
         /// </summary>
         /// </summary>
@@ -60,8 +69,70 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// 企业的通知回调地址
         /// 企业的通知回调地址
         /// </summary>
         /// </summary>
         public string webhookDomain { get; set; }
         public string webhookDomain { get; set; }
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        public long createTime { get; set; }
+    }
+
+    /// <summary>
+    /// 企业信息基础信息Table
+    /// </summary>
+
+    [TableName(Name = "IESOpenApi")]
+    public class CompanyTable : TableEntity
+    {
+
+        /// <summary>
+        /// 企业名称
+        /// </summary>
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string name { get; set; }
+
+        /// <summary>
+        /// 统一社会信用代码
+        /// </summary>
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string credit { get; set; }
+
+        /// <summary>
+        /// 企业log
+        /// </summary>
+        public string picture { get; set; }
+
+        /// <summary>
+        /// 秘钥生成
+        /// </summary>
+        public string jti { get; set; }
+
+        /// <summary>
+        /// 秘钥
+        /// </summary>
+        public string secretKey { get; set; }
+
+        /// <summary>
+        /// 企业邮箱
+        /// </summary>
+        public string emall { get; set; }
+
+        /// <summary>
+        /// 联系方式
+        /// </summary>
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string mobile { get; set; }
+        /// <summary>
+        /// 密码生成秘钥
+        /// </summary>
         public string salt { get; set; }
         public string salt { get; set; }
         /// <summary>
         /// <summary>
+        /// 密码
+        /// </summary>
+        public string password { get; set; }
+        /// <summary>
+        /// 企业的通知回调地址
+        /// </summary>
+        public string webhookDomain { get; set; }
+        /// <summary>
         /// 创建时间
         /// 创建时间
         /// </summary>
         /// </summary>
         public long createTime { get; set; }
         public long createTime { get; set; }