提交审核调用大简云规则库

usertest
嵇文龙 3 months ago
parent d7a6ca900b
commit fd9df6302c

@ -84,11 +84,7 @@ namespace DS.Module.Core
if (!queryString.IsNullOrEmpty())
url = url.LastOrDefault() == '?' ? url + queryString : url + "?" + queryString;
var result = await SendRequestAsync(HttpMethod.Get, url);
if (!result.Succeeded)
return DataResult<T>.Failed(result.Message, result.MultiCode);
var response = result.Data;
var response = await SendRequestAsync(HttpMethod.Get, url);
T? data = default;
if (response != null)
{
@ -96,7 +92,7 @@ namespace DS.Module.Core
data = JsonConvert.DeserializeObject<T>(json);
}
return new DataResult<T>(result.Code, result.Message, data, result.MultiCode);
return DataResult<T>.Success(data);
}
/// <summary>
@ -109,11 +105,7 @@ namespace DS.Module.Core
/// <exception cref="ArgumentException"><paramref name="url"/>为null或空字符串</exception>
public async Task<DataResult<T>> PostAsync<T>(string url, object? requestParams = null)
{
var result = await SendRequestAsync(HttpMethod.Post, url, requestParams);
if (!result.Succeeded)
return DataResult<T>.Failed(result.Message, result.MultiCode);
var response = result.Data;
var response = await SendRequestAsync(HttpMethod.Post, url, requestParams);
T? data = default;
if (response != null)
{
@ -121,7 +113,7 @@ namespace DS.Module.Core
data = JsonConvert.DeserializeObject<T>(json);
}
return new DataResult<T>(result.Code, result.Message, data, result.MultiCode);
return DataResult<T>.Success(data);
}
/// <summary>
@ -134,7 +126,7 @@ namespace DS.Module.Core
/// <exception cref="ArgumentNullException"><paramref name="method"/>为null</exception>
/// <exception cref="ArgumentException"><paramref name="url"/>为null或空字符串</exception>
/// <exception cref="NotSupportedException"><paramref name="method"/>不等于 GET/POST/PUT/Delete 中的任何一个请求方法</exception>
public async Task<DataResult<HttpResponseMessage>> SendRequestAsync(HttpMethod method, string url, object? requestParams = null)
public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, string url, object? requestParams = null)
{
ArgumentNullException.ThrowIfNull(method);
ArgumentException.ThrowIfNullOrEmpty(url);
@ -159,8 +151,6 @@ namespace DS.Module.Core
RequestUri = reqUri
});
try
{
HttpResponseMessage? response = null;
if (method == HttpMethod.Get)
{
@ -193,15 +183,7 @@ namespace DS.Module.Core
Response = response
});
if (!response.IsSuccessStatusCode)
return DataResult<HttpResponseMessage>.FailedData(response, string.Format(MultiLanguageConst.HttpRequestFailed, $"{response.StatusCode}"));
return DataResult<HttpResponseMessage>.Success(response);
}
catch (Exception ex)
{
return DataResult<HttpResponseMessage>.Failed(ex.Message);
}
return response;
}
/// <summary>

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.Module.DjyRulesEngine
namespace DS.Module.DjyRulesEngine
{
public interface IRuleEngineService
{
@ -14,5 +8,12 @@ namespace DS.Module.DjyRulesEngine
/// <param name="req">修改服务状态详情</param>
/// <returns>返回回执</returns>
public Task<RuleEngineResult> ExcuteRulesOceanBooking(RuleEngineReq req);
/// <summary>
/// 执行海运出口订单审核规则引擎校验
/// </summary>
/// <param name="req">服务状态详情</param>
/// <returns>返回回执</returns>
Task<RuleEngineResult?> ExecuteSeaExportAuditRulesAsync(RuleEngineReq req);
}
}

@ -1,9 +1,4 @@
using DS.Module.Core.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.Module.DjyRulesEngine
{

@ -1,16 +1,22 @@
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
{
static readonly ApiFox api;
static RuleEngineService()
{
api = new ApiFox(60);
}
private readonly IServiceProvider _serviceProvider;
private readonly string ip;
private readonly int port;
@ -59,5 +65,30 @@ namespace DS.Module.DjyRulesEngine
}
/// <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;
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;
}
}
}

