using DS.Module.Core; using DS.Module.Core.Extensions; using Newtonsoft.Json; using NLog; namespace DS.Module.DjyRulesEngine { /// /// 大简云规则引擎 /// public class RuleEngineService : IRuleEngineService { static readonly ApiFox api; static RuleEngineService() { api = new ApiFox(60); } 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); } } /// /// 执行海运出口订单审核规则引擎校验 /// /// 服务状态详情 /// 返回回执 public async Task ExecuteSeaExportAuditRulesAsync(RuleEngineReq req) { if (string.IsNullOrEmpty(req.Head.SenderKey)) req.Head.SenderKey = senderKey; var uriBuilder = new UriBuilder { Host = ip, Port = port, Path = sendUrl }; var result = await api.PostAsync(uriBuilder.ToString(), req); if (!result.Succeeded || result.Data == null) return RuleEngineResult.Failed("请求失败,请联系管理员"); return result.Data; } } }