修改CARGOO

dev
jianghaiqing 1 month ago
parent adcf3336b6
commit 3f369cfa96

@ -115,6 +115,46 @@ public class RequestHelper
}
}
}
/// <summary>
/// http post请求
/// </summary>
/// <param name="url">地址</param>
/// <param name="parameter">入参</param>
/// <param name="headers">头信息</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
/// , string token ="", Dictionary<string, string> headers = null
public static async Task<string> PostAsyncWithHeaders(string url, string parameter,Dictionary<string,string> headers)
{
using (var client = new HttpClient())
{
//var data = new StringContent("param1=value1&param2=value2", Encoding.UTF8, "application/x-www-form-urlencoded");
var data = new StringContent(parameter, Encoding.UTF8, "application/json");
//_logger.LogWarning($"data:{data.ToJsonString()}parameter{parameter}");
// 添加header参数
//client.DefaultRequestHeaders.Add("Authorization", "Bearer your_token_here");
foreach (var header in headers)
{
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
//_logger.LogWarning($"header:{client.DefaultRequestHeaders.ToJsonString()}");
try
{
var response = await client.PostAsync(url, data);
//response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
return responseBody;
}
catch (HttpRequestException e)
{
throw new Exception(e.Message);
}
}
}
/// <summary>
/// http post请求
/// </summary>

@ -529,14 +529,14 @@ namespace DS.WMS.Core.Op.Dtos
/// <summary>
/// Cargoo Code (see appendix below)
/// </summary>
public int Code { get; set; }
public int code { get; set; }
/// <summary>
/// Description of the Status
/// </summary>
public string Description { get; set; }
public string description { get; set; }
/// <summary>
/// Date when the status changed
/// </summary>
public string Date { get; set; }
public string date { get; set; }
}
}

