Bladeren bron

fix:合法性检测增加主键重复检测

chenbin 3 maanden geleden
bovenliggende
commit
2bd48e5eaa

+ 1 - 1
Configs/CSTemplates/TableComponent.cs

@@ -1,4 +1,4 @@
-// Generate By EToy
+// Generate By EToy
 // Don't Edit It!!
 using XGame.Database;
 using XGame.Framework.Asyncs;

+ 7 - 6
etoy/Components/Parser/CommonTableCsvParser.cs

@@ -111,12 +111,13 @@ namespace etoy
                             else 
                                 throw new Exception($"配置表({tableName}) 不支持该Tag格式: [{tags}], 应满足以下格式: [Tag1Key:Tag1Value;Tag2Key:Tag2Value] (行: {excelRow}, 列: {excelCol})");
                         }
-
-                        FieldTagInfo info = new FieldTagInfo();
-                        info.Key = fieldTag;
-                        info.Value = null;
-                        result.Add(info);
-
+                        else
+                        {
+                            FieldTagInfo info = new FieldTagInfo();
+                            info.Key = fieldTag;
+                            info.Value = null;
+                            result.Add(info);
+                        }
                     }
                     else if (kv.Length == 2)
                     {

+ 12 - 1
etoy/Pileline/Cmd/CmdCheckDataIntegrity.cs

@@ -1,4 +1,6 @@
 
+using System.Linq;
+
 namespace etoy
 {
     class CmdCheckDataIntegrity : Command
@@ -163,6 +165,7 @@ namespace etoy
                 AddException(new Exception($"配置表({table.Name}), 表结构未含PrimaryKey的字段. {table.Path}"));
 
             // Cells 合法性检测
+            var primaryKeys = new HashSet<string>();
             for (int i = 0, rowCount = table.Rows.Count; i < rowCount; i++)
             {
                 var row = table.Rows[i];
@@ -174,7 +177,14 @@ namespace etoy
                     int excelRow = cell.Row + 1;
                     int excelCol = cell.Column + 1;
                     string fieldType = cell.FieldInfo.FieldType;
-
+                    if (cell.FieldInfo.IsPrimaryKey)
+                    { // 主键
+                        if (!primaryKeys.Add(cell.Value))
+                        {
+                            AddException(new Exception($"配置表({table.Name}) 主键重复 字段内容: ({cell.Value}) 与 字段类型: ({fieldType})。 {table.Path} (行: {excelRow}, 列: {excelCol})"));
+                            continue;
+                        }
+                    }
 
                     bool valid;
                     if (cell.FieldInfo.IsRepeated)
@@ -220,6 +230,7 @@ namespace etoy
                         AddException(new Exception($"配置表({table.Name}) 字段内容: ({cell.Value}) 与 字段类型: ({fieldType}) 转换失败。 {table.Path} (行: {excelRow}, 列: {excelCol})"));
                 }
             }
+            primaryKeys.Clear();
         }
     }
 }