Parcourir la source

人员部门筛选功能调整

user5 il y a 2 ans
Parent
commit
ac1fcb3ed8

+ 18 - 9
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/UserController.java

@@ -153,8 +153,9 @@ public class UserController {
     @GetMapping("list")
     public ResponseEntity list(UserDTO userDTO, Page <UserDTO> page) throws Exception {
         QueryWrapper <UserDTO> queryWrapper = QueryWrapperGenerator.buildQueryCondition ( userDTO, UserDTO.class );
+        OfficeDTO officeDTO1 = UserUtils.getCurrentUserDTO().getOfficeDTO();
         // 管理员查询不限制
-        /*if (!UserUtils.getCurrentUserDTO().isAdmin()) {
+        if (!UserUtils.getCurrentUserDTO().isAdmin()) {
             queryWrapper.isNull("a.is_admin");
             if (ObjectUtil.isNotEmpty(userDTO)){
                 // 当不是精确的部门查询时,再添加下面的筛选条件
@@ -163,18 +164,26 @@ public class UserController {
                         // 根据当前用户的部门id找到此部门的ids
                         String ids = officeService.getById(UserUtils.getCurrentUserDTO().getOfficeDTO().getId()).getParentIds();
                         // 根据ids分隔后的index[2],找到当前用户的所属公司id
+                        String companyId = null;
                         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);
+                        if(split.length>2){
+                            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);
+                        }else{
+                            companyId = officeDTO1.getId();
+                            // 添加筛选条件为这些部门的id
+                            queryWrapper.in("a.office_id",companyId);
+                        }
                     }
                 }
             }
-        }*/
+        }
         if (ObjectUtil.isNotEmpty(userDTO)) {
             // 当certType传值时,获取拥有此资格证类型的人员
             if (StringUtils.isNotBlank(userDTO.getCertType())) {

+ 12 - 5
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/OfficeService.java

@@ -60,9 +60,9 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
             OfficeDTO officeDTO = UserUtils.getCurrentUserDTO().getOfficeDTO();
             // 排除管理员
             if (!UserUtils.getCurrentUserDTO().isAdmin()){
-                /*if(null != officeDTO && StringUtils.isNotBlank(officeDTO.getParentIds()) && !officeDTO.getParentIds().contains("1602911406782988290")){
+                if(null != officeDTO && StringUtils.isNotBlank(officeDTO.getParentIds()) && !officeDTO.getParentIds().contains("1602911406782988290")){
                     offices = this.getCompanyFromTree(offices);
-                }*/
+                }
             }
         }
         return offices;
@@ -74,20 +74,27 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
     public List<OfficeDTO> getCompanyFromTree(List<OfficeDTO> rootTrees){
         // 当前登录人的集团id
         String corporationId = UserUtils.getCurrentUserDTO().getCompanyDTO().getId();
+        OfficeDTO officeDTO1 = UserUtils.getCurrentUserDTO().getOfficeDTO();
         // 公司id
         String parentIds = officeMapper.selectById(UserUtils.getCurrentUserDTO().getOfficeDTO().getId()).getParentIds();
+        String companyId = null;
         String[] split = parentIds.split(",");
-        String companyId = split[2];
+        if(split.length>2){
+            companyId = split[2];
+        }else{
+            companyId = officeDTO1.getId();
+        }
 
         AtomicReference<OfficeDTO> officeDTO = new AtomicReference<>(new OfficeDTO());
         if (CollectionUtil.isNotEmpty(rootTrees)) {
+            String finalCompanyId = companyId;
             rootTrees.stream().forEach(item->{
                 if(item.getId().equals(corporationId)){  // 找到登录人的集团
                     officeDTO.set(item);
-                    if (CollectionUtil.isNotEmpty(item.getChildren())&&!"".equals(companyId)){
+                    if (CollectionUtil.isNotEmpty(item.getChildren())&&!"".equals(finalCompanyId)){
                         List<OfficeDTO> companys = new ArrayList<>();
                         item.getChildren().stream().forEach(child->{
-                            if(child.getId().equals(companyId)){ // 找到登录人的公司
+                            if(child.getId().equals(finalCompanyId)){ // 找到登录人的公司
                                 companys.add(child);
                             }
                         });