人员同步修复
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.cool.store.http;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.dto.calendar.*;
|
||||
import com.cool.store.dto.enterprise.AuthInfoDTO;
|
||||
import com.cool.store.dto.enterprise.AuthScopeDTO;
|
||||
@@ -12,6 +13,7 @@ import com.cool.store.dto.response.ResultDTO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.exception.ApiException;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.mq.util.HttpRestTemplateService;
|
||||
import com.cool.store.request.EnterpriseUserRequest;
|
||||
import com.cool.store.utils.RestTemplateUtil;
|
||||
@@ -56,6 +58,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -73,6 +76,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -89,6 +93,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -105,6 +110,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -122,6 +128,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -144,6 +151,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -160,6 +168,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -177,14 +186,15 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<EnterpriseUserDTO> getUserDetailByUserIds(List<String> userIdList) {
|
||||
String url = isvDomain + "/corp/getDepartmentUsers";
|
||||
String url = isvDomain + "/corp/getUserDetailByUserIds";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("userIds", userIdList);
|
||||
requestMap.put("userIds", String.join(CommonConstants.COMMA, userIdList));
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
@@ -194,6 +204,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -212,6 +223,7 @@ public class ISVHttpRequest {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -54,13 +54,15 @@ public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
|
||||
|
||||
@Override
|
||||
public void syncAll() {
|
||||
AuthScopeDTO authScope = isvHttpRequest.getAuthScope();
|
||||
List<String> authUserIdList = authScope.getUserIdList();
|
||||
//同步部门
|
||||
Pair<List<RegionDO>, Multimap<String, String>> listMultimapPair = syncRegion();
|
||||
List<RegionDO> regionList = listMultimapPair.getKey();
|
||||
Multimap<String, String> leaderDeptMap = listMultimapPair.getValue();
|
||||
Multimap<String, String> roleUserMap = ArrayListMultimap.create();
|
||||
//同步用户及部门
|
||||
syncUserAndUserRegion(regionList, roleUserMap, leaderDeptMap);
|
||||
syncUserAndUserRegion(regionList, authUserIdList, roleUserMap, leaderDeptMap);
|
||||
//处理用户角色 删除多余的角色
|
||||
if(!roleUserMap.isEmpty()){
|
||||
List<SysRoleDO> insertOrUpdateList = new ArrayList<>();
|
||||
@@ -114,7 +116,7 @@ public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
|
||||
* @param roleUserMap
|
||||
* @param leaderDeptMap
|
||||
*/
|
||||
private void syncUserAndUserRegion(List<RegionDO> regionList, Multimap<String, String> roleUserMap, Multimap<String, String> leaderDeptMap){
|
||||
private void syncUserAndUserRegion(List<RegionDO> regionList, List<String> authUserIdList, Multimap<String, String> roleUserMap, Multimap<String, String> leaderDeptMap){
|
||||
Map<String, String> regionPathMap = regionList.stream().collect(Collectors.toMap(RegionDO::getRegionId, RegionDO::getRegionPath));
|
||||
List<EnterpriseUserDO> userList = new ArrayList<>();
|
||||
List<UserRegionMappingDO> userRegionList = new ArrayList<>();
|
||||
@@ -141,6 +143,14 @@ public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
|
||||
userRegionList.clear();
|
||||
}
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(authUserIdList)){
|
||||
userIds.addAll(authUserIdList);
|
||||
List<EnterpriseUserDTO> userDetailList = isvHttpRequest.getUserDetailByUserIds(authUserIdList);
|
||||
List<EnterpriseUserDO> enterpriseUserList = EnterpriseUserDTO.transUserDtoToDo(userDetailList, regionPathMap, leaderDeptMap, roleUserMap);
|
||||
List<UserRegionMappingDO> userRegionMapping = UserRegionMappingDO.convertSyncDO(enterpriseUserList);
|
||||
userRegionList.addAll(userRegionMapping);
|
||||
userList.addAll(enterpriseUserList);
|
||||
}
|
||||
enterpriseUserDAO.batchInsertOrUpdate(userList);
|
||||
userRegionMappingDAO.batchInsertOrUpdateUserRegion(userRegionList);
|
||||
//删除不存在的用户
|
||||
@@ -185,9 +195,7 @@ public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
|
||||
leaderDeptMap = regionPair.getValue();
|
||||
}
|
||||
regionPathMap = regionList.stream().collect(Collectors.toMap(k->k.getRegionId(), v->v.getRegionPath()));
|
||||
userRegionMappingDAO.batchInsertOrUpdateUserRegion(UserRegionMappingDO.convertSyncDO(departmentLists, userDetail.getUserId()));
|
||||
}
|
||||
userRegionMappingDAO.deleteUserRegionByUserId(userDetail.getUserId(), DataSourceEnum.SYNC, departmentLists);
|
||||
String jobTitle = userDetail.getJobTitle();
|
||||
if(StringUtils.isNotBlank(jobTitle)){
|
||||
SysRoleDO role = sysRoleDAO.getRoleByName(jobTitle, DataSourceEnum.SYNC);
|
||||
@@ -204,6 +212,8 @@ public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
|
||||
}
|
||||
EnterpriseUserDO enterpriseUser = EnterpriseUserDTO.transUserDtoToDo(userDetail, regionPathMap, leaderDeptMap, eventType);
|
||||
enterpriseUserDAO.batchInsertOrUpdate(new ArrayList<>(Arrays.asList(enterpriseUser)));
|
||||
userRegionMappingDAO.batchInsertOrUpdateUserRegion(UserRegionMappingDO.convertSyncDO(Arrays.asList(enterpriseUser)));
|
||||
userRegionMappingDAO.deleteUserRegionByUserId(userDetail.getUserId(), DataSourceEnum.SYNC, departmentLists);
|
||||
break;
|
||||
case USER_DELETED:
|
||||
//人员职位删除状态,角色职位删除状态,人员从部门去除
|
||||
|
||||
Reference in New Issue
Block a user