ソースを参照

泸州市政府回复工单调用

libin 3 週間 前
コミット
e5bb1d67a9

+ 1 - 1
src/DataSharing.Share/Dtos/LuZhou/CityPortalSiteResponseDto.cs

@@ -5,7 +5,7 @@
     /// </summary>
     public class CityPortalSiteResponseDto
     {
-        public string? code { get; set; }
+        public int code { get; set; }
 
         public string? message { get; set; }
     }

+ 44 - 0
src/DataSharing/LuZhou/LZCityPortal/LZCityPortalSiteClient.cs

@@ -111,5 +111,49 @@ namespace DataSharing.LuZhou.LZCityPortal
 
             return dataToken;
         }
+
+        /// <summary>
+        /// 请求,不带token
+        /// </summary>
+        /// <typeparam name="TResponse"></typeparam>
+        /// <param name="url"></param>
+        /// <param name="httpMethod"></param>
+        /// <param name="stringContent"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task<TResponse?> RequestNoTokenAsync<TResponse>(string url, string httpMethod, string? stringContent = null, CancellationToken cancellationToken = default)
+        {
+            using var scope = _scopeFactory.CreateScope();
+            var provider = scope.ServiceProvider;
+            var channelconfigManager = provider.GetRequiredService<IChannelConfigurationManager>();
+            var httpInvoker = provider.GetRequiredService<IHttpInvoker>();
+
+            var configHotlineClient = channelconfigManager.GetConfigurationHotlineClient();
+            var postUrl = configHotlineClient.AddressUrl + url;
+            return await httpInvoker.RequestStringContentAsync<TResponse>(postUrl, httpMethod, stringContent,
+                d => d.SetHttpClient(configHotlineClient.AddressUrl), cancellationToken);
+        }
+
+
+        /// <summary>
+        /// 请求,不带token
+        /// </summary>
+        /// <typeparam name="TResponse"></typeparam>
+        /// <param name="addressUrl"></param>
+        /// <param name="url"></param>
+        /// <param name="httpMethod"></param>
+        /// <param name="stringContent"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task<TResponse?> RequestNoTokenOtherAsync<TResponse>(string addressUrl, string url, string httpMethod, string? stringContent = null, CancellationToken cancellationToken = default)
+        {
+            using var scope = _scopeFactory.CreateScope();
+            var provider = scope.ServiceProvider;
+            var channelconfigManager = provider.GetRequiredService<IChannelConfigurationManager>();
+            var httpInvoker = provider.GetRequiredService<IHttpInvoker>();
+
+            return await httpInvoker.RequestStringContentAsync<TResponse>(addressUrl + url, httpMethod, stringContent,
+                d => d.SetHttpClient(addressUrl), cancellationToken);
+        }
     }
 }

+ 52 - 7
src/DataSharing/LuZhou/LZCityPortal/LZCityPortalSitePusherProviderService.cs

@@ -1,26 +1,38 @@
-using DataSharing.RawData;
+using DataSharing.FwDataExchange;
+using DataSharing.RawData;
 using DataSharing.SendTask;
 using DataSharing.SendTask.OtherPlatforms;
 using DataSharing.Share.Dtos.CityStateDataExchange;
 using DataSharing.Share.Dtos.LuZhou;
 using DataSharing.Share.Enums;
 using DotNetCore.CAP;
+using Fw.Utility.UnifyResponse;
+using IdentityModel;
 using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using Org.BouncyCastle.Asn1.Ocsp;
+using Org.BouncyCastle.Tls;
+using RestSharp;
+using System.Net;
+using System.Security.Policy;
+using System.Text;
 using XF.Domain.Dependency;
 using XF.Domain.Repository;
