|
@@ -2,21 +2,26 @@ package com.cyksj.service.corp.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
import com.cyksj.common.constant.Constant;
|
|
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
import com.cyksj.common.util.IoKit;
|
|
import com.cyksj.common.util.IoKit;
|
|
|
import com.cyksj.common.util.J11HttpC;
|
|
import com.cyksj.common.util.J11HttpC;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
|
|
+import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.config.corp.WeChatCorpFactory;
|
|
import com.cyksj.config.corp.WeChatCorpFactory;
|
|
|
import com.cyksj.mapper.GroupsRelationExpiryRecordMapper;
|
|
import com.cyksj.mapper.GroupsRelationExpiryRecordMapper;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
|
|
+import com.cyksj.mapper.channel.ChannelPopularizeMapper;
|
|
|
import com.cyksj.mapper.corp.*;
|
|
import com.cyksj.mapper.corp.*;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
@@ -36,6 +41,9 @@ import com.cyksj.service.corp.msg.CorpEventActionService;
|
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
|
import com.cyksj.service.market.MarketFrontService;
|
|
import com.cyksj.service.market.MarketFrontService;
|
|
|
import com.cyksj.service.oceanengine.OceanengineService;
|
|
import com.cyksj.service.oceanengine.OceanengineService;
|
|
|
|
|
+import com.cyksj.service.order.OrderDonPostService;
|
|
|
|
|
+import com.cyksj.service.order.post.AbstractPostDataService;
|
|
|
|
|
+import com.cyksj.service.order.post.PostDataFactory;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
@@ -44,9 +52,11 @@ import com.ejlchina.searcher.util.MapUtils;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
import java.net.http.HttpRequest;
|
|
import java.net.http.HttpRequest;
|
|
|
import java.net.http.HttpResponse;
|
|
import java.net.http.HttpResponse;
|
|
@@ -119,6 +129,12 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
|
|
|
|
|
private final UserBindDetailMapper userBindDetailMapper;
|
|
private final UserBindDetailMapper userBindDetailMapper;
|
|
|
|
|
|
|
|
|
|
+ private final CorpCustomerAcquisitionLinkMapper corpCustomerAcquisitionLinkMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final CorpCustomerAcquisitionLinkPopularizeMapper corpCustomerAcquisitionLinkPopularizeMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final OrderDonPostService orderDonPostService;
|
|
|
|
|
+
|
|
|
private static final String DEFAULT_MSG = "您好,欢迎加入银河录像局";
|
|
private static final String DEFAULT_MSG = "您好,欢迎加入银河录像局";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -152,6 +168,7 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(Wrappers.lambdaQuery(CorpUserAuth.class).eq(CorpUserAuth::getExternalUserid, corpUserInfo.getExternalUserId()).eq(CorpUserAuth::getWxCorpId, wxCorpApp.getId()));
|
|
CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(Wrappers.lambdaQuery(CorpUserAuth.class).eq(CorpUserAuth::getExternalUserid, corpUserInfo.getExternalUserId()).eq(CorpUserAuth::getWxCorpId, wxCorpApp.getId()));
|
|
|
if (corpUserAuth == null) {
|
|
if (corpUserAuth == null) {
|
|
|
corpUserAuth = new CorpUserAuth();
|
|
corpUserAuth = new CorpUserAuth();
|
|
@@ -690,6 +707,15 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //加粉深度回传逻辑.
|
|
|
|
|
+ if(StrUtil.isNotBlank(message.getState()) && message.getState().contains(Constant.ACQUISTION_LINK_STATE_KEY)){
|
|
|
|
|
+ String customer = message.getState().replaceAll("customer_", "");
|
|
|
|
|
+ THREAD_POOL.execute(()->{
|
|
|
|
|
+ saveAcqusitionCallback(customer, corpUser, message.getExternalUserId(), message.getUserId());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//扫码来源
|
|
//扫码来源
|
|
|
if (corpUser.getId() == null) {
|
|
if (corpUser.getId() == null) {
|
|
|
corpUser.setState(state);
|
|
corpUser.setState(state);
|
|
@@ -962,4 +988,75 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
|
|
|
}
|
|
}
|
|
|
return relationUserIds;
|
|
return relationUserIds;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void saveAcqusitionCallback(String customer, CorpUser corpUser,String externalUserid ,String userId) {
|
|
|
|
|
+ //获客链接
|
|
|
|
|
+ Long linkId = customerAcquisitionSaveClickId(customer, corpUser.getUnionid());
|
|
|
|
|
+ CorpCustomerAcquisitionLink customerAcquisitionLink = corpCustomerAcquisitionLinkMapper.getByLinkPopularizeId(linkId);
|
|
|
|
|
+ corpUser.setCustomerAcquisitionLinkId(customerAcquisitionLink.getId());
|
|
|
|
|
+ if (StringUtils.isNotBlank(customerAcquisitionLink.getTags())){
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("处理获客链接客户标签");
|
|
|
|
|
+ List<Long> tags = Jsons.parseList(customerAcquisitionLink.getTags(), Long.class);
|
|
|
|
|
+ if (CollectionUtil.isEmpty(tags)) {
|
|
|
|
|
+ log.info("获客链接id为:{},无标签处理", customerAcquisitionLink.getId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 处理标签
|
|
|
|
|
+ List<CorpTag> tagList = corpTagMapper.selectBatchIds(tags);
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(tagList)) {
|
|
|
|
|
+ wxCorpOps.markTag(externalUserid, userId, tagList.stream().map(CorpTag::getTagId).toArray(String[]::new), null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理获客链接解析标签id出错了,内容{},获客链接id: {}", customerAcquisitionLink.getTags(), customerAcquisitionLink.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Long customerAcquisitionSaveClickId(String state, String unionId){
|
|
|
|
|
+ log.info("获客链接申请好友 state:{}",state);
|
|
|
|
|
+
|
|
|
|
|
+ Long linkId = null;
|
|
|
|
|
+ if (StringUtils.isNotBlank(state)){
|
|
|
|
|
+ //根据state获取缓存数据.
|
|
|
|
|
+ String json = redisService.getStr(String.format(RedisService.key.CORP_CUSTOMER_ACQUISTION_CLICKID.getName(),state));
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(json)){
|
|
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(json);
|
|
|
|
|
+ linkId = jsonObject.getLong("linkId");
|
|
|
|
|
+ //1.2版本 clickId 为前版本内容,后续都用callback 可能存在clickId数据 兼容
|
|
|
|
|
+ String callback = jsonObject.getStr("callback");
|
|
|
|
|
+
|
|
|
|
|
+ CorpCustomerAcquisitionLinkPopularize corpCustomerAcquisitionLinkPopularize = corpCustomerAcquisitionLinkPopularizeMapper.selectById(linkId);
|
|
|
|
|
+
|
|
|
|
|
+ if (corpCustomerAcquisitionLinkPopularize != null) {
|
|
|
|
|
+ //如果为加粉则直接回传
|
|
|
|
|
+ if (corpCustomerAcquisitionLinkPopularize.getType() == 1) {
|
|
|
|
|
+ postData(callback, corpCustomerAcquisitionLinkPopularize.getEvent());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //深度转化 前置加粉事件回传.
|
|
|
|
|
+ if(StringUtils.isNotBlank(corpCustomerAcquisitionLinkPopularize.getAddEvent())){
|
|
|
|
|
+ postData(callback, corpCustomerAcquisitionLinkPopularize.getAddEvent());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //深度回传.
|
|
|
|
|
+ redisService.set(String.format(RedisService.key.CORP_CUSTOMER_ACQUISTION_UNIONID_CLICKID.getName(),unionId), json, corpCustomerAcquisitionLinkPopularize.getTime() * 60 * 60);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return linkId;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 加粉回传 目前 OE
|
|
|
|
|
+ */
|
|
|
|
|
+ private void postData(String callback, String event) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ orderDonPostService.post(OrderDonPost.Type.OE.getType(), callback, event);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("加粉回传出错. error:" + StringUtil.getErrorText(e));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|