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

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

@ -206,7 +206,10 @@ public static class MultiLanguageConst
/// </summary> /// </summary>
[Description("权限模块不存在")] [Description("权限模块不存在")]
public const string PermissionNotExist = "Permission_NotExist"; public const string PermissionNotExist = "Permission_NotExist";
[Description("此模块未授权")]
public const string ModuleUnauthorized = "Module_Unauthorized";
[Description("数据权限已存在")] [Description("数据权限已存在")]
public const string DataRuleExist = "Data_Rule_Exist"; public const string DataRuleExist = "Data_Rule_Exist";

@ -88,6 +88,17 @@ public class DataResult : DataResult<object>
return new DataResult(ResultCode.Success, message, multiCode); 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>
/// 其他操作 /// 其他操作
/// </summary> /// </summary>
@ -125,7 +136,7 @@ public class DataResult : DataResult<object>
/// <exception cref="Exception"></exception> /// <exception cref="Exception"></exception>
public static DataResult FailedWithPlaceholder(ISqlSugarClient db, IHttpContextAccessor accessor, string multiCode, string placeholde1 = "", string placeholde2 = "", string placeholde3 = "", string placeholde4 = "", string placeholde5 = "") public static DataResult FailedWithPlaceholder(ISqlSugarClient db, IHttpContextAccessor accessor, string multiCode, string placeholde1 = "", string placeholde2 = "", string placeholde3 = "", string placeholde4 = "", string placeholde5 = "")
{ {
var desc = string.Empty; var desc = string.Empty;
var language = accessor.HttpContext.Request.Headers["LanguageType"].FirstOrDefault(); var language = accessor.HttpContext.Request.Headers["LanguageType"].FirstOrDefault();
if (language.IsNullOrEmpty()) if (language.IsNullOrEmpty())
@ -144,16 +155,16 @@ public class DataResult : DataResult<object>
{ {
if (language == "CN") if (language == "CN")
{ {
var fieldInfo = typeof(MultiLanguageConst).GetField(nameof(multiCode)); var fieldInfo = typeof(MultiLanguageConst).GetField(nameof(multiCode));
var attribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>(); var attribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
desc = attribute?.Description ?? string.Empty; desc = attribute?.Description ?? string.Empty;
} }
else else
{ {
throw new Exception($"未设置多语言:" + language + "下的消息提示代码:" + multiCode); throw new Exception($"未设置多语言:" + language + "下的消息提示代码:" + multiCode);
} }
} }
return new DataResult(ResultCode.Error, string.Format(desc, placeholde1, placeholde2, placeholde3, placeholde4, placeholde5), multiCode); return new DataResult(ResultCode.Error, string.Format(desc, placeholde1, placeholde2, placeholde3, placeholde4, placeholde5), multiCode);
} }
@ -170,7 +181,7 @@ public class DataResult : DataResult<object>
var desc = attribute?.Description ?? string.Empty; var desc = attribute?.Description ?? string.Empty;
var value = fieldInfo.GetValue(null) as string ?? 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>
/// 附加数据 /// 附加数据
/// </summary> /// </summary>
public Dictionary<string,object>? AdditionalData { get; set; } public Dictionary<string, object>? AdditionalData { get; set; }
/// <summary> /// <summary>
/// 返回成功的结果 /// 返回成功的结果

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

@ -1,4 +1,3 @@
using System.Text;
using DS.Module.Core; using DS.Module.Core;
using DS.Module.Core.Extensions; using DS.Module.Core.Extensions;
using DS.Module.UserModule; 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())) if (string.IsNullOrEmpty(req.TemplateId.ToString()))
return null; return null;

@ -27,5 +27,10 @@ namespace DS.WMS.Core.Op.Dtos.TaskInteraction
/// 任务状态 /// 任务状态
/// </summary> /// </summary>
public TaskStatusEnum TaskStatus { get; set; } 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) 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); var list = await GetSubRequestAsync(request.BusinessId, request.BusinessType);
await CreateSubTaskAsync(list); await CreateSubTaskAsync(list);