+using static System.Runtime.InteropServices.JavaScript.JSType;
 
 namespace DataSharing.LuZhou.LZCityPortal
 {
     public class LZCityPortalSitePusherProviderService : ILZCityPortalSitePusherProviderService, IScopeDependency
     {
         private readonly ILogger<LZCityPortalSitePusherProviderService> _logger;
-        private readonly LZCityPortalSiteClient _dataExchangeClient;
+        private readonly LZCityPortalSiteClient _lzCityPortalSiteClient;
         private readonly IRepository<DsWaitSendTaskOtherPlatforms> _dsSendTaskRepository;
         private readonly ICapPublisher _capPublisher;
         private readonly IRepository<DsSendTaskDetailInfo> _dsSendTaskInfoRepository;
         private readonly IRepository<DsUserTokenInfo> _dsUserTokenInfoRepository;
         private readonly IRepository<DsSendTaskOtherPlatforms> _sendTaskOtherPlatformsRepository;
         private readonly IChannelConfigurationManager _channelConfigurationManager;
+        private readonly RestClient _client;
 
         /// <summary>
         /// 
@@ -34,7 +46,7 @@ namespace DataSharing.LuZhou.LZCityPortal
         /// <param name="sendTaskOtherPlatformsRepository"></param>
         /// <param name="channelConfigurationManager"></param>
         public LZCityPortalSitePusherProviderService(ILogger<LZCityPortalSitePusherProviderService> logger,
-             LZCityPortalSiteClient dataExchangeClient,
+             LZCityPortalSiteClient lzCityPortalSiteClient,
             IRepository<DsWaitSendTaskOtherPlatforms> dsSendTaskRepository,
             ICapPublisher capPublisher,
             IRepository<DsSendTaskDetailInfo> dsSendTaskInfoRepository,
@@ -43,13 +55,14 @@ namespace DataSharing.LuZhou.LZCityPortal
             IChannelConfigurationManager channelConfigurationManager)
         {
             _logger = logger;
-            _dataExchangeClient = dataExchangeClient;
+            _lzCityPortalSiteClient = lzCityPortalSiteClient;
             _dsSendTaskRepository = dsSendTaskRepository;
             _capPublisher = capPublisher;
             _dsSendTaskInfoRepository = dsSendTaskInfoRepository;
             _dsUserTokenInfoRepository = dsUserTokenInfoRepository;
             _sendTaskOtherPlatformsRepository = sendTaskOtherPlatformsRepository;
             _channelConfigurationManager = channelConfigurationManager;
+            _client = new RestClient();
         }
 
         /// <summary>
@@ -75,7 +88,13 @@ namespace DataSharing.LuZhou.LZCityPortal
             string error = "";
             try
             {
-                response = await _dataExchangeClient.RequestAsync<CityPortalSiteResponseDto>(userInfo, baseAddress + dto.Path, dto.HttpMethod, dto.Request, cancellationToken);
+                var data = JsonConvert.SerializeObject(dto.Request);
+                ApiResponse apiResponse = await ExecuteAsync(baseAddress + dto.Path, Method.Post, dto.Request, cancellationToken);
+                if (apiResponse != null)
+                {
+                    response.code = apiResponse.Code;
+                    response.message = apiResponse.Message;
+                }
             }
             catch (Exception ex)
             {
@@ -96,7 +115,7 @@ namespace DataSharing.LuZhou.LZCityPortal
             {
                 #region 处理待推送数据,如果返回成功则直接删除数据,返回失败更新数据
                 //处理待推送数据,如果返回成功则直接删除数据,返回失败更新数据
-                if (response.code == "200")
+                if (response.code == 200)
                 {
                     await _dsSendTaskRepository.RemoveAsync(dto, cancellationToken: cancellationToken);
                 }
@@ -128,7 +147,7 @@ namespace DataSharing.LuZhou.LZCityPortal
 
                     if (data.FirstTime is null)
                         data.FirstTime = DateTime.Now;
-                    if (response.code == "1")
+                    if (response.code == 200)
                         data.IsSuccess = ESendTaskState.PushSuccess;
                     else
                         data.IsSuccess = ESendTaskState.PushFail;
@@ -138,5 +157,31 @@ namespace DataSharing.LuZhou.LZCityPortal
             }
             await _dsSendTaskInfoRepository.AddAsync(dsSendTaskInfo, cancellationToken);
         }
+
+        public async Task<ApiResponse> ExecuteAsync<TRequest>(string path, Method httpMethod, TRequest request,
+            CancellationToken cancellationToken)
+            where TRequest : class
+        {
+            var req = new RestRequest(path, httpMethod);
+            req.AddHeader("content-type", "application/json");
+            if (httpMethod is Method.Get)
+            {
+                req.AddObject(request);
+            }
+            else
+            {
+                req.AddJsonBody(request);
+            }
+
+            try
+            {
+                var response = await _client.ExecuteAsync<ApiResponse>(req, cancellationToken);
+                return response.Data;
+            }
+            catch (Exception e)
+            {
+                throw new HttpRequestException($"智能质检平台错误,Error: {e.Message}");
+            }
+        }
     }
 }

