using DS.Module.Core;
using DS.Module.Core.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using NLog;
namespace DS.Module.DjyRulesEngine
{
///
///
///
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();
///
/// 构造函数
///
///
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();
}
///
/// 执行海运出口规则引擎校验
///
/// 修改服务状态详情
/// 返回回执
public async Task 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(result);
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
return await Task.FromResult(res);
}
}
}
}