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
{
///
/// 任务请求基类
///
public class TaskRequest : IValidatableObject
{
///
/// 业务ID
///
public long BusinessId { get; set; }
///
/// 业务类型
///
public BusinessType BusinessType { get; set; }
static readonly TaskBaseTypeEnum _defaultTaskType = TaskBaseTypeEnum.NOT_SPECIFIED;
///
/// 任务类型
///
[IgnoreDataMember]
public TaskBaseTypeEnum TaskType => string.IsNullOrEmpty(TaskTypeName) ? _defaultTaskType : Enum.Parse(TaskTypeName);
///
/// 任务类型名称
///
public string TaskTypeName { get; set; } = string.Empty;
///
/// 确定当前对象是否有效
///
/// 验证上下文
///
public virtual IEnumerable 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)} 值不在有效枚举范围之内");
}
}
}
}