jianghaiqing 4 months ago
commit 2d94483bcd

@ -1400,4 +1400,9 @@ public static class MultiLanguageConst
#endregion #endregion
#region 关联任务
[Description("此类型的任务已存在")]
public const string Task_Exists = "Task_Exists";
#endregion
} }

@ -183,57 +183,101 @@ namespace DS.Module.Core
TRNAS_PLAN_HAS_CHANGE = 30, TRNAS_PLAN_HAS_CHANGE = 30,
#region 工作流--主要流程
/// <summary> /// <summary>
/// 待审单 /// 待审单
/// </summary> /// </summary>
[Description("待审单")] [Description("待审单")]
WAIT_ORDER_AUDIT = 31, WAIT_ORDER_AUDIT = 201,
/// <summary>
/// 待收BC
/// </summary>
[Description("待收BC")]
WAIT_BC = 32,
/// <summary> /// <summary>
/// 待订舱 /// 待订舱
/// </summary> /// </summary>
[Description("待订舱")] [Description("待订舱")]
WAIT_BOOKING = 33, WAIT_BOOKING = 202,
/// <summary>
/// 待收BC
/// </summary>
[Description("待收BC")]
WAIT_BC = 203,
/// <summary> /// <summary>
/// 待放舱 /// 待放舱
/// </summary> /// </summary>
[Description("待放舱")] [Description("待放舱")]
WAIT_SPACE_RELEASE = 34, WAIT_SPACE_RELEASE = 204,
/// <summary> /// <summary>
/// 待提单确认 /// 待提单确认
/// </summary> /// </summary>
[Description("待提单确认")] [Description("待提单确认")]
WAIT_BILL_CONFIRM = 35, WAIT_BILL_CONFIRM = 205,
/// <summary> /// <summary>
/// 待提交SI /// 待提交SI
/// </summary> /// </summary>
[Description("待提交SI")] [Description("待提交SI")]
WAIT_SI = 36, WAIT_SI = 206,
/// <summary> /// <summary>
/// 待处理Draft /// 待处理Draft
/// </summary> /// </summary>
[Description("待处理Draft")] [Description("待处理Draft")]
WAIT_DRAFT = 37, WAIT_DRAFT = 207,
/// <summary>
/// 待放单
/// </summary>
[Description("待放单")]
WAIT_CHECKOUT_BILL = 208,
#endregion
#region 工作流--可选服务项目
/// <summary> /// <summary>
/// 待签出提单 /// 待报关
/// </summary> /// </summary>
[Description("待签出提单")] [Description("待报关")]
WAIT_CHECKOUT_BILL = 38, WAIT_BAOGUAN = 301,
/// <summary> /// <summary>
/// 待派车 /// 待发舱单
/// </summary> /// </summary>
[Description("待派车")] [Description("待发舱单")]
WAIT_TRUCK_DISPATCH = 39, WAIT_CANGDAN = 302,
/// <summary> /// <summary>
/// 待提交VGM /// 待提交VGM
/// </summary> /// </summary>
[Description("待提交VGM")] [Description("待提交VGM")]
WAIT_VGM = 40 WAIT_VGM = 303,
/// <summary>
/// 待发AFR
/// </summary>
[Description("待发AFR")]
WAIT_AFR = 304,
/// <summary>
/// 待发AMS
/// </summary>
[Description("待发AMS")]
WAIT_AMS = 305,
/// <summary>
/// 待发ISF
/// </summary>
[Description("待发ISF")]
WAIT_ISF = 306,
/// <summary>
/// 待熏蒸
/// </summary>
[Description("待熏蒸")]
WAIT_XUNZHENG = 307,
/// <summary>
/// 待报商检
/// </summary>
[Description("待报商检")]
WAIT_SHANGJIAN = 308,
/// <summary>
/// 待报COA
/// </summary>
[Description("待报COA")]
WAIT_COA = 309,
/// <summary>
/// 待出产地证
/// </summary>
[Description("待出产地证")]
WAIT_CHANDIZHENG = 310,
#endregion
} }
} }

