Parcourir la source

加分链接添加有效获客前置事件,客户发起会话回传条件

zoujiajian il y a 2 ans
Parent
commit
1968bcad47

+ 5 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -301,4 +301,9 @@ public interface Constant {
 	 * 设备客服活码用户分销专用
 	 */
 	Long EP_AC_CODE_ID = 7l;
+
+	/**
+	 * 有效获客
+	 */
+	String CUSTOMER_EFFECTIVE = "customer_effective";
 }

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpCustomerAcquisitionLinkPopularize.java

@@ -44,4 +44,9 @@ public class CorpCustomerAcquisitionLinkPopularize extends BaseEntity {
     @DbIgnore
     private String url;
 
+    /**
+     * 是否监听微信客户发起会话事件 才回传
+     */
+    private Boolean isChat;
+
 }

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/request/corp/CorpXmlMessage.java

@@ -236,6 +236,12 @@ public class CorpXmlMessage implements Serializable {
 	@JacksonXmlProperty(localName = "ChatId")
 	private String chatId;
 
+	/**
+	 * 获客链接ID
+	 */
+	@JacksonXmlProperty(localName = "LinkId")
+	private String LinkId;
+
 
 	public static CorpXmlMessage fromXml(String xml) {
 		//修改微信变态的消息内容格式,方便解析

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CorpCustomerAcquisitionLinkPopularizeView.java

@@ -61,6 +61,12 @@ public class CorpCustomerAcquisitionLinkPopularizeView {
 	@DbField("cap.time")
 	private Long time;
 
+	/**
+	 * 是否监听微信客户发起会话事件 才回传
+	 */
+	@DbField("cap.is_chat")
+	private Boolean isChat;
+
 	@DbField("cap.created_time")
 	private Date createdTime;
 }

+ 74 - 3
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java

@@ -569,6 +569,72 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		return null;
 	}
 
+	@Override
+	public CorpXmlOutMessage customerStartChat(CorpXmlMessage message, Map<String, Object> context) {
+		//微信客户发起会话事件
+		//外部联系人id
+		String externalUserId = message.getExternalUserId();
+		log.info("监听微信客户:{}发起会话事件", externalUserId);
+		//获客链接id
+		String linkId = message.getLinkId();
+		CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(Wrappers.lambdaQuery(CorpUserAuth.class)
+				.eq(CorpUserAuth::getExternalUserid, externalUserId).last("limit 1"));
+		String unionId = null;
+		if (corpUserAuth != null) {
+			CorpUser corpUser = corpUserMapper.selectById(corpUserAuth.getCorpUserId());
+			if (corpUser != null) {
+				unionId = corpUser.getUnionid();
+			}
+		}
+		if (StrUtil.isEmpty(unionId)) {
+			return null;
+		}
+		CorpCustomerAcquisitionLinkPopularize corpCustomerAcquisitionLinkPopularize = corpCustomerAcquisitionLinkPopularizeMapper.selectOne(Wrappers.lambdaQuery(CorpCustomerAcquisitionLinkPopularize.class)
+				.eq(CorpCustomerAcquisitionLinkPopularize::getCustomerAcquistionLinkId, linkId).last("limit 1"));
+		if (corpCustomerAcquisitionLinkPopularize != null) {
+			//callback
+			String callback = null;
+			String params = redisService.getStr(String.format(RedisService.key.CORP_CUSTOMER_ACQUISTION_UNIONID_CLICKID.getName(), unionId));
+			if (StringUtils.isNotBlank(params)) {
+				JSONObject paramsObj = JSONUtil.parseObj(params);
+				callback = paramsObj.getStr("callback");
+			}
+			//如果需要延后主动回传的做持久化.
+			if (StrUtil.isNotBlank(callback)) {
+				log.info("开始回传客户:{}发起会话事件", externalUserId);
+				//如果为加粉则直接回传
+				if (corpCustomerAcquisitionLinkPopularize.getType() == 1) {
+					//如果需要延后主动回传的做持久化.
+					if (!corpCustomerAcquisitionLinkPopularize.getDelayedPost()) {
+						postData(callback, corpCustomerAcquisitionLinkPopularize.getEvent());
+					}
+				} else {
+					//深度转化 前置加粉事件回传.
+					if (StringUtils.isNotBlank(corpCustomerAcquisitionLinkPopularize.getAddEvent())) {
+						postData(callback, corpCustomerAcquisitionLinkPopularize.getAddEvent());
+					}
+				}
+
+				if (corpCustomerAcquisitionLinkPopularize.getDelayedPost()) {
+					CorpCustomerAcquistionCallback corpCustomerAcquistionCallback =
+							corpCustomerAcquistionCallbackMapper.selectOne(Wrappers.lambdaQuery(CorpCustomerAcquistionCallback.class).eq(CorpCustomerAcquistionCallback::getCallback, callback).eq(CorpCustomerAcquistionCallback::getUnionId, unionId));
+					if (corpCustomerAcquistionCallback == null) {
+						corpCustomerAcquistionCallback = new CorpCustomerAcquistionCallback();
+					}
+					corpCustomerAcquistionCallback.setCallback(callback);
+					corpCustomerAcquistionCallback.setEvent(corpCustomerAcquisitionLinkPopularize.getEvent());
+					corpCustomerAcquistionCallback.setUnionId(unionId);
+					if (corpCustomerAcquistionCallback.getId() != null) {
+						corpCustomerAcquistionCallbackMapper.updateById(corpCustomerAcquistionCallback);
+					} else {
+						corpCustomerAcquistionCallbackMapper.insert(corpCustomerAcquistionCallback);
+					}
+				}
+			}
+		}
+		return null;
+	}
+
 	/**
 	 * 修改客户成员关系,客户标签
 	 */
@@ -1124,12 +1190,17 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 					if (corpCustomerAcquisitionLinkPopularize.getType() == 1) {
 						//如果需要延后主动回传的做持久化.
 						if(!corpCustomerAcquisitionLinkPopularize.getDelayedPost()){
-							postData(callback, corpCustomerAcquisitionLinkPopularize.getEvent());
+							if (!corpCustomerAcquisitionLinkPopularize.getIsChat()) {
+								postData(callback, corpCustomerAcquisitionLinkPopularize.getEvent());
+							}
 						}
 					}else {
 						//深度转化 前置加粉事件回传.
-						if(StringUtils.isNotBlank(corpCustomerAcquisitionLinkPopularize.getAddEvent())){
-							postData(callback, corpCustomerAcquisitionLinkPopularize.getAddEvent());
+						if (StringUtils.isNotBlank(corpCustomerAcquisitionLinkPopularize.getAddEvent())) {
+							//是否是监听客户发起会话事件 false
+							if (!corpCustomerAcquisitionLinkPopularize.getIsChat()) {
+								postData(callback, corpCustomerAcquisitionLinkPopularize.getAddEvent());
+							}
 						}
 
 						//深度回传.

+ 9 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java

@@ -164,6 +164,15 @@ public class CorpServiceImpl implements CorpService {
 					}
 				})
 				.end()
+				//微信客户发起会话事件
+				.rule().async(false).changeType("customer_start_chat").event("customer_acquisition")
+				.handler(new CorpMessageHandler() {
+					@Override
+					public CorpXmlOutMessage handle(CorpXmlMessage message, Map<String, Object> context, CorpService corpService) throws Exception {
+						return corpEventActionService.customerStartChat(message, context);
+					}
+				})
+				.end()
 		;
 
 	}

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/corp/msg/CorpEventActionService.java

@@ -31,4 +31,6 @@ public interface CorpEventActionService {
 	CorpXmlOutMessage delCorpGroupChat(CorpXmlMessage message);
 
     CorpXmlOutMessage msgAuditApproved(CorpXmlMessage message, Map<String, Object> context);
+
+	CorpXmlOutMessage customerStartChat(CorpXmlMessage message, Map<String, Object> context);
 }