diff --git a/Myshipping.Application/EDI/ZhongYuanSoApiHelper.cs b/Myshipping.Application/EDI/ZhongYuanSoApiHelper.cs index f249bb88..bc63c1c1 100644 --- a/Myshipping.Application/EDI/ZhongYuanSoApiHelper.cs +++ b/Myshipping.Application/EDI/ZhongYuanSoApiHelper.cs @@ -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>(); var repOrder = App.GetService>(); var repCtn = App.GetService>(); + var repCustomer = App.GetService>(); + var repContact = App.GetService>(); + var repTemplate = App.GetService>(); + var cache = App.GetService(); var cacheService = App.GetService(); - 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(false, "订舱信息未找到"); } + var custOrder = await repCustOrder.AsQueryable().Filter(null, true).FirstAsync(x => x.BookingId == order.Id); + if (custOrder == null) + { + return new KeyValuePair(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(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((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(false, "未找到客户及联系人信息"); + } + + template = await repTemplate.AsQueryable().FirstAsync(x => x.CarrierId == order.CARRIERID && x.UserId == custContact.Id && x.IsEnable); + if (template == null) + { + return new KeyValuePair(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(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(false, $"未找到起运港映射信息:{custOrder.PORTLOADCODE}"); + } + + if (mapPort == null) + { + return new KeyValuePair(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(); + foreach (var ctn in ctns) + { + if (!ctn.CTNNUM.HasValue || !ctn.KGS.HasValue) + { + return new KeyValuePair(false, $"所有箱的箱量和毛重都不能为空"); + } + + var mapCtn = mappingCtn.FirstOrDefault(x => x.Module == "DjyCustBooking" && x.CarrierCode == "COSCO" && x.Code == ctn.CTNCODE); + if (mapCtn == null) + { + return new KeyValuePair(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(false, $"未找到付款方式映射信息:{custOrder.FRTCODE}"); + } + + postModel.rateInfos = new ZhongYuanSoApiRateInfo() + { + paymentMethod = mapFrt.MapCode + }; + postModel.special = new ZhongYuanSoApiSpecial() + { + emailAddresses = custContact.Email, + remarksForEntireBooking = custOrder.SOREMARK + }; return new KeyValuePair(); } + + /// + /// 获取中远货物类型 + /// + /// + /// + 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; + } } + + /// + /// 中远API订舱传输对象 + /// public class ZhongYuanSoApiModel { /// @@ -50,7 +270,7 @@ namespace Myshipping.Application.EDI /// /// 网站账户 /// - public string webAccount { get; set; } + public string webAccount { get; set; } /// /// 网站密码 @@ -80,30 +300,53 @@ namespace Myshipping.Application.EDI /// /// 发货人信息 /// - public string shipperInfo { get; set; } + public ZhongYuanSoApiSFT shipperInfo { get; set; } /// /// 收货人信息 /// - public string consigneeInfo { get; set; } + public ZhongYuanSoApiSFT consigneeInfo { get; set; } /// /// 通知人信息 /// - public string notifyInfo { get; set; } + public ZhongYuanSoApiSFT notifyInfo { get; set; } /// /// 货代信息 /// - public string forwarderInfo { get; set; } + public ZhongYuanSoApiSFT forwarderInfo { get; set; } + + /// + /// 货物信息 + /// + public ZhongYuanSoApiCargoInfo cargoInfo { get; set; } + + /// + /// 箱信息 + /// + public List boxInfos { get; set; } + + /// + /// 费率相关信息 + /// + public ZhongYuanSoApiRateInfo rateInfos { get; set; } + + /// + /// 特殊要求及备注 + /// + public ZhongYuanSoApiSpecial special { get; set; } } + /// + /// 路线信息 + /// public class ZhongYuanSoApiRoute { /// /// 出发城市 /// - public string originCity { get; set; } + public string originCity { get; set; } /// /// 目的城市 @@ -124,8 +367,16 @@ namespace Myshipping.Application.EDI /// 航线代码 /// public string serviceCode { get; set; } + + /// + /// 船期选择优先级 + /// + public List sailSchedulePriority { get; set; } } + /// + /// 收发通信息 + /// public class ZhongYuanSoApiSFT { /// @@ -179,9 +430,11 @@ namespace Myshipping.Application.EDI public ZhongYuanSoApiPhone phone { get; set; } } + /// + /// 收发通电话 + /// public class ZhongYuanSoApiPhone { - /// /// 国家代码 /// @@ -197,4 +450,79 @@ namespace Myshipping.Application.EDI /// public string number { get; set; } } + + /// + /// 货物信息 + /// + public class ZhongYuanSoApiCargoInfo + { + /// + /// 货物类型 + /// + public string cargoName { get; set; } + + /// + /// 货物描述 + /// + public string cargoDes { get; set; } + + /// + /// HS代码 + /// + public string hsCode { get; set; } + + } + + /// + /// 箱信息 + /// + public class ZhongYuanSoApiBoxInfo + { + /// + /// 箱量 + /// + public int boxNum { get; set; } + + /// + /// 箱型 + /// + public string boxType { get; set; } + + /// + /// 毛重 + /// + public string weight { get; set; } + + /// + /// 重量单位 + /// + public string weightUnit { get; set; } + + } + + public class ZhongYuanSoApiRateInfo + { + /// + /// 付款方式 + /// + public string paymentMethod { get; set; } + + } + + /// + /// 特殊要求及备注 + /// + public class ZhongYuanSoApiSpecial + { + /// + /// 备注信息 + /// + public string remarksForEntireBooking { get; set; } + + + /// + /// 邮箱地址 + /// + public string emailAddresses { get; set; } + } } diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index d13a3cd8..1e9e952d 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -12490,5 +12490,23 @@ namespace Myshipping.Application return result; } #endregion + + #region 发送订舱 + + /// + /// 发送Api订舱,目前只有中远 + /// + /// + /// + [HttpPost("/BookingOrder/PostApiSO")] + public async Task PostApiSO(long id) + { + var rtn = await ZhongYuanSoApiHelper.DoPost(id); + if (!rtn.Key) + { + throw Oops.Bah(rtn.Value); + } + } + #endregion } } diff --git a/Myshipping.Core/Const/CommonConst.cs b/Myshipping.Core/Const/CommonConst.cs index 3aa0d089..124126a8 100644 --- a/Myshipping.Core/Const/CommonConst.cs +++ b/Myshipping.Core/Const/CommonConst.cs @@ -206,6 +206,11 @@ public class CommonConst /// 省份信息 /// public const string CACHE_KEY_COMMON_DB_PROVINCE = "CommonDbCodeProvince"; + + /// + /// 起运港与船代的关系 + /// + public const string CACHE_KEY_COMMON_DB_RELA_PORTLOAD_FORWARDER = "CommonDbRelaPortLoadForwarder"; #endregion public const string API_USER_HEADER_KEY = "USER_KEY"; diff --git a/Myshipping.Core/Entity/CommonDB/RelaPortLoadForwarder.cs b/Myshipping.Core/Entity/CommonDB/RelaPortLoadForwarder.cs new file mode 100644 index 00000000..02939270 --- /dev/null +++ b/Myshipping.Core/Entity/CommonDB/RelaPortLoadForwarder.cs @@ -0,0 +1,35 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Core.Entity +{ + [SugarTable("RelaPortLoadForwarder")] + [Description("起运港和船代的关系表")] + public class RelaPortLoadForwarder : CommonDbEntity + { + /// + /// 起运港代码 + /// + public string PortLoadCode { get; set; } + + /// + /// 船代代码 + /// + public string ForwarderCode { get; set; } + + /// + /// 模块(公用时为空字符串) + /// + public string Module { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + } +} diff --git a/Myshipping.Core/Entity/DJY/DjyCustomer.cs b/Myshipping.Core/Entity/DJY/DjyCustomer.cs index 87e66363..df42ab4c 100644 --- a/Myshipping.Core/Entity/DJY/DjyCustomer.cs +++ b/Myshipping.Core/Entity/DJY/DjyCustomer.cs @@ -152,5 +152,15 @@ namespace Myshipping.Core.Entity /// 等级 /// public string Level { get; set; } + + /// + /// 客户端系统ID + /// + public long CustSysId { get; set; } + + /// + /// 大简云GID + /// + public string DjyGid { get; set; } } } \ No newline at end of file diff --git a/Myshipping.Core/Entity/DJY/DjyCustomerContact.cs b/Myshipping.Core/Entity/DJY/DjyCustomerContact.cs index 06d73bad..73881f8a 100644 --- a/Myshipping.Core/Entity/DJY/DjyCustomerContact.cs +++ b/Myshipping.Core/Entity/DJY/DjyCustomerContact.cs @@ -47,5 +47,15 @@ namespace Myshipping.Core.Entity /// 备注 /// public string Remark { get; set; } + + /// + /// 客户端系统ID + /// + public long CustSysId { get; set; } + + /// + /// 大简云GID + /// + public string DjyGid { get; set; } } } \ No newline at end of file diff --git a/Myshipping.Core/Job/CacheCommonWorker.cs b/Myshipping.Core/Job/CacheCommonWorker.cs index 2a12faa4..4be242b1 100644 --- a/Myshipping.Core/Job/CacheCommonWorker.cs +++ b/Myshipping.Core/Job/CacheCommonWorker.cs @@ -101,6 +101,9 @@ namespace Myshipping.Core.Job //航线与港口的的关系 await App.GetService().GetAllRelaPortCarrierLane(true); + //起运港与船代的的关系 + await App.GetService().GetAllRelaPortLoadForwarder(true); + //国家 await App.GetService().GetAllCountry(true); diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml index 89bc38d5..47f17498 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -782,6 +782,11 @@ 省份信息 + + + 起运港与船代的关系 + + 程序集 @@ -1732,6 +1737,26 @@ 备注 + + + 起运港代码 + + + + + 船代代码 + + + + + 模块(公用时为空字符串) + + + + + 备注 + + 自定义租户基类实体 @@ -2044,6 +2069,16 @@ 等级 + + + 客户端系统ID + + + + + 大简云GID + + 客户地址 @@ -2129,6 +2164,16 @@ 备注 + + + 客户端系统ID + + + + + 大简云GID + + 钉钉客服通知群配置 @@ -7332,6 +7377,12 @@ + + + 获取公共库 起运港与船代的关系表 + + + 获取公共库 国家 @@ -7554,6 +7605,12 @@ + + + 设置公共库 起运港与船代的关系表 + + + 设置公共库 国家 @@ -7878,7 +7935,13 @@ - 设置公共库 航线与港口的的关系表 + 获取公共库 航线与港口的的关系表 + + + + + + 获取公共库 起运港与船代的关系表 @@ -7996,6 +8059,12 @@ + + + 设置公共库 起运港与船代的关系表 + + + 设置公共库 国家 @@ -10158,6 +10227,12 @@ + + + 起运港与船代的关系 + + + 国家 diff --git a/Myshipping.Core/Service/Cache/ISysCacheService.cs b/Myshipping.Core/Service/Cache/ISysCacheService.cs index f9ad2c13..2cc6f8a5 100644 --- a/Myshipping.Core/Service/Cache/ISysCacheService.cs +++ b/Myshipping.Core/Service/Cache/ISysCacheService.cs @@ -109,6 +109,12 @@ public interface ISysCacheService /// Task> GetAllRelaPortCarrierLane(); + /// + /// 获取公共库 起运港与船代的关系表 + /// + /// + Task> GetAllRelaPortLoadForwarder(); + /// /// 获取公共库 国家 /// @@ -332,6 +338,12 @@ public interface ISysCacheService /// Task SetAllRelaPortCarrierLane(List list); + /// + /// 设置公共库 起运港与船代的关系表 + /// + /// + Task SetAllRelaPortLoadForwarder(List list); + /// /// 设置公共库 国家 /// diff --git a/Myshipping.Core/Service/Cache/SysCacheService.cs b/Myshipping.Core/Service/Cache/SysCacheService.cs index eeb3e7ce..e6e70166 100644 --- a/Myshipping.Core/Service/Cache/SysCacheService.cs +++ b/Myshipping.Core/Service/Cache/SysCacheService.cs @@ -398,7 +398,7 @@ public class SysCacheService : ISysCacheService, IDynamicApiController, ISinglet } /// - /// 设置公共库 航线与港口的的关系表 + /// 获取公共库 航线与港口的的关系表 /// /// public Task> GetAllRelaPortCarrierLane() @@ -406,6 +406,15 @@ public class SysCacheService : ISysCacheService, IDynamicApiController, ISinglet return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_LANE_PORT); } + /// + /// 获取公共库 起运港与船代的关系表 + /// + /// + public Task> GetAllRelaPortLoadForwarder() + { + return _cache.GetAsync>(CommonConst.CACHE_KEY_COMMON_DB_RELA_PORTLOAD_FORWARDER); + } + /// /// 获取公共库 国家 /// @@ -580,6 +589,15 @@ public class SysCacheService : ISysCacheService, IDynamicApiController, ISinglet return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_LANE_PORT, list); } + /// + /// 设置公共库 起运港与船代的关系表 + /// + /// + public Task SetAllRelaPortLoadForwarder(List list) + { + return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_RELA_PORTLOAD_FORWARDER, list); + } + /// /// 设置公共库 国家 /// diff --git a/Myshipping.Core/Service/CommonDB/CommonDBService.cs b/Myshipping.Core/Service/CommonDB/CommonDBService.cs index 10818afd..c0e89374 100644 --- a/Myshipping.Core/Service/CommonDB/CommonDBService.cs +++ b/Myshipping.Core/Service/CommonDB/CommonDBService.cs @@ -51,6 +51,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie private readonly SqlSugarRepository _mappingForwarder; private readonly SqlSugarRepository _codeCityRep; private readonly SqlSugarRepository _codeProvinceRep; + private readonly SqlSugarRepository _relaPortLoadForwarderRep; public CommonDBService(SqlSugarRepository codeCarrierRep, SqlSugarRepository codeVesselRep, SqlSugarRepository codeForwarderRep, @@ -80,7 +81,8 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie SqlSugarRepository codeCountryRep, SqlSugarRepository mappingForwarder, SqlSugarRepository codeCityRep, - SqlSugarRepository codeProvinceRep + SqlSugarRepository codeProvinceRep, + SqlSugarRepository relaPortLoadForwarderRep ) { _codeCarrierRep = codeCarrierRep; @@ -113,7 +115,7 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie _mappingForwarder = mappingForwarder; _codeCityRep = codeCityRep; _codeProvinceRep = codeProvinceRep; - + _relaPortLoadForwarderRep = relaPortLoadForwarderRep; } #endregion @@ -1918,6 +1920,26 @@ public class CommonDBService : ICommonDBService, IDynamicApiController, ITransie } + } + + [NonAction] + public async Task GetAllRelaPortLoadForwarder(bool flag = false) + { + if (flag) + { + if (!_sysCacheService.Exists(CommonConst.CACHE_KEY_COMMON_DB_RELA_PORTLOAD_FORWARDER)) + { + var list = await _relaPortLoadForwarderRep.ToListAsync(); + await _sysCacheService.SetAllRelaPortLoadForwarder(list); + } + } + else + { + var list = await _relaPortLoadForwarderRep.ToListAsync(); + await _sysCacheService.SetAllRelaPortLoadForwarder(list); + } + + } /// diff --git a/Myshipping.Core/Service/CommonDB/ICommonDBService.cs b/Myshipping.Core/Service/CommonDB/ICommonDBService.cs index e9f3db31..ca8809ff 100644 --- a/Myshipping.Core/Service/CommonDB/ICommonDBService.cs +++ b/Myshipping.Core/Service/CommonDB/ICommonDBService.cs @@ -105,6 +105,12 @@ public interface ICommonDBService /// Task GetAllRelaPortCarrierLane(bool flag); + /// + /// 起运港与船代的关系 + /// + /// + Task GetAllRelaPortLoadForwarder(bool flag); + /// /// 国家 ///