From a680fd38300a6c6ca45f9439661e763bd4c82a95 Mon Sep 17 00:00:00 2001 From: lxd <1004405501@qq.com> Date: Fri, 13 Sep 2024 15:45:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B6=85=E5=A3=B0=E5=92=8C?= =?UTF-8?q?=E5=BD=B1=E5=83=8F=E6=9F=A5=E8=AF=A2=E8=AF=8A=E6=96=AD=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/ultrasonic/Tree.java | 1 + .../ultrasonic/ultrasonicController.java | 105 ++++++++++-------- .../dal/ultrasonic/ultrasonicDO.java | 3 + 3 files changed, 65 insertions(+), 44 deletions(-) diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/Tree.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/Tree.java index f975d544b..71df577ac 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/Tree.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/Tree.java @@ -13,6 +13,7 @@ public class Tree { public String tempname; public String examDescription; public String diagResults; + public String dataType; public List children; // public Tree(String id, String cname, String pid,String tempname,String examDescription,String diagResults) { // this.id = id; diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java index 070ca6479..fbd62f079 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java @@ -118,62 +118,79 @@ public class ultrasonicController { ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(filteredList); - List tree = convertJsonToTree(json); + List tree = convertJsonToTree(json,isprivate); return success(tree); } - //返回树结构 - private List convertJsonToTree(String jsonData) { - List> dataList; + //返回树结构 + private List convertJsonToTree(String jsonData,String isprivate) { try { ObjectMapper objectMapper = new ObjectMapper(); - dataList = objectMapper.readValue(jsonData, List.class); + List> dataList = objectMapper.readValue(jsonData, List.class); + Map treeMap = new HashMap<>(); + List privateTrees = new ArrayList<>(); // 私有节点列表 + List publicTrees = new ArrayList<>(); // 公共节点列表 + + for (Map data : dataList) { + String id = (String) data.get("id"); + String pid = (String) data.get("pid"); + String privateId = (String) data.get("privateDoctorId"); + + Tree tree = new Tree(); + tree.id = id; + tree.cname = (String) data.get("examPart"); + tree.pid = pid; + tree.tempname = (String) data.get("templateName"); + tree.examDescription = (String) data.get("examDescription"); + tree.diagResults = (String) data.get("diagResults"); + tree.dataType=(String) data.get("dataType"); + treeMap.put(id, tree); + + if (privateId != null && !privateId.isEmpty()) { + privateTrees.add(tree); // 添加到私有节点列表 + } else if ("0".equals(pid)) { + publicTrees.add(tree); // 添加到公共节点列表 + } + } + if (isprivate.equals("1")) + { + // 构建公共树 + buildTree(privateTrees, "0", treeMap); + // 将私有节点添加到结果列表 + return new ArrayList<>(privateTrees); // + } + else + { + // 构建公共树 + buildTree(publicTrees, "0", treeMap); + // 将私有节点添加到结果列表 + return new ArrayList<>(publicTrees); // + } + + + } catch (JsonProcessingException e) { - e.printStackTrace(); return new ArrayList<>(); } - - Map treeMap = new HashMap<>(); - List treeList = new ArrayList<>(); - for (Map data : dataList) { - String pid = (String) data.get("pid"); - String id = (String) data.get("id"); - String privateId = (String) data.get("privateDoctorId"); - - Tree tree = new Tree(); - tree.id = id; - tree.cname = (String) data.get("examPart"); - tree.pid = pid; - tree.tempname = (String) data.get("templateName"); - tree.examDescription = (String) data.get("examDescription"); - tree.diagResults = (String) data.get("diagResults"); - - treeMap.put(id, tree); - if (pid != null && treeMap.containsKey(pid)) { - Tree parent = treeMap.get(pid); - if (parent.children == null) { - parent.children = new ArrayList<>(); // 初始化 parent.children 列表 - } - parent.children.add(tree); - } else if (privateId != null && !privateId.isEmpty())//判断是否是私有模版 私有的直接加到树里面 - { - treeList.add(tree); - } - - } - - - for (Tree tree : treeMap.values()) { - if ("0".equals(tree.pid)) { - treeList.add(tree); - } - } - - return treeList; } + + private void buildTree(List currentLevelTrees, String parentId, Map treeMap) { + for (Tree tree : currentLevelTrees) { + if (treeMap.containsKey(tree.id)) { + List children = new ArrayList<>(); + for (Tree child : treeMap.values()) { + if (child.pid != null && child.pid.equals(tree.id)) { + children.add(child); + } + } + tree.children = children; + buildTree(children, tree.id, treeMap); // 递归构建子树 + } + } + } @GetMapping("/getimageslist") @Operation(summary = "获取图片列表") @Parameter(name = "orgid", description = "机构ID", required = true, example = "1024") diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/ultrasonic/ultrasonicDO.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/ultrasonic/ultrasonicDO.java index 4b80ef4f0..bfd66c578 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/ultrasonic/ultrasonicDO.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/ultrasonic/ultrasonicDO.java @@ -111,4 +111,7 @@ public class ultrasonicDO { @TableField("updateTime") private Date updateTime; + @TableField("dataType") + private String dataType; + }