@ -1,4 +1,5 @@
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Net.Http.Headers;
using System.Text; using System.Text;
using DS.Module.Core.Extensions; using DS.Module.Core.Extensions;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -20,6 +21,16 @@ namespace DS.Module.Core
/// </summary> /// </summary>
public IDictionary<string, string> DefaultHeaders { get; private set; } public IDictionary<string, string> DefaultHeaders { get; private set; }
/// <summary>
/// 在发送网络请求之前的事件
/// </summary>
public event EventHandler<BeforeSendEventArgs>? BeforeSend;
/// <summary>
/// 在发送网络请求完成时的事件
/// </summary>
public event EventHandler<CompleteEventArgs>? Completed;
/// <summary> /// <summary>
/// 初始化 /// 初始化
/// </summary> /// </summary>
@ -100,7 +111,7 @@ namespace DS.Module.Core
/// <returns></returns> /// <returns></returns>
/// <exception cref="ArgumentNullException"><paramref name="method"/>为null</exception> /// <exception cref="ArgumentNullException"><paramref name="method"/>为null</exception>
/// <exception cref="ArgumentException"><paramref name="url"/>为null或空字符串</exception> /// <exception cref="ArgumentException"><paramref name="url"/>为null或空字符串</exception>
public virtual async Task<DataResult<HttpResponseMessage>> SendRequestAsync(HttpMethod method, string url, object? requestParams = null) public async Task<DataResult<HttpResponseMessage>> SendRequestAsync(HttpMethod method, string url, object? requestParams = null)
{ {
ArgumentNullException.ThrowIfNull(method); ArgumentNullException.ThrowIfNull(method);
ArgumentException.ThrowIfNullOrEmpty(url); ArgumentException.ThrowIfNullOrEmpty(url);
@ -128,6 +139,13 @@ namespace DS.Module.Core
if (!http.DefaultRequestHeaders.Contains("Accept")) if (!http.DefaultRequestHeaders.Contains("Accept"))
http.DefaultRequestHeaders.Add("Accept", "application/json, text/plain"); http.DefaultRequestHeaders.Add("Accept", "application/json, text/plain");
OnBeforeSend(new BeforeSendEventArgs
{
RequestHeaders = http.DefaultRequestHeaders,
RequestParameter = requestParams,
RequestUri = reqUri
});
try try
{ {
HttpResponseMessage? response = null; HttpResponseMessage? response = null;
@ -154,6 +172,12 @@ namespace DS.Module.Core
throw new NotSupportedException($"不支持的请求方法:{method.Method}"); throw new NotSupportedException($"不支持的请求方法:{method.Method}");
} }
OnCompleted(new CompleteEventArgs
{
RequestUri = reqUri,
Response = response
});
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
return DataResult<HttpResponseMessage>.FailedData(response, string.Format(MultiLanguageConst.HttpRequestFailed, $"{response.StatusCode}")); return DataResult<HttpResponseMessage>.FailedData(response, string.Format(MultiLanguageConst.HttpRequestFailed, $"{response.StatusCode}"));
@ -164,5 +188,60 @@ namespace DS.Module.Core
http?.Dispose(); http?.Dispose();
} }
} }
/// <summary>
/// 在发送网络请求之前调用
/// </summary>
/// <param name="e">事件参数</param>
protected virtual void OnBeforeSend(BeforeSendEventArgs e)
{
BeforeSend?.Invoke(this, e);
}
/// <summary>
/// 在发送网络请求完成时调用
/// </summary>
/// <param name="e">事件参数</param>
protected virtual void OnCompleted(CompleteEventArgs e)
{
Completed?.Invoke(this, e);
}
}
/// <summary>
/// 发送网络请求之前的事件参数
/// </summary>
public class BeforeSendEventArgs : EventArgs
{
/// <summary>
/// 远程请求的URI
/// </summary>
public Uri RequestUri { get; internal set; }
/// <summary>
/// 请求标头
/// </summary>
public HttpRequestHeaders RequestHeaders { get; internal set; }
/// <summary>
/// 请求参数
/// </summary>
public object? RequestParameter { get; set; }
}
/// <summary>
/// 发送网络请求完成的事件参数
/// </summary>
public class CompleteEventArgs : EventArgs
{
/// <summary>
/// 远程请求的URI
/// </summary>
public Uri RequestUri { get; internal set; }
/// <summary>
/// 网络响应对象
/// </summary>
public HttpResponseMessage Response { get; internal set; }
} }
} }

