【特性】新增 sort_data_list 模板函数,对记录排序
parent
48f7ffe0b9
commit
47e950be6f
Binary file not shown.
|
After Width: | Height: | Size: 183 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 215 KiB |
|
|
@ -43,7 +43,7 @@ namespace Luban.ClientServer
|
|||
Console.WriteLine("ERRORS:");
|
||||
Console.WriteLine("\t" + err);
|
||||
Console.WriteLine(@"
|
||||
Luban.Client <Options>... [-- [job options]]
|
||||
Luban.ClientServer <Options>... [-- [job options]]
|
||||
e.g.
|
||||
Luban.ClientServer -j cfg -- --name abc
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ namespace Luban.Job.Cfg.Datas
|
|||
throw new System.NotSupportedException();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Apply<T>(IDataActionVisitor<T> visitor, T x)
|
||||
{
|
||||
visitor.Accept(this, x);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ namespace Luban.Job.Cfg.Datas
|
|||
throw new System.NotSupportedException();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
|
||||
public DType GetField(string fieldName)
|
||||
{
|
||||
if (ImplType.TryGetField(fieldName, out var _, out var findex))
|
||||
|
|
|
|||
|
|
@ -48,5 +48,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DBool d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,5 +53,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DByte d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,15 @@ namespace Luban.Job.Cfg.Datas
|
|||
return _localTime.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DDateTime d)
|
||||
{
|
||||
return this._localTime.CompareTo(d._localTime);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
|
||||
public string ToFormatString()
|
||||
{
|
||||
return DataUtil.FormatDateTime(Time);
|
||||
|
|
|
|||
|
|
@ -46,5 +46,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DDouble d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,5 +56,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DEnum d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,5 +52,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DFint d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,5 +50,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DFloat d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,5 +46,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DFlong d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,15 @@ namespace Luban.Job.Cfg.Datas
|
|||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DFshort d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Apply<T>(IDataActionVisitor<T> visitor, T x)
|
||||
{
|
||||
visitor.Accept(this, x);
|
||||
|
|
|
|||
|
|
@ -67,5 +67,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DInt d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,5 +60,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DLong d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,5 +46,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DShort d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,5 +50,14 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
public override int CompareTo(DType other)
|
||||
{
|
||||
if (other is DString d)
|
||||
{
|
||||
return this.Value.CompareTo(d.Value);
|
||||
}
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using Luban.Job.Cfg.DataVisitors;
|
|||
|
||||
namespace Luban.Job.Cfg.Datas
|
||||
{
|
||||
public abstract class DType
|
||||
public abstract class DType : System.IComparable<DType>
|
||||
{
|
||||
public abstract void Apply<T>(IDataActionVisitor<T> visitor, T x);
|
||||
|
||||
|
|
@ -19,6 +19,11 @@ namespace Luban.Job.Cfg.Datas
|
|||
{
|
||||
return this.Apply(ToStringVisitor.Ins);
|
||||
}
|
||||
|
||||
public virtual int CompareTo(DType other)
|
||||
{
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class DType<T> : DType
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace Luban.Job.Cfg
|
|||
public static string RenderData(this Template template, DefTable table, List<DBean> exportDatas, Dictionary<string, object> extraModels = null)
|
||||
{
|
||||
var ctx = new TemplateContext();
|
||||
|
||||
var env = new DTypeTemplateExtends
|
||||
{
|
||||
["table"] = table,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Luban.Job.Cfg.Datas;
|
||||
using Luban.Job.Cfg.DataVisitors;
|
||||
using Luban.Job.Cfg.Defs;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Luban.Job.Cfg.Utils
|
||||
{
|
||||
|
|
@ -66,5 +67,22 @@ namespace Luban.Job.Cfg.Utils
|
|||
{
|
||||
return type.Apply(ToErlangLiteralVisitor.Ins);
|
||||
}
|
||||
|
||||
public static List<DBean> SortDataList(List<DBean> datas, string indexName, bool asce)
|
||||
{
|
||||
var sortedDatas = new List<DBean>(datas);
|
||||
if (sortedDatas.Count > 1)
|
||||
{
|
||||
if (asce)
|
||||
{
|
||||
sortedDatas.Sort((a, b) => a.GetField(indexName).CompareTo(b.GetField(indexName)));
|
||||
}
|
||||
else
|
||||
{
|
||||
sortedDatas.Sort((a, b) => -a.GetField(indexName).CompareTo(b.GetField(indexName)));
|
||||
}
|
||||
}
|
||||
return sortedDatas;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue