From 1f19fc38b37ed1aa96802702ca406ab740a8aa6c Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期四, 19 十月 2023 15:35:49 +0800
Subject: [PATCH] RTU列表

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
index bdd0df7..0d33856 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -1,10 +1,12 @@
 package com.ruoyi.system.service.impl;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
-import org.springframework.beans.factory.annotation.Autowired;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.core.domain.HealthVo;
+import com.ruoyi.common.core.domain.TreeDeptWell;
+import com.ruoyi.common.core.domain.TreeSelectWell;
 import org.springframework.stereotype.Service;
 import com.ruoyi.common.annotation.DataScope;
 import com.ruoyi.common.constant.UserConstants;
@@ -21,6 +23,8 @@
 import com.ruoyi.system.mapper.SysRoleMapper;
 import com.ruoyi.system.service.ISysDeptService;
 
+import javax.annotation.Resource;
+
 /**
  * 閮ㄩ棬绠$悊 鏈嶅姟瀹炵幇
  * 
@@ -29,10 +33,10 @@
 @Service
 public class SysDeptServiceImpl implements ISysDeptService
 {
-    @Autowired
+    @Resource
     private SysDeptMapper deptMapper;
 
-    @Autowired
+    @Resource
     private SysRoleMapper roleMapper;
 
     /**
@@ -335,4 +339,94 @@
     {
         return getChildList(list, t).size() > 0;
     }
+
+    @Override
+    public List<Long> deptIdBySub(Long deptId) {
+        QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("dept_id").apply("string_to_array( ancestors, ',' ) @> ARRAY [ '"+deptId+"']");
+//                in("cast(ancestors as bigint)",deptId);
+        List<SysDept> list = deptMapper.selectList(queryWrapper);
+        List<Long> deptList = new ArrayList<>();
+        deptList.add(deptId);
+        for (int i = 0; i < list.size(); i++) {
+            deptList.add(list.get(i).getDeptId());
+        }
+        return deptList;
+    }
+
+    @Override
+    public List<SysDept> all() {
+        return deptMapper.selectList(null);
+    }
+
+    @Override
+    public List<SysDept> allByUser(List<Long> deptList) {
+        QueryWrapper<SysDept> queryWrapper = new QueryWrapper();
+        queryWrapper.in("dept_id",deptList);
+        return deptMapper.selectList(queryWrapper);
+    }
+
+    @Override
+    public List<TreeDeptWell> wellTree(List<TreeDeptWell> depts) {
+        List<TreeDeptWell> deptTrees = buildDeptWellTree(depts);
+        return deptTrees;
+//        return deptTrees.stream().map(TreeSelectWell::new).collect(Collectors.toList());
+    }
+
+    @Override
+    public List<TreeDeptWell> buildDeptWellTree(List<TreeDeptWell> depts)
+    {
+        List<TreeDeptWell> returnList = new ArrayList<TreeDeptWell>();
+        List<Long> tempList = depts.stream().map(TreeDeptWell::getDeptId).collect(Collectors.toList());
+        for (TreeDeptWell dept : depts)
+        {
+            // 濡傛灉鏄《绾ц妭鐐�, 閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣
+            if (!tempList.contains(dept.getParentId()))
+            {
+                recursionFnWell(depts, dept);
+                returnList.add(dept);
+            }
+        }
+        if (returnList.isEmpty())
+        {
+            returnList = depts;
+        }
+        return returnList;
+    }
+
+    private void recursionFnWell(List<TreeDeptWell> list, TreeDeptWell t)
+    {
+        // 寰楀埌瀛愯妭鐐瑰垪琛�
+        if(t.getId() == null){
+            List<TreeDeptWell> childList = getChildListWell(list, t);
+            t.setChildren(childList);
+            for (TreeDeptWell tChild : childList)
+            {
+                if (hasChildWell(list, tChild))
+                {
+                    recursionFnWell(list, tChild);
+                }
+            }
+        }
+    }
+
+    private List<TreeDeptWell> getChildListWell(List<TreeDeptWell> list, TreeDeptWell t)
+    {
+        List<TreeDeptWell> tlist = new ArrayList<TreeDeptWell>();
+        Iterator<TreeDeptWell> it = list.iterator();
+        while (it.hasNext())
+        {
+            TreeDeptWell n = (TreeDeptWell) it.next();
+            if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())
+            {
+                tlist.add(n);
+            }
+        }
+        return tlist;
+    }
+
+    private boolean hasChildWell(List<TreeDeptWell> list, TreeDeptWell t)
+    {
+        return getChildListWell(list, t).size() > 0;
+    }
 }

--
Gitblit v1.9.3