@ -69,7 +69,5 @@ namespace DS.WMS.Core.Op.Interface.TaskInteraction
/// <param name="additionalData">附加参数</param>
/// <returns></returns>
Task TriggerActionAsync(BusinessTask businessTask, bool includeOrder = false, IDictionary<string, object>? additionalData = null);
Task<DataResult> TriggerTestAsync(TaskBaseTypeEnum taskType, long? id);
}
}

@ -47,7 +47,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking
});
}
protected async Task SetTaskComplete(ActionExecutionContext context)
protected async Task SetTaskCompleteAsync(ActionExecutionContext context)
{
if (!context.TaskInfo.NextType.HasValue)
return;

@ -41,7 +41,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking
return;
}
await SetTaskComplete(context);
await SetTaskCompleteAsync(context);
}
}
}

@ -2,7 +2,6 @@
using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Entity.TaskInteraction;
using DS.WMS.Core.Op.Interface;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using Masuit.Tools;
using Masuit.Tools.Systems;
@ -80,7 +79,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking
return;
}
await SetTaskComplete(context);
await SetTaskCompleteAsync(context);
}
}

@ -112,7 +112,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
//未设置查询字段
if (fields == null || fields.Length == 0)
{
biz = await TenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId)).Where(a => a.Id == businessId)
biz = await TenantDb.Queryable<SeaExport>().Where(a => a.Id == businessId)
.Select<SeaExportRes>().Mapper(it =>
{
it.DischargePortCountry = TenantDb.Queryable<CodePort>().Where(x => x.Id == it.DischargePortId).Select(x => x.CountryName).First();
@ -121,7 +121,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
else
{
var selectors = fields.Select(x => new SelectModel { FieldName = x }).ToList();
biz = await TenantDb.Queryable<object>().AS("op_sea_export").ClearFilter(typeof(IOrgId))
biz = await TenantDb.Queryable<object>().AS("op_sea_export")
.Where("Id=@Id", new { Id = businessId }).Select(selectors).FirstAsync();
}
break;
@ -264,30 +264,5 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
await logService.WriteLogAsync(context.TaskInfo, $"开始运行后台任务({currentExecutor.GetType().FullName}...");
await currentExecutor.ExecuteAsync(context);
}
public async Task<DataResult> TriggerTestAsync(TaskBaseTypeEnum taskType, long? id)
{
var task = await TenantDb.Queryable<BusinessTask>()
.Where(t => t.TaskType == taskType
//&& SqlFunc.Subqueryable<SeaExport>().Where(s => t.BusinessId == s.Id && s.BillSubmitStatus == AuditStatusEnum.Approve).Any()
)
//.Where(x => x.TaskStatus == TaskStatusEnum.Complete)
.WhereIF(id.HasValue, x => x.BusinessId == id)
.OrderByDescending(t => SqlFunc.GetRandom()).Take(1).FirstAsync();
if (task != null)
{
TaskFlowDataContext dataContext = new(
(TaskFlowDataNameConst.BusinessTask, task)
);
TaskFlowRuner taskFlow = new(TenantDb, ServiceProvider);
await taskFlow.RunWithBsno(task.TaskType, task.BusinessId, dataContext);
return DataResult.Success;
}
var result = DataResult.Failed("找不到指定类型的任务");
result.Data = 404;
return result;
}
}
}

