zhangqin 4 недель назад
Родитель
Сommit
d1a8f0dbc5

+ 3 - 3
fs-ad-new-api/src/main/java/com/fs/app/event/ConversionEvent.java

@@ -24,7 +24,7 @@ public class ConversionEvent extends ApplicationEvent {
     /**
      * 点击ID(广告平台提供)
      */
-    private final String clickId;
+    private final String traceId;
 
     /**
      * 广告商名称(BAIDU, OCEANENGINE, SINA, GDT)
@@ -46,11 +46,11 @@ public class ConversionEvent extends ApplicationEvent {
      */
     private final Long leadId;
 
-    public ConversionEvent(Object source, Long siteId, String clickId,
+    public ConversionEvent(Object source, Long siteId, String traceId,
                            String advertiser, ConversionTypeEnum eventType, Double value, Long leadId) {
         super(source);
         this.siteId = siteId;
-        this.clickId = clickId;
+        this.traceId = traceId;
         this.advertiser = advertiser;
         this.eventType = eventType;
         this.value = value;

+ 5 - 3
fs-ad-new-api/src/main/java/com/fs/app/event/ConversionEventListener.java

@@ -34,19 +34,21 @@ public class ConversionEventListener {
     @EventListener
     public void handleConversionEvent(ConversionEvent event) {
         Long siteId = event.getSiteId();
-        String clickId = event.getClickId();
+        String traceId = event.getTraceId();
         String advertiser = event.getAdvertiser();
         ConversionTypeEnum eventType = event.getEventType();
         Double value = event.getValue();
         Long leadId = event.getLeadId();
-        log.info("接收到转化事件 | siteId={}, clickId={}, advertiser={}, eventType={}",
-                siteId, clickId, advertiser, eventType);
+        log.info("接收到转化事件 | siteId={}, traceId={}, advertiser={}, eventType={}",
+                siteId, traceId, advertiser, eventType);
         // 1. 校验参数
         // 2. 构建MQ消息
         ConversionMessage message = new ConversionMessage();
         message.setSiteId(siteId);
         message.setAdvertiser(advertiser);
         message.setEventType(eventType);
+        message.setLeadId(leadId);
+        message.setTraceId(traceId);
         // 3. 发送到MQ
         messageProducer.sendConversionMessage(message);
     }

+ 1 - 1
fs-ad-new-api/src/main/java/com/fs/app/facade/CallbackProcessingFacadeServiceImpl.java

@@ -103,7 +103,7 @@ public class CallbackProcessingFacadeServiceImpl implements CallbackProcessingFa
             traceId.put("source", AdvertiserTypeEnum.BAIDU.getName());
             return traceId;
         } else {
-            throw new BusinessException("回传参数错误");
+            throw new BusinessException("回传参数错误 缺少traceId");
         }
 
     }

+ 7 - 6
fs-ad-new-api/src/main/java/com/fs/app/facade/ConversionServiceImpl.java

@@ -10,14 +10,12 @@ import com.fs.common.constant.RedisKeyConstant;
 import com.fs.common.exception.base.BusinessException;
 import com.fs.common.utils.RedisUtil;
 import com.fs.common.utils.SnowflakeUtil;
-import com.fs.newAdv.domain.CallbackAccount;
-import com.fs.newAdv.domain.ConversionLog;
-import com.fs.newAdv.domain.PromotionAccount;
-import com.fs.newAdv.domain.Site;
+import com.fs.newAdv.domain.*;
 import com.fs.newAdv.mapper.ConversionLogMapper;
 import com.fs.newAdv.mapper.ConversionTargetMapper;
 import com.fs.newAdv.service.ICallbackAccountService;
 import com.fs.newAdv.service.IClickTraceService;
+import com.fs.newAdv.service.ILeadService;
 import com.fs.newAdv.service.ISiteService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -61,6 +59,8 @@ public class ConversionServiceImpl implements IConversionService {
 
     @Autowired
     private IClickTraceService clickTraceService;
+    @Autowired
+    private ILeadService leadService;
 
     @Override
     @Async("asyncExecutor")
@@ -113,7 +113,7 @@ public class ConversionServiceImpl implements IConversionService {
 
     @Override
     @Async("asyncExecutor")
-    public boolean reportToBaidu(Long siteId, ConversionTypeEnum eventType, String traceId, Double value) {
+    public Boolean reportToBaidu(Long siteId, ConversionTypeEnum eventType, String traceId, Long leadId,Double value) {
         log.info("开始回传转化数据到百度:站点ID={},点击ID={},事件类型={}",
                 siteId, traceId, eventType);
         // 询站点信息
@@ -134,10 +134,11 @@ public class ConversionServiceImpl implements IConversionService {
         String accessToken = callbackAccount.getOcpcToken();
 
 
+        Lead lead = leadService.getById(leadId);
         // 构建回传参数
         Map<String, Object> conversionData = new HashMap<>();
         conversionData.put("token", accessToken);
-        conversionData.put("traceId", traceId); // 百度使用logId
+        conversionData.put("logidUrl", lead.getViewUrl());
         conversionData.put("newType", eventType.getAdvertiserType(AdvertiserTypeEnum.BAIDU));
         conversionData.put("conversionTime", System.currentTimeMillis() / 1000);
 

+ 1 - 1
fs-ad-new-api/src/main/java/com/fs/app/facade/IConversionService.java

@@ -31,6 +31,6 @@ public interface IConversionService {
      * @param value 转化价值
      * @return 是否成功
      */
-    boolean reportToBaidu(Long siteId, ConversionTypeEnum eventType, String traceId, Double value);
+    Boolean reportToBaidu(Long siteId, ConversionTypeEnum eventType, String traceId, Long leadId,Double value);
 }
 

+ 2 - 6
fs-ad-new-api/src/main/java/com/fs/app/integration/client/BaiduApiClient.java

@@ -113,16 +113,12 @@ public class BaiduApiClient implements IApiClient{
         // 点击ID(必填)
         String logidUrl = (String) conversionData.get("logidUrl");
         if (StrUtil.isBlank(logidUrl)) {
-            throw new ThirdPartyException("落地页");
+            throw new ThirdPartyException("落地页不能为空");
         }
         conversion.put("logidUrl", logidUrl);
 
         // 转化类型(必填)
-        Integer conversionType = (Integer) conversionData.get("newType");
-        if (conversionType == null) {
-            conversionType = 1; // 默认为1(激活)
-        }
-        conversion.put("newType", conversionType);
+        conversion.put("newType", conversionData.get("newType"));
 
         // 转化时间(毫秒时间戳)
         Long conversionTime = (Long) conversionData.get("conversionTime");

+ 18 - 25
fs-ad-new-api/src/main/java/com/fs/app/mq/consumer/ConversionMessageConsumer.java

@@ -58,31 +58,23 @@ public class ConversionMessageConsumer implements RocketMQListener<ConversionMes
         log.info("消费者接收到转化消息 | traceId={}, advertiser={}, eventType={}",
                 traceId, advertiser, eventType.getDesc());
 
-        try {
-            // 1. 幂等性校验(防止重复消费)
-            if (!checkIdempotent(messageId)) {
-                log.warn("消息已处理,跳过 | messageId={}", messageId);
-                return;
-            }
-
-            // 2. 调用广告平台API回传
-            boolean success = callAdvertiserApi(message);
-
-            if (success) {
-                // 3. 标记为已处理
-                markAsProcessed(messageId);
-
-                log.info("转化回传成功 | traceId={}, eventType={}", traceId, eventType);
-            } else {
-                // 抛出异常触发RocketMQ重试
-                throw new RuntimeException("回传失败,触发重试");
-            }
-
-        } catch (Exception e) {
-            log.error("处理转化消息失败 | traceId={}, eventType={}, error={}",
-                    traceId, eventType, e.getMessage(), e);
-            // 抛出异常,RocketMQ会自动重试
-            throw new RuntimeException("处理转化消息失败: " + e.getMessage(), e);
+        // 1. 幂等性校验(防止重复消费)
+        if (!checkIdempotent(messageId)) {
+            log.warn("消息已处理,跳过 | messageId={}", messageId);
+            return;
+        }
+
+        // 2. 调用广告平台API回传
+        boolean success = callAdvertiserApi(message);
+
+        if (success) {
+            // 3. 标记为已处理
+            markAsProcessed(messageId);
+
+            log.info("转化回传成功 | traceId={}, eventType={}", traceId, eventType);
+        } else {
+            // 抛出异常触发RocketMQ重试
+            throw new RuntimeException("回传失败,触发重试");
         }
     }
 
@@ -128,6 +120,7 @@ public class ConversionMessageConsumer implements RocketMQListener<ConversionMes
                         message.getSiteId(),
                         message.getEventType(),
                         message.getTraceId(),
+                        message.getLeadId(),
                         null
                 );
 

+ 3 - 0
fs-ad-new-api/src/main/java/com/fs/app/mq/message/ConversionMessage.java

@@ -36,6 +36,9 @@ public class ConversionMessage extends MqMessageDto implements Serializable {
      */
     private ConversionTypeEnum eventType;
 
+
+    private Long leadId;
+
    /* *//**
      * 转化价值(可选)
      *//*

+ 3 - 2
fs-ad-new-api/src/main/resources/static/landing.html

@@ -271,7 +271,7 @@
                           urlParams.get('advertiser');
 
             // 2.4 提取其他常用参数
-            const siteId = urlParams.get('site_id') || urlParams.get('siteid');
+            const siteId = urlParams.get('site_id') || urlParams.get('siteId');
             const campaignId = urlParams.get('campaign_id') || urlParams.get('cid');
             const keyword = urlParams.get('keyword') || urlParams.get('kw');
             const creativeId = urlParams.get('creative_id') || urlParams.get('creative');
@@ -280,6 +280,7 @@
             const submitData = {
                 ...formData,
                 siteId: siteId ? parseInt(siteId) : null,
+                viewUrl: window.location.href, // 添加完整的URL
                 clickId: clickId,
                 source: source ? source.toUpperCase() : null,
                 campaignId: campaignId,
@@ -290,7 +291,7 @@
 
             try {
                 // 4. 提交到线索接口(会自动触发转化事件)
-                const response = await fetch(`${API_BASE}/leads/submit`, {
+                const response = await fetch(`${API_BASE}/landing/submit`, {
                     method: 'POST',
                     headers: {
                         'Content-Type': 'application/json'

+ 1 - 1
fs-service/src/main/java/com/fs/newAdv/domain/CallbackAccount.java

@@ -28,7 +28,7 @@ public class CallbackAccount implements Serializable {
     /**
      * 回传账号名称
      */
-    private String callbackAccountName;
+    private String accountName;
     /**
      * ocpcId 回传账号id
      */

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

@@ -11,5 +11,6 @@ import com.fs.newAdv.domain.Lead;
  */
 public interface ILeadService extends IService<Lead> {
 
+    Lead getByTraceId(String traceId);
 }
 

+ 3 - 3
fs-service/src/main/java/com/fs/newAdv/service/impl/CallbackAccountServiceImpl.java

@@ -31,7 +31,7 @@ public class CallbackAccountServiceImpl implements ICallbackAccountService {
     @Override
     public IPage<CallbackAccount> page(Page<CallbackAccount> page, String accountName) {
         LambdaQueryWrapper<CallbackAccount> wrapper = new LambdaQueryWrapper<>();
-        wrapper.like(StrUtil.isNotBlank(accountName), CallbackAccount::getCallbackAccountName, accountName);
+        wrapper.like(StrUtil.isNotBlank(accountName), CallbackAccount::getAccountName, accountName);
         wrapper.orderByDesc(CallbackAccount::getCreateTime);
 
         return callbackAccountMapper.selectPage(page, wrapper);
@@ -51,7 +51,7 @@ public class CallbackAccountServiceImpl implements ICallbackAccountService {
     public boolean create(CallbackAccount callbackAccount) {
         // 校验账号名称是否重复
         LambdaQueryWrapper<CallbackAccount> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(CallbackAccount::getCallbackAccountName, callbackAccount.getCallbackAccountName());
+        wrapper.eq(CallbackAccount::getAccountName, callbackAccount.getAccountName());
         Integer count = callbackAccountMapper.selectCount(wrapper);
         if (count > 0) {
             throw new BusinessException("回传账号名称已存在");
@@ -70,7 +70,7 @@ public class CallbackAccountServiceImpl implements ICallbackAccountService {
 
         // 校验名称是否重复
         LambdaQueryWrapper<CallbackAccount> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(CallbackAccount::getCallbackAccountName, callbackAccount.getCallbackAccountName());
+        wrapper.eq(CallbackAccount::getAccountName, callbackAccount.getAccountName());
         wrapper.ne(CallbackAccount::getId, callbackAccount.getId());
         Integer count = callbackAccountMapper.selectCount(wrapper);
         if (count > 0) {

+ 5 - 0
fs-service/src/main/java/com/fs/newAdv/service/impl/LeadServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.newAdv.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.newAdv.domain.Lead;
 import com.fs.newAdv.mapper.LeadMapper;
@@ -17,5 +18,9 @@ import org.springframework.stereotype.Service;
 @Service
 public class LeadServiceImpl extends ServiceImpl<LeadMapper, Lead> implements ILeadService {
 
+    @Override
+    public Lead getByTraceId(String traceId) {
+        return this.getOne(new LambdaQueryWrapper<Lead>().eq(Lead::getTraceId, traceId));
+    }
 }