bc解析调整

master
zhangxiaofeng 6 months ago
parent b8f59f3514
commit 0072c2e0d2

@ -10,6 +10,13 @@ namespace Myshipping.Application.Helper
{
public static class PlaceToPortHelper
{
/// <summary>
/// 根据收货地港口英文名解析出起始港对象
/// </summary>
/// <param name="portEnName">收货地港口英文名</param>
/// <param name="cachePortLoad">起始港缓存</param>
/// <param name="cacheMapPortLoadFunc">起始港缓存映射</param>
/// <returns>起始港对象</returns>
public static async Task<CodePortLoad> PlaceReceiptToPortload(string portEnName, List<CodePortLoad> cachePortLoad, Func<Task<List<MappingPortLoad>>> cacheMapPortLoadFunc)
{
if (string.IsNullOrEmpty(portEnName))
@ -42,6 +49,13 @@ namespace Myshipping.Application.Helper
}
return null;
}
/// <summary>
/// 根据交货地港口英文名解析出目的港对象
/// </summary>
/// <param name="portEnName">交货地港口英文名</param>
/// <param name="cachePort">目的港缓存</param>
/// <param name="cacheMapPortFunc">目的港缓存映射</param>
/// <returns>目的港对象</returns>
public static async Task<CodePort> PlaceDeliveryToPort(string portEnName, List<CodePort> cachePort, Func<Task<List<MappingPort>>> cacheMapPortFunc)
{
if (string.IsNullOrEmpty(portEnName))

@ -1091,7 +1091,7 @@ namespace Myshipping.Application
/// </summary>
/// <returns></returns>
[HttpPost("/BookingSlot/refreshAllStock")]
public async Task RefreshAllStock([FromBody] long telentId)
public async Task RefreshAllStock([FromQuery] long telentId)
{
var n = await _repStock.DeleteAsync(x => x.TenantId == telentId);
@ -1131,18 +1131,18 @@ namespace Myshipping.Application
/// 根据某租户下面所有收货地、交货地、计算出装货港、卸货港
/// </summary>
[HttpPost("/BookingSlot/refreshAllPort")]
public async Task RefreshAllPort([FromBody] long telentId)
public async Task RefreshAllPort([FromQuery] long? telentId, [FromQuery] int? type)
{
var cachePort = await _cache.GetAllCodePort();
var cachePortLoad = await _cache.GetAllCodePortLoad();
var list = await _repBase.AsQueryable().Filter(null, true)
.Where(x => x.TenantId == telentId
&& x.IsDeleted == false
&& x.IS_CANCELLATION == false
&& !string.IsNullOrEmpty(x.PLACERECEIPT)
&& !string.IsNullOrEmpty(x.PLACEDELIVERY)
&& (string.IsNullOrEmpty(x.PORTLOADID) || string.IsNullOrEmpty(x.PORTDISCHARGEID)))
.Where(x => x.IsDeleted == false && x.IS_CANCELLATION == false)
.WhereIF(telentId != null, x => x.TenantId == telentId)
.WhereIF(type == 1, x => !string.IsNullOrEmpty(x.PLACERECEIPT) && (string.IsNullOrEmpty(x.PORTLOADID) || string.IsNullOrEmpty(x.PORTLOAD)))
.WhereIF(type == 2, x => !string.IsNullOrEmpty(x.PLACEDELIVERY) && (string.IsNullOrEmpty(x.PORTDISCHARGEID) || string.IsNullOrEmpty(x.PORTDISCHARGE)))
.WhereIF(type == null, x => (!string.IsNullOrEmpty(x.PLACERECEIPT) || !string.IsNullOrEmpty(x.PLACEDELIVERY))
&& (string.IsNullOrEmpty(x.PORTDISCHARGE) || string.IsNullOrEmpty(x.PORTDISCHARGEID) || string.IsNullOrEmpty(x.PORTLOAD) || string.IsNullOrEmpty(x.PORTLOADID)))
.Select(x => new BookingSlotBase()
{
Id = x.Id,
@ -1168,6 +1168,8 @@ namespace Myshipping.Application
foreach (var item in list)
{
// 解析收货地,得到装货港名称及五字码
if (!string.IsNullOrEmpty(item.PLACERECEIPT))
{
var portEnName = item.PLACERECEIPT.Split(',')[0]?.Trim();
if (!string.IsNullOrWhiteSpace(portEnName)
&& (string.IsNullOrEmpty(item.PORTLOADID) || string.IsNullOrEmpty(item.PORTLOAD)))
@ -1175,14 +1177,14 @@ namespace Myshipping.Application
var portInfo = await PlaceToPortHelper.PlaceReceiptToPortload(portEnName, cachePortLoad, () => _cache.GetAllMappingPortLoad());
if (portInfo != null)
{
if (string.IsNullOrEmpty(item.PORTLOADID))
//if (string.IsNullOrEmpty(item.PORTLOADID))
{
updateIdSet.Add(item.Id);
item.PORTLOADID = portInfo.EdiCode;
}
if (string.IsNullOrEmpty(item.PORTLOAD))
//if (string.IsNullOrEmpty(item.PORTLOAD))
{
updateIdSet.Add(item.Id);
//updateIdSet.Add(item.Id);
item.PORTLOAD = portInfo.EnName;
}
}
@ -1191,8 +1193,11 @@ namespace Myshipping.Application
_logger.LogInformation("通过收货地城市名称未匹配到港口信息,订舱编号:{SLOT_BOOKING_NO}", item.SLOT_BOOKING_NO);
}
}
}
// 解析交货地,得到为卸货港名称及五字码, 以及国家信息
if (!string.IsNullOrEmpty(item.PLACEDELIVERY))
{
var portEnName2 = item.PLACEDELIVERY.Split(',')[0]?.Trim();
if (!string.IsNullOrWhiteSpace(portEnName2))
{
@ -1204,24 +1209,24 @@ namespace Myshipping.Application
|| string.IsNullOrEmpty(item.PORTDISCHARGE_COUNTRY_CODE)
|| string.IsNullOrEmpty(item.PORTDISCHARGE_COUNTRY)))
{
if (string.IsNullOrEmpty(item.PORTDISCHARGEID))
//if (string.IsNullOrEmpty(item.PORTDISCHARGEID))
{
updateIdSet.Add(item.Id);
item.PORTDISCHARGEID = portInfo.EdiCode;
}
if (string.IsNullOrEmpty(item.PORTDISCHARGE))
//if (string.IsNullOrEmpty(item.PORTDISCHARGE))
{
updateIdSet.Add(item.Id);
//updateIdSet.Add(item.Id);
item.PORTDISCHARGE = portInfo.EnName;
}
if (string.IsNullOrEmpty(item.PORTDISCHARGE_COUNTRY_CODE))
//if (string.IsNullOrEmpty(item.PORTDISCHARGE_COUNTRY_CODE))
{
updateIdSet.Add(item.Id);
//updateIdSet.Add(item.Id);
item.PORTDISCHARGE_COUNTRY_CODE = portInfo.CountryCode;
}
if (string.IsNullOrEmpty(item.PORTDISCHARGE_COUNTRY))
//if (string.IsNullOrEmpty(item.PORTDISCHARGE_COUNTRY))
{
updateIdSet.Add(item.Id);
//updateIdSet.Add(item.Id);
item.PORTDISCHARGE_COUNTRY = portInfo.Country;
}
}
@ -1231,11 +1236,25 @@ namespace Myshipping.Application
}
}
}
}
if (updateIdSet.Count > 0)
{
var updateList = list.Where(x => updateIdSet.Contains(x.Id)).ToList();
await _repBase.AsUpdateable(updateList).UpdateColumns(x => new
await _repBase.AsUpdateable(updateList)
.UpdateColumnsIF(type == 1, x => new
{
x.PORTLOADID,
x.PORTLOAD,
})
.UpdateColumnsIF(type == 2, x => new
{
x.PORTDISCHARGEID,
x.PORTDISCHARGE,
x.PORTDISCHARGE_COUNTRY_CODE,
x.PORTDISCHARGE_COUNTRY,
})
.UpdateColumnsIF(type == null, x => new
{
x.PORTLOADID,
x.PORTDISCHARGEID,
@ -1263,9 +1282,11 @@ namespace Myshipping.Application
x.CONTRACT_NO,
x.TenantId
}).ToList();
_ = Task.Run(async () =>
{
foreach (var item in group)
{
await Task.Delay(1000);
await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", new BookingSlotStockUpdateModel
{
BOOKING_SLOT_TYPE = item.Key.BOOKING_SLOT_TYPE,
@ -1278,6 +1299,7 @@ namespace Myshipping.Application
TenantId = item.Key.TenantId
}));
}
});
}
}
#endregion

Loading…
Cancel
Save