Ver código fonte

编写查询所有的学校中间件,没有查询到更新。

Li 2 anos atrás
pai
commit
3a857031f3
1 arquivos alterados com 63 adições e 54 exclusões
  1. 63 54
      TEAMModelBI/Controllers/Census/SchoolController.cs

+ 63 - 54
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -692,74 +692,83 @@ namespace TEAMModelBI.Controllers.Census
         [HttpPost("get-scinfos")]
         public async Task<IActionResult> GetScInfos(JsonElement jsonElement)
         {
-            var cosmosClient = _azureCosmos.GetCosmosClient();
-            List<string> scId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
-            List<BIRelation> scInfos = new();
-            foreach (var itemId in scId)
+            try
             {
-                BIRelation bIRelation = null;
-                var resRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("BIRel"));
-                if (resRel.Status == 200)
-                {
-                    using var fileJson = await JsonDocument.ParseAsync(resRel.ContentStream);
-                    bIRelation = fileJson.ToObject<BIRelation>();
-                }
-                else
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                List<string> scId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
+                List<BIRelation> scInfos = new();
+                foreach (var itemId in scId)
                 {
-                    ScBaseInfo scBaseInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ScBaseInfo>(itemId, new PartitionKey("Base"));
-                    string areaName = null;
-                    if (!string.IsNullOrEmpty(scBaseInfo.areaId)) 
+                    BIRelation bIRelation = null;
+                    var resRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("BIRel"));
+                    if (resRel.Status == 200)
                     {
-                        await foreach (var itemName in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.pk='Area' and c.id='{scBaseInfo.areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
-                        {
-                            areaName = itemName;
-                        }
+                        using var fileJson = await JsonDocument.ParseAsync(resRel.ContentStream);
+                        bIRelation = fileJson.ToObject<BIRelation>();
                     }
-
-                    bIRelation = new BIRelation()
-                    {
-                        name = scBaseInfo.name,
-                        picture = scBaseInfo.picture,
-                        size = scBaseInfo.size,
-                        createDate = scBaseInfo.createTime,
-                        region = scBaseInfo.region,
-                        province = scBaseInfo.province,
-                        city = scBaseInfo.city,
-                        dist = scBaseInfo.dist,
-                        address = scBaseInfo.address,
-                        areaId = scBaseInfo.areaId,
-                        scale = scBaseInfo.scale,
-                        areaName = areaName,
-                        upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
-                    };
-
-                    var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("ProductSum"));
-                    if (response.Status == 200)
+                    else
                     {
-                        using var json = await JsonDocument.ParseAsync(response.ContentStream);
-                        if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
+                        ScBaseInfo scBaseInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ScBaseInfo>(itemId, new PartitionKey("Base"));
+                        string areaName = null;
+                        if (!string.IsNullOrEmpty(scBaseInfo.areaId))
                         {
-                            List<string> serials = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
-                            bIRelation.serial = serials;
+                            await foreach (var itemName in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.pk='Area' and c.id='{scBaseInfo.areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
+                            {
+                                areaName = itemName;
+                            }
                         }
-                        if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
+
+                        bIRelation = new BIRelation()
                         {
-                            List<string> services = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
-                            bIRelation.service = services;
-                        }
-                        if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
+                            id = scBaseInfo.id,
+                            name = scBaseInfo.name,
+                            picture = scBaseInfo.picture,
+                            size = scBaseInfo.size,
+                            createDate = scBaseInfo.createTime,
+                            region = scBaseInfo.region,
+                            province = scBaseInfo.province,
+                            city = scBaseInfo.city,
+                            dist = scBaseInfo.dist,
+                            address = scBaseInfo.address,
+                            areaId = scBaseInfo.areaId,
+                            scale = scBaseInfo.scale,
+                            areaName = areaName,
+                            upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+                        };
+
+                        var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("ProductSum"));
+                        if (response.Status == 200)
                         {
-                            List<string> hards = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
-                            bIRelation.hard = hards;
+                            using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                            if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
+                            {
+                                List<string> serials = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
+                                bIRelation.serial = serials;
+                            }
+                            if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
+                            {
+                                List<string> services = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
+                                bIRelation.service = services;
+                            }
+                            if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
+                            {
+                                List<string> hards = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
+                                bIRelation.hard = hards;
+                            }
                         }
+                        bIRelation = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<BIRelation>(bIRelation, new PartitionKey("BIRel"));
                     }
-                    bIRelation = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<BIRelation>(bIRelation, new PartitionKey("BIRel"));
+
+                    scInfos.Add(bIRelation);
                 }
 
-                scInfos.Add(bIRelation);
+                return Ok(new { state = RespondCode.Ok, cnt = scId.Count, scInfos });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"BI,{_option.Location},/school/get-scinfos \n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                return BadRequest();
             }
-
-            return Ok(new { state = RespondCode.Ok, cnt = scId.Count, scInfos });
         }