|
@@ -1981,53 +1981,55 @@ public R<Boolean> copyContractTreeNode(@RequestBody CopyContractTreeNodeVO vo) {
|
|
|
.distinct()
|
|
|
.collect(Collectors.toList());
|
|
|
//表名集合转逗号拼接的字符串
|
|
|
- String inClausePlaceholders = String.join(",", Collections.nCopies(tabNames.size(), "?"));
|
|
|
- String sql = "SELECT table_name AS queryType, GROUP_CONCAT(COLUMN_name) AS ancestors " +
|
|
|
- "FROM information_schema.COLUMNS WHERE table_name IN (" + inClausePlaceholders + ") " +
|
|
|
- "GROUP BY table_name";
|
|
|
- Object[] params = tabNames.toArray();
|
|
|
- //数据库中查询 表与表对应的列名
|
|
|
- List<Map<String, Object>> results = jdbcTemplate.queryForList(sql, params);
|
|
|
-
|
|
|
- //表名集合转Map key=表名 value=表对应的数据集合
|
|
|
- Map<String, List<WbsTreeContract>> tabsGroup = nodeChildAll.stream()
|
|
|
- .filter(f -> f.getType() == 2 && ObjectUtil.isNotEmpty(f.getInitTableName()))
|
|
|
- .collect(Collectors.groupingBy(WbsTreeContract::getInitTableName));
|
|
|
-
|
|
|
- Set<Long> continuePkeyIds = new HashSet<>();
|
|
|
- for (Map<String, Object> result : results) {
|
|
|
- String tabName = (String) result.get("queryType");
|
|
|
- String col = (String) result.get("ancestors");
|
|
|
- if (ObjectUtil.isEmpty(col) || ObjectUtil.isEmpty(tabName)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- //字段集合 过滤掉不存在指定字段的表
|
|
|
- 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, ",");
|
|
|
- //根据表明查询指定数据集合
|
|
|
- List<WbsTreeContract> tabs = tabsGroup.get(tabName);
|
|
|
- for (WbsTreeContract tab : tabs) {
|
|
|
- // 在复制数据时,测量记录表 的数据不需要复制
|
|
|
- if(tab.getType()==2 && tab.getTableType()==6){
|
|
|
+ if (!tabNames.isEmpty()) {
|
|
|
+ String inClausePlaceholders = String.join(",", Collections.nCopies(tabNames.size(), "?"));
|
|
|
+ String sql = "SELECT table_name AS queryType, GROUP_CONCAT(COLUMN_name) AS ancestors " +
|
|
|
+ "FROM information_schema.COLUMNS WHERE table_name IN (" + inClausePlaceholders + ") " +
|
|
|
+ "GROUP BY table_name";
|
|
|
+ Object[] params = tabNames.toArray();
|
|
|
+ //数据库中查询 表与表对应的列名
|
|
|
+ List<Map<String, Object>> results = jdbcTemplate.queryForList(sql, params);
|
|
|
+
|
|
|
+ //表名集合转Map key=表名 value=表对应的数据集合
|
|
|
+ Map<String, List<WbsTreeContract>> tabsGroup = nodeChildAll.stream()
|
|
|
+ .filter(f -> f.getType() == 2 && ObjectUtil.isNotEmpty(f.getInitTableName()))
|
|
|
+ .collect(Collectors.groupingBy(WbsTreeContract::getInitTableName));
|
|
|
+
|
|
|
+ Set<Long> continuePkeyIds = new HashSet<>();
|
|
|
+ for (Map<String, Object> result : results) {
|
|
|
+ String tabName = (String) result.get("queryType");
|
|
|
+ String col = (String) result.get("ancestors");
|
|
|
+ if (ObjectUtil.isEmpty(col) || ObjectUtil.isEmpty(tabName)) {
|
|
|
continue;
|
|
|
}
|
|
|
- //根据字段
|
|
|
- String dataSql = "SELECT " + keys + " FROM " + tabName + " WHERE p_key_id = " + tab.getPKeyId() + " LIMIT 1;";
|
|
|
- try {
|
|
|
- //查询指定表指定表节点的数据
|
|
|
- Map<String, Object> resultMap = jdbcTemplate.queryForMap(dataSql);
|
|
|
- //删除空值
|
|
|
- resultMap.values().removeIf(value -> value == null || (value instanceof String && ObjectUtil.isEmpty(value)));
|
|
|
- colMaps.put(tab.getPKeyId(), resultMap);
|
|
|
- } catch (EmptyResultDataAccessException e) {
|
|
|
- continuePkeyIds.add(tab.getPKeyId());
|
|
|
+ //字段集合 过滤掉不存在指定字段的表
|
|
|
+ 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, ",");
|
|
|
+ //根据表明查询指定数据集合
|
|
|
+ List<WbsTreeContract> tabs = tabsGroup.get(tabName);
|
|
|
+ for (WbsTreeContract tab : tabs) {
|
|
|
+ // 在复制数据时,测量记录表 的数据不需要复制
|
|
|
+ if(tab.getType()==2 && tab.getTableType()==6){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //根据字段
|
|
|
+ String dataSql = "SELECT " + keys + " FROM " + tabName + " WHERE p_key_id = " + tab.getPKeyId() + " LIMIT 1;";
|
|
|
+ try {
|
|
|
+ //查询指定表指定表节点的数据
|
|
|
+ Map<String, Object> resultMap = jdbcTemplate.queryForMap(dataSql);
|
|
|
+ //删除空值
|
|
|
+ resultMap.values().removeIf(value -> value == null || (value instanceof String && ObjectUtil.isEmpty(value)));
|
|
|
+ colMaps.put(tab.getPKeyId(), resultMap);
|
|
|
+ } catch (EmptyResultDataAccessException e) {
|
|
|
+ continuePkeyIds.add(tab.getPKeyId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ logger.info("以下元素表没有获取到对应实体表数据,已跳过 ===> 表pKeyId:[{}]", StringUtils.join(continuePkeyIds, ","));
|
|
|
}
|
|
|
- logger.info("以下元素表没有获取到对应实体表数据,已跳过 ===> 表pKeyId:[{}]", StringUtils.join(continuePkeyIds, ","));
|
|
|
}
|
|
|
// 节点+表节点
|
|
|
for (WbsTreeContract nodeOld : nodeChildAll) {
|