更改手机号校验code码,重构ec同步代码

This commit is contained in:
xiaodong.hu
2023-10-27 13:55:38 +08:00
parent 19993c9ce8
commit 5498832bd4
7 changed files with 157 additions and 75 deletions

View File

@@ -17,6 +17,11 @@ import java.util.stream.Collectors;
*/
public enum ErrorCodeEnum {
PARTNER_MOBILE_INCORRECT(418, "请输入正确的手机号", null),
PUBLIC_LINE_NOT_FOLLOW(419, "该线索已存在公海,无跟进人", null),
LINE_EXIST_FOLLOW(420, "该线索已存在,跟进人为【{0}{1}】", null),
/**
* 000000 未知错误
*/
@@ -70,9 +75,7 @@ public enum ErrorCodeEnum {
MOBILE_EXIST(500015, "此手机号码已存在,请修改后重试", null),
INVESTMENT_MANAGER_NOT_EXIST(500016, "当前招商经理不存在", null),
PARTNER_MOBILE_EXIST_0(500017, "手机号码已存在", null),
PARTNER_MOBILE_INCORRECT(500018, "请输入正确的手机号", null),
PUBLIC_LINE_NOT_FOLLOW(500019, "该线索已存在公海,无跟进人", null),
LINE_EXIST_FOLLOW(500020, "该线索已存在,跟进人为{0}", null),
INTERVIEW_ENTER_FAIL(1021101, "进入面试间失败", null),
DINGDING_USER_NOT_EXIST(1021102, "用户钉钉信息不存在,无法发起资质审核!", null),

View File

@@ -115,7 +115,7 @@
SELECT crm_create_time as crmCreateTime FROM hy_partner_user_info ORDER BY crm_create_time desc limit 1
</select>
<select id="selectByCheckMobile" resultType="com.cool.store.dto.partner.MobileCheckDTO">
select a.partner_id as partnerId,a.mobile,line_status as lineStatus ,c.`name`as investmentManager FROM hy_partner_user_info a left join hy_partner_line_info b on a.partner_id=b.partner_id and b.deleted=0 left join enterprise_user c on b.investment_manager=c.user_id and c.deleted=0 WHERE a.mobile=#{mobile}
select a.partner_id as partnerId,a.mobile,line_status as lineStatus ,c.`name`as investmentManager,c.mobile as investmentManagerMobile FROM hy_partner_user_info a left join hy_partner_line_info b on a.partner_id=b.partner_id and b.deleted=0 left join enterprise_user c on b.investment_manager=c.user_id and c.deleted=0 WHERE a.mobile=#{mobile}
</select>
<insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">

View File

@@ -16,4 +16,6 @@ public class MobileCheckDTO {
private Integer lineStatus;
private String investmentManager;
private String investmentManagerMobile;
}

View File

@@ -10,5 +10,5 @@ public interface LineHighSeasService {
ResponseResult importLine(MultipartFile file);
Boolean addCheckout(String mobile);
ResponseResult addCheckout(String mobile);
}

View File

@@ -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(channelId)).setEcWantShopArea(customerInfoItem.getEcWantShopArea());
resultUser.setUsername(customerInfoItem.getName()).setMobile(customerInfoItem.getMobile()).setUserChannelId(Convert.toInt(getChannelId(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(followUserName)) {
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, followUserMobile));
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())) {
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);
updateEcCustomer(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)) {
ChangeFollowUserRequest 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);
changeEcFollowUser(customerInfoItem, ecClient, enterpriseUser, 1);
}
//电话不同
if (!enterpriseUser.getMobile().equals(followUserMobile)) {
ChangeFollowUserRequest 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);
changeEcFollowUser(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(time);
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, resultLine);
}
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(time);
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, resultLine);
}
}
/**
* 发送请求更改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跟进人就是唐佑玉

View File

@@ -259,7 +259,7 @@ public class LineHighSeasServiceImpl implements LineHighSeasService {
}
@Override
public Boolean addCheckout(String mobile) {
public ResponseResult addCheckout(String mobile) {
if (!isPhone(mobile)) {
throw new ServiceException(ErrorCodeEnum.PARTNER_MOBILE_INCORRECT);
}
@@ -268,10 +268,11 @@ public class LineHighSeasServiceImpl implements LineHighSeasService {
if (mobileCheckDTO.getLineStatus().equals(LineStatusEnum.PUBLIC_SEAS.getCode())) {
throw new ServiceException(ErrorCodeEnum.PUBLIC_LINE_NOT_FOLLOW);
} else {
throw new ServiceException(MessageFormat.format(ErrorCodeEnum.LINE_EXIST_FOLLOW.getMessage(),mobileCheckDTO.getInvestmentManager()));
String message = MessageFormat.format(ErrorCodeEnum.LINE_EXIST_FOLLOW.getMessage(), mobileCheckDTO.getInvestmentManager(), mobileCheckDTO.getInvestmentManagerMobile());
return new ResponseResult(ErrorCodeEnum.LINE_EXIST_FOLLOW.getCode(),message);
}
}
return Boolean.TRUE;
return ResponseResult.success() ;
}
/**

View File

@@ -44,6 +44,6 @@ public class LineHighSeasController {
@GetMapping("/addCheckout")
@ApiOperation("线索手机号校验")
public ResponseResult addCheckout(@Param("partnerMobile")String partnerMobile) throws ApiException {
return ResponseResult.success(lineHighSeasService.addCheckout(partnerMobile));
return lineHighSeasService.addCheckout(partnerMobile);
}
}