Procházet zdrojové kódy

新增数据库过滤不是当前表字段名的数据

andy před 1 rokem
rodič
revize
169aa9db9a

+ 5 - 4
src/main/java/com/scbfkj/uni/library/script/DatabaseScriptUtil.java

@@ -448,6 +448,7 @@ public class DatabaseScriptUtil {
             return UniReturnUtil.success(data);
         } else {
 //                新增
+            List<String> allColumns = DATABASE.getColumnsByTableName(connectionStr, expression);
             if (Objects.equals("1", event)) {
                 Map<String, Object> value = dataContent.get(0);
                 Object valueObj = value.getOrDefault("value", value);
@@ -460,15 +461,15 @@ public class DatabaseScriptUtil {
                     map = v;
                 }
 //                    Map<String, Object> value = ((Map<String, Object>) map.getOrDefault("value", map));
-                valueNames = map.keySet().stream().toList();
+                valueNames = map.keySet().stream().filter(allColumns::contains).toList();
                 expression = "insert into %s ( %s) values(%s)".formatted(expression, String.join(",", valueNames), valueNames.stream().map(it -> "?").collect(Collectors.joining(",")));
 //                    更新
             } else if (Objects.equals("2", event)) {
                 Map<String, Object> map = dataContent.get(0);
                 Map<String, Object> value = ((Map<String, Object>) map.get("value"));
-                valueNames = value.keySet().stream().toList();
+                valueNames = value.keySet().stream().filter(allColumns::contains).toList();
                 Map<String, Object> filter = ((Map<String, Object>) map.get("filter"));
-                filterNames = filter.keySet().stream().toList();
+                filterNames = filter.keySet().stream().filter(allColumns::contains).toList();
 
                 expression = "update %s set %s where %s and %s".formatted(expression, valueNames.stream().map("%s = ?"::formatted).collect(Collectors.joining(",")), filterNames.stream().map("%s = ?"::formatted).collect(Collectors.joining(" and ")), Objects.isNull(filterLineWhereStr) ? " 1=1 " : filterLineWhereStr);
 //                    删除
@@ -486,7 +487,7 @@ public class DatabaseScriptUtil {
                 } else if (filter instanceof Map<?, ?> f) {
                     map = f;
                 }
-                filterNames = map.keySet().stream().toList();
+                filterNames = map.keySet().stream().filter(allColumns::contains).toList();
                 expression = "delete from %s where %s and  %s".formatted(expression, filterNames.stream().map("%s = ?"::formatted).collect(Collectors.joining(" and ")), Objects.isNull(filterLineWhereStr) ? " 1=1 " : filterLineWhereStr);
             } else if (Objects.equals("7", event)) {
 //                    先删除