EquipmentDataRecord.cs 2.96 KB
using FreeSql.DataAnnotations;
using HHECS.DAQHandle.Common.Utils;
using System.Text.Json;

namespace HHECS.DAQHandle.Models
{
    /// <summary>
    /// 设备数据记录
    /// </summary>
    [Table(Name = "daq_equipmentdatarecord")]
    public class EquipmentDataRecord
    {
        /// <summary>
        /// 设置值异常
        /// </summary>
        public readonly byte SET_VALUE_ERROR = 0b001;
        /// <summary>
        /// 设置报警异常
        /// </summary>
        public readonly byte SET_ALARM_ERROR = 0b010;
        /// <summary>
        /// 设置状态异常
        /// </summary>
        public readonly byte SET_STATUS_ERROR = 0b100;



        /// <summary>
        /// 主键
        /// </summary>
        [Column(IsPrimary = true)]
        public Guid Id { get; set; }

        /// <summary>
        /// 设备编号/IOT云平台设备SN
        /// </summary>
        public string EquipmentCode { get; set; } = null!;

        /// <summary>
        /// 设备类型编号
        /// </summary>
        public string EquipmentTypeCode { get; set; } = null!;

        /// <summary>
        /// 设备名称
        /// </summary>
        public string EquipmentName { get; set; } = null!;

        private string _tags = null;
        /// <summary>
        /// Json数据
        /// </summary>
        [Column(DbType = "varchar(max)")]
        public string Tags
        {
            get { return _tags; }
            set
            {
                _tags = value;
                try
                {
                    if (!string.IsNullOrWhiteSpace(_tags))
                    {
                        Props = JsonSerializer.Deserialize<Dictionary<string, string>>(value);
                    }
                }
                catch (Exception ex)
                {
                    SystemLog.PrintError($"{ex}");
                }
            }
        }


        [Column(IsIgnore = true)]
        public Dictionary<string, string> Props { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>
        public int Version { get; set; }

        /// <summary>
        /// 客户端提交时间戳
        /// </summary>
        public long Timestamp { get; set; }

        /// <summary>
        /// 是否已处理
        /// </summary>
        public bool IsHandle { get; set; }
        /// <summary>
        /// 各阶段是否处理成功
        /// 第一位赋值是否报错,第二位是否记录异常成功 第三位是否记录状态成功
        /// public readonly byte SET_VALUE_ERROR = 0b001;
        /// public readonly byte SET_ALARM_ERROR = 0b010;
        /// public readonly byte SET_STATUS_ERROR = 0b100;
        /// </summary>
        public byte HandleStage { get; set; }

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

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

    }
}