Prechádzať zdrojové kódy

coding:广告线索

zhangqin 1 deň pred
rodič
commit
7019d86800

+ 1 - 1
fs-ad-new-api/Dockerfile

@@ -1,4 +1,4 @@
-FROM openjdk:8-jre
+FROM anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/openjdk:8-8.6
 # java版本,最好使用openjdk,而不是类似于Java:1.8
 COPY ./target/fs-ad-new-api.jar fs-ad-new-api.jar
 # 向外暴露的接口,最好与项目yml文件中的端口一致

+ 12 - 1
fs-qw-api/src/main/java/com/fs/app/service/QwDataCallbackService.java

@@ -1,6 +1,7 @@
 package com.fs.app.service;
 
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.fs.app.util.WXBizMsgCrypt;
 import com.fs.common.core.domain.AjaxResult;
@@ -8,6 +9,7 @@ import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.PubFun;
 import com.fs.company.service.ICompanyConfigService;
+import com.fs.newAdv.service.ILeadService;
 import com.fs.qw.domain.*;
 import com.fs.qw.mapper.QwCompanyMapper;
 import com.fs.qw.mapper.QwExternalContactMapper;
@@ -92,6 +94,8 @@ public class QwDataCallbackService {
     private RedisCache redisCache;
     @Autowired
     private QwCompanyMapper qwCompanyMapper;
+    @Autowired
+    private ILeadService leadService;
 
     @Async
     public void dataCallback( Document document,String corpId,QwCompany qwCompany) throws Exception {
@@ -224,10 +228,15 @@ public class QwDataCallbackService {
                                     String qwApiExternal = redisCache.getCacheObject(cacheKey);
                                     if (StringUtil.strIsNullOrEmpty(qwApiExternal)) {
                                         try {
+                                            String externalUserID = root.getElementsByTagName("ExternalUserID").item(0).getTextContent();
+                                            String userID = root.getElementsByTagName("UserID").item(0).getTextContent();
                                             // 5. 新增用户
-                                            qwExternalContactService.insertQwExternalContactByExternalUserId(root.getElementsByTagName("ExternalUserID").item(0).getTextContent(),root.getElementsByTagName("UserID").item(0).getTextContent(),null,corpId,State,WelcomeCode);
+                                            qwExternalContactService.insertQwExternalContactByExternalUserId(externalUserID,userID,null,corpId,State,WelcomeCode);
                                             // 6. 业务逻辑执行成功后,写入 Redis 缓存(有效期 10 分钟)
                                             redisCache.setCacheObject(cacheKey, "1", 10, TimeUnit.MINUTES);
+
+                                            // 广告线索处理
+                                            leadService.updateAddMemberLead(externalUserID,userID,corpId,State);
                                         } catch (Exception e) {
                                             // 7. 业务逻辑失败时,删除缓存
                                             redisCache.deleteObject(cacheKey);
@@ -404,6 +413,8 @@ public class QwDataCallbackService {
 
                                     if (qwGroupChatUserOld==null) {
                                         qwGroupChatUserService.insertQwGroupChatUser(qwGroupChatUser);
+                                        // 群员入群 广告判断记录
+                                        leadService.updateGroupAddMemberLead(qwGroupChatUser.getName(),qwGroupChatUser.getChatId(),qwGroupChatUser.getCorpId(),qwGroupChatUser.getUnionid());
                                     }else {
                                         qwGroupChatUserOld.setIsOut(1L);
                                         qwGroupChatUserOld.setCorpId(corpId);

+ 8 - 0
fs-service/src/main/java/com/fs/newAdv/domain/Lead.java

@@ -83,6 +83,10 @@ public class Lead implements Serializable {
      * 群Id
      */
     private String chatId;
+    /**
+     * 企微主题Id
+     */
+    private String corpId;
     /**
      * 是否添加企微 1是 0否
      */
@@ -101,6 +105,10 @@ public class Lead implements Serializable {
      */
     private String openid;
     private String unionid;
+    /**
+     * 微信名称 unionid不存在时关联
+     */
+    private String weiChatName;
     /**
      * 小程序授权1是 0否
      */

+ 4 - 0
fs-service/src/main/java/com/fs/newAdv/service/ILeadService.java

@@ -31,6 +31,10 @@ public interface ILeadService extends IService<Lead> {
      * 用户添加企业微信线索处理
      */
     void updateAddMemberLead(Long externalId, String unionId);
+    /**
+     * 用户添加企业微信线索处理
+     */
+    void updateAddMemberLead(String externalUserID,String userID,String corpId,String State);
     /**
      * 小程序授权线索处理
      * @param traceId

+ 37 - 13
fs-service/src/main/java/com/fs/newAdv/service/impl/LeadServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fs.newAdv.service.impl;
 
 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.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -61,23 +62,27 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
 
     @Override
     @Async
-    public void updateGroupAddMemberLead(String userId, String chatId, String corpId, String unionid) {
+    public void updateGroupAddMemberLead(String name, String chatId, String corpId, String 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) {
             lead.setChatId(chatId);
             lead.setAddContactQw(1);
+            lead.setCorpId(corpId);
             this.updateById(lead);
-
             if (ObjectUtil.isNotEmpty(lead.getLandingPageTs()) && lead.getLandingPageTs().toLocalDate().isEqual(LocalDate.now())) {
                 // 当日加群事件回调
                 conversionEventPublisher.publishConversionEvent(lead.getTraceId(), SystemEventTypeEnum.GROUP_TODAY);
             }
         } else {
-            log.info("用户加群线索信息不存在:{}", userId);
+            log.info("用户加群线索信息不存在:{}", name);
         }
 
 
@@ -91,13 +96,32 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
             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) {
+        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) {
-            lead.setExternalId(externalId);
+            lead.setExternalId(qwExternalContact.getId());
             lead.setAddContactQwGroup(1);
             this.updateById(lead);
             // 绑定企微用户线索关系
@@ -111,7 +135,7 @@ public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements IL
             }
 
         } else {
-            log.info("广告归因线索不存在:{} {}", externalId, unionid);
+            log.info("广告归因线索不存在:{}", qwExternalContact);
         }
     }
 

+ 7 - 0
fs-user-app/src/main/java/com/fs/app/controller/store/WxUserScrmController.java

@@ -244,6 +244,7 @@ public class WxUserScrmController extends AppBaseController {
             if (!wxService.getUserService().checkUserInfo(session.getSessionKey(), param.getRawData(), param.getSignature())) {
                 return R.error("user check failed");
             }
+
             // 解密用户信息
             WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv());
             FsUserScrm user=userService.selectFsUserById(Long.parseLong(getUserId()));
@@ -286,6 +287,12 @@ public class WxUserScrmController extends AppBaseController {
             logger.info("session 得到:{}" , session);
             // 解密
             WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv());
+            try {
+                WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv());
+                logger.info("userInfo 获取:{}" , userInfo);
+            }catch (Exception e){
+                logger.info("获取用户信息失败!",e);
+            }
             FsUserScrm user=new FsUserScrm();
             logger.info("===========用户unionid:{},用户openid:{}",session.getUnionid(),session.getOpenid());
             if (session.getUnionid()!=null){