You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.4 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using DS.Module.Core;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.TaskInteraction.Method;
using Masuit.Tools.Systems;
namespace DS.WMS.Core.TaskInteraction.Dtos
{
/// <summary>
/// 任务请求基类
/// </summary>
public class TaskRequest : IValidatableObject
{
/// <summary>
/// 业务ID
/// </summary>
public long BusinessId { get; set; }
/// <summary>
/// 业务ID用于批量请求
/// </summary>
public long[]? Ids { get; set; }
/// <summary>
/// 业务类型
/// </summary>
public BusinessType? BusinessType { get; set; }
/// <summary>
/// 任务类型;该属性为只读
/// </summary>
[IgnoreDataMember]
1 month ago
public TaskBaseTypeEnum TaskType => string.IsNullOrEmpty(TaskTypeName) ? TaskBaseTypeEnum.NOT_SPECIFIED : Enum.Parse<TaskBaseTypeEnum>(TaskTypeName);
/// <summary>
/// 任务类型名称
/// </summary>
public string TaskTypeName { get; set; } = string.Empty;
/// <summary>
1 month ago
/// 父级任务类型名称(用于子任务)
/// </summary>
public string? ParentTaskTypeName { get; set; }
/// <summary>
/// 父级任务类型;该属性为只读
/// </summary>
[IgnoreDataMember]
public TaskBaseTypeEnum? ParentTaskType => string.IsNullOrEmpty(ParentTaskTypeName) ? null : Enum.Parse<TaskBaseTypeEnum>(ParentTaskTypeName);
/// <summary>
/// 父级任务ID用于子任务
/// </summary>
public long? ParentId { get; set; }
/// <summary>
/// 父级业务ID用于子任务
/// </summary>
public long? ParentBusinessId { get; set; }
/// <summary>
/// 附加数据(内部使用)
/// </summary>
public object? ExtraData { get; set; }
/// <summary>
/// 是否自动同步更新主任务状态
/// </summary>
public bool AutoSync { get; set; } = true;
/// <summary>
/// 任务步骤
/// </summary>
public List<TaskStepDto>? Steps { get; set; }
/// <summary>
/// 确定当前对象是否有效
/// </summary>
/// <param name="validationContext">验证上下文</param>
/// <returns></returns>
public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
//if (BusinessId == 0 && (Ids == null || Ids.Length == 0))
//{
// yield return new ValidationResult($"参数 {nameof(BusinessId)} 与 {nameof(Ids)} 至少指定一项");
//}
if (string.IsNullOrEmpty(TaskTypeName))
{
yield return new ValidationResult($"参数 {nameof(TaskTypeName)} 不能为空");
}
else if (!Enum.TryParse(TaskTypeName, out TaskBaseTypeEnum taskType))
{
4 months ago
yield return new ValidationResult($"参数 {nameof(TaskTypeName)} 值不在有效枚举范围之内");
}
else if (TaskService.IsOrderType(TaskType) && BusinessType == null)
{
yield return new ValidationResult($"任务类型为【{TaskType.GetDescription()}】时,参数 {nameof(BusinessType)} 不能为空");
}
}
}
}