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æè å½ååæå±ä¸çº§çæædeptId 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)); } } 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; /** ç¶é¨é¨ID */ @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<>(); } 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); } 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); } 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; } } 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); } }