fix conditions logic

This commit is contained in:
2026-09-11 23:52:11 +03:30
parent 8eb465c0e7
commit a48deb95da
19 changed files with 2545 additions and 453 deletions

View File

@@ -12,7 +12,8 @@ public sealed class GreenHomeDbContext : DbContext
public DbSet<Domain.AlertCondition> AlertConditions => Set<Domain.AlertCondition>();
public DbSet<Domain.AlertRule> AlertRules => Set<Domain.AlertRule>();
public DbSet<Domain.DeviceRelay> DeviceRelays => Set<Domain.DeviceRelay>();
public DbSet<Domain.RelayRule> RelayRules => Set<Domain.RelayRule>();
public DbSet<Domain.RelayRuleGroup> RelayRuleGroups => Set<Domain.RelayRuleGroup>();
public DbSet<Domain.RelayRuleCondition> RelayRuleConditions => Set<Domain.RelayRuleCondition>();
public DbSet<Domain.User> Users => Set<Domain.User>();
public DbSet<Domain.VerificationCode> VerificationCodes => Set<Domain.VerificationCode>();
public DbSet<Domain.DeviceUser> DeviceUsers => Set<Domain.DeviceUser>();
@@ -101,24 +102,37 @@ public sealed class GreenHomeDbContext : DbContext
b.HasIndex(x => new { x.DeviceSettingsId, x.RelayIndex }).IsUnique();
});
modelBuilder.Entity<Domain.RelayRule>(b =>
modelBuilder.Entity<Domain.RelayRuleGroup>(b =>
{
b.ToTable("RelayRules");
b.ToTable("RelayRuleGroups");
b.HasKey(x => x.Id);
b.Property(x => x.SensorType).IsRequired().HasConversion<int>();
b.Property(x => x.ComparisonType).IsRequired().HasConversion<int>();
b.Property(x => x.Action).IsRequired().HasConversion<int>();
b.Property(x => x.TimeType).IsRequired().HasConversion<int>();
b.Property(x => x.Value1).IsRequired().HasColumnType("decimal(18,2)");
b.Property(x => x.Value2).HasColumnType("decimal(18,2)");
b.Property(x => x.Label).HasMaxLength(200);
b.Property(x => x.Order).IsRequired();
b.HasOne(x => x.DeviceRelay)
.WithMany(r => r.Rules)
.WithMany(r => r.RuleGroups)
.HasForeignKey(x => x.DeviceRelayId)
.OnDelete(DeleteBehavior.Cascade);
b.HasIndex(x => x.DeviceRelayId);
});
modelBuilder.Entity<Domain.RelayRuleCondition>(b =>
{
b.ToTable("RelayRuleConditions");
b.HasKey(x => x.Id);
b.Property(x => x.ConditionType).IsRequired().HasConversion<int>();
b.Property(x => x.SensorType).HasConversion<int>();
b.Property(x => x.ComparisonType).HasConversion<int>();
b.Property(x => x.Value1).HasColumnType("decimal(18,2)");
b.Property(x => x.Value2).HasColumnType("decimal(18,2)");
b.Property(x => x.Order).IsRequired();
b.HasOne(x => x.RelayRuleGroup)
.WithMany(g => g.Conditions)
.HasForeignKey(x => x.RelayRuleGroupId)
.OnDelete(DeleteBehavior.Cascade);
b.HasIndex(x => x.RelayRuleGroupId);
});
modelBuilder.Entity<Domain.AlertCondition>(b =>
{
b.ToTable("AlertConditions");