【cfg】 支持bean类型数据的multi_rows模式,使用流式格式从多行区间读取数据

main
walon 2021-06-07 17:44:06 +08:00
parent 7e03fe7192
commit d67e232cdc
5 changed files with 35 additions and 9 deletions

View File

@ -189,6 +189,21 @@ namespace Luban.Job.Cfg.DataSources.Excel
throw new Exception($"单元薄 缺失 列:{name},请检查是否写错或者遗漏");
}
}
public ExcelStream GetMultiRowStream(string name, string sep)
{
if (Titles.TryGetValue(name, out var title))
{
var totalCells = Rows.SelectMany(r => r.GetRange(title.FromIndex, title.ToIndex - title.FromIndex + 1))
.Where(c => c.Value != null && !(c.Value is string s && string.IsNullOrWhiteSpace(s))).ToList();
return new ExcelStream(totalCells, 0, totalCells.Count - 1, sep, false);
}
else
{
throw new Exception($"单元薄 缺失 列:{name},请检查是否写错或者遗漏");
}
}
}
public Sheet(string name, bool exportTestData)

View File

@ -48,10 +48,10 @@ namespace Luban.Job.Cfg.Defs
// 对于 two key map, 需要检查 ref,但不为它生成 ref 代码.故只有map类型表才要生成代码
public bool GenRef => Ref != null && Ref.Tables.Count == 1 && Assembly.GetCfgTable(Ref.FirstTable).IsMapTable;
public bool HasRecursiveRef => (CType is TBean)
|| (CType is TArray ta && ta.ElementType is TBean)
|| (CType is TList tl && tl.ElementType is TBean)
|| (CType is TMap tm && tm.ValueType is TBean);
public bool HasRecursiveRef => (CType.IsBean)
|| (CType is TArray ta && ta.ElementType.IsBean)
|| (CType is TList tl && tl.ElementType.IsBean)
|| (CType is TMap tm && tm.ValueType.IsBean);
public string CsRefTypeName
{
@ -182,7 +182,7 @@ namespace Luban.Job.Cfg.Defs
}
}
if (IsMultiRow && !CType.IsCollection)
if (IsMultiRow && !CType.IsCollection && !CType.IsBean)
{
throw new Exception($"只有容器类型才支持 multi_line 属性");
}
@ -213,7 +213,7 @@ namespace Luban.Job.Cfg.Defs
}
}
if (!CType.IsCollection && !(CType is TBean))
if (!CType.IsCollection && !(CType.IsBean))
{
this.Ref = (RefValidator)this.Validators.FirstOrDefault(v => v is RefValidator);
}

View File

@ -120,11 +120,11 @@ namespace Luban.Job.Cfg.TypeVisitors
{
if (f.IsMultiRow)
{
list.Add(f.CType.Apply(this, row.GetSubTitleNamedRowOfMultiRows(fname), f.RawIsMultiRow, f.IsNullable));
list.Add(f.CType.Apply(this, row.GetSubTitleNamedRowOfMultiRows(fname), f.IsMultiRow, f.IsNullable));
}
else
{
list.Add(f.CType.Apply(this, row.GetSubTitleNamedRow(fname), f.RawIsMultiRow /* 肯定是 false */, f.IsNullable));
list.Add(f.CType.Apply(this, row.GetSubTitleNamedRow(fname), f.IsMultiRow /* 肯定是 false */, f.IsNullable));
}
}
catch (Exception e)
@ -144,7 +144,14 @@ namespace Luban.Job.Cfg.TypeVisitors
{
try
{
list.Add(f.CType.Apply(MultiRowExcelDataCreator.Ins, row.GetColumnOfMultiRows(f.Name, sep), f.IsNullable, (DefAssembly)bean.AssemblyBase));
if (f.CType.IsCollection)
{
list.Add(f.CType.Apply(MultiRowExcelDataCreator.Ins, row.GetColumnOfMultiRows(f.Name, sep), f.IsNullable, (DefAssembly)bean.AssemblyBase));
}
else
{
list.Add(f.CType.Apply(ExcelDataCreator.Ins, null, row.GetMultiRowStream(f.Name, sep), (DefAssembly)bean.AssemblyBase));
}
}
catch (Exception e)
{

View File

@ -23,6 +23,8 @@ namespace Luban.Job.Common.Types
public bool IsDynamic => Bean.IsAbstractType;
public override bool IsBean => true;
public override void Apply<T>(ITypeActionVisitor<T> visitor, T x)
{
visitor.Accept(this, x);

View File

@ -15,6 +15,8 @@ namespace Luban.Job.Common.Types
public virtual bool IsCollection => false;
public virtual bool IsBean => false;
public abstract void Apply<T>(ITypeActionVisitor<T> visitor, T x);
public abstract void Apply<T1, T2>(ITypeActionVisitor<T1, T2> visitor, T1 x, T2 y);
public abstract TR Apply<TR>(ITypeFuncVisitor<TR> visitor);