diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 8cb40886..1e9e952d 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1755,6 +1755,10 @@ namespace Myshipping.Application }; var mlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == input.Id).FirstAsync(); + if (mlist.IsDeleted) + { + throw Oops.Bah("当前单据为【已删除】状态,无法修改"); + } if (!string.IsNullOrEmpty(reqId)) { @@ -2287,6 +2291,9 @@ namespace Myshipping.Application // 要取消订阅运踪的列表 List waitUnsubscribeBilltrace = new(arr.Count()); + var tenantParamList = await _cache.GetAllTenantParam(); + var isAskDs = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == TenantParamCode.ASK_DS_BEFORE_DELETE_BOOKING_ORDER); + foreach (var ar in arr) { long Id = Convert.ToInt64(ar); @@ -2300,27 +2307,64 @@ namespace Myshipping.Application // 将待删除的订舱单id存放到Cache中。目的:使用SendBookingOrder()推送订舱单数据前通过Cache判断是否正在走删除逻辑,来决定是否推送(如果是正在处理删除逻辑的数据,则不推送) string deletingCacheKey = $"DeletingBookingOrderId_{ar}"; - await _cache.SetTimeoutAsync(deletingCacheKey, null, TimeSpan.FromMinutes(1)); - _logger.LogInformation("设置待删除的订舱单id到Cache中,key:" + deletingCacheKey); - BookingOrderDelete bookingOrderDelete = new BookingOrderDelete(); - List deletelist = new List(); - deletelist.Add(new BookingOrderDeleteDetail + try { - Id = Id, - MBLNO = mblno - }); - bookingOrderDelete.Delete = deletelist; + await _cache.SetTimeoutAsync(deletingCacheKey, null, TimeSpan.FromMinutes(1)); + _logger.LogInformation("设置待删除的订舱单id到Cache中,key:" + deletingCacheKey); - var stn = await url.SetBody(bookingOrderDelete).PostAsStringAsync(); - var jobj = stn.ToJObject(); - _logger.LogInformation(mblno + "删除单据:" + jobj); - if (jobj.GetIntValue("Code") == 200) - { - JObject data = jobj.GetValue("Data") as JObject; - JArray NoDeleted = data.GetValue("NoDeleted") as JArray; var deleteTime = DateTime.Now; - if (NoDeleted == null || NoDeleted.Count() == 0) + if (isAskDs?.ItemCode == "YES") + { + BookingOrderDelete bookingOrderDelete = new BookingOrderDelete(); + List deletelist = new List + { + new BookingOrderDeleteDetail + { + Id = Id, + MBLNO = mblno + } + }; + bookingOrderDelete.Delete = deletelist; + + var stn = await url.SetBody(bookingOrderDelete).PostAsStringAsync(); + var jobj = stn.ToJObject(); + _logger.LogInformation(mblno + "删除单据:" + jobj); + if (jobj.GetIntValue("Code") == 200) + { + JObject data = jobj.GetValue("Data") as JObject; + JArray NoDeleted = data.GetValue("NoDeleted") as JArray; + if (NoDeleted == null || NoDeleted.Count() == 0 || (NoDeleted[0] is JObject re2 && re2.GetIntValue("Code") == 201)) + { + var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).Select(x => x.Id).ToListAsync(); + await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true }); + await _ctndetailrep.UpdateAsync(x => ctnlist.Contains((long)x.CTNID), x => new BookingCtnDetail { IsDeleted = true }); + await _rep.UpdateAsync(x => x.Id == Id, x => new BookingOrder { IsDeleted = true, DeleteTime = deleteTime }); + await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id && x.IsDeleted == false, x => new BookingEDIExt { IsDeleted = true }); + _logger.LogInformation(mblno + "删除成功!"); + + // 取消订阅运踪 + waitUnsubscribeBilltrace.Add(new BillTraceUnsubscribeList(Id.ToString(), mblno)); + + // 记录日志 + var newOrder = order.Adapt(); + newOrder.IsDeleted = true; + newOrder.DeleteTime = deleteTime; + await SaveLog(newOrder, order, "删除"); + } + else + { + var re = NoDeleted[0] as JObject; + string result = re.GetStringValue("Result"); + throw Oops.Bah(result); + } + } + else + { + throw Oops.Bah(mblno + "删除单据失败"); + } + } + else { var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).Select(x => x.Id).ToListAsync(); await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true }); @@ -2338,48 +2382,19 @@ namespace Myshipping.Application newOrder.DeleteTime = deleteTime; await SaveLog(newOrder, order, "删除"); } - else - { - var re = NoDeleted[0] as JObject; - if (re.GetIntValue("Code") == 201) - { - var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).Select(x => x.Id).ToListAsync(); - await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true }); - await _ctndetailrep.UpdateAsync(x => ctnlist.Contains((long)x.CTNID), x => new BookingCtnDetail { IsDeleted = true }); - await _rep.UpdateAsync(x => x.Id == Id, x => new BookingOrder { IsDeleted = true, DeleteTime = deleteTime }); - await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id && x.IsDeleted == false, x => new BookingEDIExt { IsDeleted = true }); - _logger.LogInformation(mblno + "删除成功!"); - - // 取消订阅运踪 - waitUnsubscribeBilltrace.Add(new BillTraceUnsubscribeList(Id.ToString(), mblno)); - - // 记录日志 - var newOrder = order.Adapt(); - newOrder.IsDeleted = true; - newOrder.DeleteTime = deleteTime; - await SaveLog(newOrder, order, "删除"); - } - else - { - await _cache.DelAsync(deletingCacheKey); - _logger.LogInformation("从Cache中移除待删除的订舱单id,key:" + deletingCacheKey); - - string result = re.GetStringValue("Result"); - throw Oops.Bah(result); - } - - } } - else + catch (Exception) { await _cache.DelAsync(deletingCacheKey); _logger.LogInformation("从Cache中移除待删除的订舱单id,key:" + deletingCacheKey); - throw Oops.Bah(mblno + "删除单据失败"); + throw; + } + finally + { + await _cache.DelAsync(deletingCacheKey); + _logger.LogInformation("从Cache中移除待删除的订舱单id,key:" + deletingCacheKey); } - - await _cache.DelAsync(deletingCacheKey); - _logger.LogInformation("从Cache中移除待删除的订舱单id,key:" + deletingCacheKey); } // 取消订阅运踪 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/Const/TenantParamCode.cs b/Myshipping.Core/Const/TenantParamCode.cs index a0549bca..ff8bb48b 100644 --- a/Myshipping.Core/Const/TenantParamCode.cs +++ b/Myshipping.Core/Const/TenantParamCode.cs @@ -24,5 +24,10 @@ /// 通过运踪更新船舶动态开关 /// public const string ENABLE_STATUS_TO_SAILING_DATE = "EnableStatusToSailingDate"; + + /// + /// 删除订舱前是否先询问东胜 + /// + public const string ASK_DS_BEFORE_DELETE_BOOKING_ORDER = "AskDsBeforeDeleteBookingOrder"; } } 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/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 f0beaa77..47f17498 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -782,6 +782,11 @@ 省份信息 + + + 起运港与船代的关系 + + 程序集 @@ -872,6 +877,11 @@ 通过运踪更新船舶动态开关 + + + 删除订舱前是否先询问东胜 + + 代码 @@ -1727,6 +1737,26 @@ 备注 + + + 起运港代码 + + + + + 船代代码 + + + + + 模块(公用时为空字符串) + + + + + 备注 + + 自定义租户基类实体 @@ -7347,6 +7377,12 @@ + + + 获取公共库 起运港与船代的关系表 + + + 获取公共库 国家 @@ -7569,6 +7605,12 @@ + + + 设置公共库 起运港与船代的关系表 + + + 设置公共库 国家 @@ -7893,7 +7935,13 @@ - 设置公共库 航线与港口的的关系表 + 获取公共库 航线与港口的的关系表 + + + + + + 获取公共库 起运港与船代的关系表 @@ -8011,6 +8059,12 @@ + + + 设置公共库 起运港与船代的关系表 + + + 设置公共库 国家 @@ -10173,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); + /// /// 国家 ///