|
@@ -14,6 +14,7 @@ using WingInterfaceLibrary.Interface.DBInterface;
|
|
|
using WingInterfaceLibrary.DB.Request;
|
|
|
using WingServerCommon.Mapper;
|
|
|
using WingInterfaceLibrary.Request;
|
|
|
+using WingInterfaceLibrary.Request.Authentication;
|
|
|
using WingInterfaceLibrary.DTO.User;
|
|
|
using System.IO;
|
|
|
using WingInterfaceLibrary.DTO.Management;
|
|
@@ -37,7 +38,7 @@ namespace WingDeviceService.Service
|
|
|
|
|
|
private IDeviceInfoDBService _deviceInfoDBServiceProxy;
|
|
|
|
|
|
- private IAuthenticationService _authenticationServiceProxy;
|
|
|
+ private IAuthenticationService _authenticationService;
|
|
|
|
|
|
private IOrganizationDBService _organizationDBService;
|
|
|
|
|
@@ -61,7 +62,7 @@ namespace WingDeviceService.Service
|
|
|
{
|
|
|
base.Load(jsonRpcClientPool);
|
|
|
_userServiceProxy = GetProxy<IUserDBService>();
|
|
|
- _authenticationServiceProxy = GetProxy<IAuthenticationService>();
|
|
|
+ _authenticationService = GetProxy<IAuthenticationService>();
|
|
|
_deviceInfoDBServiceProxy = GetProxy<IDeviceInfoDBService>();
|
|
|
_organizationDBService = GetProxy<IOrganizationDBService>();
|
|
|
_notificationService = GetProxy<INotificationService>();
|
|
@@ -80,7 +81,7 @@ namespace WingDeviceService.Service
|
|
|
{
|
|
|
var userCodes = request.UserCodes;
|
|
|
var deviceCode = request.DeviceCode;
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -123,7 +124,7 @@ namespace WingDeviceService.Service
|
|
|
public async Task<DeviceExtendInfoDTO> GetDeviceInfoAsync(GetDeviceRequest request)
|
|
|
{
|
|
|
//验证
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -180,7 +181,7 @@ namespace WingDeviceService.Service
|
|
|
public async Task<DeviceExtendInfoDTO> GetDeviceByShortCodeAsync(GetDeviceByShortCodeRequest request)
|
|
|
{
|
|
|
//验证
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -205,7 +206,7 @@ namespace WingDeviceService.Service
|
|
|
{
|
|
|
var userCodes = request.UserCodes;
|
|
|
var deviceCode = request.DeviceCode;
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -264,7 +265,7 @@ namespace WingDeviceService.Service
|
|
|
public async Task<bool> RemoveDeviceRelevancyAsync(RemoveDeviceRelevancyRequest request)
|
|
|
{
|
|
|
//验证
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -298,6 +299,17 @@ namespace WingDeviceService.Service
|
|
|
return removeDeviceResult;
|
|
|
}
|
|
|
|
|
|
+ private async Task<string> ValidateTokenAsync(string token)
|
|
|
+ {
|
|
|
+ var request = new ValidateTokenRequest() { Token = token};
|
|
|
+ var result = await _authenticationService.ValidateTokenAsync(request);
|
|
|
+ //Check 权限
|
|
|
+ if (result != null && result.Code != CustomerRpcCode.Ok)
|
|
|
+ {
|
|
|
+ throw new RpcException(1002, "Permission validation error", "Permission validation error"); //TODO refacor 1002 ? not clear
|
|
|
+ }
|
|
|
+ return result.Token.ClientId; //return User code
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 查询个人名下所有设备列表接口
|
|
|
/// </summary>
|
|
@@ -306,13 +318,9 @@ namespace WingDeviceService.Service
|
|
|
public async Task<PageCollection<DeviceExtendInfoDTO>> GetPersonDeviceListAsync(GetPersonDeviceRequest request)
|
|
|
{
|
|
|
//验证
|
|
|
- var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token });
|
|
|
- if (tokenInfo == null)
|
|
|
- {
|
|
|
- throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
- }
|
|
|
+ var userCode = await ValidateTokenAsync(request.Token);
|
|
|
//查询用户是否存在
|
|
|
- var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(tokenInfo.UserCode);
|
|
|
+ var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
|
|
|
if (userInfoDO == null)
|
|
|
{
|
|
|
throw new RpcException(1007, "User not exist.", "User not exist.");
|
|
@@ -377,13 +385,9 @@ namespace WingDeviceService.Service
|
|
|
public async Task<bool> BindDeviceAsync(BindDeviceRequest request)
|
|
|
{
|
|
|
//验证
|
|
|
- var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token });
|
|
|
- if (tokenInfo == null)
|
|
|
- {
|
|
|
- throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
- }
|
|
|
+ var userCode = await ValidateTokenAsync(request.Token);
|
|
|
//查询用户是否存在
|
|
|
- var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(tokenInfo.UserCode);
|
|
|
+ var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
|
|
|
if (userInfoDO == null)
|
|
|
{
|
|
|
throw new RpcException(1007, "User not exist.", "User not exist.");
|
|
@@ -459,7 +463,7 @@ namespace WingDeviceService.Service
|
|
|
/// <returns></returns>
|
|
|
public async Task<bool> ModifyDeviceAsync(ModifyDeviceRequest request)
|
|
|
{
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -520,15 +524,14 @@ namespace WingDeviceService.Service
|
|
|
/// <returns></returns>
|
|
|
public async Task<string> CreateDictionaryItemAsync(CreateDictionaryItemRequest request)
|
|
|
{
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
|
- var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token });
|
|
|
+ var userCode = await ValidateTokenAsync(request.Token);
|
|
|
return await _deviceInfoDBServiceProxy.CreateDictionaryItemAsync(new CreateDictionaryItemDBRequest
|
|
|
{
|
|
|
- Data = new DictionaryDTO { DictionaryType = request.DictionaryType, Value = request.DictionaryItemValue, ParentCode = request.ParentCode },
|
|
|
- PlatformDatas = tokenInfo.HeaderMap,
|
|
|
+ Data = new DictionaryDTO { DictionaryType = request.DictionaryType, Value = request.DictionaryItemValue, ParentCode = request.ParentCode },
|
|
|
ExtensionData = string.Empty
|
|
|
});
|
|
|
}
|
|
@@ -540,7 +543,7 @@ namespace WingDeviceService.Service
|
|
|
/// <returns></returns>
|
|
|
public async Task<List<DictionaryDTO>> FindDeviceModelItemsAsync(FindDeviceModelItemsRequest request)
|
|
|
{
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -559,7 +562,7 @@ namespace WingDeviceService.Service
|
|
|
/// <returns></returns>
|
|
|
public async Task<List<DictionaryDTO>> FindDeviceTypeItemsAsync(FindDeviceTypeItemsRequest request)
|
|
|
{
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -577,7 +580,7 @@ namespace WingDeviceService.Service
|
|
|
/// <returns></returns>
|
|
|
public async Task<List<DeviceExtendInfoDTO>> FindDevicesByOrganizationCodeAsync(FindDevicesByOrganizationCodeRequest request)
|
|
|
{
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new WingInterfaceLibrary.Request.TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
@@ -631,13 +634,9 @@ namespace WingDeviceService.Service
|
|
|
public async Task<List<SelectItemDTO>> GetPersonDeviceDropdownListAsync(TokenRequest request)
|
|
|
{
|
|
|
//验证
|
|
|
- var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(request);
|
|
|
- if (tokenInfo == null)
|
|
|
- {
|
|
|
- throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
- }
|
|
|
+ var userCode = await ValidateTokenAsync(request.Token);
|
|
|
//查询用户是否存在
|
|
|
- var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(tokenInfo.UserCode);
|
|
|
+ var userInfoDO = await _userServiceProxy.FindUserByCodeAsync(userCode);
|
|
|
if (userInfoDO == null)
|
|
|
{
|
|
|
throw new RpcException(1007, "User not exist.", "User not exist.");
|
|
@@ -703,12 +702,7 @@ namespace WingDeviceService.Service
|
|
|
{
|
|
|
var shortCode = request.UniqueCode;
|
|
|
#region Params Check
|
|
|
- var tokenInfo = await _authenticationServiceProxy.GetTokenInfoAsync(new TokenRequest() { Token = request.Token });
|
|
|
- //Check 权限
|
|
|
- if (tokenInfo == null)
|
|
|
- {
|
|
|
- throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
- }
|
|
|
+ var userCode = await ValidateTokenAsync(request.Token);
|
|
|
if (string.IsNullOrEmpty(shortCode))
|
|
|
{
|
|
|
throw new RpcException((int)DeviceErrorCodeEnum.UniqueCodeIsEmpty, "Unique code is empty", "Unique code is empty");
|
|
@@ -724,7 +718,7 @@ namespace WingDeviceService.Service
|
|
|
throw new RpcException((int)DeviceErrorCodeEnum.OrganizationNotExist, "Not exist device's organization ", "Not exist device's organization ");
|
|
|
}
|
|
|
//用户
|
|
|
- var userDTO = await _userServiceProxy.FindUserByCodeAsync(tokenInfo.UserCode);
|
|
|
+ var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
|
|
|
if (userDTO == null)
|
|
|
{
|
|
|
throw new RpcException(1007, "user not exist", "user not exist");
|
|
@@ -858,7 +852,7 @@ namespace WingDeviceService.Service
|
|
|
/// <returns>test01,test02</returns>
|
|
|
public async Task<List<string>> GetDeviceBindUsersCodesAsync(GetDeviceRequest request)
|
|
|
{
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -888,7 +882,7 @@ namespace WingDeviceService.Service
|
|
|
/// <returns>AI应用集合</returns>
|
|
|
public async Task<List<DiagnosisModuleDTO>> FindDeviceDiagnosisModulesAsync(FindDeviceDiagnosisModulesRequest request)
|
|
|
{
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|
|
@@ -908,7 +902,7 @@ namespace WingDeviceService.Service
|
|
|
/// <para>DeviceErrorCodeEnum</para>
|
|
|
public async Task<bool> ModifyDeviceDiagnosisModuleStateAsync(ModifyDeviceDiagnosisModuleStateRequest request)
|
|
|
{
|
|
|
- if (!await _authenticationServiceProxy.CheckTokenAsync(new TokenRequest() { Token = request.Token }))
|
|
|
+ if (!await _authenticationService.CheckTokenAsync(new TokenRequest() { Token = request.Token }))
|
|
|
{
|
|
|
throw new RpcException(1002, "Permission validation error", "Permission validation error");
|
|
|
}
|