Browse Source

获取区域树

黄远 5 years ago
parent
commit
76a8fec2e0

+ 2 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/dao/entity/AreaCode.java

@@ -1,5 +1,6 @@
 package cn.com.ty.lift.system.user.dao.entity;
 
+import cn.com.ty.lift.system.user.tree.BaseTree;
 import lombok.Data;
 
 /**
@@ -7,7 +8,7 @@ import lombok.Data;
  * @since 2019-12-03 17:17:14
  */
 @Data
-public class AreaCode {
+public class AreaCode extends BaseTree {
 	private Integer id;
 
 	private String code;

+ 4 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/dao/mapper/AreaCodeMapper.java

@@ -4,6 +4,8 @@ import cn.com.ty.lift.system.user.dao.entity.AreaCode;
 import cn.com.xwy.boot.mybatis.MyBatisMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import java.util.List;
+
 /**
  * MyBatis Mapper 接口 - 表:area_code
  * @since 2019-12-03 17:17:14
@@ -21,4 +23,6 @@ public interface AreaCodeMapper extends BaseMapper<AreaCode> {
 	int updateByPrimaryKeySelective(AreaCode record);
 
 	int updateByPrimaryKey(AreaCode record);
+
+    List<AreaCode> getAll();
 }

+ 6 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/AreaCodeService.java

@@ -6,6 +6,7 @@ import cn.com.ty.lift.system.user.dao.mapper.AreaCodeMapper;
 import cn.com.ty.lift.system.user.service.IAreaCodeService;
 import cn.com.ty.lift.system.user.tree.TreeUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -17,9 +18,13 @@ import java.util.List;
  */
 @Service
 public class AreaCodeService extends ServiceImpl<AreaCodeMapper, AreaCode> implements IAreaCodeService {
+
+    @Autowired
+    private AreaCodeMapper areaCodeMapper;
+
     @Override
     public List<AreaCode> areaTree() {
-        List<AreaCode> allAreaCodeList = this.list();
+        List<AreaCode> allAreaCodeList = areaCodeMapper.getAll();
         return TreeUtil.listToTree(allAreaCodeList, ApiConstants.AREA_PARENT_ATTR, ApiConstants.ROOT_AREA_PARENT_ID);
     }
 }

+ 3 - 33
lift-system-service/src/main/java/cn/com/ty/lift/system/user/tree/BaseTree.java

@@ -9,48 +9,18 @@ import java.util.List;
  */
 public class BaseTree {
 
-    private Long id;
-
-    private Long parentId;//父id
-
-    private Integer level;//级别
-
-    private boolean isLeaf;//是否是叶子节点
+    private Object id;
 
     private List children;//子节点
 
-    public Long getId() {
+    public Object getId() {
         return id;
     }
 
-    public void setId(Long id) {
+    public void setId(Object id) {
         this.id = id;
     }
 
-    public Long getParentId() {
-        return parentId;
-    }
-
-    public void setParentId(Long parentId) {
-        this.parentId = parentId;
-    }
-
-    public Integer getLevel() {
-        return level;
-    }
-
-    public void setLevel(Integer level) {
-        this.level = level;
-    }
-
-    public boolean isLeaf() {
-        return isLeaf;
-    }
-
-    public void setLeaf(boolean leaf) {
-        isLeaf = leaf;
-    }
-
     public List getChildren() {
         return children;
     }

+ 1 - 2
lift-system-service/src/main/java/cn/com/ty/lift/system/user/tree/TreeUtil.java

@@ -1,6 +1,5 @@
 package cn.com.ty.lift.system.user.tree;
 
-import cn.com.ty.lift.system.utils.PojoUtils;
 import cn.com.ty.lift.system.utils.ProjectUtils;
 
 import java.util.List;
@@ -24,7 +23,7 @@ public class TreeUtil {
      */
     public static <T> List listToTree(List treeList, String parentAttr, T rootParentId) {
         BaseTree rootBaseTree = new BaseTree();
-        Map parentIdToChild = ProjectUtils.attrToListMap(treeList, PojoUtils.attrGetMethodName(parentAttr), null);
+        Map parentIdToChild = ProjectUtils.attrToListMap(treeList, parentAttr, null);
         getChildren(rootBaseTree, parentIdToChild, rootParentId);
         return rootBaseTree.getChildren();
     }

+ 6 - 0
lift-system-service/src/main/resources/mapper/AreaCodeMapper.xml

@@ -109,4 +109,10 @@
 		where id = #{id,jdbcType=INTEGER}
 	</update>
 
+	<select id="getAll" resultType="cn.com.ty.lift.system.user.dao.entity.AreaCode">
+		select
+		<include refid="Base_Column_List"></include>
+		from area_code
+	</select>
+
 </mapper>