| | |
| | | |
| | | /** |
| | | * 保存部门角色关联信息,带查重功能 |
| | | * @param userId 用户id |
| | | * @param deptIds 部门id |
| | | * @param userOIds 用户id |
| | | * @param deptId 部门id |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveUserDepts(String userId, List<String> deptIds) throws PLException { |
| | | if(Func.isBlank(userId) || Func.isEmpty(deptIds)){ |
| | | public boolean saveUsersDept(String[] userOIds, String deptId) throws PLException { |
| | | if(Func.isEmpty(userOIds) || Func.isBlank(deptId)){ |
| | | return false; |
| | | } |
| | | List<String> repeatDeptOidList = new ArrayList<>(); |
| | | //先进性查重处理 |
| | | List<String> repeatUserOidList = 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]))+")"; |
| | | WebUtil.switchCollectionForOracleIn(Arrays.asList(userOIds)).stream().forEach(userOId->{ |
| | | String sql = "select pluseruid,pldeptuid from pluserdept where pldeptuid = '" + deptId |
| | | + "' and " + "pluseruid in ("+WebUtil.toInSql(userOId.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")); |
| | | repeatUserOidList.add(ObjectTool.getNewBOAttributeValue(cbo,"pluseruid")); |
| | | }); |
| | | } |
| | | |
| | | }); |
| | | //从即将要执行保存的部门oid中移除当前用户已经存在关联关系的的部门oid |
| | | deptIds.removeAll(repeatDeptOidList); |
| | | if(Func.isNotEmpty(deptIds)){ |
| | | for (String deptId : deptIds){ |
| | | platformClientUtil.getFrameworkService().saveUserDept(new String[]{userId}, deptId,null); |
| | | } |
| | | |
| | | //从即将要执行保存的用户oid中移除当前用户已经存在关联关系的oid |
| | | //移除重复的 |
| | | List<String> tempList = new ArrayList<>(Arrays.asList(userOIds)); |
| | | tempList.removeAll(repeatUserOidList); |
| | | userOIds = tempList.toArray(new String[tempList.size()]); |
| | | if(Func.isNotEmpty(userOIds)){ |
| | | platformClientUtil.getFrameworkService().saveUserDept(userOIds, deptId,null); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |