Skip to content

Commit

Permalink
代码生成加强对数据分区字段的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jul 30, 2024
1 parent e764720 commit 07b527e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion XCode/Attributes/BindColumnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public sealed class BindColumnAttribute : Attribute
/// <summary>是否主字段。主字段作为业务主要字段,代表当前数据行意义</summary>
public Boolean Master { get; set; }

/// <summary>数据规模。time表示这是大数据单表的数据时间字段,shard:yyMMdd表示这是大数据多表的分表字段</summary>
/// <summary>数据规模。time表示这是大数据单表的数据时间字段,timeShard:yyMMdd表示这是大数据多表的分表字段</summary>
public String? DataScale { get; set; }
#endregion

Expand Down
2 changes: 1 addition & 1 deletion XCode/Cache/DbCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public override Boolean Set<T>(String key, T value, Int32 expire = -1)
e.Value = value!.ToJson();
e.ExpiredTime = TimerX.Now.AddSeconds(expire);

if (e.CreateTime.Year < 2000) e.CreateTime = TimerX.Now;
if (e.CreateTime.Year < 1000) e.CreateTime = TimerX.Now;
e.SaveAsync();

return true;
Expand Down
33 changes: 27 additions & 6 deletions XCode/Code/EntityBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,17 @@ protected virtual void BuildExtendSearch()
}
}

// 时间数据字段,生成查询
foreach (var dc in Table.Columns)
{
if (dc.PrimaryKey || dc.Identity) continue;

if (dc.DataScale.StartsWithIgnoreCase("time"))
{
if (BuildExtendFindAll([dc], methods)) methods++;
}
}

WriteLine("#endregion");
}

Expand Down Expand Up @@ -1658,8 +1669,8 @@ protected virtual Boolean BuildExtendFind(IDataColumn[] columns, Int32 index)
else
WriteLine("if ({0}.IsNullOrEmpty()) return null;", dc.CamelName());
}
else if (dc.DataType == typeof(DateTime) && dc.ItemType.EqualIgnoreCase("date"))
WriteLine("if ({0}.Year < 2000) return null;", dc.CamelName());
else if (dc.DataType == typeof(DateTime) && IsDataTime(dc))
WriteLine("if ({0}.Year < 1000) return null;", dc.CamelName());

header |= CanSearch(dc);
}
Expand Down Expand Up @@ -1759,8 +1770,8 @@ protected virtual Boolean BuildExtendFindAll(IDataColumn[] columns, Int32 index)
else
WriteLine("if ({0}.IsNullOrEmpty()) return [];", dc.CamelName(), ClassName);
}
else if (dc.DataType == typeof(DateTime) && dc.ItemType.EqualIgnoreCase("date"))
WriteLine("if ({0}.Year < 2000) return [];", dc.CamelName());
else if (dc.DataType == typeof(DateTime) && IsDataTime(dc))
WriteLine("if ({0}.Year < 1000) return [];", dc.CamelName());

header |= CanSearch(dc);
}
Expand Down Expand Up @@ -2025,7 +2036,7 @@ protected virtual void BuildBusiness()
#endregion 业务类

#region 辅助
/// <summary>该列是否能够搜索。整型、字符串以及日期类型可以搜索</summary>
/// <summary>该列是否能够搜索。整型、字符串以及时间日期类型可以搜索</summary>
/// <param name="column"></param>
/// <returns></returns>
private Boolean CanSearch(IDataColumn column)
Expand All @@ -2034,7 +2045,17 @@ private Boolean CanSearch(IDataColumn column)

if (column.DataType.IsInt()) return true;
if (column.DataType == typeof(String)) return true;
if (column.DataType == typeof(DateTime) && column.ItemType.EqualIgnoreCase("date")) return true;
if (column.DataType == typeof(DateTime) && IsDataTime(column)) return true;

return false;
}

/// <summary>是否数据时间字段</summary>
/// <param name="column"></param>
/// <returns></returns>
private Boolean IsDataTime(IDataColumn column)
{
if (column.DataType == typeof(DateTime) && (column.ItemType.EqualIgnoreCase("date") || column.DataScale.StartsWithIgnoreCase("time"))) return true;

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion XCode/DataAccessLayer/Model/IDataColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface IDataColumn
/// <summary>允许空</summary>
Boolean Nullable { get; set; }

/// <summary>数据规模。time表示这是大数据单表的数据时间字段,shard:yyMMdd表示这是大数据多表的分表字段</summary>
/// <summary>数据规模。time表示这是大数据单表的数据时间字段,timeShard:yyMMdd表示这是大数据多表的分表字段</summary>
String? DataScale { get; set; }

/// <summary>默认值</summary>
Expand Down
4 changes: 2 additions & 2 deletions XCode/DataAccessLayer/Model/XField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ class XField : SerializableDataMember, IDataColumn, ICloneable
[Description("允许空")]
public Boolean Nullable { get; set; }

/// <summary>数据规模。time表示这是大数据单表的数据时间字段,shard:yyMMdd表示这是大数据多表的分表字段</summary>
/// <summary>数据规模。time表示这是大数据单表的数据时间字段,timeShard:yyMMdd表示这是大数据多表的分表字段</summary>
[XmlAttribute]
[DisplayName("数据规模")]
[Description("数据规模。time表示这是大数据单表的数据时间字段,shard:yyMMdd表示这是大数据多表的分表字段")]
[Description("数据规模。time表示这是大数据单表的数据时间字段,timeShard:yyMMdd表示这是大数据多表的分表字段")]
public String? DataScale { get; set; }

/// <summary>默认值</summary>
Expand Down
2 changes: 1 addition & 1 deletion XCode/ModelSchema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
<xs:attribute name="DataScale" type="xs:string">
<xs:annotation>
<xs:documentation xml:lang="zh-cn">
数据规模。time表示这是大数据单表的数据时间字段,shard:yyMMdd表示这是大数据多表的分表字段
数据规模。time表示这是大数据单表的数据时间字段,timeShard:yyMMdd表示这是大数据多表的分表字段
</xs:documentation>
</xs:annotation>
</xs:attribute>
Expand Down
4 changes: 2 additions & 2 deletions XCode/Transform/TimeExtracter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public virtual IEnumerable<DbTable> Fetch()
var name = db.FormatName(field);

// 第一次查询,不带时间条件,目的是为了找到第一个时间
if (StartTime.Year < 2000)
if (StartTime.Year < 1000)
{
// 查询数据
var sb = Builder.Clone();
Expand All @@ -75,7 +75,7 @@ public virtual IEnumerable<DbTable> Fetch()

StartTime = dt.Get<DateTime>(0, field.ColumnName);

if (StartTime.Year < 2000) yield break;
if (StartTime.Year < 1000) yield break;
}

// 时间步进,分页查询
Expand Down

0 comments on commit 07b527e

Please sign in to comment.