增加确保任务交互模块已授权的检查

usertest
嵇文龙 4 months ago
parent 63c4ff7ae2
commit c2c3b9cf57

@ -207,6 +207,9 @@ public static class MultiLanguageConst
[Description("权限模块不存在")]
public const string PermissionNotExist = "Permission_NotExist";
[Description("此模块未授权")]
public const string ModuleUnauthorized = "Module_Unauthorized";
[Description("数据权限已存在")]
public const string DataRuleExist = "Data_Rule_Exist";

@ -88,6 +88,17 @@ public class DataResult : DataResult<object>
return new DataResult(ResultCode.Success, message, multiCode);
}
public static DataResult SuccessedWithDesc(string fieldName)
{
var fieldInfo = typeof(MultiLanguageConst).GetField(fieldName) ?? throw new ArgumentException($"不存在的常量:{fieldName}", fieldName);
var attribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
var desc = attribute?.Description ?? string.Empty;
var value = fieldInfo.GetValue(null) as string ?? string.Empty;
return Successed(desc, value);
}
/// <summary>
/// 其他操作
/// </summary>
@ -170,7 +181,7 @@ public class DataResult : DataResult<object>
var desc = attribute?.Description ?? string.Empty;
var value = fieldInfo.GetValue(null) as string ?? string.Empty;
return Failed(desc, fieldName);
return Failed(desc, value);
}
}
@ -269,7 +280,7 @@ public class DataResult<TData> : IDataResult<ResultCode, TData>
/// <summary>
/// 附加数据
/// </summary>
public Dictionary<string,object>? AdditionalData { get; set; }
public Dictionary<string, object>? AdditionalData { get; set; }
/// <summary>
/// 返回成功的结果

@ -23,7 +23,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
saasService = serviceProvider.GetRequiredService<ISaasDbService>();
}
protected override FlowInstance BuildInstance(CreateFlowInstanceReq req)
protected override FlowInstance? BuildInstance(CreateFlowInstanceReq req)
{
if (string.IsNullOrEmpty(req.TemplateId.ToString()))
return null;

@ -1,4 +1,3 @@
using System.Text;
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
@ -78,7 +77,7 @@ public class FlowInstanceService : IFlowInstanceService
}
}
protected virtual FlowInstance BuildInstance(CreateFlowInstanceReq req)
protected virtual FlowInstance? BuildInstance(CreateFlowInstanceReq req)
{
if (string.IsNullOrEmpty(req.TemplateId.ToString()))
return null;

@ -27,5 +27,10 @@ namespace DS.WMS.Core.Op.Dtos.TaskInteraction
/// 任务状态
/// </summary>
public TaskStatusEnum TaskStatus { get; set; }
/// <summary>
/// 当任务完成时是否根据任务类型自动创建下一任务默认为true
/// </summary>
public bool AutoCreateNext { get; set; } = true;
}
}

@ -147,7 +147,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
protected override async Task OnTaskStatusChanged(TaskUpdateRequest request)
{
//放舱结束,根据业务所选服务,生成子任务
if (request.TaskType == TaskBaseTypeEnum.WAIT_SPACE_RELEASE)
if (request.TaskType == TaskBaseTypeEnum.WAIT_SPACE_RELEASE && request.TaskStatus == TaskStatusEnum.Complete)
{
var list = await GetSubRequestAsync(request.BusinessId, request.BusinessType);
await CreateSubTaskAsync(list);

@ -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));
@ -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
{
@ -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 =>

Loading…
Cancel
Save