通过租户参数控制删除时是否先询问东胜

master
zhangxiaofeng 8 months ago
parent 26bd7b1195
commit 91753f9dd8

@ -2291,6 +2291,9 @@ namespace Myshipping.Application
// 要取消订阅运踪的列表 // 要取消订阅运踪的列表
List<BillTraceUnsubscribeList> waitUnsubscribeBilltrace = new(arr.Count()); List<BillTraceUnsubscribeList> 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) foreach (var ar in arr)
{ {
long Id = Convert.ToInt64(ar); long Id = Convert.ToInt64(ar);
@ -2304,27 +2307,64 @@ namespace Myshipping.Application
// 将待删除的订舱单id存放到Cache中。目的使用SendBookingOrder()推送订舱单数据前通过Cache判断是否正在走删除逻辑来决定是否推送(如果是正在处理删除逻辑的数据,则不推送) // 将待删除的订舱单id存放到Cache中。目的使用SendBookingOrder()推送订舱单数据前通过Cache判断是否正在走删除逻辑来决定是否推送(如果是正在处理删除逻辑的数据,则不推送)
string deletingCacheKey = $"DeletingBookingOrderId_{ar}"; string deletingCacheKey = $"DeletingBookingOrderId_{ar}";
await _cache.SetTimeoutAsync(deletingCacheKey, null, TimeSpan.FromMinutes(1));
_logger.LogInformation("设置待删除的订舱单id到Cache中key" + deletingCacheKey);
BookingOrderDelete bookingOrderDelete = new BookingOrderDelete(); try
List<BookingOrderDeleteDetail> deletelist = new List<BookingOrderDeleteDetail>();
deletelist.Add(new BookingOrderDeleteDetail
{ {
Id = Id, await _cache.SetTimeoutAsync(deletingCacheKey, null, TimeSpan.FromMinutes(1));
MBLNO = mblno _logger.LogInformation("设置待删除的订舱单id到Cache中key" + deletingCacheKey);
});
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;
var deleteTime = DateTime.Now; var deleteTime = DateTime.Now;
if (NoDeleted == null || NoDeleted.Count() == 0) if (isAskDs?.ItemCode == "YES")
{
BookingOrderDelete bookingOrderDelete = new BookingOrderDelete();
List<BookingOrderDeleteDetail> deletelist = new List<BookingOrderDeleteDetail>
{
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<BookingOrder>();
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(); 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 _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true });
@ -2342,48 +2382,19 @@ namespace Myshipping.Application
newOrder.DeleteTime = deleteTime; newOrder.DeleteTime = deleteTime;
await SaveLog(newOrder, order, "删除"); 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<BookingOrder>();
newOrder.IsDeleted = true;
newOrder.DeleteTime = deleteTime;
await SaveLog(newOrder, order, "删除");
}
else
{
await _cache.DelAsync(deletingCacheKey);
_logger.LogInformation("从Cache中移除待删除的订舱单idkey" + deletingCacheKey);
string result = re.GetStringValue("Result");
throw Oops.Bah(result);
}
}
} }
else catch (Exception)
{ {
await _cache.DelAsync(deletingCacheKey); await _cache.DelAsync(deletingCacheKey);
_logger.LogInformation("从Cache中移除待删除的订舱单idkey" + deletingCacheKey); _logger.LogInformation("从Cache中移除待删除的订舱单idkey" + deletingCacheKey);
throw Oops.Bah(mblno + "删除单据失败"); throw;
}
finally
{
await _cache.DelAsync(deletingCacheKey);
_logger.LogInformation("从Cache中移除待删除的订舱单idkey" + deletingCacheKey);
} }
await _cache.DelAsync(deletingCacheKey);
_logger.LogInformation("从Cache中移除待删除的订舱单idkey" + deletingCacheKey);
} }
// 取消订阅运踪 // 取消订阅运踪

@ -24,5 +24,10 @@
/// 通过运踪更新船舶动态开关 /// 通过运踪更新船舶动态开关
/// </summary> /// </summary>
public const string ENABLE_STATUS_TO_SAILING_DATE = "EnableStatusToSailingDate"; public const string ENABLE_STATUS_TO_SAILING_DATE = "EnableStatusToSailingDate";
/// <summary>
/// 删除订舱前是否先询问东胜
/// </summary>
public const string ASK_DS_BEFORE_DELETE_BOOKING_ORDER = "AskDsBeforeDeleteBookingOrder";
} }
} }

@ -872,6 +872,11 @@
通过运踪更新船舶动态开关 通过运踪更新船舶动态开关
</summary> </summary>
</member> </member>
<member name="F:Myshipping.Core.Const.TenantParamCode.ASK_DS_BEFORE_DELETE_BOOKING_ORDER">
<summary>
删除订舱前是否先询问东胜
</summary>
</member>
<member name="P:Myshipping.Core.Entity.CodeCarrier.Code"> <member name="P:Myshipping.Core.Entity.CodeCarrier.Code">
<summary> <summary>
代码 代码

Loading…
Cancel
Save