Pārlūkot izejas kodu

多份、单份复制bug

liuyc 1 gadu atpakaļ
vecāks
revīzija
762a06fce4

+ 12 - 6
blade-service/blade-business/src/main/java/org/springblade/business/controller/InformationWriteQueryController.java

@@ -1410,10 +1410,6 @@ public class InformationWriteQueryController extends BladeController {
             //获取数据源表(附件复制使用)
             Set<WbsTreeContract> oldTabs = nodeChildAll.stream().filter(f -> (new Integer(2).equals(f.getType()))).collect(Collectors.toSet());
 
-            //获取实体表列对象
-            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 copySql = new StringBuilder();
             /*重置内容*/
             Map<String, Map<String, String>> ekvMap = new HashMap<>();
@@ -1483,10 +1479,20 @@ public class InformationWriteQueryController extends BladeController {
                     //表单所属方,只有勾选了对应的所属方权限才复制数据;勾选了复制数据才能复制,否则只是创建节点、表
                     if (nodeOld.getType() == 2 && StringUtils.isNotEmpty(newData.getInitTableName()) && tabOwner.contains(nodeOld.getTableOwner()) && vo.getIsCopyData() == 1) {
                         String tableName = newData.getInitTableName();
+                        if (StringUtils.isEmpty(tableName)){ //没有实体表名,跳过
+                            continue;
+                        }
+
+                        //获取实体表对应字段
+                        List<QueryProcessDataVO> nodeTabCols = informationQueryService.getNodeChildTabColsAllByTabName(tableName);
+                        //转化为map
+                        Map<String, String> nodeTabColsMap = nodeTabCols.stream().collect(Collectors.toMap(QueryProcessDataVO::getQueryType, QueryProcessDataVO::getAncestors, (key1, key2) -> key2));
+
                         String col = nodeTabColsMap.get(tableName);
                         if (ObjectUtil.isEmpty(col)) { //如果没获取到字段,那么跳过
                             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());
@@ -2298,9 +2304,9 @@ public class InformationWriteQueryController extends BladeController {
                                         StringBuilder copyDataSql = new StringBuilder();
                                         String col = queryProcessDataVO.getAncestors();
                                         String colVal = queryProcessDataVO.getAncestors();
-                                        colVal = colVal.replaceAll("id,p_key_id,", "'" + SnowFlakeUtil.getId() + "' as id,'" + needTab.getPKeyId() + "' as p_key_id,");
+                                        colVal = colVal.replaceAll("id,p_key_id,", "'" + SnowFlakeUtil.getId() + "' as id,'" + objTab.getPKeyId() + "' as p_key_id,");
                                         //delete SQL (先删除旧数据,再新增)
-                                        String delSql = "delete from " + tableName + " where p_key_id = " + needTab.getPKeyId() + " ; ";
+                                        String delSql = "delete from " + tableName + " where p_key_id = " + objTab.getPKeyId() + " ; ";
                                         //insert into SQL
                                         String testColVal = reviseCols(eMap, colVal, oldPKeyId, tableName);
                                         StaticLog.info("KT3356:" + testColVal);