using System.ComponentModel;
using Newtonsoft.Json;
using SqlSugar;
namespace DS.WMS.Core.TaskInteraction.Entity
{
///
/// 任务步骤表
///
[SugarTable("business_task_step", "任务步骤表")]
public class TaskStep
{
///
/// ID
///
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
///
/// 任务ID
///
[SugarColumn(ColumnDescription = "任务ID")]
public long TaskId { get; set; }
///
/// 步骤类型
///
[SugarColumn(ColumnDescription = "明细类型")]
public StepType Type { get; set; }
///
/// 名称
///
[SugarColumn(ColumnDescription = "名称", Length = 50, IsNullable = true)]
public string? Name { get; set; }
///
/// 值
///
[SugarColumn(ColumnDescription = "值", IsNullable = true)]
public string? Value { get; set; }
///
/// 是否已完成
///
[SugarColumn(ColumnDescription = "是否已完成")]
public bool IsCompleted { get; set; }
///
/// 优先级
///
[SugarColumn(ColumnDescription = "优先级")]
public int Priority { get; set; }
///
/// 创建人
///
[SugarColumn(ColumnDescription = "创建人", IsNullable = false)]
public long CreateBy { get; set; }
///
/// 创建时间
///
[SugarColumn(ColumnDescription = "创建时间", IsNullable = false)]
public DateTime CreateTime { get; set; }
///
/// 更新人
///
[SugarColumn(ColumnDescription = "更新人", IsNullable = true)]
public long? UpdateBy { get; set; }
///
/// 更新时间
///
[SugarColumn(ColumnDescription = "更新时间", IsNullable = true)]
public DateTime? UpdateTime { get; set; }
///
/// 返回指定类型的值
///
/// 值的类型
///
public T? GetValue()
{
if (string.IsNullOrEmpty(Value))
return default;
var type = typeof(T);
if (type.IsEnum)
return (T)Enum.Parse(type, Value);
if (!type.IsClass)
return (T)Convert.ChangeType(Value, type);
return JsonConvert.DeserializeObject(Value);
}
///
/// 设置值
///
/// 要设置的值
///
public void SetValue(object? value)
{
if (value == null)
return;
var type = value.GetType();
if (type.IsClass && type != typeof(string))
{
Value = JsonConvert.SerializeObject(value);
}
else
{
Value = value.ToString();
}
}
}
///
/// 任务步骤类型
///
public enum StepType
{
///
/// 未指定
///
[Description("未指定")]
NotSpecified = 0,
///
/// 客户确认
///
[Description("客户确认")]
CustomerConfirm = 1,
///
/// 国外代理确认
///
[Description("国外代理确认")]
ForeignAgentConfirm = 2,
///
/// 操作确认
///
[Description("操作确认")]
OPConfirm = 3,
}
}