|
@@ -11,9 +11,9 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
public class DatabaseScriptUtil {
|
|
|
|
|
|
- public static Map<String, Object> exec(String connectionStr, String expression, List<Map<String, Object>> args, Object executionNumber, List<String> filterColumns, List<Map<String, Object>> filterLines) throws Exception {
|
|
|
+ public static Map<String, Object> exec(String connectionStr, String expression, List<Map<String, Object>> args, Object event, List<String> filterColumns, List<Map<String, Object>> filterLines) throws Exception {
|
|
|
|
|
|
- if (Objects.isNull(executionNumber) || !StringUtils.hasText(executionNumber.toString())) {
|
|
|
+ if (Objects.isNull(event) || !StringUtils.hasText(event.toString())) {
|
|
|
throw new RuntimeException("执行编号不能为空");
|
|
|
}
|
|
|
expression = expression.replaceAll("\\s*(\\r)?\\n\\s*", " ").trim();
|
|
@@ -41,7 +41,7 @@ public class DatabaseScriptUtil {
|
|
|
List<String> valueNames = null;
|
|
|
List<String> filterNames = null;
|
|
|
// 查询
|
|
|
- if (Objects.equals("0", executionNumber)) {
|
|
|
+ if (Objects.equals("0", event)) {
|
|
|
Map<String, Object> map = args.get(0);
|
|
|
Map<String, Object> filter = ((Map<String, Object>) map.getOrDefault("filter", map));
|
|
|
filterNames = filter.keySet().stream().toList();
|
|
@@ -84,7 +84,7 @@ public class DatabaseScriptUtil {
|
|
|
List<Map<String, Object>> result = DataBase.query(connectionStr, expression, values);
|
|
|
return UniReturnUtil.success(result);
|
|
|
// 更新或新增
|
|
|
- } else if (Objects.equals("6", executionNumber)) {
|
|
|
+ } else if (Objects.equals("6", event)) {
|
|
|
Map<String, Object> map = args.get(0);
|
|
|
Map<String, Object> filter = ((Map<String, Object>) map.get("filter"));
|
|
|
filterNames = filter.keySet().stream().toList();
|
|
@@ -114,13 +114,13 @@ public class DatabaseScriptUtil {
|
|
|
} else {
|
|
|
|
|
|
// 新增
|
|
|
- if (Objects.equals("1", executionNumber)) {
|
|
|
+ if (Objects.equals("1", event)) {
|
|
|
Map<String, Object> map = args.get(0);
|
|
|
Map<String, Object> value = ((Map<String, Object>) map.getOrDefault("value", map));
|
|
|
valueNames = value.keySet().stream().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", executionNumber)) {
|
|
|
+ } else if (Objects.equals("2", event)) {
|
|
|
Map<String, Object> map = args.get(0);
|
|
|
Map<String, Object> value = ((Map<String, Object>) map.get("value"));
|
|
|
valueNames = value.keySet().stream().toList();
|
|
@@ -131,7 +131,7 @@ public class DatabaseScriptUtil {
|
|
|
filterNames.stream().map("%s = ?"::formatted).collect(Collectors.joining(" and ")),
|
|
|
Objects.isNull(filterLineWhereStr) ? " 1=1 " : filterLineWhereStr);
|
|
|
// 删除
|
|
|
- } else if (Objects.equals("3", executionNumber)) {
|
|
|
+ } else if (Objects.equals("3", event)) {
|
|
|
Map<String, Object> map = args.get(0);
|
|
|
Map<String, Object> filter = ((Map<String, Object>) map.getOrDefault("filter", map));
|
|
|
filterNames = filter.keySet().stream().toList();
|
|
@@ -212,10 +212,10 @@ public class DatabaseScriptUtil {
|
|
|
return UniReturnUtil.success(queryResult);
|
|
|
|
|
|
} else {
|
|
|
- if (Objects.equals(executionNumber, "0")) {
|
|
|
+ if (Objects.equals(event, "0")) {
|
|
|
List<Map<String, Object>> queryResult = DataBase.query(connectionStr, expression, args, filterColumns, filterLines);
|
|
|
return UniReturnUtil.success(queryResult);
|
|
|
- } else if (Objects.equals(executionNumber, "1")) {
|
|
|
+ } else if (Objects.equals(event, "1")) {
|
|
|
if (sqlStrVarList.containsKey(expression)) {
|
|
|
getSQLVarList(expression);
|
|
|
}
|