Ver código fonte

人员、机构选择组件调整

lizhenhao 2 anos atrás
pai
commit
ed374a7995

+ 63 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/reimbursement/reimbursementInfo/service/ReimbursementInfoService.java

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
 import com.jeeplus.core.query.QueryWrapperGenerator;
+import com.jeeplus.sys.domain.Office;
+import com.jeeplus.sys.mapper.OfficeMapper;
 import com.jeeplus.sys.service.dto.UserDTO;
 import com.jeeplus.sys.utils.StringUtils;
 import com.jeeplus.sys.utils.UserUtils;
@@ -28,6 +30,7 @@ import com.jeeplus.test.workContract.service.WorkContractService;
 import com.jeeplus.test.workContract.service.dto.WorkAttachmentDto;
 import com.jeeplus.test.workContract.service.dto.WorkContractInfoDto;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -55,6 +58,9 @@ public class ReimbursementInfoService {
     @Resource
     private WorkContractService workContractService;
 
+    @Autowired
+    private OfficeMapper officeMapper;
+
     /**
      * 列表查询
      */
@@ -292,6 +298,62 @@ public class ReimbursementInfoService {
         List<TreeUserDto> list = new ArrayList<>();
         // 查询部门
         List<TreeUserDto> officeList = infoMapper.findOfficeList();
+        List<TreeUserDto> filterList = new ArrayList<>();
+        String parentIds = officeMapper.selectById(UserUtils.getCurrentUserDTO().getOfficeDTO().getId()).getParentIds();
+        String[] split = parentIds.split(",");
+        if(split.length>2){
+            // 公司id
+            String companyId = split[2];
+            // 过滤出登录人所属公司和集团
+            officeList.stream().forEach(o -> {
+                if (split[2].equals(o.getId())) {
+                    filterList.add(o);
+                } else if(split[1].equals(o.getId())) {
+                    filterList.add(o);
+                }
+            });
+            // 根据公司id找到其下部门
+            List<Office> oList = officeMapper.selectList(new QueryWrapper<Office>().lambda().eq(Office::getParentId, companyId));
+            // 过滤出这些部门
+            oList.stream().forEach(item -> {
+                officeList.stream().forEach(o -> {
+                    if (item.getId().equals(o.getId())) {
+                        filterList.add(o);
+                    }
+                });
+            });
+            // 找到所有的公有部门
+            List<Office> publicOfficeList = officeMapper.selectList(new QueryWrapper<Office>().lambda().eq(Office::getIsPublic, "1"));
+            // 过滤出这些部门
+            publicOfficeList.stream().forEach(item -> {
+                officeList.stream().forEach(o -> {
+                    if (item.getId().equals(o.getId())) {
+                        filterList.add(o);
+                    }
+                });
+            });
+        }else{
+            // 公司id
+            String companyId = UserUtils.getCurrentUserDTO().getOfficeDTO().getId();
+            // 过滤出登录人所属公司和集团
+            officeList.stream().forEach(o -> {
+                if (companyId.equals(o.getId())) {
+                    filterList.add(o);
+                } else if(split[1].equals(o.getId()) && !split[1].equals(companyId)) {
+                    filterList.add(o);
+                }
+            });
+            // 找到所有的公有部门
+            List<Office> publicOfficeList = officeMapper.selectList(new QueryWrapper<Office>().lambda().eq(Office::getIsPublic, "1"));
+            // 过滤出这些部门
+            publicOfficeList.stream().forEach(item -> {
+                officeList.stream().forEach(o -> {
+                    if (item.getId().equals(o.getId())) {
+                        filterList.add(o);
+                    }
+                });
+            });
+        }
         /*if (CollectionUtils.isNotEmpty(officeList)) {
             list.addAll(officeList);
         }*/
@@ -301,7 +363,7 @@ public class ReimbursementInfoService {
         /*if (CollectionUtils.isNotEmpty(userList)) {
             list.addAll(userList);
         }*/
-        list = disposeUserTree(userList, officeList);
+        list = disposeUserTree(userList, filterList);
         for (TreeUserDto officeDto : officeList) {
             if("0".equals(officeDto.getParentId())){
                 list.add(officeDto);

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

@@ -3,12 +3,14 @@
  */
 package com.jeeplus.sys.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
 import com.jeeplus.aop.demo.annotation.DemoMode;
 import com.jeeplus.aop.logging.annotation.ApiLog;
 import com.jeeplus.sys.constant.CommonConstants;
+import com.jeeplus.sys.domain.Office;
 import com.jeeplus.sys.service.OfficeService;
 import com.jeeplus.sys.service.dto.OfficeDTO;
 import com.jeeplus.sys.service.mapstruct.OfficeWrapper;
@@ -94,7 +96,7 @@ public class OfficeController {
     @ApiLog("获取部门数据")
     @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<OfficeDTO> list = officeWrapper.toDTO (officeService.list (new QueryWrapper<Office>().lambda().eq(Office::getDelFlag,"0")));
         List rootTree = officeService.getRootTree (list, extId, type, showAll, "1");
         return ResponseEntity.ok (rootTree);
     }

+ 13 - 8
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/controller/UserController.java

@@ -7,6 +7,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.aliyun.oss.OSSClient;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -153,7 +154,6 @@ 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()) {
             queryWrapper.isNull("a.is_admin");
@@ -168,17 +168,23 @@ public class UserController {
                         String[] split = ids.split(",");
                         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
+                            List<String> officePublicIdList = officeService.list(new LambdaQueryWrapper<Office>().eq(Office::getIsPublic,"1")).stream().map(Office::getId).collect(Collectors.toList());
+                            // 拿到直属公司的id
+                            officeIdList.add(companyId);
+                            // 最后得到的所有部门的id
+                            officeIdList.addAll(officePublicIdList);
+                            List<String> lastIds = officeIdList.stream().distinct().collect(Collectors.toList());
                             // 添加筛选条件为这些部门的id
-                            queryWrapper.in("a.office_id",officeIdList);
+                            queryWrapper.in("a.office_id",lastIds);
                         }else{
-                            companyId = officeDTO1.getId();
-                            // 添加筛选条件为这些部门的id
-                            queryWrapper.in("a.office_id",companyId);
+                            companyId = UserUtils.getCurrentUserDTO().getOfficeDTO().getId();
+                            // 添加筛选条件为当前登录人部门的id
+                            queryWrapper.eq("a.office_id",companyId);
                         }
                     }
                 }
@@ -584,8 +590,7 @@ public class UserController {
         List<OfficeDTO> list = officeService.getOfficeAllByOfficeName (officeName);
         if(list.size()>0){
             List<String> officeIds = Lists.newArrayList();
-            for (OfficeDTO info :
-                    list) {
+            for (OfficeDTO info : list) {
                 info.setTypeFlag(true);
                 officeIds.add(info.getId());
             }

+ 5 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/domain/Office.java

@@ -82,6 +82,11 @@ public class Office extends TreeEntity<Office> {
     private String remarks;
 
     /**
+     * 0为私有,1为公有
+     */
+    private String isPublic;
+
+    /**
      * 构造函数
      */
     public Office () {

+ 5 - 1
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/xml/OfficeMapper.xml

@@ -26,7 +26,8 @@
 		a.update_by as "updateBy.id",
 		a.update_date as "updateDate",
         a.remarks as "remarks",
-        a.del_flag as "delFlag"
+        a.del_flag as "delFlag",
+        a.is_public as "isPublic"
     </sql>
 
     <select id="getOfficeByName" resultType="com.jeeplus.sys.service.dto.OfficeDTO">
@@ -47,10 +48,13 @@
         <include refid="officeColumns"/>
         from sys_office a
         <where>
+            a.del_flag = 0
             <if test="officeName != null and officeName != ''">
+                and (
                 a.id = (select id from sys_office where name = #{officeName})
                 or
                 a.parent_ids like concat('%',(select id from sys_office where name = #{officeName}),'%')
+                )
             </if>
         </where>
     </select>

+ 3 - 1
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/mapper/xml/UserMapper.xml

@@ -23,6 +23,7 @@
 		<result property="officeDTO.id" column="officeDTO.id" />
 		<result property="officeDTO.name" column="officeDTO.name" />
 		<result property="officeDTO.parentIds" column="officeDTO.parentIds" />
+		<result property="officeDTO.isPublic" column="officeDTO.isPublic"></result>
 		<collection property="roleDTOList" javaType="java.util.List" ofType="com.jeeplus.sys.service.dto.RoleDTO">
 			<id property="id" column="roleDTO.id" />
 			<result property="name" column="roleDTO.name"/>
@@ -63,7 +64,8 @@
     	c.parent_ids AS "companyDTO.parentIds",
     	o.name AS "officeDTO.name",
     	o.parent_id AS "officeDTO.parent.id",
-    	o.parent_ids AS "officeDTO.parentIds"
+    	o.parent_ids AS "officeDTO.parentIds",
+    	o.is_public AS "officeDTO.isPublic"
     </sql>
 	<sql id="Cert_Column_List">
         cert.id,

+ 29 - 19
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/OfficeService.java

@@ -5,6 +5,7 @@ package com.jeeplus.sys.service;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -48,6 +49,7 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
 
     public List <OfficeDTO> getRootTree(List<OfficeDTO> list, String extId, String type, String showAll, String showMyOffice) {
         List<OfficeDTO> offices = Lists.newArrayList ();
+        // 获取到所有parent_id为‘0’的部门数据
         List<OfficeDTO> rootTrees = officeWrapper.toDTO (super.getChildren (new Office (OfficeDTO.getRootId ())));
         for (OfficeDTO root : rootTrees) {
             if (this.isUseAble ( extId, type,root, showAll )){
@@ -60,8 +62,11 @@ 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")){
-                    offices = this.getCompanyFromTree(offices);
+                // isPublic为“0”,当前用户的部门为私有部门,查询的部门包含自己所属部门和公有部门
+                if ("0".equals(officeDTO.getIsPublic())) {
+                    if(null != officeDTO && StringUtils.isNotBlank(officeDTO.getParentIds())){
+                        offices = this.getCompanyFromTree(offices);
+                    }
                 }
             }
         }
@@ -74,7 +79,6 @@ 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;
@@ -82,30 +86,36 @@ public class OfficeService extends TreeService<OfficeMapper, Office> {
         if(split.length>2){
             companyId = split[2];
         }else{
-            companyId = officeDTO1.getId();
+            companyId = UserUtils.getCurrentUserDTO().getOfficeDTO().getId();
         }
-
-        AtomicReference<OfficeDTO> officeDTO = new AtomicReference<>(new OfficeDTO());
+        List<OfficeDTO> os = new ArrayList<>();
         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(finalCompanyId)){
-                        List<OfficeDTO> companys = new ArrayList<>();
-                        item.getChildren().stream().forEach(child->{
-                            if(child.getId().equals(finalCompanyId)){ // 找到登录人的公司
-                                companys.add(child);
-                            }
-                        });
-                        officeDTO.get().setChildren(companys);
+                if ("1".equals(item.getIsPublic())) { // 找到公有的集团
+                    OfficeDTO officeDTO = item;
+                    if (CollectionUtil.isNotEmpty(item.getChildren())){
+                        officeDTO.setChildren(item.getChildren());
+                    }
+                    os.add(officeDTO);
+                }else{
+                    if(item.getId().equals(corporationId)){  // 找到登录人的集团
+                        OfficeDTO officeDTO = item;
+                        if (CollectionUtil.isNotEmpty(item.getChildren())&&!"".equals(finalCompanyId)){
+                            List<OfficeDTO> companys = new ArrayList<>();
+                            item.getChildren().stream().forEach(child->{
+                                if(child.getId().equals(finalCompanyId) || "1".equals(child.getIsPublic())){ // 登录人的公司 或者 公有公司
+                                    companys.add(child);
+                                }
+                            });
+                            officeDTO.setChildren(companys);
+                        }
+                        os.add(officeDTO);
                     }
                 }
             });
         }
-        List<OfficeDTO> trees = new ArrayList<>();
-        trees.add(officeDTO.get());
-        return trees;
+        return os;
     }
 
 

+ 5 - 0
jeeplus-platform/jeeplus-admin/src/main/java/com/jeeplus/sys/service/dto/OfficeDTO.java

@@ -205,4 +205,9 @@ public class OfficeDTO extends TreeDTO <OfficeDTO> {
 	 */
 	private String parentId;
 
+	/**
+	 * 是否公用
+	 */
+	private String isPublic;
+
 }

+ 1 - 1
jeeplus-platform/jeeplus-admin/target/generated-sources/annotations/com/jeeplus/sys/service/mapstruct/UserWrapperImpl.java

@@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
 
 @Generated(
     value = "org.mapstruct.ap.MappingProcessor",
-    date = "2023-01-11T12:38:05+0800",
+    date = "2023-01-12T11:10:23+0800",
     comments = "version: 1.4.1.Final, compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)"
 )
 @Component