工作流状态更改为枚举

usertest
嵇文龙 4 months ago
parent 4193489bc3
commit cb86573add

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

@ -1,4 +1,5 @@
using System.Collections.Specialized;
using System.Net.Http.Headers;
using System.Text;
using DS.Module.Core.Extensions;
using Newtonsoft.Json;
@ -20,6 +21,16 @@ namespace DS.Module.Core
/// </summary>
public IDictionary<string, string> DefaultHeaders { get; private set; }
/// <summary>
/// 在发送网络请求之前的事件
/// </summary>
public event EventHandler<BeforeSendEventArgs>? BeforeSend;
/// <summary>
/// 在发送网络请求完成时的事件
/// </summary>
public event EventHandler<CompleteEventArgs>? Completed;
/// <summary>
/// 初始化
/// </summary>
@ -100,7 +111,7 @@ namespace DS.Module.Core
/// <returns></returns>
/// <exception cref="ArgumentNullException"><paramref name="method"/>为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);
ArgumentException.ThrowIfNullOrEmpty(url);
@ -128,6 +139,13 @@ namespace DS.Module.Core
if (!http.DefaultRequestHeaders.Contains("Accept"))
http.DefaultRequestHeaders.Add("Accept", "application/json, text/plain");
OnBeforeSend(new BeforeSendEventArgs
{
RequestHeaders = http.DefaultRequestHeaders,
RequestParameter = requestParams,
RequestUri = reqUri
});
try
{
HttpResponseMessage? response = null;
@ -154,6 +172,12 @@ namespace DS.Module.Core
throw new NotSupportedException($"不支持的请求方法:{method.Method}");
}
OnCompleted(new CompleteEventArgs
{
RequestUri = reqUri,
Response = response
});
if (!response.IsSuccessStatusCode)
return DataResult<HttpResponseMessage>.FailedData(response, string.Format(MultiLanguageConst.HttpRequestFailed, $"{response.StatusCode}"));
@ -164,5 +188,60 @@ namespace DS.Module.Core
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));
}
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;
try
{

@ -566,7 +566,7 @@ namespace DS.WMS.Core.Fee.Method
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;
await TenantDb.Ado.BeginTranAsync();
try

@ -27,11 +27,6 @@ namespace DS.WMS.Core.Fee.Method
/// </summary>
public const string USD_CODE = "USD";
/// <summary>
/// 工作流运行状态值
/// </summary>
public static readonly int RunningStatus = (int)FlowStatusEnum.Running;
/// <summary>
/// 获取用户相关信息
/// </summary>
@ -294,7 +289,7 @@ namespace DS.WMS.Core.Fee.Method
/// <returns></returns>
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))
.Select(x => new FlowInstance { Id = x.Id, BusinessId = x.BusinessId, BusinessType = x.BusinessType });
}

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

