- 新增 build_docker.sh, tag_and_push.sh脚本

- 配置的NamedMode ExcelStream下,支持用空白、""、null来表达空白
main
walon 2021-03-28 11:18:49 +08:00
parent 87877f4671
commit 88f7ccb96f
6 changed files with 48 additions and 13 deletions

View File

@ -13,8 +13,15 @@ namespace Luban.Job.Cfg.DataSources.Excel
private readonly int _toIndex;
private int _curIndex;
public ExcelStream(List<Sheet.Cell> datas, int fromIndex, int toIndex, string sep)
/// <summary>
/// NamedMode下 string可以用空白表达空字符串而不必用null或""
/// </summary>
public bool NamedMode { get; set; }
public ExcelStream(List<Sheet.Cell> datas, int fromIndex, int toIndex, string sep, bool namedMode)
{
NamedMode = namedMode;
if (string.IsNullOrWhiteSpace(sep))
{
this._datas = datas;
@ -42,8 +49,9 @@ namespace Luban.Job.Cfg.DataSources.Excel
}
}
public ExcelStream(Sheet.Cell cell, string sep)
public ExcelStream(Sheet.Cell cell, string sep, bool namedMode)
{
NamedMode = namedMode;
if (string.IsNullOrWhiteSpace(sep))
{
this._datas = new List<Sheet.Cell> { cell };
@ -102,7 +110,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
return false;
}
public object Read()
public object Read(bool notSkip = false)
{
//if (curIndex <= toIndex)
//{
@ -112,7 +120,12 @@ namespace Luban.Job.Cfg.DataSources.Excel
//{
// throw new Exception($"cell:{datas[curIndex - 1]} 无法读取到足够多的数据");
//}
return ReadSkipNull();
return notSkip ? ReadMayNull() : ReadSkipNull();
}
private object ReadMayNull()
{
return _curIndex <= _toIndex ? _datas[_curIndex++].Value : null;
}
//public object Read(bool nullable)

View File

@ -137,7 +137,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
if (Titles.TryGetValue(name, out var title))
{
CheckEmptySinceSecondRow(name, title.FromIndex, title.ToIndex);
var es = new ExcelStream(Rows[0], title.FromIndex, title.ToIndex, sep);
var es = new ExcelStream(Rows[0], title.FromIndex, title.ToIndex, sep, true);
return es;
}
else
@ -181,7 +181,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
{
continue;
}
yield return new ExcelStream(row, title.FromIndex, title.ToIndex, sep);
yield return new ExcelStream(row, title.FromIndex, title.ToIndex, sep, false);
}
}
else

View File

@ -235,11 +235,15 @@ namespace Luban.Job.Cfg.TypeVisitors
public DType Accept(TString type, object converter, ExcelStream x, DefAssembly ass)
{
var d = x.Read();
if (d is string s && s == "null")
var d = x.Read(x.NamedMode);
if (d == null)
{
return new DString("");
}
if (d is string s)
{
return new DString(DataUtil.UnEscapeString(s));
}
return new DString(d.ToString());
}
@ -250,11 +254,15 @@ namespace Luban.Job.Cfg.TypeVisitors
public DType Accept(TText type, object converter, ExcelStream x, DefAssembly ass)
{
var d = x.Read();
if (d is string s && s == "null")
var d = x.Read(x.NamedMode);
if (d == null)
{
return new DString("");
}
if (d is string s)
{
return new DString(DataUtil.UnEscapeString(s));
}
return new DString(d.ToString());
}
@ -272,7 +280,7 @@ namespace Luban.Job.Cfg.TypeVisitors
}
else
{
list.Add(f.CType.Apply(this, f.Remapper, new ExcelStream(stream.ReadCell(), sep), ass));
list.Add(f.CType.Apply(this, f.Remapper, new ExcelStream(stream.ReadCell(), sep, false), ass));
}
}
catch (Exception e)
@ -312,6 +320,7 @@ namespace Luban.Job.Cfg.TypeVisitors
// 因为貌似没意义?
public List<DType> ReadList(TType type, object converter, ExcelStream stream, DefAssembly ass)
{
stream.NamedMode = false;
string sep = type is TBean bean ? ((DefBean)bean.Bean).Sep : null;
var datas = new List<DType>();
while (!stream.TryReadEOF())
@ -322,7 +331,7 @@ namespace Luban.Job.Cfg.TypeVisitors
}
else
{
datas.Add(type.Apply(this, converter, new ExcelStream(stream.ReadCell(), sep), ass));
datas.Add(type.Apply(this, converter, new ExcelStream(stream.ReadCell(), sep, false), ass)); ;
}
}
return datas;
@ -345,13 +354,14 @@ namespace Luban.Job.Cfg.TypeVisitors
public DType Accept(TMap type, object converter, ExcelStream x, DefAssembly ass)
{
x.NamedMode = false;
string sep = type.ValueType is TBean bean ? ((DefBean)bean.Bean).Sep : null;
var datas = new Dictionary<DType, DType>();
while (!x.TryReadEOF())
{
var key = type.KeyType.Apply(this, null, x, ass);
var value = string.IsNullOrWhiteSpace(sep) ? type.ValueType.Apply(this, null, x, ass) : type.ValueType.Apply(this, null, new ExcelStream(x.ReadCell(), sep), ass);
var value = string.IsNullOrWhiteSpace(sep) ? type.ValueType.Apply(this, null, x, ass) : type.ValueType.Apply(this, null, new ExcelStream(x.ReadCell(), sep, false), ass);
if (!datas.TryAdd(key, value))
{
throw new Exception($"map 的 key:{key} 重复");

View File

@ -64,6 +64,15 @@ namespace Luban.Job.Cfg.Utils
return (string)data.Source;
}
public static string UnEscapeString(string s)
{
if (s == "null" || s == "\"\"")
{
return "";
}
return s;
}
//public static string Data2String(DType data)
//{
// var s = new StringBuilder();

View File

@ -0,0 +1 @@
docker build -t luban-server:latest -f Dockerfile ../..

View File

@ -0,0 +1,2 @@
docker tag luban-server:latest focuscreativegames/luban-server:latest
docker push focuscreativegames/luban-server:latest