|
|
@@ -31,6 +31,7 @@ import com.fs.course.param.FsCourseLinkCreateParam;
|
|
|
import com.fs.course.param.FsCourseListBySidebarParam;
|
|
|
import com.fs.course.service.IFsCourseLinkService;
|
|
|
import com.fs.course.service.IFsUserCourseVideoService;
|
|
|
+import com.fs.course.service.IUserProjectRepeatMaintainService;
|
|
|
import com.fs.course.vo.FsUserCourseVideoQVO;
|
|
|
import com.fs.crm.domain.CrmCustomer;
|
|
|
import com.fs.crm.mapper.CrmCustomerMapper;
|
|
|
@@ -217,6 +218,9 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
@Autowired
|
|
|
private FsUserCourseMapper fsUserCourseMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserProjectRepeatMaintainService userProjectRepeatMaintainService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IQwExternalErrRetryService errRetryService;
|
|
|
|
|
|
@@ -1190,7 +1194,9 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
qwExternalContactTransferLog.setTakeoverUserId(qwUser.getQwUserId());
|
|
|
qwExternalContactTransferLog.setCorpId(param.getCorpId());
|
|
|
qwExternalContactTransferLog.setExternalUserId(qwCustomer.getExternal_userid());
|
|
|
+ qwExternalContactTransferLog.setHandoverQwUserId(qwExternalContact.getQwUserId());
|
|
|
qwExternalContactTransferLog.setNeedClearTag(param.getNeedClearTag());
|
|
|
+ qwExternalContactTransferLog.setFsUserId(qwExternalContact.getFsUserId());
|
|
|
qwExternalContactTransferLogMapper.insertQwExternalContactTransferLog(qwExternalContactTransferLog);
|
|
|
QwExternalContact qwExternal = new QwExternalContact();
|
|
|
qwExternal.setStatus(2);
|
|
|
@@ -2002,6 +2008,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
contact1.setTransferStatus(1);
|
|
|
contact1.setExternalUserId(transferLogListByCheck.getExternalUserId());
|
|
|
qwExternalContactMapper.updateQwExternalContactByUseridTransfer(contact1);
|
|
|
+ applyTransferContactInfo(qwExternalContact.getId(), transferLogListByCheck, null);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2795,9 +2802,22 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
qwExternalContactMapper.updateQwExternalContactByUseridTransfer(contact1);
|
|
|
}
|
|
|
|
|
|
+ Long transferOldContactId = null;
|
|
|
+ if (transferLogListByCheck != null) {
|
|
|
+ transferOldContactId = transferLogListByCheck.getExternalContactId();
|
|
|
+ } else if (!auditUserList.isEmpty()) {
|
|
|
+ transferOldContactId = auditUserList.get(0).getExternalId();
|
|
|
+ }
|
|
|
//上面存过了,这里就更新
|
|
|
qwExternalContact.setId(contact.getId());
|
|
|
+ if (transferLogListByCheck != null || !auditUserList.isEmpty()) {
|
|
|
+ fillTransferContactInfo(qwExternalContact, transferLogListByCheck, transferOldContactId);
|
|
|
+ applyTransferRemarkAndTags(qwExternalContact, transferLogListByCheck, transferOldContactId, needClearTag);
|
|
|
+ }
|
|
|
qwExternalContactMapper.updateQwExternalContact(qwExternalContact);
|
|
|
+ if (transferLogListByCheck != null || !auditUserList.isEmpty()) {
|
|
|
+ migrateTransferProjectRepeat(transferLogListByCheck, transferOldContactId, qwExternalContact);
|
|
|
+ }
|
|
|
QwOpenidByExternalcontactParams externalcontactParams = new QwOpenidByExternalcontactParams();
|
|
|
externalcontactParams.setExternal_userid(externalUserID);
|
|
|
//录入单独的CRM客户信息 没啥用
|
|
|
@@ -2825,8 +2845,10 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
}
|
|
|
/*只有ddgy加重粉*/
|
|
|
if (("叮当国医".equals(cloudHostProper.getCompanyName()))) {
|
|
|
- if (qwExternalContactMapper.selectCount(new LambdaQueryWrapper<QwExternalContact>().eq(QwExternalContact::getExternalUserId, qwExternalContact.getExternalUserId()))
|
|
|
- >1){
|
|
|
+ long activeCount = qwExternalContactMapper.selectCount(new LambdaQueryWrapper<QwExternalContact>()
|
|
|
+ .eq(QwExternalContact::getExternalUserId, qwExternalContact.getExternalUserId())
|
|
|
+ .ne(QwExternalContact::getStatus, 4));
|
|
|
+ if (activeCount > 1){
|
|
|
qwExternalContact.setIsRepeat(1);
|
|
|
qwExternalContactMapper.update(null,new LambdaUpdateWrapper<QwExternalContact>().eq(QwExternalContact::getId,qwExternalContact.getId())
|
|
|
.set(QwExternalContact::getIsRepeat,1));
|
|
|
@@ -3365,7 +3387,15 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
|
|
|
//上面存过了,这里就更新
|
|
|
qwExternalContact.setId(contact.getId());
|
|
|
+ if (transferLogListByCheck != null) {
|
|
|
+ fillTransferContactInfo(qwExternalContact, transferLogListByCheck, transferLogListByCheck.getExternalContactId());
|
|
|
+ boolean needClearTag = transferLogListByCheck.getNeedClearTag() != null && transferLogListByCheck.getNeedClearTag() == 1;
|
|
|
+ applyTransferRemarkAndTags(qwExternalContact, transferLogListByCheck, transferLogListByCheck.getExternalContactId(), needClearTag);
|
|
|
+ }
|
|
|
qwExternalContactMapper.updateQwExternalContact(qwExternalContact);
|
|
|
+ if (transferLogListByCheck != null) {
|
|
|
+ migrateTransferProjectRepeat(transferLogListByCheck, transferLogListByCheck.getExternalContactId(), qwExternalContact);
|
|
|
+ }
|
|
|
QwOpenidByExternalcontactParams externalcontactParams = new QwOpenidByExternalcontactParams();
|
|
|
externalcontactParams.setExternal_userid(externalUserID);
|
|
|
//录入单独的CRM客户信息 没啥用
|
|
|
@@ -4455,6 +4485,195 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void applyTransferContactInfo(Long newContactId, QwExternalContactTransferLog transferLog, Long oldContactId) {
|
|
|
+ if (newContactId == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QwExternalContact update = new QwExternalContact();
|
|
|
+ update.setId(newContactId);
|
|
|
+ fillTransferContactInfo(update, transferLog, oldContactId);
|
|
|
+ qwExternalContactMapper.updateQwExternalContact(update);
|
|
|
+ QwExternalContact newContact = qwExternalContactMapper.selectQwExternalContactById(newContactId);
|
|
|
+ if (newContact != null) {
|
|
|
+ applyTransferRemarkAndTags(newContact, transferLog, oldContactId);
|
|
|
+ updateTransferRemarkAndTagsInDb(newContactId, newContact);
|
|
|
+ newContact.setFsUserId(update.getFsUserId());
|
|
|
+ newContact.setIsTransfer(update.getIsTransfer());
|
|
|
+ migrateTransferProjectRepeat(transferLog, oldContactId, newContact);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void migrateTransferProjectRepeat(QwExternalContactTransferLog transferLog, Long oldContactId, QwExternalContact newContact) {
|
|
|
+ if (newContact == null || newContact.getFsUserId() == null || newContact.getQwUserId() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long oldQwUserId = null;
|
|
|
+ if (transferLog != null && transferLog.getHandoverQwUserId() != null) {
|
|
|
+ oldQwUserId = transferLog.getHandoverQwUserId();
|
|
|
+ }
|
|
|
+ if (oldQwUserId == null && oldContactId != null) {
|
|
|
+ QwExternalContact oldContact = qwExternalContactMapper.selectQwExternalContactById(oldContactId);
|
|
|
+ if (oldContact != null) {
|
|
|
+ oldQwUserId = oldContact.getQwUserId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userProjectRepeatMaintainService.migrateQwUserOnTransfer(
|
|
|
+ newContact.getFsUserId(), oldQwUserId, newContact.getQwUserId(), newContact.getCompanyId());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillTransferContactInfo(QwExternalContact target, QwExternalContactTransferLog transferLog, Long oldContactId) {
|
|
|
+ target.setIsTransfer(1);
|
|
|
+ Long fsUserId = resolveTransferFsUserId(transferLog, oldContactId);
|
|
|
+ if (fsUserId != null) {
|
|
|
+ target.setFsUserId(fsUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long resolveTransferFsUserId(QwExternalContactTransferLog transferLog, Long oldContactId) {
|
|
|
+ if (transferLog != null && transferLog.getFsUserId() != null) {
|
|
|
+ return transferLog.getFsUserId();
|
|
|
+ }
|
|
|
+ QwExternalContact oldContact = resolveOldTransferContact(transferLog, oldContactId);
|
|
|
+ return oldContact == null ? null : oldContact.getFsUserId();
|
|
|
+ }
|
|
|
+
|
|
|
+ private QwExternalContact resolveOldTransferContact(QwExternalContactTransferLog transferLog, Long oldContactId) {
|
|
|
+ Long sourceContactId = oldContactId;
|
|
|
+ if (sourceContactId == null && transferLog != null) {
|
|
|
+ sourceContactId = transferLog.getExternalContactId();
|
|
|
+ }
|
|
|
+ if (sourceContactId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return qwExternalContactMapper.selectQwExternalContactById(sourceContactId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void applyTransferRemarkAndTags(QwExternalContact newContact, QwExternalContactTransferLog transferLog, Long oldContactId) {
|
|
|
+ applyTransferRemarkAndTags(newContact, transferLog, oldContactId, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void applyTransferRemarkAndTags(QwExternalContact newContact, QwExternalContactTransferLog transferLog,
|
|
|
+ Long oldContactId, Boolean needClearTagOverride) {
|
|
|
+ if (newContact == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QwExternalContact oldContact = resolveOldTransferContact(transferLog, oldContactId);
|
|
|
+ if (oldContact == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean needClearTag = needClearTagOverride != null
|
|
|
+ ? needClearTagOverride
|
|
|
+ : (transferLog != null && Integer.valueOf(1).equals(transferLog.getNeedClearTag()));
|
|
|
+
|
|
|
+ String userId = newContact.getUserId();
|
|
|
+ String externalUserId = newContact.getExternalUserId();
|
|
|
+ String corpId = newContact.getCorpId();
|
|
|
+ if (StringUtil.strIsNullOrEmpty(userId) || StringUtil.strIsNullOrEmpty(externalUserId) || StringUtil.strIsNullOrEmpty(corpId)) {
|
|
|
+ logger.warn("转接同步备注标签跳过:新客户缺少必要字段 contactId={}", newContact.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean hasRemark = !StringUtil.strIsNullOrEmpty(oldContact.getRemark());
|
|
|
+ boolean hasDescription = !StringUtil.strIsNullOrEmpty(oldContact.getDescription());
|
|
|
+ boolean hasRemarkCorp = !StringUtil.strIsNullOrEmpty(oldContact.getRemarkCorpName());
|
|
|
+ boolean hasRemarkMobiles = !StringUtil.strIsNullOrEmpty(oldContact.getRemarkMobiles())
|
|
|
+ && !"[]".equals(oldContact.getRemarkMobiles().trim());
|
|
|
+
|
|
|
+ if (hasRemark) {
|
|
|
+ newContact.setRemark(oldContact.getRemark());
|
|
|
+ }
|
|
|
+ if (hasDescription) {
|
|
|
+ newContact.setDescription(oldContact.getDescription());
|
|
|
+ }
|
|
|
+ if (hasRemarkCorp) {
|
|
|
+ newContact.setRemarkCorpName(oldContact.getRemarkCorpName());
|
|
|
+ }
|
|
|
+ if (hasRemarkMobiles) {
|
|
|
+ newContact.setRemarkMobiles(oldContact.getRemarkMobiles());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> tagList = null;
|
|
|
+ if (!needClearTag && !StringUtil.strIsNullOrEmpty(oldContact.getTagIds()) && !"[]".equals(oldContact.getTagIds().trim())) {
|
|
|
+ try {
|
|
|
+ tagList = JSON.parseArray(oldContact.getTagIds(), String.class);
|
|
|
+ if (tagList != null) {
|
|
|
+ tagList = tagList.stream()
|
|
|
+ .filter(t -> !StringUtil.strIsNullOrEmpty(t))
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (tagList != null && !tagList.isEmpty()) {
|
|
|
+ newContact.setTagIds(JSON.toJSONString(tagList));
|
|
|
+ } else {
|
|
|
+ tagList = null;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("转接解析原客户标签失败 contactId={}, tagIds={}", oldContact.getId(), oldContact.getTagIds(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasRemark || hasDescription || hasRemarkCorp || hasRemarkMobiles) {
|
|
|
+ QwExternalContactRemarkParam remarkParam = new QwExternalContactRemarkParam();
|
|
|
+ remarkParam.setUserid(userId);
|
|
|
+ remarkParam.setExternal_userid(externalUserId);
|
|
|
+ if (hasRemark) {
|
|
|
+ remarkParam.setRemark(oldContact.getRemark());
|
|
|
+ }
|
|
|
+ if (hasDescription) {
|
|
|
+ remarkParam.setDescription(oldContact.getDescription());
|
|
|
+ }
|
|
|
+ if (hasRemarkCorp) {
|
|
|
+ remarkParam.setRemark_company(oldContact.getRemarkCorpName());
|
|
|
+ }
|
|
|
+ if (hasRemarkMobiles) {
|
|
|
+ try {
|
|
|
+ remarkParam.setRemark_mobiles(JSON.parseArray(oldContact.getRemarkMobiles(), String.class));
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("转接解析原客户备注手机号失败 contactId={}", oldContact.getId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ QwExternalContactRemarkResult remarkResult = qwApiService.externalcontactRemark(remarkParam, corpId);
|
|
|
+ if (remarkResult.getErrcode() == 45035) {
|
|
|
+ insertQwExternalErrRetryTool(corpId, JSON.toJSONString(remarkParam), 2, remarkResult.getErrmsg());
|
|
|
+ logger.error("转接同步备注失败-已加入补偿机制:{}", remarkParam);
|
|
|
+ } else if (remarkResult.getErrcode() != 0) {
|
|
|
+ logger.error("转接同步备注失败 errcode={}, errmsg={}, contactId={}",
|
|
|
+ remarkResult.getErrcode(), remarkResult.getErrmsg(), newContact.getId());
|
|
|
+ } else {
|
|
|
+ logger.info("转接同步备注成功 contactId={}, remark={}", newContact.getId(), oldContact.getRemark());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tagList != null && !tagList.isEmpty()) {
|
|
|
+ QwEditUserTagParam tagParam = new QwEditUserTagParam();
|
|
|
+ tagParam.setUserid(userId);
|
|
|
+ tagParam.setExternal_userid(externalUserId);
|
|
|
+ tagParam.setAdd_tag(tagList);
|
|
|
+ QwResult tagResult = qwApiService.editUserTag(tagParam, corpId);
|
|
|
+ if (tagResult.getErrcode() == 45035) {
|
|
|
+ insertQwExternalErrRetryTool(corpId, JSON.toJSONString(tagParam), 1, tagResult.getErrmsg());
|
|
|
+ logger.error("转接同步标签失败-已加入补偿机制:{}", tagParam);
|
|
|
+ } else if (tagResult.getErrcode() != 0) {
|
|
|
+ logger.error("转接同步标签失败 errcode={}, errmsg={}, contactId={}",
|
|
|
+ tagResult.getErrcode(), tagResult.getErrmsg(), newContact.getId());
|
|
|
+ } else {
|
|
|
+ logger.info("转接同步标签成功 contactId={}, tags={}", newContact.getId(), tagList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateTransferRemarkAndTagsInDb(Long contactId, QwExternalContact source) {
|
|
|
+ QwExternalContact update = new QwExternalContact();
|
|
|
+ update.setId(contactId);
|
|
|
+ update.setRemark(source.getRemark());
|
|
|
+ update.setDescription(source.getDescription());
|
|
|
+ update.setTagIds(source.getTagIds());
|
|
|
+ update.setRemarkMobiles(source.getRemarkMobiles());
|
|
|
+ update.setRemarkCorpName(source.getRemarkCorpName());
|
|
|
+ qwExternalContactMapper.updateQwExternalContact(update);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void transferFailByExternalUserId(String externalUserID, String userID, String corpId, String failReason) {
|
|
|
|