You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.4 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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