You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
7.0 KiB
C#
185 lines
7.0 KiB
C#
using Furion;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DistributedIDGenerator;
|
|
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Furion.JsonSerialization;
|
|
using Furion.RemoteRequest.Extensions;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Myshipping.Core;
|
|
using Myshipping.Core.Service;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Reflection.Emit;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace Myshipping.Application
|
|
{
|
|
/// <summary>
|
|
/// 内嵌运踪港后数据查询
|
|
/// </summary>
|
|
[AllowAnonymous, ApiDescriptionSettings("Application", Name = "EmbedTraceProduct", Order = 20)]
|
|
public class EmbedTraceProductService : IEmbedTraceProductService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ILogger<EmbedTraceProductService> _logger;
|
|
private const string CONST_TRACE_API_URL = "embed_trace_flow_url";
|
|
private readonly ISysCacheService _cache;
|
|
private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="logger"></param>
|
|
public EmbedTraceProductService(ILogger<EmbedTraceProductService> logger, ISysCacheService cache, IDjyWebsiteAccountConfigService webAccountConfig)
|
|
{
|
|
_logger = logger;
|
|
_cache = cache;
|
|
_webAccountConfig = webAccountConfig;
|
|
}
|
|
|
|
#region 获取单票运踪流程详情
|
|
/// <summary>
|
|
/// 获取单票运踪流程详情
|
|
/// </summary>
|
|
/// <param name="model">查询单票运踪流程详情</param>
|
|
/// <returns>返回回执</returns>
|
|
[AllowAnonymous, HttpPost("/EmbedTraceProduct/GetTraceFlowInfo"), ApiUser(ApiCode = "EmbedServiceTraceShow")]
|
|
public async Task<QueryTraceAfterPortResultDataDto> GetTraceFlowInfo(EmbedQueryTraceFlowDto model)
|
|
{
|
|
/*
|
|
1、调取运踪接口。 embed_trace_flow_url
|
|
2、根据返回结果组织暂时的JSON结果。
|
|
3、返回结果
|
|
|
|
*/
|
|
QueryTraceAfterPortResultDataDto result = null;
|
|
|
|
string batchNo = IDGen.NextID().ToString();
|
|
|
|
string sendUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
|
|
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == CONST_TRACE_API_URL)?.Value;
|
|
|
|
if (string.IsNullOrWhiteSpace(sendUrl))
|
|
throw Oops.Oh("未配置发送订舱请求接口地址,请联系管理员");
|
|
|
|
var webAccountConfig = _webAccountConfig
|
|
.GetAccountConfigByTenantId("seae_billtraceurl", UserManager.UserId, UserManager.TENANT_ID).GetAwaiter().GetResult();
|
|
|
|
if (webAccountConfig == null)
|
|
throw Oops.Oh("未配置账户,请先配置公司或者个人账户 类型-运踪新增调用");
|
|
|
|
QueryTraceAfterPortDto queryDto = new QueryTraceAfterPortDto
|
|
{
|
|
user_key = webAccountConfig.Account,
|
|
user_secret = webAccountConfig.Password,
|
|
carriercd = model.carrier,
|
|
referenceno = model.billNo,
|
|
ctnrno = model.ctnNo
|
|
};
|
|
|
|
var queryRlt = await QueryTraceAsync(queryDto, sendUrl);
|
|
|
|
var statusDict = _cache.GetAllDictData().GetAwaiter().GetResult()
|
|
.Where(t => t.TypeCode.Equals("after_port_trace_ctn_status", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
if(queryRlt.code == 200)
|
|
{
|
|
result = queryRlt.data.FirstOrDefault();
|
|
|
|
if (result != null && result.resultData != null)
|
|
{
|
|
if (result.resultData.containerInfoList != null && result.resultData.containerInfoList.Count > 0)
|
|
{
|
|
result.resultData.containerInfoList.ForEach(s =>
|
|
{
|
|
if(s.containerStatusInfoList != null && s.containerStatusInfoList.Count > 0)
|
|
{
|
|
s.containerStatusInfoList = s.containerStatusInfoList.Select((a, idx) =>
|
|
{
|
|
a.sortNo = idx + 1;
|
|
return a;
|
|
}).ToList();
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 获取单票运踪流程纵向详情
|
|
/// <summary>
|
|
/// 获取单票运踪流程纵向详情
|
|
/// </summary>
|
|
/// <param name="model">查询单票运踪流程详情</param>
|
|
/// <returns>返回回执</returns>
|
|
[AllowAnonymous, HttpPost("/EmbedTraceProduct/GetTraceVerticalInfo"), ApiUser(ApiCode = "EmbedServiceTraceShow")]
|
|
public async Task<QueryTraceAfterPortResultDataDto> GetTraceVerticalInfo(EmbedQueryTraceFlowDto model)
|
|
{
|
|
/*
|
|
1、调取运踪接口。 embed_trace_flow_url
|
|
2、根据返回结果组织暂时的JSON结果。
|
|
3、返回结果
|
|
|
|
*/
|
|
QueryTraceAfterPortResultDataDto result = null;
|
|
|
|
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 查询运踪
|
|
/// <summary>
|
|
/// 查询运踪
|
|
/// </summary>
|
|
/// <param name="query">查询参数</param>
|
|
/// <param name="url">请求URL</param>
|
|
/// <returns></returns>
|
|
public async Task<QueryTraceAfterPortResultDto> QueryTraceAsync(QueryTraceAfterPortDto query,string url)
|
|
{
|
|
QueryTraceAfterPortResultDto model = null;
|
|
|
|
try
|
|
{
|
|
|
|
var res = await url.OnClientCreating(client => {
|
|
// client 为 HttpClient 对象
|
|
client.Timeout = TimeSpan.FromMinutes(15); // 设置超时时间 15分钟
|
|
}).SetHttpMethod(HttpMethod.Post)
|
|
.SetBody(JSON.Serialize(query), "application/json")
|
|
.SetContentEncoding(Encoding.UTF8)
|
|
.PostAsync();
|
|
|
|
_logger.LogInformation("单号={no} 对应请求报文完成 post={post} res={res}", query.referenceno, JSON.Serialize(query), JSON.Serialize(res));
|
|
|
|
if (res.StatusCode == System.Net.HttpStatusCode.OK)
|
|
{
|
|
var userResult = await res.Content.ReadAsStringAsync();
|
|
|
|
model = JSON.Deserialize<QueryTraceAfterPortResultDto>(userResult);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogInformation($"请求运踪查询异常,原因:{ex.Message}");
|
|
|
|
throw Oops.Oh($"请求运踪查询异常,原因:{ex.Message}");
|
|
}
|
|
|
|
return model;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|