|
|
|
@ -34,6 +34,9 @@ namespace Myshipping.Application
|
|
|
|
|
private readonly SqlSugarRepository<BookingCtn> _bookingOrderContaRepository;
|
|
|
|
|
private readonly SqlSugarRepository<BookingCtnDetail> _bookingOrderContaCargoRepository;
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
private readonly SqlSugarRepository<RelaPortCarrierLane> _relaPortCarrierLaneRep;
|
|
|
|
|
|
|
|
|
|
const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
@ -41,12 +44,14 @@ namespace Myshipping.Application
|
|
|
|
|
public RulesEngineClientService(SqlSugarRepository<BookingOrder> bookingOrderRepository,
|
|
|
|
|
SqlSugarRepository<BookingCtn> bookingOrderContaRepository,
|
|
|
|
|
SqlSugarRepository<BookingCtnDetail> bookingOrderContaCargoRepository,
|
|
|
|
|
ISysCacheService cache)
|
|
|
|
|
ISysCacheService cache,
|
|
|
|
|
SqlSugarRepository<RelaPortCarrierLane> relaPortCarrierLaneRep)
|
|
|
|
|
{
|
|
|
|
|
_bookingOrderRepository = bookingOrderRepository;
|
|
|
|
|
_bookingOrderContaRepository = bookingOrderContaRepository;
|
|
|
|
|
_bookingOrderContaCargoRepository = bookingOrderContaCargoRepository;
|
|
|
|
|
_cache = cache;
|
|
|
|
|
_relaPortCarrierLaneRep = relaPortCarrierLaneRep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 海运订舱请求规则引擎校验
|
|
|
|
@ -110,42 +115,22 @@ namespace Myshipping.Application
|
|
|
|
|
if (model == null)
|
|
|
|
|
throw Oops.Oh($"订舱主键{bookingId}无法获取业务信息");
|
|
|
|
|
|
|
|
|
|
RulesEngineOrderBookingMessageInfo msgModel = new RulesEngineOrderBookingMessageInfo();
|
|
|
|
|
|
|
|
|
|
msgModel.Head = new RulesEngineWebAPIHeadBase
|
|
|
|
|
{
|
|
|
|
|
GID = IDGen.NextID().ToString(),
|
|
|
|
|
MessageType = "BUSI_RULE",
|
|
|
|
|
SenderId = App.Configuration["RulesEngineSender"],
|
|
|
|
|
SenderName = App.Configuration["RulesEngineSenderName"],
|
|
|
|
|
SenderKey = App.Configuration["RulesEngineAuthKey"],
|
|
|
|
|
ReceiverId = "RulesEngine",
|
|
|
|
|
ReceiverName = "大简云规则引擎",
|
|
|
|
|
Version = "1.0",
|
|
|
|
|
RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
RequestAction = "CheckRule",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
msgModel.Main = new RulesEngineOrderBookingMainInfo {
|
|
|
|
|
ProjectCode = App.Configuration["RulesEngineProjects"].Split(new char[] { ','}).ToArray(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
msgModel.Main.BusinessInfo = model.Adapt<RulesEngineOrderBookingMainBusinessInfo>();
|
|
|
|
|
var mainInfo = model.Adapt<RulesEngineOrderBookingMainBusinessInfo>();
|
|
|
|
|
|
|
|
|
|
var contaList = await _bookingOrderContaRepository.AsQueryable().Where(x => x.BILLID == model.Id).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (contaList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.Adapt<List<RulesEngineOrderBookingContaInfo>>();
|
|
|
|
|
mainInfo.ContaList = contaList.Adapt<List<RulesEngineOrderBookingContaInfo>>();
|
|
|
|
|
|
|
|
|
|
var ctnArg = contaList.Select(t => t.Id).ToArray();
|
|
|
|
|
|
|
|
|
|
var cargoList = await _bookingOrderContaCargoRepository.AsQueryable()
|
|
|
|
|
.Where(x=> ctnArg.Contains(x.CTNID.Value)).ToListAsync();
|
|
|
|
|
var cargoList = await _bookingOrderContaCargoRepository.AsQueryable()
|
|
|
|
|
.Where(x => ctnArg.Contains(x.CTNID.Value)).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if(cargoList.Count > 0)
|
|
|
|
|
if (cargoList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.GroupJoin(cargoList, l => l.Id, r => r.CTNID, (l, r) => {
|
|
|
|
|
mainInfo.ContaList = contaList.GroupJoin(cargoList, l => l.Id, r => r.CTNID, (l, r) => {
|
|
|
|
|
var currList = r.ToList();
|
|
|
|
|
|
|
|
|
|
if (currList.Count > 0)
|
|
|
|
@ -162,11 +147,13 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.Adapt<List<RulesEngineOrderBookingContaInfo>>();
|
|
|
|
|
mainInfo.ContaList = contaList.Adapt<List<RulesEngineOrderBookingContaInfo>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var msgModel = GetMessageInfo(mainInfo);
|
|
|
|
|
|
|
|
|
|
var ruleResult = await ExcuteRulesEngine(msgModel);
|
|
|
|
|
|
|
|
|
|
if(ruleResult == null)
|
|
|
|
@ -218,91 +205,10 @@ namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
//var model =
|
|
|
|
|
|
|
|
|
|
//if()
|
|
|
|
|
// _bookingOrderRepository.AsQueryable().InSingle(bookingId);
|
|
|
|
|
|
|
|
|
|
//if (model == null)
|
|
|
|
|
// throw Oops.Oh($"订舱主键{bookingId}无法获取业务信息");
|
|
|
|
|
|
|
|
|
|
RulesEngineOrderBookingMessageInfo msgModel = new RulesEngineOrderBookingMessageInfo();
|
|
|
|
|
|
|
|
|
|
msgModel.Head = new RulesEngineWebAPIHeadBase
|
|
|
|
|
{
|
|
|
|
|
GID = IDGen.NextID().ToString(),
|
|
|
|
|
MessageType = "BUSI_RULE",
|
|
|
|
|
SenderId = App.Configuration["RulesEngineSender"],
|
|
|
|
|
SenderName = App.Configuration["RulesEngineSenderName"],
|
|
|
|
|
SenderKey = App.Configuration["RulesEngineAuthKey"],
|
|
|
|
|
ReceiverId = "RulesEngine",
|
|
|
|
|
ReceiverName = "大简云规则引擎",
|
|
|
|
|
Version = "1.0",
|
|
|
|
|
RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
RequestAction = "CheckRule",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
msgModel.Main = new RulesEngineOrderBookingMainInfo
|
|
|
|
|
{
|
|
|
|
|
ProjectCode = App.Configuration["RulesEngineProjects"].Split(new char[] { ',' }).ToArray(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
msgModel.Main.BusinessInfo = model.Adapt<RulesEngineOrderBookingMainBusinessInfo>();
|
|
|
|
|
|
|
|
|
|
//根据卸货港翻译航线信息
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(model.PORTDISCHARGEID))
|
|
|
|
|
{
|
|
|
|
|
var laneList = _cache.GetAllRelaPortCarrierLane().GetAwaiter().GetResult();
|
|
|
|
|
var laneInfo = laneList
|
|
|
|
|
.FirstOrDefault(p => !string.IsNullOrWhiteSpace(model.CARRIER) && !string.IsNullOrWhiteSpace(p.CarrierCode) &&
|
|
|
|
|
p.CarrierCode.Equals(model.CARRIER, StringComparison.OrdinalIgnoreCase) && p.PortCode.Equals(model.PORTDISCHARGEID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
var mainInfo = model.Adapt<RulesEngineOrderBookingMainBusinessInfo>();
|
|
|
|
|
|
|
|
|
|
if(laneInfo == null)
|
|
|
|
|
laneInfo = laneList.FirstOrDefault(p => string.IsNullOrWhiteSpace(p.CarrierCode) && p.PortCode.Equals(model.PORTDISCHARGEID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
RulesEngineOrderBookingMessageInfo msgModel = GetMessageInfo(mainInfo);
|
|
|
|
|
|
|
|
|
|
if (laneInfo != null)
|
|
|
|
|
{
|
|
|
|
|
var lineModel = _cache.GetAllCodeLane().GetAwaiter().GetResult().FirstOrDefault(t => t.Code.Equals(laneInfo.LaneCode, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
msgModel.Main.BusinessInfo.LaneCode = laneInfo.LaneCode;
|
|
|
|
|
msgModel.Main.BusinessInfo.LaneName = lineModel?.CnName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var contaList = await _bookingOrderContaRepository.AsQueryable().Where(x => x.BILLID == model.Id).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (contaList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.Adapt<List<RulesEngineOrderBookingContaInfo>>();
|
|
|
|
|
|
|
|
|
|
var cargoList = await _bookingOrderContaCargoRepository.AsQueryable()
|
|
|
|
|
.Where(x => contaList.Any(a => a.Id == x.CTNID)).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (cargoList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.GroupJoin(cargoList, l => l.Id, r => r.CTNID, (l, r) =>
|
|
|
|
|
{
|
|
|
|
|
var currList = r.ToList();
|
|
|
|
|
|
|
|
|
|
if (currList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var info = l.Adapt<RulesEngineOrderBookingContaInfo>();
|
|
|
|
|
info.CargoList = currList.Adapt<List<RulesEngineOrderBookingContaCargoInfo>>();
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return l.Adapt<RulesEngineOrderBookingContaInfo>();
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.Adapt<List<RulesEngineOrderBookingContaInfo>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
var ruleResult = await ExcuteRulesEngine(msgModel);
|
|
|
|
|
|
|
|
|
|
if (ruleResult == null)
|
|
|
|
@ -330,12 +236,95 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成请求规则报文
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mainInfo">订舱主业务信息</param>
|
|
|
|
|
/// <returns>返回请求报文类</returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private RulesEngineOrderBookingMessageInfo GetMessageInfo(RulesEngineOrderBookingMainBusinessInfo mainInfo)
|
|
|
|
|
{
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
RulesEngineOrderBookingMessageInfo msgModel = new RulesEngineOrderBookingMessageInfo();
|
|
|
|
|
|
|
|
|
|
msgModel.Head = new RulesEngineWebAPIHeadBase
|
|
|
|
|
{
|
|
|
|
|
GID = IDGen.NextID().ToString(),
|
|
|
|
|
MessageType = "BUSI_RULE",
|
|
|
|
|
SenderId = App.Configuration["RulesEngineSender"],
|
|
|
|
|
SenderName = App.Configuration["RulesEngineSenderName"],
|
|
|
|
|
SenderKey = App.Configuration["RulesEngineAuthKey"],
|
|
|
|
|
ReceiverId = "RulesEngine",
|
|
|
|
|
ReceiverName = "大简云规则引擎",
|
|
|
|
|
Version = "1.0",
|
|
|
|
|
RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
RequestAction = "CheckRule",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
msgModel.Main = new RulesEngineOrderBookingMainInfo
|
|
|
|
|
{
|
|
|
|
|
ProjectCode = App.Configuration["RulesEngineProjects"].Split(new char[] { ',' }).ToArray(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
msgModel.Main.BusinessInfo = mainInfo;
|
|
|
|
|
|
|
|
|
|
//根据卸货港翻译航线信息
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mainInfo.PortDischargeId))
|
|
|
|
|
{
|
|
|
|
|
var laneList = _cache.GetAllRelaPortCarrierLane().GetAwaiter().GetResult();
|
|
|
|
|
var laneInfo = laneList
|
|
|
|
|
.FirstOrDefault(p => !string.IsNullOrWhiteSpace(mainInfo.CarrierId) && !string.IsNullOrWhiteSpace(p.CarrierCode) &&
|
|
|
|
|
p.CarrierCode.Equals(mainInfo.CarrierId, StringComparison.OrdinalIgnoreCase) && p.PortCode.Equals(mainInfo.PortDischargeId, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (laneInfo == null)
|
|
|
|
|
laneInfo = laneList.FirstOrDefault(p => string.IsNullOrWhiteSpace(p.CarrierCode) && p.PortCode.Equals(mainInfo.PortDischargeId, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (laneInfo != null)
|
|
|
|
|
{
|
|
|
|
|
var lineModel = _cache.GetAllCodeLane().GetAwaiter().GetResult().FirstOrDefault(t => t.Code.Equals(laneInfo.LaneCode, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
msgModel.Main.BusinessInfo.LaneCode = laneInfo.LaneCode;
|
|
|
|
|
msgModel.Main.BusinessInfo.LaneName = lineModel?.CnName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//对应签单方式
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mainInfo.IssueType))
|
|
|
|
|
{
|
|
|
|
|
var issueType = _cache.GetAllCodeIssueType().GetAwaiter().GetResult().FirstOrDefault(p => p.EnName.Equals(mainInfo.IssueType, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
//这里规则约定用了签单方式的代码大写
|
|
|
|
|
if (issueType != null)
|
|
|
|
|
msgModel.Main.BusinessInfo.IssueType = issueType.Code.ToUpper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mainInfo.ContaList != null && mainInfo.ContaList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var contaList = _cache.GetAllMappingCtn().GetAwaiter().GetResult();
|
|
|
|
|
mainInfo.ContaList.ForEach(t =>
|
|
|
|
|
{
|
|
|
|
|
var currContaType = contaList.FirstOrDefault(x => x.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
&& x.Code.Equals(t.ContaType, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (currContaType != null)
|
|
|
|
|
{
|
|
|
|
|
t.ContaType = currContaType.MapCode?.ToUpper();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return msgModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 请求规则平台
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 请求规则平台
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="BusinessMsg"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task<RulesEngineWebApiResult> ExcuteRulesEngine(RulesEngineOrderBookingMessageInfo info)
|
|
|
|
|
{
|
|
|
|
|
RulesEngineWebApiResult model = null;
|
|
|
|
|