|
|
|
@ -21,6 +21,9 @@ using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using NLog;
|
|
|
|
|
using DS.Module.Core.Constants;
|
|
|
|
|
using DS.WMS.Core.Map.Dtos;
|
|
|
|
|
using DS.WMS.Core.Map.Interface;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Op.Method
|
|
|
|
|
{
|
|
|
|
@ -34,6 +37,7 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
private readonly ISeaExportCommonService seaComService;
|
|
|
|
|
private readonly IConfigService configService;
|
|
|
|
|
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
private readonly IMappingCarrierService _mappingCarrierService;
|
|
|
|
|
|
|
|
|
|
const string CONST_MAPPING_MODULE = "CARGOO_DATA";
|
|
|
|
|
|
|
|
|
@ -43,6 +47,7 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
seaComService = _serviceProvider.GetRequiredService<ISeaExportCommonService>();
|
|
|
|
|
configService = _serviceProvider.GetRequiredService<IConfigService>();
|
|
|
|
|
_mappingCarrierService = _serviceProvider.GetRequiredService<IMappingCarrierService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 发送Cargoo
|
|
|
|
@ -175,7 +180,23 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//起始港映射
|
|
|
|
|
//这里默认对应
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(order.MBLFrt))
|
|
|
|
|
{
|
|
|
|
|
if (order.MBLFrt.IndexOf("COLLECT") >= 0)
|
|
|
|
|
{
|
|
|
|
|
dto.incoterm = "CIF";
|
|
|
|
|
}
|
|
|
|
|
else if (order.MBLFrt.IndexOf("PREPAID") >= 0)
|
|
|
|
|
{
|
|
|
|
|
dto.incoterm = "FOB";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//默认整箱
|
|
|
|
|
dto.movementType = "FCL_FCL";
|
|
|
|
|
|
|
|
|
|
//起始港映射
|
|
|
|
|
var mapPortList = new List<MappingPort>();
|
|
|
|
|
|
|
|
|
|
var portList = new List<CodePort>();
|
|
|
|
@ -246,6 +267,22 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
if (order.CarrierId > 0)
|
|
|
|
|
{
|
|
|
|
|
var carrierRlt = GetCarrierEDICode(order.CarrierId);
|
|
|
|
|
|
|
|
|
|
if (carrierRlt.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
dto.carrierCode = carrierRlt.Data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<CodeCtn> codeCtnList = new List<CodeCtn>();
|
|
|
|
|
List<MappingCtn> mapCtnList = new List<MappingCtn>();
|
|
|
|
|
|
|
|
|
|
List<CodePackage> codePackageList = new List<CodePackage>();
|
|
|
|
|
List<MappingPackage> mapPackageList = new List<MappingPackage>();
|
|
|
|
|
|
|
|
|
|
if (ctnList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
dto.containerTypes = ctnList.GroupBy(a => a.CtnCode).Select(a =>
|
|
|
|
@ -257,6 +294,45 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
weight = a.Sum(b => b.WeightKGS.HasValue ? b.WeightKGS.Value : 0),
|
|
|
|
|
};
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var currCtn in dto.containerTypes)
|
|
|
|
|
{
|
|
|
|
|
var mapCtnRlt = GetCtnEDICode(currCtn.type, codeCtnList, mapCtnList, order.CarrierId, CONST_MAPPING_MODULE, "");
|
|
|
|
|
|
|
|
|
|
if (mapCtnRlt.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
currCtn.type = mapCtnRlt.Data;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return DataResult<CargooShipmentDto>.Failed($"箱型{currCtn.type} 的映射数据代码未找到");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string kindPkgs = string.Empty;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(order.KindPkgs))
|
|
|
|
|
{
|
|
|
|
|
long packageId = long.Parse(order.KindPkgs);
|
|
|
|
|
|
|
|
|
|
var portRlt = GetPackageEDICode(packageId, codePackageList, mapPackageList, order.CarrierId, CONST_MAPPING_MODULE);
|
|
|
|
|
|
|
|
|
|
if (codePackageList.Any(b => b.Id == packageId))
|
|
|
|
|
kindPkgs = codePackageList.FirstOrDefault(b => b.Id == packageId).PackageName;
|
|
|
|
|
|
|
|
|
|
if (portRlt.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
kindPkgs = portRlt.Data;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return DataResult<CargooShipmentDto>.Failed($"包装{order.KindPkgs}的映射数据代码未找到");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return DataResult<CargooShipmentDto>.Failed($"包装不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var shipCargo = new CargooShipmentItemDto
|
|
|
|
@ -264,7 +340,7 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
commodityCode = order.Description,
|
|
|
|
|
articleDescription = order.Description,
|
|
|
|
|
|
|
|
|
|
packageType = order.KindPkgs,
|
|
|
|
|
packageType = kindPkgs,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//件数
|
|
|
|
@ -416,5 +492,180 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
return DataResult<string>.FailedData(loadPortCodeRlt.Data?.EdiCode);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取船公司映射
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取船公司映射
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="carrierId">船公司ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private DataResult<string> GetCarrierEDICode(long carrierId)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var mapInfo = tenantDb.Queryable<MappingCarrier>()
|
|
|
|
|
.First(a => a.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && a.LinkId == carrierId);
|
|
|
|
|
|
|
|
|
|
if (mapInfo != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mapInfo.MapCode))
|
|
|
|
|
return DataResult<string>.Success(mapInfo.MapCode);
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.FailedData(mapInfo.MapCode);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var carrierRlt = seaComService.GetCarrierInfo(carrierId, tenantDb).GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
if(carrierRlt.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Success(carrierRlt.Data.EdiCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.FailedData("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 检索集装箱型EDI代码
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检索集装箱型EDI代码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ctnCode">集装箱型ID</param>
|
|
|
|
|
/// <param name="codeCtnList">集装箱基础表</param>
|
|
|
|
|
/// <param name="mapCtnList">集装箱映射表</param>
|
|
|
|
|
/// <param name="carrierId">船公司ID</param>
|
|
|
|
|
/// <param name="moduleName">模块代码</param>
|
|
|
|
|
/// <param name="ctnName">集装箱名称</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private DataResult<string> GetCtnEDICode(string ctnCode, List<CodeCtn> codeCtnList, List<MappingCtn> mapCtnList, long carrierId, string moduleName
|
|
|
|
|
, string ctnName)
|
|
|
|
|
{
|
|
|
|
|
CodeCtn codeCtnInfo = null;
|
|
|
|
|
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
if (codeCtnList.Any(a => a.EdiCode == ctnCode))
|
|
|
|
|
{
|
|
|
|
|
codeCtnInfo = codeCtnList.FirstOrDefault(a => a.EdiCode == ctnCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (codeCtnInfo == null)
|
|
|
|
|
{
|
|
|
|
|
codeCtnInfo = tenantDb.Queryable<CodeCtn>().First(a => a.EdiCode == ctnCode && a.Status == StatusEnum.Enable);
|
|
|
|
|
|
|
|
|
|
if (codeCtnInfo != null)
|
|
|
|
|
{
|
|
|
|
|
codeCtnList.Add(codeCtnInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"集装箱 {ctnName} 基础代码未找到");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果历史港口映射有记录直接返回
|
|
|
|
|
if (mapCtnList.Any(a => a.LinkId == codeCtnInfo.Id))
|
|
|
|
|
{
|
|
|
|
|
var edi = mapCtnList.FirstOrDefault(a => a.LinkId == codeCtnInfo.Id).MapCode;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(edi))
|
|
|
|
|
return DataResult<string>.Success(edi);
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.FailedData(edi);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MappingCtn mapCtnInfo = null;
|
|
|
|
|
|
|
|
|
|
mapCtnInfo = tenantDb.Queryable<MappingCtn>()
|
|
|
|
|
.First(a => a.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && a.CarrierId == carrierId && a.LinkId == codeCtnInfo.Id);
|
|
|
|
|
|
|
|
|
|
if (mapCtnInfo != null)
|
|
|
|
|
{
|
|
|
|
|
mapCtnList.Add(mapCtnInfo);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mapCtnInfo.MapCode))
|
|
|
|
|
return DataResult<string>.Success(mapCtnInfo.MapCode);
|
|
|
|
|
|
|
|
|
|
throw new Exception($"集装箱型 {ctnName}的映射代码未找到");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (codeCtnInfo != null && !string.IsNullOrWhiteSpace(codeCtnInfo.EdiCode))
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Success(codeCtnInfo.EdiCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Exception($"集装箱型 {ctnName}基础代码EDI 错误");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 检索包装EDI代码
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检索包装EDI代码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="packageCodeId">包装ID</param>
|
|
|
|
|
/// <param name="codePackageList">包装基础表</param>
|
|
|
|
|
/// <param name="mapPackageList">包装映射表</param>
|
|
|
|
|
/// <param name="carrierId">船公司ID</param>
|
|
|
|
|
/// <param name="moduleName">模块代码</param>
|
|
|
|
|
/// <param name="packageName">包装名称</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private DataResult<string> GetPackageEDICode(long packageCodeId, List<CodePackage> codePackageList, List<MappingPackage> mapPackageList, long carrierId, string moduleName)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
if (!codePackageList.Any(b => b.Id == packageCodeId))
|
|
|
|
|
{
|
|
|
|
|
var codePackage = tenantDb.Queryable<CodePackage>().First(a => a.Id == packageCodeId);
|
|
|
|
|
|
|
|
|
|
if (codePackage != null)
|
|
|
|
|
codePackageList.Add(codePackage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果历史港口映射有记录直接返回
|
|
|
|
|
if (mapPackageList.Any(a => a.LinkId == packageCodeId))
|
|
|
|
|
{
|
|
|
|
|
var edi = mapPackageList.FirstOrDefault(a => a.LinkId == packageCodeId).MapCode;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(edi))
|
|
|
|
|
return DataResult<string>.Success(edi);
|
|
|
|
|
|
|
|
|
|
//return DataResult<string>.FailedData(edi);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//优先判断跟船公司设置包装映射,如果没有取默认映射
|
|
|
|
|
var mapPackageInfo = tenantDb.Queryable<MappingPackage>()
|
|
|
|
|
.First(a => a.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && a.CarrierId == carrierId && a.LinkId == packageCodeId);
|
|
|
|
|
|
|
|
|
|
if (mapPackageInfo != null)
|
|
|
|
|
{
|
|
|
|
|
mapPackageList.Add(mapPackageInfo);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mapPackageInfo.MapCode))
|
|
|
|
|
return DataResult<string>.Success(mapPackageInfo.MapCode);
|
|
|
|
|
|
|
|
|
|
//return DataResult<string>.FailedData(mapPackageInfo.MapCode);
|
|
|
|
|
throw new Exception($"包装的映射代码未找到");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var codePackage = codePackageList.FirstOrDefault(b => b.Id == packageCodeId);
|
|
|
|
|
|
|
|
|
|
if (codePackage != null && !string.IsNullOrWhiteSpace(codePackage.EdiCode))
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Success(codePackage.EdiCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Exception($"包装的基础信息EDI代码未找到");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|