diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs index 25e106a..8eef8f3 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs @@ -13,8 +13,15 @@ namespace Luban.Job.Cfg.DataSources.Excel private readonly int _toIndex; private int _curIndex; - public ExcelStream(List datas, int fromIndex, int toIndex, string sep) + + /// + /// NamedMode下 string可以用空白表达空字符串,而不必用null或"" + /// + public bool NamedMode { get; set; } + + public ExcelStream(List 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 { 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) diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs index 2d374a2..d4864bc 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs @@ -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 diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/ExcelDataCreator.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/ExcelDataCreator.cs index c329e0d..8719a39 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/ExcelDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/ExcelDataCreator.cs @@ -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 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(); 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(); 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} 重复"); diff --git a/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs b/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs index 2f1834d..fabe806 100644 --- a/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs +++ b/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs @@ -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(); diff --git a/src/Luban.Server/Scripts/build_docker.sh b/src/Luban.Server/Scripts/build_docker.sh new file mode 100644 index 0000000..07c3fec --- /dev/null +++ b/src/Luban.Server/Scripts/build_docker.sh @@ -0,0 +1 @@ +docker build -t luban-server:latest -f Dockerfile ../.. \ No newline at end of file diff --git a/src/Luban.Server/Scripts/tag_and_push.sh b/src/Luban.Server/Scripts/tag_and_push.sh new file mode 100644 index 0000000..75170c2 --- /dev/null +++ b/src/Luban.Server/Scripts/tag_and_push.sh @@ -0,0 +1,2 @@ +docker tag luban-server:latest focuscreativegames/luban-server:latest +docker push focuscreativegames/luban-server:latest \ No newline at end of file