新增车辆表及OTA权限与逻辑优化

新增车辆任务与报警表,完善实体与DbContext配置。细化OTA权限校验,增强回传会话IP安全。优化OTA上传与设置面板,调度器支持重启恢复。报警采集逻辑支持历史分段。
This commit is contained in:
2026-07-27 15:12:14 +08:00
parent bc3e9c5172
commit 1f72488a8d
20 changed files with 2392 additions and 53 deletions
+32
View File
@@ -0,0 +1,32 @@
namespace MiGu.DB.Domains.Fleet;
/// <summary>
/// CDM 搬运任务的平台侧快照(表 cdm_tasks)。
/// 以任务 Id 为主键;SimpleLite/StandardScene 把终态任务从自身 JSON 里删除,这里则永久保留=完整历史。
/// </summary>
public sealed class CdmTaskRecord
{
public string Id { get; set; } = "";
public string? TaskId { get; set; }
public int MissionId { get; set; }
public string MissionName { get; set; } = "";
public string MissionTypeName { get; set; } = "";
public int SrcSiteId { get; set; }
public string SrcLabel { get; set; } = "";
public int DstSiteId { get; set; }
public string DstLabel { get; set; } = "";
public string Status { get; set; } = "";
public string StatusCode { get; set; } = "";
public int? CarId { get; set; }
public string? CarName { get; set; }
public int Priority { get; set; }
/// <summary>下发/开始/结束时间:直接存投影返回的 ISO 字符串(可空)。</summary>
public string? CreateTime { get; set; }
public string? StartTime { get; set; }
public string? FinishTime { get; set; }
public string? StuckReason { get; set; }
public bool Overdue { get; set; }
/// <summary>平台首次/最近一次同步到该任务的时间。</summary>
public DateTimeOffset FirstSeenAt { get; set; }
public DateTimeOffset LastSeenAt { get; set; }
}
@@ -0,0 +1,61 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace MiGu.DB.Domains.Fleet;
public sealed class CdmTaskRecordConfiguration : IEntityTypeConfiguration<CdmTaskRecord>
{
public void Configure(EntityTypeBuilder<CdmTaskRecord> e)
{
e.ToTable("cdm_tasks");
e.HasKey(x => x.Id);
e.Property(x => x.Id).HasColumnName("id").HasMaxLength(64);
e.Property(x => x.TaskId).HasColumnName("task_id").HasMaxLength(128).IsRequired(false);
e.Property(x => x.MissionId).HasColumnName("mission_id");
e.Property(x => x.MissionName).HasColumnName("mission_name").HasMaxLength(128);
e.Property(x => x.MissionTypeName).HasColumnName("mission_type").HasMaxLength(128);
e.Property(x => x.SrcSiteId).HasColumnName("src_site_id");
e.Property(x => x.SrcLabel).HasColumnName("src_label").HasMaxLength(256);
e.Property(x => x.DstSiteId).HasColumnName("dst_site_id");
e.Property(x => x.DstLabel).HasColumnName("dst_label").HasMaxLength(256);
e.Property(x => x.Status).HasColumnName("status").HasMaxLength(32);
e.Property(x => x.StatusCode).HasColumnName("status_code").HasMaxLength(32);
e.Property(x => x.CarId).HasColumnName("car_id").IsRequired(false);
e.Property(x => x.CarName).HasColumnName("car_name").HasMaxLength(128).IsRequired(false);
e.Property(x => x.Priority).HasColumnName("priority");
e.Property(x => x.CreateTime).HasColumnName("create_time").HasMaxLength(40).IsRequired(false);
e.Property(x => x.StartTime).HasColumnName("start_time").HasMaxLength(40).IsRequired(false);
e.Property(x => x.FinishTime).HasColumnName("finish_time").HasMaxLength(40).IsRequired(false);
e.Property(x => x.StuckReason).HasColumnName("stuck_reason").HasMaxLength(512).IsRequired(false);
e.Property(x => x.Overdue).HasColumnName("overdue");
e.Property(x => x.FirstSeenAt).HasColumnName("first_seen_at");
e.Property(x => x.LastSeenAt).HasColumnName("last_seen_at");
e.HasIndex(x => x.StatusCode);
e.HasIndex(x => x.CreateTime);
}
}
public sealed class VehicleAlarmRecordConfiguration : IEntityTypeConfiguration<VehicleAlarmRecord>
{
public void Configure(EntityTypeBuilder<VehicleAlarmRecord> e)
{
e.ToTable("vehicle_alarms");
e.HasKey(x => x.Id);
e.Property(x => x.Id).HasColumnName("id").HasMaxLength(36);
e.Property(x => x.CarId).HasColumnName("car_id");
e.Property(x => x.CarName).HasColumnName("car_name").HasMaxLength(128);
e.Property(x => x.Info).HasColumnName("info").HasColumnType("text");
e.Property(x => x.Level).HasColumnName("level");
e.Property(x => x.Status).HasColumnName("status").HasMaxLength(16);
e.Property(x => x.FirstAt).HasColumnName("first_at");
e.Property(x => x.LastAt).HasColumnName("last_at");
e.Property(x => x.ResolvedAt).HasColumnName("resolved_at").IsRequired(false);
e.Property(x => x.DurationSecs).HasColumnName("duration_secs").IsRequired(false);
e.Property(x => x.Acknowledged).HasColumnName("acknowledged");
e.Property(x => x.AcknowledgedAt).HasColumnName("acknowledged_at").IsRequired(false);
e.Property(x => x.AcknowledgedBy).HasColumnName("acknowledged_by").HasMaxLength(128).IsRequired(false);
e.HasIndex(x => new { x.CarId, x.Status });
e.HasIndex(x => x.Status);
e.HasIndex(x => x.FirstAt);
}
}
@@ -0,0 +1,27 @@
namespace MiGu.DB.Domains.Fleet;
/// <summary>
/// 车辆报警的平台侧记录(表 vehicle_alarms)。
/// 出现报警→开一条 active 记录;文案/级别变化→先 clear 再建新 active;消失→cleared。
/// </summary>
public sealed class VehicleAlarmRecord
{
public string Id { get; set; } = Guid.NewGuid().ToString("D");
public int CarId { get; set; }
public string CarName { get; set; } = "";
/// <summary>报警文案(车体_AlarmInfo)。</summary>
public string Info { get; set; } = "";
/// <summary>报警级别(车体_AlarmLevel,未知为 0)。</summary>
public int Level { get; set; }
/// <summary>active | cleared</summary>
public string Status { get; set; } = "active";
public DateTimeOffset FirstAt { get; set; }
public DateTimeOffset LastAt { get; set; }
public DateTimeOffset? ResolvedAt { get; set; }
/// <summary>持续时长(秒),恢复后写入。</summary>
public long? DurationSecs { get; set; }
/// <summary>预留:平台侧确认(不代表车端消警)。</summary>
public bool Acknowledged { get; set; }
public DateTimeOffset? AcknowledgedAt { get; set; }
public string? AcknowledgedBy { get; set; }
}
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using MiGu.DB.Domains.Dashboard;
using MiGu.DB.Domains.Fleet;
using MiGu.DB.Domains.SimpleFields;
using MiGu.DB.Domains.Transport;
using MiGu.DB.Domains.Wms;
@@ -25,4 +26,6 @@ public partial class MiGuDbContext
public DbSet<WmsTransportTaskHistory> WmsTransportTaskHistories => Set<WmsTransportTaskHistory>();
public DbSet<SimpleField> SimpleFields => Set<SimpleField>();
public DbSet<UserDashboardShortcut> UserDashboardShortcuts => Set<UserDashboardShortcut>();
public DbSet<CdmTaskRecord> CdmTasks => Set<CdmTaskRecord>();
public DbSet<VehicleAlarmRecord> VehicleAlarms => Set<VehicleAlarmRecord>();
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,103 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MiGu.DB.Migrations.Sqlite
{
/// <inheritdoc />
public partial class AddFleetTables : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "cdm_tasks",
columns: table => new
{
id = table.Column<string>(type: "TEXT", maxLength: 64, nullable: false),
task_id = table.Column<string>(type: "TEXT", maxLength: 128, nullable: true),
mission_id = table.Column<int>(type: "INTEGER", nullable: false),
mission_name = table.Column<string>(type: "TEXT", maxLength: 128, nullable: false),
mission_type = table.Column<string>(type: "TEXT", maxLength: 128, nullable: false),
src_site_id = table.Column<int>(type: "INTEGER", nullable: false),
src_label = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
dst_site_id = table.Column<int>(type: "INTEGER", nullable: false),
dst_label = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
status = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
status_code = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
car_id = table.Column<int>(type: "INTEGER", nullable: true),
car_name = table.Column<string>(type: "TEXT", maxLength: 128, nullable: true),
priority = table.Column<int>(type: "INTEGER", nullable: false),
create_time = table.Column<string>(type: "TEXT", maxLength: 40, nullable: true),
start_time = table.Column<string>(type: "TEXT", maxLength: 40, nullable: true),
finish_time = table.Column<string>(type: "TEXT", maxLength: 40, nullable: true),
stuck_reason = table.Column<string>(type: "TEXT", maxLength: 512, nullable: true),
overdue = table.Column<bool>(type: "INTEGER", nullable: false),
first_seen_at = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false),
last_seen_at = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_cdm_tasks", x => x.id);
});
migrationBuilder.CreateTable(
name: "vehicle_alarms",
columns: table => new
{
id = table.Column<string>(type: "TEXT", maxLength: 36, nullable: false),
car_id = table.Column<int>(type: "INTEGER", nullable: false),
car_name = table.Column<string>(type: "TEXT", maxLength: 128, nullable: false),
info = table.Column<string>(type: "text", nullable: false),
level = table.Column<int>(type: "INTEGER", nullable: false),
status = table.Column<string>(type: "TEXT", maxLength: 16, nullable: false),
first_at = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false),
last_at = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false),
resolved_at = table.Column<string>(type: "TEXT", maxLength: 40, nullable: true),
duration_secs = table.Column<long>(type: "INTEGER", nullable: true),
acknowledged = table.Column<bool>(type: "INTEGER", nullable: false),
acknowledged_at = table.Column<string>(type: "TEXT", maxLength: 40, nullable: true),
acknowledged_by = table.Column<string>(type: "TEXT", maxLength: 128, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_vehicle_alarms", x => x.id);
});
migrationBuilder.CreateIndex(
name: "IX_cdm_tasks_create_time",
table: "cdm_tasks",
column: "create_time");
migrationBuilder.CreateIndex(
name: "IX_cdm_tasks_status_code",
table: "cdm_tasks",
column: "status_code");
migrationBuilder.CreateIndex(
name: "IX_vehicle_alarms_car_id_status",
table: "vehicle_alarms",
columns: new[] { "car_id", "status" });
migrationBuilder.CreateIndex(
name: "IX_vehicle_alarms_first_at",
table: "vehicle_alarms",
column: "first_at");
migrationBuilder.CreateIndex(
name: "IX_vehicle_alarms_status",
table: "vehicle_alarms",
column: "status");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "cdm_tasks");
migrationBuilder.DropTable(
name: "vehicle_alarms");
}
}
}
@@ -45,6 +45,202 @@ namespace MiGu.DB.Migrations.Sqlite
b.ToTable("user_dashboard_shortcuts", (string)null);
});
modelBuilder.Entity("MiGu.DB.Domains.Fleet.CdmTaskRecord", b =>
{
b.Property<string>("Id")
.HasMaxLength(64)
.HasColumnType("TEXT")
.HasColumnName("id");
b.Property<int?>("CarId")
.HasColumnType("INTEGER")
.HasColumnName("car_id");
b.Property<string>("CarName")
.HasMaxLength(128)
.HasColumnType("TEXT")
.HasColumnName("car_name");
b.Property<string>("CreateTime")
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("create_time");
b.Property<string>("DstLabel")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT")
.HasColumnName("dst_label");
b.Property<int>("DstSiteId")
.HasColumnType("INTEGER")
.HasColumnName("dst_site_id");
b.Property<string>("FinishTime")
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("finish_time");
b.Property<string>("FirstSeenAt")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("first_seen_at");
b.Property<string>("LastSeenAt")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("last_seen_at");
b.Property<int>("MissionId")
.HasColumnType("INTEGER")
.HasColumnName("mission_id");
b.Property<string>("MissionName")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("TEXT")
.HasColumnName("mission_name");
b.Property<string>("MissionTypeName")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("TEXT")
.HasColumnName("mission_type");
b.Property<bool>("Overdue")
.HasColumnType("INTEGER")
.HasColumnName("overdue");
b.Property<int>("Priority")
.HasColumnType("INTEGER")
.HasColumnName("priority");
b.Property<string>("SrcLabel")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT")
.HasColumnName("src_label");
b.Property<int>("SrcSiteId")
.HasColumnType("INTEGER")
.HasColumnName("src_site_id");
b.Property<string>("StartTime")
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("start_time");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT")
.HasColumnName("status");
b.Property<string>("StatusCode")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT")
.HasColumnName("status_code");
b.Property<string>("StuckReason")
.HasMaxLength(512)
.HasColumnType("TEXT")
.HasColumnName("stuck_reason");
b.Property<string>("TaskId")
.HasMaxLength(128)
.HasColumnType("TEXT")
.HasColumnName("task_id");
b.HasKey("Id");
b.HasIndex("CreateTime");
b.HasIndex("StatusCode");
b.ToTable("cdm_tasks", (string)null);
});
modelBuilder.Entity("MiGu.DB.Domains.Fleet.VehicleAlarmRecord", b =>
{
b.Property<string>("Id")
.HasMaxLength(36)
.HasColumnType("TEXT")
.HasColumnName("id");
b.Property<bool>("Acknowledged")
.HasColumnType("INTEGER")
.HasColumnName("acknowledged");
b.Property<string>("AcknowledgedAt")
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("acknowledged_at");
b.Property<string>("AcknowledgedBy")
.HasMaxLength(128)
.HasColumnType("TEXT")
.HasColumnName("acknowledged_by");
b.Property<int>("CarId")
.HasColumnType("INTEGER")
.HasColumnName("car_id");
b.Property<string>("CarName")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("TEXT")
.HasColumnName("car_name");
b.Property<long?>("DurationSecs")
.HasColumnType("INTEGER")
.HasColumnName("duration_secs");
b.Property<string>("FirstAt")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("first_at");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("text")
.HasColumnName("info");
b.Property<string>("LastAt")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("last_at");
b.Property<int>("Level")
.HasColumnType("INTEGER")
.HasColumnName("level");
b.Property<string>("ResolvedAt")
.HasMaxLength(40)
.HasColumnType("TEXT")
.HasColumnName("resolved_at");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("TEXT")
.HasColumnName("status");
b.HasKey("Id");
b.HasIndex("FirstAt");
b.HasIndex("Status");
b.HasIndex("CarId", "Status");
b.ToTable("vehicle_alarms", (string)null);
});
modelBuilder.Entity("MiGu.DB.Domains.SimpleFields.SimpleField", b =>
{
b.Property<string>("Id")