@ -485,7 +485,7 @@ namespace DS.WMS.Core.Application.Method
return DataResult.Failed(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.NoNeedWithdraw)), msg)); return DataResult.Failed(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.NoNeedWithdraw)), msg));
} }
var flows = list.Select(x => new FlowInstance { Id = x.FlowId.Value, FlowStatus = (int)FlowStatusEnum.Draft, MakerList = string.Empty }).ToList(); var flows = list.Select(x => new FlowInstance { Id = x.FlowId.Value, FlowStatus = FlowStatusEnum.Draft, MakerList = string.Empty }).ToList();
DateTime dtNow = DateTime.Now; DateTime dtNow = DateTime.Now;
try try
{ {

@ -566,7 +566,7 @@ namespace DS.WMS.Core.Fee.Method
return DataResult.Failed(string.Format(MultiLanguageConst.NoNeedWithdraw, msg)); return DataResult.Failed(string.Format(MultiLanguageConst.NoNeedWithdraw, msg));
} }
var flows = fees.Select(x => new FlowInstance { Id = x.FlowId.Value, FlowStatus = (int)FlowStatusEnum.Draft, MakerList = string.Empty }).ToList(); var flows = fees.Select(x => new FlowInstance { Id = x.FlowId.Value, FlowStatus = FlowStatusEnum.Draft, MakerList = string.Empty }).ToList();
DateTime dtNow = DateTime.Now; DateTime dtNow = DateTime.Now;
await TenantDb.Ado.BeginTranAsync(); await TenantDb.Ado.BeginTranAsync();
try try

@ -27,11 +27,6 @@ namespace DS.WMS.Core.Fee.Method
/// </summary> /// </summary>
public const string USD_CODE = "USD"; public const string USD_CODE = "USD";
/// <summary>
/// 工作流运行状态值
/// </summary>
public static readonly int RunningStatus = (int)FlowStatusEnum.Running;
/// <summary> /// <summary>
/// 获取用户相关信息 /// 获取用户相关信息
/// </summary> /// </summary>
@ -294,7 +289,7 @@ namespace DS.WMS.Core.Fee.Method
/// <returns></returns> /// <returns></returns>
protected ISugarQueryable<FlowInstance> GetCurrentFlowsQuery(string[] auditTypes) protected ISugarQueryable<FlowInstance> GetCurrentFlowsQuery(string[] auditTypes)
{ {
return Db.Queryable<FlowInstance>().Where(x => x.FlowStatus == RunningStatus return Db.Queryable<FlowInstance>().Where(x => x.FlowStatus == FlowStatusEnum.Running
&& SqlFunc.SplitIn(x.MakerList, User.UserId) && auditTypes.Contains(x.AuditType)) && SqlFunc.SplitIn(x.MakerList, User.UserId) && auditTypes.Contains(x.AuditType))
.Select(x => new FlowInstance { Id = x.Id, BusinessId = x.BusinessId, BusinessType = x.BusinessType }); .Select(x => new FlowInstance { Id = x.Id, BusinessId = x.BusinessId, BusinessType = x.BusinessType });
} }

@ -17,6 +17,9 @@ public class FlowInstance : BaseTenantModel<long>
[Description("业务Id")] [Description("业务Id")]
public long BusinessId { get; set; } public long BusinessId { get; set; }
/// <summary>
/// 业务类型
/// </summary>
[Description("业务类型")] [Description("业务类型")]
public BusinessType? BusinessType { get; set; } public BusinessType? BusinessType { get; set; }
@ -68,7 +71,7 @@ public class FlowInstance : BaseTenantModel<long>
/// 工作流状态 /// 工作流状态
/// </summary> /// </summary>
[Description("工作流状态")] [Description("工作流状态")]
public int FlowStatus { get; set; } = FlowStatusEnum.Ready.ToEnumInt(); public FlowStatusEnum FlowStatus { get; set; } = FlowStatusEnum.Ready;
/// <summary> /// <summary>
/// 中文视图名;设计方案时,提供中文字段的视图来源 /// 中文视图名;设计方案时,提供中文字段的视图来源
@ -86,7 +89,7 @@ public class FlowInstance : BaseTenantModel<long>
/// 回调地址 /// 回调地址
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "回调地址", IsNullable = true, Length = 255)] [SugarColumn(ColumnDescription = "回调地址", IsNullable = true, Length = 255)]
public string CallbackURL { get; set; } public string? CallbackURL { get; set; }
/// <summary> /// <summary>
/// 审批类型 /// 审批类型

