Base_Equipment.cs 3.21 KB
using RCS.Model.Entity.PrimaryKey;
using System.Collections.Concurrent;
using System.ComponentModel.DataAnnotations.Schema;

namespace RCS.Model.Entity
{
    [Table("t_base_equipment")]

    public class Base_Equipment: IdEntity
    {
        /// <summary>
        /// 设备编码
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// CAD编码
        /// </summary>
        public string CADCode { get; set; }

        /// <summary>
        /// 设备名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 设备类型
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 设备IP
        /// </summary>
        public string Ip { get; set; }

        /// <summary>
        /// PLC类型
        /// </summary>
        public string PlcType { get; set; }

        /// <summary>
        /// 是否可用
        /// </summary>
        public bool IsEnable { get; set; }

        /// <summary>
        /// 是否连接
        /// </summary>
        [NotMapped]
        public bool Online { get; set; } = false;

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime Created { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string CreatedBy { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime Updated { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        public string UpdatedBy { get; set; }


        private ConcurrentBag<Base_EquipmentProp> equipmentProps = new ConcurrentBag<Base_EquipmentProp>();

        /// <summary>
        /// 逻辑外键实体-设备属性
        /// </summary>
        [NotMapped]
        public ConcurrentBag<Base_EquipmentProp> EquipmentProps
        {
            get { return equipmentProps; }
            set
            {
                equipmentProps = value;
                //清空设备属性字典
                propDic.Clear();
                //把值添加到设备属性
                foreach (var item in value)
                {
                    //这里不做重复值检测,重复本来就该有异常
                    propDic.TryAdd(item.Code, item);
                }
            }
        }


        #region 添加数据字典 键值只需要执行一次初始化 后续不需要再Find 

        private ConcurrentDictionary<string, Base_EquipmentProp> propDic = new ConcurrentDictionary<string, Base_EquipmentProp>();
        /// <summary>
        /// 获取设备属性
        /// </summary>
        /// <param name="key">设备属性code </param>
        /// <returns></returns>
        [NotMapped]
        public Base_EquipmentProp? this[string key]
        {
            get
            {
                propDic.TryGetValue(key, out Base_EquipmentProp? prop);
                return prop;
            }
        }
        [NotMapped]
        public Base_EquipmentProp? this[Enum key]
        {
            get
            {
                propDic.TryGetValue(key.ToString(), out Base_EquipmentProp? prop);
                return prop;
            }
        }
        #endregion
    }
}