Sfoglia il codice sorgente

2022-09-22 修改查询树状部门列表,子项为空的时候,返回空数组。

zhuchangxue 3 anni fa
parent
commit
920e72c5e2

+ 1 - 1
zd-api/zd-api-system/src/main/java/com/zd/system/api/domain/SysUser.java

@@ -102,7 +102,7 @@ public class SysUser extends BaseEntity {
     /**
      * 最后登录时间
      */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
     private Date loginDate;
 

+ 1 - 1
zd-modules/zd-modules-system/src/main/java/com/zd/system/controller/SysDeptController.java

@@ -154,7 +154,7 @@ public class SysDeptController extends BaseController {
     @GetMapping("/treeselectByUser")
     public AjaxResult treeselectByUser(SysDept dept) {
         List<SysDept> depts = deptService.treeselectByUser(dept);
-        return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
+        return AjaxResult.success(deptService.buildDeptTreeSelectByNo(depts));
     }
 
     /**

+ 115 - 0
zd-modules/zd-modules-system/src/main/java/com/zd/system/domain/vo/TreeSelectVo.java

@@ -0,0 +1,115 @@
+package com.zd.system.domain.vo;
+
+import com.zd.system.api.domain.SysDept;
+import com.zd.system.domain.SysMenu;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Treeselect树结构实体类
+ *
+ * @author zd
+ */
+public class TreeSelectVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 节点ID
+     */
+    private Long id;
+
+    /**
+     * 节点名称
+     */
+    private String label;
+
+    /**
+     * 父部门ID
+     */
+    private Long parentId;
+
+    /**
+     * 祖级列表
+     */
+    private String ancestors;
+
+    /**
+     * 部门编号
+     */
+    private String deptNum;
+
+    /**
+     * 子节点
+     */
+//    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private List<TreeSelectVo> children;
+
+    public TreeSelectVo() {
+
+    }
+
+    public TreeSelectVo(SysDept dept) {
+        this.id = dept.getDeptId();
+        this.label = dept.getDeptName();
+        this.parentId = dept.getParentId();
+        this.ancestors = dept.getAncestors();
+        this.deptNum = dept.getDeptNum();
+        this.children = dept.getChildren().stream().map(TreeSelectVo::new).collect(Collectors.toList());
+    }
+
+    public TreeSelectVo(SysMenu menu) {
+        this.id = menu.getMenuId();
+        this.label = menu.getMenuName();
+        this.children = menu.getChildren().stream().map(TreeSelectVo::new).collect(Collectors.toList());
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public List<TreeSelectVo> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<TreeSelectVo> children) {
+        this.children = children;
+    }
+
+    public Long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Long parentId) {
+        this.parentId = parentId;
+    }
+
+    public String getAncestors() {
+        return ancestors;
+    }
+
+    public void setAncestors(String ancestors) {
+        this.ancestors = ancestors;
+    }
+
+    public String getDeptNum() {
+        return deptNum;
+    }
+
+    public void setDeptNum(String deptNum) {
+        this.deptNum = deptNum;
+    }
+}

+ 10 - 0
zd-modules/zd-modules-system/src/main/java/com/zd/system/service/ISysDeptService.java

@@ -6,6 +6,7 @@ import java.util.Map;
 import com.zd.system.api.domain.SysDept;
 import com.zd.system.api.domain.SysDeptVO;
 import com.zd.system.domain.vo.TreeSelect;
+import com.zd.system.domain.vo.TreeSelectVo;
 
 /**
  * 部门管理 服务层
@@ -53,6 +54,15 @@ public interface ISysDeptService {
      */
     public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts);
 
+
+    /**
+     * 构建前端所需要下拉树结构(包涵空的子节点)
+     *
+     * @param depts 部门列表
+     * @return 下拉树结构列表
+     */
+    public List<TreeSelectVo> buildDeptTreeSelectByNo(List<SysDept> depts);
+
     /**
      * 根据角色ID查询部门树信息
      *

+ 7 - 0
zd-modules/zd-modules-system/src/main/java/com/zd/system/service/impl/SysDeptServiceImpl.java

@@ -7,6 +7,7 @@ import com.zd.common.core.domain.per.PerPrefix;
 import com.zd.common.core.utils.SecurityUtils;
 import com.zd.common.security.service.TokenService;
 import com.zd.system.api.domain.SysDeptVO;
+import com.zd.system.domain.vo.TreeSelectVo;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -122,6 +123,12 @@ public class SysDeptServiceImpl implements ISysDeptService {
         return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
     }
 
+    @Override
+    public List <TreeSelectVo> buildDeptTreeSelectByNo(List <SysDept> depts) {
+        List<SysDept> deptTrees = buildDeptTree(depts);
+        return deptTrees.stream().map(TreeSelectVo::new).collect(Collectors.toList());
+    }
+
     /**
      * 根据角色ID查询部门树信息
      *