@ -80,7 +80,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
/// <returns></returns> /// <returns></returns>
public DataResult<List<FlowInstanceRes>> GetFlowInstances(long businessId, BusinessType? businessType) public DataResult<List<FlowInstanceRes>> GetFlowInstances(long businessId, BusinessType? businessType)
{ {
var query = db.Queryable<FlowInstance>().Where(x => x.BusinessId == businessId && x.FlowStatus != 1); var query = db.Queryable<FlowInstance>().Where(x => x.BusinessId == businessId && x.FlowStatus != FlowStatusEnum.Running);
if (businessType.HasValue) if (businessType.HasValue)
query = query.Where(x => x.BusinessType == businessType.Value); query = query.Where(x => x.BusinessType == businessType.Value);
@ -112,7 +112,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
if (info == null) if (info == null)
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist); return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
if (info.Instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt()) if (info.Instance.FlowStatus == FlowStatusEnum.Approve)
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished); return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
return AuditFlowCore(info.Status, info.AuditNote, info.Instance); return AuditFlowCore(info.Status, info.AuditNote, info.Instance);

@ -24,6 +24,8 @@ public class FlowInstanceService : IFlowInstanceService
protected readonly IUser user; protected readonly IUser user;
private readonly ICommonService _commonService; private readonly ICommonService _commonService;
private ApiFox api;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -34,6 +36,14 @@ public class FlowInstanceService : IFlowInstanceService
db = _serviceProvider.GetRequiredService<ISqlSugarClient>(); db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>(); user = _serviceProvider.GetRequiredService<IUser>();
_commonService = _serviceProvider.GetRequiredService<ICommonService>(); _commonService = _serviceProvider.GetRequiredService<ICommonService>();
api = new ApiFox();
api.BeforeSend += Api_BeforeSend;
}
private void Api_BeforeSend(object? sender, BeforeSendEventArgs e)
{
e.RequestHeaders.Add("Authorization", "Bearer " + user.GetToken());
} }
public DataResult<List<FlowInstanceRes>> GetListByPage(PageRequest request) public DataResult<List<FlowInstanceRes>> GetListByPage(PageRequest request)
@ -57,7 +67,7 @@ public class FlowInstanceService : IFlowInstanceService
{ {
var info = db.Queryable<FlowInstance>().Where(x => x.Id == req.Id).First(); var info = db.Queryable<FlowInstance>().Where(x => x.Id == req.Id).First();
if (!(info.FlowStatus == FlowStatusEnum.Draft.ToEnumInt() || info.FlowStatus == FlowStatusEnum.Ready.ToEnumInt())) if (!(info.FlowStatus == FlowStatusEnum.Draft || info.FlowStatus == FlowStatusEnum.Ready))
{ {
return DataResult.Failed("只能修改【就绪】和【撤销】状态的流程", MultiLanguageConst.FlowEditOnlyReadyAndCancel); return DataResult.Failed("只能修改【就绪】和【撤销】状态的流程", MultiLanguageConst.FlowEditOnlyReadyAndCancel);
} }
@ -129,7 +139,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityName = wfruntime.CurrentNode.Name; instance.ActivityName = wfruntime.CurrentNode.Name;
instance.PreviousId = ""; instance.PreviousId = "";
instance.MakerList = GetCurrentMakers(wfruntime); instance.MakerList = GetCurrentMakers(wfruntime);
instance.FlowStatus = FlowStatusEnum.Ready.ToEnumInt(); instance.FlowStatus = FlowStatusEnum.Ready;
wfruntime.FlowInstanceId = instance.Id; wfruntime.FlowInstanceId = instance.Id;
@ -176,7 +186,7 @@ public class FlowInstanceService : IFlowInstanceService
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist); return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
} }
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt()) if (instance.FlowStatus == FlowStatusEnum.Approve)
{ {
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished); return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
} }
@ -195,7 +205,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityName = wfruntime.ChildNodes.First(x => x.Id == startNodeId).Name; instance.ActivityName = wfruntime.ChildNodes.First(x => x.Id == startNodeId).Name;
instance.MakerList = instance.MakerList =
(wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1"); (wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1");
instance.FlowStatus = FlowStatusEnum.Draft.ToEnumInt(); instance.FlowStatus = FlowStatusEnum.Draft;
wfruntime.FlowInstanceId = instance.Id; wfruntime.FlowInstanceId = instance.Id;
@ -242,7 +252,7 @@ public class FlowInstanceService : IFlowInstanceService
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist); return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
} }
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt()) if (instance.FlowStatus == FlowStatusEnum.Approve)
{ {
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished); return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
} }
@ -258,9 +268,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.PreviousId = wfruntime.CurrentNodeId; instance.PreviousId = wfruntime.CurrentNodeId;
instance.MakerList = instance.MakerList =
(wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "1"); (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "1");
instance.FlowStatus = (wfruntime.GetNextNodeType() == 4 instance.FlowStatus = (wfruntime.GetNextNodeType() == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running);
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt());
wfruntime.FlowInstanceId = instance.Id; wfruntime.FlowInstanceId = instance.Id;
@ -293,7 +301,7 @@ public class FlowInstanceService : IFlowInstanceService
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist); return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
} }
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt()) if (instance.FlowStatus == FlowStatusEnum.Approve)
{ {
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished); return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
} }
@ -328,7 +336,7 @@ public class FlowInstanceService : IFlowInstanceService
var res = runtime.NodeConfluence(runtime.CurrentNodeId, tag); var res = runtime.NodeConfluence(runtime.CurrentNodeId, tag);
if (res == TagState.No.ToString("D")) if (res == TagState.No.ToString("D"))
{ {
instance.FlowStatus = FlowStatusEnum.Reject.ToEnumInt(); instance.FlowStatus = FlowStatusEnum.Reject;
} }
else if (!string.IsNullOrEmpty(res)) else if (!string.IsNullOrEmpty(res))
{ {
@ -342,9 +350,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityId = runtime.NextNodeId; instance.ActivityId = runtime.NextNodeId;
instance.ActivityType = runtime.NextNodeType; instance.ActivityType = runtime.NextNodeType;
instance.ActivityName = runtime.NextNode.Name; instance.ActivityName = runtime.NextNode.Name;
instance.FlowStatus = runtime.NextNodeType == 4 instance.FlowStatus = runtime.NextNodeType == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running;
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt();
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime); instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
} }
// AddTransHistory(wfruntime); // AddTransHistory(wfruntime);
@ -371,13 +377,11 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityType = runtime.NextNodeType; instance.ActivityType = runtime.NextNodeType;
instance.ActivityName = runtime.NextNode.Name; instance.ActivityName = runtime.NextNode.Name;
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime); instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
instance.FlowStatus = (runtime.NextNodeType == 4 instance.FlowStatus = (runtime.NextNodeType == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running);
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt());
} }
else else
{ {
instance.FlowStatus = FlowStatusEnum.Reject.ToEnumInt(); //表示该节点不同意 instance.FlowStatus = FlowStatusEnum.Reject; //表示该节点不同意
runtime.NextNodeId = "-1"; runtime.NextNodeId = "-1";
runtime.NextNodeType = 4; runtime.NextNodeType = 4;
} }
@ -425,13 +429,6 @@ public class FlowInstanceService : IFlowInstanceService
/// <param name="instance">运行实例</param> /// <param name="instance">运行实例</param>
protected virtual async Task RunCallbackAsync(FlowInstance instance) protected virtual async Task RunCallbackAsync(FlowInstance instance)
{ {
if (!Uri.TryCreate(instance.CallbackURL, UriKind.RelativeOrAbsolute, out Uri? uri))
return;
HttpClient http = new HttpClient();
http.DefaultRequestHeaders.Add("User-Agent", "X-HttpClient");
http.DefaultRequestHeaders.Add("Authorization", "Bearer " + user.GetToken());
//请求参数设置 //请求参数设置
var callback = new FlowCallback var callback = new FlowCallback
{ {
@ -442,29 +439,13 @@ public class FlowInstanceService : IFlowInstanceService
FlowStatus = (FlowStatusEnum)instance.FlowStatus, FlowStatus = (FlowStatusEnum)instance.FlowStatus,
RejectReason = instance.Note RejectReason = instance.Note
}; };
var jsonRequest = new StringContent(JsonConvert.SerializeObject(callback), Encoding.UTF8, "application/json");
try
{
var response = await http.PostAsync(uri, jsonRequest);
if (!response.IsSuccessStatusCode)
{
await new HttpRequestException("回调请求失败", null, response.StatusCode).LogAsync(db);
return;
}
//更新回调执行标识 await api.PostAsync<DataResult>(instance.CallbackURL, callback);
var id = instance.Id;
db.Updateable<FlowInstance>().SetColumns(it => new FlowInstance { IsCallbackExecuted = true }) //更新回调执行标识
.Where(it => it.Id == id).ExecuteCommand(); var id = instance.Id;
} await db.Updateable<FlowInstance>().SetColumns(it => new FlowInstance { IsCallbackExecuted = true })
catch (Exception ex) .Where(it => it.Id == id).ExecuteCommandAsync();
{
await ex.LogAsync(db);
}
finally
{
http?.Dispose();
}
} }
protected virtual FlowRuntime CreateRuntimeService(FlowInstance instance) protected virtual FlowRuntime CreateRuntimeService(FlowInstance instance)

