Browse Source

add RpcException

MIke 2 years ago
parent
commit
afbdfc933c

+ 3 - 3
Common/Exceptions/HasAddDeviceException.cs

@@ -6,14 +6,14 @@ using JsonRpcLite.Services;
 namespace WingDeviceService.Common
 {
     /// <summary>
-    /// 设备不存在
+    /// 设备已添加
     /// </summary>
     public class HasAddDeviceException : RpcException
     {
         public HasAddDeviceException():base((int)CustomerRpcCode.HasAddedDevice,"The device has been Added" , null)
         {
-            
-        }   
+
+        }
     }
 
 }

+ 18 - 0
Common/Exceptions/NoExistOrgException.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Globalization;
+using WingInterfaceLibrary.Enum;
+using JsonRpcLite.Services;
+
+namespace WingDeviceService.Common
+{
+    /// <summary>
+    /// 医院不存在
+    /// </summary>
+    public class NoExistOrgException : RpcException
+    {
+        public  NoExistOrgException() : base((int)CustomerRpcCode.OrganizationNotExist, "Org does not exist", null)
+        {
+          
+        }
+    }
+}

+ 18 - 0
Common/Exceptions/NoExistUserException.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Globalization;
+using WingInterfaceLibrary.Enum;
+using JsonRpcLite.Services;
+
+namespace WingDeviceService.Common
+{
+    /// <summary>
+    /// 设备不存在
+    /// </summary>
+    public class NoExistUserException : RpcException
+    {
+        public  NoExistUserException() : base((int)CustomerRpcCode.UserNotExistError, "User does not exist", null)
+        {
+          
+        }
+    }
+}

+ 10 - 10
Service/DeviceService.cs

@@ -110,14 +110,14 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
             if (deviceDb == null)
             {
-                throw new RpcException(1007, "Device not exist.", "Device not exist.");
+                throw new NoExistDeviceException();
             }
             foreach (var userCode in userCodes)
             {
                 var existUser = await _userServiceProxy.FindUserByCodeAsync(userCode);
                 if (existUser == null)
                 {
-                    throw new RpcException(1007, " Users not exist.", " Users not exist.");
+                    throw new NoExistUserException();
                 }
             }
 
@@ -227,7 +227,7 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
             if (deviceDb == null)
             {
-                throw new RpcException(1007, "Device not exist.", "Device not exist.");
+               throw new NoExistDeviceException();
             }
             var updateUsers = new List<TableDataItem<UserPasswordDTO>>();
             foreach (var userCode in userCodes)
@@ -323,12 +323,12 @@ namespace WingDeviceService.Service
             var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
             if (userInfoDO == null)
             {
-                throw new RpcException(1007, "User not exist.", "User not exist.");
+              throw new NoExistUserException();
             }
             //查询用户的医院是否存在
             if (string.IsNullOrWhiteSpace(userInfoDO.OrganizationCode))
             {
-                throw new RpcException(1007, "User's organization not exist.", "User's organization not exist.");
+                throw new NoExistOrgException();
             }
             var deviceInfoDOList = new List<DeviceInfoDTO>();
             if (!userInfoDO.IsDirector)
@@ -390,7 +390,7 @@ namespace WingDeviceService.Service
             var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
             if (userInfoDO == null)
             {
-                throw new RpcException(1007, "User not exist.", "User not exist.");
+              throw new NoExistUserException();
             }
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
             if (deviceDb == null)
@@ -617,13 +617,13 @@ namespace WingDeviceService.Service
             var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
             if (userInfoDO == null)
             {
-                throw new RpcException(1007, "User not exist.", "User not exist.");
+              throw new NoExistUserException();
             }
             var result = new List<SelectItemDTO>();
             //查询用户的医院是否存在
             if (string.IsNullOrEmpty(userInfoDO.OrganizationCode))
             {
-                throw new RpcException(1007, "User's organization not exist.", "User's organization not exist.");
+               throw new NoExistOrgException();
             }
             //查询用户绑定的设备
             if (userInfoDO.BindDevices == null || userInfoDO.BindDevices.Count <= 0)
@@ -653,7 +653,7 @@ namespace WingDeviceService.Service
             var deviceInfo = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
             if (deviceInfo == null || string.IsNullOrWhiteSpace(deviceInfo.DeviceCode))
             {
-                throw new RpcException(1007, "deviceInfo not find", "deviceInfo not find");
+                throw new NoExistDeviceException();
             }
             var org = new OrganizationDTO();
             if (!string.IsNullOrWhiteSpace(deviceInfo.OrganizationCode))
@@ -843,7 +843,7 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
             if (deviceDb == null)
             {
-                throw new RpcException(1007, "Device not exist.", "Device not exist.");
+               throw new NoExistDeviceException();
             }
             var userListResult = await _userServiceProxy.GetUsersByDeviceAsync(request.DeviceCode);
             if (userListResult != null && userListResult.Count > 0)