iotcenter:1.1.0.5

添加树型结构左右值方式支持

Former-commit-id: e8ffcb08be162cad83d83769584bc9927ae45883
Former-commit-id: 3ad3ad4e9c1fe4b0b5056aa6b27b98cfc8e15ab9
1.0
wanggang 5 years ago
parent c59273edec
commit 649fffa70d

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Infrastructure.Domain
{
@ -14,21 +15,65 @@ namespace Infrastructure.Domain
public List<T> Children { get; set; } = new List<T>();
#pragma warning restore CA2227 // 集合属性应为只读
public List<T> GetPath()
//public List<T> GetPath()
//{
// var list = new List<T>();
// var item = this as T;
// while (item != null)
// {
// list.Add(item);
// if (item.Parent == null || item.Parent.Id == this.Id)
// {
// break;
// }
// item = item.Parent;
// }
// list.Reverse();
// return list;
//}
private void UpdateLeftRight()
{
var list = new List<T>();
var item = this as T;
while (item != null)
}
public void Update()
{
Left(this as T);
void Left(T node, int prev = 0)
{
if (node.Parent == null)
{
node.Left = 1;
}
else
{
node.Left = prev + 1;
}
if (node.Children.Any())
{
Left(node.Children.OrderBy(o => o.DisplayOrder).First(), node.Left);
}
else
{
Right(node, node.Left);
}
}
void Right(T node, int prev)
{
list.Add(item);
if (item.Parent == null || item.Parent.Id == this.Id)
node.Right = prev + 1;
if (node.Parent != null)
{
break;
var list = node.Parent.Children.OrderBy(o => o.DisplayOrder).ToList();
var index = list.IndexOf(node);
if (list.Count > index + 1)
{
Left(list[index + 1], node.Right);
}
else
{
Right(node.Parent, node.Right);
}
}
item = item.Parent;
}
list.Reverse();
return list;
}
}
}

@ -1,4 +1,4 @@
using Application.Domain.Entities;
using Application.Domain.Entities;
using Cronos;
using Infrastructure.Data;
using Infrastructure.Extensions;
@ -30,6 +30,7 @@ namespace IoT.Shared.Areas.Admin.Controlls
private readonly IRepository<Command> _commandRepo;
private readonly IRepository<Scene> _sceneRepo;
private readonly IRepository<SceneTigger> _sceneTiggerRepo;
private readonly IRepository<Area> _areaRepo;
public AjaxController(ILogger<AjaxController> logger,
IRepository<Category> categoryRepo,
@ -43,7 +44,8 @@ namespace IoT.Shared.Areas.Admin.Controlls
IRepository<Device> deviceRepo,
IRepository<Data> dataRepo,
IRepository<Api> apiRepo,
IRepository<SceneTigger> sceneTiggerRepo)
IRepository<SceneTigger> sceneTiggerRepo,
IRepository<Area> areaRepo)
{
this._logger = logger;
this._categoryRepo = categoryRepo;
@ -58,6 +60,7 @@ namespace IoT.Shared.Areas.Admin.Controlls
this._dataRepo = dataRepo;
this._apiRepo = apiRepo;
this._sceneTiggerRepo = sceneTiggerRepo;
this._areaRepo = areaRepo;
}
public MultiSelectList GetNodeMultiSelectList(IEnumerable<Guid> selected)
@ -245,7 +248,7 @@ namespace IoT.Shared.Areas.Admin.Controlls
{
var list = this._dataRepo.ReadOnlyTable()
.Where(o => !o.Hidden && o.DeviceId == parentId)
.Select(o => new { o.Id, Name = $"{o.Name}[当前数据:{o.Value})(当前状态:{o.Description}]" })
.Select(o => new { o.Id, Name = $"{o.Name}[当前数据:{o.Value})(当前状态:{o.Description}]" })
.ToList();
return new SelectList(list, "Id", "Name", selected);
}
@ -297,6 +300,18 @@ namespace IoT.Shared.Areas.Admin.Controlls
#endregion Api
public SelectList GetAreaSelectList(Guid? selected = null, Guid? currentId = null)
{
var list = this._areaRepo.ReadOnlyTable()
.Where(o => o.ParentId != null)
.WhereIf(currentId.HasValue, o => o.Id != currentId.Value)
.OrderBy(o => o.Parent)
.ThenBy(o => o.DisplayOrder)
.Select(o => new { o.Id, Name = $"{o.Name}({o.Number})" })
.ToList();
return new SelectList(list, "Id", "Name", selected);
}
public SelectList GetCameraSelectList(string deviceNumber)
{
var list = this._deviceRepo.ReadOnlyTable()
@ -338,7 +353,7 @@ namespace IoT.Shared.Areas.Admin.Controlls
}
else
{
return new JsonResult($"表达式运算结果无效:{result}");
return new JsonResult($"表达式运算结果无效:{result}");
}
}
catch (Exception ex)

