diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryDTO.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryDTO.java index 3d03bf7c..85ea6f35 100644 --- a/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryDTO.java +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryDTO.java @@ -17,7 +17,6 @@ package com.elink.esua.epdc.dto; -import com.elink.esua.epdc.commons.tools.utils.TreeNode; import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/TreeNode.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/TreeNode.java new file mode 100644 index 00000000..4a1628fd --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/TreeNode.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + * + * https://www.renren.io + * + * 版权所有,侵权必究! + */ + +package com.elink.esua.epdc.dto; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 树节点,所有需要实现树节点的,都需要继承该类 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +public class TreeNode implements Serializable { + private static final long serialVersionUID = 1L; + /** + * 主键 + */ + private String id; + /** + * 上级ID + */ + private String pid; + /** + * 子节点列表 + */ + private List children = new ArrayList<>(); + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/dao/ModuleCategoryDao.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/dao/ModuleCategoryDao.java index a3f7b66b..15978a75 100644 --- a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/dao/ModuleCategoryDao.java +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/dao/ModuleCategoryDao.java @@ -33,8 +33,28 @@ import java.util.Map; */ @Mapper public interface ModuleCategoryDao extends BaseDao { - + /** + * @Description 获取列表 + * @Author songyunpeng + * @Date 2020/10/29 + * @Param [params] + * @return java.util.List + **/ List getList(Map params); - + /** + * @Description 查询类别tree + * @Author songyunpeng + * @Date 2020/10/29 + * @Param [] + * @return java.util.List + **/ List selectListCategoryTreeDTO(); + /** + * @Description 单条查询 + * @Author songyunpeng + * @Date 2020/10/29 + * @Param [id] + * @return com.elink.esua.epdc.modules.moduleCategory.entity.ModuleCategoryEntity + **/ + ModuleCategoryEntity getById(String id); } \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/entity/ModuleCategoryEntity.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/entity/ModuleCategoryEntity.java index cb1e80ef..10db246c 100644 --- a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/entity/ModuleCategoryEntity.java +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/entity/ModuleCategoryEntity.java @@ -17,14 +17,12 @@ package com.elink.esua.epdc.modules.moduleCategory.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; - import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Date; - /** * 模块类别表 模块类别表 * @@ -93,4 +91,16 @@ public class ModuleCategoryEntity extends BaseEpdcEntity { */ private String enableFlag; + /** + * 上级部门名称 + */ + @TableField(exist = false) + private String parentName; + + @TableField(exist = false) + private String value; + + @TableField(exist = false) + private String label; + } \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/impl/ModuleCategoryServiceImpl.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/impl/ModuleCategoryServiceImpl.java index ea91c2ca..e709a462 100644 --- a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/impl/ModuleCategoryServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/impl/ModuleCategoryServiceImpl.java @@ -22,14 +22,12 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; -import com.elink.esua.epdc.commons.tools.constant.Constant; import com.elink.esua.epdc.commons.tools.constant.FieldConstant; import com.elink.esua.epdc.commons.tools.exception.ErrorCode; import com.elink.esua.epdc.commons.tools.exception.RenException; import com.elink.esua.epdc.commons.tools.page.PageData; import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; import com.elink.esua.epdc.commons.tools.utils.Result; -import com.elink.esua.epdc.commons.tools.utils.TreeUtils; import com.elink.esua.epdc.dto.CategoryOption; import com.elink.esua.epdc.dto.ModuleCategoryDTO; import com.elink.esua.epdc.dto.ModuleCategoryTreeDTO; @@ -37,6 +35,7 @@ import com.elink.esua.epdc.modules.moduleCategory.dao.ModuleCategoryDao; import com.elink.esua.epdc.modules.moduleCategory.entity.ModuleCategoryEntity; import com.elink.esua.epdc.modules.moduleCategory.redis.ModuleCategoryRedis; import com.elink.esua.epdc.modules.moduleCategory.service.ModuleCategoryService; +import com.elink.esua.epdc.modules.moduleCategory.utils.TreeUtils; import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -86,7 +85,11 @@ public class ModuleCategoryServiceImpl extends BaseServiceImpl getPidListByPid(String pid) { //顶级部门,无上级部门 - if (Constant.CATEGORY_ROOT.equals(pid)) { + if ("0".equals(pid)) { return new ArrayList<>(); } @@ -146,7 +149,7 @@ public class ModuleCategoryServiceImpl extends BaseServiceImpl map, List pCategoryEntityList) { //顶级,无上级 - if (Constant.CATEGORY_ROOT.equals(pid)) { + if ("0".equals(pid)) { return; } //上级存在 diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/utils/TreeUtils.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/utils/TreeUtils.java new file mode 100644 index 00000000..8fc66f38 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/utils/TreeUtils.java @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + * + * https://www.renren.io + * + * 版权所有,侵权必究! + */ + +package com.elink.esua.epdc.modules.moduleCategory.utils; + +import com.elink.esua.epdc.commons.tools.validator.AssertUtils; +import com.elink.esua.epdc.dto.TreeNode; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 树形结构工具类,如:菜单、部门等 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +public class TreeUtils { + + /** + * 根据pid,构建树节点 + */ + public static List build(List treeNodes, String pid) { + //pid不能为空 + AssertUtils.isNull(pid, "pid"); + + List treeList = new ArrayList<>(); + for(T treeNode : treeNodes) { + if (pid.equals(treeNode.getPid())) { + treeList.add(findChildren(treeNodes, treeNode)); + } + } + + return treeList; + } + + /** + * 查找子节点 + */ + private static T findChildren(List treeNodes, T rootNode) { + for(T treeNode : treeNodes) { + if(rootNode.getId().equals(treeNode.getPid())) { + rootNode.getChildren().add(findChildren(treeNodes, treeNode)); + } + } + return rootNode; + } + + /** + * 构建树节点 + */ + public static List build(List treeNodes) { + List result = new ArrayList<>(); + + //list转map + Map nodeMap = new LinkedHashMap<>(treeNodes.size()); + for(T treeNode : treeNodes){ + nodeMap.put(treeNode.getId(), treeNode); + } + + for(T node : nodeMap.values()) { + T parent = nodeMap.get(node.getPid()); + if(parent != null && !(node.getId().equals(parent.getId()))){ + parent.getChildren().add(node); + continue; + } + + result.add(node); + } + + return result; + } + +} diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml index 2f456d17..8bc29a19 100644 --- a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml @@ -42,6 +42,10 @@ ORDER BY t1.sort ASC + \ No newline at end of file