add Voltage and Power fields
This commit is contained in:
@@ -25,22 +25,11 @@ public class TelemetryController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("AddData")]
|
[HttpGet("AddData")]
|
||||||
public async Task<ActionResult<int>> Create(int deviceId, decimal temperatureC, decimal humidityPercent,
|
public async Task<ActionResult<int>> Create([FromQuery] TelemetryDto telementry, CancellationToken cancellationToken)
|
||||||
decimal soilPercent, int gasPPM, decimal lux, CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
TelemetryDto dto = new TelemetryDto
|
telementry.TimestampUtc = DateTime.UtcNow;
|
||||||
{
|
var id = await telemetryService.AddAsync(telementry, cancellationToken);
|
||||||
//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);
|
|
||||||
|
|
||||||
// Check and send alerts if needed (fire and forget)
|
// Check and send alerts if needed (fire and forget)
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
@@ -48,10 +37,10 @@ public class TelemetryController : ControllerBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get deviceId from the saved telemetry record
|
// Get deviceId from the saved telemetry record
|
||||||
var deviceId = dto.DeviceId;
|
var deviceId = telementry.DeviceId;
|
||||||
if (deviceId > 0)
|
if (deviceId > 0)
|
||||||
{
|
{
|
||||||
await alertService.CheckAndSendAlertsAsync(deviceId, dto, cancellationToken);
|
await alertService.CheckAndSendAlertsAsync(deviceId, telementry, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -19,17 +19,19 @@ public sealed class TelemetryDto
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int DeviceId { get; set; }
|
public int DeviceId { get; set; }
|
||||||
public string DeviceName { get; set; }
|
public string? DeviceName { get; set; }
|
||||||
public DateTime TimestampUtc { get; set; }
|
public DateTime? TimestampUtc { get; set; }
|
||||||
public decimal TemperatureC { get; set; }
|
public decimal TemperatureC { get; set; }
|
||||||
public decimal HumidityPercent { get; set; }
|
public decimal HumidityPercent { get; set; }
|
||||||
public decimal SoilPercent { get; set; }
|
public decimal SoilPercent { get; set; }
|
||||||
public int GasPPM { get; set; }
|
public int GasPPM { get; set; }
|
||||||
|
public decimal? Voltage { get; set; }
|
||||||
|
public byte? Power { get; set; }
|
||||||
public decimal Lux { get; set; }
|
public decimal Lux { get; set; }
|
||||||
public int PersianYear { get; set; }
|
public int? PersianYear { get; set; }
|
||||||
public int PersianMonth { get; set; }
|
public int? PersianMonth { get; set; }
|
||||||
public string PersianDate { get; set; } = string.Empty;
|
public string PersianDate { get; set; } = string.Empty;
|
||||||
public DateTime ServerTimestampUtc { get; set; }
|
public DateTime? ServerTimestampUtc { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class TelemetryFilter
|
public sealed class TelemetryFilter
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace GreenHome.Domain;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace GreenHome.Domain;
|
||||||
|
|
||||||
public sealed class TelemetryRecord
|
public sealed class TelemetryRecord
|
||||||
{
|
{
|
||||||
@@ -11,6 +13,10 @@ public sealed class TelemetryRecord
|
|||||||
public decimal SoilPercent { get; set; } // decimal(18,2)
|
public decimal SoilPercent { get; set; } // decimal(18,2)
|
||||||
public int GasPPM { get; set; }
|
public int GasPPM { get; set; }
|
||||||
public decimal Lux { get; set; } // decimal(18,2)
|
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 PersianYear { get; set; }
|
||||||
public int PersianMonth { get; set; }
|
public int PersianMonth { get; set; }
|
||||||
public string PersianDate { get; set; } = string.Empty; // yyyy/MM/dd
|
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")
|
b.Property<int>("PersianYear")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<byte?>("Power")
|
||||||
|
.HasColumnType("tinyint");
|
||||||
|
|
||||||
b.Property<DateTime>("ServerTimestampUtc")
|
b.Property<DateTime>("ServerTimestampUtc")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
@@ -752,6 +755,9 @@ namespace GreenHome.Infrastructure.Migrations
|
|||||||
b.Property<DateTime>("TimestampUtc")
|
b.Property<DateTime>("TimestampUtc")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<decimal?>("Voltage")
|
||||||
|
.HasColumnType("decimal(18,2)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("DeviceId", "ServerTimestampUtc");
|
b.HasIndex("DeviceId", "ServerTimestampUtc");
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public sealed class TelemetryService : ITelemetryService
|
|||||||
// ذخیره زمان سرور در لحظه ثبت
|
// ذخیره زمان سرور در لحظه ثبت
|
||||||
entity.ServerTimestampUtc = DateTime.Now;
|
entity.ServerTimestampUtc = DateTime.Now;
|
||||||
|
|
||||||
var dt = dto.TimestampUtc.ToLocalTime();
|
var dt = dto.TimestampUtc!.Value.ToLocalTime();
|
||||||
var py = PersianCalendar.GetYear(dt);
|
var py = PersianCalendar.GetYear(dt);
|
||||||
var pm = PersianCalendar.GetMonth(dt);
|
var pm = PersianCalendar.GetMonth(dt);
|
||||||
var pd = PersianCalendar.GetDayOfMonth(dt);
|
var pd = PersianCalendar.GetDayOfMonth(dt);
|
||||||
|
|||||||
Reference in New Issue
Block a user