using Edge.Core.Database.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; namespace SuZhou_SIPAC_Client { public class AppDbContext : DbContext { private DbContextOptions options; public AppDbContext() : base() { } //public AppDbContext(DbContextOptions options) : base(options) { this.options = options; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlite("Data Source=SuZhou_SIPAC_Client_App_database.db"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasIndex(p => new { p.Id }).IsUnique(true); modelBuilder.Entity().HasIndex(p => new { p.ReadTimeStamp }).IsUnique(false); modelBuilder.Entity().HasIndex(p => new { p.Id }).IsUnique(true); //modelBuilder.Entity().HasIndex(p => new { p.TriggeredReadingBatchNo }).IsUnique(true); } public DbSet InverterRealTimeDatas { get; set; } public DbSet InverterAccumulatedDatas { get; set; } } public class InverterRealTimeDataModel { public int Id { get; set; } //public Guid ReadingBatchNo { get; set; } public string DeviceName { get; set; } public string DeviceDescription { get; set; } public int DeviceSlaveAddress { get; set; } //public string Id_唯一标识符 { get; set; } //public string gffdqyhh_光伏发电企业户号 { get; set; } //public string qymc_企业名称 { get; set; } //public string tyshxydm_统一社会信用代码 { get; set; } //public string jsdd_建设地点 { get; set; } //public string jsddjwd_建设地点经纬度 { get; set; } //public string xmmc_项目名称 { get; set; } //public DateTime bwtysj_并网投运时间 { get; set; } /// /// 当日有功发电量 KWh /// 此读数一般由设备侧直接提供,无需要fc中进行计算 /// public decimal Raw_当日有功发电量 { get; set; } /// /// 当日无功发电量 Kvarh /// 此读数一般由设备侧直接提供,无需要fc中进行计算 /// public decimal Raw_当日无功发电量 { get; set; } //采集日期 public DateTime ReadTimeStamp { get; set; } public string ToLogString() { return $"采集日期: {this.ReadTimeStamp.ToString("yyyy-MM-dd HH:mm:ss fff")}, 当日有功发电量: {this.Raw_当日有功发电量}, 当日无功发电量: {this.Raw_当日无功发电量}"; } } //public enum AccumulateTypeEnum //{ // ForDay, // ForMonth, // ForYear, //} public class InverterAccumulatedDataModel { public int Id { get; set; } /// /// an accumulation always triggered by a batch reading from devices. /// public List SourceRealTimeDatas { get; set; } //当日有功发电量 KWh public decimal 当日有功发电量 { get; set; } //当日无功发电量 Kvarh public decimal 当日无功发电量 { get; set; } //当月有功发电量 KWh public decimal? 当月有功发电量 { get; set; } //当月无功发电量 KWh public decimal? 当月无功发电量 { get; set; } //当年有功发电量 KWh public decimal? 当年有功发电量 { get; set; } //当年无功发电量 KWh public decimal? 当年无功发电量 { get; set; } public DateTime CreatedTimeStamp { get; set; } public DateTime? HttpPostResponseReceivedTime { get; set; } public string HttpPostResponse { get; set; } public string ToLogString() { return $"DbId: {this.Id}, 当日有功发电量: {this.当日有功发电量}, 当日无功发电量: {this.当日无功发电量}, 当月有功发电量: {this.当月有功发电量}, 当年有功发电量: {this.当年有功发电量}, linked realtime data timestamp: {this.SourceRealTimeDatas?.Max(d => d.ReadTimeStamp).ToString("yyyy-MM-dd HH:mm:ss fff")} "; } } }