订舱方法,新增VOLTA发送EDI

optimize
jianghaiqing 1 year ago
parent 4e263f0063
commit 91abf2969e

@ -16,6 +16,11 @@ namespace Myshipping.Application
/// </summary>
public string BookingId { get; set; }
/// <summary>
/// 订舱主键
/// </summary>
public long id { get; set; }
/// <summary>
/// 发货人名称(必填)
/// </summary>
@ -149,7 +154,7 @@ namespace Myshipping.Application
/// <summary>
/// 件数
/// </summary>
public Nullable<long> Qty { get; set; }
public Nullable<int> Qty { get; set; }
/// <summary>
/// 毛重
@ -175,5 +180,10 @@ namespace Myshipping.Application
/// 包装
/// </summary>
public string Pkgs { get; set; }
/// <summary>
/// EDI转换包装代码
/// </summary>
public string EdiPkgs { get; set; }
}
}

@ -43,6 +43,10 @@ namespace Myshipping.Application
/// <summary>
/// 玛丽亚娜
/// </summary>
MELL
MELL,
/// <summary>
/// 沃尔塔航运
/// </summary>
VOL
}
}

@ -138,6 +138,8 @@ namespace Myshipping.Application
const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING";
const string CONST_MAPPING_MODULE_ROUTE = "BOOK_OR_CLOSING_RT";
const string CONST_MAPPING_MODULE_VOLTA = "BOOK_CLOSING_VOLTA";
private const string PrintRecentListTypeKey = "booking_print_recent_list";
const string CONST_TSL_EDI_URL = "tsl_edi_declare_url";
@ -5788,6 +5790,10 @@ namespace Myshipping.Application
if (ediRouteEnum == EDIRouteEnum.NULL)
throw Oops.Bah($"当前船公司没有对应的请求路由配置");
//这里船公司VOL的单子不能走此通道发送
if(ediRouteEnum == EDIRouteEnum.VOL)
throw Oops.Bah($"当前船公司VOL不能执行标准发送");
//集装箱型
var ediCtnList = _cache.GetAllMappingCtn().GetAwaiter().GetResult()
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
@ -5798,8 +5804,6 @@ namespace Myshipping.Application
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)).ToList();
//包装基础数据
var basePkgsList = _cache.GetAllCodePackage().GetAwaiter().GetResult();
@ -9917,5 +9921,214 @@ namespace Myshipping.Application
#endregion
#region 检查是否VOLTA并返回初始数据
/// <summary>
/// 检查是否VOLTA并返回初始数据
/// </summary>
/// <param name="model">请求参数</param>
/// <returns>返回回执</returns>
[HttpPost("/BookingOrder/CheckAndInitVOLTAEdi")]
public dynamic CheckAndInitVOLTAEdi(BookingOrClosingEDIOrderDto model)
{
CommonWebApiResult result = new CommonWebApiResult();
/*
VOLTA
1
2VOL
3VOLFCSREL
*/
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no}获取请求VOLTA截单EDI {msg}", batchNo, JSON.Serialize(model));
if (!model.sendType.Equals("E", StringComparison.OrdinalIgnoreCase))
{
throw Oops.Bah("只接受发送类型截单E");
}
if (model.Id == 0)
throw Oops.Bah("订单Id不能为空");
var order = _rep.FirstOrDefault(a => a.Id == model.Id);
if (order == null)
throw Oops.Bah($"获取订单信息失败");
if (order.ParentId.HasValue && order.ParentId.Value > 0)
throw Oops.Bah($"获取当前订单为分单不能生成EDI信息");
_logger.LogInformation("批次={no}提取订单信息完成", batchNo);
if (!order.CARRIERID.Equals("VOL", StringComparison.OrdinalIgnoreCase))
{
throw Oops.Bah("当前订单的船公司不是VOL(沃尔塔航运)不能发送VOLTA截单EDI");
}
if(string.IsNullOrWhiteSpace(order.MBLNO))
throw Oops.Bah($"提单号不能为空");
if (!order.MBLNO.StartsWith("VOL") && !order.MBLNO.StartsWith("FCS") && !order.MBLNO.StartsWith("REL"))
{
throw Oops.Bah($"只支持提单号开头是VOL、FCS、REL发送截单");
}
//箱信息
var contaList = _repCtn.AsQueryable().Where(t => t.BILLID == order.Id).ToList();
VOLTAEDIBaseModel voltaModel = order.Adapt<VOLTAEDIBaseModel>();
#region 拆分收、发、通(名称、地址拆分)
if (!string.IsNullOrWhiteSpace(voltaModel.ShpperName))
{
string name = voltaModel.ShpperName;
voltaModel.ShpperName = GetShipCneeNotifyDetail(name);
voltaModel.ShpperAddr = GetShipCneeNotifyDetail(name, "addr");
}
if (!string.IsNullOrWhiteSpace(voltaModel.ConsigneeName))
{
string name = voltaModel.ConsigneeName;
voltaModel.ConsigneeName = GetShipCneeNotifyDetail(name);
voltaModel.ConsigneeAddr = GetShipCneeNotifyDetail(name, "addr");
}
if (!string.IsNullOrWhiteSpace(voltaModel.NotifyName))
{
string name = voltaModel.NotifyName;
voltaModel.NotifyName = GetShipCneeNotifyDetail(name);
voltaModel.NotifyAddr = GetShipCneeNotifyDetail(name, "addr");
}
#endregion
if (voltaModel != null)
voltaModel.ContaList = contaList.Adapt<List<VOLTAEDIContaModel>>();
//还需要翻译箱明细的包装
result.succ = true;
result.extra = voltaModel;
return result;
}
#endregion
#region 发送VOLTA截单请求
/// <summary>
/// 发送VOLTA截单请求
/// </summary>
/// <param name="model">请求截单详情</param>
/// <returns>返回回执</returns>
[HttpPost("/BookingOrder/SendVOLTAEdiSI")]
public async Task<dynamic> SendVOLTAEdiSI(VOLTAEDIBaseModel model)
{
CommonWebApiResult result = new CommonWebApiResult();
return result;
}
#endregion
#region 下载VOLTA截单请求报文
/// <summary>
/// 下载VOLTA截单请求报文
/// </summary>
/// <param name="model">请求截单详情</param>
/// <returns>返回回执</returns>
[HttpPost("/BookingOrder/DownloadVOLTAEdiSI")]
public async Task<IActionResult> DownloadVOLTAEdiSI(VOLTAEDIBaseModel model)
{
var filePath = InnerVOLTAEDI(model).GetAwaiter().GetResult();
var fileInfo = new FileInfo(filePath);
var result = new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileInfo.Name };
return result;
}
#endregion
#region 生成VOLTA报文内部方法
/// <summary>
/// 生成VOLTA报文内部方法
/// </summary>
/// <param name="model">请求截单详情</param>
/// <returns>返回回执</returns>
[NonAction]
public async Task<dynamic> InnerVOLTAEDI(VOLTAEDIBaseModel model)
{
CommonWebApiResult result = new CommonWebApiResult();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no}获取请求VOLTA截单EDI {msg}", batchNo, JSON.Serialize(model));
if (model.id == 0)
throw Oops.Bah("订单Id不能为空");
var order = _rep.FirstOrDefault(a => a.Id == model.id);
if (order == null)
throw Oops.Bah($"获取订单信息失败");
if (order.ParentId.HasValue && order.ParentId.Value > 0)
throw Oops.Bah($"获取当前订单为分单不能生成EDI信息");
_logger.LogInformation("批次={no}提取订单信息完成", batchNo);
//箱信息
var contaList = _repCtn.AsQueryable().Where(t => t.BILLID == order.Id).ToList();
EDIRouteEnum ediRouteEnum = GetEDIRoute(order.CARRIERID);
_logger.LogInformation("批次={no} 获取EDI路由完成 路由={route}", batchNo, ediRouteEnum.ToString());
if (ediRouteEnum == EDIRouteEnum.NULL)
throw Oops.Bah($"当前船公司没有对应的请求路由配置");
return result;
}
#endregion
#region 提取收、发、通详情
/// <summary>
/// 提取收、发、通详情
/// </summary>
/// <param name="name">收、发、通信息</param>
/// <param name="location">内容定位name-名称addr-地址)</param>
/// <returns>返回截取字符</returns>
public string GetShipCneeNotifyDetail(string name,string location = "name")
{
string result = string.Empty;
try
{
if (location == "name")
{
result = Regex.Match(name, ".*(?=\\n)").Value;
}
else if (location == "addr")
{
string s = Regex.Match(name, ".*(?=\\n)").Value;
result = name.Replace(s, "");
if(Regex.IsMatch(result,"^\\n"))
{
result = Regex.Replace(result, "^\\n", "");
}
//result = Regex.Match(name, $"(?<={s}).*").Value;
}
}
catch(Exception ex)
{
_logger.LogInformation($"{nameof(GetShipCneeNotifyDetail)} 提取收、发、通详情异常,原因:{ex.Message}");
}
return result;
}
#endregion
}
}

