using System; using System.Collections.Generic; using System.Linq; using WCS.Core.DataTrans; using WCS.Entity; namespace WCS.Core { public abstract class EntityEx { public T Entity { get; } protected EntityEx(T entity) { Entity = entity; } public virtual DateTime UpdateTime { get; set; } public double Times => (DateTime.Now - UpdateTime).TotalMilliseconds; public override string ToString() { return Entity.ToString(); } } public class Device : EntityEx where T : IProtocol { public T Data { get; } public Device(WCS_DEVICE entity) : base(entity) { //新增一个报错 var data = entity.DEVICEPROTOCOLS.FirstOrDefault(v => v.DB.PROTOCOL == typeof(T).AssemblyQualifiedName) ?? throw new Exception($"设备{entity.CODE}对应PROTOCOL有误,请检查相关配置"); Data = data.Data(); } } public class Device : Device where T : IProtocol where T2 : IProtocol { public T2 Data2 { get; } public Device(WCS_DEVICE entity) : base(entity) { Data2 = entity.DEVICEPROTOCOLS.Single(v => v.DB.PROTOCOL == typeof(T2).AssemblyQualifiedName).Data(); } } public class Device : Device where T : IProtocol where T2 : IProtocol where T3 : IProtocol { public T3 Data3 { get; } public Device(WCS_DEVICE entity) : base(entity) { Data3 = entity.DEVICEPROTOCOLS.Single(v => v.DB.PROTOCOL == typeof(T3).AssemblyQualifiedName).Data(); } } public class Device : Device where T : IProtocol where T2 : IProtocol where T3 : IProtocol where T4 : IProtocol { public T4 Data4 { get; } public Device(WCS_DEVICE entity) : base(entity) { Data4 = entity.DEVICEPROTOCOLS.Single(v => v.DB.PROTOCOL == typeof(T4).AssemblyQualifiedName).Data(); } } public class Group : EntityEx where T : EntityEx { public IEnumerable Items { get; } public Group(WCS_DEVICE entity) : base(entity) { Items = entity.DEVICEGROUP.Select(v => Device.Find(v.MEMBER.CODE).Create()).OrderBy(p => p.Entity.CODE).ToList(); } } public class DeviceGroup : Group> where T : IProtocol { public DeviceGroup(WCS_DEVICE entity) : base(entity) { } } public class DeviceGroup : Group> where T : IProtocol where T2 : IProtocol { public DeviceGroup(WCS_DEVICE entity) : base(entity) { } } public class DeviceGroup : Group> where T : IProtocol where T2 : IProtocol where T3 : IProtocol { public DeviceGroup(WCS_DEVICE entity) : base(entity) { } } }