@ -24,6 +24,7 @@ using NLog;
using DS.Module.Core.Constants;
using DS.WMS.Core.Map.Dtos;
using DS.WMS.Core.Map.Interface;
using Org.BouncyCastle.Ocsp;
namespace DS.WMS.Core.Op.Method
{
@ -45,6 +46,9 @@ namespace DS.WMS.Core.Op.Method
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
seaComService = _serviceProvider.GetRequiredService<ISeaExportCommonService>();
configService = _serviceProvider.GetRequiredService<IConfigService>();
_mappingCarrierService = _serviceProvider.GetRequiredService<IMappingCarrierService>();
@ -58,6 +62,8 @@ namespace DS.WMS.Core.Op.Method
/// <returns>返回回执</returns>
public async Task<DataResult<CargooShipmentResultDto>> SendCargoo(CargooShipmentReqDto model)
{
Logger.Log(NLog.LogLevel.Info, $"请求Cargoo API推送消息接收请求{JsonConvert.SerializeObject(model)}");
if (model.bookingId <= 0)
return DataResult<CargooShipmentResultDto>.Failed("订单ID不能为空");
@ -72,50 +78,104 @@ namespace DS.WMS.Core.Op.Method
if (bookingInfo == null)
return DataResult<CargooShipmentResultDto>.Failed("订单信息获取失败订单ID错误或数据已作废");
var ctnList = tenantDb.Queryable<OpCtn>().Where(a => a.BSNO == model.bookingId.ToString()).ToList();
//生成报文
var shipDtoRlt = GetCargooShipment(model.cargooStatusEnum, bookingInfo, ctnList).GetAwaiter().GetResult();
if (!bookingInfo.SourceCode.Equals("FOB-WSL"))
{
return DataResult<CargooShipmentResultDto>.Failed("Cargoo只支持业务来源是WSL指定货");
}
if (!shipDtoRlt.Succeeded)
if (string.IsNullOrWhiteSpace(bookingInfo.MBLNO))
{
return DataResult<CargooShipmentResultDto>.Failed($"生成Cargoo报文失败原因{shipDtoRlt.Message}");
return DataResult<CargooShipmentResultDto>.Failed("提单号不能为空");
}
var queryInfo = shipDtoRlt.Data;
if (string.IsNullOrWhiteSpace(bookingInfo.CustomerNo))
{
return DataResult<CargooShipmentResultDto>.Failed("委托编号不能为空");
}
//发送报文至API接口
var queryUrl = configService.GetConfig("CargooAPI", long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value;
if (string.IsNullOrWhiteSpace(bookingInfo.ContractNo))
{
return DataResult<CargooShipmentResultDto>.Failed("约号不能为空");
}
CargooShipmentResultDto resultInfo = null;
var ctnList = tenantDb.Queryable<OpCtn>().Where(a => a.BSNO == model.bookingId.ToString()).ToList();
var jsonBody = Newtonsoft.Json.JsonConvert.SerializeObject(queryInfo, Formatting.Indented, new JsonSerializerSettings
try
{
NullValueHandling = NullValueHandling.Ignore
});
//生成报文
var shipDtoRlt = GetCargooShipment(model.cargooStatusEnum, bookingInfo, ctnList).GetAwaiter().GetResult();
var rlt = RequestHelper.Post(jsonBody, queryUrl);
if (!shipDtoRlt.Succeeded)
{
return DataResult<CargooShipmentResultDto>.Failed($"生成Cargoo报文失败原因{shipDtoRlt.Message}");
}
Logger.Log(NLog.LogLevel.Info, $"请求Cargoo API查询船期请求{jsonBody}");
var queryInfo = shipDtoRlt.Data;
if (!string.IsNullOrWhiteSpace(rlt))
{
try
//发送报文至API接口
var queryUrl = configService.GetConfig("CargooAPI", long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value;
var cargooKey = configService.GetConfig("CarooAPIKey", long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value;
CargooShipmentResultDto resultInfo = null;
var jsonBody = Newtonsoft.Json.JsonConvert.SerializeObject(queryInfo, Formatting.Indented, new JsonSerializerSettings
{
Logger.Log(NLog.LogLevel.Info, $"请求Cargoo API查询船期结果{rlt}");
NullValueHandling = NullValueHandling.Ignore
});
resultInfo = JsonConvert.DeserializeObject<CargooShipmentResultDto>(rlt);
}
catch (Exception ex)
//var rlt = RequestHelper.Post(jsonBody, queryUrl);
var rlt = await RequestHelper.PostAsyncWithHeaders(queryUrl, jsonBody, new Dictionary<string, string> { { "Authorization", cargooKey } });
Logger.Log(NLog.LogLevel.Info, $"请求Cargoo API推送消息{jsonBody}");
if (!string.IsNullOrWhiteSpace(rlt))
{
Logger.Log(NLog.LogLevel.Info, $"请求Cargoo API查询船期异常原因{ex.Message}");
try
{
Logger.Log(NLog.LogLevel.Info, $"请求Cargoo API推送消息结果{rlt}");
resultInfo = JsonConvert.DeserializeObject<CargooShipmentResultDto>(rlt);
}
catch (Exception ex)
{
Logger.Log(NLog.LogLevel.Info, $"请求Cargoo API推送消息异常原因{ex.Message}");
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.SpaceBookingAPISearchShipException)), ex.Message));
throw new Exception($"请求Cargoo API推送消息异常原因{ex.Message}");
}
}
if (resultInfo != null)
{
if (resultInfo.data.FirstOrDefault().code == 200)
{
// 记录日志
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = bookingInfo,
NewOrder = bookingInfo,
SourceCode = "SendCargoo",
SourceName = $"发送Cargoo {model.cargooStatusEnum.ToString()}",
}, tenantDb);
return DataResult<CargooShipmentResultDto>.Success("成功", resultInfo);
}
else
{
return DataResult<CargooShipmentResultDto>.FailedData(resultInfo);
}
}
}
catch (Exception ex)
{
Logger.Log(NLog.LogLevel.Info, $"请求Cargoo API推送消息异常 ALL原因{ex.Message}");
//记录返回结果
return DataResult<CargooShipmentResultDto>.Success("成功", null);
return DataResult<CargooShipmentResultDto>.Failed($"发送失败,原因:{ex.Message}");
}
return DataResult<CargooShipmentResultDto>.Failed("发送失败");
}
#endregion
@ -185,11 +245,11 @@ namespace DS.WMS.Core.Op.Method
{
if (order.MBLFrt.IndexOf("COLLECT") >= 0)
{
dto.incoterm = "CIF";
dto.incoterm = "FOB";
}
else if (order.MBLFrt.IndexOf("PREPAID") >= 0)
{
dto.incoterm = "FOB";
dto.incoterm = "CIF";
}
}
@ -291,7 +351,7 @@ namespace DS.WMS.Core.Op.Method
{
count = a.Sum(b => b.CtnNum.HasValue ? b.CtnNum.Value : 1),
type = a.Key,
weight = a.Sum(b => b.WeightKGS.HasValue ? b.WeightKGS.Value : 0),
weight = a.Sum(b => b.KGS.HasValue ? b.KGS.Value : 0),
};
}).ToList();
@ -386,7 +446,7 @@ namespace DS.WMS.Core.Op.Method
transportMean = new CargooShipmentTransportMeanDto {
name = order.Vessel
},
conveyanceReferenceNumber = $"{order.InnerVoyno}/{order.Voyno}"
conveyanceReferenceNumber = $"{order.InnerVoyno}"
});
dto.parties.Add(new CargooShipmentPartyDto {
@ -396,11 +456,11 @@ namespace DS.WMS.Core.Op.Method
dto.currentStatus = new CargooShipmentCurrentStatusDto
{
Code = (int)cargooStatusEnum,
Description = cargooStatusEnum.ToString()
code = (int)cargooStatusEnum,
description = cargooStatusEnum.ToString()
};
dto.integrationId = order.Id.ToString();
dto.integrationId = order.CustomerNo;
dto.contractNumber = order.ContractNo;
}
catch (Exception ex)
@ -578,7 +638,7 @@ namespace DS.WMS.Core.Op.Method
MappingCtn mapCtnInfo = null;
mapCtnInfo = tenantDb.Queryable<MappingCtn>()
.First(a => a.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && a.CarrierId == carrierId && a.LinkId == codeCtnInfo.Id);
.First(a => a.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && a.LinkId == codeCtnInfo.Id);
if (mapCtnInfo != null)
{

Loading…
Cancel
Save