更新表格模块提高查询效率

This commit is contained in:
dingxiaowei
2024-07-20 13:32:53 +08:00
parent 121e59732d
commit 821a1d481c
17 changed files with 50 additions and 45 deletions
+13 -7
View File
@@ -29,7 +29,7 @@ namespace ExcelTool
var excelName = fileInfo.Name.Remove(fileInfo.Name.IndexOf(".xlsx"));
StringBuilder sb = new StringBuilder();
sb.Append($"/*\n * auto generated by tools(注意:千万不要手动修改本文件)\n * {excelName}\n */\n");
sb.Append("using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Linq;\n\n");
sb.Append("using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Text;\n\n");
sb.Append("[Serializable]\n");
sb.Append($"public partial class {excelName} : IBinarySerializable\n");
sb.Append("{\n");
@@ -475,7 +475,8 @@ namespace ExcelTool
sb.Append("[Serializable]\n");
sb.Append($"public partial class {excelName}Config : IBinarySerializable\n");
sb.Append("{\n");
sb.Append($"\tpublic List<{excelName}> {excelName}Infos = new List<{excelName}>();\n");
// sb.Append($"\tpublic List<{excelName}> {excelName}Infos = new List<{excelName}>();\n");
sb.Append($"\tDictionary<int,{excelName}> {excelName}Infos = new Dictionary<int,{excelName}>();\n");
sb.Append($"\tpublic void DeSerialize(BinaryReader reader)\n");
sb.Append("\t{\n");
sb.Append($"\t\tint count = reader.ReadInt32();\n");
@@ -483,7 +484,8 @@ namespace ExcelTool
sb.Append("\t\t{\n");
sb.Append($"\t\t\t{excelName} tempData = new {excelName}();\n");
sb.Append($"\t\t\ttempData.DeSerialize(reader);\n");
sb.Append($"\t\t\t{excelName}Infos.Add(tempData);\n");
// sb.Append($"\t\t\t{excelName}Infos.Add(tempData);\n");
sb.Append($"\t\t\t{excelName}Infos.Add(tempData.Id, tempData);\n");
sb.Append("\t\t}\n");
sb.Append("\t}\n");
sb.Append("\n");
@@ -497,10 +499,14 @@ namespace ExcelTool
sb.Append("\t}\n\n");
sb.Append($"\tpublic {excelName} QueryById(int id)\n");
sb.Append("\t{\n");
sb.Append($"\t\tvar datas = from d in {excelName}Infos\n");
sb.Append($"\t\t\t\t\twhere d.Id == id\n");
sb.Append($"\t\t\t\t\tselect d;\n");
sb.Append("\t\treturn datas.First();\n");
// sb.Append($"\t\tvar datas = from d in {excelName}Infos\n");
// sb.Append($"\t\t\t\t\twhere d.Id == id\n");
// sb.Append($"\t\t\t\t\tselect d;\n");
// sb.Append("\t\treturn datas.First();\n");
sb.Append($"\t\tif ({excelName}Infos.ContainsKey(id))\n");
sb.Append($"\t\t\treturn {excelName}Infos[id];\n");
sb.Append($"\t\telse\n");
sb.Append($"\t\t\treturn null;\n");
sb.Append("\t}\n");
sb.Append("}\n");
FileManager.WriteToFile(Path.Combine(outputDir, $"{excelName}.cs"), sb.ToString());