using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
namespace WIDESEA_DTO.Basic
{
public class ContainerArrivalRequest
{
///
/// 调用ID
///
[JsonProperty("callid")]
public string CallId { get; set; }
///
/// 槽位代码
///
[JsonProperty("slotCode")]
public string SlotCode { get; set; }
///
/// 容器代码
///
[JsonProperty("containerCode")]
public string ContainerCode { get; set; }
///
/// 容器属性
///
[JsonProperty("containerAttribute")]
public ContainerAttribute ContainerAttribute { get; set; } = new ContainerAttribute();
}
///
/// 容器属性模型
///
public class ContainerAttribute
{
///
/// 高度
///
[JsonProperty("height")]
[Range(1, int.MaxValue, ErrorMessage = "高度必须大于0")]
public int Height { get; set; }
///
/// 长度
///
[JsonProperty("length")]
[Range(1, int.MaxValue, ErrorMessage = "长度必须大于0")]
public int Length { get; set; }
///
/// 宽度
///
[JsonProperty("width")]
[Range(1, int.MaxValue, ErrorMessage = "宽度必须大于0")]
public int Width { get; set; }
///
/// 重量
///
[JsonProperty("weight")]
[Range(0.1, double.MaxValue, ErrorMessage = "重量必须大于0")]
public double Weight { get; set; }
///
/// 材质
/// 1-塑料, 2-金属, 3-木材, 4-纸板
///
[JsonProperty("material")]
[Range(1, 4, ErrorMessage = "材质值必须在1-4范围内")]
public int Material { get; set; }
///
/// 方向
///
[JsonProperty("orientation")]
public string Orientation { get; set; } = string.Empty;
///
/// 二维码
///
[JsonProperty("qrcode")]
public string QRCode { get; set; } = string.Empty;
///
/// 异常原因
///
[JsonProperty("abnormalReason")]
public string AbnormalReason { get; set; } = string.Empty;
}
public class ContainerArrivalResponseData
{
public string? direction { get; set; }
}
public class MoveContainerRequest
{
///
/// 输送线节点编码。 必填
///
public string slotCode { get; set; }
///
/// 容器编码。 必填
///
public string containerCode { get; set; }
public string? direction { get; set; } = "100";
}
public class ApiResponse
{
[JsonProperty("code")]
public int Code { get; set; }
[JsonProperty("msg")]
public string? Msg { get; set; }
[JsonProperty("data")]
public T? Data { get; set; }
public static ApiResponse Success(T data)
=> new ApiResponse { Code = 0, Msg = "success", Data = data };
public static ApiResponse Error(int code, string msg)
=> new ApiResponse { Code = code, Msg = msg };
}
public class TaskDescribeType
{
public string containerCode { get; set; }
public string containerType { get; set; }
public string storageTag { get; set; }
public string fromLocationCode { get; set; }
public string toStationCode { get; set; }
public string toLocationCode { get; set; }
public int deadline { get; set; }
}
public class TasksType
{
public string taskCode { get; set; }
public int taskPriority { get; set; }
public TaskDescribeType taskDescribe { get; set; }
}
public class TaskModel
{
//入库 "taskType": "putaway" , 出库 "taskType": "carry"
public string taskType { get; set; }
public string taskGroupCode { get; set; }
public int groupPriority { get; set; }
public List tasks { get; set; }
}
public class ErrTasks
{
public string errorCode { get; set; }
public string message { get; set; }
public string taskCode { get; set; }
}
public class TasksData
{
public List tasks { get; set; }
}
[JsonConverter(typeof(StringEnumConverter))]
public enum AbnormalEventType
{
//工作位异常
[JsonProperty("location_abnormal")]
LocationAbnormal,
//机器人异常
[JsonProperty("robot_abnormal")]
RobotAbnormal
}
[JsonConverter(typeof(StringEnumConverter))]
public enum Direction
{
Forward = 100,
Backward = 200
}
///
/// 异常上报
///
public class AbnormalReportRequest
{
[JsonProperty("eventType")]
public AbnormalEventType EventType { get; set; }
[JsonProperty("robotCode")]
public string? RobotCode { get; set; }
[JsonProperty("stationCode")]
public string? StationCode { get; set; }
[JsonProperty("locationCode")]
public string? LocationCode { get; set; }
[JsonProperty("containerCode")]
public string? ContainerCode { get; set; }
[JsonProperty("message")]
public string? Message { get; set; }
[JsonProperty("updateTime")]
public long UpdateTime { get; set; }
}
///
/// 事件类型枚举
///
public enum EventType
{
///
/// 任务状态变化
///
task,
///
/// 任务分配
///
task_allocated,
///
/// 取箱状态
///
tote_load,
///
/// 放箱状态
///
tote_unload,
///
/// 机器人到达工作站
///
robot_reach
}
///
/// 任务状态枚举
///
public enum TaskStatus
{
///
/// 成功
///
success,
///
/// 失败
///
fail,
///
/// 取消
///
cancel,
///
/// 挂起
///
suspend
}
///
/// 容器朝向枚举
///
public enum ContainerFace
{
///
/// 0度
///
A = 0,
///
/// 90度
///
B = 90,
///
/// 180度
///
C = 180,
///
/// 270度
///
D = 270
}
///
/// 任务状态回调请求模型
///
public class StatusCallbackRequest
{
///
/// 一次回调唯一标识
///
[JsonProperty("callId", Required = Required.Always)]
public string CallId { get; set; }
///
/// 业务任务号
/// 当eventType为robot_reach时不填,其他值时必填
///
[JsonProperty("taskCode")]
public string TaskCode { get; set; }
///
/// 上报事件类型
///
[JsonProperty("eventType", Required = Required.Always)]
public EventType EventType { get; set; }
///
/// 任务状态
///
[JsonProperty("status", Required = Required.Always)]
public TaskStatus Status { get; set; }
///
/// 机器人编码
///
[JsonProperty("robotCode")]
public string RobotCode { get; set; }
///
/// 容器编码
///
[JsonProperty("containerCode")]
public string ContainerCode { get; set; }
///
/// 工作位编码
///
[JsonProperty("locationCode")]
public string LocationCode { get; set; }
///
/// 工作站编码
///
[JsonProperty("stationCode")]
public string StationCode { get; set; }
///
/// 描述信息,描述异常原因/挂起原因等
///
[JsonProperty("message")]
public string Message { get; set; }
///
/// 系统任务编码,用于任务挂起回调
///
[JsonProperty("sysTaskCode")]
public string SysTaskCode { get; set; }
///
/// 库位是否有容器,eventType为task且为盘点任务时才会返回该值
///
[JsonProperty("isLocationHasContainer")]
public bool? IsLocationHasContainer { get; set; }
///
/// 背签层叶,从0层开始,从下往上编号。64表示放在了货叉上
/// 当eventType为task且为称重盘点任务或rfid盘点任务时才会返回该值
///
[JsonProperty("trayLevel")]
public int? TrayLevel { get; set; }
///
/// 重量,单位为g。当eventType为task且为称重盘点任务时才会返回该值
///
[JsonProperty("weight")]
public int? Weight { get; set; }
///
/// RFID盘点信息。当eventType为task且为rfid盘点任务时才会返回该值
///
[JsonProperty("rfids")]
public List Rfids { get; set; }
///
/// 机器人类型编码。当eventType为robot_reach时才会返回该值
///
[JsonProperty("robotTypeCode")]
public string RobotTypeCode { get; set; }
///
/// 托盘信息。当eventType为robot_reach时才会返回该值
///
[JsonProperty("trays")]
public List Trays { get; set; }
}
///
/// 托盘信息模型
///
public class TrayItem
{
///
/// 容器编码
///
[JsonProperty("containerCode")]
public string ContainerCode { get; set; }
///
/// 背签层叶,从0层开始,从下往上编号。64表示容器放在了货叉上
///
[JsonProperty("trayLevel", Required = Required.Always)]
public int TrayLevel { get; set; }
///
/// 位置编码,由机器人编码和背签层数组成,即机器人id#层数
///
[JsonProperty("positionCode", Required = Required.Always)]
public string PositionCode { get; set; }
///
/// 目标容器朝向,取值为枚举值A、B、C、D
///
[JsonProperty("containerFace")]
public ContainerFace? ContainerFace { get; set; }
}
///
/// 状态回调响应模型
///
public class StatusCallbackResponse
{
///
/// 响应状态码
/// 0: 正常
/// 4560: 异常
///
[JsonProperty("code", Required = Required.Always)]
public int Code { get; set; }
///
/// 响应消息补充说明,success或其他异常消息
///
[JsonProperty("msg", Required = Required.Always)]
public string Msg { get; set; }
///
/// 返回的数据
///
[JsonProperty("data", Required = Required.Always)]
public object Data { get; set; }
///
/// 创建成功响应
///
public static StatusCallbackResponse Success()
{
return new StatusCallbackResponse
{
Code = 0,
Msg = "success",
Data = new { }
};
}
///
/// 创建错误响应
///
public static StatusCallbackResponse Error(string message)
{
return new StatusCallbackResponse
{
Code = 4560,
Msg = message,
Data = new { }
};
}
}
///
/// 机器人异常事件请求模型
///
public class RobotAbnormalEventRequest
{
///
/// 事件类型
///
[JsonProperty("eventType")]
public string EventType { get; set; } = "robot_abnormal";
///
/// 机器人代码
///
[JsonProperty("robotCode")]
public string RobotCode { get; set; }
///
/// 站台代码
///
[JsonProperty("stationCode")]
public string StationCode { get; set; } = string.Empty;
///
/// 位置代码
///
[JsonProperty("locationCode")]
public string LocationCode { get; set; }
///
/// 容器代码
///
[JsonProperty("containerCode")]
public string ContainerCode { get; set; }
///
/// 异常消息
///
[JsonProperty("message")]
public string Message { get; set; }
///
/// 更新时间(Unix时间戳,毫秒)
///
[JsonProperty("updateTime")]
public long UpdateTime { get; set; }
///
/// 获取DateTime类型的更新时间
///
[JsonIgnore]
public DateTime UpdateDateTime
{
get
{
return DateTimeOffset.FromUnixTimeMilliseconds(UpdateTime).DateTime;
}
set
{
UpdateTime = new DateTimeOffset(value).ToUnixTimeMilliseconds();
}
}
///
/// 设置当前时间为更新时间
///
public void SetCurrentTime()
{
UpdateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
}
///
/// 创建成功响应
///
public override string ToString()
{
return $"RobotAbnormalEvent: Robot={RobotCode}, Location={LocationCode}, Container={ContainerCode}, Time={UpdateDateTime:yyyy-MM-dd HH:mm:ss}";
}
}
}