@ -211,11 +211,11 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
string url = config["TaskMail:FileBaseUrl"] + @"/PrintTempFile/" + reqResult.Data.Data;
var fileResult = await Api.SendRequestAsync(HttpMethod.Get, url);
if (!fileResult.Succeeded)
if (!fileResult.IsSuccessStatusCode)
return DataResult.Failed($"未能获取打印API生成的文件附件地址{url}");
string fileName = item.FileName.IsNullOrEmpty() ? Path.GetFileName(reqResult.Data.Data) : item.FileName;
var byteArray = await fileResult.Data.Content.ReadAsByteArrayAsync();
string? fileName = item.FileName.IsNullOrEmpty() ? Path.GetFileName(reqResult.Data.Data) : item.FileName;
var byteArray = await fileResult.Content.ReadAsByteArrayAsync();
string base64Str = Convert.ToBase64String(byteArray);
attachmentList.Add(new Tuple<string, string>(fileName, base64Str));
}
@ -260,13 +260,13 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
}];
var mailResult = await Api.SendRequestAsync(HttpMethod.Post, config["TaskMail:MailApiUrl"], mailParams);
if (mailResult.Data.IsSuccessStatusCode)
if (mailResult.IsSuccessStatusCode)
{
return DataResult.Successed($"已发邮件(委托单:{order.CustomerNo}),收件人:"
+ string.Join(",", sendTo) + "发件人:" + senderConfig.MailAccount);
}
return DataResult.Failed($"邮件发送失败API返回状态为{(int)mailResult.Data.StatusCode} {mailResult.Data.StatusCode}"
return DataResult.Failed($"邮件发送失败API返回状态为{(int)mailResult.StatusCode} {mailResult.StatusCode}"
+ $"(委托单:{order.CustomerNo}),收件人:" + string.Join(",", sendTo) + "发件人:" + senderConfig.MailAccount);
}
catch (Exception ex)

@ -140,6 +140,20 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
await CreateSubTaskAsync(list.FindAll(x => x.TaskType != TaskBaseTypeEnum.NOT_SPECIFIED).OrderBy(x => x.TaskType));
}
/// <summary>
/// 创建关联子任务
/// </summary>
/// <param name="dataContext"></param>
/// <returns></returns>
public async Task CreateSubTaskAsync(TaskFlowDataContext dataContext)
{
ArgumentNullException.ThrowIfNull(dataContext, nameof(dataContext));
var task = dataContext.GetOrDefault<BusinessTask>(TaskFlowDataNameConst.BusinessTask);
if (task != null)
await CreateSubTaskAsync(task);
}
///// <summary>
///// 当任务状态发生变化时调用
///// </summary>

