From 1487a187cc4e9daf2b733626929c77e945c926fe Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期一, 30 十月 2023 14:36:56 +0800
Subject: [PATCH] app任务管理组织架构

---
 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DeptUserTree.java        |   35 +++++++++++
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java |    7 ++
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java |   62 +++++++++++++++++++-
 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java         |    6 ++
 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java         |    2 
 ard-work/src/main/java/com/ruoyi/app/task/controller/ArdAppTaskController.java   |   61 ++++++++++++++++----
 6 files changed, 156 insertions(+), 17 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/app/task/controller/ArdAppTaskController.java b/ard-work/src/main/java/com/ruoyi/app/task/controller/ArdAppTaskController.java
index b164ead..5c7a168 100644
--- a/ard-work/src/main/java/com/ruoyi/app/task/controller/ArdAppTaskController.java
+++ b/ard-work/src/main/java/com/ruoyi/app/task/controller/ArdAppTaskController.java
@@ -1,26 +1,22 @@
 package com.ruoyi.app.task.controller;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.servlet.http.HttpServletResponse;
 
-import com.alibaba.fastjson2.JSONObject;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
-import com.ruoyi.alarm.steal.domain.ArdAlarmStealelec;
-import com.ruoyi.app.task.domain.AppParam;
-import com.ruoyi.app.task.domain.ArdAppTaskDetail;
-import com.ruoyi.app.task.domain.WellParam;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.app.task.domain.*;
+import com.ruoyi.common.core.domain.DeptUserTree;
+import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysUserService;
-import com.ruoyi.utils.pagehelper.JpaPageHelper;
-import com.ruoyi.utils.pagehelper.JpaPageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import org.apache.catalina.security.SecurityUtil;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -28,11 +24,9 @@
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.enums.BusinessType;
-import com.ruoyi.app.task.domain.ArdAppTask;
 import com.ruoyi.app.task.service.IArdAppTaskService;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
-import org.springframework.web.multipart.MultipartFile;
 
 /**
  * app浠诲姟绠$悊Controller
@@ -46,6 +40,11 @@
 public class ArdAppTaskController extends BaseController {
     @Autowired
     private IArdAppTaskService ardAppTaskService;
+    @Autowired
+    private ISysUserService sysUserService;
+
+    @Autowired
+    private ISysDeptService sysDeptService;
 
 
     /**
@@ -180,4 +179,40 @@
         return success(ardAppTaskService.likeWell(wellParam));
     }
 
+    @ApiOperation("鎸囨尌绔�-鏌ヨ鏍戝舰缁勭粐鏋舵瀯")
+    @PostMapping(value = "/treeDept")
+    public AjaxResult treeDept() {
+        //鏌ヨ鐢ㄦ埛ID
+        String usersId = SecurityUtils.getUserId();
+        //鏍规嵁userId鏌ヨ閮ㄩ棬Id
+        SysUser sysUser = sysUserService.selectUserById(usersId);
+        //鏍规嵁褰撳墠deptId鎴栬�呭綋鍓嶅強鎵�灞炰笅绾х殑鎵�鏈塪eptId
+        List<Long> deptList = sysDeptService.deptIdBySub(sysUser.getDeptId());
+        //鏌ヨ鎵�鏈夐儴闂ㄤ俊鎭�
+        List<SysDept> sysDeptList = sysDeptService.allByUser(deptList);
+        List<DeptUserTree> deptUserTrees = new ArrayList<>();
+        for (int i = 0; i < sysDeptList.size(); i++) {
+            SysDept sysDept = sysDeptList.get(i);
+            DeptUserTree deptUserTree = new DeptUserTree();
+            deptUserTree.setAncestors(sysDept.getAncestors());
+            deptUserTree.setDeptId(sysDept.getDeptId());
+            deptUserTree.setDeptName(sysDept.getDeptName());
+            deptUserTree.setParentId(sysDept.getParentId());
+            deptUserTrees.add(deptUserTree);
+            QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("dept_id",sysDept.getDeptId());
+            List<SysUser> users = sysUserService.userByDept(sysDept.getDeptId());
+            for (int j = 0; j < users.size(); j++) {
+                SysUser user = users.get(j);
+                DeptUserTree deptUserTree1 = new DeptUserTree();
+                deptUserTree1.setDeptId(user.getDeptId());
+                deptUserTree1.setUserId(user.getUserId());
+                deptUserTree1.setNickName(user.getNickName());
+                deptUserTree1.setParentId(sysDept.getParentId());
+                deptUserTrees.add(deptUserTree1);
+            }
+        }
+        return success(sysDeptService.deptUserTree(deptUserTrees));
+    }
+
 }
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DeptUserTree.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DeptUserTree.java
new file mode 100644
index 0000000..3d00f14
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DeptUserTree.java
@@ -0,0 +1,35 @@
+package com.ruoyi.common.core.domain;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.ruoyi.common.core.domain.TreeDeptWell;
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class DeptUserTree {
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private Long deptId;
+    /** 鐖堕儴闂↖D */
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private Long parentId;
+
+    /** 绁栫骇鍒楄〃 */
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private String ancestors;
+
+    /** 閮ㄩ棬鍚嶇О */
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private String deptName;
+
+    /** 濮撳悕ID */
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private String userId;
+
+    /** 濮撳悕 */
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private String nickName;
+
+    private List<DeptUserTree> children = new ArrayList<>();
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
index 403ffed..47cf6f0 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
@@ -4,6 +4,7 @@
 import java.util.Map;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.common.core.domain.DeptUserTree;
 import com.ruoyi.common.core.domain.TreeDeptWell;
 import com.ruoyi.common.core.domain.TreeSelect;
 import com.ruoyi.common.core.domain.TreeSelectWell;
