|
|
|
@ -83,6 +83,7 @@ using Myshipping.Application.EDI.VOLTA;
|
|
|
|
|
using TinyPinyin;
|
|
|
|
|
using Furion.EventBus;
|
|
|
|
|
using Myshipping.Application.Service.BookingSlot.Dto;
|
|
|
|
|
using Myshipping.Application.Service.BookingOrder.Dto.MSKAPI;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
@ -5084,8 +5085,10 @@ namespace Myshipping.Application
|
|
|
|
|
/// <param name="bookingId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingOrder/VgmSend")]
|
|
|
|
|
public async Task VgmSend(long bookingId)
|
|
|
|
|
public async Task<object> VgmSend(long bookingId)
|
|
|
|
|
{
|
|
|
|
|
object result = null;
|
|
|
|
|
|
|
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
|
|
var ctns = _repCtn.Where(x => x.BILLID == bookingId).ToList();
|
|
|
|
|
|
|
|
|
@ -5101,14 +5104,150 @@ namespace Myshipping.Application
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK127);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var config = _cache.GetAllTenantParam().Result.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "VgmDirectSendCarrierId");
|
|
|
|
|
/* 1. 先通过 租户参数里的 支持API发送的船司列表 判断是否走API发送
|
|
|
|
|
* 2. 如果不走API,再通过 租户参数里的 直发船司列表 判断走爬虫直发或大简云发送
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var tenantParamList = _cache.GetAllTenantParam().Result;
|
|
|
|
|
|
|
|
|
|
var vgmApiSendCarrierIdStr = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "VgmApiSendCarrierId");
|
|
|
|
|
|
|
|
|
|
string[] vgmApiSendCarrierIdArr = vgmApiSendCarrierIdStr == null
|
|
|
|
|
? new string[0]
|
|
|
|
|
: vgmApiSendCarrierIdStr.ItemCode.Split(",");
|
|
|
|
|
|
|
|
|
|
// VGM发送方式1:通过API发送
|
|
|
|
|
if (vgmApiSendCarrierIdArr.Contains(order.CARRIERID))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!order.CARRIERID.Equals("MSK", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah($"[{order.CARRIERID}]船公司暂不支持通过API发送VGM");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//config1
|
|
|
|
|
string userKey = App.Configuration["MSKAPIDjyUserKey"];
|
|
|
|
|
string userSecret = App.Configuration["MSKAPIDjyUserSecret"];
|
|
|
|
|
string env = App.Configuration["MSKAPIOPEnvironment"];
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(userKey) || string.IsNullOrWhiteSpace(userSecret) || string.IsNullOrWhiteSpace(env))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("通过MSKAPI发送VGM所需的Key或Secret或Environment未配置,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// config2
|
|
|
|
|
var webAccount = await _webAccountConfig.GetAccountConfig("MSKApi", UserManager.UserId) ?? throw Oops.Bah("未配置网站账户,类型:MSKApi");
|
|
|
|
|
|
|
|
|
|
// config3
|
|
|
|
|
var allSysConfig = await _cache.GetAllSysConfig();
|
|
|
|
|
var url = allSysConfig.FirstOrDefault(x => x.Code == "VgmSendMskApiUrl")?.Value;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("通过MSKAPI发送VGM所需的Url未配置,请联系管理员,配置名称:[VgmSendMskApiUrl]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// config4
|
|
|
|
|
var vgmSendMskCustomerCode = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "VgmSendMskCustomerCode")?.ItemCode;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(vgmSendMskCustomerCode))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("通过MSKAPI发送VGM所需的[客户编号],请联系管理员,配置名称:[VgmSendMskCustomerCode]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var param = new
|
|
|
|
|
{
|
|
|
|
|
userKey,
|
|
|
|
|
userSecret,
|
|
|
|
|
operatingEnvironment = env,
|
|
|
|
|
mskAppKey = webAccount.Account,
|
|
|
|
|
mskAppSecret = webAccount.Password,
|
|
|
|
|
shipmentNumber = order.MBLNO,
|
|
|
|
|
brandCode = "MAEU",
|
|
|
|
|
customerCode = vgmSendMskCustomerCode,
|
|
|
|
|
terminalCode = "",
|
|
|
|
|
containerList = new List<object>()
|
|
|
|
|
};
|
|
|
|
|
foreach (var ctn in ctns)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(ctn.CNTRNO)
|
|
|
|
|
|| !ctn.WEIGHKGS.HasValue
|
|
|
|
|
|| ctn.WEIGHKGS == 0
|
|
|
|
|
|| string.IsNullOrWhiteSpace(ctn.WEIGHTYPE))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("所有箱子的箱号、称重重量、称重方式都不能为空");
|
|
|
|
|
}
|
|
|
|
|
var vgmMethod = ctn.WEIGHTYPE switch
|
|
|
|
|
{
|
|
|
|
|
"累加" => "CALCULATED",
|
|
|
|
|
"总重" => "SCALED",
|
|
|
|
|
_ => throw Oops.Bah($"箱号为[{ctn.CNTRNO}]的箱子称重方式非[累加]或[总重],请检查")
|
|
|
|
|
};
|
|
|
|
|
param.containerList.Add(new
|
|
|
|
|
{
|
|
|
|
|
containerNumber = ctn.CNTRNO,
|
|
|
|
|
vgmSource = "Shipper",
|
|
|
|
|
vgm = ctn.WEIGHKGS,
|
|
|
|
|
vgmUnit = "KGS",
|
|
|
|
|
vgmMethod,
|
|
|
|
|
authorizedPersonName = UserManager.Name,
|
|
|
|
|
authorizedPersonEmail = UserManager.Email
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("通过MSKAPI发送VGM,单号:{mblno},入参:{param}", order.MBLNO, param.ToJson());
|
|
|
|
|
var resp = await url.SetBody(param).PostAsAsync<MSKAPISendVgmResultDto>();
|
|
|
|
|
_logger.LogInformation("通过MSKAPI发送VGM,单号:{mblno},响应:{resp}", order.MBLNO, resp.ToJson());
|
|
|
|
|
|
|
|
|
|
if (resp.code == 200)
|
|
|
|
|
{
|
|
|
|
|
if (resp.data.Any(x => !x.status))
|
|
|
|
|
{
|
|
|
|
|
result = resp.data.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
CNTRNO = x.containerNumber,
|
|
|
|
|
IsSuccess = x.status,
|
|
|
|
|
FailReason = x.error_msg
|
|
|
|
|
}).ToList();
|
|
|
|
|
_logger.LogInformation("通过MSKAPI发送VGM,部分成功,单号:{mblno},详细结果:{data}", order.MBLNO, result.ToJson());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("通过MSKAPI发送VGM,全部成功,单号:{mblno},详细结果:{data}", order.MBLNO, result.ToJson());
|
|
|
|
|
|
|
|
|
|
//货运动态
|
|
|
|
|
var bsl = new BookingStatusLog();
|
|
|
|
|
bsl.BookingId = order.Id;
|
|
|
|
|
bsl.Status = $"直发VGM(API)";
|
|
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
|
|
bsl.Category = "ship";
|
|
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
|
|
await _repStatuslog.InsertAsync(bsl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("通过MSKAPI发送VGM,VGM服务接口返回失败结果,单号:{mblno}", order.MBLNO);
|
|
|
|
|
throw Oops.Bah($"VGM服务接口返回失败结果:{resp.msg}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "通过MSKAPI发送VGM时发生未知异常,单号:{mblno}", order.MBLNO);
|
|
|
|
|
throw Oops.Bah($"发送失败:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var config = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "VgmDirectSendCarrierId");
|
|
|
|
|
if (config == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("请配置租户的VGM直发船司参数");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var arrCarr = config.ItemCode.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
if (!arrCarr.Contains(order.CARRIERID)) //使用大简云发送vgm
|
|
|
|
|
// VGM发送方式2:使用大简云发送vgm
|
|
|
|
|
if (!arrCarr.Contains(order.CARRIERID))
|
|
|
|
|
{
|
|
|
|
|
//ETD不能为空
|
|
|
|
|
if (!order.ETD.HasValue)
|
|
|
|
@ -5199,7 +5338,8 @@ namespace Myshipping.Application
|
|
|
|
|
throw Oops.Bah(jobjRtn.GetStringValue("Message"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else //直接调用vgm接口直发
|
|
|
|
|
// VGM发送方式3:直接调用vgm接口直发
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//判断船公司是否支持
|
|
|
|
|
var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList();
|
|
|
|
@ -5359,10 +5499,13 @@ namespace Myshipping.Application
|
|
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
|
|
await _repStatuslog.InsertAsync(bsl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//设置货物状态:已发VGM,并回传东胜
|
|
|
|
|
await SetGoodsStatus("YFVGM", bookingId);
|
|
|
|
|
await SendBookingOrder(new long[] { bookingId });
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|