jianghaiqing 8 months ago
commit c97b247aed

@ -1,7 +1,9 @@
using Furion;
using Myshipping.Application.Entity;
using Myshipping.Core;
using Myshipping.Core.Entity;
using Myshipping.Core.Service;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@ -20,21 +22,239 @@ namespace Myshipping.Application.EDI
var repCustOrder = App.GetService<SqlSugarRepository<BookingCustomerOrder>>();
var repOrder = App.GetService<SqlSugarRepository<BookingOrder>>();
var repCtn = App.GetService<SqlSugarRepository<BookingCtn>>();
var repCustomer = App.GetService<SqlSugarRepository<DjyCustomer>>();
var repContact = App.GetService<SqlSugarRepository<DjyCustomerContact>>();
var repTemplate = App.GetService<SqlSugarRepository<BookingSoTemplate>>();
var cache = App.GetService<ISysCacheService>();
var cacheService = App.GetService<ISysCacheService>();
var order = repOrder.FirstOrDefault(o => o.Id == bookingId);
var order = await repOrder.AsQueryable().Filter(null, true).FirstAsync(o => o.Id == bookingId);
if (order == null)
{
return new KeyValuePair<bool, string>(false, "订舱信息未找到");
}
var custOrder = await repCustOrder.AsQueryable().Filter(null, true).FirstAsync(x => x.BookingId == order.Id);
if (custOrder == null)
{
return new KeyValuePair<bool, string>(false, "客户订舱信息未找到");
}
var sysConfigList = await cache.GetAllSysConfig();
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和密钥为配置请联系管理员");
}
BookingSoTemplate template = null;
DjyCustomerContact custContact = null;
//查找模板:
//1.根据客户订舱信息中的BookingUserId和BookingTenantId去客户信息中根据CustSysId查找客户公司及联系人员工信息
//2.根据找到的客户及联系人信息,查找中远订舱模板
if (custOrder.BookingUserId > 0 && custOrder.BookingTenantId > 0)
{
custContact = await repCustomer.AsQueryable()
.InnerJoin<DjyCustomerContact>((cust, contact) => cust.Id == contact.CustomerId)
.Where((cust, contact) => cust.CustSysId == custOrder.TenantId && contact.CustSysId == custOrder.BookingUserId)
.Select((cust, contact) => contact)
.SingleAsync();
if (custContact == null)
{
return new KeyValuePair<bool, string>(false, "未找到客户及联系人信息");
}
template = await repTemplate.AsQueryable().FirstAsync(x => x.CarrierId == order.CARRIERID && x.UserId == custContact.Id && x.IsEnable);
if (template == null)
{
return new KeyValuePair<bool, string>(false, "未找到订舱模板");
}
}
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 = "DRAFT"; //DRAFT, TEMPLATE, BOOKING分别对应草稿, 模板, 订舱
postModel.saveName = template.TemplateName;
var mapPortLoad = mappingPortLoad.FirstOrDefault(x => x.Module == "DjyCustBooking" && x.CarrierCode == "COSCO" && x.Code == custOrder.PORTLOADCODE);
var mapPort = mappingPort.FirstOrDefault(x => x.Module == "DjyCustBooking" && x.CarrierCode == "COSCO" && x.Code == custOrder.PORTDISCHARGECODE);
if (mapPortLoad == null)
{
return new KeyValuePair<bool, string>(false, $"未找到起运港映射信息:{custOrder.PORTLOADCODE}");
}
if (mapPort == null)
{
return new KeyValuePair<bool, string>(false, $"未找到目的港映射信息:{custOrder.PORTDISCHARGECODE}");
}
postModel.routes = new ZhongYuanSoApiRoute()
{
originCity = mapPortLoad.MapCode,
destinationCity = mapPort.MapCode,
vesselName = custOrder.VESSEL,
voyageNumber = custOrder.VOYNO,
serviceCode = custOrder.LANECODE,
sailSchedulePriority = template.Priority.Split(',').ToList(),
};
#region 收发通及货代
postModel.shipperInfo = new ZhongYuanSoApiSFT()
{
firstName = template.ShipperFirstName,
lastName = template.ShipperLastName,
country = template.ShipperCountry,
state = template.ShipperProvince,
city = template.ShipperCity,
partyName = template.ShipperName,
addressDes = template.ShipperAddress,
phone = new ZhongYuanSoApiPhone() { countryCode = template.ShipperPhoneCountryCode, areaCode = template.ShipperPhoneCode, number = template.ShipperPhone },
postalCode = template.ShipperPostCode
};
postModel.consigneeInfo = new ZhongYuanSoApiSFT()
{
firstName = template.ConsigneeFirstName,
lastName = template.ConsigneeLastName,
country = template.ConsigneeCountry,
state = template.ConsigneeProvince,
city = template.ConsigneeCity,
partyName = template.ConsigneeName,
addressDes = template.ConsigneeAddress,
phone = new ZhongYuanSoApiPhone() { countryCode = template.ConsigneePhoneCountryCode, areaCode = template.ConsigneePhoneCode, number = template.ConsigneePhone },
postalCode = template.ConsigneePostCode
};
postModel.notifyInfo = new ZhongYuanSoApiSFT()
{
firstName = template.NotifypartFirstName,
lastName = template.NotifypartLastName,
country = template.NotifypartCountry,
state = template.NotifypartProvince,
city = template.NotifypartCity,
partyName = template.NotifypartName,
addressDes = template.NotifypartAddress,
phone = new ZhongYuanSoApiPhone() { countryCode = template.NotifypartPhoneCountryCode, areaCode = template.NotifypartPhoneCode, number = template.NotifypartPhone },
postalCode = template.NotifypartPostCode
};
postModel.forwarderInfo = new ZhongYuanSoApiSFT()
{
firstName = template.BookingFirstName,
lastName = template.BookingLastName,
country = template.BookingCountry,
state = template.BookingProvince,
city = template.BookingCity,
partyName = template.BookingName,
addressDes = template.BookingAddress,
phone = new ZhongYuanSoApiPhone() { countryCode = template.BookingPhoneCountryCode, areaCode = template.BookingPhoneCode, number = template.BookingPhone },
postalCode = template.BookingPostCode
};
#endregion
postModel.cargoInfo = new ZhongYuanSoApiCargoInfo()
{
cargoName = CargoIdZhongyuan(custOrder.CARGOID),
cargoDes = custOrder.DESCRIPTION,
hsCode = custOrder.HSCODE,
};
var ctns = await repCtn.AsQueryable().Where(x => x.BILLID == custOrder.Id).ToListAsync();
postModel.boxInfos = new List<ZhongYuanSoApiBoxInfo>();
foreach (var ctn in ctns)
{
if (!ctn.CTNNUM.HasValue || !ctn.KGS.HasValue)
{
return new KeyValuePair<bool, string>(false, $"所有箱的箱量和毛重都不能为空");
}
var mapCtn = mappingCtn.FirstOrDefault(x => x.Module == "DjyCustBooking" && x.CarrierCode == "COSCO" && x.Code == ctn.CTNCODE);
if (mapCtn == null)
{
return new KeyValuePair<bool, string>(false, $"未找箱型映射信息:{ctn.CTNCODE}");
}
var apiBox = new ZhongYuanSoApiBoxInfo()
{
boxType = mapCtn.MapCode,
boxNum = ctn.CTNNUM.Value,
weight = ctn.KGS.Value.ToString(),
weightUnit = "KGS"
};
postModel.boxInfos.Add(apiBox);
}
var mapFrt = mappingFrt.FirstOrDefault(x => x.Module == "DjyCustBooking" && x.CarrierCode == "COSCO" && x.Code == custOrder.FRTCODE);
if (mapFrt == null)
{
return new KeyValuePair<bool, string>(false, $"未找到付款方式映射信息:{custOrder.FRTCODE}");
}
postModel.rateInfos = new ZhongYuanSoApiRateInfo()
{
paymentMethod = mapFrt.MapCode
};
postModel.special = new ZhongYuanSoApiSpecial()
{
emailAddresses = custContact.Email,
remarksForEntireBooking = custOrder.SOREMARK
};
return new KeyValuePair<bool, string>();
}
/// <summary>
/// 获取中远货物类型
/// </summary>
/// <param name="cargoId"></param>
/// <returns></returns>
private static string CargoIdZhongyuan(string cargoId)
{
if (cargoId is "S")
{
return "General";
}
else if (cargoId is "R")
{
return "Reefer";
}
else if (cargoId is "D")
{
return "Dangerous";
}
return null;
}
}
/// <summary>
/// 中远API订舱传输对象
/// </summary>
public class ZhongYuanSoApiModel
{
/// <summary>
@ -80,24 +300,47 @@ namespace Myshipping.Application.EDI
/// <summary>
/// 发货人信息
/// </summary>
public string shipperInfo { get; set; }
public ZhongYuanSoApiSFT shipperInfo { get; set; }
/// <summary>
/// 收货人信息
/// </summary>
public string consigneeInfo { get; set; }
public ZhongYuanSoApiSFT consigneeInfo { get; set; }
/// <summary>
/// 通知人信息
/// </summary>
public string notifyInfo { get; set; }
public ZhongYuanSoApiSFT notifyInfo { get; set; }
/// <summary>
/// 货代信息
/// </summary>
public string forwarderInfo { get; set; }
public ZhongYuanSoApiSFT forwarderInfo { get; set; }
/// <summary>
/// 货物信息
/// </summary>
public ZhongYuanSoApiCargoInfo cargoInfo { get; set; }
/// <summary>
/// 箱信息
/// </summary>
public List<ZhongYuanSoApiBoxInfo> boxInfos { get; set; }
/// <summary>
/// 费率相关信息
/// </summary>
public ZhongYuanSoApiRateInfo rateInfos { get; set; }
/// <summary>
/// 特殊要求及备注
/// </summary>
public ZhongYuanSoApiSpecial special { get; set; }
}
/// <summary>
/// 路线信息
/// </summary>
public class ZhongYuanSoApiRoute
{
/// <summary>
@ -124,8 +367,16 @@ namespace Myshipping.Application.EDI
/// 航线代码
/// </summary>
public string serviceCode { get; set; }
/// <summary>
/// 船期选择优先级
/// </summary>
public List<string> sailSchedulePriority { get; set; }
}
/// <summary>
/// 收发通信息
/// </summary>
public class ZhongYuanSoApiSFT
{
/// <summary>
@ -179,9 +430,11 @@ namespace Myshipping.Application.EDI
public ZhongYuanSoApiPhone phone { get; set; }
}
/// <summary>
/// 收发通电话
/// </summary>
public class ZhongYuanSoApiPhone
{
/// <summary>
/// 国家代码
/// </summary>
@ -197,4 +450,79 @@ namespace Myshipping.Application.EDI
/// </summary>
public string number { get; set; }
}
/// <summary>
/// 货物信息
/// </summary>
public class ZhongYuanSoApiCargoInfo
{
/// <summary>
/// 货物类型
/// </summary>
public string cargoName { get; set; }
/// <summary>
/// 货物描述
/// </summary>
public string cargoDes { get; set; }
/// <summary>
/// HS代码
/// </summary>
public string hsCode { get; set; }
}
/// <summary>
/// 箱信息
/// </summary>
public class ZhongYuanSoApiBoxInfo
{
/// <summary>
/// 箱量
/// </summary>
public int boxNum { get; set; }
/// <summary>
/// 箱型
/// </summary>
public string boxType { get; set; }
/// <summary>
/// 毛重
/// </summary>
public string weight { get; set; }
/// <summary>
/// 重量单位
/// </summary>
public string weightUnit { get; set; }
}
public class ZhongYuanSoApiRateInfo
{
/// <summary>
/// 付款方式
/// </summary>
public string paymentMethod { get; set; }
}
/// <summary>
/// 特殊要求及备注
/// </summary>
public class ZhongYuanSoApiSpecial
{
/// <summary>
/// 备注信息
/// </summary>
public string remarksForEntireBooking { get; set; }
/// <summary>
/// 邮箱地址
/// </summary>
public string emailAddresses { get; set; }
}
}

