|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
|
|
namespace DS.Module.DjyRulesEngine
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class RuleEngineService : IRuleEngineService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly string ip;
|
|
|
|
|
private readonly int port;
|
|
|
|
|
private readonly string senderKey;
|
|
|
|
|
//private readonly string accessSecret;
|
|
|
|
|
private readonly string sendUrl;
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public RuleEngineService(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
|
|
|
|
|
ip = AppSetting.app(new string[] { "ExcuteRuleService", "IP" }).ObjToString();
|
|
|
|
|
port = AppSetting.app(new string[] { "ExcuteRuleService", "Port" }).ToInt();
|
|
|
|
|
senderKey = AppSetting.app(new string[] { "ExcuteRuleService", "SenderKey" }).ObjToString();
|
|
|
|
|
|
|
|
|
|
sendUrl = AppSetting.app(new string[] { "ExcuteRuleService", "SendUrl" }).ObjToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 执行海运出口规则引擎校验
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">修改服务状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<RuleEngineResult> ExcuteRulesOceanBooking(RuleEngineReq req)
|
|
|
|
|
{
|
|
|
|
|
// 只要平台信息参数一致,多个请求只需设置一次参数
|
|
|
|
|
RuleEngineHttpUtil.SetPlatformInfo(ip, port, false);
|
|
|
|
|
|
|
|
|
|
// 发起POST请求,超时时间15秒,返回响应字节数组
|
|
|
|
|
string result = RuleEngineHttpUtil.HttpPost(sendUrl, JsonConvert.SerializeObject(req), 30);
|
|
|
|
|
if (null == result)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(RuleEngineResult.Failed("请求失败,请联系管理员"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var res = JsonConvert.DeserializeObject<RuleEngineResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
return await Task.FromResult(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|