From d67e232cdc8b7fdd152fb8b540eb411b212c60ed Mon Sep 17 00:00:00 2001 From: walon Date: Mon, 7 Jun 2021 17:44:06 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90cfg=E3=80=91=20=E6=94=AF=E6=8C=81bean?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=95=B0=E6=8D=AE=E7=9A=84multi=5Frows?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=B5=81=E5=BC=8F?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BB=8E=E5=A4=9A=E8=A1=8C=E5=8C=BA=E9=97=B4?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataSources/Excel/Sheet.cs | 15 +++++++++++++++ src/Luban.Job.Cfg/Source/Defs/DefField.cs | 12 ++++++------ .../TypeVisitors/ExcelNamedRowDataCreator.cs | 13 ++++++++++--- src/Luban.Job.Common/Source/Types/TBean.cs | 2 ++ src/Luban.Job.Common/Source/Types/TType.cs | 2 ++ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs index d4864bc..a5e11b3 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs @@ -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) diff --git a/src/Luban.Job.Cfg/Source/Defs/DefField.cs b/src/Luban.Job.Cfg/Source/Defs/DefField.cs index 1dcc819..7ebda3a 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefField.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefField.cs @@ -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); } diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/ExcelNamedRowDataCreator.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/ExcelNamedRowDataCreator.cs index da12db2..af43673 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/ExcelNamedRowDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/ExcelNamedRowDataCreator.cs @@ -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) { diff --git a/src/Luban.Job.Common/Source/Types/TBean.cs b/src/Luban.Job.Common/Source/Types/TBean.cs index db5b305..de09636 100644 --- a/src/Luban.Job.Common/Source/Types/TBean.cs +++ b/src/Luban.Job.Common/Source/Types/TBean.cs @@ -23,6 +23,8 @@ namespace Luban.Job.Common.Types public bool IsDynamic => Bean.IsAbstractType; + public override bool IsBean => true; + public override void Apply(ITypeActionVisitor visitor, T x) { visitor.Accept(this, x); diff --git a/src/Luban.Job.Common/Source/Types/TType.cs b/src/Luban.Job.Common/Source/Types/TType.cs index 2a76e85..98874d7 100644 --- a/src/Luban.Job.Common/Source/Types/TType.cs +++ b/src/Luban.Job.Common/Source/Types/TType.cs @@ -15,6 +15,8 @@ namespace Luban.Job.Common.Types public virtual bool IsCollection => false; + public virtual bool IsBean => false; + public abstract void Apply(ITypeActionVisitor visitor, T x); public abstract void Apply(ITypeActionVisitor visitor, T1 x, T2 y); public abstract TR Apply(ITypeFuncVisitor visitor);