Merge remote-tracking branch 'origin/cc_20230520_partner' into cc_20230520_partner
This commit is contained in:
@@ -68,6 +68,7 @@ public class CommonConstants {
|
||||
public static final String SQUAREBRACKETSRIGHT = "]";
|
||||
|
||||
public static final String PATH_SPILT = "/";
|
||||
public static final String ROOT_REGION_PATH = "/1/";
|
||||
|
||||
/**
|
||||
* rocketmq 消息最大重试次数
|
||||
|
||||
@@ -56,7 +56,6 @@ public class ServiceException extends RuntimeException{
|
||||
* 构造函数
|
||||
* @param errorMessage
|
||||
*/
|
||||
@Deprecated
|
||||
public ServiceException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
this.errorMessage = errorMessage;
|
||||
|
||||
@@ -52,16 +52,16 @@
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectByHourDate" resultType="com.cool.store.entity.SyncEcCustomerDO" >
|
||||
SELECT a.id as id, a.username as customername,a.mobile as customermobile,c.`name` as followname,c.mobile as followmobile ,d.channel_id as channelId FROM hy_partner_user_info a LEFT join hy_partner_line_info b on
|
||||
a.partner_id=b.partner_id left join enterprise_user c on b.investment_manager=c.user_id LEFT join hy_partner_user_channel d on b.user_channel_id=d.id
|
||||
WHERE a.create_time BETWEEN #{selectTime} and #{now} or
|
||||
a.update_time BETWEEN #{selectTime} and #{now} order by a.id Limit #{limit1},#{limit2}
|
||||
SELECT a.id as id, a.username as customername,a.mobile as customermobile,d.`name` as followname,d.mobile as followmobile ,c.channel_id as channelId FROM hy_partner_user_info a LEFT join hy_partner_line_info b on
|
||||
a.partner_id=b.partner_id LEFT join hy_partner_user_channel c on b.user_channel_id=c.channel_id left join enterprise_user d on b.investment_manager=d.user_id
|
||||
WHERE ( a.create_time BETWEEN #{selectTime} and #{now} or
|
||||
a.update_time BETWEEN #{selectTime} and #{now} ) order by a.id Limit #{limit1},#{limit2}
|
||||
</select>
|
||||
<select id="selectByHourDateCount" resultType="java.lang.Integer">
|
||||
SELECT count(*) FROM hy_partner_user_info a LEFT join hy_partner_line_info b on
|
||||
a.partner_id=b.partner_id left join enterprise_user c on b.investment_manager=c.user_id
|
||||
WHERE a.create_time BETWEEN #{selectTime} and #{now} or
|
||||
a.update_time BETWEEN #{selectTime} and #{now}
|
||||
a.partner_id=b.partner_id LEFT join hy_partner_user_channel c on b.user_channel_id=c.channel_id left join enterprise_user d on b.investment_manager=d.user_id
|
||||
WHERE (a.create_time BETWEEN #{selectTime} and #{now} or
|
||||
a.update_time BETWEEN #{selectTime} and #{now} )
|
||||
</select>
|
||||
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
|
||||
|
||||
@@ -165,7 +165,7 @@
|
||||
from
|
||||
region
|
||||
where
|
||||
region_id in <foreach collection="regionIds" item="regionId" separator="," open="(" close=")">#{regionId}</foreach>
|
||||
deleted ='0' and region_id in <foreach collection="regionIds" item="regionId" separator="," open="(" close=")">#{regionId}</foreach>
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cool.store.dto.enterprise;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.enums.FSEventTypeEnum;
|
||||
import com.cool.store.enums.UserStatusEnum;
|
||||
@@ -123,9 +124,16 @@ public class EnterpriseUserDTO implements Serializable {
|
||||
List<String> regionPaths = new ArrayList<>();
|
||||
if(CollectionUtils.isNotEmpty(departmentLists)){
|
||||
for (String departmentId : departmentLists) {
|
||||
regionPaths.add(regionPathMap.get(departmentId));
|
||||
String regionPath = regionPathMap.get(departmentId);
|
||||
if(StringUtils.isNotBlank(regionPath)){
|
||||
regionPaths.add(regionPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
//挂跟节点
|
||||
if(CollectionUtils.isEmpty(regionPaths)){
|
||||
regionPaths.add(CommonConstants.ROOT_REGION_PATH);
|
||||
}
|
||||
Collection<String> deptIds = leaderDeptMap.get(user.getUserId());
|
||||
if(CollectionUtils.isNotEmpty(deptIds)){
|
||||
enterpriseUserDO.setIsLeader(Boolean.TRUE);
|
||||
@@ -162,9 +170,15 @@ public class EnterpriseUserDTO implements Serializable {
|
||||
List<String> regionPaths = new ArrayList<>();
|
||||
if(CollectionUtils.isNotEmpty(departmentLists)){
|
||||
for (String departmentId : departmentLists) {
|
||||
regionPaths.add(regionPathMap.get(departmentId));
|
||||
String regionPath = regionPathMap.get(departmentId);
|
||||
if(StringUtils.isNotBlank(regionPath)){
|
||||
regionPaths.add(regionPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(CollectionUtils.isEmpty(regionPaths)){
|
||||
regionPaths.add(CommonConstants.ROOT_REGION_PATH);
|
||||
}
|
||||
//创建的时候给个默认值
|
||||
if(FSEventTypeEnum.USER_CREATED.equals(eventType)){
|
||||
enterpriseUserDO.setIsLeader(Boolean.FALSE);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cool.store.entity;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.dto.enterprise.EnterpriseUserDTO;
|
||||
import com.cool.store.enums.DataSourceEnum;
|
||||
@@ -8,6 +9,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -88,4 +90,33 @@ public class UserRegionMappingDO implements Serializable {
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
public static List<UserRegionMappingDO> convertSyncDO(List<EnterpriseUserDO> userList){
|
||||
if(CollectionUtils.isEmpty(userList)){
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
List<UserRegionMappingDO> resultList = new ArrayList<>();
|
||||
for (EnterpriseUserDO user : userList) {
|
||||
List<String> userRegionIds = JSONObject.parseArray(user.getUserRegionIds(), String.class).stream().distinct().collect(Collectors.toList());
|
||||
for (String userRegionId : userRegionIds) {
|
||||
if(StringUtils.isNotBlank(userRegionId)){
|
||||
continue;
|
||||
}
|
||||
String[] split = userRegionId.split(CommonConstants.PATH_SPILT);
|
||||
if(split.length == 0){
|
||||
continue;
|
||||
}
|
||||
UserRegionMappingDO userRegion = new UserRegionMappingDO();
|
||||
userRegion.setRegionId(split[split.length-1]);
|
||||
userRegion.setUserId(user.getUserId());
|
||||
userRegion.setType(DataSourceEnum.SYNC.getCode());
|
||||
userRegion.setCreateTime(System.currentTimeMillis());
|
||||
userRegion.setUpdateTime(System.currentTimeMillis());
|
||||
userRegion.setDeleted(Boolean.FALSE);
|
||||
resultList.add(userRegion);
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ public class EcSyncServiceImpl implements EcSyncService {
|
||||
public boolean ecToApplet(List<CustomerInfoRequest> queryListData) {
|
||||
for (CustomerInfoRequest customerInfoItem : queryListData) {
|
||||
try {
|
||||
Thread.sleep(500L);
|
||||
insertSelectiveSync(customerInfoItem);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -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