|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.Module.Core.Helpers;
|
|
|
|
|
using DS.WMS.Core.Fee.Method;
|
|
|
|
|
using DS.WMS.Core.Flow.Dtos;
|
|
|
|
|
using DS.WMS.Core.Op.Dtos.TaskInteraction;
|
|
|
|
@ -20,6 +21,8 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class TaskService : FeeServiceBase, ITaskService
|
|
|
|
|
{
|
|
|
|
|
const long PERMISSION_ID = 1815294400855674880;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 任务管理服务
|
|
|
|
|
/// </summary>
|
|
|
|
@ -34,6 +37,26 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
ManagerService = provider.GetRequiredService<ITaskManageService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 确保任务交互模块已授权
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected virtual async Task<bool> EnsureModuleAuthorized()
|
|
|
|
|
{
|
|
|
|
|
//if (!await Db.Queryable<SysPermissionTenant>().AnyAsync(x => x.PermissionId == PERMISSION_ID))
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
|
|
long tid = long.Parse(User.TenantId);
|
|
|
|
|
var authStr = await Db.Queryable<SysTenantPermissionAuth>().Where(x => x.PermissionId == PERMISSION_ID && x.TenantId == tid &&
|
|
|
|
|
SqlFunc.Subqueryable<SysPermissionTenant>().Where(spt => spt.PermissionId == x.PermissionId).Any())
|
|
|
|
|
.Select(x => x.AuthNum).FirstAsync();
|
|
|
|
|
if (authStr.IsNullOrEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var appSecret = await Db.Queryable<SysTenant>().Where(x => x.Id == tid).Select(x => x.AppSecret).FirstAsync();
|
|
|
|
|
return int.TryParse(EncrypteHelper.DecryptData(authStr, appSecret), out int authNum) && authNum > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建关联任务
|
|
|
|
|
/// </summary>
|
|
|
|
@ -42,6 +65,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> CreateTaskAsync(TaskCreationRequest request, bool useTransaction = true)
|
|
|
|
|
{
|
|
|
|
|
if (!await EnsureModuleAuthorized())
|
|
|
|
|
return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized));
|
|
|
|
|
|
|
|
|
|
var task = await GetTaskAsync(request.BusinessId, request.BusinessType, request.TaskType);
|
|
|
|
|
if (task != null)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Task_Exists));
|
|
|
|
@ -137,7 +163,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="task"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected virtual Task<DataResult> OnTaskCreated(BusinessTask task)
|
|
|
|
|
protected virtual Task<DataResult> OnTaskCreated(BusinessTask task)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(DataResult.Success);
|
|
|
|
|
}
|
|
|
|
@ -149,6 +175,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> SetTaskStatusAsync(TaskUpdateRequest request)
|
|
|
|
|
{
|
|
|
|
|
if (!await EnsureModuleAuthorized())
|
|
|
|
|
return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized));
|
|
|
|
|
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
@ -161,7 +190,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
if (task == null)
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
|
|
|
|
|
|
|
|
|
|
if (task.TaskStatus!= request.TaskStatus)
|
|
|
|
|
if (task.TaskStatus != request.TaskStatus)
|
|
|
|
|
await OnTaskStatusChanged(request);
|
|
|
|
|
|
|
|
|
|
task.TaskStatus = request.TaskStatus;
|
|
|
|
@ -170,7 +199,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
if (task.TaskStatus == TaskStatusEnum.Complete)
|
|
|
|
|
{
|
|
|
|
|
//若存在下一任务,则继续创建
|
|
|
|
|
if (task.NextType.HasValue)
|
|
|
|
|
if (task.NextType.HasValue && request.AutoCreateNext)
|
|
|
|
|
{
|
|
|
|
|
var req = new TaskCreationRequest
|
|
|
|
|
{
|
|
|
|
@ -198,7 +227,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected virtual Task OnTaskStatusChanged(TaskUpdateRequest request)
|
|
|
|
|
protected virtual Task OnTaskStatusChanged(TaskUpdateRequest request)
|
|
|
|
|
{
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
@ -214,7 +243,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
ArgumentNullException.ThrowIfNull(callback, nameof(callback));
|
|
|
|
|
|
|
|
|
|
//更新任务状态为完成
|
|
|
|
|
await SetTaskStatusAsync(new TaskUpdateRequest
|
|
|
|
|
await SetTaskStatusAsync(new TaskUpdateRequest
|
|
|
|
|
{
|
|
|
|
|
BusinessId = callback.BusinessId,
|
|
|
|
|
BusinessType = callback.BusinessType.GetValueOrDefault(),
|
|
|
|
@ -223,6 +252,13 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取指定类型的业务关联任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">业务ID</param>
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <param name="taskType">任务类型</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected internal async Task<BusinessTask> GetTaskAsync(long id, BusinessType businessType, TaskBaseTypeEnum taskType)
|
|
|
|
|
{
|
|
|
|
|
return await TenantDb.Queryable<BusinessTask>().FirstAsync(x =>
|
|
|
|
|