|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
using Furion;
|
|
|
|
|
using Furion.Logging;
|
|
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Entity;
|
|
|
|
@ -8,6 +10,7 @@ using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application.EDI
|
|
|
|
@ -42,16 +45,35 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sysConfigList = await cache.GetAllSysConfig();
|
|
|
|
|
var sCfgSpiderUrl = sysConfigList.FirstOrDefault(x => x.Code == "ZhongYuanApiSpiderUrl" && x.GroupCode == "DJY_CONST");
|
|
|
|
|
if (sCfgSpiderUrl == null)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "中远订舱API的爬虫URL地址未配置,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sCfgUserKey = sysConfigList.FirstOrDefault(x => x.Code == "ZhongYuanApiSpiderKey" && x.GroupCode == "DJY_CONST");
|
|
|
|
|
var sCfgUserSecret = sysConfigList.FirstOrDefault(x => x.Code == "ZhongYuanApiSpiderSecret" && x.GroupCode == "DJY_CONST");
|
|
|
|
|
if (sCfgUserKey == null || sCfgUserSecret == null)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "中远订舱API的KEY和密钥为配置,请联系管理员");
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "中远订舱API的KEY和密钥未配置,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BookingSoTemplate template = null;
|
|
|
|
|
DjyCustomerContact custContact = null;
|
|
|
|
|
var postModel = new ZhongYuanSoApiModel();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(custOrder.ExtendData))
|
|
|
|
|
{
|
|
|
|
|
var extObj = JObject.Parse(custOrder.ExtendData);
|
|
|
|
|
postModel.webAccount = extObj.GetStringValue("Account");
|
|
|
|
|
postModel.webPassword = extObj.GetStringValue("Password");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "未找到订舱账号信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查找模板:
|
|
|
|
|
//1.根据客户订舱信息中的BookingUserId和BookingTenantId,去客户信息中根据CustSysId查找客户(公司)及联系人(员工)信息
|
|
|
|
|
//2.根据找到的客户及联系人信息,查找中远订舱模板
|
|
|
|
@ -67,32 +89,26 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "未找到客户及联系人信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template = await repTemplate.AsQueryable().FirstAsync(x => x.CarrierId == custOrder.CARRIERID && x.UserId == custContact.Id && x.IsEnable);
|
|
|
|
|
//根据:用户+船司+船司账号+约号,找到启用的模板
|
|
|
|
|
template = await repTemplate.AsQueryable().FirstAsync(x => x.CarrierId == custOrder.CARRIERID && x.UserId == custContact.Id && x.ContractNO == custOrder.CONTRACTNO && x.BookingAccount == postModel.webAccount && x.IsEnable);
|
|
|
|
|
if (template == null)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "未找到订舱模板");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "未找到客户端公司和用户ID");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mappingCtn = await cache.GetAllMappingCtn();
|
|
|
|
|
var mappingFrt = await cache.GetAllMappingFrt();
|
|
|
|
|
var mappingPortLoad = await cache.GetAllMappingPortLoad();
|
|
|
|
|
var mappingPort = await cache.GetAllMappingPort();
|
|
|
|
|
|
|
|
|
|
var postModel = new ZhongYuanSoApiModel();
|
|
|
|
|
postModel.userKey = sCfgUserKey.Value;
|
|
|
|
|
postModel.userSecret = sCfgUserSecret.Value;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(custOrder.ExtendData))
|
|
|
|
|
{
|
|
|
|
|
var extObj = JObject.Parse(custOrder.ExtendData);
|
|
|
|
|
postModel.webAccount = extObj.GetStringValue("Account");
|
|
|
|
|
postModel.webPassword = extObj.GetStringValue("Password");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "未找到订舱账号信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
postModel.uploadType = template.Category; //DRAFT, TEMPLATE, BOOKING分别对应:草稿, 模板, 订舱
|
|
|
|
|
postModel.saveName = template.TemplateName;
|
|
|
|
@ -109,6 +125,21 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"未找到目的港映射信息:{custOrder.PORTDISCHARGECODE}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//运输条款
|
|
|
|
|
var mappingService = await cacheService.GetAllMappingService();
|
|
|
|
|
var mappService = mappingService.FirstOrDefault(x => x.Module == "DjyCustBooking" && x.CarrierCode == "COSCO" && x.Code == custOrder.SERVICE);
|
|
|
|
|
if (mappService == null)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"未找到运输条款映射信息:{custOrder.SERVICE}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Regex.IsMatch(mappService.MapCode, "^[A-Za-z]+-[A-Za-z]+$"))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"映射配置不正确:{mappService.MapCode}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mapServArr = mappService.MapCode.Split('-');
|
|
|
|
|
|
|
|
|
|
postModel.routes = new ZhongYuanSoApiRoute()
|
|
|
|
|
{
|
|
|
|
|
originCity = mapPortLoad.MapCode,
|
|
|
|
@ -117,9 +148,37 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
voyageNumber = custOrder.VOYNO,
|
|
|
|
|
serviceCode = custOrder.LANECODE,
|
|
|
|
|
sailSchedulePriority = template.Priority.Split(',').ToList(),
|
|
|
|
|
outboundHaulage = mapServArr[0],
|
|
|
|
|
inboundHaulage = mapServArr[1],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#region 收发通及货代
|
|
|
|
|
//发货人
|
|
|
|
|
ZhongYuanSoApiPhone shipperPhone = null;
|
|
|
|
|
if (string.IsNullOrEmpty(template.ShipperName))
|
|
|
|
|
{
|
|
|
|
|
shipperPhone = new ZhongYuanSoApiPhone()
|
|
|
|
|
{
|
|
|
|
|
countryCode = custOrder.ShipperPhoneCountryCode,
|
|
|
|
|
areaCode = custOrder.ShipperPhoneCode,
|
|
|
|
|
number = custOrder.ShipperPhone
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shipperPhone = new ZhongYuanSoApiPhone()
|
|
|
|
|
{
|
|
|
|
|
countryCode = template.ShipperPhoneCountryCode,
|
|
|
|
|
areaCode = template.ShipperPhoneCode,
|
|
|
|
|
number = template.ShipperPhone
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shipperPhone.countryCode = shipperPhone.countryCode == null ? "" : shipperPhone.countryCode;
|
|
|
|
|
shipperPhone.areaCode = shipperPhone.areaCode == null ? "" : shipperPhone.areaCode;
|
|
|
|
|
shipperPhone.number = shipperPhone.number == null ? "" : shipperPhone.number;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
postModel.shipperInfo = new ZhongYuanSoApiSFT()
|
|
|
|
|
{
|
|
|
|
|
firstName = string.IsNullOrEmpty(template.ShipperName) ? custOrder.ShipperFirstName : template.ShipperFirstName,
|
|
|
|
@ -129,10 +188,35 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
city = string.IsNullOrEmpty(template.ShipperCity) ? custOrder.ShipperCity : template.ShipperCity,
|
|
|
|
|
partyName = string.IsNullOrEmpty(template.ShipperName) ? custOrder.ShipperName : template.ShipperName,
|
|
|
|
|
addressDes = string.IsNullOrEmpty(template.ShipperAddress) ? custOrder.ShipperAddress : template.ShipperAddress,
|
|
|
|
|
phone = string.IsNullOrEmpty(template.ShipperName) ? new ZhongYuanSoApiPhone() { countryCode = custOrder.ShipperPhoneCountryCode, areaCode = custOrder.ShipperPhoneCode, number = custOrder.ShipperPhone } : new ZhongYuanSoApiPhone() { countryCode = template.ShipperPhoneCountryCode, areaCode = template.ShipperPhoneCode, number = template.ShipperPhone },
|
|
|
|
|
phone = shipperPhone,
|
|
|
|
|
postalCode = string.IsNullOrEmpty(template.ShipperPostCode) ? custOrder.ShipperPostCode : template.ShipperPostCode
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//收货人
|
|
|
|
|
ZhongYuanSoApiPhone consigneePhone = null;
|
|
|
|
|
if (string.IsNullOrEmpty(template.ConsigneeName))
|
|
|
|
|
{
|
|
|
|
|
consigneePhone = new ZhongYuanSoApiPhone()
|
|
|
|
|
{
|
|
|
|
|
countryCode = custOrder.ConsigneePhoneCountryCode,
|
|
|
|
|
areaCode = custOrder.ConsigneePhoneCode,
|
|
|
|
|
number = custOrder.ConsigneePhone
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
consigneePhone = new ZhongYuanSoApiPhone()
|
|
|
|
|
{
|
|
|
|
|
countryCode = template.ConsigneePhoneCountryCode,
|
|
|
|
|
areaCode = template.ConsigneePhoneCode,
|
|
|
|
|
number = template.ConsigneePhone
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
consigneePhone.countryCode = consigneePhone.countryCode == null ? "" : consigneePhone.countryCode;
|
|
|
|
|
consigneePhone.areaCode = consigneePhone.areaCode == null ? "" : consigneePhone.areaCode;
|
|
|
|
|
consigneePhone.number = consigneePhone.number == null ? "" : consigneePhone.number;
|
|
|
|
|
|
|
|
|
|
postModel.consigneeInfo = new ZhongYuanSoApiSFT()
|
|
|
|
|
{
|
|
|
|
|
firstName = string.IsNullOrEmpty(template.ConsigneeFirstName) ? custOrder.ConsigneeFirstName : template.ConsigneeFirstName,
|
|
|
|
@ -142,10 +226,35 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
city = string.IsNullOrEmpty(template.ConsigneeCity) ? custOrder.ConsigneeCity : template.ConsigneeCity,
|
|
|
|
|
partyName = string.IsNullOrEmpty(template.ConsigneeName) ? custOrder.ConsigneeName : template.ConsigneeName,
|
|
|
|
|
addressDes = string.IsNullOrEmpty(template.ConsigneeAddress) ? custOrder.ConsigneeAddress : template.ConsigneeAddress,
|
|
|
|
|
phone = string.IsNullOrEmpty(template.ConsigneeName) ? new ZhongYuanSoApiPhone() { countryCode = custOrder.ConsigneePhoneCountryCode, areaCode = custOrder.ConsigneePhoneCode, number = custOrder.ConsigneePhone } : new ZhongYuanSoApiPhone() { countryCode = template.ConsigneePhoneCountryCode, areaCode = template.ConsigneePhoneCode, number = template.ConsigneePhone },
|
|
|
|
|
phone = consigneePhone,
|
|
|
|
|
postalCode = string.IsNullOrEmpty(template.ConsigneePostCode) ? custOrder.ConsigneePostCode : template.ConsigneePostCode
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//通知人
|
|
|
|
|
ZhongYuanSoApiPhone notifyPhone = null;
|
|
|
|
|
if (string.IsNullOrEmpty(template.NotifypartName))
|
|
|
|
|
{
|
|
|
|
|
notifyPhone = new ZhongYuanSoApiPhone()
|
|
|
|
|
{
|
|
|
|
|
countryCode = custOrder.NotifypartPhoneCountryCode,
|
|
|
|
|
areaCode = custOrder.NotifypartPhoneCode,
|
|
|
|
|
number = custOrder.NotifypartPhone
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
notifyPhone = new ZhongYuanSoApiPhone()
|
|
|
|
|
{
|
|
|
|
|
countryCode = template.NotifypartPhoneCountryCode,
|
|
|
|
|
areaCode = template.NotifypartPhoneCode,
|
|
|
|
|
number = template.NotifypartPhone
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notifyPhone.countryCode = notifyPhone.countryCode == null ? "" : notifyPhone.countryCode;
|
|
|
|
|
notifyPhone.areaCode = notifyPhone.areaCode == null ? "" : notifyPhone.areaCode;
|
|
|
|
|
notifyPhone.number = notifyPhone.number == null ? "" : notifyPhone.number;
|
|
|
|
|
|
|
|
|
|
postModel.notifyInfo = new ZhongYuanSoApiSFT()
|
|
|
|
|
{
|
|
|
|
|
firstName = string.IsNullOrEmpty(template.NotifypartFirstName) ? custOrder.NotifypartFirstName : template.NotifypartFirstName,
|
|
|
|
@ -155,10 +264,36 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
city = string.IsNullOrEmpty(template.NotifypartCity) ? custOrder.NotifypartCity : template.NotifypartCity,
|
|
|
|
|
partyName = string.IsNullOrEmpty(template.NotifypartName) ? custOrder.NotifypartName : template.NotifypartName,
|
|
|
|
|
addressDes = string.IsNullOrEmpty(template.NotifypartAddress) ? custOrder.NotifypartAddress : template.NotifypartAddress,
|
|
|
|
|
phone = string.IsNullOrEmpty(template.NotifypartName) ? new ZhongYuanSoApiPhone() { countryCode = custOrder.NotifypartPhoneCountryCode, areaCode = custOrder.NotifypartPhoneCode, number = custOrder.NotifypartPhone } : new ZhongYuanSoApiPhone() { countryCode = template.NotifypartPhoneCountryCode, areaCode = template.NotifypartPhoneCode, number = template.NotifypartPhone },
|
|
|
|
|
phone = notifyPhone,
|
|
|
|
|
postalCode = string.IsNullOrEmpty(template.NotifypartPostCode) ? custOrder.NotifypartPostCode : template.NotifypartPostCode
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//货代
|
|
|
|
|
ZhongYuanSoApiPhone forwarderPhone = null;
|
|
|
|
|
if (string.IsNullOrEmpty(template.BookingName))
|
|
|
|
|
{
|
|
|
|
|
forwarderPhone = new ZhongYuanSoApiPhone()
|
|
|
|
|
{
|
|
|
|
|
countryCode = custOrder.BookingPhoneCountryCode,
|
|
|
|
|
areaCode = custOrder.BookingPhoneCode,
|
|
|
|
|
number = custOrder.BookingPhone
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
forwarderPhone = new ZhongYuanSoApiPhone()
|
|
|
|
|
{
|
|
|
|
|
countryCode = template.BookingPhoneCountryCode,
|
|
|
|
|
areaCode = template.BookingPhoneCode,
|
|
|
|
|
number = template.BookingPhone
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forwarderPhone.countryCode = forwarderPhone.countryCode == null ? "" : forwarderPhone.countryCode;
|
|
|
|
|
forwarderPhone.areaCode = forwarderPhone.areaCode == null ? "" : forwarderPhone.areaCode;
|
|
|
|
|
forwarderPhone.number = forwarderPhone.number == null ? "" : forwarderPhone.number;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
postModel.forwarderInfo = new ZhongYuanSoApiSFT()
|
|
|
|
|
{
|
|
|
|
|
firstName = string.IsNullOrEmpty(template.BookingFirstName) ? custOrder.BookingFirstName : template.BookingFirstName,
|
|
|
|
@ -168,7 +303,7 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
city = string.IsNullOrEmpty(template.BookingCity) ? custOrder.BookingCity : template.BookingCity,
|
|
|
|
|
partyName = string.IsNullOrEmpty(template.BookingName) ? custOrder.BookingName : template.BookingName,
|
|
|
|
|
addressDes = string.IsNullOrEmpty(template.BookingAddress) ? custOrder.BookingAddress : template.BookingAddress,
|
|
|
|
|
phone = string.IsNullOrEmpty(template.BookingName) ? new ZhongYuanSoApiPhone() { countryCode = custOrder.BookingPhoneCountryCode, areaCode = custOrder.BookingPhoneCode, number = custOrder.BookingPhone } : new ZhongYuanSoApiPhone() { countryCode = template.BookingPhoneCountryCode, areaCode = template.BookingPhoneCode, number = template.BookingPhone },
|
|
|
|
|
phone = forwarderPhone,
|
|
|
|
|
postalCode = string.IsNullOrEmpty(template.BookingPostCode) ? custOrder.BookingPostCode : template.BookingPostCode
|
|
|
|
|
};
|
|
|
|
|
#endregion
|
|
|
|
@ -218,13 +353,38 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
paymentMethod = mapFrt.MapCode
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//大简云客户订舱接收BC邮箱
|
|
|
|
|
var djyBookMail = sysConfigList.FirstOrDefault(x => x.Code == "DjyCustomerBookReceiveBcMail");
|
|
|
|
|
var bcMail = custContact.Email;
|
|
|
|
|
if (djyBookMail != null)
|
|
|
|
|
{
|
|
|
|
|
bcMail += djyBookMail.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
postModel.special = new ZhongYuanSoApiSpecial()
|
|
|
|
|
{
|
|
|
|
|
emailAddresses = custContact.Email,
|
|
|
|
|
emailAddresses = bcMail,
|
|
|
|
|
remarksForEntireBooking = custOrder.SOREMARK
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>();
|
|
|
|
|
Log.Information($"发送API数据给爬虫({sCfgSpiderUrl.Value}):{postModel.ToJsonString()}");
|
|
|
|
|
var rtn = await sCfgSpiderUrl.Value.SetBody(postModel)
|
|
|
|
|
.PostAsStringAsync();
|
|
|
|
|
|
|
|
|
|
Log.Information($"爬虫返回:{rtn}");
|
|
|
|
|
var jobjRtn = JObject.Parse(rtn);
|
|
|
|
|
if (jobjRtn.GetIntValue("code") == 200)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(true, "发送成功");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, jobjRtn.GetStringValue("msg"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -372,6 +532,16 @@ namespace Myshipping.Application.EDI
|
|
|
|
|
/// 船期选择优先级
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<string> sailSchedulePriority { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 出发地运输条款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string outboundHaulage { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 目的地运输条款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string inboundHaulage { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|