diff --git a/projects/IoT.Shared/Application/Models/EditCommandModel.cs b/projects/IoT.Shared/Application/Models/EditCommandModel.cs index b55d264e..1067c876 100644 --- a/projects/IoT.Shared/Application/Models/EditCommandModel.cs +++ b/projects/IoT.Shared/Application/Models/EditCommandModel.cs @@ -26,6 +26,7 @@ namespace Application.Models public Guid? ApiId { get; set; } [Display(Name = "命令名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] [Required(ErrorMessage = nameof(RequiredAttribute))] public string Name { get; set; } diff --git a/projects/IoT.Shared/Application/Models/EditDeviceModel.cs b/projects/IoT.Shared/Application/Models/EditDeviceModel.cs index 178c2387..04fd8709 100644 --- a/projects/IoT.Shared/Application/Models/EditDeviceModel.cs +++ b/projects/IoT.Shared/Application/Models/EditDeviceModel.cs @@ -24,6 +24,7 @@ namespace Application.Models public string Name { get; set; } [Display(Name = "显示名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] [Required] public string DisplayName { get; set; } diff --git a/projects/IoT.Shared/Application/Models/EditSceneModel.cs b/projects/IoT.Shared/Application/Models/EditSceneModel.cs index 848cb164..9f80e347 100644 --- a/projects/IoT.Shared/Application/Models/EditSceneModel.cs +++ b/projects/IoT.Shared/Application/Models/EditSceneModel.cs @@ -9,11 +9,11 @@ namespace Application.Models { [DataType("SelectList")] [Display(Name = "场景节点")] - [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? NodeId { get; set; } [Display(Name = "场景名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] [Required(ErrorMessage = nameof(RequiredAttribute))] public string Name { get; set; } diff --git a/projects/IoT.Shared/Application/Models/EditSceneTiggerModel.cs b/projects/IoT.Shared/Application/Models/EditSceneTiggerModel.cs index ae93fa8f..067a3c5f 100644 --- a/projects/IoT.Shared/Application/Models/EditSceneTiggerModel.cs +++ b/projects/IoT.Shared/Application/Models/EditSceneTiggerModel.cs @@ -36,6 +36,7 @@ namespace Application.Models public string Condition { get; set; } [Display(Name = "触发器名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] public string Name { get; set; } [Display(Name = "禁用")] diff --git a/projects/IoT.Shared/Application/Models/EditSceneTimerModel.cs b/projects/IoT.Shared/Application/Models/EditSceneTimerModel.cs index 52d91c5a..e1769fdc 100644 --- a/projects/IoT.Shared/Application/Models/EditSceneTimerModel.cs +++ b/projects/IoT.Shared/Application/Models/EditSceneTimerModel.cs @@ -19,6 +19,7 @@ namespace Application.Models public Guid SceneId { get; set; } [Display(Name = "定时器名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] public string Name { get; set; } [Display(Name = "定时器规则")] diff --git a/projects/IoT.Shared/Areas/Admin/Controlls/Users/PermissionController.cs b/projects/IoT.Shared/Areas/Admin/Controlls/Users/PermissionController.cs index ca86ca26..b1fe8759 100644 --- a/projects/IoT.Shared/Areas/Admin/Controlls/Users/PermissionController.cs +++ b/projects/IoT.Shared/Areas/Admin/Controlls/Users/PermissionController.cs @@ -30,6 +30,11 @@ namespace IoT.Shared.Areas.Admin.Controllers return query.Include(o => o.Category).ThenInclude(o => o.Parent); } + public override IQueryable Query(PagedListModel model, IQueryable query) + { + return query.OrderBy(o => o.CategoryId).ThenBy(o => o.Name); + } + public override void ToEditModel(Permission entity, EditPermissionModel model) { this.ViewData.SelectList(o => model.CategoryId, () => this.GetPermissionCategorySelectList(model.CategoryId), model.CategoryId.HasValue); @@ -58,6 +63,7 @@ namespace IoT.Shared.Areas.Admin.Controllers } var list = this.Repo.ReadOnlyTable() .Include(o => o.Category) + .OrderBy(o => o.CategoryId).ThenBy(o => o.Name) .Select(o => new { o.Id, o.Name, Group = o.Category.Name }) .ToList(); return new MultiSelectList(list, "Id", "Name", selectedValues, "Group"); diff --git a/projects/IoTCenter/Application/Models/EditGlobalSceneTiggerModel.cs b/projects/IoTCenter/Application/Models/EditGlobalSceneTiggerModel.cs index a60d74f4..2fca782b 100644 --- a/projects/IoTCenter/Application/Models/EditGlobalSceneTiggerModel.cs +++ b/projects/IoTCenter/Application/Models/EditGlobalSceneTiggerModel.cs @@ -15,6 +15,7 @@ namespace IoTCenter.Application.Models public Guid SceneId { get; set; } [Display(Name = "触发器名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] public string Name { get; set; } [DataType("SelectList")] diff --git a/projects/IoTCenter/Application/Models/EditGlobalSceneTimerModel.cs b/projects/IoTCenter/Application/Models/EditGlobalSceneTimerModel.cs index 089db1cf..2ae62ea3 100644 --- a/projects/IoTCenter/Application/Models/EditGlobalSceneTimerModel.cs +++ b/projects/IoTCenter/Application/Models/EditGlobalSceneTimerModel.cs @@ -14,6 +14,7 @@ namespace IoTCenter.Application.Models public Guid SceneId { get; set; } [Display(Name = "平台定时器名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] public string Name { get; set; } [Display(Name = "定时器规则")] diff --git a/projects/IoTCenter/Application/Models/EditNodeCategoryModel.cs b/projects/IoTCenter/Application/Models/EditNodeCategoryModel.cs index db6457c7..9bde2021 100644 --- a/projects/IoTCenter/Application/Models/EditNodeCategoryModel.cs +++ b/projects/IoTCenter/Application/Models/EditNodeCategoryModel.cs @@ -9,6 +9,7 @@ namespace IoTCenter.Application.Models public class EditNodeCategoryModel : EditModel { [Display(Name = "分类名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] [Required(ErrorMessage = nameof(RequiredAttribute))] public string Name { get; set; } diff --git a/projects/IoTCenter/Application/Models/EditOrganModel.cs b/projects/IoTCenter/Application/Models/EditOrganModel.cs index 21d4b93c..fd26e62a 100644 --- a/projects/IoTCenter/Application/Models/EditOrganModel.cs +++ b/projects/IoTCenter/Application/Models/EditOrganModel.cs @@ -9,6 +9,7 @@ namespace IoTCenter.Application.Models public class EditOrganModel : EditModel { [Display(Name = "机构名称")] + [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] [Required(ErrorMessage = nameof(RequiredAttribute))] public string Name { get; set; } diff --git a/projects/IoTCenter/DbConfig.cs b/projects/IoTCenter/DbConfig.cs index 66f5b150..168fae50 100644 --- a/projects/IoTCenter/DbConfig.cs +++ b/projects/IoTCenter/DbConfig.cs @@ -7,6 +7,7 @@ using IoT.Shared; using IoTCenter.Application.Domain; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; +using System.Linq; namespace IoTCenter { @@ -44,12 +45,12 @@ namespace IoTCenter var saRole = new Role { Name = "超级管理员", IsReadOnly = true }; var adminRole = new Role { Name = "管理员", IsReadOnly = true }; - //var skips = new string[] { "添加节点", "删除节点", "添加设备", "删除设备" }; + var skips = new string[] { "添加Api", "修改Api", "添加分类", "修改分类", "添加参数", "修改参数", "添加产品", "修改产品", "添加节点", "添加权限", "修改权限", "添加权限分类", "修改权限分类", "添加设备" }; foreach (var item in db.Set()) { saRole.RolePermissions.Add(new RolePermission { Permission = item, IsReadOnly = true }); - if (!item.Name.Contains("删除"))// && !skips.Contains(item.Name)) + if (!item.Name.Contains("删除") && !skips.Contains(item.Name)) { adminRole.RolePermissions.Add(new RolePermission { Permission = item, IsReadOnly = true }); } diff --git a/projects/IoTNode/DbConfig.cs b/projects/IoTNode/DbConfig.cs index 99701cc3..d4d999f5 100644 --- a/projects/IoTNode/DbConfig.cs +++ b/projects/IoTNode/DbConfig.cs @@ -6,6 +6,7 @@ using Infrastructure.Security; using IoT.Shared; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; +using System.Linq; namespace IoTNode { @@ -33,12 +34,12 @@ namespace IoTNode var saRole = new Role { Name = "超级管理员", IsReadOnly = true }; var adminRole = new Role { Name = "管理员", IsReadOnly = true }; - //var skips = new string[] { "添加节点", "删除节点", "添加设备", "删除设备" }; + var skips = new string[] { "添加Api", "修改Api", "添加分类", "修改分类", "添加参数", "修改参数", "添加产品", "修改产品", "添加节点", "添加权限", "修改权限", "添加权限分类", "修改权限分类", "添加设备" }; foreach (var item in db.Set()) { saRole.RolePermissions.Add(new RolePermission { Permission = item, IsReadOnly = true }); - if (!item.Name.Contains("删除"))// && !skips.Contains(item.Name)) + if (!item.Name.Contains("删除") && !skips.Contains(item.Name)) { adminRole.RolePermissions.Add(new RolePermission { Permission = item, IsReadOnly = true }); } diff --git a/projects/StudyCenter/Areas/Admin/Controllers/PermissionController.cs b/projects/StudyCenter/Areas/Admin/Controllers/PermissionController.cs index 5081db20..180f40ce 100644 --- a/projects/StudyCenter/Areas/Admin/Controllers/PermissionController.cs +++ b/projects/StudyCenter/Areas/Admin/Controllers/PermissionController.cs @@ -47,6 +47,7 @@ namespace IoTCenter.Areas.Admin.Controllers } var list = this._permissionRepo.Table() .Include(o => o.Category) + .OrderBy(o => o.CategoryId).ThenBy(o => o.Name) .Select(o => new { o.Id, o.Name, Group = o.Category.Name }) .ToList(); return new MultiSelectList(list, "Id", "Name", selectedValues, "Group"); diff --git a/projects/UserCenter/Application/Domain/Entities/Organ.cs b/projects/UserCenter/Application/Domain/Entities/Organ.cs new file mode 100644 index 00000000..19a52760 --- /dev/null +++ b/projects/UserCenter/Application/Domain/Entities/Organ.cs @@ -0,0 +1,13 @@ +using Infrastructure.Domain; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace Application.Domain.Entities +{ + [Display(Name = "机构")] + public class Organ : BaseTreeEntity + { + public string Contact { get; set; } + public List OrganUsers { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/projects/UserCenter/Application/Domain/Entities/OrganUser.cs b/projects/UserCenter/Application/Domain/Entities/OrganUser.cs new file mode 100644 index 00000000..b132f57d --- /dev/null +++ b/projects/UserCenter/Application/Domain/Entities/OrganUser.cs @@ -0,0 +1,15 @@ +using Infrastructure.Domain; +using System; +using System.ComponentModel.DataAnnotations; + +namespace Application.Domain.Entities +{ + [Display(Name = "机构用户")] + public class OrganUser : BaseEntity + { + public Guid UserId { get; set; } + public Guid OrganId { get; set; } + public User User { get; set; } + public Organ Organ { get; set; } + } +} \ No newline at end of file diff --git a/projects/UserCenter/Application/Domain/Entities/User.cs b/projects/UserCenter/Application/Domain/Entities/User.cs index 9607ab64..9d98b43f 100644 --- a/projects/UserCenter/Application/Domain/Entities/User.cs +++ b/projects/UserCenter/Application/Domain/Entities/User.cs @@ -81,6 +81,7 @@ namespace Application.Domain.Entities public string RowVersion { get; set; } public List UserRoles { get; set; } = new List(); + public List OrganUsers { get; set; } = new List(); public List UserDepartments { get; set; } = new List(); } } \ No newline at end of file diff --git a/projects/UserCenter/Application/Models/EditUserModel.cs b/projects/UserCenter/Application/Models/EditUserModel.cs index 1722b097..6db8bbb9 100644 --- a/projects/UserCenter/Application/Models/EditUserModel.cs +++ b/projects/UserCenter/Application/Models/EditUserModel.cs @@ -42,6 +42,14 @@ namespace Application.Models [DataType(DataType.ImageUrl)] public string Avatar { get; set; } + [Display(Name = "真实姓名")] + [RegularExpression("[\u4E00-\u9FA5]{2,4}", ErrorMessage = "姓名格式错误")] + public string RealName { get; set; } + + [Display(Name = "身份证号")] + [RegularExpression(@"^(\d{15}|\d{17}(x|X|\d))$", ErrorMessage = "身份证号格式错。")] + public string IdCardNumber { get; set; } + [Display(Name = "性别")] [UIHint("RadioButtonList")] [Required(ErrorMessage = nameof(RequiredAttribute))] diff --git a/projects/UserCenter/Areas/Admin/Controllers/AjaxController.cs b/projects/UserCenter/Areas/Admin/Controllers/AjaxController.cs index 4bf40a4a..d820b5b6 100644 --- a/projects/UserCenter/Areas/Admin/Controllers/AjaxController.cs +++ b/projects/UserCenter/Areas/Admin/Controllers/AjaxController.cs @@ -55,6 +55,7 @@ namespace UserCenter.Areas.Admin.Controllers } var list = this._permissionRepo.Table() .Include(o => o.Category) + .OrderBy(o => o.CategoryId).ThenBy(o => o.Name) .Select(o => new { o.Id, o.Name, Group = o.Category.Name }) .ToList(); return new MultiSelectList(list, "Id", "Name", selectedValues, "Group"); @@ -63,6 +64,7 @@ namespace UserCenter.Areas.Admin.Controllers #endregion Permission #region PermissionCategory + public SelectList GetPermissionCategorySelectList(Guid? selected) { var list = this._permissionCategoryRepo.ReadOnlyTable() @@ -70,6 +72,7 @@ namespace UserCenter.Areas.Admin.Controllers .ToList(); return new SelectList(list, "Id", "Name", selected); } - #endregion + + #endregion PermissionCategory } } \ No newline at end of file diff --git a/projects/UserCenter/Areas/Admin/Controllers/PermissionController.cs b/projects/UserCenter/Areas/Admin/Controllers/PermissionController.cs index 7d6b1471..63517305 100644 --- a/projects/UserCenter/Areas/Admin/Controllers/PermissionController.cs +++ b/projects/UserCenter/Areas/Admin/Controllers/PermissionController.cs @@ -27,6 +27,11 @@ namespace UserCenter.Areas.Admin.Controllers return query.Include(o => o.Category).ThenInclude(o => o.Parent); } + public override IQueryable Query(PagedListModel model, IQueryable query) + { + return query.OrderBy(o => o.CategoryId).ThenBy(o => o.Name); + } + public override void ToEditModel(Permission entity, EditPermissionModel model) { this.ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetPermissionCategorySelectList(model.CategoryId), model.CategoryId.HasValue); diff --git a/projects/UserCenter/Areas/Admin/Controllers/UserController.cs b/projects/UserCenter/Areas/Admin/Controllers/UserController.cs index aa2c02e4..20e65796 100644 --- a/projects/UserCenter/Areas/Admin/Controllers/UserController.cs +++ b/projects/UserCenter/Areas/Admin/Controllers/UserController.cs @@ -96,6 +96,10 @@ namespace UserCenter.Areas.Admin.Controllers { ModelState.AddModelError(o => model.UserName, "Ѿ"); } + if (this.Repo.ReadOnlyTable().Any(o => o.NickName == model.NickName)) + { + ModelState.AddModelError(o => model.UserName, "dzѾ"); + } return base.Add(model); } diff --git a/projects/UserCenter/DbConfig.cs b/projects/UserCenter/DbConfig.cs index 3692c344..21978332 100644 --- a/projects/UserCenter/DbConfig.cs +++ b/projects/UserCenter/DbConfig.cs @@ -46,6 +46,11 @@ namespace UserCenter modelBuilder.Entity().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId); modelBuilder.Entity().Property(o => o.Number).IsRequired(); modelBuilder.Entity().HasIndex(o => o.Number).IsUnique(); + modelBuilder.Entity().Property(o => o.Number).IsRequired(); + modelBuilder.Entity().HasIndex(o => o.Number).IsUnique(); + modelBuilder.Entity().HasOne(o => o.User).WithMany(o => o.OrganUsers).HasForeignKey(o => o.UserId); + modelBuilder.Entity().HasOne(o => o.Organ).WithMany(o => o.OrganUsers).HasForeignKey(o => o.OrganId); + modelBuilder.Entity().HasIndex(o => new { o.UserId, o.OrganId }).IsUnique(); modelBuilder.Entity().HasOne(o => o.User).WithMany(o => o.UserDepartments).HasForeignKey(o => o.UserId); modelBuilder.Entity().HasOne(o => o.Department).WithMany(o => o.UserDepartments).HasForeignKey(o => o.DepartmentId); modelBuilder.Entity().HasIndex(o => new { o.UserId, o.DepartmentId }).IsUnique(); @@ -100,10 +105,12 @@ namespace UserCenter var saRole = new Role { Name = "超级管理员", IsReadOnly = true }; var adminRole = new Role { Name = "管理员", IsReadOnly = true }; + var skips = new string[] { "添加权限", "修改权限", "添加权限分类", "修改权限分类" }; + foreach (var item in dbContext.Set()) { saRole.RolePermissions.Add(new RolePermission { Permission = item, IsReadOnly = true }); - if (!item.Name.Contains("删除")) + if (!item.Name.Contains("删除") && !skips.Contains(item.Name)) { adminRole.RolePermissions.Add(new RolePermission { Permission = item, IsReadOnly = true }); } diff --git a/projects/UserCenter/db.sql b/projects/UserCenter/db.sql index 5ca16cd9..824779d4 100644 --- a/projects/UserCenter/db.sql +++ b/projects/UserCenter/db.sql @@ -8,6 +8,17 @@ CREATE TABLE "uc_Department" ( CONSTRAINT "FK_uc_Department_uc_Department_ParentId" FOREIGN KEY ("ParentId") REFERENCES "uc_Department" ("Id") ON DELETE RESTRICT ); +CREATE TABLE "uc_Organ" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_uc_Organ" PRIMARY KEY, + "IsDeleted" TEXT NULL, + "Name" TEXT NULL, + "Number" TEXT NOT NULL, + "Path" TEXT NULL, + "ParentId" TEXT NULL, + "Contact" TEXT NULL, + CONSTRAINT "FK_uc_Organ_uc_Organ_ParentId" FOREIGN KEY ("ParentId") REFERENCES "uc_Organ" ("Id") ON DELETE RESTRICT +); + CREATE TABLE "uc_PermissionCategory" ( "Id" TEXT NOT NULL CONSTRAINT "PK_uc_PermissionCategory" PRIMARY KEY, "IsDeleted" TEXT NULL, @@ -84,6 +95,15 @@ CREATE TABLE "uc_Permission" ( CONSTRAINT "FK_uc_Permission_uc_PermissionCategory_CategoryId" FOREIGN KEY ("CategoryId") REFERENCES "uc_PermissionCategory" ("Id") ON DELETE SET NULL ); +CREATE TABLE "uc_OrganUser" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_uc_OrganUser" PRIMARY KEY, + "IsDeleted" TEXT NULL, + "UserId" TEXT NOT NULL, + "OrganId" TEXT NOT NULL, + CONSTRAINT "FK_uc_OrganUser_uc_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "uc_Organ" ("Id") ON DELETE CASCADE, + CONSTRAINT "FK_uc_OrganUser_uc_User_UserId" FOREIGN KEY ("UserId") REFERENCES "uc_User" ("Id") ON DELETE CASCADE +); + CREATE TABLE "uc_UserDepartment" ( "Id" TEXT NOT NULL CONSTRAINT "PK_uc_UserDepartment" PRIMARY KEY, "IsDeleted" TEXT NULL, @@ -116,6 +136,14 @@ CREATE UNIQUE INDEX "IX_uc_Department_Number" ON "uc_Department" ("Number"); CREATE INDEX "IX_uc_Department_ParentId" ON "uc_Department" ("ParentId"); +CREATE UNIQUE INDEX "IX_uc_Organ_Number" ON "uc_Organ" ("Number"); + +CREATE INDEX "IX_uc_Organ_ParentId" ON "uc_Organ" ("ParentId"); + +CREATE INDEX "IX_uc_OrganUser_OrganId" ON "uc_OrganUser" ("OrganId"); + +CREATE UNIQUE INDEX "IX_uc_OrganUser_UserId_OrganId" ON "uc_OrganUser" ("UserId", "OrganId"); + CREATE INDEX "IX_uc_Permission_CategoryId" ON "uc_Permission" ("CategoryId"); CREATE UNIQUE INDEX "IX_uc_Permission_Number" ON "uc_Permission" ("Number"); diff --git a/projects/Version.cs b/projects/Version.cs index 7b82791b..f1dba7d9 100644 --- a/projects/Version.cs +++ b/projects/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.*")] -[assembly: AssemblyInformationalVersion("1.0.0.513")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.514")] \ No newline at end of file