From 8ebe8810d164c32bf193d1578be77954d0529e44 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Mon, 3 Aug 2020 17:08:06 +0800 Subject: [PATCH] 1.0.0.803d1 Former-commit-id: 48c052b7e1625c4d34ad0f37b8cd15359e86f3ad Former-commit-id: 211e3201b85656cba047eeccc1e6817295ec04c1 --- .../Application/Domain/Entities/Node.cs | 1 + .../Application/Domain/Entities}/NodeCategory.cs | 2 +- .../Domain/Entities}/NodeCategoryNode.cs | 5 ++--- .../Application/Domain/Entities}/Organ.cs | 2 +- .../Application/Domain/Entities}/OrganNode.cs | 5 ++--- .../Application/Domain/Entities}/OrganUser.cs | 7 +++---- .../Application/Domain/Entities/Users/User.cs | 1 + .../Application/Models/EditNodeModel.cs | 1 - .../Application/Models/EditSceneModel.cs | 9 +++++++-- .../Application/Models/SPCommandModel.cs | 1 + .../Application/Models/SearchDataHistoryModel.cs | 3 +-- .../Areas/Admin/Controlls/NodeController.cs | 2 +- projects/IoT.Shared/IoTSharedDbConfig.cs | 16 +++++++++++++++- projects/IoTCenter/Api/DeviceController.cs | 4 ++-- projects/IoTCenter/Api/NodeController.cs | 1 - projects/IoTCenter/Api/OrganController.cs | 1 - projects/IoTCenter/Api/ProductController.cs | 2 +- projects/IoTCenter/Api/ProjectController.cs | 1 - projects/IoTCenter/Api/SceneController.cs | 2 +- .../Controllers/GlobalSceneTimerController.cs | 1 - .../Admin/Controllers/NodeCategoryController.cs | 2 +- .../Areas/Admin/Controllers/OrganController.cs | 2 +- .../Areas/Admin/ViewModels/HomeIndexViewModel.cs | 3 +-- projects/IoTCenter/Controllers/HomeController.cs | 7 ------- projects/IoTCenter/DbConfig.cs | 12 ------------ .../IoTCenter/Services/IoTCenterEventHandler.cs | 1 - 26 files changed, 43 insertions(+), 51 deletions(-) rename projects/{IoTCenter/Application/Domain => IoT.Shared/Application/Domain/Entities}/NodeCategory.cs (93%) rename projects/{IoTCenter/Application/Domain => IoT.Shared/Application/Domain/Entities}/NodeCategoryNode.cs (75%) rename projects/{IoTCenter/Application/Domain => IoT.Shared/Application/Domain/Entities}/Organ.cs (93%) rename projects/{IoTCenter/Application/Domain => IoT.Shared/Application/Domain/Entities}/OrganNode.cs (74%) rename projects/{IoTCenter/Application/Domain => IoT.Shared/Application/Domain/Entities}/OrganUser.cs (74%) diff --git a/projects/IoT.Shared/Application/Domain/Entities/Node.cs b/projects/IoT.Shared/Application/Domain/Entities/Node.cs index 9b976834..540abd9c 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/Node.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Node.cs @@ -45,5 +45,6 @@ namespace Application.Domain.Entities public List Devices { get; set; } = new List(); public List Scenes { get; set; } = new List(); + public List OrganNodes { get; set; } = new List(); } } \ No newline at end of file diff --git a/projects/IoTCenter/Application/Domain/NodeCategory.cs b/projects/IoT.Shared/Application/Domain/Entities/NodeCategory.cs similarity index 93% rename from projects/IoTCenter/Application/Domain/NodeCategory.cs rename to projects/IoT.Shared/Application/Domain/Entities/NodeCategory.cs index 225bf857..5847d8b5 100644 --- a/projects/IoTCenter/Application/Domain/NodeCategory.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/NodeCategory.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -namespace IoTCenter.Application.Domain +namespace Application.Domain.Entities { [Display(Name = "节点类型")] public class NodeCategory : BaseEntity diff --git a/projects/IoTCenter/Application/Domain/NodeCategoryNode.cs b/projects/IoT.Shared/Application/Domain/Entities/NodeCategoryNode.cs similarity index 75% rename from projects/IoTCenter/Application/Domain/NodeCategoryNode.cs rename to projects/IoT.Shared/Application/Domain/Entities/NodeCategoryNode.cs index 09881190..9b6f899e 100644 --- a/projects/IoTCenter/Application/Domain/NodeCategoryNode.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/NodeCategoryNode.cs @@ -1,9 +1,8 @@ -using Application.Domain.Entities; -using Infrastructure.Domain; +using Infrastructure.Domain; using System; using System.ComponentModel.DataAnnotations; -namespace IoTCenter.Application.Domain +namespace Application.Domain.Entities { [Display(Name = "节点分类")] public class NodeCategoryNode : BaseEntity diff --git a/projects/IoTCenter/Application/Domain/Organ.cs b/projects/IoT.Shared/Application/Domain/Entities/Organ.cs similarity index 93% rename from projects/IoTCenter/Application/Domain/Organ.cs rename to projects/IoT.Shared/Application/Domain/Entities/Organ.cs index 55ce5f37..1f233cc5 100644 --- a/projects/IoTCenter/Application/Domain/Organ.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Organ.cs @@ -3,7 +3,7 @@ using Infrastructure.Web.Mvc; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -namespace IoTCenter.Application.Domain +namespace Application.Domain.Entities { [GeneratedController] [Display(Name = "机构")] diff --git a/projects/IoTCenter/Application/Domain/OrganNode.cs b/projects/IoT.Shared/Application/Domain/Entities/OrganNode.cs similarity index 74% rename from projects/IoTCenter/Application/Domain/OrganNode.cs rename to projects/IoT.Shared/Application/Domain/Entities/OrganNode.cs index f5f628c3..a18f5009 100644 --- a/projects/IoTCenter/Application/Domain/OrganNode.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/OrganNode.cs @@ -1,9 +1,8 @@ -using Application.Domain.Entities; -using Infrastructure.Domain; +using Infrastructure.Domain; using System; using System.ComponentModel.DataAnnotations; -namespace IoTCenter.Application.Domain +namespace Application.Domain.Entities { [Display(Name = "机构节点")] public class OrganNode : BaseEntity diff --git a/projects/IoTCenter/Application/Domain/OrganUser.cs b/projects/IoT.Shared/Application/Domain/Entities/OrganUser.cs similarity index 74% rename from projects/IoTCenter/Application/Domain/OrganUser.cs rename to projects/IoT.Shared/Application/Domain/Entities/OrganUser.cs index 42dc11af..41201962 100644 --- a/projects/IoTCenter/Application/Domain/OrganUser.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/OrganUser.cs @@ -1,9 +1,8 @@ -using Application.Domain.Entities; -using Infrastructure.Domain; +using Infrastructure.Domain; using System; using System.ComponentModel.DataAnnotations; -namespace IoTCenter.Application.Domain +namespace Application.Domain.Entities { [Display(Name = "机构用户")] public class OrganUser : BaseEntity @@ -13,4 +12,4 @@ namespace IoTCenter.Application.Domain public Organ Organ { get; set; } public User User { get; set; } } -} +} \ No newline at end of file diff --git a/projects/IoT.Shared/Application/Domain/Entities/Users/User.cs b/projects/IoT.Shared/Application/Domain/Entities/Users/User.cs index 64eb1b0b..efc079f8 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/Users/User.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Users/User.cs @@ -14,5 +14,6 @@ namespace Application.Domain.Entities public string PasswordHash { get; set; } public string Email { get; set; } public List UserRoles { get; set; } = new List(); + public List OrganUsers { get; set; } = new List(); } } \ No newline at end of file diff --git a/projects/IoT.Shared/Application/Models/EditNodeModel.cs b/projects/IoT.Shared/Application/Models/EditNodeModel.cs index 5094b734..d4e34112 100644 --- a/projects/IoT.Shared/Application/Models/EditNodeModel.cs +++ b/projects/IoT.Shared/Application/Models/EditNodeModel.cs @@ -1,5 +1,4 @@ using Infrastructure.Application; -using Microsoft.AspNetCore.Mvc; using System.ComponentModel; using System.ComponentModel.DataAnnotations; diff --git a/projects/IoT.Shared/Application/Models/EditSceneModel.cs b/projects/IoT.Shared/Application/Models/EditSceneModel.cs index b6ecfe69..31ab0d7a 100644 --- a/projects/IoT.Shared/Application/Models/EditSceneModel.cs +++ b/projects/IoT.Shared/Application/Models/EditSceneModel.cs @@ -8,11 +8,16 @@ namespace Application.Models public class EditSceneModel : EditModel { [DataType("SelectList")] - [Display(Name = "场景节点")] + [Display(Name = "机构")] + [Required(ErrorMessage = nameof(RequiredAttribute))] + public Guid? OrganId { get; set; } + + [DataType("SelectList")] + [Display(Name = "节点")] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? NodeId { get; set; } - [Display(Name = "场景名称")] + [Display(Name = "名称")] [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] [Required(ErrorMessage = nameof(RequiredAttribute))] public string Name { get; set; } diff --git a/projects/IoT.Shared/Application/Models/SPCommandModel.cs b/projects/IoT.Shared/Application/Models/SPCommandModel.cs index 83dd5fd8..e496b4d0 100644 --- a/projects/IoT.Shared/Application/Models/SPCommandModel.cs +++ b/projects/IoT.Shared/Application/Models/SPCommandModel.cs @@ -22,6 +22,7 @@ /// hex /// public string Message { get; set; } + public int Order { get; set; } } } \ No newline at end of file diff --git a/projects/IoT.Shared/Application/Models/SearchDataHistoryModel.cs b/projects/IoT.Shared/Application/Models/SearchDataHistoryModel.cs index 009e7ce0..6b00871d 100644 --- a/projects/IoT.Shared/Application/Models/SearchDataHistoryModel.cs +++ b/projects/IoT.Shared/Application/Models/SearchDataHistoryModel.cs @@ -1,5 +1,4 @@ -using Application.Domain.Entities; -using Infrastructure.Application; +using Infrastructure.Application; using System; using System.ComponentModel.DataAnnotations; diff --git a/projects/IoT.Shared/Areas/Admin/Controlls/NodeController.cs b/projects/IoT.Shared/Areas/Admin/Controlls/NodeController.cs index 9d382658..09b05293 100644 --- a/projects/IoT.Shared/Areas/Admin/Controlls/NodeController.cs +++ b/projects/IoT.Shared/Areas/Admin/Controlls/NodeController.cs @@ -48,7 +48,7 @@ namespace IoT.Shared.Areas.Admin.Controlls { try { - this.Repo.Delete(this.Repo.Table().Include(o => o.Scenes).FirstOrDefault(o => o.Id == id)); + this.Repo.Delete(this.Repo.Table().FirstOrDefault(o => o.Id == id)); this.Repo.SaveChanges(); } catch (Exception ex) diff --git a/projects/IoT.Shared/IoTSharedDbConfig.cs b/projects/IoT.Shared/IoTSharedDbConfig.cs index 7d53a1fe..dcb92b7c 100644 --- a/projects/IoT.Shared/IoTSharedDbConfig.cs +++ b/projects/IoT.Shared/IoTSharedDbConfig.cs @@ -42,12 +42,26 @@ namespace IoT.Shared modelBuilder.Entity().HasOne(o => o.Device).WithMany(o => o.Data).HasForeignKey(o => o.DeviceId); // modelBuilder.Entity().HasOne(o => o.Api).WithMany(o => o.Commands).HasForeignKey(o => o.ApiId); - modelBuilder.Entity().HasOne(o => o.Node).WithMany(o => o.Scenes).HasForeignKey(o => o.NodeId); + modelBuilder.Entity().HasOne(o => o.Node).WithMany(o => o.Scenes).HasForeignKey(o => o.NodeId).OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity().HasOne(o => o.Scene).WithMany(o => o.SceneCommands).HasForeignKey(o => o.SceneId); modelBuilder.Entity().HasOne(o => o.Command).WithMany(o => o.SceneCommands).HasForeignKey(o => o.CommandId); modelBuilder.Entity().HasOne(o => o.Scene).WithMany(o => o.SceneTimers).HasForeignKey(o => o.SceneId); modelBuilder.Entity().HasOne(o => o.Scene).WithMany(o => o.SceneTiggers).HasForeignKey(o => o.SceneId); modelBuilder.Entity().HasOne(o => o.Data).WithMany(o => o.Tiggers).HasForeignKey(o => o.DataId); + // + modelBuilder.Entity().HasIndex(o => o.Name).IsUnique(); + modelBuilder.Entity().HasOne(o => o.Node).WithMany().HasForeignKey(o => o.NodeId); + modelBuilder.Entity().HasOne(o => o.Category).WithMany(o => o.CategoryNodes).HasForeignKey(o => o.CategoryId); + modelBuilder.Entity().HasIndex(o => new { o.CategoryId, o.NodeId }).IsUnique(); + modelBuilder.Entity().Property(o => o.Number).IsRequired(); + modelBuilder.Entity().HasIndex(o => o.Number).IsUnique(); + modelBuilder.Entity().HasOne(o => o.Organ).WithMany(o => o.OrganUsers).HasForeignKey(o => o.OrganId); + modelBuilder.Entity().HasOne(o => o.User).WithMany(o => o.OrganUsers).HasForeignKey(o => o.UserId); + modelBuilder.Entity().HasIndex(o => new { o.OrganId, o.UserId }).IsUnique(); + modelBuilder.Entity().HasOne(o => o.Organ).WithMany(o => o.OrganNodes).HasForeignKey(o => o.OrganId); + modelBuilder.Entity().HasOne(o => o.Organ).WithMany(o => o.OrganNodes).HasForeignKey(o => o.OrganId); + modelBuilder.Entity().HasOne(o => o.Node).WithMany(o => o.OrganNodes).HasForeignKey(o => o.NodeId); + modelBuilder.Entity().HasIndex(o => new { o.OrganId, o.NodeId }).IsUnique(); } public static void Seed(DbContext db) diff --git a/projects/IoTCenter/Api/DeviceController.cs b/projects/IoTCenter/Api/DeviceController.cs index f951e0f9..157e15f6 100644 --- a/projects/IoTCenter/Api/DeviceController.cs +++ b/projects/IoTCenter/Api/DeviceController.cs @@ -32,7 +32,7 @@ namespace IoTCenter.Api.Controllers } [HttpPost] - public ActionResult GetDevice([Required(ErrorMessage = nameof(RequiredAttribute))]string number) + public ActionResult GetDevice([Required(ErrorMessage = nameof(RequiredAttribute))] string number) { try { @@ -54,7 +54,7 @@ namespace IoTCenter.Api.Controllers } [HttpPost] - public IActionResult GetChartData([FromBody]ChartDataRequest model) + public IActionResult GetChartData([FromBody] ChartDataRequest model) { try { diff --git a/projects/IoTCenter/Api/NodeController.cs b/projects/IoTCenter/Api/NodeController.cs index 4ac2c896..4a4ec196 100644 --- a/projects/IoTCenter/Api/NodeController.cs +++ b/projects/IoTCenter/Api/NodeController.cs @@ -3,7 +3,6 @@ using Application.Models; using Infrastructure.Application.Services.Settings; using Infrastructure.Data; using Infrastructure.Extensions; -using IoTCenter.Application.Domain; using IoTCenter.Services; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; diff --git a/projects/IoTCenter/Api/OrganController.cs b/projects/IoTCenter/Api/OrganController.cs index a8c7583c..02a6e4e7 100644 --- a/projects/IoTCenter/Api/OrganController.cs +++ b/projects/IoTCenter/Api/OrganController.cs @@ -2,7 +2,6 @@ using Infrastructure.Application.Services.Settings; using Infrastructure.Data; using Infrastructure.Extensions; -using IoTCenter.Application.Domain; using IoTCenter.Services; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; diff --git a/projects/IoTCenter/Api/ProductController.cs b/projects/IoTCenter/Api/ProductController.cs index 05385758..de05f876 100644 --- a/projects/IoTCenter/Api/ProductController.cs +++ b/projects/IoTCenter/Api/ProductController.cs @@ -52,7 +52,7 @@ namespace IoTCenter.Api.Controllers } [HttpPost] - public ActionResult GetProduct([Required(ErrorMessage = nameof(RequiredAttribute))]string number) + public ActionResult GetProduct([Required(ErrorMessage = nameof(RequiredAttribute))] string number) { try { diff --git a/projects/IoTCenter/Api/ProjectController.cs b/projects/IoTCenter/Api/ProjectController.cs index de21bfe0..feabe755 100644 --- a/projects/IoTCenter/Api/ProjectController.cs +++ b/projects/IoTCenter/Api/ProjectController.cs @@ -1,7 +1,6 @@ using Application.Domain.Entities; using Infrastructure.Data; using Infrastructure.Extensions; -using IoTCenter.Application.Domain; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; diff --git a/projects/IoTCenter/Api/SceneController.cs b/projects/IoTCenter/Api/SceneController.cs index d2cc451c..4efc48e4 100644 --- a/projects/IoTCenter/Api/SceneController.cs +++ b/projects/IoTCenter/Api/SceneController.cs @@ -39,7 +39,7 @@ namespace IoTCenter.Api.Controllers } [HttpPost] - public ActionResult GetScene([Required(ErrorMessage = nameof(RequiredAttribute))]Guid id) + public ActionResult GetScene([Required(ErrorMessage = nameof(RequiredAttribute))] Guid id) { try { diff --git a/projects/IoTCenter/Areas/Admin/Controllers/GlobalSceneTimerController.cs b/projects/IoTCenter/Areas/Admin/Controllers/GlobalSceneTimerController.cs index a95dda26..252ea11f 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/GlobalSceneTimerController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/GlobalSceneTimerController.cs @@ -1,7 +1,6 @@ using Application.Domain.Entities; using Infrastructure.Application; using Infrastructure.Data; -using Infrastructure.Events; using Infrastructure.Extensions; using Infrastructure.Web.Mvc; using IoT.Shared.Areas.Admin.Controlls; diff --git a/projects/IoTCenter/Areas/Admin/Controllers/NodeCategoryController.cs b/projects/IoTCenter/Areas/Admin/Controllers/NodeCategoryController.cs index 4caebf96..f0803dc5 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/NodeCategoryController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/NodeCategoryController.cs @@ -1,4 +1,4 @@ -using IoTCenter.Application.Domain; +using Application.Domain.Entities; using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Extensions; diff --git a/projects/IoTCenter/Areas/Admin/Controllers/OrganController.cs b/projects/IoTCenter/Areas/Admin/Controllers/OrganController.cs index c1b13f38..2bebdf52 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/OrganController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/OrganController.cs @@ -1,9 +1,9 @@ +using Application.Domain.Entities; using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web.Mvc; using IoT.Shared.Areas.Admin.Controlls; -using IoTCenter.Application.Domain; using IoTCenter.Application.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/projects/IoTCenter/Areas/Admin/ViewModels/HomeIndexViewModel.cs b/projects/IoTCenter/Areas/Admin/ViewModels/HomeIndexViewModel.cs index 56f0fe3f..57d7899a 100644 --- a/projects/IoTCenter/Areas/Admin/ViewModels/HomeIndexViewModel.cs +++ b/projects/IoTCenter/Areas/Admin/ViewModels/HomeIndexViewModel.cs @@ -1,5 +1,4 @@ -using Application.Domain.Entities; -using System.Collections.Generic; +using System.Collections.Generic; namespace IoTCenter.Areas.Admin.ViewModels { diff --git a/projects/IoTCenter/Controllers/HomeController.cs b/projects/IoTCenter/Controllers/HomeController.cs index 8168f7bc..9ed7174a 100644 --- a/projects/IoTCenter/Controllers/HomeController.cs +++ b/projects/IoTCenter/Controllers/HomeController.cs @@ -1,16 +1,9 @@ using Application.Domain.Entities; using Infrastructure.Data; -using Infrastructure.Extensions; -using IoTCenter.Application.Domain; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using System; -using System.Collections.Generic; -using System.Linq; -using Vibrant.InfluxDB.Client; -using Vibrant.InfluxDB.Client.Rows; namespace IoTCenter.Controllers { diff --git a/projects/IoTCenter/DbConfig.cs b/projects/IoTCenter/DbConfig.cs index 1030949e..79d566a8 100644 --- a/projects/IoTCenter/DbConfig.cs +++ b/projects/IoTCenter/DbConfig.cs @@ -28,18 +28,6 @@ namespace IoTCenter { IoTSharedDbConfig.OnModelCreating(modelBuilder); modelBuilder.Entity().Property(o => o.DeviceNumber).IsRequired(); - modelBuilder.Entity().HasIndex(o => o.Name).IsUnique(); - modelBuilder.Entity().HasOne(o => o.Node).WithMany().HasForeignKey(o => o.NodeId); - modelBuilder.Entity().HasOne(o => o.Category).WithMany(o => o.CategoryNodes).HasForeignKey(o => o.CategoryId); - modelBuilder.Entity().HasIndex(o => new { o.CategoryId, o.NodeId }).IsUnique(); - modelBuilder.Entity().Property(o => o.Number).IsRequired(); - modelBuilder.Entity().HasIndex(o => o.Number).IsUnique(); - modelBuilder.Entity().HasOne(o => o.Organ).WithMany(o => o.OrganUsers).HasForeignKey(o => o.OrganId); - modelBuilder.Entity().HasOne(o => o.User).WithMany().HasForeignKey(o => o.UserId); - modelBuilder.Entity().HasIndex(o => new { o.OrganId, o.UserId }).IsUnique(); - modelBuilder.Entity().HasOne(o => o.Organ).WithMany(o => o.OrganNodes).HasForeignKey(o => o.OrganId); - modelBuilder.Entity().HasOne(o => o.Node).WithMany().HasForeignKey(o => o.NodeId); - modelBuilder.Entity().HasIndex(o => new { o.OrganId, o.NodeId }).IsUnique(); } public void Seed(DbContext db) diff --git a/projects/IoTCenter/Services/IoTCenterEventHandler.cs b/projects/IoTCenter/Services/IoTCenterEventHandler.cs index 6bcef16e..e4caf898 100644 --- a/projects/IoTCenter/Services/IoTCenterEventHandler.cs +++ b/projects/IoTCenter/Services/IoTCenterEventHandler.cs @@ -5,7 +5,6 @@ using Infrastructure.Data; using Infrastructure.Events; using Infrastructure.Extensions; using IoT.Shared.Services.IoTCenter; -using IoTCenter.Application.Domain; using Jint; using Jint.Native; using Microsoft.AspNetCore.SignalR;