@ -1,149 +0,0 @@
using System.Runtime.Serialization;
using DS.Module.Core;
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
/// <summary>
/// 任务台创建参数
/// </summary>
public class TaskCreation
{
[DataMember(Name = "head")]
public TaskHeader Head { get; set; }
[DataMember(Name = "main")]
public TaskMain Main { get; set; }
public TaskCreation()
{
Head = new TaskHeader();
Main = new TaskMain();
}
}
/// <summary>
/// 任务标头
/// </summary>
public class TaskHeader
{
/// <summary>
/// 流水ID
/// </summary>
[DataMember(Name = "gid")]
public Guid GID { get; set; } = Guid.NewGuid();
/// <summary>
/// 订单Id
/// </summary>
[DataMember(Name = "bsno")]
public long BSNO { get; set; }
/// <summary>
/// 消息类型
/// </summary>
[DataMember(Name = "messageType")]
public string MessageType { get; set; } = "WORK_FLOW_TASK";
[DataMember(Name = "senderId")]
public string SenderId { get; set; } = "WorkFlow";
[DataMember(Name = "senderName")]
public string SenderName { get; set; } = "工作流平台";
[DataMember(Name = "receiverId")]
public string ReceiverId { get; set; } = "TaskManage";
[DataMember(Name = "receiverName")]
public string ReceiverName { get; set; } = "任务管理平台";
/// <summary>
/// 标识符
/// </summary>
[DataMember(Name = "token")]
public string? Token { get; set; }
/// <summary>
/// 版本
/// </summary>
[DataMember(Name = "version")]
public string? Version { get; set; } = "1.0";
/// <summary>
/// 请求时间
/// </summary>
[DataMember(Name = "requestDate")]
public DateTime RequestDate { get; set; } = DateTime.Now;
[DataMember(Name = "senderKey")]
public string? SenderKey { get; set; }
[DataMember(Name = "requestAction")]
public string? RequestAction { get; set; } = "Add";
}
/// <summary>
/// 任务主信息
/// </summary>
public class TaskMain
{
/// <summary>
/// 任务类型
/// </summary>
[DataMember(Name = "taskType")]
public TaskBaseTypeEnum TaskType { get; set; }
/// <summary>
/// 任务来源
/// </summary>
[DataMember(Name = "taskSource")]
public int TaskSource { get; set; } = 9;
/// <summary>
/// 任务标题
/// </summary>
[DataMember(Name = "taskTitle")]
public string TaskTitle { get; set; } = string.Empty;
/// <summary>
/// 任务描述
/// </summary>
[DataMember(Name = "taskDesp")]
public string? TaskDescription { get; set; }
/// <summary>
/// 任务创建者ID
/// </summary>
[DataMember(Name = "taskUserId")]
public long TaskUserId { get; set; }
/// <summary>
/// 任务创建者
/// </summary>
[DataMember(Name = "taskUserName")]
public string? TaskUserName { get; set; }
/// <summary>
/// 任务接收者ID
/// </summary>
[DataMember(Name = "recvUserId")]
public long RecvUserId { get; set; }
/// <summary>
/// 任务创建者
/// </summary>
[DataMember(Name = "recvUserName")]
public string? RecvUserName { get; set; }
/// <summary>
/// 任务租户ID
/// </summary>
[DataMember(Name = "taskTenatId")]
public long TaskTenatId { get; set; }
/// <summary>
/// 任务租户
/// </summary>
[DataMember(Name = "taskTenatName")]
public string? TaskTenatName { get; set; }
}
}

