Browse Source

FISWebsocket优化,RemedicalV2 当ID为空时,自动填充NotFilled作为ID

felix 2 years ago
parent
commit
813a11d28a

+ 16 - 2
Vinno.vCloud.Common.FIS/Helper/DTOConverter.cs

@@ -53,7 +53,10 @@ namespace Vinno.vCloud.Common.FIS.Helper
                             patientName = patientInfo.FirstName.Trim() + " " + patientInfo.LastName.Trim();
                         }
                     }
-                    patientInfoList.Add(new DataItemDTO() { Key = "Name", Value = Base64CryptionHelper.EncryptIndependent(patientName) });
+                    if (!string.IsNullOrWhiteSpace(patientName))
+                    {
+                        patientInfoList.Add(new DataItemDTO() { Key = "Name", Value = Base64CryptionHelper.EncryptIndependent(patientName) });
+                    }
                     if (!string.IsNullOrWhiteSpace(patientInfo.Phone))
                     {
                         patientInfoList.Add(new DataItemDTO() { Key = "Phone", Value = Base64CryptionHelper.EncryptIndependent(patientInfo.Phone) });
@@ -110,6 +113,10 @@ namespace Vinno.vCloud.Common.FIS.Helper
                     {
                         patientInfoList.Add(new DataItemDTO() { Key = "ID", Value = patientInfo.PatientId });
                     }
+                    else
+                    {
+                        patientInfoList.Add(new DataItemDTO() { Key = "ID", Value = "NotFilled" });
+                    }
                     break;
 
                 case OrganizationPatientTypeEnum.Animals:
@@ -126,7 +133,10 @@ namespace Vinno.vCloud.Common.FIS.Helper
                     {
                         animalName = patientInfo.FirstName + patientInfo.LastName;
                     }
-                    patientInfoList.Add(new DataItemDTO() { Key = "AnimalInfoName", Value = Base64CryptionHelper.EncryptIndependent(animalName) });
+                    if (!string.IsNullOrWhiteSpace(animalName))
+                    {
+                        patientInfoList.Add(new DataItemDTO() { Key = "AnimalInfoName", Value = Base64CryptionHelper.EncryptIndependent(animalName) });
+                    }
                     if (!string.IsNullOrWhiteSpace(patientInfo.Phone))
                     {
                         patientInfoList.Add(new DataItemDTO() { Key = "AnimalInfoPhone", Value = Base64CryptionHelper.EncryptIndependent(patientInfo.Phone) });
@@ -186,6 +196,10 @@ namespace Vinno.vCloud.Common.FIS.Helper
                     {
                         patientInfoList.Add(new DataItemDTO() { Key = "AnimalInfoID", Value = patientInfo.PatientId });
                     }
+                    else
+                    {
+                        patientInfoList.Add(new DataItemDTO() { Key = "AnimalInfoID", Value = "NotFilled" });
+                    }
                     break;
             }
             return patientInfoList;

+ 46 - 15
Vinno.vCloud.Common.FIS/Notification/FISWebSocket.cs

@@ -36,6 +36,33 @@ namespace Vinno.vCloud.Common.FIS.Notification
                 _webSocket.Opened += OnOpened;
                 _webSocket.Error += OnError;
                 _webSocket.DataReceived += OnDataReceived;
+                _webSocket.Closed += OnClosed;
+                var xx = _webSocket.EnableAutoSendPing;
+                var xs = _webSocket.AutoSendPingInterval;
+            }
+        }
+
+        private void OnClosed(object sender, EventArgs e)
+        {
+            try
+            {
+                Logger.WriteLineInfo($"FISWebsocket OnClosed Invoked");
+                Dispose();
+                Retry();
+            }
+            catch (Exception ex)
+            {
+                Logger.WriteLineError($"FISWebsocket OnClosed Error:{ex}");
+            }
+        }
+
+        private void Retry()
+        {
+            if (_retryCount < 2)
+            {
+                _retryCount++;
+                CreateWebSocket();
+                Connect();
             }
         }
 
@@ -157,25 +184,21 @@ namespace Vinno.vCloud.Common.FIS.Notification
 
         private void OnOpened(object sender, EventArgs e)
         {
+            _retryCount = 0;
             Logger.WriteLineInfo($"FISWebsocket OnOpened Invoked");
         }
 
         private void OnError(object sender, ErrorEventArgs e)
         {
-            Logger.WriteLineInfo($"FISWebsocket OnError Invoked");
             try
             {
+                Logger.WriteLineInfo($"FISWebsocket OnError Invoked");
                 Dispose();
-                if (_retryCount < 1)
-                {
-                    _retryCount++;
-                    CreateWebSocket();
-                    Connect();
-                }
+                Retry();
             }
             catch (Exception ex)
             {
-                Logger.WriteLineError($"FISWebsocket OnError Dispose Websocket Error:{ex}");
+                Logger.WriteLineError($"FISWebsocket OnError Error:{ex}");
             }
         }
 
@@ -193,14 +216,22 @@ namespace Vinno.vCloud.Common.FIS.Notification
 
         public void Dispose()
         {
-            if (_webSocket != null)
+            try
+            {
+                if (_webSocket != null)
+                {
+                    _webSocket.Opened -= OnOpened;
+                    _webSocket.Error -= OnError;
+                    _webSocket.Closed -= OnClosed;
+                    _webSocket.DataReceived -= OnDataReceived;
+                    _webSocket.Close();
+                    _webSocket.Dispose();
+                    _webSocket = null;
+                }
+            }
+            catch (Exception ex)
             {
-                _webSocket.Opened -= OnOpened;
-                _webSocket.Error -= OnError;
-                _webSocket.DataReceived -= OnDataReceived;
-                _webSocket.Close();
-                _webSocket.Dispose();
-                _webSocket = null;
+                Logger.WriteLineError($"FISWebsocket Dispose Error:{ex}");
             }
         }
     }