Prechádzať zdrojové kódy

用户选择组件调整

lizhenhao 2 rokov pred
rodič
commit
fb809d7f1a

+ 1 - 1
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/OfficeController.java

@@ -93,7 +93,7 @@ public class OfficeController {
     @GetMapping("treeData")
     public ResponseEntity treeData(@RequestParam(required = false) String extId, @RequestParam(required = false) String type, @RequestParam(required = false, defaultValue = CommonConstants.NO) String showAll) {
         List<OfficeDTO> list = officeWrapper.toDTO (officeService.list ());
-        List rootTree = officeService.getRootTree (list, extId, type, showAll);
+        List rootTree = officeService.getRootTree (list, extId, type, showAll, "1");
         return ResponseEntity.ok (rootTree);
     }
 

+ 24 - 2
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/UserController.java

@@ -142,6 +142,28 @@ public class UserController {
     @GetMapping("list")
     public ResponseEntity list(UserDTO userDTO, Page <UserDTO> page) throws Exception {
         QueryWrapper <UserDTO> queryWrapper = QueryWrapperGenerator.buildQueryCondition ( userDTO, UserDTO.class );
+        // 管理员查询不限制
+        if (!UserUtils.getCurrentUserDTO().isAdmin()) {
+            queryWrapper.ne("a.id","1");
+            if (ObjectUtil.isNotEmpty(userDTO)){
+                // 当不是精确的部门查询时,再添加下面的筛选条件
+                if (ObjectUtil.isNotEmpty(userDTO.getOfficeDTO())) {
+                    if(StringUtils.isBlank(userDTO.getOfficeDTO().getId())){
+                        // 根据当前用户的部门id找到此部门的ids
+                        String ids = officeService.getById(UserUtils.getCurrentUserDTO().getOfficeDTO().getId()).getParentIds();
+                        // 根据ids分隔后的index[2],找到当前用户的所属公司id
+                        String[] split = ids.split(",");
+                        String companyId = split[2];
+                        // 根据公司id,找到此公司下的所有部门
+                        List<Office> officeList = officeService.list(new QueryWrapper<Office>().lambda().eq(Office::getParentId, companyId));
+                        // 拿到这些部门的id
+                        List<String> officeIdList = officeList.stream().distinct().map(Office::getId).collect(Collectors.toList());
+                        // 添加筛选条件为这些部门的id
+                        queryWrapper.in("a.office_id",officeIdList);
+                    }
+                }
+            }
+        }
         IPage <UserDTO> result = userService.findPage ( page, queryWrapper );
         return ResponseEntity.ok ( result );
     }
@@ -491,7 +513,7 @@ public class UserController {
         //根据部门查询对应部门下的所有数据
         List<OfficeDTO> officeDTOList = userService.disposeUserOffice(list,type);
         list.addAll(officeDTOList);
-        List rootTree = officeService.getRootTree (list, extId, type, showAll);
+        List rootTree = officeService.getRootTree (list, extId, type, showAll, "1");
         return ResponseEntity.ok (rootTree);
     }
 
@@ -519,7 +541,7 @@ public class UserController {
             List<OfficeDTO> officeDTOList = userService.getUserByOffice(officeIds,type);
             list.addAll(officeDTOList);
         }
-        List rootTree = officeService.getRootTree (list, extId, type, showAll);
+        List rootTree = officeService.getRootTree (list, extId, type, showAll, "1");
         return ResponseEntity.ok (rootTree);
     }
 

+ 45 - 3
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/OfficeService.java

@@ -3,7 +3,7 @@
  */
 package com.jeeplus.sys.service;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import cn.hutool.core.collection.CollectionUtil;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.jeeplus.core.service.TreeService;
@@ -12,15 +12,18 @@ import com.jeeplus.sys.constant.enums.OfficeTypeEnum;
 import com.jeeplus.sys.domain.Office;
 import com.jeeplus.sys.mapper.OfficeMapper;
 import com.jeeplus.sys.service.dto.OfficeDTO;
+import com.jeeplus.sys.service.dto.UserDTO;
 import com.jeeplus.sys.service.mapstruct.OfficeWrapper;
+import com.jeeplus.sys.utils.UserUtils;
 import org.apache.commons.lang.StringUtils;
-import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * 机构Service
@@ -37,7 +40,7 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
     @Autowired
     private OfficeMapper officeMapper;
 
-    public List <OfficeDTO> getRootTree(List<OfficeDTO> list, String extId, String type, String showAll) {
+    public List <OfficeDTO> getRootTree(List<OfficeDTO> list, String extId, String type, String showAll, String showMyOffice) {
         List<OfficeDTO> offices = Lists.newArrayList ();
         List<OfficeDTO> rootTrees = officeWrapper.toDTO (super.getChildren (new Office (OfficeDTO.getRootId ())));
         for (OfficeDTO root : rootTrees) {
@@ -47,9 +50,48 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
                 offices.addAll (officeList);
             }
         }
+        if (com.jeeplus.sys.utils.StringUtils.isNotBlank(showMyOffice)) {
+            // 排除管理员
+            if (!UserUtils.getCurrentUserDTO().isAdmin()){
+                offices = this.getCompanyFromTree(offices);
+            }
+        }
         return offices;
     }
 
+    /**
+     * 在tree数据中找到当前登录人的“集团”以及“公司”
+     */
+    public List<OfficeDTO> getCompanyFromTree(List<OfficeDTO> rootTrees){
+        // 当前登录人的集团id
+        String corporationId = UserUtils.getCurrentUserDTO().getCompanyDTO().getId();
+        // 公司id
+        String parentIds = officeMapper.selectById(UserUtils.getCurrentUserDTO().getOfficeDTO().getId()).getParentIds();
+        String[] split = parentIds.split(",");
+        String companyId = split[2];
+
+        AtomicReference<OfficeDTO> officeDTO = new AtomicReference<>(new OfficeDTO());
+        if (CollectionUtil.isNotEmpty(rootTrees)) {
+            rootTrees.stream().forEach(item->{
+                if(item.getId().equals(corporationId)){  // 找到登录人的集团
+                    officeDTO.set(item);
+                    if (CollectionUtil.isNotEmpty(item.getChildren())&&!"".equals(companyId)){
+                        List<OfficeDTO> companys = new ArrayList<>();
+                        item.getChildren().stream().forEach(child->{
+                            if(child.getId().equals(companyId)){ // 找到登录人的公司
+                                companys.add(child);
+                            }
+                        });
+                        officeDTO.get().setChildren(companys);
+                    }
+                }
+            });
+        }
+        List<OfficeDTO> trees = new ArrayList<>();
+        trees.add(officeDTO.get());
+        return trees;
+    }
+
 
     public List<OfficeDTO> formatListToTree(OfficeDTO root, List<OfficeDTO> allList, String extId, String type, String showAll) {
         String rootId = root.getId ();