diff --git a/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs b/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs index 89feb56..f276eaf 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs @@ -7,6 +7,7 @@ using Luban.Job.Cfg.l10n; using Luban.Job.Cfg.RawDefs; using Luban.Job.Cfg.TypeVisitors; using Luban.Job.Common.Defs; +using Luban.Job.Common.Types; using Luban.Server.Common; using System; using System.Collections.Concurrent; @@ -140,6 +141,29 @@ namespace Luban.Job.Cfg.Defs } } + public static List ToSortByKeyDataList(DefTable table, List originRecords) + { + var sortedRecords = new List(originRecords); + + DefField keyField = table.IndexField; + if (keyField != null && (keyField.CType is TInt || keyField.CType is TLong)) + { + string keyFieldName = keyField.Name; + sortedRecords.Sort((a, b) => + { + DType keya = a.Data.GetField(keyFieldName); + DType keyb = b.Data.GetField(keyFieldName); + switch (keya) + { + case DInt ai: return ai.Value.CompareTo((keyb as DInt).Value); + case DLong al: return al.Value.CompareTo((keyb as DLong).Value); + default: throw new NotSupportedException(); + } + }); + } + return sortedRecords; + } + public TableDataInfo GetTableDataInfo(DefTable table) { return _recordsByTables[table.FullName]; diff --git a/src/Luban.Job.Cfg/Source/Generate/ExcelConvertRender.cs b/src/Luban.Job.Cfg/Source/Generate/ExcelConvertRender.cs index ca1048b..8cf7062 100644 --- a/src/Luban.Job.Cfg/Source/Generate/ExcelConvertRender.cs +++ b/src/Luban.Job.Cfg/Source/Generate/ExcelConvertRender.cs @@ -1,6 +1,7 @@ using ClosedXML.Excel; using Luban.Job.Cfg.Cache; using Luban.Job.Cfg.DataConverts; +using Luban.Job.Cfg.Defs; using Luban.Job.Cfg.Utils; using Luban.Job.Common.Types; using Luban.Job.Common.TypeVisitors; @@ -25,7 +26,8 @@ namespace Luban.Job.Cfg.Generate { ctx.Tasks.Add(Task.Run(() => { - var records = ctx.Assembly.GetTableAllDataList(table); + var records = DefAssembly.ToSortByKeyDataList(table, ctx.Assembly.GetTableAllDataList(table)); + string dirName = table.FullName; var fileName = table.FullName; var filePath = $"{dirName}/{fileName}.xlsx"; diff --git a/src/LubanAssistant/ExcelUtil.cs b/src/LubanAssistant/ExcelUtil.cs index 10d8f57..f904694 100644 --- a/src/LubanAssistant/ExcelUtil.cs +++ b/src/LubanAssistant/ExcelUtil.cs @@ -195,24 +195,7 @@ namespace LubanAssistant //int nextRowIndex = titleRowNum + 2; - // 对于 int和long类型记录,按值排序 - var records = tableDataInfo.MainRecords; - DefField keyField = tableDataInfo.Table.IndexField; - if (keyField != null && (keyField.CType is TInt || keyField.CType is TLong)) - { - string keyFieldName = keyField.Name; - records.Sort((a, b) => - { - DType keya = a.Data.GetField(keyFieldName); - DType keyb = b.Data.GetField(keyFieldName); - switch (keya) - { - case DInt ai: return ai.Value.CompareTo((keyb as DInt).Value); - case DLong al: return al.Value.CompareTo((keyb as DLong).Value); - default: throw new NotSupportedException(); - } - }); - } + var records = DefAssembly.ToSortByKeyDataList(tableDataInfo.Table, tableDataInfo.MainRecords); int totalRowCount = 0; var dataRangeArray = new List();