@ -1,5 +1,6 @@
using DS.Module.Core; using DS.Module.Core;
using DS.Module.Core.Extensions; using DS.Module.Core.Extensions;
using DS.Module.Core.Helpers;
using DS.WMS.Core.Fee.Method; using DS.WMS.Core.Fee.Method;
using DS.WMS.Core.Flow.Dtos; using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Op.Dtos.TaskInteraction; using DS.WMS.Core.Op.Dtos.TaskInteraction;
@ -20,6 +21,8 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// </summary> /// </summary>
public abstract class TaskService : FeeServiceBase, ITaskService public abstract class TaskService : FeeServiceBase, ITaskService
{ {
const long PERMISSION_ID = 1815294400855674880;
/// <summary> /// <summary>
/// 任务管理服务 /// 任务管理服务
/// </summary> /// </summary>
@ -34,6 +37,26 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
ManagerService = provider.GetRequiredService<ITaskManageService>(); 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>
/// 创建关联任务 /// 创建关联任务
/// </summary> /// </summary>
@ -42,6 +65,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// <returns></returns> /// <returns></returns>
public async Task<DataResult> CreateTaskAsync(TaskCreationRequest request, bool useTransaction = true) 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); var task = await GetTaskAsync(request.BusinessId, request.BusinessType, request.TaskType);
if (task != null) if (task != null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Task_Exists)); return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Task_Exists));
@ -137,7 +163,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// </summary> /// </summary>
/// <param name="task"></param> /// <param name="task"></param>
/// <returns></returns> /// <returns></returns>
protected virtual Task<DataResult> OnTaskCreated(BusinessTask task) protected virtual Task<DataResult> OnTaskCreated(BusinessTask task)
{ {
return Task.FromResult(DataResult.Success); return Task.FromResult(DataResult.Success);
} }
@ -149,6 +175,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// <returns></returns> /// <returns></returns>
public async Task<DataResult> SetTaskStatusAsync(TaskUpdateRequest request) public async Task<DataResult> SetTaskStatusAsync(TaskUpdateRequest request)
{ {
if (!await EnsureModuleAuthorized())
return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized));
await TenantDb.Ado.BeginTranAsync(); await TenantDb.Ado.BeginTranAsync();
try try
{ {
@ -161,7 +190,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (task == null) if (task == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.EmptyData)); return DataResult.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
if (task.TaskStatus!= request.TaskStatus) if (task.TaskStatus != request.TaskStatus)
await OnTaskStatusChanged(request); await OnTaskStatusChanged(request);
task.TaskStatus = request.TaskStatus; task.TaskStatus = request.TaskStatus;
@ -170,7 +199,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (task.TaskStatus == TaskStatusEnum.Complete) if (task.TaskStatus == TaskStatusEnum.Complete)
{ {
//若存在下一任务,则继续创建 //若存在下一任务,则继续创建
if (task.NextType.HasValue) if (task.NextType.HasValue && request.AutoCreateNext)
{ {
var req = new TaskCreationRequest var req = new TaskCreationRequest
{ {
@ -198,7 +227,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
protected virtual Task OnTaskStatusChanged(TaskUpdateRequest request) protected virtual Task OnTaskStatusChanged(TaskUpdateRequest request)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
@ -214,7 +243,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
ArgumentNullException.ThrowIfNull(callback, nameof(callback)); ArgumentNullException.ThrowIfNull(callback, nameof(callback));
//更新任务状态为完成 //更新任务状态为完成
await SetTaskStatusAsync(new TaskUpdateRequest await SetTaskStatusAsync(new TaskUpdateRequest
{ {
BusinessId = callback.BusinessId, BusinessId = callback.BusinessId,
BusinessType = callback.BusinessType.GetValueOrDefault(), 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) protected internal async Task<BusinessTask> GetTaskAsync(long id, BusinessType businessType, TaskBaseTypeEnum taskType)
{ {
return await TenantDb.Queryable<BusinessTask>().FirstAsync(x => return await TenantDb.Queryable<BusinessTask>().FirstAsync(x =>

Loading…
Cancel
Save