add Voltage and Power fields
This commit is contained in:
@@ -25,22 +25,11 @@ public class TelemetryController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("AddData")]
|
||||
public async Task<ActionResult<int>> Create(int deviceId, decimal temperatureC, decimal humidityPercent,
|
||||
decimal soilPercent, int gasPPM, decimal lux, CancellationToken cancellationToken)
|
||||
public async Task<ActionResult<int>> Create([FromQuery] TelemetryDto telementry, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
TelemetryDto dto = new TelemetryDto
|
||||
{
|
||||
//DeviceName = deviceName.ToString() == "dr110"? "dr110":"",
|
||||
DeviceId = deviceId,
|
||||
TemperatureC = temperatureC,
|
||||
HumidityPercent = humidityPercent,
|
||||
SoilPercent = soilPercent,
|
||||
GasPPM = gasPPM,
|
||||
Lux = lux,
|
||||
TimestampUtc = DateTime.UtcNow
|
||||
};
|
||||
var id = await telemetryService.AddAsync(dto, cancellationToken);
|
||||
telementry.TimestampUtc = DateTime.UtcNow;
|
||||
var id = await telemetryService.AddAsync(telementry, cancellationToken);
|
||||
|
||||
// Check and send alerts if needed (fire and forget)
|
||||
_ = Task.Run(async () =>
|
||||
@@ -48,10 +37,10 @@ public class TelemetryController : ControllerBase
|
||||
try
|
||||
{
|
||||
// Get deviceId from the saved telemetry record
|
||||
var deviceId = dto.DeviceId;
|
||||
var deviceId = telementry.DeviceId;
|
||||
if (deviceId > 0)
|
||||
{
|
||||
await alertService.CheckAndSendAlertsAsync(deviceId, dto, cancellationToken);
|
||||
await alertService.CheckAndSendAlertsAsync(deviceId, telementry, cancellationToken);
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -19,17 +19,19 @@ public sealed class TelemetryDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int DeviceId { get; set; }
|
||||
public string DeviceName { get; set; }
|
||||
public DateTime TimestampUtc { get; set; }
|
||||
public string? DeviceName { get; set; }
|
||||
public DateTime? TimestampUtc { get; set; }
|
||||
public decimal TemperatureC { get; set; }
|
||||
public decimal HumidityPercent { get; set; }
|
||||
public decimal SoilPercent { get; set; }
|
||||
public int GasPPM { get; set; }
|
||||
public decimal? Voltage { get; set; }
|
||||
public byte? Power { get; set; }
|
||||
public decimal Lux { get; set; }
|
||||
public int PersianYear { get; set; }
|
||||
public int PersianMonth { get; set; }
|
||||
public int? PersianYear { get; set; }
|
||||
public int? PersianMonth { get; set; }
|
||||
public string PersianDate { get; set; } = string.Empty;
|
||||
public DateTime ServerTimestampUtc { get; set; }
|
||||
public DateTime? ServerTimestampUtc { get; set; }
|
||||
}
|
||||
|
||||
public sealed class TelemetryFilter
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace GreenHome.Domain;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace GreenHome.Domain;
|
||||
|
||||
public sealed class TelemetryRecord
|
||||
{
|
||||
@@ -11,6 +13,10 @@ public sealed class TelemetryRecord
|
||||
public decimal SoilPercent { get; set; } // decimal(18,2)
|
||||
public int GasPPM { get; set; }
|
||||
public decimal Lux { get; set; } // decimal(18,2)
|
||||
|
||||
[Column(TypeName = "decimal(18,2)")]
|
||||
public decimal? Voltage { get; set; }
|
||||
public byte? Power { get; set; }
|
||||
public int PersianYear { get; set; }
|
||||
public int PersianMonth { get; set; }
|
||||
public string PersianDate { get; set; } = string.Empty; // yyyy/MM/dd
|
||||
|
||||
1224
src/GreenHome.Infrastructure/Migrations/20260106150615_POWER_VOLTAGE_FIELDS.Designer.cs
generated
Normal file
1224
src/GreenHome.Infrastructure/Migrations/20260106150615_POWER_VOLTAGE_FIELDS.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace GreenHome.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class POWER_VOLTAGE_FIELDS : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<byte>(
|
||||
name: "Power",
|
||||
table: "Telemetry",
|
||||
type: "tinyint",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Voltage",
|
||||
table: "Telemetry",
|
||||
type: "int",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Power",
|
||||
table: "Telemetry");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Voltage",
|
||||
table: "Telemetry");
|
||||
}
|
||||
}
|
||||
}
|
||||
1224
src/GreenHome.Infrastructure/Migrations/20260106151206_FIX_VOLTAGE_TYPE.Designer.cs
generated
Normal file
1224
src/GreenHome.Infrastructure/Migrations/20260106151206_FIX_VOLTAGE_TYPE.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace GreenHome.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FIX_VOLTAGE_TYPE : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "Voltage",
|
||||
table: "Telemetry",
|
||||
type: "decimal(18,2)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int",
|
||||
oldNullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "Voltage",
|
||||
table: "Telemetry",
|
||||
type: "int",
|
||||
nullable: true,
|
||||
oldClrType: typeof(decimal),
|
||||
oldType: "decimal(18,2)",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -740,6 +740,9 @@ namespace GreenHome.Infrastructure.Migrations
|
||||
b.Property<int>("PersianYear")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<byte?>("Power")
|
||||
.HasColumnType("tinyint");
|
||||
|
||||
b.Property<DateTime>("ServerTimestampUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
@@ -752,6 +755,9 @@ namespace GreenHome.Infrastructure.Migrations
|
||||
b.Property<DateTime>("TimestampUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<decimal?>("Voltage")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DeviceId", "ServerTimestampUtc");
|
||||
|
||||
@@ -40,7 +40,7 @@ public sealed class TelemetryService : ITelemetryService
|
||||
// ذخیره زمان سرور در لحظه ثبت
|
||||
entity.ServerTimestampUtc = DateTime.Now;
|
||||
|
||||
var dt = dto.TimestampUtc.ToLocalTime();
|
||||
var dt = dto.TimestampUtc!.Value.ToLocalTime();
|
||||
var py = PersianCalendar.GetYear(dt);
|
||||
var pm = PersianCalendar.GetMonth(dt);
|
||||
var pd = PersianCalendar.GetDayOfMonth(dt);
|
||||
|
||||
Reference in New Issue
Block a user