组织架构监听
This commit is contained in:
@@ -48,6 +48,7 @@ public enum ErrorCodeEnum {
|
|||||||
IDENTITY_CARD_PARSE_FAIL(1021080, "身份证解析失败", null),
|
IDENTITY_CARD_PARSE_FAIL(1021080, "身份证解析失败", null),
|
||||||
PARAMS_REQUIRED(400002, "参数缺失!", null),
|
PARAMS_REQUIRED(400002, "参数缺失!", null),
|
||||||
DATA_CONVERT_ERROR(400002, "日期转换异常!", null),
|
DATA_CONVERT_ERROR(400002, "日期转换异常!", null),
|
||||||
|
PARENT_NODE_NOT_EXIST(400002, "父节点不存在", null),
|
||||||
|
|
||||||
|
|
||||||
LINE_ID_IS_NOT_EXIST(500001, "线索ID不存在!", null),
|
LINE_ID_IS_NOT_EXIST(500001, "线索ID不存在!", null),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.collections4.ListUtils;
|
import org.apache.commons.collections4.ListUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -61,4 +62,16 @@ public class RegionDAO {
|
|||||||
return ListUtils.emptyIfNull(regionList).stream().collect(Collectors.toMap(RegionDO::getRegionId, RegionDO::getName));
|
return ListUtils.emptyIfNull(regionList).stream().collect(Collectors.toMap(RegionDO::getRegionId, RegionDO::getName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取区域
|
||||||
|
* @param regionId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public RegionDO getRegionInfoByRegionId(String regionId){
|
||||||
|
if(StringUtils.isBlank(regionId)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return regionMapper.getRegionInfoByRegionId(regionId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,4 +51,11 @@ public interface RegionMapper {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<RegionDO> getRegionBaseInfoList();
|
List<RegionDO> getRegionBaseInfoList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取区域信息
|
||||||
|
* @param regionId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
RegionDO getRegionInfoByRegionId(@Param("regionId") String regionId);
|
||||||
}
|
}
|
||||||
@@ -187,4 +187,13 @@
|
|||||||
where
|
where
|
||||||
deleted = 0
|
deleted = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getRegionInfoByRegionId" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
from
|
||||||
|
region
|
||||||
|
where
|
||||||
|
deleted = 0 and region_id= #{regionId}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -250,4 +250,24 @@ public class SysDepartmentDTO {
|
|||||||
}
|
}
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RegionDO convertRegionDO(SysDepartmentDTO dept, Multimap<String, String> leaderDeptMap){
|
||||||
|
RegionDO region = new RegionDO();
|
||||||
|
region.setRegionId(dept.getId());
|
||||||
|
region.setName(dept.getName());
|
||||||
|
region.setParentId(dept.getParentId());
|
||||||
|
region.setUnclassifiedFlag(CommonConstants.ZERO);
|
||||||
|
region.setLeaderUserId(dept.getLeaderUserId());
|
||||||
|
region.setOrderNum(dept.getDepartOrder());
|
||||||
|
region.setThirdDeptId(dept.getId());
|
||||||
|
region.setCreateTime(System.currentTimeMillis());
|
||||||
|
region.setUpdateTime(System.currentTimeMillis());
|
||||||
|
region.setDeleted(Boolean.FALSE);
|
||||||
|
if(CollectionUtils.isNotEmpty(dept.getDeptManagerUseridList())){
|
||||||
|
for (String leader : dept.getDeptManagerUseridList()) {
|
||||||
|
leaderDeptMap.put(leader, dept.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return region;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.cool.store.service.impl;
|
package com.cool.store.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.cool.store.constants.CommonConstants;
|
import com.cool.store.constants.CommonConstants;
|
||||||
import com.cool.store.dao.*;
|
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.dto.enterprise.*;
|
||||||
import com.cool.store.entity.*;
|
import com.cool.store.entity.*;
|
||||||
import com.cool.store.enums.DataSourceEnum;
|
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.http.ISVHttpRequest;
|
||||||
import com.cool.store.service.EnterpriseSyncService;
|
import com.cool.store.service.EnterpriseSyncService;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
@@ -216,14 +219,54 @@ public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
|
|||||||
log.info("部门变更:{}", JSONObject.toJSONString(param));
|
log.info("部门变更:{}", JSONObject.toJSONString(param));
|
||||||
switch (parseValue(param.getEventType())){
|
switch (parseValue(param.getEventType())){
|
||||||
case DEPARTMENT_CREATED:
|
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;
|
break;
|
||||||
case DEPARTMENT_UPDATED:
|
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;
|
break;
|
||||||
case DEPARTMENT_DELETED:
|
case DEPARTMENT_DELETED:
|
||||||
|
syncAll();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user