diff --git a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj index c1ea91dc3..a0715f854 100644 --- a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj +++ b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj @@ -103,6 +103,7 @@ + diff --git a/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs b/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs index 1428f222f..d246d9e98 100644 --- a/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs +++ b/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + Unit001.Init(); UnitPgSplit.Init(); UJsonFunc.Init(); UnitTestReturnPkList.Init(); diff --git a/Src/Asp.Net/PgSqlTest/UnitTest/Unit001.cs b/Src/Asp.Net/PgSqlTest/UnitTest/Unit001.cs new file mode 100644 index 000000000..9fcf377fd --- /dev/null +++ b/Src/Asp.Net/PgSqlTest/UnitTest/Unit001.cs @@ -0,0 +1,839 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest +{ + public class Unit001 + { + + public static void Init() + { + Get().GetAwaiter().GetResult(); + } + public static async Task Get() + { + var db = NewUnitTest.Db; + db.DbMaintenance.CreateDatabase(); + + db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings() + { + PgSqlIsAutoToLowerCodeFirst = false, + PgSqlIsAutoToLower=false + }; + + //建表 + if (!db.DbMaintenance.IsAnyTable(nameof(RoleEntity), false)) + { + db.CodeFirst.InitTables(); + } + if (!db.DbMaintenance.IsAnyTable(nameof(ManagerRoleRelationEntity), false)) + { + db.CodeFirst.InitTables(); + } + if (!db.DbMaintenance.IsAnyTable(nameof(ManagerEntity), false)) + { + db.CodeFirst.InitTables(); + } + if (!db.DbMaintenance.IsAnyTable(nameof(RoleManagerGroupRelationEntity), false)) + { + db.CodeFirst.InitTables(); + } + if (!db.DbMaintenance.IsAnyTable(nameof(ManagerManagerGroupRelationEntity), false)) + { + db.CodeFirst.InitTables(); + } + RefAsync total = 0; + + //用例代码 + var roleList = await db.Queryable() + .Where(item => item.RemoveMark == 0) + .Select(item => new GetRoleOutput() + { + RoleID = item.RoleID, + RoleName = item.RoleName, + NumberOfAssociatedAcount = SqlFunc.Subqueryable().Where(it => it.RoleID == item.RoleID).Count() + + + SqlFunc.Subqueryable() + .LeftJoin((mmgMap, manger) => manger.ManagerID == mmgMap.ManagerID && manger.EnabledMark == 1 && manger.RemoveMark == 0) + .InnerJoin((mmgMap, rmgMap) => mmgMap.ManagerGroupID == rmgMap.ManagerGroupID && rmgMap.RoleID == item.RoleID) + .Where(mmgMap => SqlFunc.Subqueryable().Where(it => it.RoleID == item.RoleID && it.ManagerID == mmgMap.ManagerID).NotAny()) + + .Select(mmgMap => SqlFunc.AggregateDistinctCount(mmgMap.ManagerID)) + , + CreateTime = item.CreateTime, + ModifyTime = item.ModifyTime, + EnabledMark = item.EnabledMark, + + } + ) + .ToPageListAsync(2, 2, total); + + + return roleList; + } + #region 用例实体 + //用例实体 + + [SugarTable("sys_manager_managergroup_relation")] + public class ManagerManagerGroupRelationEntity + { + /// + /// + /// + public ManagerManagerGroupRelationEntity() + { + } + + /// + /// + /// + [SugarColumn(IsPrimaryKey = true)] + public System.String ManagerManagerGroupRelationID { get; set; } + + /// + /// + /// + public System.String ManagerID { get; set; } + + /// + /// + /// + public System.String ManagerGroupID { get; set; } + + /// + /// + /// + public System.Int32? SortCode { get; set; } + + /// + /// + /// + public System.Int32? RemoveMark { get; set; } + + /// + /// + /// + public System.Int32? EnabledMark { get; set; } + + /// + /// + /// + public System.String Description { get; set; } + + /// + /// + /// + public System.DateTime? CreateTime { get; set; } + + /// + /// + /// + public System.String CreateUserID { get; set; } + + /// + /// + /// + public System.String CreateUserName { get; set; } + + /// + /// + /// + public System.DateTime? ModifyTime { get; set; } + + /// + /// + /// + public System.String ModifyUserID { get; set; } + + /// + /// + /// + public System.String ModifyUserName { get; set; } + + /// + /// + /// + public System.String DeleteUserID { get; set; } + + /// + /// + /// + public System.String DeleteUserName { get; set; } + + /// + /// + /// + public System.DateTime? DeleteTime { get; set; } + + + public void Create() + { + this.ManagerManagerGroupRelationID = ""; + this.CreateTime = DateTime.Now; + this.RemoveMark = 0; + this.EnabledMark = 1; + + } + } + + + [SugarTable("sys_role_managergroup_relation")] + public class RoleManagerGroupRelationEntity + { + /// + /// + /// + public RoleManagerGroupRelationEntity() + { + } + + /// + /// + /// + [SugarColumn(IsPrimaryKey = true)] + public System.String RoleManagerGroupRelationID { get; set; } + + /// + /// + /// + public System.String RoleID { get; set; } + + /// + /// + /// + public System.String ManagerGroupID { get; set; } + + /// + /// + /// + public System.Int32? SortCode { get; set; } + + /// + /// + /// + public System.Int32? RemoveMark { get; set; } + + /// + /// + /// + public System.Int32? EnabledMark { get; set; } + + /// + /// + /// + public System.String Description { get; set; } + + /// + /// + /// + public System.DateTime? CreateTime { get; set; } + + /// + /// + /// + public System.String CreateUserID { get; set; } + + /// + /// + /// + public System.String CreateUserName { get; set; } + + /// + /// + /// + public System.DateTime? ModifyTime { get; set; } + + /// + /// + /// + public System.String ModifyUserID { get; set; } + + /// + /// + /// + public System.String ModifyUserName { get; set; } + + /// + /// + /// + public System.String DeleteUserID { get; set; } + + /// + /// + /// + public System.String DeleteUserName { get; set; } + + /// + /// + /// + public System.DateTime? DeleteTime { get; set; } + } + + + [SugarTable("sys_role")] + public class RoleEntity + { + /// + /// + /// + public RoleEntity() + { + } + + [SugarColumn(IsIgnore = true)] + public int NumberOfAssociatedAcount { get; set; } + + /// + /// + /// + [SugarColumn(IsPrimaryKey = true)] + public System.String RoleID { get; set; } + + /// + /// + /// + public System.String RoleCategory { get; set; } + + /// + /// + /// + public System.String RoleName { get; set; } + + /// + /// + /// + public System.String EnCode { get; set; } + + /// + /// + /// + public System.Boolean? IsSys { get; set; } + + /// + /// + /// + public System.Int32? SortCode { get; set; } + + /// + /// + /// + public System.Int32? RemoveMark { get; set; } + + /// + /// + /// + public System.Int32? EnabledMark { get; set; } + + /// + /// + /// + public System.String Description { get; set; } + + /// + /// + /// + public System.DateTime CreateTime { get; set; } + + /// + /// + /// + public System.String CreateUserID { get; set; } + + /// + /// + /// + public System.String CreateUserName { get; set; } + + /// + /// + /// + public System.DateTime? ModifyTime { get; set; } + + /// + /// + /// + public System.String ModifyUserID { get; set; } + + /// + /// + /// + public System.String ModifyUserName { get; set; } + + /// + /// + /// + public System.String DeleteUserID { get; set; } + + /// + /// + /// + public System.String DeleteUserName { get; set; } + + /// + /// + /// + public System.DateTime? DeleteTime { get; set; } + + + + public void Create() + { + this.RoleID = ""; + this.CreateTime = DateTime.Now; + this.RemoveMark = 0; + this.EnabledMark = 1; + + } + + public void Modified() + { + this.ModifyTime = DateTime.Now; + } + + } + + [SugarTable("sys_manager_role_relation")] + public class ManagerRoleRelationEntity + { + + /// + /// + /// + [SugarColumn(IsPrimaryKey = true)] + public System.String ManagerRoleRelationID { get; set; } + + /// + /// + /// + public System.String ManagerID { get; set; } + + /// + /// + /// + public System.String RoleID { get; set; } + + /// + /// + /// + public System.Int32? SortCode { get; set; } + + /// + /// + /// + public System.Int32? RemoveMark { get; set; } + + /// + /// + /// + public System.Int32? EnabledMark { get; set; } + + /// + /// + /// + public System.String Description { get; set; } + + /// + /// + /// + public System.DateTime? CreateTime { get; set; } + + /// + /// + /// + public System.String CreateUserID { get; set; } + + /// + /// + /// + public System.String CreateUserName { get; set; } + + /// + /// + /// + public System.DateTime? ModifyTime { get; set; } + + /// + /// + /// + public System.String ModifyUserID { get; set; } + + /// + /// + /// + public System.String ModifyUserName { get; set; } + + /// + /// + /// + public System.String DeleteUserID { get; set; } + + /// + /// + /// + public System.String DeleteUserName { get; set; } + + /// + /// + /// + public System.DateTime? DeleteTime { get; set; } + } + + + [SugarTable("sys_manager")] + public class ManagerEntity + { + + [SugarColumn(IsIgnore = true)] + public List OrganizationIDs { get; set; } + + + + + + + + [SugarColumn(IsIgnore = true)] + public List Roles { get; set; } + + /// + /// + /// + public ManagerEntity() + { + } + + /// + /// + /// + [SugarColumn(IsPrimaryKey = true)] + public System.String ManagerID { get; set; } + + + /// + /// + /// + public System.String Encode { get; set; } + + /// + /// + /// + public System.String Account { get; set; } + + /// + /// + /// + public System.String Password { get; set; } + + /// + /// + /// + public System.String SecretKey { get; set; } + + /// + /// + /// + public System.String RealName { get; set; } + + /// + /// + /// + public System.String NickName { get; set; } + + /// + /// + /// + public System.Int32 LoginCount { get; set; } + + /// + /// + /// + public System.String AvatarImage { get; set; } + + /// + /// + /// + public System.String QuickQuery { get; set; } + + /// + /// + /// + public System.String SimpleSpelling { get; set; } + + /// + /// + /// + public System.String Gender { get; set; } + + /// + /// + /// + public System.Boolean? IsSys { get; set; } + + /// + /// + /// + public System.DateTime? Birthday { get; set; } + + /// + /// + /// + public System.String Mobile { get; set; } + + /// + /// + /// + public System.String Telephone { get; set; } + + /// + /// + /// + public System.String Email { get; set; } + + /// + /// + /// + public System.String OICQNO { get; set; } + + /// + /// + /// + public System.String WeChat { get; set; } + + /// + /// + /// + public System.String MSN { get; set; } + + /// + /// + /// + public System.Int32? SecurityLevel { get; set; } + + /// + /// + /// + public System.String OpenID { get; set; } + + /// + /// + /// + public System.String Question { get; set; } + + /// + /// + /// + public System.String AnswerQuestion { get; set; } + + /// + /// + /// + public System.Int32? CheckOnLine { get; set; } + + /// + /// + /// + public System.DateTime? AllowStartTime { get; set; } + + /// + /// + /// + public System.DateTime? AllowEndTime { get; set; } + + /// + /// + /// + public System.DateTime? LockStartDate { get; set; } + + /// + /// + /// + public System.DateTime? LockEndDate { get; set; } + + /// + /// + /// + public System.DateTime? LastLoginTime { get; set; } + + /// + /// + /// + public System.Int32? SortCode { get; set; } + + /// + /// + /// + public System.Int32? EnabledMark { get; set; } + + /// + /// + /// + public System.String Description { get; set; } + + /// + /// + /// + public System.DateTime CreateTime { get; set; } + + /// + /// + /// + public System.String CreateUserID { get; set; } + + /// + /// + /// + public System.String CreateUserName { get; set; } + + /// + /// + /// + public System.DateTime? ModifyTime { get; set; } + + /// + /// + /// + public System.String ModifyUserID { get; set; } + + /// + /// + /// + public System.String ModifyUserName { get; set; } + + /// + /// + /// + public System.String DeleteUserID { get; set; } + + /// + /// + /// + public System.String DeleteUserName { get; set; } + + /// + /// + /// + public System.DateTime? DeleteTime { get; set; } + + /// + /// + /// + public System.Int32? RemoveMark { get; set; } + + public void Create() + { + this.ManagerID = ""; + this.CreateTime = DateTime.Now; + this.RemoveMark = 0; + //this.EnabledMark = 1; + + } + + + public void Modify(string id) + { + this.ManagerID = id; + this.ModifyTime = DateTime.Now; + this.QuickQuery = this.RealName ?? ""; + this.SimpleSpelling = this.RealName; + this.SortCode = this.SortCode ?? 99; + this.RemoveMark = 0; + //this.EnabledMark = 1; + this.IsSys = false; + this.LockEndDate = DateTime.Now; + this.DeleteTime = DateTime.MinValue; + } + } + + + + #region DTO + //DTO + public class GetRoleOutput + { + + public int NumberOfAssociatedAcount { get; set; } + + public string RoleID { get; set; } + + + /// + /// + /// + public string RoleName { get; set; } + + /// + /// + /// + public string Encode { get; set; } + + /// + /// + /// + public bool? IsSys { get; set; } + + /// + /// + /// + public int? SortCode { get; set; } + + /// + /// + /// + public int? RemoveMark { get; set; } + + /// + /// + /// + public int? EnabledMark { get; set; } + + /// + /// + /// + public string Description { get; set; } + + /// + /// + /// + public DateTime? CreateTime { get; set; } + public DateTime? ModifyTime { get; set; } + + /// + /// + /// + public string CreateUserName { get; set; } + + public List GetRoleNavigationList { get; set; } + } + + + + public class GetRoleNavigationModel + { + /// + /// 导航栏ID + /// + public string NavigationID { get; set; } + public string RoleNavigationRelationID { get; set; } + + public List GetRoleFunctionPermissionList { get; set; } + + } + + public class GetRoleFunctionPermissionModel + { + + public string FunctionAuthID { get; set; } + + + } + + #endregion + + #endregion + } + + +}