AppDbContext.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Edge.Core.Database.Models;
  2. using Microsoft.EntityFrameworkCore;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace SuZhou_SIPAC_Client
  7. {
  8. public class AppDbContext : DbContext
  9. {
  10. private DbContextOptions options;
  11. public AppDbContext() : base()
  12. {
  13. }
  14. //public AppDbContext(DbContextOptions options) : base(options) { this.options = options; }
  15. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  16. {
  17. optionsBuilder.UseSqlite("Data Source=SuZhou_SIPAC_Client_App_database.db");
  18. }
  19. protected override void OnModelCreating(ModelBuilder modelBuilder)
  20. {
  21. modelBuilder.Entity<InverterRealTimeDataModel>().HasIndex(p => new { p.Id }).IsUnique(true);
  22. modelBuilder.Entity<InverterRealTimeDataModel>().HasIndex(p => new { p.ReadTimeStamp }).IsUnique(false);
  23. modelBuilder.Entity<InverterAccumulatedDataModel>().HasIndex(p => new { p.Id }).IsUnique(true);
  24. //modelBuilder.Entity<InverterAccumulatedDataModel>().HasIndex(p => new { p.TriggeredReadingBatchNo }).IsUnique(true);
  25. }
  26. public DbSet<InverterRealTimeDataModel> InverterRealTimeDatas { get; set; }
  27. public DbSet<InverterAccumulatedDataModel> InverterAccumulatedDatas { get; set; }
  28. }
  29. public class InverterRealTimeDataModel
  30. {
  31. public int Id { get; set; }
  32. //public Guid ReadingBatchNo { get; set; }
  33. public string DeviceName { get; set; }
  34. public string DeviceDescription { get; set; }
  35. public int DeviceSlaveAddress { get; set; }
  36. //public string Id_唯一标识符 { get; set; }
  37. //public string gffdqyhh_光伏发电企业户号 { get; set; }
  38. //public string qymc_企业名称 { get; set; }
  39. //public string tyshxydm_统一社会信用代码 { get; set; }
  40. //public string jsdd_建设地点 { get; set; }
  41. //public string jsddjwd_建设地点经纬度 { get; set; }
  42. //public string xmmc_项目名称 { get; set; }
  43. //public DateTime bwtysj_并网投运时间 { get; set; }
  44. /// <summary>
  45. /// 当日有功发电量 KWh
  46. /// 此读数一般由设备侧直接提供,无需要fc中进行计算
  47. /// </summary>
  48. public decimal Raw_当日有功发电量 { get; set; }
  49. /// <summary>
  50. /// 当日无功发电量 Kvarh
  51. /// 此读数一般由设备侧直接提供,无需要fc中进行计算
  52. /// </summary>
  53. public decimal Raw_当日无功发电量 { get; set; }
  54. //采集日期
  55. public DateTime ReadTimeStamp { get; set; }
  56. public string ToLogString()
  57. {
  58. return $"采集日期: {this.ReadTimeStamp.ToString("yyyy-MM-dd HH:mm:ss fff")}, 当日有功发电量: {this.Raw_当日有功发电量}, 当日无功发电量: {this.Raw_当日无功发电量}";
  59. }
  60. }
  61. //public enum AccumulateTypeEnum
  62. //{
  63. // ForDay,
  64. // ForMonth,
  65. // ForYear,
  66. //}
  67. public class InverterAccumulatedDataModel
  68. {
  69. public int Id { get; set; }
  70. /// <summary>
  71. /// an accumulation always triggered by a batch reading from devices.
  72. /// </summary>
  73. public List<InverterRealTimeDataModel> SourceRealTimeDatas { get; set; }
  74. //当日有功发电量 KWh
  75. public decimal 当日有功发电量 { get; set; }
  76. //当日无功发电量 Kvarh
  77. public decimal 当日无功发电量 { get; set; }
  78. //当月有功发电量 KWh
  79. public decimal? 当月有功发电量 { get; set; }
  80. //当月无功发电量 KWh
  81. public decimal? 当月无功发电量 { get; set; }
  82. //当年有功发电量 KWh
  83. public decimal? 当年有功发电量 { get; set; }
  84. //当年无功发电量 KWh
  85. public decimal? 当年无功发电量 { get; set; }
  86. public DateTime CreatedTimeStamp { get; set; }
  87. public DateTime? HttpPostResponseReceivedTime { get; set; }
  88. public string HttpPostResponse { get; set; }
  89. public string ToLogString()
  90. {
  91. 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")} ";
  92. }
  93. }
  94. }