Xfedge 1 år sedan
förälder
incheckning
01d8cbedb1

+ 4 - 4
src/Hotline.Api/Controllers/OrderController.cs

@@ -101,7 +101,7 @@ public class OrderController : BaseController
     private readonly IEnterpriseService _enterpriseService;
     private readonly IPushDomainService _pushDomainService;
     private readonly ILogger<OrderController> _logger;
-    private readonly ITypedCache<EnterpriseToken> _cacheResponse;
+    private readonly ITypedCache<YbEnterpriseToken> _cacheResponse;
     private readonly IRepository<OrderSendBackAudit> _orderSendBackAuditRepository;
     private readonly IRepository<User> _userRepository;
     private readonly IExportApplication _exportApplication;
@@ -151,7 +151,7 @@ public class OrderController : BaseController
         IEnterpriseService enterpriseService,
         IPushDomainService pushDomainService,
         ILogger<OrderController> logger,
-        ITypedCache<EnterpriseToken> cacheResponse,
+        ITypedCache<YbEnterpriseToken> cacheResponse,
         IRepository<OrderSendBackAudit> orderSendBackAuditRepository,
         IRepository<User> userRepository,
         IExportApplication exportApplication
@@ -3990,9 +3990,9 @@ public class OrderController : BaseController
     /// <returns></returns>
     [HttpGet("enterprise/list")]
     [LogFilter("查询企业列表")]
