|
@@ -1,6 +1,7 @@
|
|
|
package com.fs.newAdv.service.impl;
|
|
package com.fs.newAdv.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -11,17 +12,14 @@ import com.fs.newAdv.mapper.LeadMapper;
|
|
|
import com.fs.newAdv.service.ILeadService;
|
|
import com.fs.newAdv.service.ILeadService;
|
|
|
import com.fs.qw.domain.QwExternalContact;
|
|
import com.fs.qw.domain.QwExternalContact;
|
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
-import com.fs.qwApi.domain.QwExternalContactResult;
|
|
|
|
|
-import com.fs.qwApi.service.QwApiService;
|
|
|
|
|
|
|
+import com.fs.qw.service.IQwExternalContactService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
-import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 域名管理Service实现类
|
|
* 域名管理Service实现类
|
|
@@ -36,9 +34,9 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ConversionEventPublisher conversionEventPublisher;
|
|
private ConversionEventPublisher conversionEventPublisher;
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private QwApiService qwApiService;
|
|
|
|
|
|
|
+ private IQwExternalContactService qwExternalContactService;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private QwExternalContactMapper qwExternalContactMapper;
|
|
private QwExternalContactMapper qwExternalContactMapper;
|
|
|
|
|
|
|
@@ -52,27 +50,40 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
|
|
|
return list.isEmpty() ? null : list.get(0);
|
|
return list.isEmpty() ? null : list.get(0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Lead getByClickId(String clickId) {
|
|
|
|
|
+ List<Lead> list = this.list(new LambdaQueryWrapper<Lead>()
|
|
|
|
|
+ .eq(Lead::getClickId, clickId));
|
|
|
|
|
+ if (list.size() > 1) {
|
|
|
|
|
+ log.error("查询投流点击信息不唯一:{}", clickId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return list.isEmpty() ? null : list.get(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Async
|
|
@Async
|
|
|
- public void updateGroupAddMemberLead(String userId, String chatId, String corpId, String unionid) {
|
|
|
|
|
|
|
+ public void updateGroupAddMemberLead(String name, String chatId, String corpId, String unionid) {
|
|
|
|
|
+ log.info("用户加群线索信息:{} {} {} {}", name, chatId, corpId, unionid);
|
|
|
|
|
+ LambdaQueryWrapper<Lead> last = new LambdaQueryWrapper<Lead>();
|
|
|
|
|
+ if (StrUtil.isNotEmpty(unionid)) {
|
|
|
|
|
+ last.eq(Lead::getUnionid, unionid);
|
|
|
|
|
+ } else if (StrUtil.isNotEmpty(name)) {
|
|
|
|
|
+ last.eq(Lead::getWeiChatName, name);
|
|
|
|
|
+ }
|
|
|
|
|
+ last.eq(Lead::getAddContactQw, 0).last("LIMIT 1");
|
|
|
// 末次归因逻辑
|
|
// 末次归因逻辑
|
|
|
- Lead lead = this.getOne(new LambdaQueryWrapper<Lead>()
|
|
|
|
|
- .eq(Lead::getUnionid, unionid)
|
|
|
|
|
- .eq(Lead::getAddContactQw, 0)
|
|
|
|
|
- .last("LIMIT 1"));
|
|
|
|
|
|
|
+ Lead lead = this.getOne(last);
|
|
|
if (lead != null) {
|
|
if (lead != null) {
|
|
|
- lead.setCorpId(corpId);
|
|
|
|
|
lead.setChatId(chatId);
|
|
lead.setChatId(chatId);
|
|
|
- lead.setUserId(userId);
|
|
|
|
|
lead.setAddContactQw(1);
|
|
lead.setAddContactQw(1);
|
|
|
|
|
+ lead.setCorpId(corpId);
|
|
|
this.updateById(lead);
|
|
this.updateById(lead);
|
|
|
-
|
|
|
|
|
if (ObjectUtil.isNotEmpty(lead.getLandingPageTs()) && lead.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
|
|
if (ObjectUtil.isNotEmpty(lead.getLandingPageTs()) && lead.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
|
|
|
// 当日加群事件回调
|
|
// 当日加群事件回调
|
|
|
conversionEventPublisher.publishConversionEvent(lead.getTraceId(), SystemEventTypeEnum.GROUP_TODAY);
|
|
conversionEventPublisher.publishConversionEvent(lead.getTraceId(), SystemEventTypeEnum.GROUP_TODAY);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- log.info("用户加群线索信息不存在:{}", userId);
|
|
|
|
|
|
|
+ log.info("用户加群线索信息不存在:{}", name);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -80,65 +91,90 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Async
|
|
@Async
|
|
|
- public CompletableFuture<String> updateAddMemberLead(String externalUserID, String userID, String corpId, String state) {
|
|
|
|
|
- QwExternalContactResult externalContactResult = qwApiService.getExternalcontact(externalUserID, corpId);
|
|
|
|
|
- String unionid = externalContactResult.getExternal_contact().getUnionid();
|
|
|
|
|
|
|
+ public void updateAddMemberLead(Long externalId, String unionid) {
|
|
|
|
|
+ QwExternalContact qwExternalContact = qwExternalContactService.selectQwExternalContactById(externalId);
|
|
|
|
|
+ if (qwExternalContact == null) {
|
|
|
|
|
+ log.info("外部联系人信息不存在:{}", externalId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ qwExternalContact.setUnionid(unionid);
|
|
|
|
|
+ this.updateAddMemberLead(qwExternalContact);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void updateAddMemberLead(String externalUserID, String userID, String corpId, String State) {
|
|
|
|
|
+ QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalByExternalIdAndCompanyIdToIdAndFs(externalUserID, userID, corpId);
|
|
|
|
|
+ if (qwExternalContact == null) {
|
|
|
|
|
+ log.info("外部联系人信息不存在:{} {} {}", externalUserID, userID, corpId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ this.updateAddMemberLead(qwExternalContact);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void updateAddMemberLead(QwExternalContact qwExternalContact) {
|
|
|
|
|
+ log.info("用户加微线索信息:{}", qwExternalContact);
|
|
|
|
|
+ LambdaQueryWrapper<Lead> last = new LambdaQueryWrapper<Lead>();
|
|
|
|
|
+ if (StrUtil.isNotEmpty(qwExternalContact.getUnionid())) {
|
|
|
|
|
+ last.eq(Lead::getUnionid, qwExternalContact.getUnionid());
|
|
|
|
|
+ } else if (StrUtil.isNotEmpty(qwExternalContact.getName())) {
|
|
|
|
|
+ last.eq(Lead::getWeiChatName, qwExternalContact.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ last.eq(Lead::getAddContactQwGroup, 0).last("LIMIT 1");
|
|
|
// 末次归因逻辑
|
|
// 末次归因逻辑
|
|
|
- Lead lead = this.getOne(new LambdaQueryWrapper<Lead>()
|
|
|
|
|
- .eq(Lead::getUnionid, unionid)
|
|
|
|
|
- .eq(Lead::getAddContactQwGroup, 0)
|
|
|
|
|
- .last("LIMIT 1"));
|
|
|
|
|
|
|
+ Lead lead = this.getOne(last);
|
|
|
if (lead != null) {
|
|
if (lead != null) {
|
|
|
- lead.setExternalUserId(externalUserID);
|
|
|
|
|
- lead.setCorpId(corpId);
|
|
|
|
|
- lead.setUserId(userID);
|
|
|
|
|
|
|
+ lead.setExternalId(qwExternalContact.getId());
|
|
|
lead.setAddContactQwGroup(1);
|
|
lead.setAddContactQwGroup(1);
|
|
|
this.updateById(lead);
|
|
this.updateById(lead);
|
|
|
-
|
|
|
|
|
// 绑定企微用户线索关系
|
|
// 绑定企微用户线索关系
|
|
|
- QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalByExternalIdAndCompanyIdToIdAndFs(externalUserID, userID, corpId);
|
|
|
|
|
- if (qwExternalContact != null){
|
|
|
|
|
- QwExternalContact temp = new QwExternalContact();
|
|
|
|
|
- temp.setId(qwExternalContact.getId());
|
|
|
|
|
- temp.setTraceId(lead.getTraceId());
|
|
|
|
|
- qwExternalContactMapper.updateById(temp);
|
|
|
|
|
- }else {
|
|
|
|
|
- log.info("广告归因企微用户信息不存在:{} {} {} ", externalUserID, userID,corpId);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ QwExternalContact temp = new QwExternalContact();
|
|
|
|
|
+ temp.setId(qwExternalContact.getId());
|
|
|
|
|
+ temp.setTraceId(lead.getTraceId());
|
|
|
|
|
+ qwExternalContactMapper.updateById(temp);
|
|
|
if (ObjectUtil.isNotEmpty(lead.getLandingPageTs()) && lead.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
|
|
if (ObjectUtil.isNotEmpty(lead.getLandingPageTs()) && lead.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
|
|
|
// 当日加微事件回调
|
|
// 当日加微事件回调
|
|
|
conversionEventPublisher.publishConversionEvent(lead.getTraceId(), SystemEventTypeEnum.WEI_CHAT_TODAY);
|
|
conversionEventPublisher.publishConversionEvent(lead.getTraceId(), SystemEventTypeEnum.WEI_CHAT_TODAY);
|
|
|
}
|
|
}
|
|
|
- return CompletableFuture.completedFuture(lead.getTraceId());
|
|
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
- log.info("广告归因线索不存在:{} {} {}", externalUserID, userID,corpId);
|
|
|
|
|
|
|
+ log.info("广告归因线索不存在:{}", qwExternalContact);
|
|
|
}
|
|
}
|
|
|
- return CompletableFuture.completedFuture(null);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Async
|
|
@Async
|
|
|
public void weChatAuthorizationLead(String traceId, String unionId, String maOpenId, String phone) {
|
|
public void weChatAuthorizationLead(String traceId, String unionId, String maOpenId, String phone) {
|
|
|
- try{
|
|
|
|
|
- log.info("用户微信授权线索信息:{}", traceId);
|
|
|
|
|
- Lead byTraceId = this.getByTraceId(traceId);
|
|
|
|
|
- if (byTraceId == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.update(new LambdaUpdateWrapper<Lead>()
|
|
|
|
|
- .eq(Lead::getTraceId, traceId)
|
|
|
|
|
- .set(ObjectUtil.isNotEmpty(unionId),Lead::getUnionid, unionId)
|
|
|
|
|
- .set(ObjectUtil.isNotEmpty(phone),Lead::getPhone, phone)
|
|
|
|
|
- .set(ObjectUtil.isNotEmpty(maOpenId),Lead::getOpenid, maOpenId)
|
|
|
|
|
- .set(Lead::getMiniAuth, 1));
|
|
|
|
|
- if (ObjectUtil.isNotEmpty(byTraceId.getLandingPageTs()) && byTraceId.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
|
|
|
|
|
- // 微信授权且当日创建事件
|
|
|
|
|
- log.info("用户微信授权线索事件回传:{}", traceId);
|
|
|
|
|
- conversionEventPublisher.publishConversionEvent(traceId, SystemEventTypeEnum.AUTH_TODAY_CREATE);
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ log.info("用户微信授权线索信息:{} {} {} {}", traceId, unionId, phone, maOpenId);
|
|
|
|
|
+ Lead byTraceId = this.getByTraceId(traceId);
|
|
|
|
|
+ if (byTraceId == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ this.update(new LambdaUpdateWrapper<Lead>()
|
|
|
|
|
+ .eq(Lead::getTraceId, traceId)
|
|
|
|
|
+ .set(ObjectUtil.isNotEmpty(unionId), Lead::getUnionid, unionId)
|
|
|
|
|
+ .set(ObjectUtil.isNotEmpty(phone), Lead::getPhone, phone)
|
|
|
|
|
+ .set(ObjectUtil.isNotEmpty(maOpenId), Lead::getOpenid, maOpenId)
|
|
|
|
|
+ .set(Lead::getMiniAuth, 1));
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(byTraceId.getLandingPageTs()) && byTraceId.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
|
|
|
|
|
+ // 微信授权且当日创建事件
|
|
|
|
|
+ log.info("用户微信授权线索事件回传:{}", traceId);
|
|
|
|
|
+ conversionEventPublisher.publishConversionEvent(traceId, SystemEventTypeEnum.AUTH_TODAY_CREATE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Async
|
|
|
|
|
+ public void weChatNameLead(String traceId, String weiChatName) {
|
|
|
|
|
+ log.info("用户微信昵称线索信息:{} {}", traceId, weiChatName);
|
|
|
|
|
+ Lead byTraceId = this.getByTraceId(traceId);
|
|
|
|
|
+ if (byTraceId == null || StrUtil.isEmpty(weiChatName)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ this.update(new LambdaUpdateWrapper<Lead>()
|
|
|
|
|
+ .eq(Lead::getTraceId, traceId)
|
|
|
|
|
+ .isNull(Lead::getWeiChatName)
|
|
|
|
|
+ .set(Lead::getWeiChatName, weiChatName)
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -161,7 +197,7 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
|
|
|
boolean update = this.update(new LambdaUpdateWrapper<Lead>()
|
|
boolean update = this.update(new LambdaUpdateWrapper<Lead>()
|
|
|
.eq(Lead::getTraceId, traceId)
|
|
.eq(Lead::getTraceId, traceId)
|
|
|
.set(Lead::getMiniLaunchIndexCount, 1));
|
|
.set(Lead::getMiniLaunchIndexCount, 1));
|
|
|
- if (!update){
|
|
|
|
|
|
|
+ if (!update) {
|
|
|
log.error("发起进入小程序失败:{}", traceId);
|
|
log.error("发起进入小程序失败:{}", traceId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|