@ -9239,11 +9239,15 @@ namespace Myshipping.Application
var ctnList = await _cache.GetAllCodeCtn();
var mapCtn = await _cache.GetAllMappingCtn();
var packageList = await _cache.GetAllCodePackage();
var mapPackageList = await _cache.GetAllMappingPackage();
var listRtn = JsonConvert.DeserializeObject<List<BookingGetYardDataDto>>(rtn.data);
var contact = JsonConvert.DeserializeObject<List<YardContactDto>>(rtn.contact)?.FirstOrDefault();
foreach (var item in listRtn)
{
// 箱型
var ctnall = item.CTNALL;
var findMap = mapCtn.FirstOrDefault(x => x.Module == "YardData" && x.MapCode == ctnall);
var findCtn = ctnList.FirstOrDefault(x => x.Name == ctnall);
@ -9264,14 +9268,28 @@ namespace Myshipping.Application
throw Oops.Bah($"未找到箱型{ctnall}的场站引入配置");
}
// 包装
if (!string.IsNullOrWhiteSpace(item.KINDPKGS))
{
var findMapPkg = mapPackageList.FirstOrDefault(x => x.Module == "YardData" && x.MapCode == item.KINDPKGS.Trim());
if (findMapPkg != null)
{
var findPkg = packageList.FirstOrDefault(x => x.Code == findMapPkg.Code);
if (findPkg != null)
{
item.KINDPKGS = findPkg.Name;
}
}
}
// 赋值联系人信息
item.contact_tel = contact?.contact_tel1;
item.contact_tel = contact?.contact_tel1?.Trim();
if (!string.IsNullOrWhiteSpace(contact?.contact_tel2))
{
item.contact_tel += (" " + contact.contact_tel2);
item.contact_tel += " " + contact.contact_tel2.Trim();
}
item.contact_name = contact?.contact_name;
item.contact_email = contact?.contact_email;
item.contact_name = contact?.contact_name?.Trim();
item.contact_email = contact?.contact_email?.Trim();
}
return listRtn;
@ -12457,5 +12475,23 @@ namespace Myshipping.Application
return result;
}
#endregion
#region 发送订舱
/// <summary>
/// 发送Api订舱目前只有中远
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("/BookingOrder/PostApiSO")]
public async Task PostApiSO(long id)
{
var rtn = await ZhongYuanSoApiHelper.DoPost(id);
if (!rtn.Key)
{
throw Oops.Bah(rtn.Value);
}
}
#endregion
}
}

@ -152,5 +152,15 @@ namespace Myshipping.Core.Entity
/// 等级
/// </summary>
public string Level { get; set; }
/// <summary>
/// 客户端系统ID
/// </summary>
public long CustSysId { get; set; }
/// <summary>
/// 大简云GID
/// </summary>
public string DjyGid { get; set; }
}
}

@ -47,5 +47,15 @@ namespace Myshipping.Core.Entity
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 客户端系统ID
/// </summary>
public long CustSysId { get; set; }
/// <summary>
/// 大简云GID
/// </summary>
public string DjyGid { get; set; }
}
}

@ -12802,6 +12802,11 @@
列表输出
</summary>
</member>
<member name="P:Myshipping.Core.Service.DjyTenantParamValueListOutput.Id">
<summary>
id
</summary>
</member>
<member name="P:Myshipping.Core.Service.DjyTenantParamValueListOutput.ParaCode">
<summary>
参数类别

@ -13,6 +13,11 @@
/// </summary>
public class DjyTenantParamValueListOutput
{
/// <summary>
/// id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 参数类别
/// </summary>

Loading…
Cancel
Save