From 3612d4e2d8f7a9c697c7c4bdc704bbf81be39bd7 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 5 Nov 2021 17:10:43 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91convert=5Fx?= =?UTF-8?q?lsx=E8=BE=93=E5=87=BA=E8=AE=B0=E5=BD=95=E6=8C=89key=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs | 24 +++++++++++++++++++ .../Source/Generate/ExcelConvertRender.cs | 4 +++- src/LubanAssistant/ExcelUtil.cs | 19 +-------------- 3 files changed, 28 insertions(+), 19 deletions(-) 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();