@ -28,10 +28,13 @@ namespace IoTCenter
{
IoTSharedDbConfig.OnModelCreating(modelBuilder);
//
modelBuilder.Entity<Area>().HasIndex(o => o.Number).IsUnique();
modelBuilder.Entity<Area>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId).OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<Department>().HasIndex(o => new { o.OrganId, o.Number }).IsUnique();
modelBuilder.Entity<Department>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId).OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<Department>().Property(o => o.Number).IsRequired();
modelBuilder.Entity<Department>().HasIndex(o => o.Number).IsUnique();
modelBuilder.Entity<Organ>().HasIndex(o => o.Number).IsUnique();
modelBuilder.Entity<Organ>().Property(o => o.Name).IsRequired();
modelBuilder.Entity<Organ>().Property(o => o.Number).IsRequired();
modelBuilder.Entity<Organ>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId).OnDelete(DeleteBehavior.SetNull);
@ -53,6 +56,7 @@ namespace IoTCenter
modelBuilder.Entity<OrganSceneTigger>().HasOne(o => o.Data).WithMany(o => o.OrganSceneTiggers).HasForeignKey(o => o.DataId);
//
modelBuilder.Entity<NodeCategory>().HasIndex(o => o.Name).IsUnique();
modelBuilder.Entity<NodeCategory>().HasIndex(o => o.Number).IsUnique();
modelBuilder.Entity<NodeCategoryNode>().HasOne(o => o.Node).WithMany(o => o.CategoryNodes).HasForeignKey(o => o.NodeId);
modelBuilder.Entity<NodeCategoryNode>().HasOne(o => o.Category).WithMany(o => o.CategoryNodes).HasForeignKey(o => o.CategoryId);
modelBuilder.Entity<NodeCategoryNode>().HasIndex(o => new { o.CategoryId, o.NodeId }).IsUnique();

@ -4,7 +4,7 @@
<SatelliteResourceLanguages>Zh-CN</SatelliteResourceLanguages>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<GenerateAssemblyProductAttribute>true</GenerateAssemblyProductAttribute>
<Version>1.1.0.4</Version>
<Version>1.1.0.5</Version>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

@ -6,7 +6,7 @@
`Right` int NOT NULL,
`ParentId` char(36) NULL,
`Name` longtext CHARACTER SET utf8mb4 NULL,
`Number` longtext CHARACTER SET utf8mb4 NULL,
`Number` varchar(255) CHARACTER SET utf8mb4 NULL,
CONSTRAINT `PK_iot_Area` PRIMARY KEY (`Id`),
CONSTRAINT `FK_iot_Area_iot_Area_ParentId` FOREIGN KEY (`ParentId`) REFERENCES `iot_Area` (`Id`) ON DELETE SET NULL
);
@ -56,7 +56,7 @@ CREATE TABLE `iot_NodeCategory` (
`Right` int NOT NULL,
`ParentId` char(36) NULL,
`Name` varchar(255) CHARACTER SET utf8mb4 NULL,
`Number` longtext CHARACTER SET utf8mb4 NULL,
`Number` varchar(255) CHARACTER SET utf8mb4 NULL,
`Template` longtext CHARACTER SET utf8mb4 NULL,
CONSTRAINT `PK_iot_NodeCategory` PRIMARY KEY (`Id`),
CONSTRAINT `FK_iot_NodeCategory_iot_NodeCategory_ParentId` FOREIGN KEY (`ParentId`) REFERENCES `iot_NodeCategory` (`Id`) ON DELETE RESTRICT
@ -126,7 +126,7 @@ CREATE TABLE `iot_Organ` (
`Right` int NOT NULL,
`ParentId` char(36) NULL,
`Name` longtext CHARACTER SET utf8mb4 NOT NULL,
`Number` longtext CHARACTER SET utf8mb4 NOT NULL,
`Number` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
`Image` longtext CHARACTER SET utf8mb4 NULL,
`Description` longtext CHARACTER SET utf8mb4 NULL,
`AreaId` char(36) NULL,
@ -410,6 +410,8 @@ CREATE TABLE `iot_SceneTigger` (
CREATE UNIQUE INDEX `IX_iot_Api_ProductId_Name` ON `iot_Api` (`ProductId`, `Name`);
CREATE UNIQUE INDEX `IX_iot_Area_Number` ON `iot_Area` (`Number`);
CREATE INDEX `IX_iot_Area_ParentId` ON `iot_Area` (`ParentId`);
CREATE UNIQUE INDEX `IX_iot_Category_Number` ON `iot_Category` (`Number`);
@ -424,10 +426,10 @@ CREATE INDEX `IX_iot_Data_DeviceId` ON `iot_Data` (`DeviceId`);
CREATE UNIQUE INDEX `IX_iot_Department_Number` ON `iot_Department` (`Number`);
CREATE INDEX `IX_iot_Department_OrganId` ON `iot_Department` (`OrganId`);
CREATE INDEX `IX_iot_Department_ParentId` ON `iot_Department` (`ParentId`);
CREATE UNIQUE INDEX `IX_iot_Department_OrganId_Number` ON `iot_Department` (`OrganId`, `Number`);
CREATE INDEX `IX_iot_DepartmentUser_DepartmentId` ON `iot_DepartmentUser` (`DepartmentId`);
CREATE INDEX `IX_iot_DepartmentUser_UserId` ON `iot_DepartmentUser` (`UserId`);
@ -442,12 +444,16 @@ CREATE UNIQUE INDEX `IX_iot_Node_Number` ON `iot_Node` (`Number`);
CREATE UNIQUE INDEX `IX_iot_NodeCategory_Name` ON `iot_NodeCategory` (`Name`);
CREATE UNIQUE INDEX `IX_iot_NodeCategory_Number` ON `iot_NodeCategory` (`Number`);
CREATE INDEX `IX_iot_NodeCategory_ParentId` ON `iot_NodeCategory` (`ParentId`);
CREATE INDEX `IX_iot_NodeCategoryNode_NodeId` ON `iot_NodeCategoryNode` (`NodeId`);
CREATE UNIQUE INDEX `IX_iot_NodeCategoryNode_CategoryId_NodeId` ON `iot_NodeCategoryNode` (`CategoryId`, `NodeId`);
CREATE UNIQUE INDEX `IX_iot_Organ_Number` ON `iot_Organ` (`Number`);
CREATE INDEX `IX_iot_Organ_ParentId` ON `iot_Organ` (`ParentId`);
CREATE INDEX `IX_iot_OrganNode_NodeId` ON `iot_OrganNode` (`NodeId`);

Loading…
Cancel
Save