ludc
2024-06-26 79dd20bae9e8af17d5d66b67da4ca6ebc56cd9dd
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/OrgDeptQueryServiceImpl.java
@@ -1,5 +1,6 @@
package com.vci.frameworkcore.compatibility.impl;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.frameworkcore.compatibility.OrgDeptQueryServiceI;
import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus;
@@ -20,10 +21,13 @@
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
import com.vci.web.service.WebBoServiceI;
import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.*;
@@ -43,6 +47,12 @@
    */
   @Autowired
   private WebBoServiceI boService;
   /**
    * 平台调用客户端
    */
   @Autowired
   private PlatformClientUtil platformClientUtil;
   /**
    * 对象操作工具类
@@ -179,7 +189,7 @@
      if(queryMap == null){
         queryMap = new HashMap<>();
      }
      List<OrgDeptForPlatform1> roles = new ArrayList<>();
      List<OrgDeptForPlatform1> deptForPlatform1s = new ArrayList<>();
      if(userOid.contains(",")){
         Map<String, String> finalQueryMap = queryMap;
         WebUtil.switchCollectionForOracleIn(WebUtil.str2List(userOid)).stream().forEach(userOids->{
@@ -191,7 +201,7 @@
            VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class);
            List<OrgDeptForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class);
            if(!CollectionUtils.isEmpty(roleForPlatform1s)){
               roles.addAll(roleForPlatform1s);
               deptForPlatform1s.addAll(roleForPlatform1s);
            }
         });
      }else {
@@ -200,9 +210,9 @@
      VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(queryMap,OrgDeptForPlatform1.class);
      List<OrgDeptForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class);
      if(!CollectionUtils.isEmpty(roleForPlatform1s)){
         roles.addAll(roleForPlatform1s);
         deptForPlatform1s.addAll(roleForPlatform1s);
      }
      return deptDO2VOs(roles);
      return deptDO2VOs(deptForPlatform1s);
   }
   /**
@@ -212,13 +222,13 @@
     * @return 部门的显示对象
     */
   @Override
   public OrgDepartmentVO listDeptByUserOid(String userOid,
   public List<OrgDepartmentVO> listDeptByUserOid(String userOid,
         Map<String, String> queryMap) {
      List<OrgDepartmentVO> departmentVOS = listDeptByUserOid(userOid, queryMap, false);
      if(CollectionUtils.isEmpty(departmentVOS)){
         return null;
         return new ArrayList<>();
      }
      return departmentVOS.get(0);
      return departmentVOS;
   }
   /**
@@ -412,4 +422,39 @@
      return dataGrid;
   }
   /**
    * 保存部门角色关联信息,带查重功能
    * @param userId 用户id
    * @param deptIds 部门id
    * @return
    */
   @Override
   @Transactional(rollbackFor = Exception.class)
   public boolean saveUserDepts(String userId, List<String> deptIds) throws PLException {
      if(Func.isBlank(userId) || Func.isEmpty(deptIds)){
         return false;
      }
      List<String> repeatDeptOidList = new ArrayList<>();
      //循环进行查重,避免in大于1000
      WebUtil.switchCollectionForOracleIn(deptIds).stream().forEach(deptoids->{
         String sql = "select pluseruid,pldeptuid from pluserdept where pluseruid = " + userId
               + " and " + "pldeptuid in ("+WebUtil.toInSql(deptoids.toArray(new String[0]))+")";
         List<BusinessObject> cbos = boService.queryBySql(sql, null);
         if(!CollectionUtils.isEmpty(cbos)){
            cbos.stream().forEach(cbo->{
               repeatDeptOidList.add(ObjectTool.getNewBOAttributeValue(cbo,"pldeptuid"));
            });
         }
      });
      //从即将要执行保存的部门oid中移除当前用户已经存在关联关系的的部门oid
      deptIds.removeAll(repeatDeptOidList);
      if(Func.isNotEmpty(deptIds)){
         for (String deptId : deptIds){
            platformClientUtil.getFrameworkService().saveUserDept(new String[]{userId}, deptId,null);
         }
      }
      return true;
   }
}