Bläddra i källkod

add RpcException

MIke 2 år sedan
förälder
incheckning
84c887bb6b

+ 2 - 2
Common/Exceptions/CustomerRpcCodeException.cs

@@ -10,10 +10,10 @@ namespace WingDeviceService.Common
     /// </summary>
     public class CustomerRpcCodeException : RpcException
     {
-        public CustomerRpcCodeException(CustomerRpcCode code):base((int)code,code.ToString() , null)
+        public CustomerRpcCodeException(CustomerRpcCode code,string message):base((int)code,message , null)
         {
             
-        }   
+        }
     }
 
 }

+ 0 - 19
Common/Exceptions/HasAddDeviceException.cs

@@ -1,19 +0,0 @@
-using System;
-using System.Globalization;
-using WingInterfaceLibrary.Enum;
-using JsonRpcLite.Services;
-
-namespace WingDeviceService.Common
-{
-    /// <summary>
-    /// 设备已添加
-    /// </summary>
-    public class HasAddDeviceException : RpcException
-    {
-        public HasAddDeviceException():base((int)CustomerRpcCode.HasAddedDevice,"The device has been Added" , null)
-        {
-
-        }
-    }
-
-}

+ 0 - 18
Common/Exceptions/NoExistDeviceException.cs

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

+ 0 - 18
Common/Exceptions/NoExistOrgException.cs

@@ -1,18 +0,0 @@
-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)
-        {
-          
-        }
-    }
-}

+ 0 - 18
Common/Exceptions/NoExistUserException.cs

@@ -1,18 +0,0 @@
-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)
-        {
-          
-        }
-    }
-}

+ 19 - 20
Service/DeviceService.cs

@@ -110,14 +110,14 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
             if (deviceDb == null)
             {
-                throw new NoExistDeviceException();
+                 throw new CustomerRpcCodeException(CustomerRpcCode.NoExistDevice, "Device does not exist");
             }
             foreach (var userCode in userCodes)
             {
                 var existUser = await _userServiceProxy.FindUserByCodeAsync(userCode);
                 if (existUser == null)
                 {
-                    throw new NoExistUserException();
+                    throw new CustomerRpcCodeException(CustomerRpcCode.UserNotExistError, "User does not exist");
                 }
             }
 
@@ -144,7 +144,7 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
             if (deviceDb == null || deviceDb.DeviceCode != request.DeviceCode)
             {
-               throw new NoExistDeviceException();
+               throw new CustomerRpcCodeException(CustomerRpcCode.NoExistDevice, "Device does not exist");
             }
             //根据机构编号查询机构名称
             var organizationName = "";
@@ -198,7 +198,7 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
             if (deviceDb == null || deviceDb.ShortCode != request.ShortCode)
             {
-                throw new NoExistDeviceException();
+               throw new CustomerRpcCodeException(CustomerRpcCode.NoExistDevice, "Device does not exist");
             }
             return await MapToExtendDTO(deviceDb);
         }
@@ -227,7 +227,7 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
             if (deviceDb == null)
             {
-               throw new NoExistDeviceException();
+                throw new CustomerRpcCodeException(CustomerRpcCode.NoExistDevice, "Device does not exist");
             }
             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 NoExistUserException();
+              throw new CustomerRpcCodeException(CustomerRpcCode.UserNotExistError, "User does not exist");
             }
             //查询用户的医院是否存在
             if (string.IsNullOrWhiteSpace(userInfoDO.OrganizationCode))
             {
-                throw new NoExistOrgException();
+                throw new CustomerRpcCodeException(CustomerRpcCode.OrganizationNotExist, "Org does not exist");
             }
             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 NoExistUserException();
+              throw new CustomerRpcCodeException(CustomerRpcCode.UserNotExistError, "User does not exist");
             }
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(request.ShortCode);
             if (deviceDb == null)
