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.

57 lines
1.8 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using DS.Module.Core;
using DS.WMS.Core.Op.Entity;
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
/// <summary>
/// 任务请求基类
/// </summary>
public class TaskRequest : IValidatableObject
{
/// <summary>
/// 业务ID
/// </summary>
public long BusinessId { get; set; }
/// <summary>
/// 业务类型
/// </summary>
public BusinessType BusinessType { get; set; }
static readonly TaskBaseTypeEnum _defaultTaskType = TaskBaseTypeEnum.NOT_SPECIFIED;
/// <summary>
/// 任务类型
/// </summary>
[IgnoreDataMember]
public TaskBaseTypeEnum TaskType => string.IsNullOrEmpty(TaskTypeName) ? _defaultTaskType : Enum.Parse<TaskBaseTypeEnum>(TaskTypeName);
/// <summary>
/// 任务类型名称
/// </summary>
public string TaskTypeName { get; set; } = string.Empty;
/// <summary>
/// 确定当前对象是否有效
/// </summary>
/// <param name="validationContext">验证上下文</param>
/// <returns></returns>
public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (BusinessId == 0)
{
yield return new ValidationResult($"参数 {nameof(BusinessId)} 不能为空");
}
else if (string.IsNullOrEmpty(TaskTypeName))
{
yield return new ValidationResult($"参数 {nameof(TaskTypeName)} 不能为空");
}
else if (!Enum.TryParse(TaskTypeName, out TaskBaseTypeEnum taskType))
{
yield return new ValidationResult($"参数 {nameof(TaskTypeName)} 值无效");
}
}
}
}