日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

[Spring cloud 一步步实现广告系统] 17. 根据流量类型查询广告

發布時間:2025/6/17 windows 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [Spring cloud 一步步实现广告系统] 17. 根据流量类型查询广告 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

廣告檢索服務

功能介紹

媒體方(手機APP打開的展示廣告,走在路上看到的大屏幕廣告等等)

請求數據對象實現

從上圖我們可以看出,在媒體方向我們的廣告檢索系統發起請求的時候,請求中會有很多的請求參數信息,他們分為了三個部分,我們來編碼封裝這幾個參數對象信息以及我們請求本身的信息。Let's code.

  • 創建廣告檢索請求接口
/*** ISearch for 請求接口,* 根據廣告請求對象,獲取廣告響應信息** @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang | 若初</a>*/ @FunctionalInterface public interface ISearch {/*** 根據請求返回廣告結果*/SearchResponse fetchAds(SearchRequest request); }
  • 創建SearchRequest,包含三部分:mediaId,RequestInfo,FeatureInfo
@Data @NoArgsConstructor @AllArgsConstructor public class SearchRequest {//媒體方請求標示private String mediaId;//請求基本信息private RequestInfo requestInfo;//匹配信息private FeatureInfo featureInfo;@Data@NoArgsConstructor@AllArgsConstructorpublic static class RequestInfo {private String requestId;private List<AdSlot> adSlots;private App app;private Geo geo;private Device device;}@Data@NoArgsConstructor@AllArgsConstructorpublic static class FeatureInfo {private KeywordFeature keywordFeature;private DistrictFeature districtFeature;private HobbyFeatrue hobbyFeatrue;private FeatureRelation relation = FeatureRelation.AND;} }

其他的對象大家可以去github傳送門 & gitee傳送門 下載源碼。

檢索響應對象定義
/*** SearchResponse for 檢索API響應對象** @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang | 若初</a>*/ @Data @Builder @NoArgsConstructor @AllArgsConstructor public class SearchResponse {//一個廣告位,可以展示多個廣告//Map key為廣告位 AdSlot#adSlotCodepublic Map<String, List<Creative>> adSlotRelationAds = new HashMap<>();@Data@Builder@NoArgsConstructor@AllArgsConstructorpublic static class Creative {private Long adId;private String adUrl;private Integer width;private Integer height;private Integer type;private Integer materialType;//展示監控urlprivate List<String> showMonitorUrl = Arrays.asList("www.life-runner.com", "www.babydy.cn");//點擊監控urlprivate List<String> clickMonitorUrl = Arrays.asList("www.life-runner.com", "www.babydy.cn");}/*** 我們的檢索服務針對的是內存中的索引檢索,那么我們就需要一個轉換方法*/public static Creative convert(CreativeIndexObject object) {return Creative.builder().adId(object.getAdId()).adUrl(object.getAdUrl()).width(object.getWidth()).height(object.getHeight()).type(object.getType()).materialType(object.getMaterialType()).build();} }
根據流量類型廣告過濾

流量類型本身屬于推廣單元下的類目,有很多種類貼片廣告,開屏廣告等等,這些類型需要同步到媒體方,媒體方會根據不同的流量類型發起不同的廣告請求,我們需要先定義一個流量類型的信息類。

public class AdUnitConstants {public static class PositionType{//App啟動時展示的、展示時間短暫的全屏化廣告形式。private static final int KAIPING = 1;//電影開始之前的廣告private static final int TIEPIAN = 2;//電影播放中途廣告private static final int TIEPIAN_MIDDLE = 4;//暫停視頻時候播放的廣告private static final int TIEPIAN_PAUSE = 8;//視頻播放完private static final int TIEPIAN_POST = 16;} }

從上述類型的數字,我們可以看出是2的倍數,這是為了使用位運算提升性能。

在com.sxzhongf.ad.index.adunit.AdUnitIndexObject中,我們添加類型校驗方法:

public static boolean isAdSlotType(int adSlotType, int positionType) {switch (adSlotType) {case AdUnitConstants.PositionType.KAIPING:return isKaiPing(positionType);case AdUnitConstants.PositionType.TIEPIAN:return isTiePian(positionType);case AdUnitConstants.PositionType.TIEPIAN_MIDDLE:return isTiePianMiddle(positionType);case AdUnitConstants.PositionType.TIEPIAN_PAUSE:return isTiePianPause(positionType);case AdUnitConstants.PositionType.TIEPIAN_POST:return isTiePianPost(positionType);default:return false;}}/*** 與運算,低位取等,高位補零。* 如果 > 0,則為開屏*/private static boolean isKaiPing(int positionType) {return (positionType & AdUnitConstants.PositionType.KAIPING) > 0;}private static boolean isTiePianMiddle(int positionType) {return (positionType & AdUnitConstants.PositionType.TIEPIAN_MIDDLE) > 0;}private static boolean isTiePianPause(int positionType) {return (positionType & AdUnitConstants.PositionType.TIEPIAN_PAUSE) > 0;}private static boolean isTiePianPost(int positionType) {return (positionType & AdUnitConstants.PositionType.TIEPIAN_POST) > 0;}private static boolean isTiePian(int positionType) {return (positionType & AdUnitConstants.PositionType.TIEPIAN) > 0;}

無所如何,我們都是需要根據positionType進行數據查詢過濾,我們在之前的com.sxzhongf.ad.index.adunit.AdUnitIndexAwareImpl中添加2個方法來實現過濾:

/*** 過濾當前是否存在滿足positionType的UnitIds*/public Set<Long> match(Integer positionType) {Set<Long> adUnitIds = new HashSet<>();objectMap.forEach((k, v) -> {if (AdUnitIndexObject.isAdSlotType(positionType, v.getPositionType())) {adUnitIds.add(k);}});return adUnitIds;}/*** 根據UnitIds查詢AdUnit list*/public List<AdUnitIndexObject> fetch(Collection<Long> adUnitIds) {if (CollectionUtils.isEmpty(adUnitIds)) {return Collections.EMPTY_LIST;}List<AdUnitIndexObject> result = new ArrayList<>();adUnitIds.forEach(id -> {AdUnitIndexObject object = get(id);if (null == object) {log.error("AdUnitIndexObject does not found:{}", id);return;}result.add(object);});return result;}
  • 實現Search服務接口

上述我們準備了一系列的查詢方法,都是為了根據流量類型查詢廣告單元信息,我們現在開始實現我們的查詢接口,查詢接口中,我們可以獲取到媒體方的請求對象信息,它帶有一系列查詢所需要的過濾參數:

/*** SearchImpl for 實現search 服務** @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang | 若初</a>*/ @Service @Slf4j public class SearchImpl implements ISearch {@Overridepublic SearchResponse fetchAds(SearchRequest request) {//獲取請求廣告位信息List<AdSlot> adSlotList = request.getRequestInfo().getAdSlots();//獲取三個Feature信息KeywordFeature keywordFeature = request.getFeatureInfo().getKeywordFeature();HobbyFeatrue hobbyFeatrue = request.getFeatureInfo().getHobbyFeatrue();DistrictFeature districtFeature = request.getFeatureInfo().getDistrictFeature();//Feature關系FeatureRelation featureRelation = request.getFeatureInfo().getRelation();//構造響應對象SearchResponse response = new SearchResponse();Map<String, List<SearchResponse.Creative>> adSlotRelationAds = response.getAdSlotRelationAds();for (AdSlot adSlot : adSlotList) {Set<Long> targetUnitIdSet;//根據流量類型從緩存中獲取 初始 廣告信息Set<Long> adUnitIdSet = IndexDataTableUtils.of(AdUnitIndexAwareImpl.class).match(adSlot.getPositionType());}return null;} }

轉載于:https://www.cnblogs.com/zhangpan1244/p/11343026.html

總結

以上是生活随笔為你收集整理的[Spring cloud 一步步实现广告系统] 17. 根据流量类型查询广告的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。