@ -0,0 +1,36 @@
using DS.Module.Core;
using DS.WMS.Core.Op.Entity;
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
/// <summary>
/// 任务台创建参数
/// </summary>
public class TaskCreationRequest
{
/// <summary>
/// 业务ID
/// </summary>
public long BusinessId { get; set; }
/// <summary>
/// 业务类型
/// </summary>
public BusinessType BusinessType { get; set; }
/// <summary>
/// 任务类型
/// </summary>
public TaskBaseTypeEnum TaskType { get; set; }
/// <summary>
/// 任务标题
/// </summary>
public string TaskTitle { get; set; } = string.Empty;
/// <summary>
/// 任务描述
/// </summary>
public string? TaskDescription { get; set; }
}
}

@ -0,0 +1,31 @@
using DS.Module.Core;
using DS.WMS.Core.Op.Entity;
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
/// <summary>
/// 任务台状态更新参数
/// </summary>
public class TaskUpdateRequest
{
/// <summary>
/// 业务ID
/// </summary>
public long BusinessId { get; set; }
/// <summary>
/// 业务类型
/// </summary>
public BusinessType BusinessType { get; set; }
/// <summary>
/// 任务类型
/// </summary>
public TaskBaseTypeEnum TaskType { get; set; }
/// <summary>
/// 任务状态
/// </summary>
public TaskStatusEnum TaskStatus { get; set; }
}
}

