bc解析调整

master
zhangxiaofeng 6 months ago
parent b8f59f3514
commit 0072c2e0d2

@ -10,6 +10,13 @@ namespace Myshipping.Application.Helper
{ {
public static class PlaceToPortHelper 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) public static async Task<CodePortLoad> PlaceReceiptToPortload(string portEnName, List<CodePortLoad> cachePortLoad, Func<Task<List<MappingPortLoad>>> cacheMapPortLoadFunc)
{ {
if (string.IsNullOrEmpty(portEnName)) if (string.IsNullOrEmpty(portEnName))
@ -42,6 +49,13 @@ namespace Myshipping.Application.Helper
} }
return null; 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) public static async Task<CodePort> PlaceDeliveryToPort(string portEnName, List<CodePort> cachePort, Func<Task<List<MappingPort>>> cacheMapPortFunc)
{ {
if (string.IsNullOrEmpty(portEnName)) if (string.IsNullOrEmpty(portEnName))

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

Loading…
Cancel
Save