#region << 版 本 注 释 >> /*-------------------------------------------------------------------- * 版权所有 (c) 2026 WenJY 保留所有权利。 * CLR版本:4.0.30319.42000 * 机器名称:Mr.Wen's MacBook Pro * 命名空间:Sln.Wcs.Business.Util * 唯一标识:6942BA6E-D8FC-4847-BBF6-5977C3A999D6 * * 创建者:WenJY * 电子邮箱: * 创建时间:2026-05-07 18:07:25 * 版本:V1.0.0 * 描述: * *-------------------------------------------------------------------- * 修改人: * 时间: * 修改说明: * * 版本:V1.0.0 *--------------------------------------------------------------------*/ #endregion << 版 本 注 释 >> using System.Reflection; using Sln.Wcs.Business.Domain.Enum; using Sln.Wcs.Model.Domain; namespace Sln.Wcs.Business.Util; public class EntityWrapper { /// /// 反射辅助方法 /// /// /// /// private (string materialCode, string palletBarcode, string materialBarcode, int materialCount,int taskType,int taskCategory) ExtractTaskFields(object source) { if (source == null) throw new ArgumentNullException(nameof(source)); var type = source.GetType(); object GetPropertyValue(string propName) { var prop = type.GetProperty(propName, BindingFlags.Public | BindingFlags.Instance); if (prop != null && prop.CanRead) return prop.GetValue(source); var field = type.GetField(propName, BindingFlags.Public | BindingFlags.Instance); return field?.GetValue(source); } string GetString(string propName) => GetPropertyValue(propName)?.ToString() ?? string.Empty; int GetInt(string propName) { var val = GetPropertyValue(propName); return val != null ? Convert.ToInt32(val) : 0; } return ( materialCode: GetString("materialCode"), palletBarcode: GetString("palletBarcode"), materialBarcode: GetString("materialBarcode"), materialCount: GetInt("amount"), taskType: GetInt("taskType"), taskCategory: GetInt("taskCategory") ); } /// /// 任务明细包装 /// /// /// /// /// public LiveTaskDetail LiveTaskDetailWrapper(string taskCode,object source, BasePathDetails pathDetails) { var fields = ExtractTaskFields(source); return new LiveTaskDetail { taskCode = taskCode, materialCode = fields.materialCode, palletBarcode = fields.palletBarcode, materialBarcode = fields.materialBarcode, materialCount = fields.materialCount, startPoint = pathDetails.startPoint, endPoint = pathDetails.endPoint, deviceType = pathDetails.deviceType, pathCode = $"{pathDetails.pathCode}_{pathDetails.objId}", taskType = fields.taskType, taskCategory = fields.taskCategory }; } /// /// 任务队列包装 /// /// /// /// /// public LiveTaskQueue LiveTaskQueueWrapper(string taskCode, object source, BasePathInfo pathInfo) { var fields = ExtractTaskFields(source); return new LiveTaskQueue() { taskCode = taskCode, materialCode = fields.materialCode, palletBarcode = fields.palletBarcode, materialBarcode = fields.materialBarcode, materialCount = fields.materialCount, startPoint = pathInfo.startPoint, endPoint = pathInfo.endPoint, pathCode = pathInfo.pathCode, taskType = fields.taskType, taskCategory = fields.taskCategory }; } }