@ -80,7 +80,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
/// <returns></returns>
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)
query = query.Where(x => x.BusinessType == businessType.Value);
@ -112,7 +112,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
if (info == null)
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
if (info.Instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
if (info.Instance.FlowStatus == FlowStatusEnum.Approve)
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
return AuditFlowCore(info.Status, info.AuditNote, info.Instance);

@ -24,6 +24,8 @@ public class FlowInstanceService : IFlowInstanceService
protected readonly IUser user;
private readonly ICommonService _commonService;
private ApiFox api;
/// <summary>
///
/// </summary>
@ -34,6 +36,14 @@ public class FlowInstanceService : IFlowInstanceService
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
_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)
@ -57,7 +67,7 @@ public class FlowInstanceService : IFlowInstanceService
{
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);
}
@ -129,7 +139,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityName = wfruntime.CurrentNode.Name;
instance.PreviousId = "";
instance.MakerList = GetCurrentMakers(wfruntime);
instance.FlowStatus = FlowStatusEnum.Ready.ToEnumInt();
instance.FlowStatus = FlowStatusEnum.Ready;
wfruntime.FlowInstanceId = instance.Id;
@ -176,7 +186,7 @@ public class FlowInstanceService : IFlowInstanceService
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
}
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
if (instance.FlowStatus == FlowStatusEnum.Approve)
{
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
}
@ -195,7 +205,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityName = wfruntime.ChildNodes.First(x => x.Id == startNodeId).Name;
instance.MakerList =
(wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1");
instance.FlowStatus = FlowStatusEnum.Draft.ToEnumInt();
instance.FlowStatus = FlowStatusEnum.Draft;
wfruntime.FlowInstanceId = instance.Id;
@ -242,7 +252,7 @@ public class FlowInstanceService : IFlowInstanceService
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
}
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
if (instance.FlowStatus == FlowStatusEnum.Approve)
{
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
}
@ -258,9 +268,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.PreviousId = wfruntime.CurrentNodeId;
instance.MakerList =
(wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "1");
instance.FlowStatus = (wfruntime.GetNextNodeType() == 4
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt());
instance.FlowStatus = (wfruntime.GetNextNodeType() == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running);
wfruntime.FlowInstanceId = instance.Id;
@ -293,7 +301,7 @@ public class FlowInstanceService : IFlowInstanceService
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
}
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
if (instance.FlowStatus == FlowStatusEnum.Approve)
{
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
}
@ -328,7 +336,7 @@ public class FlowInstanceService : IFlowInstanceService
var res = runtime.NodeConfluence(runtime.CurrentNodeId, tag);
if (res == TagState.No.ToString("D"))
{
instance.FlowStatus = FlowStatusEnum.Reject.ToEnumInt();
instance.FlowStatus = FlowStatusEnum.Reject;
}
else if (!string.IsNullOrEmpty(res))
{
@ -342,9 +350,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityId = runtime.NextNodeId;
instance.ActivityType = runtime.NextNodeType;
instance.ActivityName = runtime.NextNode.Name;
instance.FlowStatus = runtime.NextNodeType == 4
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt();
instance.FlowStatus = runtime.NextNodeType == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running;
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
}
// AddTransHistory(wfruntime);
@ -371,13 +377,11 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityType = runtime.NextNodeType;
instance.ActivityName = runtime.NextNode.Name;
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
instance.FlowStatus = (runtime.NextNodeType == 4
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt());
instance.FlowStatus = (runtime.NextNodeType == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running);
}
else
{
instance.FlowStatus = FlowStatusEnum.Reject.ToEnumInt(); //表示该节点不同意
instance.FlowStatus = FlowStatusEnum.Reject; //表示该节点不同意
runtime.NextNodeId = "-1";
runtime.NextNodeType = 4;
}
@ -425,13 +429,6 @@ public class FlowInstanceService : IFlowInstanceService
/// <param name="instance">运行实例</param>
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
{
@ -442,29 +439,13 @@ public class FlowInstanceService : IFlowInstanceService
FlowStatus = (FlowStatusEnum)instance.FlowStatus,
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();
}
catch (Exception ex)
{
await ex.LogAsync(db);
}
finally
{
http?.Dispose();
}
await db.Updateable<FlowInstance>().SetColumns(it => new FlowInstance { IsCallbackExecuted = true })
.Where(it => it.Id == id).ExecuteCommandAsync();
}
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,60 @@
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(ColumnDescription = "业务ID", IsPrimaryKey = true, IsNullable = false)]
public long BusinessId { get; set; }
/// <summary>
/// 业务类型
/// </summary>
[SugarColumn(ColumnDescription = "业务类型", IsPrimaryKey = true, IsNullable = false)]
public BusinessType BusinessType { get; set; }
/// <summary>
/// 任务类型
/// </summary>
[SugarColumn(ColumnDescription = "任务类型", IsPrimaryKey = true, 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
{
@ -7,14 +18,179 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// </summary>
public class SeaExportTaskService : FeeServiceBase
{
ITaskManageService taskService;
/// <summary>
/// 初始化
/// </summary>
/// <param name="provider"></param>
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