@@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
import com.cool.store.constants.CommonConstants ;
import com.cool.store.dao.EnterpriseUserDAO ;
import com.cool.store.dao.HyPartnerBaseInfoDAO ;
import com.cool.store.dao.HyPartnerLineInfoDAO ;
@@ -17,6 +18,7 @@ import com.cool.store.enums.LineStatusEnum;
import com.cool.store.enums.WorkflowStageEnum ;
import com.cool.store.enums.WorkflowStatusEnum ;
import com.cool.store.exception.ApiException ;
import com.cool.store.http.EventCenterHttpRequest ;
import com.cool.store.http.UserSourceResponse ;
import com.cool.store.mapper.HyPartnerEcTrackLogMapper ;
import com.cool.store.mapper.HyPartnerUserChannelMapper ;
@@ -36,6 +38,7 @@ import com.cool.store.utils.MybatisBatchUtils;
import com.cool.store.utils.Post ;
import com.cool.store.utils.StringUtil ;
import com.cool.store.utils.UUIDUtils ;
import com.cool.store.utils.poi.constant.Constants ;
import lombok.SneakyThrows ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang3.StringUtils ;
@@ -46,10 +49,8 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource ;
import java.io.IOException ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.List ;
import java.util.* ;
import java.util.stream.Collectors ;
@Slf4j
@Service
@@ -84,11 +85,16 @@ public class EcSyncServiceImpl implements EcSyncService {
@Resource
private LabelService labelService ;
@Resource
private EventCenterHttpRequest eventCenterHttpRequest ;
@Override
public boolean ecToApplet ( List < CustomerInfoRequest > queryListData ) {
for ( CustomerInfoRequest customerInfoItem : queryListData ) {
try {
insertSelectiveSync ( customerInfoItem ) ;
Map < String , List < HyPartnerUserInfoDO > > sendUserMap = new HashMap < > ( ) ;
insertSelectiveSync ( customerInfoItem , false , sendUserMap ) ;
} catch ( Exception e ) {
log . error ( " ec同步至招商小程序报错 " + JSONObject . toJSONString ( e ) ) ;
sendFeiShuRobotMessage ( " 推送: " + JSONObject . toJSONString ( e ) , " 27243d49-97ca-4981-8aec-7c3bf84eb660 " ) ;
@@ -150,7 +156,8 @@ public class EcSyncServiceImpl implements EcSyncService {
public Boolean historyLine ( List < CustomerInfoRequest > resultCustomerInfoList ) {
for ( CustomerInfoRequest customerInfoRequest : resultCustomerInfoList ) {
customerInfoRequest . setUpdateTime ( DateUtil . parse ( customerInfoRequest . getCrmCreateTime ( ) , DatePattern . NORM_DATETIME_PATTERN ) ) ;
insertSelectiveSync ( customerInfoRequest ) ;
Map < String , List < HyPartnerUserInfoDO > > sendUserMap = new HashMap < > ( ) ;
insertSelectiveSync ( customerInfoRequest , true , sendUserMap ) ;
}
return Boolean . TRUE ;
}
@@ -163,7 +170,7 @@ public class EcSyncServiceImpl implements EcSyncService {
hyPartnerEcTrackLogDO . setPartnerId ( hyPartnerUserInfoDO . getPartnerId ( ) ) ;
}
}
return mybatisBatchUtils . batchInsertOrUpdate ( resultTrajectoryList , HyPartnerEcTrackLogMapper . class , ( record , mapper ) - > mapper . insertSelective ( record ) ) ;
return mybatisBatchUtils . batchInsertOrUpdate ( resultTrajectoryList , HyPartnerEcTrackLogMapper . class , ( record , mapper ) - > mapper . insertSelective ( record ) ) ;
}
/**
@@ -172,50 +179,30 @@ public class EcSyncServiceImpl implements EcSyncService {
* @param customerInfoItem
*/
@Transactional ( rollbackFor = Exception . class )
public void insertSelectiveSync ( CustomerInfoRequest customerInfoItem ) throws ApiException {
if ( StringUtil . isNotEmpty ( customerInfoItem . getMobile ( ) ) ) {
customerInfoItem . setMobile ( customerInfoItem . getMobile ( ) . split ( " " ) [ 1 ] ) ;
}
//获取客户来源id
String channel = customerInfoItem . getChannel ( ) ;
HyPartnerUserChannelDO hyPartnerUserChannelDO = hyPartnerUserChannelMapper . selectByChannelName ( channel ) ;
Long channelId = null ;
if ( StringUtil . isNotEmpty ( channel ) ) {
if ( ObjectUtil . isNull ( hyPartnerUserChannelDO ) | | ObjectUtil . isNull ( hyPartnerUserChannelDO . getChannelId ( ) ) ) {
getChannelSource ( ) ;
}
HyPartnerUserChannelDO channelDO = hyPartnerUserChannelMapper . selectByChannelName ( channel ) ;
channelId = channelDO . getChannelId ( ) ;
}
public void insertSelectiveSync ( CustomerInfoRequest customerInfoItem , Boolean pan , Map < String , List < HyPartnerUserInfoDO > > sendUserMap ) throws ApiException {
//发送消息
customerInfoItem . setMobile ( customerInfoItem . getMobile ( ) . split ( " " ) [ 1 ] ) ;
String newPartnerId = UUIDUtils . get32UUID ( ) ;
HyPartnerBaseInfoDO resultBase = new HyPartnerBaseInfoDO ( ) ;
HyPartnerUserInfoDO resultUser = new HyPartnerUserInfoDO ( ) ;
resultUser . setUsername ( customerInfoItem . getName ( ) ) . setMobile ( customerInfoItem . getMobile ( ) ) . setUserChannelId ( Convert . toInt ( c hannelId) ) . setEcWantShopArea ( customerInfoItem . getEcWantShopArea ( ) ) ;
resultUser . setUsername ( customerInfoItem . getName ( ) ) . setMobile ( customerInfoItem . getMobile ( ) ) . setUserChannelId ( Convert . toInt ( getC hannelId( customerInfoItem . getChannel ( ) ) )) . setEcWantShopArea ( customerInfoItem . getEcWantShopArea ( ) ) ;
Date time = new Date ( ) ;
if ( ObjectUtil . isNotNull ( customerInfoItem . getUpdateTime ( ) ) ) {
if ( ObjectUtil . isNotNull ( customerInfoItem . getUpdateTime ( ) ) & & pan ) {
//历史线索创建时间与更新时间设置为ec同步过来的时间
time = customerInfoItem . getUpdateTime ( ) ;
resultUser . setCrmCreateTime ( time ) ;
//放入历史标签id
if ( StringUtil . isNotEmpty ( customerInfoItem . getLabelIds ( ) ) ) {
resultBase . setUserPortrait ( " , " + customerInfoItem . getLabelIds ( ) + " , " ) ;
resultBase . setUserPortrait ( CommonConstants . COMMA . concat ( customerInfoItem . getLabelIds ( ) ) . concat ( CommonConstants . COMMA ) ) ;
}
}
HyPartnerLineInfoDO resultLine = new HyPartnerLineInfoDO ( ) ;
String followUserName = customerInfoItem . getFollowUserName ( ) ;
String followUserMobile = customerInfoItem . getFollowUserMobile ( ) ;
//传递过来有跟进人的情况下查询跟进人是否存在
if ( StringUtil . isNotEmpty ( followUserMobile ) & & StringUtil . isNotEmpty ( followUserNam e ) ) {
String userId = enterpriseUserDAO . selectByMobile ( followUserMobile ) ;
if ( StringUtil . isEmpty ( userId ) ) {
// 给飞书群发送消息 跟进人找不到
sendFeiShuRobotMessage ( " 推送:飞书架构中找不到该用户:【 " + followUserName + " 】,该用户电话号码为: " + followUserMobile , " 27243d49-97ca-4981-8aec-7c3bf84eb660 " ) ;
throw new ApiException ( " 飞书架构中找不到该用户:【 " + followUserName + " 】,该用户电话号码为: " + followUserMobile ) ;
}
resultLine . setInvestmentManager ( userId ) ;
}
//获取招商经理
resultLine . setInvestmentManager ( getInvestmentManager ( followUserName , followUserMobil e ) ) ;
resultLine . setWorkflowStage ( WorkflowStageEnum . INTENT . getCode ( ) )
. setLineStatus ( StringUtil . isEmpty ( customerInfoItem . getFollowUserName ( ) ) ? LineStatusEnum . PUBLIC_SEAS . getCode ( ) : LineStatusEnum . PRIVATE_SEAS . getCode ( ) ) ;
resultBase . setUsername ( customerInfoItem . getName ( ) ) . setMobile ( customerInfoItem . getMobile ( ) ) ;
HyPartnerUserInfoDO newUserInfo = hyPartnerUserInfoDAO . selectByMobile ( resultUser . getMobile ( ) ) ;
@@ -229,11 +216,7 @@ public class EcSyncServiceImpl implements EcSyncService {
}
// EC与沪姨合伙人同时存在的线索用户, 但用户姓名不同, 将沪姨合伙人线索姓名同步至EC覆盖原EC线索姓名
if ( ! newUserInfo . getUsername ( ) . equals ( resultUser . getUsername ( ) ) ) {
U pdateCustomerRequest updateUserRequest = new UpdateCustomerRequest ( ) ;
UpdateCustomerBo updateCustomerBo = new UpdateCustomerBo ( ) ;
updateCustomerBo . setUsername ( newUserInfo . getUsername ( ) ) . setMobile ( newUserInfo . getMobile ( ) ) . setCrmId ( customerInfoItem . getCrmId ( ) ) ;
updateUserRequest . setParameter ( updateCustomerBo ) ;
UpdateCustomerResponse updateUserExec = ecClient . exec ( baseUrl , updateUserRequest ) ;
u pdateEc Customer( customerInfoItem , newUserInfo , ecClient ) ;
}
String oldPartnerId = newUserInfo . getPartnerId ( ) ;
//线索表
@@ -255,21 +238,11 @@ public class EcSyncServiceImpl implements EcSyncService {
enterpriseUser . setMobile ( getNoWith86Number ( enterpriseUser . getMobile ( ) ) ) ;
//电话相同但是名字不同
if ( enterpriseUser . getMobile ( ) . equals ( followUserMobile ) & & ! enterpriseUser . getName ( ) . equals ( followUserName ) ) {
C hangeFollowUserRequest changeFollowUserRequest = new ChangeFollowUserRequest ( ) ;
ChangeFollowUserBo changeFollowUserBo = new ChangeFollowUserBo ( ) ;
changeFollowUserBo . setFollowUserId ( customerInfoItem . getLastFollowUserId ( ) ) . setCrmId ( customerInfoItem . getCrmId ( ) )
. setType ( 1 ) . setUsername ( enterpriseUser . getName ( ) ) . setMobile ( enterpriseUser . getMobile ( ) ) ;
changeFollowUserRequest . setParameter ( changeFollowUserBo ) ;
ChangeFollowUserResponse changeFollowUserExec = ecClient . exec ( baseUrl , changeFollowUserRequest ) ;
c hangeEc FollowUser( customerInfoItem , ecClient , enterpriseUser , 1 ) ;
}
//电话不同
if ( ! enterpriseUser . getMobile ( ) . equals ( followUserMobile ) ) {
C hangeFollowUserRequest changeFollowUserRequest = new ChangeFollowUserRequest ( ) ;
ChangeFollowUserBo changeFollowUserBo = new ChangeFollowUserBo ( ) ;
changeFollowUserBo . setFollowUserId ( customerInfoItem . getLastFollowUserId ( ) ) . setCrmId ( customerInfoItem . getCrmId ( ) )
. setType ( 2 ) . setUsername ( enterpriseUser . getName ( ) ) . setMobile ( enterpriseUser . getMobile ( ) ) ;
changeFollowUserRequest . setParameter ( changeFollowUserBo ) ;
ChangeFollowUserResponse changeFollowUserExec = ecClient . exec ( baseUrl , changeFollowUserRequest ) ;
c hangeEc FollowUser( customerInfoItem , ecClient , enterpriseUser , 2 ) ;
}
}
}
@@ -279,14 +252,12 @@ public class EcSyncServiceImpl implements EcSyncService {
resultBase . setPartnerId ( newPartnerId ) . setPartnerLineId ( partnerLine . getId ( ) ) . setStatus ( Integer . valueOf ( WorkflowStatusEnum . INTENT_0 . getCode ( ) ) ) .
setCreateTime ( time ) . setUpdateTime ( time ) ;
hyPartnerBaseInfoDAO . insertSelective ( resultBase ) ;
} else {
//标签共有 取并集 更改用户画像
updateUserPortrait ( partnerIdAndLine , partnerIdAndLine . getUserPortrait ( ) , resultBase . getUserPortrait ( ) ) ;
}
} else {
resultLine . setPartnerId ( newPartnerId ) . setCreateTime ( time ) . setUpdateTime ( tim e) ;
hyPartnerLineInfoDAO . insertSelective ( resultLine ) ;
resultBase . setPartnerId ( newPartnerId ) . setPartnerLineId ( resultLine . getId ( ) ) . setStatus ( Integer . valueOf ( WorkflowStatusEnum . INTENT_0 . getCode ( ) ) ) .
setCreateTime ( time ) . setUpdateTime ( time ) ;
hyPartnerBaseInfoDAO . insertSelective ( resultBase ) ;
insertUserInfo ( sendUserMap , newPartnerId , resultBase , resultUser , time , resultLin e) ;
}
newUserInfo . setEcWantShopArea ( resultUser . getEcWantShopArea ( ) ) ;
//添加ec意向区域同步
@@ -295,15 +266,120 @@ public class EcSyncServiceImpl implements EcSyncService {
resultUser . setPartnerId ( newPartnerId ) . setCreateTime ( time ) . setUpdateTime ( time ) ;
hyPartnerUserInfoDAO . insertSelective ( resultUser ) ;
resultLine . setPartnerId ( newPartnerId ) . setCreateTime ( time ) . setUpdateTime ( tim e) ;
hyPartnerLineInfoDAO . insertSelective ( resultLine ) ;
resultBase . setPartnerId ( newPartnerId ) . setPartnerLineId ( resultLine . getId ( ) ) . setStatus ( Integer . valueOf ( WorkflowStatusEnum . INTENT_0 . getCode ( ) ) ) .
setCreateTime ( time ) . setUpdateTime ( time ) ;
hyPartnerBaseInfoDAO . insertSelective ( resultBase ) ;
insertUserInfo ( sendUserMap , newPartnerId , resultBase , resultUser , time , resultLin e) ;
}
}
/**
* 发送请求更改ec线索跟进人
* @param customerInfoItem
* @param ecClient
* @param enterpriseUser
* @param i
*/
private void changeEcFollowUser ( CustomerInfoRequest customerInfoItem , EcClient ecClient , EnterpriseUserDO enterpriseUser , int i ) {
ChangeFollowUserRequest changeFollowUserRequest = new ChangeFollowUserRequest ( ) ;
ChangeFollowUserBo changeFollowUserBo = new ChangeFollowUserBo ( ) ;
changeFollowUserBo . setFollowUserId ( customerInfoItem . getLastFollowUserId ( ) ) . setCrmId ( customerInfoItem . getCrmId ( ) )
. setType ( i ) . setUsername ( enterpriseUser . getName ( ) ) . setMobile ( enterpriseUser . getMobile ( ) ) ;
changeFollowUserRequest . setParameter ( changeFollowUserBo ) ;
ChangeFollowUserResponse changeFollowUserExec = ecClient . exec ( baseUrl , changeFollowUserRequest ) ;
}
/**
* 发送请求更改ec客户
* @param customerInfoItem
* @param newUserInfo
* @param ecClient
*/
private void updateEcCustomer ( CustomerInfoRequest customerInfoItem , HyPartnerUserInfoDO newUserInfo , EcClient ecClient ) {
UpdateCustomerRequest updateUserRequest = new UpdateCustomerRequest ( ) ;
UpdateCustomerBo updateCustomerBo = new UpdateCustomerBo ( ) ;
updateCustomerBo . setUsername ( newUserInfo . getUsername ( ) ) . setMobile ( newUserInfo . getMobile ( ) ) . setCrmId ( customerInfoItem . getCrmId ( ) ) ;
updateUserRequest . setParameter ( updateCustomerBo ) ;
UpdateCustomerResponse updateUserExec = ecClient . exec ( baseUrl , updateUserRequest ) ;
}
private void insertUserInfo ( Map < String , List < HyPartnerUserInfoDO > > sendUserMap , String newPartnerId , HyPartnerBaseInfoDO resultBase , HyPartnerUserInfoDO resultUser , Date time , HyPartnerLineInfoDO resultLine ) {
resultLine . setPartnerId ( newPartnerId ) . setCreateTime ( time ) . setUpdateTime ( time ) ;
hyPartnerLineInfoDAO . insertSelective ( resultLine ) ;
resultBase . setPartnerId ( newPartnerId ) . setPartnerLineId ( resultLine . getId ( ) ) . setStatus ( Integer . valueOf ( WorkflowStatusEnum . INTENT_0 . getCode ( ) ) ) .
setCreateTime ( time ) . setUpdateTime ( time ) ;
hyPartnerBaseInfoDAO . insertSelective ( resultBase ) ;
putElement ( sendUserMap , newPartnerId , resultUser ) ;
}
private void putElement ( Map < String , List < HyPartnerUserInfoDO > > sendUserMap , String key , HyPartnerUserInfoDO element ) {
List < HyPartnerUserInfoDO > list = sendUserMap . get ( key ) ;
if ( CollectionUtils . isEmpty ( list ) ) {
ArrayList < HyPartnerUserInfoDO > hyPartnerUserInfoDOS = new ArrayList < > ( ) ;
hyPartnerUserInfoDOS . add ( element ) ;
sendUserMap . put ( key , hyPartnerUserInfoDOS ) ;
} else {
list . add ( element ) ;
}
}
/**
* 更改用户画像取并集
*
* @param partnerIdAndLine
* @param oldUserPortrait
* @param newUserPortrait
*/
private void updateUserPortrait ( HyPartnerBaseInfoDO partnerIdAndLine , String oldUserPortrait , String newUserPortrait ) {
if ( StringUtil . isNotEmpty ( newUserPortrait ) & & ! oldUserPortrait . equals ( newUserPortrait ) ) {
List < String > oldList = Arrays . asList ( oldUserPortrait . split ( Constants . COMMA ) ) ;
List < String > newList = Arrays . asList ( newUserPortrait . split ( Constants . COMMA ) ) ;
oldList . addAll ( newList ) ;
String userPortrait = Constants . COMMA . concat ( oldList . stream ( ) . distinct ( ) . collect ( Collectors . joining ( Constants . COMMA ) ) ) . concat ( Constants . COMMA ) ;
partnerIdAndLine . setUserPortrait ( userPortrait ) ;
hyPartnerBaseInfoDAO . updateByPrimaryKeySelective ( partnerIdAndLine ) ;
}
}
/***
* 获取跟进人id
* @param followUserName
* @param followUserMobile
* @return
* @throws ApiException
*/
private String getInvestmentManager ( String followUserName , String followUserMobile ) throws ApiException {
//传递过来有跟进人的情况下查询跟进人是否存在
if ( StringUtil . isNotEmpty ( followUserMobile ) & & StringUtil . isNotEmpty ( followUserName ) ) {
String userId = enterpriseUserDAO . selectByMobile ( followUserMobile ) ;
if ( StringUtil . isEmpty ( userId ) ) {
// 给飞书群发送消息 跟进人找不到
sendFeiShuRobotMessage ( " 推送:飞书架构中找不到该用户:【 " + followUserName + " 】,该用户电话号码为: " + followUserMobile , " 27243d49-97ca-4981-8aec-7c3bf84eb660 " ) ;
throw new ApiException ( " 飞书架构中找不到该用户:【 " + followUserName + " 】,该用户电话号码为: " + followUserMobile ) ;
}
return userId ;
}
return " " ;
}
/**
* @param channel
* @return
*/
private Long getChannelId ( String channel ) {
//获取客户来源id
HyPartnerUserChannelDO hyPartnerUserChannelDO = hyPartnerUserChannelMapper . selectByChannelName ( channel ) ;
Long channelId = null ;
if ( StringUtil . isNotEmpty ( channel ) ) {
if ( ObjectUtil . isNull ( hyPartnerUserChannelDO ) | | ObjectUtil . isNull ( hyPartnerUserChannelDO . getChannelId ( ) ) ) {
getChannelSource ( ) ;
}
HyPartnerUserChannelDO channelDO = hyPartnerUserChannelMapper . selectByChannelName ( channel ) ;
channelId = channelDO . getChannelId ( ) ;
}
return channelId ;
}
/**
* 招商公海内跟进次数大于等于1的用户EC同步该用户进去公海,假若跟进次数为0的同步到EC跟进人就是唐佑玉