@ -0,0 +1,66 @@
using DS.Module.Core;
using SqlSugar;
namespace DS.WMS.Core.Op.Entity.TaskInteraction
{
/// <summary>
/// 业务任务交互表
/// </summary>
[SugarTable("business_task", "业务任务交互表")]
public class BusinessTask
{
/// <summary>
/// ID
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 业务ID
/// </summary>
[SugarColumn(ColumnDescription = "业务ID", IsNullable = false)]
public long BusinessId { get; set; }
/// <summary>
/// 业务类型
/// </summary>
[SugarColumn(ColumnDescription = "业务类型", IsNullable = false)]
public BusinessType BusinessType { get; set; }
/// <summary>
/// 任务类型
/// </summary>
[SugarColumn(ColumnDescription = "任务类型", IsNullable = false)]
public TaskBaseTypeEnum TaskType { get; set; }
/// <summary>
/// 任务状态
/// </summary>
[SugarColumn(ColumnDescription = "任务状态", IsNullable = false)]
public TaskStatusEnum TaskStatus { get; set; }
/// <summary>
/// 下一任务类型
/// </summary>
[SugarColumn(ColumnDescription = "下一任务类型", IsNullable = true)]
public TaskBaseTypeEnum? NextType { get; set; }
/// <summary>
/// 工作流ID
/// </summary>
[SugarColumn(ColumnDescription = "工作流ID", IsNullable = true)]
public long? FlowId { get; set; }
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnDescription = "创建人", IsNullable = false)]
public long CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnDescription = "创建时间", IsNullable = false)]
public DateTime CreateTime { get; set; }
}
}

