Equipment.cs 1.83 KB
using DataAcquisition.Common.Enums;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;

namespace DataAcquisition.Models
{
    [Comment("设备表")]
    [Table("Equipment")]
    [Index(nameof(Code), IsUnique = true)]
    public class Equipment
    {
        public Equipment()
        {
            EquipmentProperties = new List<EquipmentProperty>();
        }

        [Key]
        [Comment("设备Id")]
        public int Id { get; set; }

        [Comment("通讯方式")]
        [ForeignKey(nameof(CommunicationConfig))]
        public int? CommunicationId { get; set; }

        public virtual CommunicationConfig? CommunicationConfig { get; set; }

        [Comment("设备编号")]
        public string Code { get; set; } = null!;

        [Comment("设备名称")]
        public string Name { get; set; } = null!;

        [Comment("设备类型")]
        public EquipmentTypeConst EquipmentType { get; set; }

        [Comment("是否启用")]
        public bool Enable { get; set; }

        [Comment("区域")]
        public int Area { get; set; }

        [Comment("创建时间")]
        public DateTime? CreateTime { get; set; } = DateTime.Now;

        [Comment("更新时间")]
        public DateTime? UpdateTime { get; set; } = null!;

        [Comment("备注")]
        public string? Remark { get; set; }

        public virtual IList<EquipmentProperty> EquipmentProperties { get; set; }

        [Comment("设备云平台SN")]
        public string? EquipmentSN { get; set; }

        [Comment("仓库编号")]
        public string? WarehouseCode { get; set; }

        public virtual EquipmentProperty this[string key] => EquipmentProperties.Where(x => x.Code.Equals(key)).First();
    }
}