@ -35,6 +35,7 @@ using System.IO;
using System.Linq ;
using System.Net.Http ;
using System.Text ;
using System.Text.RegularExpressions ;
using System.Threading.Tasks ;
using Yitter.IdGenerator ;
@ -1572,6 +1573,176 @@ namespace Myshipping.Application
throw Oops . Bah ( string . Join ( "\r\n" , errList ) ) ;
}
}
else if ( carrierId = = "EMC" )
{
var data = MiniExcel . QueryAsDataTable ( ms ) ;
var colNames = new string [ ] { "EMC账号" , "EMC密码" , "POL" , "卸货港" , "交货地" , "运送方式" , "运送型态" , "SIZE" , "WEIGHT( 单箱) " , "description of goods" , "合约类型" , "合约号" , "运费付款方式" , "船名" , "航次" , "航线" , "ETD" , "联系人" , "联系电话" , "订舱确认邮箱" , "备注 (其它注意事项)" } ;
//DataRow drHead = data.Rows[0];
foreach ( var cn in colNames )
{
if ( ! data . Columns . Contains ( cn ) )
{
throw Oops . Bah ( $"文件格式有误,未找到列:{cn}" ) ;
}
}
var carrList = await _cache . GetAllCodeCarrier ( ) ;
var portLoadList = await _cache . GetAllCodePortLoad ( ) ;
var portDestList = await _cache . GetAllCodePort ( ) ;
var serviceList = await _cache . GetAllCodeService ( ) ;
var frtList = await _cache . GetAllCodeFrt ( ) ;
var ctnList = await _cache . GetAllCodeCtn ( ) ;
var errList = new List < string > ( ) ;
for ( var idx = 0 ; idx < data . Rows . Count ; idx + + )
{
var custOrder = new BookingCustomerOrder ( ) ;
custOrder . CARRIERID = carrierId ;
custOrder . CARRIER = carrierId ;
custOrder . CONTRACTNO = data . Rows [ idx ] [ "合约号" ] . ToString ( ) ;
custOrder . VESSEL = data . Rows [ idx ] [ "船名" ] . ToString ( ) ;
custOrder . VOYNO = data . Rows [ idx ] [ "航次" ] . ToString ( ) ;
custOrder . LANECODE = data . Rows [ idx ] [ "航线" ] . ToString ( ) ;
var strETD = data . Rows [ idx ] [ "ETD" ] . ToString ( ) ;
if ( Regex . IsMatch ( strETD , "^\\d+$" ) )
{
custOrder . ETD = DateTime . FromOADate ( Convert . ToDouble ( strETD ) ) ;
}
else
{
if ( DateTime . TryParse ( strETD , out DateTime etd ) )
{
custOrder . ETD = etd ;
}
else
{
errList . Add ( $"第{idx + 1}行, 未能识别ETD: {strETD}" ) ;
}
}
//var serCode = data.Rows[idx]["运送方式"].ToString();
//var service = serviceList.FirstOrDefault(x => x.Code == serCode);
//if (service == null)
//{
// errList.Add($"第{idx + 1}行,未找到运输条款:{serCode}");
//}
//else
//{
// custOrder.SERVICECODE = service.Code;
// custOrder.SERVICE = service.Name;
//}
var frtCode = data . Rows [ idx ] [ "运费付款方式" ] . ToString ( ) ;
var frt = frtList . FirstOrDefault ( x = > x . Code = = frtCode ) ;
if ( frt = = null )
{
errList . Add ( $"第{idx + 1}行,未找到付费方式:{frtCode}" ) ;
}
else
{
custOrder . FRTCODE = frt . Code ;
custOrder . BLFRT = frt . EnName ;
}
custOrder . DESCRIPTION = data . Rows [ idx ] [ "description of goods" ] . ToString ( ) ;
var portLoadCode = data . Rows [ idx ] [ "POL" ] . ToString ( ) ;
var portLoad = portLoadList . FirstOrDefault ( x = > x . Code = = portLoadCode ) ;
if ( portLoad = = null )
{
errList . Add ( $"第{idx + 1}行,未找到起运港:{portLoadCode}" ) ;
}
else
{
custOrder . PORTLOADID = portLoad . EdiCode ;
custOrder . PORTLOAD = portLoad . EnName ;
custOrder . PORTLOADCODE = portLoad . Code ;
}
var portCode = data . Rows [ idx ] [ "卸货港" ] . ToString ( ) ;
var portDest = portDestList . FirstOrDefault ( x = > x . Code = = portCode ) ;
if ( portLoad = = null )
{
errList . Add ( $"第{idx + 1}行,未找到卸货港:{portCode}" ) ;
}
else
{
custOrder . PORTDISCHARGEID = portLoad . EdiCode ;
custOrder . PORTDISCHARGE = portLoad . EnName ;
custOrder . PORTDISCHARGECODE = portLoad . Code ;
}
var destina = data . Rows [ idx ] [ "交货地" ] . ToString ( ) ;
var destinaFind = portDestList . FirstOrDefault ( x = > x . Code = = destina ) ;
if ( portLoad = = null )
{
errList . Add ( $"第{idx + 1}行,未找到交货地:{destina}" ) ;
}
else
{
custOrder . DESTINATIONID = portLoad . EdiCode ;
custOrder . DESTINATION = portLoad . EnName ;
custOrder . DESTINATIONCODE = portLoad . Code ;
}
//var cargoId = data.Rows[idx]["货物类型"].ToString();
//custOrder.CARGOID = cargoId.Substring(0, 1);
custOrder . SOREMARK = data . Rows [ idx ] [ "备注 (其它注意事项)" ] . ToString ( ) ;
//订舱账号、密码
var jobj = new JObject ( ) ;
jobj [ "Account" ] = data . Rows [ idx ] [ "EMC账号" ] . ToString ( ) ;
jobj [ "Password" ] = data . Rows [ idx ] [ "EMC密码" ] . ToString ( ) ;
jobj [ "OpMail" ] = data . Rows [ idx ] [ "订舱确认邮箱" ] . ToString ( ) ;
jobj [ "ContactName" ] = data . Rows [ idx ] [ "联系人" ] . ToString ( ) ;
jobj [ "ContactTel" ] = data . Rows [ idx ] [ "联系电话" ] . ToString ( ) ;
jobj [ "YSFS" ] = data . Rows [ idx ] [ "运送方式" ] . ToString ( ) ;
jobj [ "YSXT" ] = data . Rows [ idx ] [ "运送型态" ] . ToString ( ) ;
jobj [ "ContractType" ] = data . Rows [ idx ] [ "合约类型" ] . ToString ( ) ;
custOrder . ExtendData = jobj . ToJsonString ( ) ;
//箱信息
var ctnStr = data . Rows [ idx ] [ "SIZE" ] . ToString ( ) ;
var arrCtn = ctnStr . Split ( "*" . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) ;
var ctns = new List < BookingCtn > ( ) ;
if ( arrCtn . Length = = 2 )
{
var ctn = ctnList . FirstOrDefault ( x = > x . Code = = arrCtn [ 0 ] ) ;
if ( ctn = = null )
{
errList . Add ( $"第{idx + 1}行,未找到箱型:{arrCtn[0]}" ) ;
}
else if ( int . TryParse ( arrCtn [ 1 ] , out int num ) )
{
var ctnAdd = new BookingCtn ( )
{
CTNALL = ctn . Name ,
CTNNUM = num ,
CTNCODE = ctn . Code
} ;
ctns . Add ( ctnAdd ) ;
var ctnKGS = data . Rows [ idx ] [ "WEIGHT( 单箱) " ] . ToString ( ) ;
if ( decimal . TryParse ( ctnKGS , out decimal cw ) )
{
ctnAdd . KGS = cw ;
}
}
}
dicIns . Add ( custOrder , ctns ) ;
}
if ( errList . Count > 0 )
{
throw Oops . Bah ( string . Join ( "\r\n" , errList ) ) ;
}
}
else
{
throw Oops . Bah ( "当前不支持的该船司" ) ;