|
|
@@ -5,6 +5,7 @@ import com.adx.tencent.baidu.model.NormalizedBidResponse;
|
|
|
import com.adx.tencent.baidu.model.TrackingResult;
|
|
|
import com.adx.tencent.honor.model.HonorBidRecord;
|
|
|
import com.adx.tencent.honor.model.HonorTrackingRecord;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -38,13 +39,16 @@ public class HonorTrackingController {
|
|
|
private final AdxClient adxClient;
|
|
|
private final HonorHotStore hotStore;
|
|
|
private final HonorPlacement placement;
|
|
|
+ private final ObjectMapper objectMapper;
|
|
|
|
|
|
public HonorTrackingController(AdxClient adxClient,
|
|
|
HonorHotStore hotStore,
|
|
|
- @Nullable HonorPlacement placement) {
|
|
|
+ @Nullable HonorPlacement placement,
|
|
|
+ ObjectMapper objectMapper) {
|
|
|
this.adxClient = adxClient;
|
|
|
this.hotStore = hotStore;
|
|
|
this.placement = placement;
|
|
|
+ this.objectMapper = objectMapper;
|
|
|
}
|
|
|
|
|
|
@GetMapping("/honor/impression")
|
|
|
@@ -76,27 +80,29 @@ public class HonorTrackingController {
|
|
|
log.warn("[荣耀][曝光] 缺少 traceId, params={}", params.keySet());
|
|
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "missing honor trace id (trackId)");
|
|
|
}
|
|
|
- log.info("[荣耀][曝光] 收到曝光请求 | traceId={} | IP={} | 全部入参: {}", traceId, clientIp(request), params);
|
|
|
+ log.info("[荣耀][曝光][入参] traceId={} ip={} params={}", traceId, clientIp(request), params);
|
|
|
+
|
|
|
+ NormalizedBidResponse response = adxClient.requestBid(traceId, buildBidRequest(request, traceId, params));
|
|
|
|
|
|
- NormalizedBidResponse response = adxClient.requestBid(buildBidRequest(request, traceId, params));
|
|
|
if (response == null) {
|
|
|
- log.warn("[荣耀][曝光] 百度ADX返回空响应, traceId={}", traceId);
|
|
|
+ log.warn("[荣耀][曝光][百度结果] traceId={} empty=true", traceId);
|
|
|
throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, "empty baidu ADX response");
|
|
|
}
|
|
|
- log.info("[荣耀][曝光] 百度ADX返回: qk={}, hasBid={}, showUrls={}, clickUrls={}",
|
|
|
+ log.info("[荣耀][曝光][竞价结果] traceId={} qk={} bidId={} success={} price={} clickUrlCount={} showUrlCount={}",
|
|
|
+ traceId,
|
|
|
response.getQk(),
|
|
|
+ response.getBidId(),
|
|
|
response.getBid() != null,
|
|
|
- response.getBid() != null && response.getBid().getShowUrls() != null ? response.getBid().getShowUrls().size() : 0,
|
|
|
- response.getBid() != null && response.getBid().getClickUrls() != null ? response.getBid().getClickUrls().size() : 0);
|
|
|
+ response.getBid() != null ? response.getBid().getPrice() : 0,
|
|
|
+ response.getBid() != null && response.getBid().getClickUrls() != null ? response.getBid().getClickUrls().size() : 0,
|
|
|
+ response.getBid() != null && response.getBid().getShowUrls() != null ? response.getBid().getShowUrls().size() : 0);
|
|
|
|
|
|
HonorBidRecord record = bidRecordFromResponse(response, traceId, "impression", params);
|
|
|
hotStore.recordBid(record);
|
|
|
- log.info("[荣耀][曝光] 已缓存bid, qk={}, traceId={}", record.getQk(), traceId);
|
|
|
|
|
|
List<TrackingResult> tracking = Collections.emptyList();
|
|
|
if (response.getBid() != null && response.getBid().getShowUrls() != null && !response.getBid().getShowUrls().isEmpty()) {
|
|
|
tracking = adxClient.reportImpression(response.getBid().getShowUrls(), response.getBid().getPrice());
|
|
|
- log.info("[荣耀][曝光] 曝光上报完成, qk={}, results={}", record.getQk(), tracking);
|
|
|
recordTracking(record.getQk(), tagId, "impression", tracking);
|
|
|
}
|
|
|
return Map.of("qk", record.getQk(), "traceId", traceId, "tagId", tagId);
|
|
|
@@ -111,43 +117,43 @@ public class HonorTrackingController {
|
|
|
log.warn("[荣耀][点击] 缺少 traceId, params={}", params.keySet());
|
|
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "missing honor trace id (trackId)");
|
|
|
}
|
|
|
- log.info("[荣耀][点击] 收到点击请求 | traceId={} | IP={} | 全部入参: {}", traceId, clientIp(request), params);
|
|
|
+ log.info("[荣耀][点击][入参] traceId={} ip={} params={}", traceId, clientIp(request), params);
|
|
|
|
|
|
HonorBidRecord record = hotStore.findBidByMediaTrace(traceId);
|
|
|
if (record == null) {
|
|
|
- log.info("[荣耀][点击] Redis未命中, 发起竞价请求, traceId={}", traceId);
|
|
|
- NormalizedBidResponse bidResponse = adxClient.requestBid(buildBidRequest(request, traceId, params));
|
|
|
+ NormalizedBidResponse bidResponse = adxClient.requestBid(traceId, buildBidRequest(request, traceId, params));
|
|
|
if (bidResponse == null) {
|
|
|
- log.warn("[荣耀][点击] 百度ADX返回空响应, traceId={}", traceId);
|
|
|
+ log.warn("[荣耀][点击][百度结果] traceId={} empty=true", traceId);
|
|
|
throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, "empty baidu ADX response");
|
|
|
}
|
|
|
+ log.info("[荣耀][点击][竞价结果] traceId={} qk={} bidId={} success={} price={} clickUrlCount={} showUrlCount={}",
|
|
|
+ traceId,
|
|
|
+ bidResponse.getQk(),
|
|
|
+ bidResponse.getBidId(),
|
|
|
+ bidResponse.getBid() != null,
|
|
|
+ bidResponse.getBid() != null ? bidResponse.getBid().getPrice() : 0,
|
|
|
+ bidResponse.getBid() != null && bidResponse.getBid().getClickUrls() != null ? bidResponse.getBid().getClickUrls().size() : 0,
|
|
|
+ bidResponse.getBid() != null && bidResponse.getBid().getShowUrls() != null ? bidResponse.getBid().getShowUrls().size() : 0);
|
|
|
record = bidRecordFromResponse(bidResponse, traceId, "click", params);
|
|
|
hotStore.recordBid(record);
|
|
|
- log.info("[荣耀][点击] 竞价成功, qk={}, traceId={}", record.getQk(), traceId);
|
|
|
if (bidResponse.getBid() != null && bidResponse.getBid().getShowUrls() != null && !bidResponse.getBid().getShowUrls().isEmpty()) {
|
|
|
List<TrackingResult> impressionTracking = adxClient.reportImpression(
|
|
|
bidResponse.getBid().getShowUrls(), bidResponse.getBid().getPrice());
|
|
|
- log.info("[荣耀][点击] Redis未命中补竞价后,曝光上报完成, qk={}, results={}", record.getQk(), impressionTracking);
|
|
|
recordTracking(record.getQk(), tagId, "impression", impressionTracking);
|
|
|
}
|
|
|
- } else {
|
|
|
- log.info("[荣耀][点击] Redis命中, qk={}, traceId={}", record.getQk(), traceId);
|
|
|
}
|
|
|
|
|
|
List<TrackingResult> tracking = adxClient.reportClick(
|
|
|
record.getClickUrls() != null ? record.getClickUrls() : Collections.emptyList());
|
|
|
- log.info("[荣耀][点击] 点击上报完成, qk={}, results={}", record.getQk(), tracking);
|
|
|
recordTracking(record.getQk(), tagId, "click", tracking);
|
|
|
try {
|
|
|
hotStore.shrinkAfterClick(record);
|
|
|
} catch (Exception e) {
|
|
|
- log.warn("[荣耀][点击] Redis缩减失败(不影响主流程), qk={}, error={}", record.getQk(), e.getMessage());
|
|
|
}
|
|
|
|
|
|
String destination = record.getAppStoreLink() != null && !record.getAppStoreLink().isBlank()
|
|
|
? record.getAppStoreLink() : record.getLandingPage();
|
|
|
if (destination != null && !destination.isBlank()) {
|
|
|
- log.info("[荣耀][点击] 302重定向, qk={}, destination={}", record.getQk(), destination);
|
|
|
response.sendRedirect(destination);
|
|
|
return null;
|
|
|
}
|
|
|
@@ -214,7 +220,7 @@ public class HonorTrackingController {
|
|
|
bidReq.put("device", device);
|
|
|
List<Integer> appList = parseAppList(firstParam(params, "appList", "app_list", "applist"));
|
|
|
if (!appList.isEmpty()) bidReq.put("appList", appList);
|
|
|
- log.info("[荣耀][百度ADX] 竞价请求 | traceId={} | body={}", traceId, bidReq);
|
|
|
+ log.info("[荣耀][百度请求] traceId={} body={}", traceId, toJson(bidReq));
|
|
|
return bidReq;
|
|
|
}
|
|
|
|
|
|
@@ -316,7 +322,7 @@ public class HonorTrackingController {
|
|
|
try {
|
|
|
result.add(Integer.parseInt(item));
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.warn("[荣耀][百度ADX] 忽略非法 appList 值 | raw={} | item={}", value, item);
|
|
|
+ log.warn("[荣耀][百度请求] invalidAppList raw={} item={}", value, item);
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
@@ -380,4 +386,12 @@ public class HonorTrackingController {
|
|
|
if (xri != null && !xri.isBlank()) return xri.trim();
|
|
|
return request.getRemoteAddr();
|
|
|
}
|
|
|
+
|
|
|
+ private String toJson(Object value) {
|
|
|
+ try {
|
|
|
+ return objectMapper.writeValueAsString(value);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return String.valueOf(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|