@@ -399,8 +399,7 @@ namespace WingDeviceService.Service
             }
             if (userInfoDO.BindDevices != null && userInfoDO.BindDevices.Contains(deviceDb.DeviceCode))
             {
-
-                throw new HasAddDeviceException();
+                  throw new CustomerRpcCodeException(CustomerRpcCode.HasAddedDevice,"The device has been Added");
             }
             try
             {
@@ -617,13 +616,13 @@ namespace WingDeviceService.Service
             var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
             if (userInfoDO == null)
             {
-              throw new NoExistUserException();
+              throw new CustomerRpcCodeException(CustomerRpcCode.UserNotExistError, "User does not exist");
             }
             var result = new List<SelectItemDTO>();
             //查询用户的医院是否存在
             if (string.IsNullOrEmpty(userInfoDO.OrganizationCode))
             {
-               throw new NoExistOrgException();
+              throw new CustomerRpcCodeException(CustomerRpcCode.OrganizationNotExist, "Org does not exist");
             }
             //查询用户绑定的设备
             if (userInfoDO.BindDevices == null || userInfoDO.BindDevices.Count <= 0)
@@ -653,7 +652,7 @@ namespace WingDeviceService.Service
             var deviceInfo = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(deviceCode);
             if (deviceInfo == null || string.IsNullOrWhiteSpace(deviceInfo.DeviceCode))
             {
-                throw new NoExistDeviceException();
+                throw new CustomerRpcCodeException(CustomerRpcCode.NoExistDevice, "Device does not exist");
             }
             var org = new OrganizationDTO();
             if (!string.IsNullOrWhiteSpace(deviceInfo.OrganizationCode))
@@ -684,32 +683,32 @@ namespace WingDeviceService.Service
             var userCode = await ValidateTokenAsync(request.Token);
             if (string.IsNullOrEmpty(shortCode))
             {
-                throw new CustomerRpcCodeException(CustomerRpcCode.UniqueCodeIsEmpty);
+                throw new CustomerRpcCodeException(CustomerRpcCode.UniqueCodeIsEmpty,"UniqueCode is empty");
             }
             var device = await _deviceInfoDBServiceProxy.FindDeviceInfoByShortCodeAsync(shortCode);
             if (device == null)
             {
-                throw new NoExistDeviceException();
+                throw new CustomerRpcCodeException(CustomerRpcCode.NoExistDevice, "Device does not exist");
             }
             var oldOrg = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = device.OrganizationCode });
             if (oldOrg == null || string.IsNullOrWhiteSpace(oldOrg.OrganizationCode))
             {
-                throw new CustomerRpcCodeException(CustomerRpcCode.OrganizationNotExist);
+                throw new CustomerRpcCodeException(CustomerRpcCode.OrganizationNotExist,"Org does not exist");
             }
             //用户
             var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
             if (userDTO == null)
             {
-                throw new CustomerRpcCodeException(CustomerRpcCode.UserNotExistError);
+                throw new CustomerRpcCodeException(CustomerRpcCode.UserNotExistError, "User does not exist");
             }
             if (!userDTO.IsDirector)
             {
-                throw new CustomerRpcCodeException(CustomerRpcCode.NotOrgAdmin);
+                throw new CustomerRpcCodeException(CustomerRpcCode.NotOrgAdmin,"not org admin");
             }
             var org = await _organizationDBService.GetOrganizationDetailAsync(new GetOrganizationDBRequest { OrganizationCode = userDTO.OrganizationCode });
             if (org == null || string.IsNullOrWhiteSpace(org.OrganizationCode))
             {
-                throw new CustomerRpcCodeException(CustomerRpcCode.OrganizationNotExist);
+                throw new CustomerRpcCodeException(CustomerRpcCode.OrganizationNotExist,"Org does not exist");
             }
             #endregion
             try
@@ -843,7 +842,7 @@ namespace WingDeviceService.Service
             var deviceDb = await _deviceInfoDBServiceProxy.FindDeviceInfoByCodeAsync(request.DeviceCode);
             if (deviceDb == null)
             {
-               throw new NoExistDeviceException();
+               throw new CustomerRpcCodeException(CustomerRpcCode.NoExistDevice, "Device does not exist");
             }
             var userListResult = await _userServiceProxy.GetUsersByDeviceAsync(request.DeviceCode);
             if (userListResult != null && userListResult.Count > 0)