|
@@ -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}");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|