[new]支持$type + 流式$value的填写方式 (#29)
[new]支持$type + 流式$value的填写方式 Co-authored-by: Tianbao Lin <kteong1012@outlook.com>main
parent
165ad69a5d
commit
bcc7bc8b37
|
|
@ -450,6 +450,7 @@ namespace Luban.Job.Cfg.DataCreators
|
||||||
}
|
}
|
||||||
else if (row.Fields != null)
|
else if (row.Fields != null)
|
||||||
{
|
{
|
||||||
|
sep += type.GetBeanAs<DefBean>().Sep;
|
||||||
var originBean = (DefBean)type.Bean;
|
var originBean = (DefBean)type.Bean;
|
||||||
if (originBean.IsAbstractType)
|
if (originBean.IsAbstractType)
|
||||||
{
|
{
|
||||||
|
|
@ -458,7 +459,7 @@ namespace Luban.Job.Cfg.DataCreators
|
||||||
{
|
{
|
||||||
throw new Exception($"type:'{originBean.FullName}' 是多态类型,需要定义'{DefBean.EXCEL_TYPE_NAME_KEY}'列来指定具体子类型");
|
throw new Exception($"type:'{originBean.FullName}' 是多态类型,需要定义'{DefBean.EXCEL_TYPE_NAME_KEY}'列来指定具体子类型");
|
||||||
}
|
}
|
||||||
|
TitleRow valueTitle = row.GetSubTitleNamedRow(DefBean.EXCEL_VALUE_NAME_KEY);
|
||||||
string subType = typeTitle.Current?.ToString()?.Trim();
|
string subType = typeTitle.Current?.ToString()?.Trim();
|
||||||
if (subType == null || subType == DefBean.BEAN_NULL_STR)
|
if (subType == null || subType == DefBean.BEAN_NULL_STR)
|
||||||
{
|
{
|
||||||
|
|
@ -469,9 +470,37 @@ namespace Luban.Job.Cfg.DataCreators
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
DefBean implType = DataUtil.GetImplTypeByNameOrAlias(originBean, subType);
|
DefBean implType = DataUtil.GetImplTypeByNameOrAlias(originBean, subType);
|
||||||
|
if (valueTitle == null)
|
||||||
|
{
|
||||||
return new DBean(type, implType, CreateBeanFields(implType, sheet, row));
|
return new DBean(type, implType, CreateBeanFields(implType, sheet, row));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (valueTitle.Row != null)
|
||||||
|
{
|
||||||
|
var s = valueTitle.AsStream(sep);
|
||||||
|
if (type.IsNullable && s.TryReadEOF())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new DBean(type, implType, CreateBeanFields(implType, s));
|
||||||
|
}
|
||||||
|
else if (valueTitle.Rows != null)
|
||||||
|
{
|
||||||
|
var s = valueTitle.AsMultiRowConcatStream(sep);
|
||||||
|
if (type.IsNullable && s.TryReadEOF())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new DBean(type, implType, CreateBeanFields(implType, s));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (type.IsNullable)
|
if (type.IsNullable)
|
||||||
{
|
{
|
||||||
|
|
@ -646,5 +675,29 @@ namespace Luban.Job.Cfg.DataCreators
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<DType> CreateBeanFields(DefBean bean, ExcelStream stream)
|
||||||
|
{
|
||||||
|
var list = new List<DType>();
|
||||||
|
foreach (DefField f in bean.HierarchyFields)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
list.Add(f.CType.Apply(ExcelStreamDataCreator.Ins, stream));
|
||||||
|
}
|
||||||
|
catch (DataCreateException dce)
|
||||||
|
{
|
||||||
|
dce.Push(bean, f);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var dce = new DataCreateException(e, stream.LastReadDataInfo);
|
||||||
|
dce.Push(bean, f);
|
||||||
|
throw dce;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,6 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool HasSubFields => Fields != null || Elements != null;
|
public bool HasSubFields => Fields != null || Elements != null;
|
||||||
|
|
||||||
public TitleRow(Title selfTitle, List<Cell> row)
|
public TitleRow(Title selfTitle, List<Cell> row)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ namespace Luban.Job.Cfg.Defs
|
||||||
public const string LUA_TYPE_NAME_KEY = "_type_";
|
public const string LUA_TYPE_NAME_KEY = "_type_";
|
||||||
|
|
||||||
public const string EXCEL_TYPE_NAME_KEY = "$type";
|
public const string EXCEL_TYPE_NAME_KEY = "$type";
|
||||||
|
public const string EXCEL_VALUE_NAME_KEY = "$value";
|
||||||
|
|
||||||
public string JsonTypeNameKey => JSON_TYPE_NAME_KEY;
|
public string JsonTypeNameKey => JSON_TYPE_NAME_KEY;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue