组织架构监听

This commit is contained in:
zhangchenbiao
2023-06-16 18:13:23 +08:00
parent 901815d714
commit 16a4256b5a
6 changed files with 94 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
package com.cool.store.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cool.store.constants.CommonConstants;
import com.cool.store.dao.*;
@@ -9,6 +10,8 @@ import com.cool.store.dto.dept.DepartmentEventDTO;
import com.cool.store.dto.enterprise.*;
import com.cool.store.entity.*;
import com.cool.store.enums.DataSourceEnum;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.http.ISVHttpRequest;
import com.cool.store.service.EnterpriseSyncService;
import com.google.common.collect.ArrayListMultimap;
@@ -216,14 +219,54 @@ public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
log.info("部门变更:{}", JSONObject.toJSONString(param));
switch (parseValue(param.getEventType())){
case DEPARTMENT_CREATED:
RegionDO parentRegionInfo = regionDAO.getRegionInfoByRegionId(departmentDetail.getParentId());
if(Objects.isNull(parentRegionInfo)){
throw new ServiceException(ErrorCodeEnum.PARENT_NODE_NOT_EXIST);
}
Multimap<String, String> leaderDeptMap = ArrayListMultimap.create();
RegionDO region = SysDepartmentDTO.convertRegionDO(departmentDetail, leaderDeptMap, parentRegionInfo);
regionDAO.batchInsertOrUpdate(Arrays.asList(region));
dealUserLeaderDept(leaderDeptMap);
break;
case DEPARTMENT_UPDATED:
if(param.getIsChangeParent()){
syncAll();
return;
}
Multimap<String, String> updateLeaderDeptMap = ArrayListMultimap.create();
RegionDO updateRegion = SysDepartmentDTO.convertRegionDO(departmentDetail, updateLeaderDeptMap);
regionDAO.batchInsertOrUpdate(Arrays.asList(updateRegion));
dealUserLeaderDept(updateLeaderDeptMap);
break;
case DEPARTMENT_DELETED:
syncAll();
break;
default:
return;
}
}
public void dealUserLeaderDept(Multimap<String, String> leaderDeptMap){
if(leaderDeptMap.isEmpty()){
return;
}
List<String> userIds = leaderDeptMap.keys().stream().collect(Collectors.toList());
List<EnterpriseUserDO> userList = enterpriseUserDAO.getUserInfoByUserIds(userIds);
for (EnterpriseUserDO enterpriseUser : userList) {
List<String> deptIds = leaderDeptMap.get(enterpriseUser.getUserId()).stream().collect(Collectors.toList());
String leaderDeptIds = enterpriseUser.getLeaderDeptIds();
if(StringUtils.isNotBlank(leaderDeptIds)){
List<String> existDeptIds = JSONObject.parseArray(leaderDeptIds).stream().map(String::valueOf).collect(Collectors.toList());
//取并集
existDeptIds.addAll(deptIds);
List<String> allDeptIds = existDeptIds.stream().distinct().collect(Collectors.toList());
enterpriseUser.setLeaderDeptIds(JSONObject.toJSONString(allDeptIds));
}else{
enterpriseUser.setLeaderDeptIds(JSONObject.toJSONString(deptIds));
}
enterpriseUser.setIsLeader(Boolean.TRUE);
}
enterpriseUserDAO.batchInsertOrUpdate(userList);
}
}