From 80738bbf89d2e43d855aac1df07ae7142db7bba2 Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Thu, 31 Oct 2019 20:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=96=E8=BE=91=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E7=94=A8=E6=88=B7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../System/DepartmentEditModel.cs | 2 +- ShadowEditor.Model/System/DepartmentModel.cs | 7 +++- .../System/DepartmentController.cs | 35 +++++++++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/ShadowEditor.Model/System/DepartmentEditModel.cs b/ShadowEditor.Model/System/DepartmentEditModel.cs index 175dbf8b..fef9cfe0 100644 --- a/ShadowEditor.Model/System/DepartmentEditModel.cs +++ b/ShadowEditor.Model/System/DepartmentEditModel.cs @@ -29,6 +29,6 @@ namespace ShadowEditor.Model.System /// /// 管理员用户ID /// - public string AdministratorID { get; set; } + public string AdminID { get; set; } } } diff --git a/ShadowEditor.Model/System/DepartmentModel.cs b/ShadowEditor.Model/System/DepartmentModel.cs index 0815c5c1..be201dfa 100644 --- a/ShadowEditor.Model/System/DepartmentModel.cs +++ b/ShadowEditor.Model/System/DepartmentModel.cs @@ -29,7 +29,12 @@ namespace ShadowEditor.Model.System /// /// 管理员用户ID /// - public string AdministratorID { get; set; } + public string AdminID { get; set; } + + /// + /// 管理员名称(不存数据库) + /// + public string AdminName { get; set; } /// /// 状态(0-正常,-1-删除) diff --git a/ShadowEditor.Server/Controllers/System/DepartmentController.cs b/ShadowEditor.Server/Controllers/System/DepartmentController.cs index 6848d73a..b9b6318a 100644 --- a/ShadowEditor.Server/Controllers/System/DepartmentController.cs +++ b/ShadowEditor.Server/Controllers/System/DepartmentController.cs @@ -31,6 +31,23 @@ namespace ShadowEditor.Server.Controllers.System { var mongo = new MongoHelper(); + // 获取所有用户 + var userDocs = mongo.FindAll(Constant.UserCollectionName).ToList(); + + var users = new List(); + + foreach (var doc in userDocs) + { + users.Add(new UserModel + { + ID = doc["ID"].ToString(), + Username = doc["Username"].ToString(), + Password = "", + Name = doc["Name"].ToString(), + }); + } + + // 获取所有机构 var filter = Builders.Filter.Eq("Status", 0); var docs = mongo.FindMany(Constant.DepartmentCollectionName, filter).ToList(); @@ -39,12 +56,16 @@ namespace ShadowEditor.Server.Controllers.System foreach (var doc in docs) { + var adminID = doc.Contains("AdminID") ? doc["AdminID"].ToString() : ""; + var admin = users.Where(n => n.ID == adminID).FirstOrDefault(); + list.Add(new DepartmentModel { ID = doc["ID"].ToString(), ParentID = doc["ParentID"].ToString(), Name = doc["Name"].ToString(), - AdministratorID = doc["AdministratorID"].ToString() + AdminID = adminID, + AdminName = admin == null ? "" : admin.Name }); } @@ -78,9 +99,9 @@ namespace ShadowEditor.Server.Controllers.System model.ParentID = ""; } - if (model.AdministratorID == null) + if (model.AdminID == null) { - model.AdministratorID = ""; + model.AdminID = ""; } var mongo = new MongoHelper(); @@ -90,7 +111,7 @@ namespace ShadowEditor.Server.Controllers.System ["ID"] = ObjectId.GenerateNewId(), ["ParentID"] = model.ParentID, ["Name"] = model.Name, - ["AdministratorID"] = model.AdministratorID, + ["AdminID"] = model.AdminID, ["Status"] = 0 }; @@ -136,9 +157,9 @@ namespace ShadowEditor.Server.Controllers.System model.ParentID = ""; } - if (model.AdministratorID == null) + if (model.AdminID == null) { - model.AdministratorID = ""; + model.AdminID = ""; } var mongo = new MongoHelper(); @@ -147,7 +168,7 @@ namespace ShadowEditor.Server.Controllers.System var update1 = Builders.Update.Set("ParentID", model.ParentID); var update2 = Builders.Update.Set("Name", model.Name); - var update3 = Builders.Update.Set("AdministratorID", model.AdministratorID); + var update3 = Builders.Update.Set("AdminID", model.AdminID); var update = Builders.Update.Combine(update1, update2, update3);