diff --git a/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/base_device.cs b/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/base_device.cs
index 242f69b..9ad1f02 100644
--- a/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/base_device.cs
+++ b/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/base_device.cs
@@ -41,13 +41,10 @@ namespace VolPro.Entity.DomainModels
///
///来源适配器(类型:实例)
///
- [SugarColumn(IsPrimaryKey = true)]
- [Key]
[Display(Name ="来源适配器(类型:实例)")]
[MaxLength(50)]
[Column(TypeName="nvarchar(50)")]
[Editable(true)]
- [Required(AllowEmptyStrings=false)]
public string AdapterCode { get; set; }
///
@@ -57,7 +54,6 @@ namespace VolPro.Entity.DomainModels
[MaxLength(100)]
[Column(TypeName="nvarchar(100)")]
[Editable(true)]
- [Required(AllowEmptyStrings=false)]
public string SourceId { get; set; }
///
@@ -73,8 +69,6 @@ namespace VolPro.Entity.DomainModels
///
///设备分组(数据字典)
///
- [SugarColumn(IsPrimaryKey = true)]
- [Key]
[Display(Name ="设备分组(数据字典)")]
[MaxLength(20)]
[Column(TypeName="nvarchar(20)")]
@@ -85,23 +79,11 @@ namespace VolPro.Entity.DomainModels
///
///所属点位ID
///
- [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
- [Key]
[Display(Name ="所属点位ID")]
[Column(TypeName="int")]
[Editable(true)]
public int? PointId { get; set; }
- ///
- ///所属网关节点ID
- ///
- [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
- [Key]
- [Display(Name ="所属网关节点ID")]
- [Column(TypeName="int")]
- [Editable(true)]
- public int? GatewayNodeId { get; set; }
-
///
///是否父设备(数据字典)
///
@@ -115,8 +97,6 @@ namespace VolPro.Entity.DomainModels
///
///父设备ID(自引用,子设备挂父设备下)
///
- [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
- [Key]
[Display(Name ="父设备ID(自引用,子设备挂父设备下)")]
[Column(TypeName="int")]
[Editable(true)]
@@ -129,7 +109,6 @@ namespace VolPro.Entity.DomainModels
[MaxLength(20)]
[Column(TypeName="nvarchar(20)")]
[Editable(true)]
- [Required(AllowEmptyStrings=false)]
public string IsOnline { get; set; }
///
@@ -284,6 +263,16 @@ namespace VolPro.Entity.DomainModels
[Editable(true)]
public DateTime? ModifyDate { get; set; }
+ ///
+ ///所属网关节点ID
+ ///
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ [Key]
+ [Display(Name ="所属网关节点ID")]
+ [Column(TypeName="int")]
+ [Editable(true)]
+ public int? NodeId { get; set; }
+
[Display(Name ="视频通道")]
[ForeignKey("DeviceId")][Navigate(NavigateType.OneToMany,nameof(DeviceId),nameof(DeviceId))]
public List video_channel { get; set; }
diff --git a/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/gateway_nodes.cs b/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/gateway_nodes.cs
index d390516..5ed35a9 100644
--- a/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/gateway_nodes.cs
+++ b/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/gateway_nodes.cs
@@ -14,7 +14,7 @@ using VolPro.Entity.SystemModels;
namespace VolPro.Entity.DomainModels
{
- [Entity(TableCnName = "设备管理_网关节点",TableName = "gateway_nodes",DBServer = "ServiceDbContext")]
+ [Entity(TableCnName = "设备管理_网关节点",TableName = "gateway_nodes",DetailTable = new Type[] { typeof(base_device)},DetailTableCnName = "设备管理",DBServer = "ServiceDbContext")]
public partial class gateway_nodes:ServiceEntity
{
///
@@ -165,6 +165,11 @@ namespace VolPro.Entity.DomainModels
[Editable(true)]
public DateTime? ModifyDate { get; set; }
+ [Display(Name ="设备管理")]
+ [ForeignKey("NodeId")][Navigate(NavigateType.OneToMany,nameof(NodeId),nameof(NodeId))]
+ public List base_device { get; set; }
+
+
}
}
\ No newline at end of file
diff --git a/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/partial/base_device.cs b/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/partial/base_device.cs
index 02be855..370b052 100644
--- a/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/partial/base_device.cs
+++ b/api_sqlsugar/VolPro.Entity/DomainModels/device_manager/partial/base_device.cs
@@ -11,17 +11,17 @@ namespace VolPro.Entity.DomainModels
{
public partial class base_device
{
- /// 导航属性:关联视频通道扩展记录(一对一)
- [Navigate(NavigateType.OneToOne, nameof(DeviceId), nameof(video_channel.DeviceId))]
- public video_channel? VideoChannel { get; set; }
+ /////// 导航属性:关联视频通道扩展记录(一对一)
+ ////[Navigate(NavigateType.OneToOne, nameof(DeviceId), nameof(video_channel.DeviceId))]
+ ////public video_channel? VideoChannel { get; set; }
- /// 导航属性:关联告警记录(一对多)
- [Navigate(NavigateType.OneToMany, nameof(DeviceId), nameof(iot_alarm.DeviceId))]
- public List? Alarms { get; set; }
+ /////// 导航属性:关联告警记录(一对多)
+ ////[Navigate(NavigateType.OneToMany, nameof(DeviceId), nameof(iot_alarm.DeviceId))]
+ ////public List? Alarms { get; set; }
- /// 导航属性:关联数据归档(一对多)
- [Navigate(NavigateType.OneToMany, nameof(DeviceId), nameof(iot_devicedata.DeviceId))]
- public List? DeviceData { get; set; }
+ /////// 导航属性:关联数据归档(一对多)
+ ////[Navigate(NavigateType.OneToMany, nameof(DeviceId), nameof(iot_devicedata.DeviceId))]
+ ////public List? DeviceData { get; set; }
///
/// 网关字段白名单。网关同步时,只有此集合中的字段会被覆盖,
diff --git a/api_sqlsugar/VolPro.WebApi/Controllers/Warehouse/Partial/base_deviceController.cs b/api_sqlsugar/VolPro.WebApi/Controllers/Warehouse/Partial/base_deviceController.cs
index be1d362..801ed2b 100644
--- a/api_sqlsugar/VolPro.WebApi/Controllers/Warehouse/Partial/base_deviceController.cs
+++ b/api_sqlsugar/VolPro.WebApi/Controllers/Warehouse/Partial/base_deviceController.cs
@@ -17,6 +17,26 @@ namespace Warehouse.Controllers
{
public partial class base_deviceController
{
+ private readonly Ibase_deviceService _service;//访问业务代码
+ private readonly Iwarehouse_regionsService _regionsService;
+ private readonly Iwarehouse_devicepointService _pointService;
+ private readonly IHttpContextAccessor _httpContextAccessor;
+
+ [ActivatorUtilitiesConstructor]
+ public base_deviceController(
+ Ibase_deviceService service,
+ Iwarehouse_regionsService regionsService,
+ Iwarehouse_devicepointService pointService,
+ IHttpContextAccessor httpContextAccessor
+ )
+ : base(service)
+ {
+ _service = service;
+ _regionsService = regionsService;
+ _pointService = pointService;
+ _httpContextAccessor = httpContextAccessor;
+ }
+
///
/// 获取区域→点位→设备树。
/// 用于管理端左侧树形控件展示层级结构。
@@ -26,32 +46,27 @@ namespace Warehouse.Controllers
[Route("/api/DeviceManager/GetRegionTree")]
public async Task GetRegionTree()
{
- // 获取区域和点位服务
- var regionSvcType = _service.GetType().Assembly.GetType("Warehouse.Services.warehouse_regionsService");
- var pointSvcType = _service.GetType().Assembly.GetType("Warehouse.Services.warehouse_devicepointService");
-
- var regionSvc = regionSvcType?.GetProperty("Instance")?.GetValue(null) as IService;
- var pointSvc = pointSvcType?.GetProperty("Instance")?.GetValue(null) as IService;
-
// 查所有区域
- var regions = regionSvc != null
- ? await regionSvc.FindAsIQueryable(x => true).ToListAsync()
- : new List();
+ var regions = await _regionsService.FindAsIQueryable(x => true).ToListAsync();
// 查所有点位
- var points = pointSvc != null
- ? await pointSvc.FindAsIQueryable(x => true).ToListAsync()
- : new List();
+ var points = await _pointService.FindAsIQueryable(x => true).ToListAsync();
// 统计每个点位下的设备数量
+ //var deviceCounts = new Dictionary();
+ //var allDevices = await _service.FindAsIQueryable(x => true)
+ // .Where(x => x.PointId != null)
+ // .GroupBy(x => x.PointId!.Value)
+ // .Select(g => new { PointId = g.Key, Count = g.Count() })
+ // .ToListAsync();
var deviceCounts = new Dictionary();
- var allDevices = await _service.FindAsIQueryable(x => true)
- .Where(x => x.PointId != null)
- .GroupBy(x => x.PointId!.Value)
- .Select(g => new { PointId = g.Key, Count = g.Count() })
+ var devices = await _service.FindAsIQueryable(x => x.PointId != null)
+ .Select(x => new { x.PointId })
.ToListAsync();
- foreach (var g in allDevices)
- deviceCounts[g.PointId] = g.Count;
+ deviceCounts = devices
+ .Where(x => x.PointId.HasValue)
+ .GroupBy(x => x.PointId!.Value)
+ .ToDictionary(g => g.Key, g => g.Count());
// 构建树形结构
var tree = new List