@ -0,0 +1,41 @@
using Mapster;
using Myshipping.Application.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
public class BookingEDIVOLTAMapper : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.ForType<BookingOrder, VOLTAEDIBaseModel>()
.Map(dest => dest.id, src => src.Id)
.Map(dest => dest.BookingId, src => src.MBLNO)
.Map(dest => dest.ShpperName, src => src.SHIPPER)
.Map(dest => dest.ConsigneeName, src => src.CONSIGNEE)
.Map(dest => dest.NotifyName, src => src.NOTIFYPARTY)
.Map(dest => dest.PlaceOfOrigin, src => src.PLACERECEIPT)
.Map(dest => dest.LoadPort, src => src.PORTLOAD)
.Map(dest => dest.DischargePort, src => src.PORTDISCHARGE)
.Map(dest => dest.FinalDestination, src => src.DESTINATION)
.Map(dest => dest.PlaceOfDelivery, src => src.PLACEDELIVERY)
.Map(dest => dest.CargoDescription, src => src.DESCRIPTION)
.Map(dest => dest.Marks, src => src.MARKS)
.Map(dest => dest.TotalGWt, src => src.KGS.HasValue ? src.KGS.Value : 0)
.Map(dest => dest.TotalCBM, src => src.CBM.HasValue ? src.CBM.Value : 0);
config.ForType<BookingCtn, VOLTAEDIContaModel>()
.Map(dest => dest.ContaNo, src => src.CNTRNO)
.Map(dest => dest.SealNo, src => src.SEALNO)
.Map(dest => dest.Qty, src => src.PKGS.HasValue ? src.PKGS.Value : 0)
.Map(dest => dest.GWt, src => src.KGS.HasValue ? src.KGS.Value : 0)
.Map(dest => dest.CBM, src => src.CBM.HasValue ? src.CBM.Value : 0)
.Map(dest => dest.Pkgs, src => src.KINDPKGS);
}
}
}

