Browse Source

处理切换区接口。

Li 2 năm trước cách đây
mục cha
commit
acf9b3a9ce
1 tập tin đã thay đổi với 20 bổ sung24 xóa
  1. 20 24
      TEAMModelBI/Controllers/BINormal/BatchAreaController.cs

+ 20 - 24
TEAMModelBI/Controllers/BINormal/BatchAreaController.cs

@@ -779,19 +779,17 @@ namespace TEAMModelBI.Controllers.BINormal
                     }
                 }
                 StandardFile tempFile = new();
-                try
-                {
-                    tempFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<StandardFile>(saveFile.id, new PartitionKey("StandardFile"));
-                }
-                catch
-                {
-                }
-                if (tempFile.id != null)
+                if (saveFile.id != null)
                 {
-                    if (tempFile.id.Equals(saveFile.id))
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<StandardFile>(saveFile, saveFile.id, new PartitionKey("StandardFile")); //直接替换以前的数据
-                    else
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
+                    var respFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveFile.id, new PartitionKey("StandardFile"));
+                    if (respFile.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(respFile.ContentStream);
+                        tempFile = json.ToObject<StandardFile>();
+                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(tempFile.id, new PartitionKey("StandardFile"));
+                    }
+
+                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
                 }
 
                 //新的区域设置
@@ -808,19 +806,17 @@ namespace TEAMModelBI.Controllers.BINormal
                 }
 
                 AreaSetting tempSetting = new();
-                try
-                {
-                    tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(saveSetting.id, new PartitionKey("StandardFile"));
-                }
-                catch
-                {
-                }
-                if (tempSetting.id != null)
+                if (saveSetting.id != null)
                 {
-                    if (tempSetting.id.Equals(saveSetting.id))
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<AreaSetting>(saveSetting, saveSetting.id, new PartitionKey($"AreaSetting"));   //直接替换以前的数据
-                    else
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting"));  //需要删除原来的区域设置数据在进行添加
+                    var respSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveSetting.id, new PartitionKey("AreaSetting"));
+                    if (respSetting.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(respSetting.ContentStream);
+                        tempSetting = json.ToObject<AreaSetting>();
+                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(tempFile.id, new PartitionKey("AreaSetting"));
+                    }
+
+                    tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting"));  //需要删除原来的区域设置数据在进行添加
                 }
 
                 //发送消息分区键