|
@@ -53,6 +53,14 @@ public class ConversionSyncService {
|
|
|
private static final Logger log = LoggerFactory.getLogger(ConversionSyncService.class);
|
|
private static final Logger log = LoggerFactory.getLogger(ConversionSyncService.class);
|
|
|
private static final int REALTIME_CONCURRENCY = 10;
|
|
private static final int REALTIME_CONCURRENCY = 10;
|
|
|
private static final int BACKFILL_CONCURRENCY = 16;
|
|
private static final int BACKFILL_CONCURRENCY = 16;
|
|
|
|
|
+ private static final int KS_EVENT_ACTIVATION = 1;
|
|
|
|
|
+ private static final int KS_EVENT_REGISTRATION = 2;
|
|
|
|
|
+ private static final int KS_EVENT_PURCHASE = 3;
|
|
|
|
|
+ private static final int KS_EVENT_NEXT_DAY_RETENTION = 7;
|
|
|
|
|
+ private static final int KS_EVENT_SEVEN_DAY_RETENTION = 8;
|
|
|
|
|
+ private static final int KS_EVENT_APP_WAKEUP = 84;
|
|
|
|
|
+ private static final int KS_EVENT_KEY_ACTION = 143;
|
|
|
|
|
+ private static final int KS_EVENT_THREE_DAY_RETENTION = 103;
|
|
|
|
|
|
|
|
private final ConversionClient baiduClient;
|
|
private final ConversionClient baiduClient;
|
|
|
private final RedisHotStore hotStore;
|
|
private final RedisHotStore hotStore;
|
|
@@ -322,9 +330,9 @@ public class ConversionSyncService {
|
|
|
log.info("[ConversionSync] 匹配到快手转化 | qk={} | act={} | deviceId={} | date={} | payment={}",
|
|
log.info("[ConversionSync] 匹配到快手转化 | qk={} | act={} | deviceId={} | date={} | payment={}",
|
|
|
payment.getQk(), payment.getAct(), payment.getDeviceId(), payment.getDate(), payment.getPayment());
|
|
payment.getQk(), payment.getAct(), payment.getDeviceId(), payment.getDate(), payment.getPayment());
|
|
|
|
|
|
|
|
- CallbackTask kuaishouTask = buildKuaishouCallbackTask(payment, kuaishouBid);
|
|
|
|
|
- if (kuaishouTask != null) {
|
|
|
|
|
- callbackTasks.add(kuaishouTask);
|
|
|
|
|
|
|
+ List<CallbackTask> kuaishouTasks = buildKuaishouCallbackTasks(payment, kuaishouBid);
|
|
|
|
|
+ if (!kuaishouTasks.isEmpty()) {
|
|
|
|
|
+ callbackTasks.addAll(kuaishouTasks);
|
|
|
}
|
|
}
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -394,24 +402,28 @@ public class ConversionSyncService {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private CallbackTask buildKuaishouCallbackTask(PaymentInfo payment, KuaishouBidRecord bid) {
|
|
|
|
|
|
|
+ private List<CallbackTask> buildKuaishouCallbackTasks(PaymentInfo payment, KuaishouBidRecord bid) {
|
|
|
if (kuaishouColdStore == null && kuaishouTagEventResolver == null) {
|
|
if (kuaishouColdStore == null && kuaishouTagEventResolver == null) {
|
|
|
- return null;
|
|
|
|
|
|
|
+ return List.of();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- KuaishouTagEventRecord tagEvent = resolveKuaishouTagEvent(bid.getTagId(), payment.getAct());
|
|
|
|
|
- if (tagEvent == null) {
|
|
|
|
|
- log.warn("[ConversionSync] 快手 eventType 未配置 | qk={} | tagId={} | act={}",
|
|
|
|
|
|
|
+ List<KuaishouTagEventRecord> tagEvents = resolveKuaishouTagEvents(bid.getTagId(), payment.getAct());
|
|
|
|
|
+ if (tagEvents.isEmpty()) {
|
|
|
|
|
+ log.warn("[ConversionSync] 快手 eventType 未配置且无兜底映射 | qk={} | tagId={} | act={}",
|
|
|
payment.getQk(), bid.getTagId(), payment.getAct());
|
|
payment.getQk(), bid.getTagId(), payment.getAct());
|
|
|
- return null;
|
|
|
|
|
|
|
+ return List.of();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return CallbackTask.kuaishou(
|
|
|
|
|
- payment,
|
|
|
|
|
- bid,
|
|
|
|
|
- kuaishouCallbackDedupeKey(payment, bid, tagEvent.getEventType()),
|
|
|
|
|
- tagEvent
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ List<CallbackTask> tasks = new ArrayList<>(tagEvents.size());
|
|
|
|
|
+ for (KuaishouTagEventRecord tagEvent : tagEvents) {
|
|
|
|
|
+ tasks.add(CallbackTask.kuaishou(
|
|
|
|
|
+ payment,
|
|
|
|
|
+ bid,
|
|
|
|
|
+ kuaishouCallbackDedupeKey(payment, bid, tagEvent.getEventType()),
|
|
|
|
|
+ tagEvent
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+ return tasks;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private Integer resolveHonorConversionIdFromDb(String tagId, int baiduAct) {
|
|
private Integer resolveHonorConversionIdFromDb(String tagId, int baiduAct) {
|
|
@@ -426,23 +438,82 @@ public class ConversionSyncService {
|
|
|
return fallback != null ? fallback.getConversionId() : null;
|
|
return fallback != null ? fallback.getConversionId() : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private KuaishouTagEventRecord resolveKuaishouTagEvent(String tagId, int baiduAct) {
|
|
|
|
|
- if (tagId == null || tagId.isBlank() || kuaishouColdStore == null) {
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ private List<KuaishouTagEventRecord> resolveKuaishouTagEvents(String tagId, int baiduAct) {
|
|
|
|
|
+ List<KuaishouTagEventRecord> configured = resolveConfiguredKuaishouTagEvents(tagId, baiduAct);
|
|
|
|
|
+ if (!configured.isEmpty()) {
|
|
|
|
|
+ return configured;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<KuaishouTagEventRecord> fallback = buildKuaishouFallbackTagEvents(tagId, baiduAct);
|
|
|
|
|
+ if (!fallback.isEmpty()) {
|
|
|
|
|
+ log.warn("[ConversionSync] 快手 eventType 未配置, 启用兜底映射 | tagId={} | act={} | fallbackEventTypes={}",
|
|
|
|
|
+ tagId, baiduAct, fallback.stream().map(KuaishouTagEventRecord::getEventType).toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ return fallback;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<KuaishouTagEventRecord> resolveConfiguredKuaishouTagEvents(String tagId, int baiduAct) {
|
|
|
|
|
+ if (tagId == null || tagId.isBlank()) {
|
|
|
|
|
+ return List.of();
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- KuaishouTagEventRecord record = kuaishouColdStore.getTagEvent(tagId, baiduAct);
|
|
|
|
|
- if (record == null) {
|
|
|
|
|
- record = kuaishouColdStore.getTagEvent(tagId, 0);
|
|
|
|
|
|
|
+ if (kuaishouTagEventResolver != null) {
|
|
|
|
|
+ List<Integer> eventTypes = kuaishouTagEventResolver.resolveEventTypes(tagId, baiduAct);
|
|
|
|
|
+ if (eventTypes != null && !eventTypes.isEmpty()) {
|
|
|
|
|
+ List<KuaishouTagEventRecord> records = new ArrayList<>(eventTypes.size());
|
|
|
|
|
+ for (Integer eventType : eventTypes) {
|
|
|
|
|
+ records.add(buildKuaishouTagEvent(tagId, baiduAct, eventType));
|
|
|
|
|
+ }
|
|
|
|
|
+ return records;
|
|
|
|
|
+ }
|
|
|
|
|
+ return List.of();
|
|
|
}
|
|
}
|
|
|
- return record;
|
|
|
|
|
|
|
+ if (kuaishouColdStore == null) {
|
|
|
|
|
+ return List.of();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<KuaishouTagEventRecord> records = kuaishouColdStore.getTagEvents(tagId, baiduAct);
|
|
|
|
|
+ if (records == null || records.isEmpty()) {
|
|
|
|
|
+ records = kuaishouColdStore.getTagEvents(tagId, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ return records == null ? List.of() : records;
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.warn("[ConversionSync] 查询快手 tag event 失败 | tagId={} | act={} | error={}",
|
|
log.warn("[ConversionSync] 查询快手 tag event 失败 | tagId={} | act={} | error={}",
|
|
|
tagId, baiduAct, e.getMessage(), e);
|
|
tagId, baiduAct, e.getMessage(), e);
|
|
|
- return null;
|
|
|
|
|
|
|
+ return List.of();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static KuaishouTagEventRecord buildKuaishouTagEvent(String tagId, int baiduAct, int eventType) {
|
|
|
|
|
+ KuaishouTagEventRecord record = new KuaishouTagEventRecord();
|
|
|
|
|
+ record.setTagId(tagId);
|
|
|
|
|
+ record.setBaiduAct(baiduAct);
|
|
|
|
|
+ record.setEventType(eventType);
|
|
|
|
|
+ return record;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static List<KuaishouTagEventRecord> buildKuaishouFallbackTagEvents(String tagId, int baiduAct) {
|
|
|
|
|
+ List<Integer> eventTypes = switch (baiduAct) {
|
|
|
|
|
+ case 1 -> List.of(KS_EVENT_ACTIVATION);
|
|
|
|
|
+ case 2, 5 -> List.of(KS_EVENT_PURCHASE);
|
|
|
|
|
+ case 3 -> List.of(KS_EVENT_REGISTRATION, KS_EVENT_ACTIVATION);
|
|
|
|
|
+ case 4 -> List.of(KS_EVENT_NEXT_DAY_RETENTION);
|
|
|
|
|
+ case 6 -> List.of(KS_EVENT_APP_WAKEUP);
|
|
|
|
|
+ case 7 -> List.of(KS_EVENT_KEY_ACTION);
|
|
|
|
|
+ case 8 -> List.of(KS_EVENT_SEVEN_DAY_RETENTION);
|
|
|
|
|
+ case 9 -> List.of(KS_EVENT_THREE_DAY_RETENTION);
|
|
|
|
|
+ case 2001 -> List.of(KS_EVENT_APP_WAKEUP);
|
|
|
|
|
+ default -> List.of();
|
|
|
|
|
+ };
|
|
|
|
|
+ if (eventTypes.isEmpty()) {
|
|
|
|
|
+ return List.of();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<KuaishouTagEventRecord> records = new ArrayList<>(eventTypes.size());
|
|
|
|
|
+ for (Integer eventType : eventTypes) {
|
|
|
|
|
+ records.add(buildKuaishouTagEvent(tagId, baiduAct, eventType));
|
|
|
|
|
+ }
|
|
|
|
|
+ return records;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ─── Step 3: 统一落百度转化明细 ───────────────────────────────────────────
|
|
// ─── Step 3: 统一落百度转化明细 ───────────────────────────────────────────
|
|
|
|
|
|
|
|
private void saveConversions(List<ConversionRecord> records) {
|
|
private void saveConversions(List<ConversionRecord> records) {
|