using Infrastructure.Domain; using System; using System.ComponentModel.DataAnnotations; using System.Globalization; namespace Application.Domain.Entities { [Display(Name = "数据统计")] [Scope(ScopeAttribute.PlatformAll | ScopeAttribute.OrganAll)] [Group("物联管控", "IoTCenter")] public class Statistic : BaseEntity { public string Key { get; set; } public string Value { get; set; } public int? IntValue { get; set; } public double? DoubleValue { get; set; } public DateTime? DateTimeValue { get; set; } public StatisticType Type { get; set; } public DateTime UpdateAt { get; set; } public void SetValue(object value) { this.UpdateAt = DateTime.UtcNow; if (this.Type == StatisticType.Int) { this.IntValue = Convert.ToInt32(value); this.Value = this.IntValue.ToString(); } else if (this.Type == StatisticType.Double) { this.DoubleValue = Convert.ToDouble(value); this.Value = this.DoubleValue.Value.ToString("f2"); } else if (this.Type == StatisticType.DateTime) { var timestamp = Convert.ToInt64(value, CultureInfo.InvariantCulture); this.DateTimeValue = DateTimeOffset.FromUnixTimeMilliseconds(timestamp).DateTime; this.Value = Convert.ToString(value); } else { this.Value = value.ToString(); } } } }