@@ -145,4 +146,9 @@
      */
     List<TreeDeptWell> wellTree(List<TreeDeptWell> depts);
     List<TreeDeptWell> buildDeptWellTree(List<TreeDeptWell> depts);
+
+    /**
+     * 浜哄憳閮ㄩ棬缁撴瀯鏍戝舰
+     */
+    List<DeptUserTree> deptUserTree(List<DeptUserTree> depts);
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
index 156e22c..ed79e23 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
@@ -236,4 +236,6 @@
 
     List<SysUser> userByDeptList(List<Long> deptList);
 
+    List<SysUser> userByDept(Long deptId);
+
 }
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 0d33856..63a92e1 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
@@ -4,13 +4,10 @@
 import java.util.stream.Collectors;
 
 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 com.ruoyi.common.core.domain.*;
 import org.springframework.stereotype.Service;
 import com.ruoyi.common.annotation.DataScope;
 import com.ruoyi.common.constant.UserConstants;
-import com.ruoyi.common.core.domain.TreeSelect;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysRole;
 import com.ruoyi.common.core.domain.entity.SysUser;
@@ -429,4 +426,61 @@
     {
         return getChildListWell(list, t).size() > 0;
     }
+
+
+
+    @Override
+    public List<DeptUserTree> deptUserTree(List<DeptUserTree> depts)
+    {
+        List<DeptUserTree> returnList = new ArrayList<>();
+        List<Long> tempList = depts.stream().map(DeptUserTree::getDeptId).collect(Collectors.toList());
+        for (DeptUserTree dept : depts)
+        {
+            // 濡傛灉鏄《绾ц妭鐐�, 閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣
+            if (!tempList.contains(dept.getParentId()))
+            {
+                recursionFnDeptUserTree(depts, dept);
+                returnList.add(dept);
+            }
+        }
+        if (returnList.isEmpty())
+        {
+            returnList = depts;
+        }
+        return returnList;
+    }
+
+    private void recursionFnDeptUserTree(List<DeptUserTree> list, DeptUserTree t)
+    {
+        // 寰楀埌瀛愯妭鐐瑰垪琛�
+        if(t.getUserId()==null){
+            List<DeptUserTree> childList = getChildListDeptUserTree(list, t);
+            t.setChildren(childList);
+            for (DeptUserTree tChild : childList) {
+                if (hasChildDeptUserTree(list, tChild)) {
+                    recursionFnDeptUserTree(list, tChild);
+                }
+            }
+        }
+    }
+
+    private List<DeptUserTree> getChildListDeptUserTree(List<DeptUserTree> list, DeptUserTree t)
+    {
+        List<DeptUserTree> tlist = new ArrayList<>();
+        Iterator<DeptUserTree> it = list.iterator();
+        while (it.hasNext())
+        {
+            DeptUserTree n = (DeptUserTree) it.next();
+            if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())
+            {
+                tlist.add(n);
+            }
+        }
+        return tlist;
+    }
+
+    private boolean hasChildDeptUserTree(List<DeptUserTree> list, DeptUserTree t)
+    {
+        return getChildListDeptUserTree(list, t).size() > 0;
+    }
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
index aa41612..a38e204 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
@@ -640,4 +640,11 @@
         queryWrapper.in("dept_id",deptList);
         return userMapper.selectList(queryWrapper);
     }
+
+    @Override
+    public List<SysUser> userByDept(Long deptId) {
+        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("dept_id",deptId);
+        return userMapper.selectList(queryWrapper);
+    }
 }

--
Gitblit v1.9.3