From 4e1f489552f7eaf2666e3c0d627f50ecf6c2723d Mon Sep 17 00:00:00 2001
From: zxh <279049017@qq.com>
Date: Thu, 03 Sep 2020 14:25:04 +0800
Subject: [PATCH] 修改树状图的判断

---
 kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java |   40 +++++++++++++++++++++++++++-------------
 1 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java
index d3795a3..3d06eac 100644
--- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java
+++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java
@@ -6,6 +6,7 @@
 import com.kidgrow.common.model.ResultBody;
 import com.kidgrow.common.model.SysOrganization;
 import com.kidgrow.common.service.impl.SuperServiceImpl;
+import com.kidgrow.common.utils.StringUtils;
 import com.kidgrow.redis.util.RedisConstant;
 import com.kidgrow.redis.util.RedisUtils;
 import com.kidgrow.usercenter.mapper.SysOrganizationMapper;
@@ -38,6 +39,7 @@
     RedisUtils redisUtils;
     @Autowired
     SysUserOrgMapper sysUserOrgMapper;
+
     /**
      * 列表
      *
@@ -137,6 +139,12 @@
     @Override
     public ResultBody getTree(Map<String, Object> params) {
         List<SysOrganization> sysOrganizations = baseMapper.selectByMap(params);
+        //查询 ,父类为-1的;即顶级父类
+//        params.put("org_parent_id",Long.valueOf("-1"));
+//        List<SysOrganization> sysOrgs=baseMapper.selectByMap(params);
+//        if (sysOrgs.isEmpty()) {
+//            return ResultBody.ok().data(null);
+//        }
         List<Map<String, Object>> treeData = getTreeData(Long.valueOf("-1"), sysOrganizations);
         return ResultBody.ok().data(treeData);
     }
@@ -144,7 +152,7 @@
     @Override
     public int deleteByUserId(Long userId) {
         Map<String, Object> params = new HashMap<>();
-        params.put("userId", userId);
+        params.put("user_id", userId);
         return sysUserOrgMapper.deleteByMap(params);
     }
 
@@ -158,7 +166,7 @@
     public List<Map<String, Object>> getTreeData(Long MyId, List<SysOrganization> sysOrganizations) {
         List<Map<String, Object>> listMap = new ArrayList<>();
         Map<Long, SysOrganization> collect = sysOrganizations.stream().collect(Collectors.toMap(SysOrganization::getId, SysOrganization -> SysOrganization));
-        List<Long> idList = sysOrganizations.stream().filter(e -> e.getOrgParentId() == MyId).map(e -> e.getId()).collect(Collectors.toList());
+        List<Long> idList = sysOrganizations.stream().filter(e -> MyId.equals(e.getOrgParentId())).map(e -> e.getId()).collect(Collectors.toList());
         for (Long id : idList
         ) {
             Map<String, Object> map = new HashMap<>();
@@ -166,7 +174,9 @@
             map.put("name", collect.get(id).getOrgName());
             map.put("level", collect.get(id).getOrgLevel());
             map.put("parentId", collect.get(id).getOrgParentId());
-            List<Long> childs = sysOrganizations.stream().filter(e -> e.getOrgParentId() == id).map(e -> e.getId()).collect(Collectors.toList());
+            List<Long> childs = sysOrganizations.stream().filter(e ->
+                    id.equals(e.getOrgParentId())
+            ).map(e -> e.getId()).collect(Collectors.toList());
             if (childs.size() > 0) {
                 List<Map<String, Object>> treeData = getTreeData(id, sysOrganizations);
                 map.put("children", treeData);
@@ -230,18 +240,21 @@
             List<SysOrganization> list = baseMapper.selectList(queryWrapper);
             if (list.size() > 0) {
                 SysOrganization sysOrganizationLast = list.get(list.size() - 1);
-                if(sysOrganizationLast.getOrgLevel()>=2){
+                if (sysOrganizationLast.getOrgLevel() >= 2) {
                     String orgCodeLast = sysOrganizationLast.getOrgCode();
-                    //取前部分
-                    String orgCodeLastQianZhui = orgCodeLast.substring(0, orgCodeLast.length() - 3);
-                    //取后部分
-                    Integer codenum = Integer.valueOf(orgCodeLast.substring(orgCodeLast.length() - 3));
-                    String str = "00";
-                    str += (codenum + 1);
-                    String substring = str.substring(str.length() - 3);
-                    return orgCodeLastQianZhui + substring;
-                }else {
+                    if (StringUtils.isNotBlank(orgCodeLast)) {
+                        //取前部分
+                        String orgCodeLastQianZhui = orgCodeLast.substring(0, orgCodeLast.length() - 3);
+                        //取后部分
+                        Integer codenum = Integer.valueOf(orgCodeLast.substring(orgCodeLast.length() - 3));
+                        String str = "00";
+                        str += (codenum + 1);
+                        String substring = str.substring(str.length() - 3);
+                        return orgCodeLastQianZhui + substring;
+                    }
+                } else {
                     String orgCodeLast = sysOrganizationLast.getOrgCode();
+                    if (StringUtils.isNotBlank(orgCodeLast)) {
                     //取前部分
                     String orgCodeLastQianZhui = orgCodeLast.substring(0, orgCodeLast.length() - 7);
                     //取后部分
@@ -250,6 +263,7 @@
                     str += (codenum + 1);
                     String substring = str.substring(str.length() - 7);
                     return orgCodeLastQianZhui + substring;
+                    }
                 }
             } else {
                 String fucode = sysOrg.getOrgCode();

--
Gitblit v1.8.0