Skip to content

Commit

Permalink
代码生成时,枚举也支持使用0,默认值使用-1
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jan 13, 2025
1 parent 3a22fd6 commit 858b8d8
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 51 deletions.
6 changes: 3 additions & 3 deletions XCode/Code/EntityBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ protected virtual Boolean BuildExtendFind(IDataColumn[] columns, Int32 index)
foreach (var dc in columns)
{
if (dc.DataType != null && dc.DataType.IsInt())
WriteLine("if ({0} < 0) return null;", dc.CamelName());
WriteLine("if ({0} <= 0) return null;", dc.CamelName());
else if (dc.DataType == typeof(String))
{
if (nullable && dc.Nullable)
Expand Down Expand Up @@ -1787,7 +1787,7 @@ protected virtual Boolean BuildExtendFindAll(IDataColumn[] columns, Int32 index)
foreach (var dc in columns)
{
if (dc.DataType != null && dc.DataType.IsInt())
WriteLine("if ({0} < 0) return [];", dc.CamelName(), ClassName);
WriteLine("if ({0} <= 0) return [];", dc.CamelName(), ClassName);
else if (dc.DataType == typeof(String))
{
if (Option.Nullable && dc.Nullable)
Expand Down Expand Up @@ -1950,7 +1950,7 @@ protected virtual IList<IDataColumn> BuildAdvanceSearch()
foreach (var dc in cs)
{
if (dc.DataType.IsInt() && (dc.DataType.IsEnum || !dc.Properties["Type"].IsNullOrEmpty()))
WriteLine("if ({0} > 0) exp &= _.{1} == {0};", dc.CamelName(), dc.Name);
WriteLine("if ({0} >= 0) exp &= _.{1} == {0};", dc.CamelName(), dc.Name);
else if (dc.DataType.IsInt())
WriteLine("if ({0} >= 0) exp &= _.{1} == {0};", dc.CamelName(), dc.Name);
else if (dc.DataType == typeof(Boolean))
Expand Down
4 changes: 2 additions & 2 deletions XCodeTool/CubeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ private String BuildSearch()
if (dc.DataType.IsInt())
{
if (dc.DataType.IsEnum)
sb.AppendLine($" var {name} = ({dc.DataType.FullName})p[\"{name}\"].ToInt();");
sb.AppendLine($" var {name} = ({dc.DataType.FullName})p[\"{name}\"].ToInt(-1);");
else if (!dc.Properties["Type"].IsNullOrEmpty())
sb.AppendLine($" var {name} = ({dc.Properties["Type"]})p[\"{name}\"].ToInt();");
sb.AppendLine($" var {name} = ({dc.Properties["Type"]})p[\"{name}\"].ToInt(-1);");
else if (dc.DataType == typeof(Int64))
sb.AppendLine($" var {name} = p[\"{name}\"].ToLong(-1);");
else
Expand Down
2 changes: 1 addition & 1 deletion XUnitTest.XCode/Code/Controllers/controller_parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override IEnumerable<Parameter> Search(Pager p)
var userId = p["userId"].ToInt(-1);
var category = p["category"];
var name = p["name"];
var kind = (XCode.Membership.ParameterKinds)p["kind"].ToInt();
var kind = (XCode.Membership.ParameterKinds)p["kind"].ToInt(-1);
var enable = p["enable"]?.ToBoolean();

var start = p["dtStart"].ToDateTime();
Expand Down
2 changes: 1 addition & 1 deletion XUnitTest.XCode/Code/Controllers/controller_user.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override IEnumerable<User> Search(Pager p)
var code = p["code"];
var roleId = p["roleId"].ToInt(-1);
var departmentId = p["departmentId"].ToInt(-1);
var sex = (XCode.Membership.SexKinds)p["sex"].ToInt();
var sex = (XCode.Membership.SexKinds)p["sex"].ToInt(-1);
var mailVerified = p["mailVerified"]?.ToBoolean();
var mobileVerified = p["mobileVerified"]?.ToBoolean();
var areaId = p["areaId"].ToInt(-1);
Expand Down
4 changes: 2 additions & 2 deletions XUnitTest.XCode/Code/Entity/地区.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Area? FindByID(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.ID == id);
Expand All @@ -282,7 +282,7 @@ public override Object? this[String name]
/// <returns>实体列表</returns>
public static IList<Area> FindAllByParentID(Int32 parentId)
{
if (parentId < 0) return [];
if (parentId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.ParentID == parentId);
Expand Down
2 changes: 1 addition & 1 deletion XUnitTest.XCode/Code/Entity/字典参数.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static IList<Parameter> Search(Int32 userId, String? category, String? na
if (userId >= 0) exp &= _.UserID == userId;
if (!category.IsNullOrEmpty()) exp &= _.Category == category;
if (!name.IsNullOrEmpty()) exp &= _.Name == name;
if (kind > 0) exp &= _.Kind == kind;
if (kind >= 0) exp &= _.Kind == kind;
if (enable != null) exp &= _.Enable == enable;
exp &= _.UpdateTime.Between(start, end);
if (!key.IsNullOrEmpty()) exp &= SearchWhereByKeys(key);
Expand Down
8 changes: 4 additions & 4 deletions XUnitTest.XCode/Code/Entity/字典参数.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Parameter? FindByID(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.ID == id);
Expand All @@ -356,7 +356,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Parameter? FindByUserIDAndCategoryAndName(Int32 userId, String? category, String? name)
{
if (userId < 0) return null;
if (userId <= 0) return null;
if (category == null) return null;
if (name == null) return null;

Expand All @@ -371,7 +371,7 @@ public override Object? this[String name]
/// <returns>实体列表</returns>
public static IList<Parameter> FindAllByUserID(Int32 userId)
{
if (userId < 0) return [];
if (userId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.UserID == userId);
Expand All @@ -385,7 +385,7 @@ public static IList<Parameter> FindAllByUserID(Int32 userId)
/// <returns>实体列表</returns>
public static IList<Parameter> FindAllByUserIDAndCategory(Int32 userId, String? category)
{
if (userId < 0) return [];
if (userId <= 0) return [];
if (category == null) return [];

// 实体缓存
Expand Down
6 changes: 3 additions & 3 deletions XUnitTest.XCode/Code/Entity/成员日志.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static MemberLog? FindByID(Int64 id)
{
if (id < 0) return null;
if (id <= 0) return null;

return Find(_.ID == id);
}
Expand All @@ -313,7 +313,7 @@ public static IList<MemberLog> FindAllByActionAndCategory(String? action, String
public static IList<MemberLog> FindAllByCategoryAndLinkID(String? category, Int32 linkId)
{
if (category == null) return [];
if (linkId < 0) return [];
if (linkId <= 0) return [];

return FindAll(_.Category == category & _.LinkID == linkId);
}
Expand All @@ -323,7 +323,7 @@ public static IList<MemberLog> FindAllByCategoryAndLinkID(String? category, Int3
/// <returns>实体列表</returns>
public static IList<MemberLog> FindAllByCreateUserID(Int32 createUserId)
{
if (createUserId < 0) return [];
if (createUserId <= 0) return [];

return FindAll(_.CreateUserID == createUserId);
}
Expand Down
6 changes: 3 additions & 3 deletions XUnitTest.XCode/Code/Entity/日志.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Log? FindByID(Int64 id)
{
if (id < 0) return null;
if (id <= 0) return null;

return Find(_.ID == id);
}
Expand All @@ -304,7 +304,7 @@ public static IList<Log> FindAllByActionAndCategory(String? action, String? cate
public static IList<Log> FindAllByCategoryAndLinkID(String? category, Int32 linkId)
{
if (category == null) return [];
if (linkId < 0) return [];
if (linkId <= 0) return [];

return FindAll(_.Category == category & _.LinkID == linkId);
}
Expand All @@ -314,7 +314,7 @@ public static IList<Log> FindAllByCategoryAndLinkID(String? category, Int32 link
/// <returns>实体列表</returns>
public static IList<Log> FindAllByCreateUserID(Int32 createUserId)
{
if (createUserId < 0) return [];
if (createUserId <= 0) return [];

return FindAll(_.CreateUserID == createUserId);
}
Expand Down
2 changes: 1 addition & 1 deletion XUnitTest.XCode/Code/Entity/用户.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static IList<User> Search(String name, String? mail, String? mobile, Stri
if (!mobile.IsNullOrEmpty()) exp &= _.Mobile == mobile;
if (!code.IsNullOrEmpty()) exp &= _.Code == code;
if (roleId >= 0) exp &= _.RoleID == roleId;
if (sex > 0) exp &= _.Sex == sex;
if (sex >= 0) exp &= _.Sex == sex;
if (areaId >= 0) exp &= _.AreaId == areaId;
if (online != null) exp &= _.Online == online;
if (enable != null) exp &= _.Enable == enable;
Expand Down
4 changes: 2 additions & 2 deletions XUnitTest.XCode/Code/Entity/用户.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static User? FindByID(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.ID == id);
Expand Down Expand Up @@ -546,7 +546,7 @@ public static IList<User> FindAllByCode(String? code)
/// <returns>实体列表</returns>
public static IList<User> FindAllByRoleID(Int32 roleId)
{
if (roleId < 0) return [];
if (roleId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.RoleID == roleId);
Expand Down
6 changes: 3 additions & 3 deletions XUnitTest.XCode/Code/Entity/用户日志.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static UserLog? FindByID(Int64 id)
{
if (id < 0) return null;
if (id <= 0) return null;

return Find(_.ID == id);
}
Expand All @@ -315,7 +315,7 @@ public static IList<UserLog> FindAllByActionAndCategory(String? action, String?
public static IList<UserLog> FindAllByCategoryAndLinkID(String? category, Int32 linkId)
{
if (category == null) return [];
if (linkId < 0) return [];
if (linkId <= 0) return [];

return FindAll(_.Category == category & _.LinkID == linkId);
}
Expand All @@ -325,7 +325,7 @@ public static IList<UserLog> FindAllByCategoryAndLinkID(String? category, Int32
/// <returns>实体列表</returns>
public static IList<UserLog> FindAllByCreateUserID(Int32 createUserId)
{
if (createUserId < 0) return [];
if (createUserId <= 0) return [];

return FindAll(_.CreateUserID == createUserId);
}
Expand Down
2 changes: 1 addition & 1 deletion XUnitTest.XCode/Code/Entity/租户.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Tenant? FindById(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id);
Expand Down
10 changes: 5 additions & 5 deletions XUnitTest.XCode/Code/Entity/租户关系.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static TenantUser? FindById(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id);
Expand All @@ -246,8 +246,8 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static TenantUser? FindByTenantIdAndUserId(Int32 tenantId, Int32 userId)
{
if (tenantId < 0) return null;
if (userId < 0) return null;
if (tenantId <= 0) return null;
if (userId <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.TenantId == tenantId && e.UserId == userId);
Expand All @@ -260,7 +260,7 @@ public override Object? this[String name]
/// <returns>实体列表</returns>
public static IList<TenantUser> FindAllByTenantId(Int32 tenantId)
{
if (tenantId < 0) return [];
if (tenantId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.TenantId == tenantId);
Expand All @@ -273,7 +273,7 @@ public static IList<TenantUser> FindAllByTenantId(Int32 tenantId)
/// <returns>实体列表</returns>
public static IList<TenantUser> FindAllByUserId(Int32 userId)
{
if (userId < 0) return [];
if (userId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.UserId == userId);
Expand Down
6 changes: 3 additions & 3 deletions XUnitTest.XCode/Code/Entity/菜单.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Menu? FindByID(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.ID == id);
Expand Down Expand Up @@ -403,7 +403,7 @@ public static IList<Menu> FindAllByName(String name)
/// <returns>实体对象</returns>
public static Menu? FindByParentIDAndName(Int32 parentId, String name)
{
if (parentId < 0) return null;
if (parentId <= 0) return null;
if (name.IsNullOrEmpty()) return null;

// 实体缓存
Expand All @@ -417,7 +417,7 @@ public static IList<Menu> FindAllByName(String name)
/// <returns>实体列表</returns>
public static IList<Menu> FindAllByParentID(Int32 parentId)
{
if (parentId < 0) return [];
if (parentId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.ParentID == parentId);
Expand Down
2 changes: 1 addition & 1 deletion XUnitTest.XCode/Code/Entity/角色.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Role? FindByID(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.ID == id);
Expand Down
6 changes: 3 additions & 3 deletions XUnitTest.XCode/Code/Entity/部门.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Department? FindByID(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.ID == id);
Expand Down Expand Up @@ -411,7 +411,7 @@ public static IList<Department> FindAllByName(String name)
/// <returns>实体列表</returns>
public static IList<Department> FindAllByParentIDAndName(Int32 parentId, String name)
{
if (parentId < 0) return [];
if (parentId <= 0) return [];
if (name.IsNullOrEmpty()) return [];

// 实体缓存
Expand All @@ -438,7 +438,7 @@ public static IList<Department> FindAllByCode(String? code)
/// <returns>实体列表</returns>
public static IList<Department> FindAllByTenantId(Int32 tenantId)
{
if (tenantId < 0) return [];
if (tenantId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.TenantId == tenantId);
Expand Down
6 changes: 3 additions & 3 deletions XUnitTest.XCode/Code/entity_log_normal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static Log? FindByID(Int64 id)
{
if (id < 0) return null;
if (id <= 0) return null;

return Find(_.ID == id);
}
Expand All @@ -272,7 +272,7 @@ public static IList<Log> FindAllByActionAndCategory(String action, String? categ
public static IList<Log> FindAllByCategoryAndLinkID(String? category, Int64 linkId)
{
if (category == null) return [];
if (linkId < 0) return [];
if (linkId <= 0) return [];

return FindAll(_.Category == category & _.LinkID == linkId);
}
Expand All @@ -282,7 +282,7 @@ public static IList<Log> FindAllByCategoryAndLinkID(String? category, Int64 link
/// <returns>实体列表</returns>
public static IList<Log> FindAllByCreateUserID(Int32 createUserId)
{
if (createUserId < 0) return [];
if (createUserId <= 0) return [];

return FindAll(_.CreateUserID == createUserId);
}
Expand Down
6 changes: 3 additions & 3 deletions XUnitTest.XCode/Code/entity_user_normal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public override Object? this[String name]
/// <returns>实体对象</returns>
public static User? FindByID(Int32 id)
{
if (id < 0) return null;
if (id <= 0) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.ID == id);
Expand Down Expand Up @@ -539,7 +539,7 @@ public static IList<User> FindAllByCode(String? code)
/// <returns>实体列表</returns>
public static IList<User> FindAllByRoleID(Int32 roleId)
{
if (roleId < 0) return [];
if (roleId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.RoleID == roleId);
Expand All @@ -552,7 +552,7 @@ public static IList<User> FindAllByRoleID(Int32 roleId)
/// <returns>实体列表</returns>
public static IList<User> FindAllByDepartmentID(Int32 departmentId)
{
if (departmentId < 0) return [];
if (departmentId <= 0) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.DepartmentID == departmentId);
Expand Down
Loading

0 comments on commit 858b8d8

Please sign in to comment.