Эх сурвалжийг харах

修改公式初始化数据时优先查找当前节点下的数据

lvy 2 сар өмнө
parent
commit
d77b22cc6c

+ 26 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -684,7 +684,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                         return;
                     }
                     List<Map<String, Object>> tableNamePkIdsMaps = this.jdbcTemplate.queryForList(
-                            "select c.init_table_name tableName,c.p_key_id pkId,c.html_url url from" +
+                            "select c.init_table_name tableName,c.p_key_id pkId,c.html_url url,c.p_id from" +
                                     " (select id from m_wbs_tree_contract where contract_id=" + currentNode.getContractId() + " and is_deleted=0 and node_type=6 and tree_code like '" + parent.getTreeCode() + "%' ORDER BY sort) k" +
                                     " join m_wbs_tree_contract c on c.parent_id = k.id " +
                                     "where  c.contract_id=" + currentNode.getContractId() + " and c.is_deleted=0 "
@@ -705,6 +705,31 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                                 }
                                 List<Map<String, Object>> tableDatas = this.jdbcTemplate.queryForList("select * from " + tn + " where p_key_id in (" + targetIds + ")");
                                 String tmp = elementInfo == null ? "" : StringUtils.handleNull(elementInfo.get("ename"));
+                                // 优先查找当前节点下的元素
+                                if (!tableDatas.isEmpty()) {
+                                    Map<Long, Long> map = new HashMap<>();
+                                    tableNamePkIdsMaps.forEach(m -> {
+                                        if (StringUtils.isEquals(m.get("tableName"), tn)) {
+                                            Object o = m.get("pkId");
+                                            Object o1 = m.get("p_id");
+                                            if(o instanceof Long && currentNode.getPkId().equals(o1)) {
+                                                map.put((Long) o, 1L);
+                                            }
+                                        }
+                                    });
+                                    if (!map.isEmpty()) {
+                                        List<Map<String, Object>> datas = tableDatas.stream().filter(t -> {
+                                            Object pKeyId = t.get("p_key_id");
+                                            if (pKeyId instanceof Long) {
+                                                return map.containsKey(pKeyId);
+                                            }
+                                            return false;
+                                        }).collect(Collectors.toList());
+                                        if (!datas.isEmpty()) {
+                                            tableDatas = datas;
+                                        }
+                                    }
+                                }
                                 fill(tableDatas, removeList, tn, key, tmp, tec);
                             }
                         });