@ -108,5 +108,33 @@ namespace Myshipping.Application
/// <param name="isAutoSyncDS">是否默认同步东胜 true-自动同步 false-不自动同步</param>
/// <returns></returns>
Task SetBookingGoodsStatus(long bookingId, bool isAutoSyncDS = false);
/// <summary>
/// 检查是否VOLTA并返回初始数据
/// </summary>
/// <param name="model">请求参数</param>
/// <returns>返回回执</returns>
dynamic CheckAndInitVOLTAEdi(BookingOrClosingEDIOrderDto model);
/// <summary>
/// 发送VOLTA截单请求
/// </summary>
/// <param name="model">请求截单详情</param>
/// <returns>返回回执</returns>
Task<dynamic> SendVOLTAEdiSI(VOLTAEDIBaseModel model);
/// <summary>
/// 下载VOLTA截单请求报文
/// </summary>
/// <param name="model">请求截单详情</param>
/// <returns>返回回执</returns>
Task<IActionResult> DownloadVOLTAEdiSI(VOLTAEDIBaseModel model);
/// <summary>
/// 生成VOLTA报文内部方法
/// </summary>
/// <param name="model">请求截单详情</param>
/// <returns>返回回执</returns>
Task<dynamic> InnerVOLTAEDI(VOLTAEDIBaseModel model);
}
}
Loading…
Cancel
Save