|
|
@@ -5,42 +5,34 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.fs.app.enums.AdvertiserTypeEnum;
|
|
|
import com.fs.app.enums.ConversionTypeEnum;
|
|
|
import com.fs.app.event.ConversionEventPublisher;
|
|
|
-import com.fs.app.integration.client.BaiduApiClient;
|
|
|
+import com.fs.app.integration.client.IAccessTokenClient;
|
|
|
+import com.fs.app.integration.client.IApiClient;
|
|
|
import com.fs.app.integration.factory.AdvertiserHandlerFactory;
|
|
|
import com.fs.app.mq.message.ClickMessage;
|
|
|
import com.fs.common.exception.base.BusinessException;
|
|
|
-import com.fs.newAdv.domain.ClickTrace;
|
|
|
-import com.fs.newAdv.domain.LandingPageTemplate;
|
|
|
-import com.fs.newAdv.domain.Lead;
|
|
|
-import com.fs.newAdv.domain.Site;
|
|
|
+import com.fs.newAdv.domain.*;
|
|
|
import com.fs.newAdv.dto.req.LeadSubmitRequest;
|
|
|
import com.fs.newAdv.dto.res.LandingIndexRes;
|
|
|
-import com.fs.newAdv.service.IClickTraceService;
|
|
|
-import com.fs.newAdv.service.ILandingPageTemplateService;
|
|
|
-import com.fs.newAdv.service.ILeadService;
|
|
|
-import com.fs.newAdv.service.ISiteService;
|
|
|
+import com.fs.newAdv.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFacadeService {
|
|
|
- @Autowired
|
|
|
- private IClickTraceService clickTraceService;
|
|
|
-
|
|
|
|
|
|
@Autowired
|
|
|
private AdvertiserHandlerFactory handlerFactory;
|
|
|
|
|
|
@Autowired
|
|
|
private ILeadService leadService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
private ISiteService siteService;
|
|
|
|
|
|
@Autowired
|
|
|
@@ -50,6 +42,8 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
private IClickTraceService iClickTraceService;
|
|
|
@Autowired
|
|
|
private ILandingPageTemplateService landingPageTemplateService;
|
|
|
+ @Autowired
|
|
|
+ private IPromotionAccountService promotionAccountService;
|
|
|
|
|
|
@Override
|
|
|
public void saveClickTrace(AdvertiserTypeEnum trackType, Map<String, String> allParams) {
|
|
|
@@ -75,20 +69,27 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
* @param allParams
|
|
|
* @return traceId 线索id
|
|
|
*/
|
|
|
- private Map<String, String> getTraceIdByPlatformParams(Map<String, String> allParams) {
|
|
|
+ private Map<String, String> getTraceIdByPlatformParams(Long advertiserId, Map<String, String> allParams) {
|
|
|
Map<String, String> traceId = new HashMap<>();
|
|
|
- if (StrUtil.isNotEmpty(allParams.get("bd_vid"))) {
|
|
|
+ if (Objects.equals(AdvertiserTypeEnum.getByCode(advertiserId), AdvertiserTypeEnum.BAIDU) && StrUtil.isNotEmpty(allParams.get("bd_vid"))) {
|
|
|
+ traceId.put("traceId", allParams.get("bd_vid"));
|
|
|
+ } else if (Objects.equals(AdvertiserTypeEnum.getByCode(advertiserId), AdvertiserTypeEnum.OCEANENGINE) && StrUtil.isNotEmpty(allParams.get("bd_vid"))) {
|
|
|
+ traceId.put("traceId", allParams.get("bd_vid"));
|
|
|
+ }else if (Objects.equals(AdvertiserTypeEnum.getByCode(advertiserId), AdvertiserTypeEnum.GDT) && StrUtil.isNotEmpty(allParams.get("bd_vid"))) {
|
|
|
+ traceId.put("traceId", allParams.get("bd_vid"));
|
|
|
+ }else if (Objects.equals(AdvertiserTypeEnum.getByCode(advertiserId), AdvertiserTypeEnum.OPPO) && StrUtil.isNotEmpty(allParams.get("pageId"))) {
|
|
|
+ traceId.put("traceId", allParams.get("pageId"));
|
|
|
+ }else if (Objects.equals(AdvertiserTypeEnum.getByCode(advertiserId), AdvertiserTypeEnum.VIVO) && StrUtil.isNotEmpty(allParams.get("bd_vid"))) {
|
|
|
+ traceId.put("traceId", allParams.get("bd_vid"));
|
|
|
+ }else if (Objects.equals(AdvertiserTypeEnum.getByCode(advertiserId), AdvertiserTypeEnum.iQIYI) && StrUtil.isNotEmpty(allParams.get("bd_vid"))) {
|
|
|
traceId.put("traceId", allParams.get("bd_vid"));
|
|
|
- return traceId;
|
|
|
- } else {
|
|
|
- throw new BusinessException("回传参数错误 缺少traceId");
|
|
|
}
|
|
|
-
|
|
|
+ return traceId;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateClickTrace(ClickMessage clickMessage) {
|
|
|
- Map<String, String> params = getTraceIdByPlatformParams(clickMessage.getAllParams());
|
|
|
+ Map<String, String> params = getTraceIdByPlatformParams(null,clickMessage.getAllParams());
|
|
|
Site site = siteService.getById(clickMessage.getSiteId());
|
|
|
ClickTrace byTraceId = iClickTraceService.getByTraceId(params.get("traceId"));
|
|
|
byTraceId.setSiteId(site.getId());
|
|
|
@@ -112,7 +113,7 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
trace.setCampaignId(allParams.get("pid"));
|
|
|
trace.setIp(allParams.get("ip"));
|
|
|
break;
|
|
|
- case SINA:
|
|
|
+ case OCEANENGINE:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
@@ -120,12 +121,15 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
|
|
|
@Override
|
|
|
public void submitForm(LeadSubmitRequest request) {
|
|
|
- Map<String, String> params = getTraceIdByPlatformParams(request.getRawParams());
|
|
|
+ Site byId = siteService.getById(request.getSiteId());
|
|
|
+ if (byId == null) {
|
|
|
+ throw new BusinessException("站点不存在");
|
|
|
+ }
|
|
|
+ Map<String, String> params = getTraceIdByPlatformParams(byId.getAdvertiserId(), request.getRawParams());
|
|
|
String traceId = params.get("traceId");
|
|
|
if (StrUtil.isEmpty(traceId)) {
|
|
|
throw new BusinessException("缺少traceId");
|
|
|
}
|
|
|
- Site byId = siteService.getById(request.getSiteId());
|
|
|
// 2. 构建Lead对象
|
|
|
Lead lead = new Lead();
|
|
|
lead.setSiteId(request.getSiteId());
|
|
|
@@ -158,6 +162,25 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void gdtGetAuthCode(Integer code, Long state) {
|
|
|
+ if (code == null || state == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ PromotionAccount byId = promotionAccountService.getById(state);
|
|
|
+ if (byId == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ IApiClient apiClient = handlerFactory.getApiClient(AdvertiserTypeEnum.GDT);
|
|
|
+ if (apiClient instanceof IAccessTokenClient) {
|
|
|
+ IAccessTokenClient tokenClient = (IAccessTokenClient) apiClient;
|
|
|
+ Map<String, String> accessToken = tokenClient.getAccessToken(code, byId.getAppId(), byId.getAppSecret(), byId.getCallbackUrl());
|
|
|
+ byId.setAccessToken(accessToken.get("access_token"));
|
|
|
+ byId.setRefreshToken(accessToken.get("refresh_token"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public void saveLeadAndTriggerConversion(Lead lead) {
|
|
|
// 1. 保存线索到数据库
|
|
|
boolean saved = leadService.save(lead);
|
|
|
@@ -177,17 +200,4 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 转换为String Map
|
|
|
- */
|
|
|
- private Map<String, String> convertToStringMap(Map<String, Object> map) {
|
|
|
- Map<String, String> result = new HashMap<>();
|
|
|
- map.forEach((key, value) -> {
|
|
|
- if (value != null) {
|
|
|
- result.put(key, value.toString());
|
|
|
- }
|
|
|
- });
|
|
|
- return result;
|
|
|
- }
|
|
|
}
|