@ -1,4 +1,15 @@
using DS.WMS.Core.Fee.Method; using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Fee.Method;
using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Entity.TaskInteraction;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Interface;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.Op.Method.TaskInteraction namespace DS.WMS.Core.Op.Method.TaskInteraction
{ {
@ -7,14 +18,179 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// </summary> /// </summary>
public class SeaExportTaskService : FeeServiceBase public class SeaExportTaskService : FeeServiceBase
{ {
ITaskManageService taskService;
/// <summary> /// <summary>
/// 初始化 /// 初始化
/// </summary> /// </summary>
/// <param name="provider"></param> /// <param name="provider"></param>
public SeaExportTaskService(IServiceProvider provider) : base(provider) public SeaExportTaskService(IServiceProvider provider) : base(provider)
{ {
taskService = provider.GetRequiredService<ITaskManageService>();
}
/// <summary>
/// 创建关联任务
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<DataResult> CreateTaskAsync(TaskCreationRequest request)
{
var task = await GetTaskAsync(request.BusinessId, request.BusinessType, request.TaskType);
if (task != null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Task_Exists));
long tenatId = long.Parse(User.TenantId);
string tenatName = Db.Queryable<SysTenant>().Where(x => x.Id == tenatId).Select(x => x.Name).First();
var info = new TaskManageOrderMessageInfo
{
Head = new TaskManageOrderMessageHeadInfo
{
GID = Guid.NewGuid().ToString(),
BSNO = request.BusinessId,
MessageType = "WORK_FLOW_TASK",
SenderId = "WorkFlow",
SenderName = "工作流平台",
ReceiverId = "TaskManage",
ReceiverName = "任务管理平台",
Version = "1.0",
RequestDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
RequestAction = "Add"
},
Main = new TaskManageOrderMessageMainInfo
{
TaskType = request.TaskType,
TaskSource = TaskSourceEnum.WORK_FLOW,
TaskTitle = request.TaskTitle,
TaskDesp = request.TaskDescription,
TaskUserId = User.UserId,
TaskUserName = User.UserName,
RecvUserId = User.UserId,
RecvUserName = User.UserName,
TaskTenatId = tenatId,
TaskTenatName = tenatName
}
};
if (info.Main.TaskTitle.IsNullOrEmpty())
{
var biz = await TenantDb.Queryable<SeaExport>().Select(x => new
{
x.Id,
x.MBLNO,
x.Vessel,
x.Voyno,
x.ETD,
}).FirstAsync();
info.Main.TaskDesp = info.Main.TaskTitle = $"{request.TaskType.GetDescription()} {biz.Vessel} {biz.Voyno} ETD:{biz.ETD?.ToString("yyyy-MM-dd")} BLNo:{biz.MBLNO}";
}
await TenantDb.Ado.BeginTranAsync();
try
{
var result = await taskService.InitTaskJob(info);
if (!result.Succeeded)
return result;
var businessTask = new BusinessTask
{
BusinessId = request.BusinessId,
BusinessType = request.BusinessType,
TaskType = request.TaskType,
TaskStatus = TaskStatusEnum.Create,
CreateBy = long.Parse(User.UserId),
CreateTime = DateTime.Now
};
businessTask.NextType = GetNextType(businessTask);
await TenantDb.Insertable(businessTask).ExecuteCommandAsync();
if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT)
{
//待审核,需创建工作流
}
else if (request.TaskType == TaskBaseTypeEnum.WAIT_BILL_CONFIRM)
{
//根据业务所选服务,生成子任务
}
return DataResult.Success;
}
catch (Exception ex)
{
await TenantDb.Ado.RollbackTranAsync();
await ex.LogAsync(Db);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
/// <summary>
/// 设置任务状态
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<DataResult> UpdateTaskStatusAsync(TaskUpdateRequest request)
{
await TenantDb.Ado.BeginTranAsync();
try
{
var result = await taskService.SetTaskStatus(request.BusinessId, request.TaskType, request.TaskStatus, DateTime.Now);
if (!result.Succeeded)
return result;
//更新当前任务状态
BusinessTask task = await GetTaskAsync(request.BusinessId, request.BusinessType, request.TaskType);
if (task == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
task.TaskStatus = request.TaskStatus;
await TenantDb.Updateable(task).UpdateColumns(x => x.TaskStatus).ExecuteCommandAsync();
//若存在下一任务,则创建
if (task.NextType.HasValue)
{
var req = new TaskCreationRequest
{
BusinessId = request.BusinessId,
BusinessType = request.BusinessType,
TaskType = task.NextType.Value
};
await CreateTaskAsync(req);
}
return DataResult.Success;
}
catch (Exception ex)
{
await TenantDb.Ado.RollbackTranAsync();
await ex.LogAsync(Db);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
} }
internal async Task<BusinessTask> GetTaskAsync(long id, BusinessType businessType, TaskBaseTypeEnum taskType)
{
return await TenantDb.Queryable<BusinessTask>().FirstAsync(x =>
x.BusinessId == id && x.BusinessType == businessType && x.TaskType == taskType);
}
internal async Task<BusinessTask> GetCurrentTaskAsync(long id, BusinessType businessType)
{
return await TenantDb.Queryable<BusinessTask>().Where(x => x.BusinessId == id && x.BusinessType == businessType)
.OrderByDescending(x => x.CreateTime).Take(1).FirstAsync();
}
internal static TaskBaseTypeEnum? GetNextType(BusinessTask current)
{
if (current.TaskType == TaskBaseTypeEnum.WAIT_VGM)
return null;
int currentTypeVal = (int)current.TaskType;
return (TaskBaseTypeEnum)currentTypeVal++;
}
} }
} }

Loading…
Cancel
Save