From 728b4a3bd0ff0a0241986b76ccf1d06807195c20 Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Thu, 23 Jul 2020 20:32:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E9=97=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.API/COMCMS.API.csproj | 2 +- COMCMS.Common/COMCMS.Common.csproj | 2 +- COMCMS.Core/COMCMS.Core.csproj | 2 +- COMCMS.Core/Core/部门.Biz.cs | 250 +++++++++++++ COMCMS.Core/Core/部门.cs | 336 ++++++++++++++++++ .../Controllers/DepartmentController.cs | 158 ++++++++ .../Views/Department/AddDepartment.cshtml | 90 +++++ .../Views/Department/DepartmentList.cshtml | 66 ++++ .../Views/Department/EditDepartment.cshtml | 91 +++++ COMCMS.Web/COMCMS.Web.csproj | 11 +- COMCMS.Web/Common/MenuRegister.cs | 145 -------- COMCMS.Web/Startup.cs | 7 - .../NewLife.UserGroup.WebUploader.csproj | 2 +- XCoder/Entity/data.project.xml | 39 ++ XCoder/Entity/数据字典.Biz.cs | 122 +++++++ XCoder/Entity/数据字典.cs | 162 +++++++++ XCoder/Entity/数据字典详情.Biz.cs | 136 +++++++ XCoder/Entity/数据字典详情.cs | 219 ++++++++++++ XCoder/Entity/部门.Biz.cs | 131 +++++++ XCoder/Entity/部门.cs | 333 +++++++++++++++++ XCoder/XCoder(代码生成器).csproj | 8 +- XCoder/packages.config | 4 +- 22 files changed, 2149 insertions(+), 167 deletions(-) create mode 100644 COMCMS.Core/Core/部门.Biz.cs create mode 100644 COMCMS.Core/Core/部门.cs create mode 100644 COMCMS.Web/Areas/AdminCP/Controllers/DepartmentController.cs create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Department/AddDepartment.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Department/DepartmentList.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Department/EditDepartment.cshtml delete mode 100644 COMCMS.Web/Common/MenuRegister.cs create mode 100644 XCoder/Entity/数据字典.Biz.cs create mode 100644 XCoder/Entity/数据字典.cs create mode 100644 XCoder/Entity/数据字典详情.Biz.cs create mode 100644 XCoder/Entity/数据字典详情.cs create mode 100644 XCoder/Entity/部门.Biz.cs create mode 100644 XCoder/Entity/部门.cs diff --git a/COMCMS.API/COMCMS.API.csproj b/COMCMS.API/COMCMS.API.csproj index d66c05d..6f241d0 100644 --- a/COMCMS.API/COMCMS.API.csproj +++ b/COMCMS.API/COMCMS.API.csproj @@ -5,7 +5,7 @@ - + diff --git a/COMCMS.Common/COMCMS.Common.csproj b/COMCMS.Common/COMCMS.Common.csproj index c3773f4..e7e1cfc 100644 --- a/COMCMS.Common/COMCMS.Common.csproj +++ b/COMCMS.Common/COMCMS.Common.csproj @@ -6,7 +6,7 @@ - + diff --git a/COMCMS.Core/COMCMS.Core.csproj b/COMCMS.Core/COMCMS.Core.csproj index 680489f..9828f4d 100644 --- a/COMCMS.Core/COMCMS.Core.csproj +++ b/COMCMS.Core/COMCMS.Core.csproj @@ -5,7 +5,7 @@ - + diff --git a/COMCMS.Core/Core/部门.Biz.cs b/COMCMS.Core/Core/部门.Biz.cs new file mode 100644 index 0000000..627d0ff --- /dev/null +++ b/COMCMS.Core/Core/部门.Biz.cs @@ -0,0 +1,250 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Web.Script.Serialization; +using System.Xml.Serialization; +using NewLife; +using NewLife.Data; +using NewLife.Log; +using NewLife.Model; +using NewLife.Reflection; +using NewLife.Threading; +using NewLife.Web; +using XCode; +using XCode.Cache; +using XCode.Configuration; +using XCode.DataAccessLayer; +using XCode.Membership; + +namespace COMCMS.Core +{ + /// 部门 + public partial class Department : Entity + { + #region 对象操作 + static Department() + { + // 累加字段,生成 Update xx Set Count=Count+1234 Where xxx + //var df = Meta.Factory.AdditionalFields; + //df.Add(nameof(PId)); + + // 过滤器 UserModule、TimeModule、IPModule + } + + /// 验证数据,通过抛出异常的方式提示验证失败。 + /// 是否插入 + public override void Valid(Boolean isNew) + { + // 如果没有脏数据,则不需要进行任何处理 + if (!HasDirty) return; + + // 在新插入数据或者修改了指定字段时进行修正 + } + + ///// 首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法 + //[EditorBrowsable(EditorBrowsableState.Never)] + //protected override void InitData() + //{ + // // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用 + // if (Meta.Session.Count > 0) return; + + // if (XTrace.Debug) XTrace.WriteLine("开始初始化Department[部门]数据……"); + + // var entity = new Department(); + // entity.Id = 0; + // entity.DepartmentName = "abc"; + // entity.PId = 0; + // entity.Level = 0; + // entity.Location = "abc"; + // entity.DepartmentDescription = "abc"; + // entity.Pic = "abc"; + // entity.Rank = 0; + // entity.IsNotAllowDel = 0; + // entity.Powers = "abc"; + // entity.IsDel = 0; + // entity.Tel = "abc"; + // entity.Fax = "abc"; + // entity.Email = "abc"; + // entity.Insert(); + + // if (XTrace.Debug) XTrace.WriteLine("完成初始化Department[部门]数据!"); + //} + + ///// 已重载。基类先调用Valid(true)验证数据,然后在事务保护内调用OnInsert + ///// + //public override Int32 Insert() + //{ + // return base.Insert(); + //} + + ///// 已重载。在事务保护范围内处理业务,位于Valid之后 + ///// + //protected override Int32 OnDelete() + //{ + // return base.OnDelete(); + //} + #endregion + + #region 扩展属性 + #endregion + + #region 扩展查询 + /// 根据编号查找 + /// 编号 + /// 实体对象 + public static Department FindById(Int32 id) + { + if (id <= 0) return null; + + // 实体缓存 + if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id); + + // 单对象缓存 + return Meta.SingleCache[id]; + + //return Find(_.Id == id); + } + + /// + /// 根据父ID查询所有子项 + /// + /// 父ID + /// 所有子栏目,按Rank正序排列 + [DataObjectMethod(DataObjectMethodType.Select)] + public static IList FindByParentID(Int32 ID) + { + + IList list = Meta.Cache.Entities.Where(x => x.PId == ID && x.IsDel==0).OrderBy(x => x.Id).OrderBy(x => x.Rank).ToList(); + if (list == null || list.Count < 1) return null; + + //list.Sort(_.Rank, true); + //list.OrderBy(x => x.Rank); + + return list; + } + + /// + /// 获取所有子栏目(递归) + /// + /// 栏目ID + /// 所有子栏目 + public static IList FindAllSubKinds(Int32 ID) + { + List alllist = new List(); + IList list = FindByParentID(ID); + if (list != null && list.Count > 0) + { + alllist.AddRange(list); + foreach (Department ak in list) + { + if (Department.FindByParentID(ak.Id) != null) + { + alllist.AddRange(FindAllSubKinds(ak.Id)); + } + } + } + return alllist; + } + #endregion + + #region 高级查询 + + /// + /// 获取路径 + /// + /// + /// + public static String GetNewLocation(int PId) + { + if (PId == 0) + return "0,"; + else + { + var pa = FindById(PId); + if (pa != null) + { + return GetNewLocation(pa.PId) + pa.Id + ","; + } + else + { + return pa.Id + ","; + } + } + } + /// + /// 获取Level + /// + /// + /// + public static int GetNewLevel(int PId) + { + if (PId == 0) + return 0; + else + { + var pa = FindById(PId); + if (pa != null) + { + return GetNewLevel(pa.PId) + 1; + } + else + { + return pa.Level + 1; + } + } + } + #endregion + + #region 业务操作 + /// + /// 获取树 + /// + /// 上级ID,0为全部 + /// 最大级别0为1级类别;-1为所有下级 + /// 是否缩进 + /// 是否显示隐藏菜单 + /// + public static IList GetListTree(int pid, int maxLevel, bool isIndentation, bool showhide = true) + { + List listTree = new List(); + IList list = FindByParentID(pid); + if (list != null && list.Count > 0) + { + foreach (Department p in list) + { + if (!showhide && p.IsDel == 1) + { + continue; + } + else + { + listTree.Add(p.CloneEntity()); + if ((maxLevel == -1 || p.Level < maxLevel) && Department.FindCount(_.PId == p.Id, null, null, 0, 0) > 0) + { + IList listtmp = GetListTree(p.Id, maxLevel, false); + foreach (Department a in listtmp) + { + if (!showhide && a.IsDel == 1) continue;//如果不显示隐藏,跳过 + Department tmpa = a.CloneEntity(); + if (a.Level > 0 && isIndentation) + { + tmpa.DepartmentName = new string(' ', tmpa.Level * 2) + tmpa.DepartmentName; + } + listTree.Add(tmpa); + } + } + } + } + } + return listTree; + } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Core/Core/部门.cs b/COMCMS.Core/Core/部门.cs new file mode 100644 index 0000000..7d06176 --- /dev/null +++ b/COMCMS.Core/Core/部门.cs @@ -0,0 +1,336 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Runtime.Serialization; +using System.Web.Script.Serialization; +using System.Xml.Serialization; +using XCode; +using XCode.Configuration; +using XCode.DataAccessLayer; + +namespace COMCMS.Core +{ + /// 部门 + [Serializable] + [DataObject] + [Description("部门")] + [BindTable("Department", Description = "部门", ConnName = "dbconn", DbType = DatabaseType.SqlServer)] + public partial class Department : IDepartment + { + #region 属性 + private Int32 _Id; + /// 编号 + [DisplayName("编号")] + [Description("编号")] + [DataObjectField(true, true, false, 0)] + [BindColumn("Id", "编号", "")] + public Int32 Id { get => _Id; set { if (OnPropertyChanging("Id", value)) { _Id = value; OnPropertyChanged("Id"); } } } + + private String _DepartmentName; + /// 部门名称 + [DisplayName("部门名称")] + [Description("部门名称")] + [DataObjectField(false, false, true, 50)] + [BindColumn("DepartmentName", "部门名称", "")] + public String DepartmentName { get => _DepartmentName; set { if (OnPropertyChanging("DepartmentName", value)) { _DepartmentName = value; OnPropertyChanged("DepartmentName"); } } } + + private Int32 _PId; + /// 上级部门ID + [DisplayName("上级部门ID")] + [Description("上级部门ID")] + [DataObjectField(false, false, false, 0)] + [BindColumn("PId", "上级部门ID", "")] + public Int32 PId { get => _PId; set { if (OnPropertyChanging("PId", value)) { _PId = value; OnPropertyChanged("PId"); } } } + + private Int32 _Level; + /// 级别 + [DisplayName("级别")] + [Description("级别")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Level", "级别", "")] + public Int32 Level { get => _Level; set { if (OnPropertyChanging("Level", value)) { _Level = value; OnPropertyChanged("Level"); } } } + + private String _Location; + /// 路径 + [DisplayName("路径")] + [Description("路径")] + [DataObjectField(false, false, true, 100)] + [BindColumn("Location", "路径", "")] + public String Location { get => _Location; set { if (OnPropertyChanging("Location", value)) { _Location = value; OnPropertyChanged("Location"); } } } + + private String _DepartmentDescription; + /// 部门说明 + [DisplayName("部门说明")] + [Description("部门说明")] + [DataObjectField(false, false, true, 250)] + [BindColumn("DepartmentDescription", "部门说明", "")] + public String DepartmentDescription { get => _DepartmentDescription; set { if (OnPropertyChanging("DepartmentDescription", value)) { _DepartmentDescription = value; OnPropertyChanged("DepartmentDescription"); } } } + + private String _Pic; + /// 部门图片 + [DisplayName("部门图片")] + [Description("部门图片")] + [DataObjectField(false, false, true, 250)] + [BindColumn("Pic", "部门图片", "")] + public String Pic { get => _Pic; set { if (OnPropertyChanging("Pic", value)) { _Pic = value; OnPropertyChanged("Pic"); } } } + + private Int32 _Rank; + /// 排序 + [DisplayName("排序")] + [Description("排序")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Rank", "排序", "")] + public Int32 Rank { get => _Rank; set { if (OnPropertyChanging("Rank", value)) { _Rank = value; OnPropertyChanged("Rank"); } } } + + private Int32 _IsNotAllowDel; + /// 是否不允许删除 + [DisplayName("是否不允许删除")] + [Description("是否不允许删除")] + [DataObjectField(false, false, false, 0)] + [BindColumn("IsNotAllowDel", "是否不允许删除", "")] + public Int32 IsNotAllowDel { get => _IsNotAllowDel; set { if (OnPropertyChanging("IsNotAllowDel", value)) { _IsNotAllowDel = value; OnPropertyChanged("IsNotAllowDel"); } } } + + private String _Powers; + /// 部门权限 + [DisplayName("部门权限")] + [Description("部门权限")] + [DataObjectField(false, false, true, -1)] + [BindColumn("Powers", "部门权限", "", Master = true)] + public String Powers { get => _Powers; set { if (OnPropertyChanging("Powers", value)) { _Powers = value; OnPropertyChanged("Powers"); } } } + + private Int32 _IsDel; + /// 是否删除 + [DisplayName("是否删除")] + [Description("是否删除")] + [DataObjectField(false, false, false, 0)] + [BindColumn("IsDel", "是否删除", "")] + public Int32 IsDel { get => _IsDel; set { if (OnPropertyChanging("IsDel", value)) { _IsDel = value; OnPropertyChanged("IsDel"); } } } + + private String _Tel; + /// 联系电话 + [DisplayName("联系电话")] + [Description("联系电话")] + [DataObjectField(false, false, true, 30)] + [BindColumn("Tel", "联系电话", "")] + public String Tel { get => _Tel; set { if (OnPropertyChanging("Tel", value)) { _Tel = value; OnPropertyChanged("Tel"); } } } + + private String _Fax; + /// 传真 + [DisplayName("传真")] + [Description("传真")] + [DataObjectField(false, false, true, 30)] + [BindColumn("Fax", "传真", "")] + public String Fax { get => _Fax; set { if (OnPropertyChanging("Fax", value)) { _Fax = value; OnPropertyChanged("Fax"); } } } + + private String _Email; + /// 邮件 + [DisplayName("邮件")] + [Description("邮件")] + [DataObjectField(false, false, true, 100)] + [BindColumn("Email", "邮件", "")] + public String Email { get => _Email; set { if (OnPropertyChanging("Email", value)) { _Email = value; OnPropertyChanged("Email"); } } } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + public override Object this[String name] + { + get + { + switch (name) + { + case "Id": return _Id; + case "DepartmentName": return _DepartmentName; + case "PId": return _PId; + case "Level": return _Level; + case "Location": return _Location; + case "DepartmentDescription": return _DepartmentDescription; + case "Pic": return _Pic; + case "Rank": return _Rank; + case "IsNotAllowDel": return _IsNotAllowDel; + case "Powers": return _Powers; + case "IsDel": return _IsDel; + case "Tel": return _Tel; + case "Fax": return _Fax; + case "Email": return _Email; + default: return base[name]; + } + } + set + { + switch (name) + { + case "Id": _Id = value.ToInt(); break; + case "DepartmentName": _DepartmentName = Convert.ToString(value); break; + case "PId": _PId = value.ToInt(); break; + case "Level": _Level = value.ToInt(); break; + case "Location": _Location = Convert.ToString(value); break; + case "DepartmentDescription": _DepartmentDescription = Convert.ToString(value); break; + case "Pic": _Pic = Convert.ToString(value); break; + case "Rank": _Rank = value.ToInt(); break; + case "IsNotAllowDel": _IsNotAllowDel = value.ToInt(); break; + case "Powers": _Powers = Convert.ToString(value); break; + case "IsDel": _IsDel = value.ToInt(); break; + case "Tel": _Tel = Convert.ToString(value); break; + case "Fax": _Fax = Convert.ToString(value); break; + case "Email": _Email = Convert.ToString(value); break; + default: base[name] = value; break; + } + } + } + #endregion + + #region 字段名 + /// 取得部门字段信息的快捷方式 + public partial class _ + { + /// 编号 + public static readonly Field Id = FindByName("Id"); + + /// 部门名称 + public static readonly Field DepartmentName = FindByName("DepartmentName"); + + /// 上级部门ID + public static readonly Field PId = FindByName("PId"); + + /// 级别 + public static readonly Field Level = FindByName("Level"); + + /// 路径 + public static readonly Field Location = FindByName("Location"); + + /// 部门说明 + public static readonly Field DepartmentDescription = FindByName("DepartmentDescription"); + + /// 部门图片 + public static readonly Field Pic = FindByName("Pic"); + + /// 排序 + public static readonly Field Rank = FindByName("Rank"); + + /// 是否不允许删除 + public static readonly Field IsNotAllowDel = FindByName("IsNotAllowDel"); + + /// 部门权限 + public static readonly Field Powers = FindByName("Powers"); + + /// 是否删除 + public static readonly Field IsDel = FindByName("IsDel"); + + /// 联系电话 + public static readonly Field Tel = FindByName("Tel"); + + /// 传真 + public static readonly Field Fax = FindByName("Fax"); + + /// 邮件 + public static readonly Field Email = FindByName("Email"); + + static Field FindByName(String name) => Meta.Table.FindByName(name); + } + + /// 取得部门字段名称的快捷方式 + public partial class __ + { + /// 编号 + public const String Id = "Id"; + + /// 部门名称 + public const String DepartmentName = "DepartmentName"; + + /// 上级部门ID + public const String PId = "PId"; + + /// 级别 + public const String Level = "Level"; + + /// 路径 + public const String Location = "Location"; + + /// 部门说明 + public const String DepartmentDescription = "DepartmentDescription"; + + /// 部门图片 + public const String Pic = "Pic"; + + /// 排序 + public const String Rank = "Rank"; + + /// 是否不允许删除 + public const String IsNotAllowDel = "IsNotAllowDel"; + + /// 部门权限 + public const String Powers = "Powers"; + + /// 是否删除 + public const String IsDel = "IsDel"; + + /// 联系电话 + public const String Tel = "Tel"; + + /// 传真 + public const String Fax = "Fax"; + + /// 邮件 + public const String Email = "Email"; + } + #endregion + } + + /// 部门接口 + public partial interface IDepartment + { + #region 属性 + /// 编号 + Int32 Id { get; set; } + + /// 部门名称 + String DepartmentName { get; set; } + + /// 上级部门ID + Int32 PId { get; set; } + + /// 级别 + Int32 Level { get; set; } + + /// 路径 + String Location { get; set; } + + /// 部门说明 + String DepartmentDescription { get; set; } + + /// 部门图片 + String Pic { get; set; } + + /// 排序 + Int32 Rank { get; set; } + + /// 是否不允许删除 + Int32 IsNotAllowDel { get; set; } + + /// 部门权限 + String Powers { get; set; } + + /// 是否删除 + Int32 IsDel { get; set; } + + /// 联系电话 + String Tel { get; set; } + + /// 传真 + String Fax { get; set; } + + /// 邮件 + String Email { get; set; } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + Object this[String name] { get; set; } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/DepartmentController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/DepartmentController.cs new file mode 100644 index 0000000..5362f3c --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Controllers/DepartmentController.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using COMCMS.Common; +using COMCMS.Core; +using XCode; +using Newtonsoft.Json; +using COMCMS.Web.Common; +using Microsoft.AspNetCore.Http; + +namespace COMCMS.Web.Areas.AdminCP.Controllers +{ + public class DepartmentController : AdminBaseController + { + #region 部门管理 + /// + /// 部门列表 + /// + /// + [MyAuthorize("viewlist", "department")] + public IActionResult DepartmentList() + { + IList list = Department.GetListTree(0, -1, false, true); + Core.Admin.WriteLogActions("查看部门列表页面;"); + return View(list); + } + + + #endregion + #region 添加部门 + [MyAuthorize("add", "department")] + public IActionResult AddDepartment() + { + //获取上级栏目 + IList list = Department.GetListTree(0, 0, true, false); + ViewBag.ListTree = list; + Department entity = new Department(); + Core.Admin.WriteLogActions("查看添加部门页面;"); + return View(entity); + } + + [HttpPost] + [MyAuthorize("add", "department", "JSON")] + public IActionResult AddDepartment(Department model) + { + //获取上级栏目 + if (string.IsNullOrWhiteSpace(model.DepartmentName)) + { + tip.Message = "部门名称不能为空!"; + return Json(tip); + } + + model.Insert(); + Core.Admin.WriteLogActions("添加部门(id:" + model.Id + ");"); + tip.Status = JsonTip.SUCCESS; + tip.Message = "添加部门成功"; + tip.ReturnUrl = "close"; + + return Json(tip); + } + #endregion + + #region 编辑部门 + //编辑部门 + [HttpGet] + [MyAuthorize("edit", "department")] + public IActionResult EditDepartment(int id) + { + Department entity = Department.Find(Department._.Id == id); + if (entity == null) + { + return EchoTipPage("系统找不到本记录!"); + } + //获取上级栏目 + IList list = Department.GetListTree(0, 0, true, false); + ViewBag.ListTree = list; + Core.Admin.WriteLogActions("查看/编辑部门(id:" + id + ")页面;"); + return View(entity); + } + + [HttpPost] + [MyAuthorize("edit", "department", "JSON")] + public IActionResult EditDepartment(Department model) + { + if (model.Id <= 0) + { + tip.Message = "错误参数传递!"; + Json(tip); + } + if (string.IsNullOrWhiteSpace(model.DepartmentName)) + { + tip.Message = "部门名称不能为空!"; + return Json(tip); + } + Department entity = Department.Find(Department._.Id == model.Id); + if (entity == null) + { + tip.Message = "系统找不到本记录!"; + Json(tip); + } + //赋值 + + entity.DepartmentName = model.DepartmentName; + entity.Pic = model.Pic; + entity.DepartmentDescription = model.DepartmentDescription; + entity.Rank = model.Rank; + entity.Pic = model.Pic; + entity.Tel = model.Tel; + entity.Fax = model.Fax; + entity.Email = model.Email; + entity.IsNotAllowDel = Request.Form["IsNotAllowDel"] == "1" ? 1 : 0; + //如果修改了路径 + if (entity.PId != model.PId) + { + entity.PId = model.PId; + entity.Location = Department.GetNewLocation(model.PId); + } + entity.Save(); + + Core.Admin.WriteLogActions("修改部门(id:" + entity.Id + ");"); + tip.Status = JsonTip.SUCCESS; + tip.Message = "修改部门成功"; + tip.ReturnUrl = "close"; + + return Json(tip); + } + + //删除栏目 + [HttpPost] + [MyAuthorize("del", "department", "JSON")] + public JsonResult DelDepartment(int id) + { + Department entity = Department.Find(Department._.Id == id); + if (entity == null) + { + tip.Message = "系统找不到本部门!"; + return Json(tip); + } + if (Department.FindCount(Department._.PId == entity.Id, null, null, 0, 0) > 0) + { + tip.Message = "部门目有下级部门,不允许删除!"; + return Json(tip); + } + //删除文章 + + Core.Admin.WriteLogActions("删除部门(id:" + entity.Id + ");"); + entity.IsDel =1; + entity.Update(); + tip.Status = JsonTip.SUCCESS; + tip.Message = "删除部门成功"; + return Json(tip); + } + #endregion + } +} diff --git a/COMCMS.Web/Areas/AdminCP/Views/Department/AddDepartment.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Department/AddDepartment.cshtml new file mode 100644 index 0000000..370a9e9 --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/Department/AddDepartment.cshtml @@ -0,0 +1,90 @@ +@model Department +@{ + ViewBag.title = "添加部门"; +} + +
+
+
+
@ViewBag.Title
+
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ + +
+
+
+ +
+
+
+ diff --git a/COMCMS.Web/Areas/AdminCP/Views/Department/DepartmentList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Department/DepartmentList.cshtml new file mode 100644 index 0000000..9da4917 --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/Department/DepartmentList.cshtml @@ -0,0 +1,66 @@ +@model IList +@{ + ViewBag.title = "部门管理"; +} + +
+
+
+
@ViewBag.Title
+
+
+
+ +
+ +
+ +
+ + + + + + + + + + + + @if (Model.Count == 0) + { + + } + @foreach (var m in Model) + { + + + + + + + + + } +
部门名称ID排序联系电话说明/备注操作
暂无记录...
@m.DepartmentName + @m.Id + @m.Rank@m.Tel + @m.DepartmentDescription + + 编辑 + 删除 +
+ +
+
+ + +
\ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Views/Department/EditDepartment.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Department/EditDepartment.cshtml new file mode 100644 index 0000000..d7e1163 --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/Department/EditDepartment.cshtml @@ -0,0 +1,91 @@ +@model Department +@{ + ViewBag.title = "编辑部门详情"; +} + +
+
+
+
@ViewBag.Title
+
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ + + +
+
+
+ +
+
+
+ diff --git a/COMCMS.Web/COMCMS.Web.csproj b/COMCMS.Web/COMCMS.Web.csproj index 58e4df8..3d22141 100644 --- a/COMCMS.Web/COMCMS.Web.csproj +++ b/COMCMS.Web/COMCMS.Web.csproj @@ -6,13 +6,14 @@ - - + + + - - - + + + diff --git a/COMCMS.Web/Common/MenuRegister.cs b/COMCMS.Web/Common/MenuRegister.cs deleted file mode 100644 index bf7efca..0000000 --- a/COMCMS.Web/Common/MenuRegister.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using COMCMS.Core; -using Microsoft.AspNetCore.Mvc; -using NewLife.Reflection; -using XCode; - -namespace COMCMS.Web.Common -{ - public class MenuRegister - { - private static void StartRegister() - { - if (AdminMenu.Meta.Count > 0) - return; - // 操作项定义 - var menuEventDic = new Dictionary> - { - { "add",new KeyValuePair(1,"添加")}, - { "edit",new KeyValuePair(2,"修改")}, - { "del",new KeyValuePair(3,"删除")}, - { "view",new KeyValuePair(4,"查看")}, - { "viewlist",new KeyValuePair(5,"查看列表")}, - { "import",new KeyValuePair(6,"导入")}, - { "export",new KeyValuePair(7,"导出")}, - { "filter",new KeyValuePair(8,"搜索")}, - { "batch",new KeyValuePair(9,"批量操作")}, - { "recycle",new KeyValuePair(10,"回收站")}, - { "confirm",new KeyValuePair(11,"确认")}, - - }; - - var asms = AppDomain.CurrentDomain.GetAssemblies(); - foreach (var asmItem in asms) - { - var types = asmItem.GetTypes().Where(e => e.Name.EndsWith("Controller")).ToList(); - if (types.Count == 0) continue; - - foreach (var type in types) - { - if (!type.Namespace.Contains(".AdminCP.Controller")) - { - continue; - } - - // 控制器名称 - var ctrName = type.Name.TrimEnd("Controller"); - - // 控制器展示名 - var ctrDpName = type.GetDisplayName(); - - var ctrDes = type.GetDescription(); - - var url = ctrName; - - var fAdminMenu = AdminMenu.Find(AdminMenu._.MenuKey == ctrName + "Sys" & AdminMenu._.Link == "#"); - var nAdminMenu = new AdminMenu - { - Description = ctrDes, - IsHide = 0, - Level = 0, - Link = "#", - Location = "0,", - MenuKey = ctrName + "Sys", - MenuName = ctrDpName, - PId = 0 - }; - var pAdminMenu = fAdminMenu ?? nAdminMenu; - if (pAdminMenu.Id > 0) - { - pAdminMenu.Description = nAdminMenu.Description; - pAdminMenu.MenuName = nAdminMenu.MenuName; - } - - // 控制器所有包含MyAuthorizeAttribute的方法 - var acts = type.GetMethods() - .Where(w => w.IsDefined(typeof(MyAuthorizeAttribute))) - .ToList(); - - if (!acts.Any()) continue; - - pAdminMenu.Save(); - - var eventKeyDic = new Dictionary(); - var adminMenuEventList = new List(); - - foreach (var method in acts) - { - var dn = method.GetDisplayName(); - var methodDes = method.GetDescription(); - var actName = method.Name; - var myAuthorize = method.GetCustomAttribute(); - - var menuKey = myAuthorize.GetValue("_menuKey").ToString(); - var eventKey = myAuthorize.GetValue("_eventKey").ToString(); - var returnType = myAuthorize.GetValue("_returnType").ToString(); - - //保存菜单 - if (eventKey == "viewlist" && returnType == "HTML") - { - var adminMenu = AdminMenu.Find(AdminMenu._.MenuKey == menuKey & AdminMenu._.Link == url + "/" + actName) ?? new AdminMenu - { - Description = methodDes, - IsHide = 0, - Level = pAdminMenu.Level + 1, - Link = url + "/" + actName, - Location = pAdminMenu.Location + ",", - MenuKey = menuKey, - MenuName = dn, - PId = pAdminMenu.Id - }; - adminMenu.Save(); - - eventKeyDic[menuKey] = adminMenu.Id; - } - - // 保存操作 - var adminmenuevent = AdminMenuEvent.Find(AdminMenuEvent._.MenuId == menuEventDic[eventKey].Key - & AdminMenuEvent._.MenuKey == menuKey & AdminMenuEvent._.EventKey == eventKey) - ?? new AdminMenuEvent - { - MenuKey = menuKey, - MenuId = menuEventDic[eventKey].Key, - EventKey = eventKey, - EventName = menuEventDic[eventKey].Value - }; - adminMenuEventList.Add(adminmenuevent); - } - - adminMenuEventList.ForEach(f => f.MenuId = eventKeyDic.ContainsKey(f.MenuKey) ? eventKeyDic[f.MenuKey] : 0); - adminMenuEventList.Save(); - } - - } - } - - public static void Register() - { - Task.Run(() => { StartRegister(); }); - } - } -} diff --git a/COMCMS.Web/Startup.cs b/COMCMS.Web/Startup.cs index 6400ac8..efae43c 100644 --- a/COMCMS.Web/Startup.cs +++ b/COMCMS.Web/Startup.cs @@ -42,13 +42,6 @@ namespace COMCMS.Web // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - // 注册菜单 - //MenuRegister.Register(); - - //注入自己的HttpContext - //services.AddSingleton(); - //services.AddMvc().AddSessionStateTempDataProvider(); - //添加Configuration到静态变量 Utils.AddUtils(Configuration); diff --git a/NewLife.UserGroup.WebUploader/NewLife.UserGroup.WebUploader.csproj b/NewLife.UserGroup.WebUploader/NewLife.UserGroup.WebUploader.csproj index 49b5e04..ecb0692 100644 --- a/NewLife.UserGroup.WebUploader/NewLife.UserGroup.WebUploader.csproj +++ b/NewLife.UserGroup.WebUploader/NewLife.UserGroup.WebUploader.csproj @@ -5,7 +5,7 @@ - + diff --git a/XCoder/Entity/data.project.xml b/XCoder/Entity/data.project.xml index 31e98c4..0a5a2d9 100644 --- a/XCoder/Entity/data.project.xml +++ b/XCoder/Entity/data.project.xml @@ -1126,4 +1126,43 @@ + + + + + + + + + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + +
\ No newline at end of file diff --git a/XCoder/Entity/数据字典.Biz.cs b/XCoder/Entity/数据字典.Biz.cs new file mode 100644 index 0000000..acdc8fa --- /dev/null +++ b/XCoder/Entity/数据字典.Biz.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Xml.Serialization; +using NewLife; +using NewLife.Data; +using NewLife.Log; +using NewLife.Model; +using NewLife.Reflection; +using NewLife.Threading; +using NewLife.Web; +using XCode; +using XCode.Cache; +using XCode.Configuration; +using XCode.DataAccessLayer; +using XCode.Membership; + +namespace COMCMS.Core +{ + /// 数据字典 + public partial class DataDictionary : Entity + { + #region 对象操作 + static DataDictionary() + { + // 累加字段,生成 Update xx Set Count=Count+1234 Where xxx + //var df = Meta.Factory.AdditionalFields; + //df.Add(__.Rank); + + // 过滤器 UserModule、TimeModule、IPModule + } + + /// 验证数据,通过抛出异常的方式提示验证失败。 + /// 是否插入 + public override void Valid(Boolean isNew) + { + // 如果没有脏数据,则不需要进行任何处理 + if (!HasDirty) return; + + // 在新插入数据或者修改了指定字段时进行修正 + } + + ///// 首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法 + //[EditorBrowsable(EditorBrowsableState.Never)] + //protected override void InitData() + //{ + // // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用 + // if (Meta.Session.Count > 0) return; + + // if (XTrace.Debug) XTrace.WriteLine("开始初始化DataDictionary[数据字典]数据……"); + + // var entity = new DataDictionary(); + // entity.Id = 0; + // entity.Key = "abc"; + // entity.Description = "abc"; + // entity.Rank = 0; + // entity.AddTime = DateTime.Now; + // entity.Insert(); + + // if (XTrace.Debug) XTrace.WriteLine("完成初始化DataDictionary[数据字典]数据!"); + //} + + ///// 已重载。基类先调用Valid(true)验证数据,然后在事务保护内调用OnInsert + ///// + //public override Int32 Insert() + //{ + // return base.Insert(); + //} + + ///// 已重载。在事务保护范围内处理业务,位于Valid之后 + ///// + //protected override Int32 OnDelete() + //{ + // return base.OnDelete(); + //} + #endregion + + #region 扩展属性 + #endregion + + #region 扩展查询 + /// 根据编号查找 + /// 编号 + /// 实体对象 + public static DataDictionary FindById(Int32 id) + { + if (id <= 0) return null; + + // 实体缓存 + if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id); + + // 单对象缓存 + return Meta.SingleCache[id]; + + //return Find(_.Id == id); + } + #endregion + + #region 高级查询 + + // Select Count(Id) as Id,Category From DataDictionary Where CreateTime>'2020-01-24 00:00:00' Group By Category Order By Id Desc limit 20 + //static readonly FieldCache _CategoryCache = new FieldCache(_.Category) + //{ + //Where = _.CreateTime > DateTime.Today.AddDays(-30) & Expression.Empty + //}; + + ///// 获取类别列表,字段缓存10分钟,分组统计数据最多的前20种,用于魔方前台下拉选择 + ///// + //public static IDictionary GetCategoryList() => _CategoryCache.FindAllName(); + #endregion + + #region 业务操作 + #endregion + } +} \ No newline at end of file diff --git a/XCoder/Entity/数据字典.cs b/XCoder/Entity/数据字典.cs new file mode 100644 index 0000000..448b67d --- /dev/null +++ b/XCoder/Entity/数据字典.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using XCode; +using XCode.Configuration; +using XCode.DataAccessLayer; + +namespace COMCMS.Core +{ + /// 数据字典 + [Serializable] + [DataObject] + [Description("数据字典")] + [BindTable("DataDictionary", Description = "数据字典", ConnName = "dbconn", DbType = DatabaseType.SqlServer)] + public partial class DataDictionary : IDataDictionary + { + #region 属性 + private Int32 _Id; + /// 编号 + [DisplayName("编号")] + [Description("编号")] + [DataObjectField(true, true, false, 0)] + [BindColumn("Id", "编号", "")] + public Int32 Id { get => _Id; set { if (OnPropertyChanging(__.Id, value)) { _Id = value; OnPropertyChanged(__.Id); } } } + + private String _Key; + /// 字典key + [DisplayName("字典key")] + [Description("字典key")] + [DataObjectField(false, false, true, 50)] + [BindColumn("Key", "字典key", "")] + public String Key { get => _Key; set { if (OnPropertyChanging(__.Key, value)) { _Key = value; OnPropertyChanged(__.Key); } } } + + private String _Description; + /// 字典介绍 + [DisplayName("字典介绍")] + [Description("字典介绍")] + [DataObjectField(false, false, true, 50)] + [BindColumn("Description", "字典介绍", "")] + public String Description { get => _Description; set { if (OnPropertyChanging(__.Description, value)) { _Description = value; OnPropertyChanged(__.Description); } } } + + private Int32 _Rank; + /// 排序 + [DisplayName("排序")] + [Description("排序")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Rank", "排序", "")] + public Int32 Rank { get => _Rank; set { if (OnPropertyChanging(__.Rank, value)) { _Rank = value; OnPropertyChanged(__.Rank); } } } + + private DateTime _AddTime; + /// 添加时间 + [DisplayName("添加时间")] + [Description("添加时间")] + [DataObjectField(false, false, true, 0)] + [BindColumn("AddTime", "添加时间", "")] + public DateTime AddTime { get => _AddTime; set { if (OnPropertyChanging(__.AddTime, value)) { _AddTime = value; OnPropertyChanged(__.AddTime); } } } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + public override Object this[String name] + { + get + { + switch (name) + { + case __.Id: return _Id; + case __.Key: return _Key; + case __.Description: return _Description; + case __.Rank: return _Rank; + case __.AddTime: return _AddTime; + default: return base[name]; + } + } + set + { + switch (name) + { + case __.Id: _Id = value.ToInt(); break; + case __.Key: _Key = Convert.ToString(value); break; + case __.Description: _Description = Convert.ToString(value); break; + case __.Rank: _Rank = value.ToInt(); break; + case __.AddTime: _AddTime = value.ToDateTime(); break; + default: base[name] = value; break; + } + } + } + #endregion + + #region 字段名 + /// 取得数据字典字段信息的快捷方式 + public partial class _ + { + /// 编号 + public static readonly Field Id = FindByName(__.Id); + + /// 字典key + public static readonly Field Key = FindByName(__.Key); + + /// 字典介绍 + public static readonly Field Description = FindByName(__.Description); + + /// 排序 + public static readonly Field Rank = FindByName(__.Rank); + + /// 添加时间 + public static readonly Field AddTime = FindByName(__.AddTime); + + static Field FindByName(String name) => Meta.Table.FindByName(name); + } + + /// 取得数据字典字段名称的快捷方式 + public partial class __ + { + /// 编号 + public const String Id = "Id"; + + /// 字典key + public const String Key = "Key"; + + /// 字典介绍 + public const String Description = "Description"; + + /// 排序 + public const String Rank = "Rank"; + + /// 添加时间 + public const String AddTime = "AddTime"; + } + #endregion + } + + /// 数据字典接口 + public partial interface IDataDictionary + { + #region 属性 + /// 编号 + Int32 Id { get; set; } + + /// 字典key + String Key { get; set; } + + /// 字典介绍 + String Description { get; set; } + + /// 排序 + Int32 Rank { get; set; } + + /// 添加时间 + DateTime AddTime { get; set; } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + Object this[String name] { get; set; } + #endregion + } +} \ No newline at end of file diff --git a/XCoder/Entity/数据字典详情.Biz.cs b/XCoder/Entity/数据字典详情.Biz.cs new file mode 100644 index 0000000..9f6243b --- /dev/null +++ b/XCoder/Entity/数据字典详情.Biz.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Xml.Serialization; +using NewLife; +using NewLife.Data; +using NewLife.Log; +using NewLife.Model; +using NewLife.Reflection; +using NewLife.Threading; +using NewLife.Web; +using XCode; +using XCode.Cache; +using XCode.Configuration; +using XCode.DataAccessLayer; +using XCode.Membership; + +namespace COMCMS.Core +{ + /// 数据字典详情 + public partial class DataDictionaryDetail : Entity + { + #region 对象操作 + static DataDictionaryDetail() + { + // 累加字段,生成 Update xx Set Count=Count+1234 Where xxx + //var df = Meta.Factory.AdditionalFields; + //df.Add(__.DataDictionaryId); + + // 过滤器 UserModule、TimeModule、IPModule + } + + /// 验证数据,通过抛出异常的方式提示验证失败。 + /// 是否插入 + public override void Valid(Boolean isNew) + { + // 如果没有脏数据,则不需要进行任何处理 + if (!HasDirty) return; + + // 在新插入数据或者修改了指定字段时进行修正 + } + + ///// 首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法 + //[EditorBrowsable(EditorBrowsableState.Never)] + //protected override void InitData() + //{ + // // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用 + // if (Meta.Session.Count > 0) return; + + // if (XTrace.Debug) XTrace.WriteLine("开始初始化DataDictionaryDetail[数据字典详情]数据……"); + + // var entity = new DataDictionaryDetail(); + // entity.Id = 0; + // entity.DataDictionaryId = 0; + // entity.Val = "abc"; + // entity.Title = "abc"; + // entity.Description = "abc"; + // entity.Rank = 0; + // entity.IsDefault = 0; + // entity.AddTime = DateTime.Now; + // entity.Insert(); + + // if (XTrace.Debug) XTrace.WriteLine("完成初始化DataDictionaryDetail[数据字典详情]数据!"); + //} + + ///// 已重载。基类先调用Valid(true)验证数据,然后在事务保护内调用OnInsert + ///// + //public override Int32 Insert() + //{ + // return base.Insert(); + //} + + ///// 已重载。在事务保护范围内处理业务,位于Valid之后 + ///// + //protected override Int32 OnDelete() + //{ + // return base.OnDelete(); + //} + #endregion + + #region 扩展属性 + /// 字典ID + [XmlIgnore, IgnoreDataMember] + //[ScriptIgnore] + public DataDictionary DataDictionary => Extends.Get(nameof(DataDictionary), k => DataDictionary.FindById(DataDictionaryId)); + + /// 字典ID + [XmlIgnore, IgnoreDataMember] + //[ScriptIgnore] + [DisplayName("字典ID")] + [Map(__.DataDictionaryId, typeof(DataDictionary), "Id")] + public Int32 DataDictionaryId => DataDictionary != null ? DataDictionary.Id : 0; + #endregion + + #region 扩展查询 + /// 根据编号查找 + /// 编号 + /// 实体对象 + public static DataDictionaryDetail FindById(Int32 id) + { + if (id <= 0) return null; + + // 实体缓存 + if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id); + + // 单对象缓存 + return Meta.SingleCache[id]; + + //return Find(_.Id == id); + } + #endregion + + #region 高级查询 + + // Select Count(Id) as Id,Category From DataDictionaryDetail Where CreateTime>'2020-01-24 00:00:00' Group By Category Order By Id Desc limit 20 + //static readonly FieldCache _CategoryCache = new FieldCache(_.Category) + //{ + //Where = _.CreateTime > DateTime.Today.AddDays(-30) & Expression.Empty + //}; + + ///// 获取类别列表,字段缓存10分钟,分组统计数据最多的前20种,用于魔方前台下拉选择 + ///// + //public static IDictionary GetCategoryList() => _CategoryCache.FindAllName(); + #endregion + + #region 业务操作 + #endregion + } +} \ No newline at end of file diff --git a/XCoder/Entity/数据字典详情.cs b/XCoder/Entity/数据字典详情.cs new file mode 100644 index 0000000..454be68 --- /dev/null +++ b/XCoder/Entity/数据字典详情.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using XCode; +using XCode.Configuration; +using XCode.DataAccessLayer; + +namespace COMCMS.Core +{ + /// 数据字典详情 + [Serializable] + [DataObject] + [Description("数据字典详情")] + [BindTable("DataDictionaryDetail", Description = "数据字典详情", ConnName = "dbconn", DbType = DatabaseType.SqlServer)] + public partial class DataDictionaryDetail : IDataDictionaryDetail + { + #region 属性 + private Int32 _Id; + /// 编号 + [DisplayName("编号")] + [Description("编号")] + [DataObjectField(true, true, false, 0)] + [BindColumn("Id", "编号", "")] + public Int32 Id { get => _Id; set { if (OnPropertyChanging(__.Id, value)) { _Id = value; OnPropertyChanged(__.Id); } } } + + private Int32 _DataDictionaryId; + /// 字典ID + [DisplayName("字典ID")] + [Description("字典ID")] + [DataObjectField(false, false, false, 0)] + [BindColumn("DataDictionaryId", "字典ID", "")] + public Int32 DataDictionaryId { get => _DataDictionaryId; set { if (OnPropertyChanging(__.DataDictionaryId, value)) { _DataDictionaryId = value; OnPropertyChanged(__.DataDictionaryId); } } } + + private String _Val; + /// 字典值 + [DisplayName("字典值")] + [Description("字典值")] + [DataObjectField(false, false, true, 50)] + [BindColumn("Val", "字典值", "")] + public String Val { get => _Val; set { if (OnPropertyChanging(__.Val, value)) { _Val = value; OnPropertyChanged(__.Val); } } } + + private String _Title; + /// 字典标签 + [DisplayName("字典标签")] + [Description("字典标签")] + [DataObjectField(false, false, true, 50)] + [BindColumn("Title", "字典标签", "", Master = true)] + public String Title { get => _Title; set { if (OnPropertyChanging(__.Title, value)) { _Title = value; OnPropertyChanged(__.Title); } } } + + private String _Description; + /// 字典介绍 + [DisplayName("字典介绍")] + [Description("字典介绍")] + [DataObjectField(false, false, true, 50)] + [BindColumn("Description", "字典介绍", "")] + public String Description { get => _Description; set { if (OnPropertyChanging(__.Description, value)) { _Description = value; OnPropertyChanged(__.Description); } } } + + private Int32 _Rank; + /// 排序 + [DisplayName("排序")] + [Description("排序")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Rank", "排序", "")] + public Int32 Rank { get => _Rank; set { if (OnPropertyChanging(__.Rank, value)) { _Rank = value; OnPropertyChanged(__.Rank); } } } + + private Int32 _IsDefault; + /// 是否默认值 + [DisplayName("是否默认值")] + [Description("是否默认值")] + [DataObjectField(false, false, false, 0)] + [BindColumn("IsDefault", "是否默认值", "")] + public Int32 IsDefault { get => _IsDefault; set { if (OnPropertyChanging(__.IsDefault, value)) { _IsDefault = value; OnPropertyChanged(__.IsDefault); } } } + + private DateTime _AddTime; + /// 添加时间 + [DisplayName("添加时间")] + [Description("添加时间")] + [DataObjectField(false, false, true, 0)] + [BindColumn("AddTime", "添加时间", "")] + public DateTime AddTime { get => _AddTime; set { if (OnPropertyChanging(__.AddTime, value)) { _AddTime = value; OnPropertyChanged(__.AddTime); } } } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + public override Object this[String name] + { + get + { + switch (name) + { + case __.Id: return _Id; + case __.DataDictionaryId: return _DataDictionaryId; + case __.Val: return _Val; + case __.Title: return _Title; + case __.Description: return _Description; + case __.Rank: return _Rank; + case __.IsDefault: return _IsDefault; + case __.AddTime: return _AddTime; + default: return base[name]; + } + } + set + { + switch (name) + { + case __.Id: _Id = value.ToInt(); break; + case __.DataDictionaryId: _DataDictionaryId = value.ToInt(); break; + case __.Val: _Val = Convert.ToString(value); break; + case __.Title: _Title = Convert.ToString(value); break; + case __.Description: _Description = Convert.ToString(value); break; + case __.Rank: _Rank = value.ToInt(); break; + case __.IsDefault: _IsDefault = value.ToInt(); break; + case __.AddTime: _AddTime = value.ToDateTime(); break; + default: base[name] = value; break; + } + } + } + #endregion + + #region 字段名 + /// 取得数据字典详情字段信息的快捷方式 + public partial class _ + { + /// 编号 + public static readonly Field Id = FindByName(__.Id); + + /// 字典ID + public static readonly Field DataDictionaryId = FindByName(__.DataDictionaryId); + + /// 字典值 + public static readonly Field Val = FindByName(__.Val); + + /// 字典标签 + public static readonly Field Title = FindByName(__.Title); + + /// 字典介绍 + public static readonly Field Description = FindByName(__.Description); + + /// 排序 + public static readonly Field Rank = FindByName(__.Rank); + + /// 是否默认值 + public static readonly Field IsDefault = FindByName(__.IsDefault); + + /// 添加时间 + public static readonly Field AddTime = FindByName(__.AddTime); + + static Field FindByName(String name) => Meta.Table.FindByName(name); + } + + /// 取得数据字典详情字段名称的快捷方式 + public partial class __ + { + /// 编号 + public const String Id = "Id"; + + /// 字典ID + public const String DataDictionaryId = "DataDictionaryId"; + + /// 字典值 + public const String Val = "Val"; + + /// 字典标签 + public const String Title = "Title"; + + /// 字典介绍 + public const String Description = "Description"; + + /// 排序 + public const String Rank = "Rank"; + + /// 是否默认值 + public const String IsDefault = "IsDefault"; + + /// 添加时间 + public const String AddTime = "AddTime"; + } + #endregion + } + + /// 数据字典详情接口 + public partial interface IDataDictionaryDetail + { + #region 属性 + /// 编号 + Int32 Id { get; set; } + + /// 字典ID + Int32 DataDictionaryId { get; set; } + + /// 字典值 + String Val { get; set; } + + /// 字典标签 + String Title { get; set; } + + /// 字典介绍 + String Description { get; set; } + + /// 排序 + Int32 Rank { get; set; } + + /// 是否默认值 + Int32 IsDefault { get; set; } + + /// 添加时间 + DateTime AddTime { get; set; } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + Object this[String name] { get; set; } + #endregion + } +} \ No newline at end of file diff --git a/XCoder/Entity/部门.Biz.cs b/XCoder/Entity/部门.Biz.cs new file mode 100644 index 0000000..88b24da --- /dev/null +++ b/XCoder/Entity/部门.Biz.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Xml.Serialization; +using NewLife; +using NewLife.Data; +using NewLife.Log; +using NewLife.Model; +using NewLife.Reflection; +using NewLife.Threading; +using NewLife.Web; +using XCode; +using XCode.Cache; +using XCode.Configuration; +using XCode.DataAccessLayer; +using XCode.Membership; + +namespace COMCMS.Core +{ + /// 部门 + public partial class Department : Entity + { + #region 对象操作 + static Department() + { + // 累加字段,生成 Update xx Set Count=Count+1234 Where xxx + //var df = Meta.Factory.AdditionalFields; + //df.Add(__.PId); + + // 过滤器 UserModule、TimeModule、IPModule + } + + /// 验证数据,通过抛出异常的方式提示验证失败。 + /// 是否插入 + public override void Valid(Boolean isNew) + { + // 如果没有脏数据,则不需要进行任何处理 + if (!HasDirty) return; + + // 在新插入数据或者修改了指定字段时进行修正 + } + + ///// 首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法 + //[EditorBrowsable(EditorBrowsableState.Never)] + //protected override void InitData() + //{ + // // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用 + // if (Meta.Session.Count > 0) return; + + // if (XTrace.Debug) XTrace.WriteLine("开始初始化Department[部门]数据……"); + + // var entity = new Department(); + // entity.Id = 0; + // entity.DepartmentName = "abc"; + // entity.PId = 0; + // entity.Level = 0; + // entity.Location = "abc"; + // entity.DepartmentDescription = "abc"; + // entity.Pic = "abc"; + // entity.Rank = 0; + // entity.IsNotAllowDel = 0; + // entity.Powers = "abc"; + // entity.IsDel = 0; + // entity.Tel = "abc"; + // entity.Fax = "abc"; + // entity.Email = "abc"; + // entity.Insert(); + + // if (XTrace.Debug) XTrace.WriteLine("完成初始化Department[部门]数据!"); + //} + + ///// 已重载。基类先调用Valid(true)验证数据,然后在事务保护内调用OnInsert + ///// + //public override Int32 Insert() + //{ + // return base.Insert(); + //} + + ///// 已重载。在事务保护范围内处理业务,位于Valid之后 + ///// + //protected override Int32 OnDelete() + //{ + // return base.OnDelete(); + //} + #endregion + + #region 扩展属性 + #endregion + + #region 扩展查询 + /// 根据编号查找 + /// 编号 + /// 实体对象 + public static Department FindById(Int32 id) + { + if (id <= 0) return null; + + // 实体缓存 + if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id); + + // 单对象缓存 + return Meta.SingleCache[id]; + + //return Find(_.Id == id); + } + #endregion + + #region 高级查询 + + // Select Count(Id) as Id,Category From Department Where CreateTime>'2020-01-24 00:00:00' Group By Category Order By Id Desc limit 20 + //static readonly FieldCache _CategoryCache = new FieldCache(_.Category) + //{ + //Where = _.CreateTime > DateTime.Today.AddDays(-30) & Expression.Empty + //}; + + ///// 获取类别列表,字段缓存10分钟,分组统计数据最多的前20种,用于魔方前台下拉选择 + ///// + //public static IDictionary GetCategoryList() => _CategoryCache.FindAllName(); + #endregion + + #region 业务操作 + #endregion + } +} \ No newline at end of file diff --git a/XCoder/Entity/部门.cs b/XCoder/Entity/部门.cs new file mode 100644 index 0000000..18ad5cc --- /dev/null +++ b/XCoder/Entity/部门.cs @@ -0,0 +1,333 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using XCode; +using XCode.Configuration; +using XCode.DataAccessLayer; + +namespace COMCMS.Core +{ + /// 部门 + [Serializable] + [DataObject] + [Description("部门")] + [BindTable("Department", Description = "部门", ConnName = "dbconn", DbType = DatabaseType.SqlServer)] + public partial class Department : IDepartment + { + #region 属性 + private Int32 _Id; + /// 编号 + [DisplayName("编号")] + [Description("编号")] + [DataObjectField(true, true, false, 0)] + [BindColumn("Id", "编号", "")] + public Int32 Id { get => _Id; set { if (OnPropertyChanging(__.Id, value)) { _Id = value; OnPropertyChanged(__.Id); } } } + + private String _DepartmentName; + /// 部门名称 + [DisplayName("部门名称")] + [Description("部门名称")] + [DataObjectField(false, false, true, 50)] + [BindColumn("DepartmentName", "部门名称", "")] + public String DepartmentName { get => _DepartmentName; set { if (OnPropertyChanging(__.DepartmentName, value)) { _DepartmentName = value; OnPropertyChanged(__.DepartmentName); } } } + + private Int32 _PId; + /// 上级部门ID + [DisplayName("上级部门ID")] + [Description("上级部门ID")] + [DataObjectField(false, false, false, 0)] + [BindColumn("PId", "上级部门ID", "")] + public Int32 PId { get => _PId; set { if (OnPropertyChanging(__.PId, value)) { _PId = value; OnPropertyChanged(__.PId); } } } + + private Int32 _Level; + /// 级别 + [DisplayName("级别")] + [Description("级别")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Level", "级别", "")] + public Int32 Level { get => _Level; set { if (OnPropertyChanging(__.Level, value)) { _Level = value; OnPropertyChanged(__.Level); } } } + + private String _Location; + /// 路径 + [DisplayName("路径")] + [Description("路径")] + [DataObjectField(false, false, true, 100)] + [BindColumn("Location", "路径", "")] + public String Location { get => _Location; set { if (OnPropertyChanging(__.Location, value)) { _Location = value; OnPropertyChanged(__.Location); } } } + + private String _DepartmentDescription; + /// 部门说明 + [DisplayName("部门说明")] + [Description("部门说明")] + [DataObjectField(false, false, true, 250)] + [BindColumn("DepartmentDescription", "部门说明", "")] + public String DepartmentDescription { get => _DepartmentDescription; set { if (OnPropertyChanging(__.DepartmentDescription, value)) { _DepartmentDescription = value; OnPropertyChanged(__.DepartmentDescription); } } } + + private String _Pic; + /// 部门图片 + [DisplayName("部门图片")] + [Description("部门图片")] + [DataObjectField(false, false, true, 250)] + [BindColumn("Pic", "部门图片", "")] + public String Pic { get => _Pic; set { if (OnPropertyChanging(__.Pic, value)) { _Pic = value; OnPropertyChanged(__.Pic); } } } + + private Int32 _Rank; + /// 排序 + [DisplayName("排序")] + [Description("排序")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Rank", "排序", "")] + public Int32 Rank { get => _Rank; set { if (OnPropertyChanging(__.Rank, value)) { _Rank = value; OnPropertyChanged(__.Rank); } } } + + private Int32 _IsNotAllowDel; + /// 是否不允许删除 + [DisplayName("是否不允许删除")] + [Description("是否不允许删除")] + [DataObjectField(false, false, false, 0)] + [BindColumn("IsNotAllowDel", "是否不允许删除", "")] + public Int32 IsNotAllowDel { get => _IsNotAllowDel; set { if (OnPropertyChanging(__.IsNotAllowDel, value)) { _IsNotAllowDel = value; OnPropertyChanged(__.IsNotAllowDel); } } } + + private String _Powers; + /// 部门权限 + [DisplayName("部门权限")] + [Description("部门权限")] + [DataObjectField(false, false, true, -1)] + [BindColumn("Powers", "部门权限", "", Master = true)] + public String Powers { get => _Powers; set { if (OnPropertyChanging(__.Powers, value)) { _Powers = value; OnPropertyChanged(__.Powers); } } } + + private Int32 _IsDel; + /// 是否删除 + [DisplayName("是否删除")] + [Description("是否删除")] + [DataObjectField(false, false, false, 0)] + [BindColumn("IsDel", "是否删除", "")] + public Int32 IsDel { get => _IsDel; set { if (OnPropertyChanging(__.IsDel, value)) { _IsDel = value; OnPropertyChanged(__.IsDel); } } } + + private String _Tel; + /// 联系电话 + [DisplayName("联系电话")] + [Description("联系电话")] + [DataObjectField(false, false, true, 30)] + [BindColumn("Tel", "联系电话", "")] + public String Tel { get => _Tel; set { if (OnPropertyChanging(__.Tel, value)) { _Tel = value; OnPropertyChanged(__.Tel); } } } + + private String _Fax; + /// 传真 + [DisplayName("传真")] + [Description("传真")] + [DataObjectField(false, false, true, 30)] + [BindColumn("Fax", "传真", "")] + public String Fax { get => _Fax; set { if (OnPropertyChanging(__.Fax, value)) { _Fax = value; OnPropertyChanged(__.Fax); } } } + + private String _Email; + /// 邮件 + [DisplayName("邮件")] + [Description("邮件")] + [DataObjectField(false, false, true, 100)] + [BindColumn("Email", "邮件", "")] + public String Email { get => _Email; set { if (OnPropertyChanging(__.Email, value)) { _Email = value; OnPropertyChanged(__.Email); } } } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + public override Object this[String name] + { + get + { + switch (name) + { + case __.Id: return _Id; + case __.DepartmentName: return _DepartmentName; + case __.PId: return _PId; + case __.Level: return _Level; + case __.Location: return _Location; + case __.DepartmentDescription: return _DepartmentDescription; + case __.Pic: return _Pic; + case __.Rank: return _Rank; + case __.IsNotAllowDel: return _IsNotAllowDel; + case __.Powers: return _Powers; + case __.IsDel: return _IsDel; + case __.Tel: return _Tel; + case __.Fax: return _Fax; + case __.Email: return _Email; + default: return base[name]; + } + } + set + { + switch (name) + { + case __.Id: _Id = value.ToInt(); break; + case __.DepartmentName: _DepartmentName = Convert.ToString(value); break; + case __.PId: _PId = value.ToInt(); break; + case __.Level: _Level = value.ToInt(); break; + case __.Location: _Location = Convert.ToString(value); break; + case __.DepartmentDescription: _DepartmentDescription = Convert.ToString(value); break; + case __.Pic: _Pic = Convert.ToString(value); break; + case __.Rank: _Rank = value.ToInt(); break; + case __.IsNotAllowDel: _IsNotAllowDel = value.ToInt(); break; + case __.Powers: _Powers = Convert.ToString(value); break; + case __.IsDel: _IsDel = value.ToInt(); break; + case __.Tel: _Tel = Convert.ToString(value); break; + case __.Fax: _Fax = Convert.ToString(value); break; + case __.Email: _Email = Convert.ToString(value); break; + default: base[name] = value; break; + } + } + } + #endregion + + #region 字段名 + /// 取得部门字段信息的快捷方式 + public partial class _ + { + /// 编号 + public static readonly Field Id = FindByName(__.Id); + + /// 部门名称 + public static readonly Field DepartmentName = FindByName(__.DepartmentName); + + /// 上级部门ID + public static readonly Field PId = FindByName(__.PId); + + /// 级别 + public static readonly Field Level = FindByName(__.Level); + + /// 路径 + public static readonly Field Location = FindByName(__.Location); + + /// 部门说明 + public static readonly Field DepartmentDescription = FindByName(__.DepartmentDescription); + + /// 部门图片 + public static readonly Field Pic = FindByName(__.Pic); + + /// 排序 + public static readonly Field Rank = FindByName(__.Rank); + + /// 是否不允许删除 + public static readonly Field IsNotAllowDel = FindByName(__.IsNotAllowDel); + + /// 部门权限 + public static readonly Field Powers = FindByName(__.Powers); + + /// 是否删除 + public static readonly Field IsDel = FindByName(__.IsDel); + + /// 联系电话 + public static readonly Field Tel = FindByName(__.Tel); + + /// 传真 + public static readonly Field Fax = FindByName(__.Fax); + + /// 邮件 + public static readonly Field Email = FindByName(__.Email); + + static Field FindByName(String name) => Meta.Table.FindByName(name); + } + + /// 取得部门字段名称的快捷方式 + public partial class __ + { + /// 编号 + public const String Id = "Id"; + + /// 部门名称 + public const String DepartmentName = "DepartmentName"; + + /// 上级部门ID + public const String PId = "PId"; + + /// 级别 + public const String Level = "Level"; + + /// 路径 + public const String Location = "Location"; + + /// 部门说明 + public const String DepartmentDescription = "DepartmentDescription"; + + /// 部门图片 + public const String Pic = "Pic"; + + /// 排序 + public const String Rank = "Rank"; + + /// 是否不允许删除 + public const String IsNotAllowDel = "IsNotAllowDel"; + + /// 部门权限 + public const String Powers = "Powers"; + + /// 是否删除 + public const String IsDel = "IsDel"; + + /// 联系电话 + public const String Tel = "Tel"; + + /// 传真 + public const String Fax = "Fax"; + + /// 邮件 + public const String Email = "Email"; + } + #endregion + } + + /// 部门接口 + public partial interface IDepartment + { + #region 属性 + /// 编号 + Int32 Id { get; set; } + + /// 部门名称 + String DepartmentName { get; set; } + + /// 上级部门ID + Int32 PId { get; set; } + + /// 级别 + Int32 Level { get; set; } + + /// 路径 + String Location { get; set; } + + /// 部门说明 + String DepartmentDescription { get; set; } + + /// 部门图片 + String Pic { get; set; } + + /// 排序 + Int32 Rank { get; set; } + + /// 是否不允许删除 + Int32 IsNotAllowDel { get; set; } + + /// 部门权限 + String Powers { get; set; } + + /// 是否删除 + Int32 IsDel { get; set; } + + /// 联系电话 + String Tel { get; set; } + + /// 传真 + String Fax { get; set; } + + /// 邮件 + String Email { get; set; } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + Object this[String name] { get; set; } + #endregion + } +} \ No newline at end of file diff --git a/XCoder/XCoder(代码生成器).csproj b/XCoder/XCoder(代码生成器).csproj index 444b5b4..fc4b1b0 100644 --- a/XCoder/XCoder(代码生成器).csproj +++ b/XCoder/XCoder(代码生成器).csproj @@ -31,8 +31,8 @@ - - ..\packages\NewLife.Core.8.8.2020.701\lib\net46\NewLife.Core.dll + + ..\packages\NewLife.Core.8.8.2020.719-beta\lib\net46\NewLife.Core.dll @@ -48,8 +48,8 @@ - - ..\packages\NewLife.XCode.9.18.2020.701\lib\net45\XCode.dll + + ..\packages\NewLife.XCode.9.18.2020.719-beta\lib\net45\XCode.dll diff --git a/XCoder/packages.config b/XCoder/packages.config index e4cd516..0bf9ce0 100644 --- a/XCoder/packages.config +++ b/XCoder/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file