You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Application/Domain/Statistic.cs

46 lines
1.6 KiB

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();
}
}
}
}