+ 26 - 26
src/DataSharing/SendTask/TaskOtherPlatformsJob.cs

@@ -65,33 +65,33 @@ namespace DataSharing.SendTask
             _logger.LogInformation("其他平台读取数据条数--------------------------------------" + tasks.Count);
             if (tasks.Count != 0)
             {
-                ////处理推送数据
-                //foreach (var sendTask in tasks)
-                //{
-                //    //状态更改为推送中
-                //    sendTask.State = EWaitSendTaskState.Pushing;
-                //    //使用乐观锁,控制数据
-                //    if (await _waitSendTaskOtherPlatformsRepository.Updateable(sendTask).ExecuteCommandWithOptLockAsync() > 0)
-                //    {
-                //        //如果是市州互转直接调用
-                //        if (sendTask.PlatformSource == Share.Enums.EPlatformSource.CityDataExchange)
-                //        {
-                //            await _dataExchangePusherProviderService.SendDataExchangeDataPusher(sendTask, context.CancellationToken);
-                //        } //如果是推随手拍天阙直接调用
-                //        //if (sendTask.PlatformSource == Share.Enums.EPlatformSource.TianQue)
-                //        //{
-                //        //    await _tianQuePusherProviderService.SendDataPusher(sendTask, context.CancellationToken);
-                //        //}
-                //        // 泸州市政府门户网站
-                //        else if (sendTask.PlatformSource == Share.Enums.EPlatformSource.LZCityPortalSite)
-                //        {
-                //            await _lzCityPortalSitePusherProviderService.SendDataOpinionDataPusher(sendTask, context.CancellationToken);
-                //        }
-                //        else
-                //            await _sendTaskDataService.SendTask(sendTask, context.CancellationToken);//其他推送
+                //处理推送数据
+                foreach (var sendTask in tasks)
+                {
+                    //状态更改为推送中
+                    sendTask.State = EWaitSendTaskState.Pushing;
+                    //使用乐观锁,控制数据
+                    if (await _waitSendTaskOtherPlatformsRepository.Updateable(sendTask).ExecuteCommandWithOptLockAsync() > 0)
+                    {
+                        //如果是市州互转直接调用
+                        if (sendTask.PlatformSource == Share.Enums.EPlatformSource.CityDataExchange)
+                        {
+                            await _dataExchangePusherProviderService.SendDataExchangeDataPusher(sendTask, context.CancellationToken);
+                        } //如果是推随手拍天阙直接调用
+                        //if (sendTask.PlatformSource == Share.Enums.EPlatformSource.TianQue)
+                        //{
+                        //    await _tianQuePusherProviderService.SendDataPusher(sendTask, context.CancellationToken);
+                        //}
+                        // 泸州市政府门户网站
+                        else if (sendTask.PlatformSource == Share.Enums.EPlatformSource.LZCityPortalSite)
+                        {
+                            await _lzCityPortalSitePusherProviderService.SendDataOpinionDataPusher(sendTask, context.CancellationToken);
+                        }
+                        else
+                            await _sendTaskDataService.SendTask(sendTask, context.CancellationToken);//其他推送
 
-                //    }
-                //}
+                    }
+                }
             }
         }