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.

123 lines
4.1 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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
{
/// <summary>
/// 反射辅助方法
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
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")
);
}
/// <summary>
/// 任务明细包装
/// </summary>
/// <param name="taskCode"></param>
/// <param name="source"></param>
/// <param name="pathDetails"></param>
/// <returns></returns>
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
};
}
/// <summary>
/// 任务队列包装
/// </summary>
/// <param name="taskCode"></param>
/// <param name="source"></param>
/// <param name="pathInfo"></param>
/// <returns></returns>
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
};
}
}