|
|
|
@ -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();
|
|
|
|
|
.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,13 +205,46 @@ namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
//var model =
|
|
|
|
|
var mainInfo = model.Adapt<RulesEngineOrderBookingMainBusinessInfo>();
|
|
|
|
|
|
|
|
|
|
RulesEngineOrderBookingMessageInfo msgModel = GetMessageInfo(mainInfo);
|
|
|
|
|
|
|
|
|
|
//if()
|
|
|
|
|
// _bookingOrderRepository.AsQueryable().InSingle(bookingId);
|
|
|
|
|
var ruleResult = await ExcuteRulesEngine(msgModel);
|
|
|
|
|
|
|
|
|
|
//if (model == null)
|
|
|
|
|
// throw Oops.Oh($"订舱主键{bookingId}无法获取业务信息");
|
|
|
|
|
if (ruleResult == null)
|
|
|
|
|
throw Oops.Oh($"订舱主键{model.BOOKINGNO}请求规则失败,返回为空");
|
|
|
|
|
|
|
|
|
|
var innerRlt = JSON.Deserialize<RemoteRulesEngineExcuteResultDto>(ruleResult.extra.ToString());
|
|
|
|
|
|
|
|
|
|
var ruleDetailList = innerRlt.DetailList;
|
|
|
|
|
|
|
|
|
|
result.succ = ruleResult.succ;
|
|
|
|
|
result.msg = ruleResult.msg;
|
|
|
|
|
|
|
|
|
|
if (ruleDetailList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
result.rows = ruleDetailList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = "请求规则异常";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成请求规则报文
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mainInfo">订舱主业务信息</param>
|
|
|
|
|
/// <returns>返回请求报文类</returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private RulesEngineOrderBookingMessageInfo GetMessageInfo(RulesEngineOrderBookingMainBusinessInfo mainInfo)
|
|
|
|
|
{
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
RulesEngineOrderBookingMessageInfo msgModel = new RulesEngineOrderBookingMessageInfo();
|
|
|
|
|
|
|
|
|
@ -247,18 +267,18 @@ namespace Myshipping.Application
|
|
|
|
|
ProjectCode = App.Configuration["RulesEngineProjects"].Split(new char[] { ',' }).ToArray(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
msgModel.Main.BusinessInfo = model.Adapt<RulesEngineOrderBookingMainBusinessInfo>();
|
|
|
|
|
msgModel.Main.BusinessInfo = mainInfo;
|
|
|
|
|
|
|
|
|
|
//根据卸货港翻译航线信息
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(model.PORTDISCHARGEID))
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mainInfo.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));
|
|
|
|
|
.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(model.PORTDISCHARGEID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
if (laneInfo == null)
|
|
|
|
|
laneInfo = laneList.FirstOrDefault(p => string.IsNullOrWhiteSpace(p.CarrierCode) && p.PortCode.Equals(mainInfo.PortDischargeId, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (laneInfo != null)
|
|
|
|
|
{
|
|
|
|
@ -269,66 +289,34 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var contaList = await _bookingOrderContaRepository.AsQueryable().Where(x => x.BILLID == model.Id).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (contaList.Count > 0)
|
|
|
|
|
//对应签单方式
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mainInfo.IssueType))
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.Adapt<List<RulesEngineOrderBookingContaInfo>>();
|
|
|
|
|
var issueType = _cache.GetAllCodeIssueType().GetAwaiter().GetResult().FirstOrDefault(p => p.EnName.Equals(mainInfo.IssueType, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
var cargoList = await _bookingOrderContaCargoRepository.AsQueryable()
|
|
|
|
|
.Where(x => contaList.Any(a => a.Id == x.CTNID)).ToListAsync();
|
|
|
|
|
//这里规则约定用了签单方式的代码大写
|
|
|
|
|
if (issueType != null)
|
|
|
|
|
msgModel.Main.BusinessInfo.IssueType = issueType.Code.ToUpper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cargoList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.GroupJoin(cargoList, l => l.Id, r => r.CTNID, (l, r) =>
|
|
|
|
|
if (mainInfo.ContaList != null && mainInfo.ContaList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var currList = r.ToList();
|
|
|
|
|
|
|
|
|
|
if (currList.Count > 0)
|
|
|
|
|
var contaList = _cache.GetAllMappingCtn().GetAwaiter().GetResult();
|
|
|
|
|
mainInfo.ContaList.ForEach(t =>
|
|
|
|
|
{
|
|
|
|
|
var info = l.Adapt<RulesEngineOrderBookingContaInfo>();
|
|
|
|
|
info.CargoList = currList.Adapt<List<RulesEngineOrderBookingContaCargoInfo>>();
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return l.Adapt<RulesEngineOrderBookingContaInfo>();
|
|
|
|
|
var currContaType = contaList.FirstOrDefault(x => x.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
&& x.Code.Equals(t.ContaType, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (currContaType != null)
|
|
|
|
|
{
|
|
|
|
|
msgModel.Main.BusinessInfo.ContaList = contaList.Adapt<List<RulesEngineOrderBookingContaInfo>>();
|
|
|
|
|
t.ContaType = currContaType.MapCode?.ToUpper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
var ruleResult = await ExcuteRulesEngine(msgModel);
|
|
|
|
|
|
|
|
|
|
if (ruleResult == null)
|
|
|
|
|
throw Oops.Oh($"订舱主键{model.BOOKINGNO}请求规则失败,返回为空");
|
|
|
|
|
|
|
|
|
|
var innerRlt = JSON.Deserialize<RemoteRulesEngineExcuteResultDto>(ruleResult.extra.ToString());
|
|
|
|
|
|
|
|
|
|
var ruleDetailList = innerRlt.DetailList;
|
|
|
|
|
|
|
|
|
|
result.succ = ruleResult.succ;
|
|
|
|
|
result.msg = ruleResult.msg;
|
|
|
|
|
|
|
|
|
|
if (ruleDetailList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
result.rows = ruleDetailList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = "请求规则异常";
|
|
|
|
|
return msgModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 请求规则平台
|
|
|
|
|
/// <summary>
|
|
|
|
@ -336,6 +324,7 @@ namespace Myshipping.Application
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="BusinessMsg"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task<RulesEngineWebApiResult> ExcuteRulesEngine(RulesEngineOrderBookingMessageInfo info)
|
|
|
|
|
{
|
|
|
|
|
RulesEngineWebApiResult model = null;
|
|
|
|
|