Browse Source

优化检测创校前检测,返回生成的学校Code信息。

Li 2 years ago
parent
commit
6a14530846

+ 52 - 3
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -83,6 +83,34 @@ namespace TEAMModelBI.Controllers.BISchool
             return Ok(new { authorityBIList });
         }
 
+
+        public async Task<IActionResult> GetSchoolCode(JsonElement jsonElement)
+        {
+            if (!jsonElement.TryGetProperty("schools", out JsonElement schools)) return BadRequest();
+
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            List<CreateSchoolInfo> cSchools = schools.ToObject<List<CreateSchoolInfo>>();
+
+            List<CreateSchoolInfo> createScInfo = new();
+
+            foreach (var item in cSchools)
+            {
+                CreateSchoolInfo createSchoolInfo = item;
+                //生成学校ID
+                bool tempStaus = true;
+                do
+                {
+                    createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
+                    var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
+                    if (schoolStatu.Status != 200) tempStaus = false;
+                    else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
+                } while (tempStaus);
+                createScInfo.Add(createSchoolInfo);
+            }
+
+            return Ok(new { state = RespondCode.Ok });
+        }
+
         /// <summary>
         /// 批量创校   //已对接
         /// </summary>
@@ -1046,8 +1074,13 @@ namespace TEAMModelBI.Controllers.BISchool
             if (!jsonElement.TryGetProperty("scNames", out JsonElement _scNames)) return BadRequest();
             if (!jsonElement.TryGetProperty("accounts", out JsonElement _accounts)) return BadRequest();
             if (!jsonElement.TryGetProperty("areaIds", out JsonElement _areaIds)) return BadRequest();
-
+            jsonElement.TryGetProperty("schools", out JsonElement schools);
+            
             var cosmosClient = _azureCosmos.GetCosmosClient();
+            List<CreateSchoolInfo> cSchools = new();
+            if (!string.IsNullOrEmpty($"{schools}"))
+                cSchools = schools.ToObject<List<CreateSchoolInfo>>();
+
 
             List<string> scNames = _scNames.ToObject<List<string>>();
             List<string> accounts = _accounts.ToObject<List<string>>();
@@ -1057,6 +1090,7 @@ namespace TEAMModelBI.Controllers.BISchool
             List<string> noAccounts = new();    // 不存在的账户
             List<string> noAreaIds = new();     //不存在的学区
             List<string> synPro = new();      //已同步省平台
+            List<CreateSchoolInfo> createScInfo = new();  //学校简码信息
 
             if (scNames.Count > 0)
             {
@@ -1120,10 +1154,25 @@ namespace TEAMModelBI.Controllers.BISchool
                 }
             }
 
+            foreach (var item in cSchools)
+            {
+                CreateSchoolInfo createSchoolInfo = item;
+                //生成学校ID
+                bool tempStaus = true;
+                do
+                {
+                    createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
+                    var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
+                    if (schoolStatu.Status != 200) tempStaus = false;
+                    else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
+                } while (tempStaus);
+                createScInfo.Add(createSchoolInfo);
+            }
+
             if (existScNames.Count > 0 || noAccounts.Count > 0 || noAreaIds.Count > 0 || synPro.Count > 0)
-                return Ok(new { state = RespondCode.Created, existScNames, noAccounts, noAreaIds, synPro });
+                return Ok(new { state = RespondCode.Created, existScNames, noAccounts, noAreaIds, synPro, createScInfo });
             else
-                return Ok(new { state = RespondCode.Ok });
+                return Ok(new { state = RespondCode.Ok , createScInfo });
         }
 
         /// <summary>

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/BI/CreateSchoolInfo.cs

@@ -11,7 +11,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
     {
         public string province { get; set; }
         public string id { get; set; }
-        public int createCount { get; set; }
+        public int createCount { get; set; } = 0;
         public string name { get; set; }
         public string city { get; set; }
         public string aname { get; set; }