|
@@ -10,7 +10,6 @@ import org.springframework.jdbc.support.KeyHolder;
|
|
import java.sql.*;
|
|
import java.sql.*;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
-import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -26,7 +25,7 @@ public class MyDbHelper {
|
|
private Map<String, List<String>> tableColumn = new HashMap<>();//缓存对象调用过的表的字段列表
|
|
private Map<String, List<String>> tableColumn = new HashMap<>();//缓存对象调用过的表的字段列表
|
|
private Map<String, List<String>> tablePrimaryKey = new HashMap<>();//缓存对象调用过的表的主键列表
|
|
private Map<String, List<String>> tablePrimaryKey = new HashMap<>();//缓存对象调用过的表的主键列表
|
|
private HashMap<String, Map<String, List<String>>> sqlColumn = new HashMap<>();//缓存对象调用过的表的主键列表
|
|
private HashMap<String, Map<String, List<String>>> sqlColumn = new HashMap<>();//缓存对象调用过的表的主键列表
|
|
- private ConcurrentHashMap<String, List<Object>> event6Map = new ConcurrentHashMap<>();
|
|
|
|
|
|
+ private HashMap<String, HashSet<Object>> event6Map = new HashMap<>();//
|
|
private Map<String, String> eventSQL = new HashMap<>() {{
|
|
private Map<String, String> eventSQL = new HashMap<>() {{
|
|
put("0", "select * from 表名");
|
|
put("0", "select * from 表名");
|
|
put("1", "insert into 表名(字段) values(值) ");
|
|
put("1", "insert into 表名(字段) values(值) ");
|
|
@@ -180,10 +179,10 @@ public class MyDbHelper {
|
|
public synchronized Boolean updateEvent6Map(String tableName, Object updateParam, boolean isAdd) {
|
|
public synchronized Boolean updateEvent6Map(String tableName, Object updateParam, boolean isAdd) {
|
|
boolean isNew = false; //{tableName:[Map<String,Object>]}
|
|
boolean isNew = false; //{tableName:[Map<String,Object>]}
|
|
if (!event6Map.containsKey(tableName)) {
|
|
if (!event6Map.containsKey(tableName)) {
|
|
- event6Map.put(tableName, new ArrayList<>());
|
|
|
|
|
|
+ event6Map.put(tableName, new HashSet<>());
|
|
}
|
|
}
|
|
String key = MapTools.jacksonObjToStr(updateParam);
|
|
String key = MapTools.jacksonObjToStr(updateParam);
|
|
- List<Object> tableUniqe = event6Map.get(tableName);
|
|
|
|
|
|
+ HashSet<Object> tableUniqe = event6Map.get(tableName);
|
|
if (isAdd) {
|
|
if (isAdd) {
|
|
if (!tableUniqe.contains(key)) {
|
|
if (!tableUniqe.contains(key)) {
|
|
isNew = true;
|
|
isNew = true;
|
|
@@ -194,6 +193,7 @@ public class MyDbHelper {
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
tableUniqe.remove(key);
|
|
tableUniqe.remove(key);
|
|
|
|
+
|
|
}
|
|
}
|
|
return isNew;
|
|
return isNew;
|
|
}
|
|
}
|
|
@@ -205,24 +205,48 @@ public class MyDbHelper {
|
|
}
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> returnList = new ArrayList<>();
|
|
List<Map<String, Object>> returnList = new ArrayList<>();
|
|
|
|
+// long l2 = System.currentTimeMillis();
|
|
|
|
+// System.out.println("event6: 操作开始 ");
|
|
|
|
+ int index = 0;
|
|
for (Map<String, Object> signParam : paramsList) {
|
|
for (Map<String, Object> signParam : paramsList) {
|
|
|
|
+ index++;
|
|
String eventStr = "2";
|
|
String eventStr = "2";
|
|
- if (updateEvent6Map(tableName, signParam.get("filter"), true)) { //不包含true
|
|
|
|
- Map<String, Object> selectMap = generalProcess("0", null, "select 1 from " + tableName, null, new ArrayList<>() {{
|
|
|
|
- add(signParam);
|
|
|
|
- }}, false, 1, 1);
|
|
|
|
- if (selectMap.get("code").equals("-1")) {
|
|
|
|
|
|
+ Map<String, Object> tempFilterMap = (Map<String, Object>) signParam.get("filter");
|
|
|
|
+ if (updateEvent6Map(tableName, tempFilterMap, true)) { //不包含true
|
|
|
|
+// long l = System.currentTimeMillis();
|
|
|
|
+ String whereStr = "";
|
|
|
|
+ List<Object> tempCheckValue = new ArrayList<>();
|
|
|
|
+ for (String key : tempFilterMap.keySet()) {
|
|
|
|
+ whereStr = whereStr + " " + key + " = ? and ";
|
|
|
|
+ tempCheckValue.add(tempFilterMap.get(key));
|
|
|
|
+ }
|
|
|
|
+ whereStr = whereStr.substring(0, whereStr.length() - 4);
|
|
|
|
+ String checkSQL = "select 1 from " + tableName + " where " + whereStr + " limit 1";
|
|
|
|
+ try {
|
|
|
|
+ List<Map<String, Object>> queryForList = theJdbcTemplate.queryForList(checkSQL, tempCheckValue.toArray());
|
|
|
|
+// eventStr = (Objects.isNull(selectMap.get("returnData")) || ((List<?>) selectMap.get("returnData")).size() == 0) ? "1" : eventStr;
|
|
|
|
+ eventStr = (queryForList.size() == 0) ? "1" : eventStr;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+// if (selectMap.get("code").equals("-1")) {
|
|
updateEvent6Map(tableName, signParam.get("filter"), false);
|
|
updateEvent6Map(tableName, signParam.get("filter"), false);
|
|
- returnList.add(selectMap);
|
|
|
|
|
|
+// returnList.add(processFail());
|
|
continue;
|
|
continue;
|
|
|
|
+// }
|
|
}
|
|
}
|
|
- eventStr = (Objects.isNull(selectMap.get("returnData")) || ((List<?>) selectMap.get("returnData")).size() == 0) ? "1" : eventStr;
|
|
|
|
|
|
+// Map<String, Object> selectMap = generalProcess("0", null, "select 1 from " + tableName, null, new ArrayList<>() {{
|
|
|
|
+// add(signParam);
|
|
|
|
+// }}, false, 1, 1);
|
|
|
|
+// System.out.println("event6: 查询时间为: " + (System.currentTimeMillis()-l));
|
|
}
|
|
}
|
|
|
|
+// System.out.println("event6: 单挑开始: " + index);
|
|
|
|
+// long l3 = System.currentTimeMillis();
|
|
// 包含:
|
|
// 包含:
|
|
returnList.add(generalProcess(eventStr, tableName, null, null, new ArrayList<>() {{
|
|
returnList.add(generalProcess(eventStr, tableName, null, null, new ArrayList<>() {{
|
|
add(signParam);
|
|
add(signParam);
|
|
}}, false, null, null));
|
|
}}, false, null, null));
|
|
|
|
+// System.out.println("event6: 单挑ji结束: " + (System.currentTimeMillis() - l3));
|
|
}
|
|
}
|
|
|
|
+// System.out.println("event6: 操作结束: " + (System.currentTimeMillis() - l2));
|
|
return returnList.size() == 1 ? returnList.get(0) : processSuccess(returnList, tableName, paramsList);
|
|
return returnList.size() == 1 ? returnList.get(0) : processSuccess(returnList, tableName, paramsList);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -264,7 +288,7 @@ public class MyDbHelper {
|
|
} else if (sql.startsWith("select count(") || sql.startsWith("select sum(")) { //??
|
|
} else if (sql.startsWith("select count(") || sql.startsWith("select sum(")) { //??
|
|
for (int i = 0; i < sqlSplit.length; i++) {
|
|
for (int i = 0; i < sqlSplit.length; i++) {
|
|
if (sqlSplit[i].equals("from")) {
|
|
if (sqlSplit[i].equals("from")) {
|
|
- tableName = sqlSplit[i+1];
|
|
|
|
|
|
+ tableName = sqlSplit[i + 1];
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -430,7 +454,7 @@ public class MyDbHelper {
|
|
tempList.add(paramsList.get(0));
|
|
tempList.add(paramsList.get(0));
|
|
paramsList = tempList;
|
|
paramsList = tempList;
|
|
}
|
|
}
|
|
- if (paramsList.size() ==0){
|
|
|
|
|
|
+ if (paramsList.size() == 0) {
|
|
paramsList.add(new HashMap<>());
|
|
paramsList.add(new HashMap<>());
|
|
}
|
|
}
|
|
for (Map<String, Object> itemMap : paramsList) {
|
|
for (Map<String, Object> itemMap : paramsList) {
|
|
@@ -439,10 +463,10 @@ public class MyDbHelper {
|
|
List<String> modifyValue = new ArrayList<>();
|
|
List<String> modifyValue = new ArrayList<>();
|
|
if ("1,2".contains(event)) {
|
|
if ("1,2".contains(event)) {
|
|
Map<String, Object> valueMap = itemMap.containsKey("Value") ? (Map<String, Object>) itemMap.get("Value") : itemMap;
|
|
Map<String, Object> valueMap = itemMap.containsKey("Value") ? (Map<String, Object>) itemMap.get("Value") : itemMap;
|
|
- if (allColumn.contains("createtime") && "1".equals(event)) {
|
|
|
|
- valueMap.put("createtime", new Date());
|
|
|
|
- }
|
|
|
|
if (event.equals("1")) {
|
|
if (event.equals("1")) {
|
|
|
|
+ if (allColumn.contains("createtime") && "1".equals(event)) {
|
|
|
|
+ valueMap.put("createtime", new Date());
|
|
|
|
+ }
|
|
for (String column : allColumn) {
|
|
for (String column : allColumn) {
|
|
cuList.add(valueMap.get(column));
|
|
cuList.add(valueMap.get(column));
|
|
modifyValue.add("?");
|
|
modifyValue.add("?");
|
|
@@ -513,7 +537,7 @@ public class MyDbHelper {
|
|
if (event.equals("0") && !MapTools.isBlank(tableName)) { // 理论上sql 不为空 可以通过allColumn 替换为count 1 来组建rowCountSQL---> select * from biao left ……
|
|
if (event.equals("0") && !MapTools.isBlank(tableName)) { // 理论上sql 不为空 可以通过allColumn 替换为count 1 来组建rowCountSQL---> select * from biao left ……
|
|
rowCountSQL = "select count(1) from " + tableName;
|
|
rowCountSQL = "select count(1) from " + tableName;
|
|
}
|
|
}
|
|
- if (event.equals("0") && MapTools.isNotBlank(sql) && MapTools.isBlank(rowCountSQL) && allColumn.size() > 0) {
|
|
|
|
|
|
+ if ( !MapTools.isBlank(tableName) &&event.equals("0") && MapTools.isNotBlank(sql) && MapTools.isBlank(rowCountSQL) && allColumn.size() > 0) {
|
|
rowCountSQL = sql;
|
|
rowCountSQL = sql;
|
|
for (int index = 0; index < allColumn.size(); index++) {
|
|
for (int index = 0; index < allColumn.size(); index++) {
|
|
rowCountSQL = rowCountSQL.replace(allColumn.get(index), index == 0 ? " count(1) " : "");
|
|
rowCountSQL = rowCountSQL.replace(allColumn.get(index), index == 0 ? " count(1) " : "");
|
|
@@ -621,7 +645,6 @@ public class MyDbHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
return processSuccess(null, tableName, null);
|
|
return processSuccess(null, tableName, null);
|
|
}
|
|
}
|