|
|
@@ -1,9 +1,12 @@
|
|
|
package com.fs.app.facade;
|
|
|
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.fs.app.integration.adapter.IAdvertiserAdapter;
|
|
|
import com.fs.app.integration.factory.AdvertiserHandlerFactory;
|
|
|
import com.fs.common.exception.base.BusinessException;
|
|
|
@@ -11,6 +14,7 @@ import com.fs.common.utils.RedisUtil;
|
|
|
import com.fs.newAdv.domain.LandingPageTemplate;
|
|
|
import com.fs.newAdv.domain.Lead;
|
|
|
import com.fs.newAdv.domain.Site;
|
|
|
+import com.fs.newAdv.dto.req.WeChatLandingIndexReq;
|
|
|
import com.fs.newAdv.dto.res.LandingIndexRes;
|
|
|
import com.fs.newAdv.enums.AdvertiserTypeEnum;
|
|
|
import com.fs.newAdv.service.ILandingPageTemplateService;
|
|
|
@@ -33,10 +37,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@@ -63,7 +66,7 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
- private static final String QR_CODE_KEY = "new-adv:qr-code:";
|
|
|
+ private static final String TEMPLATE_DATA = "new-adv:template-data:";
|
|
|
|
|
|
@Override
|
|
|
public void saveClickTrace(Long advertiserCode, Map<String, String> allParams) {
|
|
|
@@ -84,102 +87,137 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
}
|
|
|
|
|
|
private String getTraceIdByAdvertiser(AdvertiserTypeEnum byCode, Map<String, String> allParams) {
|
|
|
+ String traceId;
|
|
|
switch (byCode) {
|
|
|
case OCEANENGINE:
|
|
|
- return allParams.get("click_id");
|
|
|
case TENCENT:
|
|
|
- return allParams.get("click_id");
|
|
|
case OPPO:
|
|
|
- return allParams.get("traceId");
|
|
|
+ traceId = allParams.get("click_id");
|
|
|
+ break;
|
|
|
case BAIDU:
|
|
|
- return allParams.get("bd_vid");
|
|
|
+ traceId = allParams.get("bd_vid");
|
|
|
+ break;
|
|
|
case VIVO:
|
|
|
- return allParams.get("requestId");
|
|
|
+ traceId = allParams.get("requestId");
|
|
|
+ break;
|
|
|
case IQIYI:
|
|
|
- return allParams.get("traceId");
|
|
|
+ traceId = allParams.get("traceId");
|
|
|
+ break;
|
|
|
default:
|
|
|
- return "ylrz_test";
|
|
|
+ traceId = "ylrz_test";
|
|
|
}
|
|
|
+ if (StrUtil.isEmpty(traceId)) {
|
|
|
+ traceId = "ylrz_test";
|
|
|
+ }
|
|
|
+
|
|
|
+ return traceId;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public LandingIndexRes getLandingIndexBySiteId(Map<String, String> allParams) {
|
|
|
+ // 站点信息
|
|
|
String paramsSiteId = allParams.get("siteId");
|
|
|
if (ObjectUtil.isEmpty(paramsSiteId)) {
|
|
|
- log.error("站点id不存在:{}", paramsSiteId);
|
|
|
+ log.info("站点id不存在:{}", paramsSiteId);
|
|
|
return null;
|
|
|
}
|
|
|
Long siteId = Long.valueOf(paramsSiteId);
|
|
|
Site byId = siteService.getById(siteId);
|
|
|
if (ObjectUtil.isEmpty(byId)) {
|
|
|
- log.error("站点信息不存在:{}", siteId);
|
|
|
+ log.info("站点信息不存在:{}", siteId);
|
|
|
return null;
|
|
|
}
|
|
|
+ // 广告商信息
|
|
|
Long advertiserId = byId.getAdvertiserId();
|
|
|
// 访问链路id
|
|
|
String traceId = getTraceIdByAdvertiser(Objects.requireNonNull(AdvertiserTypeEnum.getByCode(advertiserId)), allParams);
|
|
|
- // 保存落地页访问记录
|
|
|
+ // 线索信息
|
|
|
Lead byTraceId = leadService.getByTraceId(traceId);
|
|
|
- if (ObjectUtil.isEmpty(byTraceId)) {
|
|
|
+ boolean isNewLead = ObjectUtil.isEmpty(byTraceId);
|
|
|
+ if (isNewLead) {
|
|
|
byTraceId = new Lead();
|
|
|
byTraceId.setAdvertiserId(advertiserId);
|
|
|
byTraceId.setSiteId(siteId);
|
|
|
- leadService.save(byTraceId);
|
|
|
- }
|
|
|
- if (!Objects.equals(byTraceId.getSiteId(), siteId)) {
|
|
|
- log.info("落地页站点信息异常:{}---{}", byTraceId.getSiteId(), siteId);
|
|
|
+ byTraceId.setTraceId(traceId);
|
|
|
+ } else {
|
|
|
+ // 检查站点和广告商信息是否异常
|
|
|
+ if (!Objects.equals(byTraceId.getSiteId(), siteId)) {
|
|
|
+ log.info("落地页站点信息异常:{}---{}", byTraceId.getSiteId(), siteId);
|
|
|
+ }
|
|
|
+ if (!Objects.equals(byTraceId.getAdvertiserId(), advertiserId)) {
|
|
|
+ log.info("落地页广告商信息异常:{}---{}", byTraceId.getAdvertiserId(), advertiserId);
|
|
|
+ }
|
|
|
}
|
|
|
- if (!Objects.equals(byTraceId.getAdvertiserId(), advertiserId)) {
|
|
|
- log.info("落地页广告商信息异常:{}---{}", byTraceId.getAdvertiserId(), advertiserId);
|
|
|
+ // 模板缓存
|
|
|
+ Object ca = redisUtil.get(TEMPLATE_DATA + traceId);
|
|
|
+ String templateData;
|
|
|
+ if (ca != null) {
|
|
|
+ templateData = String.valueOf(ca);
|
|
|
+ } else {
|
|
|
+ // 查询模板数据
|
|
|
+ LandingPageTemplate landingPageTemplate = landingPageTemplateService.getById(byId.getLaunchPageId());
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(landingPageTemplate.getTemplateData());
|
|
|
+ // 替换二维码链接
|
|
|
+ updateQrCodeInTemplate(jsonObject, traceId, byId, byTraceId);
|
|
|
+ templateData = JSONUtil.toJsonStr(jsonObject);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // 保存或更新 线索信息
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
byTraceId.setLandingPageRawParams(JSONUtil.toJsonStr(allParams));
|
|
|
byTraceId.setLandingPageTrigger(1);
|
|
|
- byTraceId.setLandingPageTs(LocalDateTime.now());
|
|
|
- byTraceId.setUpdateTime(LocalDateTime.now());
|
|
|
- if (ObjectUtil.isEmpty(byTraceId)) {
|
|
|
+ byTraceId.setLandingPageTs(now);
|
|
|
+ byTraceId.setUpdateTime(now);
|
|
|
+ if (isNewLead) {
|
|
|
leadService.save(byTraceId);
|
|
|
} else {
|
|
|
leadService.updateById(byTraceId);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- // 查询模板数据
|
|
|
- LandingPageTemplate landingPageTemplate = landingPageTemplateService.getById(byId.getLaunchPageId());
|
|
|
- // 更新动态页面二维码数据
|
|
|
- JSONObject jsonObject = JSONUtil.parseObj(landingPageTemplate.getTemplateData());
|
|
|
- JSONArray jsonArray = jsonObject.getJSONArray("configList");
|
|
|
- jsonArray.stream().iterator().forEachRemaining(item -> {
|
|
|
- JSONObject itemObj = (JSONObject) item;
|
|
|
- JSONArray moduleList = itemObj.getJSONArray("moduleList");
|
|
|
- moduleList.stream().iterator().forEachRemaining(module -> {
|
|
|
- JSONObject moduleObj = (JSONObject) module;
|
|
|
- String type = moduleObj.getStr("type");
|
|
|
- // 判断是否有二维码控件
|
|
|
- if ("h5-qrcode".equals(type)) {
|
|
|
- // 按照配置规则获取二维码链接
|
|
|
- String qrCode = redisUtil.get(QR_CODE_KEY + traceId).toString();
|
|
|
- if (qrCode == null) {
|
|
|
- qrCode = getQrCodeByAllocationRuleId(byId.getLaunchType(), byId.getAllocationRuleId());
|
|
|
- }
|
|
|
- // 设置二维码
|
|
|
- moduleObj.set("workUrl", qrCode);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
// 封装返回结果
|
|
|
LandingIndexRes res = new LandingIndexRes();
|
|
|
- res.setTemplateData(JSONUtil.toJsonStr(jsonObject));
|
|
|
+ redisUtil.set(TEMPLATE_DATA + traceId, templateData, 24, TimeUnit.HOURS);
|
|
|
+ res.setTemplateData(templateData);
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- private String getQrCodeByAllocationRuleId(Integer launchType, Long allocationRuleId) {
|
|
|
+ /**
|
|
|
+ * 更新模板中的二维码信息
|
|
|
+ */
|
|
|
+ private void updateQrCodeInTemplate(JSONObject templateData, String traceId, Site site, Lead lead) {
|
|
|
+ JSONArray configList = templateData.getJSONArray("configList");
|
|
|
+ if (configList == null || configList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ AtomicReference<String> qrCode = new AtomicReference<>("");
|
|
|
+ configList.stream()
|
|
|
+ .map(config -> (JSONObject) config)
|
|
|
+ .map(config -> config.getJSONArray("moduleList"))
|
|
|
+ .filter(ObjectUtil::isNotEmpty)
|
|
|
+ .flatMap(Collection::stream)
|
|
|
+ .map(module -> (JSONObject) module)
|
|
|
+ .filter(module -> "h5-qrcode".equals(module.getStr("type")))
|
|
|
+ .forEach(module -> {
|
|
|
+ if (StrUtil.isEmpty(qrCode.get())) {
|
|
|
+ qrCode.set(getQrCodeByAllocationRuleId(site.getLaunchType(), site.getAllocationRule(), site.getAllocationRuleId(), lead));
|
|
|
+ }
|
|
|
+ module.set("workUrl", qrCode.get());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getQrCodeByAllocationRuleId(Integer launchType,
|
|
|
+ Integer allocationRule,
|
|
|
+ Long allocationRuleId,
|
|
|
+ Lead byTraceId) {
|
|
|
// 二维码
|
|
|
String qrCode = "";
|
|
|
- if (allocationRuleId == 1) {
|
|
|
+ if (allocationRule == 1) {
|
|
|
// 个人分配规则
|
|
|
QwAssignRule byId1 = assignRuleService.getById(allocationRuleId);
|
|
|
QwAssignRuleUser qwAssignRuleUser = assignRuleUserService.getUserByAllocationRuleId(allocationRuleId, byId1.getAssignType());
|
|
|
+ byTraceId.setQwAssignRuleUserId(qwAssignRuleUser.getId());
|
|
|
if (byId1.getAssignType().equals(3)) {
|
|
|
List<String> users = Collections.singletonList(qwAssignRuleUser.getQwUserId());
|
|
|
QwAddContactWayParam qwAddContactWayParam = new QwAddContactWayParam();
|
|
|
@@ -190,18 +228,21 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
QwAddContactWayResult qwAddContactWayResult = qwApiService.addContactWay(qwAddContactWayParam, qwAssignRuleUser.getCorpId());
|
|
|
qrCode = qwAddContactWayResult.getQr_code();
|
|
|
}
|
|
|
- } else if (allocationRuleId == 2) {
|
|
|
+ } else if (allocationRule == 2) {
|
|
|
// 活码分配规则
|
|
|
if (launchType.equals(1)) {
|
|
|
// 线上规则--群活码
|
|
|
QwGroupActual qwGroupActual = actualService.getGroupActualByAllocationRuleId(allocationRuleId);
|
|
|
+ byTraceId.setQwGroupActualId(qwGroupActual.getId());
|
|
|
qrCode = qwGroupActual.getGroupUrl();
|
|
|
} else if (launchType.equals(2)) {
|
|
|
// 线下规则--个人活码
|
|
|
QwContactWay qwContactWay = contactWayService.selectQwContactWayById(allocationRuleId);
|
|
|
+ byTraceId.setQwContactWayId(qwContactWay.getId());
|
|
|
qrCode = qwContactWay.getQrCode();
|
|
|
}
|
|
|
}
|
|
|
+ log.info("落地页广告获取二维码: {}", qrCode);
|
|
|
return qrCode;
|
|
|
}
|
|
|
|
|
|
@@ -222,4 +263,14 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
byId.setRefreshToken(accessToken.get("refresh_token"));
|
|
|
}*/
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LandingIndexRes getWxLandingIndexBySiteId(WeChatLandingIndexReq req) {
|
|
|
+ // 更新授权页访问信息记录
|
|
|
+ leadService.updateAuthIndex(req.getTraceId(),req.getType());
|
|
|
+ String templateData = String.valueOf(redisUtil.get(TEMPLATE_DATA + req.getTraceId()));
|
|
|
+ LandingIndexRes landingIndexRes = new LandingIndexRes();
|
|
|
+ landingIndexRes.setTemplateData(templateData);
|
|
|
+ return landingIndexRes;
|
|
|
+ }
|
|
|
}
|