-    public async Task<EnterpriseListData> GetEnterpriseList([FromQuery] PagedKeywordRequest dto)
+    public async Task<YbEnterprisePaged> QueryYbEnterprises([FromQuery] PagedKeywordRequest dto)
     {
-        return await _enterpriseService.GetEnterprisesAsync(dto.Keyword!, dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
+        return await _enterpriseService.QueryYbEnterprisesAsync(dto.Keyword!, dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
     }
     #endregion
 

+ 0 - 29
src/Hotline.Share/Dtos/Enterprise/EnterpriseDto.cs

@@ -1,29 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Hotline.Share.Dtos.Enterprise
-{
-	public class EnterpriseListData
-	{
-		public EnterpriseListDataRecords records { get; set; }
-
-		public int total { get; set; }
-
-		public int size { get; set; }
-
-		public int current { get; set; }
-
-		public int pages { get; set; }
-	}
-
-	public class EnterpriseListDataRecords
-	{
-		public string enterpriseCode { get; set; }
-		public string enterpriseName { get; set; }
-		public string specialTeamCode { get; set; }
-		public string specialTeamName { get; set; }
-	}
-}

+ 44 - 0
src/Hotline.Share/Dtos/Enterprise/YbEnterprisePaged.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json.Serialization;
+using System.Threading.Tasks;
+
+namespace Hotline.Share.Dtos.Enterprise
+{
+	public class YbEnterprise
+	{
+		[JsonPropertyName("enterpriseCode")]
+		public string EnterpriseCode { get; set; }
+		
+		[JsonPropertyName("enterpriseName")]
+		public string EnterpriseName { get; set; }
+		
+		[JsonPropertyName("specialTeamCode")]
+		public string SpecialTeamCode { get; set; }
+		
+		[JsonPropertyName("specialTeamName")]
+		public string SpecialTeamName { get; set; }
+	}
+	
+	
+	public class YbEnterprisePaged
+	{
+		[JsonPropertyName("records")]
+		public List<YbEnterprise> Records { get; set; }
+		
+		[JsonPropertyName("total")]
+		public int Total { get; set; }
+
+		[JsonPropertyName("size")]
+		public int Size { get; set; }
+
+		[JsonPropertyName("current")]
+		public int Current { get; set; }
+
+		[JsonPropertyName("pages")]
+		public int Pages { get; set; }
+	}
+
+}

+ 10 - 0
src/Hotline.Share/Dtos/Enterprise/YbEnterprisesRequest.cs

@@ -0,0 +1,10 @@
+namespace Hotline.Share.Dtos.Enterprise;
+
+public class YbEnterprisesRequest
+{
+    public string EnterpriseName { get; set; }
+
+    public int Current {  get; set; }
+
+    public int Size { get; set; }
+}

+ 14 - 17
src/Hotline.YbEnterprise.Sdk/EnterpriseService.cs

@@ -14,16 +14,16 @@ using XF.Domain.Dependency;
 
 namespace Hotline.YbEnterprise.Sdk
 {
-    public class EnterpriseService : IEnterpriseService, ITransientDependency
+    public class EnterpriseService : IEnterpriseService, IScopeDependency
     {
         private readonly IHttpClientFactory _httpClientFactory;
         private readonly IOptionsSnapshot<EnterpriseConfig> _enterpriseOptions;
-        private readonly ITypedCache<EnterpriseToken> _tokenCache;
+        private readonly ITypedCache<YbEnterpriseToken> _tokenCache;
         private readonly ILogger<EnterpriseService> _logger;
         public EnterpriseService(
             IHttpClientFactory httpClientFactory,
             IOptionsSnapshot<EnterpriseConfig> enterpriseOptions,
-            ITypedCache<EnterpriseToken> tokenCache,
+            ITypedCache<YbEnterpriseToken> tokenCache,
             ILogger<EnterpriseService> logger)
         {
             _httpClientFactory = httpClientFactory;
@@ -40,10 +40,10 @@ namespace Hotline.YbEnterprise.Sdk
         /// <param name="size"></param>
         /// <param name="cancellationToken"></param>
         /// <returns></returns>
-        public async Task<EnterpriseListData> GetEnterprisesAsync(
+        public async Task<YbEnterprisePaged> QueryYbEnterprisesAsync(
             string name, int current, int size, CancellationToken cancellationToken)
         {
-            var request = new EnterpriseListRequest
+            var request = new YbEnterprisesRequest()
             {
                 EnterpriseName = name,
                 Current = current,
@@ -51,17 +51,17 @@ namespace Hotline.YbEnterprise.Sdk
             };
 
             var token = await GetTokenAsync(YbEnterpriseDefaults.KeyOfToken, cancellationToken);
-            var result = await ExecuteAsync<EnterpriseListRequest, EnterpriseListResponse>(
+            var result = await ExecuteAsync<YbEnterprisesRequest, YbEnterpriseResponse<YbEnterprisePaged>>(
                 YbEnterpriseDefaults.PathEnterprises,
                 request,
                 d => d.DefaultRequestHeaders.Add("Blade-Auth", $"{token.TokenType} {token.AccessToken}"),
                 cancellationToken);
-            if (result is null || !result.success)
+            if (result is null || !result.Success)
                 throw new UserFriendlyException("未获取到企业专班数据");
-            return result.data;
+            return result.Data;
         }
 
-        public async Task<EnterpriseToken> GetTokenAsync(string key, CancellationToken cancellationToken)
+        private async Task<YbEnterpriseToken> GetTokenAsync(string key, CancellationToken cancellationToken)
         {
             var token = await _tokenCache.GetAsync(key, cancellationToken);
             if (token is not null) return token;
@@ -70,13 +70,12 @@ namespace Hotline.YbEnterprise.Sdk
             return token;
         }
 
-        public async Task<EnterpriseToken> GetTokenAsync(CancellationToken cancellationToken)
+        private async Task<YbEnterpriseToken> GetTokenAsync(CancellationToken cancellationToken)
         {
-            //var path = "blade-auth/oauth/getAccessToken";
             var config = _enterpriseOptions.Value;
             string authorization = config.ClientId + ":" + config.ClientSecret;
             authorization = Convert.ToBase64String(Encoding.UTF8.GetBytes(authorization));
-            var result = await ExecuteAsync<object, EnterpriseTokenResponse>(
+            var result = await ExecuteAsync<object, YbEnterpriseResponse<YbEnterpriseToken>>(
                 YbEnterpriseDefaults.PathToken,
                 new(),
                 d =>
@@ -85,12 +84,12 @@ namespace Hotline.YbEnterprise.Sdk
                     d.DefaultRequestHeaders.Add("Tenant-Id", config.TenantId);
                 }, cancellationToken);
 
-            if (result is null || !result.success)
+            if (result is null || !result.Success)
                 throw new UserFriendlyException("获取enterprise token失败");
-            return result.data;
+            return result.Data;
         }
 
-        public async Task<TResponse?> ExecuteAsync<TRequest, TResponse>(string path, TRequest request,
+        private async Task<TResponse?> ExecuteAsync<TRequest, TResponse>(string path, TRequest request,
             Action<HttpClient>? clientInitialize = null, CancellationToken cancellationToken = default)
         {
             var client = _httpClientFactory.CreateClient(YbEnterpriseDefaults.HttpName);
@@ -98,8 +97,6 @@ namespace Hotline.YbEnterprise.Sdk
 
             using var responseMessage = await client.PostAsJsonAsync(path, request, cancellationToken);
             responseMessage.EnsureSuccessStatusCode();
-            var s = await responseMessage.Content.ReadAsStringAsync(cancellationToken);
-            _logger.LogInformation(s);
             var result = await responseMessage.Content.ReadFromJsonAsync<TResponse>(cancellationToken: cancellationToken);
             return result;
         }

+ 0 - 45
src/Hotline.YbEnterprise.Sdk/EnterpriseTokenResponse.cs

@@ -1,45 +0,0 @@
-using System.Text.Json.Serialization;
-using Hotline.Share.Dtos;
-using Hotline.Share.Dtos.Enterprise;
-
-namespace Hotline.YbEnterprise.Sdk
-{
-	public class EnterpriseTokenResponse
-	{
-		public int code {  get; set; }
-		public bool success { get; set; }
-		public EnterpriseToken data { get; set; }
-		public string msg { get; set; }
-	}
-
-	public class EnterpriseListRequest 
-	{
-		public string EnterpriseName { get; set; }
-
-		public int Current {  get; set; }
-
-		public int Size { get; set; }
-	}
-
-	public class EnterpriseListResponse
-	{
-		public int code { get; set; }
-		public bool success { get; set; }
-		public EnterpriseListData data { get; set; }
-	}
-
-    public class EnterpriseResponse<TData>
-    {
-		[JsonPropertyName("code")]
-        public int Code { get; set; }
-
-		[JsonPropertyName("success")]
-        public bool Success { get; set; }
-
-		[JsonPropertyName("data")]
-        public TData Data { get; set; }
-
-		[JsonPropertyName("msg")]
-        public string Message { get; set; }
-    }
-}

+ 18 - 0
src/Hotline.YbEnterprise.Sdk/YbEnterpriseResponse.cs

@@ -0,0 +1,18 @@
+using System.Text.Json.Serialization;
+
+namespace Hotline.YbEnterprise.Sdk;
+
+public class YbEnterpriseResponse<TData>
+{
+    [JsonPropertyName("code")]
+    public int Code { get; set; }
+
+    [JsonPropertyName("success")]
+    public bool Success { get; set; }
+
+    [JsonPropertyName("data")]
+    public TData Data { get; set; }
+
+    [JsonPropertyName("msg")]
+    public string Message { get; set; }
+}

+ 1 - 1
src/Hotline.YbEnterprise.Sdk/EnterpriseToken.cs → src/Hotline.YbEnterprise.Sdk/YbEnterpriseToken.cs

@@ -2,7 +2,7 @@
 
 namespace Hotline.YbEnterprise.Sdk
 {
-	public class EnterpriseToken 
+	public class YbEnterpriseToken 
 	{
 		/// <summary>
 		/// access_token

+ 1 - 1
src/Hotline/Enterprise/IEnterpriseService.cs

@@ -6,6 +6,6 @@ namespace Hotline.Enterprise
 {
 	public interface IEnterpriseService
 	{
-		Task<EnterpriseListData> GetEnterprisesAsync(string name, int current, int size, CancellationToken cancellationToken);
+		Task<YbEnterprisePaged> QueryYbEnterprisesAsync(string name, int current, int size, CancellationToken cancellationToken);
 	}
 }