|
@@ -50,6 +50,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.RowMapper;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -59,8 +60,13 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.ResultSetMetaData;
|
|
|
+import java.sql.SQLException;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -1393,7 +1399,7 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
List<QueryProcessDataVO> nodeTabCols = informationQueryService.getNodeChildTabColsAllByNodeId(needCopyNode.getId() + "", needCopyNode.getContractId());
|
|
|
//转化为map
|
|
|
Map<String, String> nodeTabColsMap = nodeTabCols.stream().collect(Collectors.toMap(QueryProcessDataVO::getQueryType, QueryProcessDataVO::getAncestors, (key1, key2) -> key2));
|
|
|
- StringBuilder copeSql = new StringBuilder();
|
|
|
+ StringBuilder copySql = new StringBuilder();
|
|
|
|
|
|
if (StringUtils.isNotEmpty(vo.getNeedCopyPrimaryKeyId())) {
|
|
|
WbsTreeContract parent = this.wbsTreeContractClient.getContractNodeByPrimaryKeyId(vo.getParentPrimaryKeyId());
|
|
@@ -1457,16 +1463,63 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
this.createLedger(newData, saveLedger, nodeMap, null);
|
|
|
}
|
|
|
//表单所属方,只有勾选了对应的所属方权限才复制数据;勾选了复制数据才能复制,否则只是创建节点、表
|
|
|
- //组织复制值Sql
|
|
|
if (nodeOld.getType() == 2 && StringUtils.isNotEmpty(newData.getInitTableName()) && tabOwner.contains(nodeOld.getTableOwner()) && vo.getIsCopyData() == 1) {
|
|
|
String tableName = newData.getInitTableName();
|
|
|
String col = nodeTabColsMap.get(tableName);
|
|
|
- String colVal = nodeTabColsMap.get(tableName);
|
|
|
- colVal = colVal.replaceAll("id,p_key_id,", "'" + SnowFlakeUtil.getId() + "' as id,'" + newData.getPKeyId() + "' as p_key_id,");
|
|
|
+ List<String> filteredList = Arrays.stream(col.split(","))
|
|
|
+ .filter(value -> !value.equals("id") && !value.equals("p_key_id") && !value.equals("group_id"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ String keys = StringUtils.join(filteredList, ",");
|
|
|
+
|
|
|
+ //构造入参
|
|
|
+ String dataSql = "SELECT " + keys + " FROM " + tableName + " WHERE p_key_id= " + nodeOld.getPKeyId() + " LIMIT 1;";
|
|
|
+ List<LinkedHashMap<String, Object>> resultList = jdbcTemplate.query(dataSql, new RowMapper<LinkedHashMap<String, Object>>() {
|
|
|
+ @Override
|
|
|
+ public LinkedHashMap<String, Object> mapRow(@NotNull ResultSet rs, int rowNum) throws SQLException {
|
|
|
+ ResultSetMetaData metaData = rs.getMetaData();
|
|
|
+ int columnCount = metaData.getColumnCount();
|
|
|
+ LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
|
|
|
+ for (int i = 1; i <= columnCount; i++) {
|
|
|
+ String columnName = metaData.getColumnName(i);
|
|
|
+ Object columnValue = rs.getObject(i);
|
|
|
+ resultMap.put(columnName, columnValue);
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ StringBuilder newString = new StringBuilder();
|
|
|
+ if (!resultList.isEmpty()) {
|
|
|
+ LinkedHashMap<String, Object> resultMap = resultList.get(0);
|
|
|
+ for (Map.Entry<String, Object> entry : resultMap.entrySet()) {
|
|
|
+ Object value = entry.getValue();
|
|
|
+ if (value != null) {
|
|
|
+ if (value.toString().contains("\n")) {
|
|
|
+ //如果值中包含换行符,则将换行符替换
|
|
|
+ value = value.toString().replace("\n", "\\n");
|
|
|
+ }
|
|
|
+ newString.append("'").append(value).append("',");
|
|
|
+ } else {
|
|
|
+ newString.append("null,");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //去除末尾的逗号
|
|
|
+ if (newString.length() > 0) {
|
|
|
+ newString.deleteCharAt(newString.length() - 1);
|
|
|
+ }
|
|
|
+
|
|
|
//delete SQL (先删除旧数据,再新增)
|
|
|
- String delSql = "delete from " + tableName + " where p_key_id = " + newData.getPKeyId() + " ; ";
|
|
|
+ String delSql = "DELETE FROM " + tableName + " WHERE p_key_id = " + newData.getPKeyId() + " ; ";
|
|
|
+
|
|
|
//insert into SQL
|
|
|
- copeSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(nodeOld.getPKeyId()).append("' ;");
|
|
|
+ copySql.append(delSql).append("INSERT INTO ").append(tableName)
|
|
|
+ .append(" (id,p_key_id,group_id,")
|
|
|
+ .append(keys)
|
|
|
+ .append(") VALUES (")
|
|
|
+ .append(SnowFlakeUtil.getId()).append(",")
|
|
|
+ .append(newData.getPKeyId()).append(",")
|
|
|
+ .append("null").append(",")
|
|
|
+ .append(newString).append(") ; ");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1477,8 +1530,8 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
|
|
|
try {
|
|
|
//复制表单数据
|
|
|
- if (copeSql.length() >= 10 && booleanR.getData()) {
|
|
|
- jdbcTemplate.execute(copeSql.toString());
|
|
|
+ if (copySql.length() >= 10 && booleanR.getData()) {
|
|
|
+ jdbcTemplate.execute(copySql.toString());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
//手动回滚,删除节点、表
|
|
@@ -1836,7 +1889,7 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
//delete SQL (先删除旧数据,再新增)
|
|
|
String delSql = "delete from " + tableName + " where p_key_id = " + toCopyNodeTab.getPKeyId() + " ; ";
|
|
|
//insert into SQL
|
|
|
- copyDataSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(oldPKeyId).append("' ;");
|
|
|
+ copyDataSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(oldPKeyId).append("' LIMIT 1;");
|
|
|
resultTablesData.add(copyDataSql.toString());
|
|
|
}
|
|
|
}
|
|
@@ -1881,7 +1934,7 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
//delete SQL (先删除旧数据,再新增)
|
|
|
String delSql = "delete from " + tableName + " where p_key_id = " + objTab.getPKeyId() + " ; ";
|
|
|
//insert into SQL
|
|
|
- copyDataSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(oldPKeyId).append("' ;");
|
|
|
+ copyDataSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(oldPKeyId).append("' LIMIT 1;");
|
|
|
resultTablesData.add(copyDataSql.toString());
|
|
|
}
|
|
|
}
|
|
@@ -1974,7 +2027,7 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
//delete SQL (先删除旧数据,再新增)
|
|
|
String delSql = "delete from " + tableName + " where p_key_id = " + obj.getPKeyId() + " ; ";
|
|
|
//insert into SQL
|
|
|
- copyDataSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(oldPKeyId).append("' ;");
|
|
|
+ copyDataSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(oldPKeyId).append("' LIMIT 1;");
|
|
|
resultTablesData.add(copyDataSql.toString());
|
|
|
}
|
|
|
}
|
|
@@ -2071,7 +2124,7 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
//delete SQL (先删除旧数据,再新增)
|
|
|
String delSql = "delete from " + tableName + " where p_key_id = " + needTab.getPKeyId() + " ; ";
|
|
|
//insert into SQL
|
|
|
- copyDataSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(oldPKeyId).append("' ;");
|
|
|
+ copyDataSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(oldPKeyId).append("' LIMIT 1;");
|
|
|
resultTablesData.add(copyDataSql.toString());
|
|
|
}
|
|
|
}
|