@ -1,7 +1,8 @@
using System;
using System.Text;
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Helpers;
using DS.Module.DjyRulesEngine;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core.Flow.Interface;
@ -12,16 +13,17 @@ using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Entity.TaskInteraction;
using DS.WMS.Core.Op.Interface;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using DS.WMS.Core.Op.Method.TaskInteraction.ActionSelector;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.TaskPlat;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
using Mapster;
using Masuit.Tools;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using static DS.WMS.Core.Op.Method.TaskInteraction.ActionSelector.BookingSelector;
namespace DS.WMS.Core.Op.Method.TaskInteraction
{
@ -56,7 +58,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// <summary>
/// 工作流服务
/// </summary>
protected IClientFlowInstanceService FlowService { get; private set; }
protected Lazy<IClientFlowInstanceService> FlowService { get; private set; }
/// <summary>
/// 动作服务
@ -73,6 +75,11 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// </summary>
protected IClientParamService ClientParamService { get; private set; }
/// <summary>
/// 规则引擎服务
/// </summary>
protected Lazy<IRuleEngineService> RuleEngineService { get; private set; }
/// <summary>
/// 初始化
/// </summary>
@ -82,11 +89,13 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
ManagerService = provider.GetRequiredService<ITaskManageService>();
LogService = provider.GetRequiredService<ITaskLogService>();
TaskAllocationService = provider.GetRequiredService<ITaskAllocationService>();
FlowService = provider.GetRequiredService<IClientFlowInstanceService>();
ActionService = provider.GetRequiredService<IActionManagerService>();
OpService = provider.GetRequiredService<ISeaExportService>();
ClientParamService = provider.GetRequiredService<IClientParamService>();
FlowService = new Lazy<IClientFlowInstanceService>(provider.GetRequiredService<IClientFlowInstanceService>());
RuleEngineService = new Lazy<IRuleEngineService>(provider.GetRequiredService<IRuleEngineService>());
TenantDb.QueryFilter.Clear<IOrgId>();
}
@ -215,6 +224,28 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
//审核任务需创建工作流
if (AuditTaskTypes.Contains(request.TaskType))
{
if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT)
{
var rulesReq = new RuleEngineReq();
rulesReq.Head.MessageType = "BUSI_RULE";
rulesReq.Head.SenderId = "NewOceanBooking";
rulesReq.Head.RequestAction = "CheckRule";
rulesReq.Main.ProjectCode = ["COMMON_OCEAN_BOOKING"];
var order = await TenantDb.Queryable<SeaExport>().Where(x => x.Id == request.BusinessId).FirstAsync();
rulesReq.Main.BusinessInfo = info.Adapt<RulesEngineOrderBookingMainBusinessInfo>();
var ruleResult = await RuleEngineService.Value.ExecuteSeaExportAuditRulesAsync(rulesReq);
if (ruleResult?.Extra.DetailList?.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (var item in ruleResult?.Extra.DetailList)
sb.Append(item.ResultName);
return DataResult.Failed(sb.ToString());
}
}
result = await CreateAndStartWorkflow(task);
if (!result.Succeeded)
return result;
@ -255,7 +286,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (template == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TemplateNotFound));
var result = FlowService.CreateFlowInstance(new CreateFlowInstanceReq
var result = FlowService.Value.CreateFlowInstance(new CreateFlowInstanceReq
{
BusinessId = task.BusinessId,
BusinessType = task.BusinessType,
@ -268,7 +299,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
task.FlowId = instance.Id;
await TenantDb.Updateable(task).UpdateColumns(x => x.FlowId).ExecuteCommandAsync();
result = FlowService.StartFlowInstance(instance.Id.ToString());
result = FlowService.Value.StartFlowInstance(instance.Id.ToString());
instance = result.Data as FlowInstance;
if (result.Succeeded && changeMarker)
@ -365,7 +396,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT)
{
dic = new Dictionary<string, object>();
var param = await ClientParamService.GetParamAsync<string>(task.BusinessId, Booking_Route,
var param = await ClientParamService.GetParamAsync<string>(task.BusinessId, BookingSelector.Booking_Route,
(x, y) => x.CustomerId == y.ForwarderId);
dic[TaskFlowDataNameConst.ClientParam] = param;
}
@ -546,7 +577,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (task.FlowId == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FlowNotFound));
var result = FlowService.AuditFlowInstance(new FlowAuditInfo
var result = FlowService.Value.AuditFlowInstance(new FlowAuditInfo
{
AuditNote = request.Remark,
Status = request.Result,

@ -1,5 +1,4 @@
using System.Net;
using DS.Module.Core;
using DS.Module.Core;
using DS.WMS.Core.Op.Entity.TaskInteraction;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using Microsoft.AspNetCore.Mvc;
@ -22,40 +21,6 @@ namespace DS.WMS.OpApi.Controllers
this.service = service;
}
/// <summary>
/// 运行测试
/// </summary>
/// <param name="actionManager"></param>
/// <param name="taskype">任务类型</param>
/// <param name="id">业务ID</param>
/// <returns></returns>
[HttpGet, Route("RunTest")]
public async Task<IActionResult> RunTestAsync([FromServices] IActionManagerService actionManager,
[FromQuery] TaskBaseTypeEnum taskype, [FromQuery] long? id)
{
HttpStatusCode statusCode;
try
{
var result = await actionManager.TriggerTestAsync(taskype, id);
if (result.Succeeded)
{
statusCode = HttpStatusCode.NoContent;
return new StatusCodeResult((int)statusCode);
}
return new ContentResult
{
Content = result.Message,
StatusCode = result.Data == null ? null : (int)result.Data
};
}
catch
{
statusCode = HttpStatusCode.InternalServerError;
return new StatusCodeResult((int)statusCode);
}
}
/// <summary>
/// 获取分页列表
/// </summary>

Loading…
Cancel
Save