From 74aa0e71dbbb20b11026538628231499ce57e0a3 Mon Sep 17 00:00:00 2001 From: bug320 <1046218884@qq.com> Date: Wed, 5 Nov 2025 09:33:30 +0800 Subject: [PATCH] feat: add test for GetConfigValue --- Src/Asp.NetCore2/PgSqlTest/Program.cs | 1 + .../PgSqlTest/b10_GetConfigValueTest.cs | 139 ++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 Src/Asp.NetCore2/PgSqlTest/b10_GetConfigValueTest.cs diff --git a/Src/Asp.NetCore2/PgSqlTest/Program.cs b/Src/Asp.NetCore2/PgSqlTest/Program.cs index 095f32bdb..c605b0795 100644 --- a/Src/Asp.NetCore2/PgSqlTest/Program.cs +++ b/Src/Asp.NetCore2/PgSqlTest/Program.cs @@ -30,6 +30,7 @@ namespace OrmTest _a7_JsonType.Init(); _a8_SelectReturnType.Init(); _a9_GeometryTest.Init(); + b10_GetConfigValueTest.Init(); } } diff --git a/Src/Asp.NetCore2/PgSqlTest/b10_GetConfigValueTest.cs b/Src/Asp.NetCore2/PgSqlTest/b10_GetConfigValueTest.cs new file mode 100644 index 000000000..348aab12b --- /dev/null +++ b/Src/Asp.NetCore2/PgSqlTest/b10_GetConfigValueTest.cs @@ -0,0 +1,139 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + internal class b10_GetConfigValueTest + { + public static void Init() + { + // Get a new database instance + // 获取新的数据库实例 + var db = DbHelper.GetNewDb(); + + // Create the database if it doesn't exist + // 如果数据库不存在,则创建数据库 + db.DbMaintenance.CreateDatabase(); + + db.CodeFirst.InitTables(); + db.CodeFirst.InitTables(); + db.CodeFirst.InitTables(); + + // 清空表 + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + + // 插入数据 + // 字典类型 + db.Insertable(new SysDictType() { DictName = "系统是否", DictType = "sys_yes_no" }).ExecuteCommand();//用例代码 + + // 字典值 + db.Insertable(new SysDictData() { DictLabel = "是", DictValue = "Y", DictType = "sys_yes_no" }).ExecuteCommand();//用例代码 + db.Insertable(new SysDictData() { DictLabel = "否", DictValue = "N", DictType = "sys_yes_no" }).ExecuteCommand();//用例代码 + + + // 实体类型 + db.Insertable(new EavEntityType() { EntityTypeName = "人员", EntityTypeCode = "Human", IsActive = true }).ExecuteCommand();//用例代码 + + // 配置 + var types = db.Queryable() + .Select(it => it.DictType) + .ToList(); + + //上面有耗时操作写在Any上面,保证程序启动后只执行一次 + if (!db.ConfigQuery.Any()) + { + foreach (var type in types) + { + //db.ConfigQuery.SetTable(it => SqlFunc.ToString(it.DictValue), it => it.DictLabel, type, it => it.DictType == type); + db.ConfigQuery.SetTable(it => it.DictValue.ToString(), it => it.DictLabel, type, it => it.DictType == type); + } + } + + // 查询 + var total = 0; + var result = db.Queryable().Select((it) => new + { + it, + IsActiveLabel = (it.IsActive ? "Y" : "N").GetConfigValue("sys_yes_no"), + }, true) + .ToPageList(1, 100000, ref total); + } + } + + [SugarTable("sys_dict_type", "字典类型表")] + [SugarIndex("index_dict_type", nameof(DictType), OrderByType.Asc, true)] + public class SysDictType + { + /// + /// 字典名称 + /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] + public string DictName { get; set; } + /// + /// 字典类型 + /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] + public string DictType { get; set; } + } + [SugarTable("sys_dict_data", "字典数据表")] + public class SysDictData + { + /// + /// 字典标签 + /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] + public string DictLabel { get; set; } + /// + /// 字典键值 + /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] + public string DictValue { get; set; } + /// + /// 字典类型 + /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] + public string DictType { get; set; } + } + /// + /// 实体类型 + /// + [SugarTable("eav_entity_type")] + public class EavEntityType + { + /// + /// 主键 主键,自增ID + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "entity_type_id")] + public int? EntityTypeId { get; set; } + + /// + /// 代码 实体类型代码(如 product, user) + /// + [SugarColumn(ColumnName = "entity_type_code")] + public string EntityTypeCode { get; set; } + + /// + /// 名称 实体类型名称(如 产品, 用户)) + /// + [SugarColumn(ColumnName = "entity_type_name")] + public string EntityTypeName { get; set; } + + /// + /// 启用 是否启用该实体类型 + /// + [SugarColumn(ColumnName = "is_active")] + public bool IsActive { get; set; } + + } + public enum ProteryConstant + { + NOTNULL = 0 + } + +} \ No newline at end of file