Commit d2f6d7d0 authored by 宋新宇's avatar 宋新宇

点击

parent 5ba5ece1
package com.lwby.marketing.controller;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
......@@ -24,11 +25,13 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController
@Slf4j
......@@ -110,6 +113,37 @@ public class ClickbackService extends ServiceHelper{
return RESULT_SUCCESS;
}
@RequestMapping("/jrttFreeVideo")
@ResponseBody
public Object jrttFreeVideoClick(@RequestParam Map<String, String> params){
NovelAction action = fullJrttFreeVideo(params);
for(DeviceVideoType type: DeviceVideoType.values()){
String deviceIdKey = type.getDeviceId(action.getClientInfo());
if(null != deviceIdKey){
DeliveryDeviceInfo ddi = action.getDeliveryDeviceInfo();
if (StringUtils.isNotEmpty(ddi.getDj_channel())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(Integer.parseInt(ddi.getDj_channel())), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getBook_id())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryVRIdCacheKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi.getVideoResourceId()), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getPartId())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryVIIdCacheKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi.getVideoId()), bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
if (type == DeviceVideoType.IDFA) {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
} else {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKeyByIdfaAndPlatformId(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
return RESULT_SUCCESS;
}
public NovelAction fullJrtt(Map<String, String> params) {
ClientInfo clientInfo = new ClientInfo();
......@@ -216,6 +250,74 @@ public class ClickbackService extends ServiceHelper{
return new NovelAction(clientInfo,deliveryDeviceInfo);
}
public NovelAction fullJrttFreeVideo(Map<String, String> params) {
ClientInfo clientInfo = new ClientInfo();
//imeiMd5
clientInfo.setImei(params.get("imei"));
clientInfo.setOaid(params.get("oaid_md5"));
String idfa = params.get("idfa");
if (!filter.contains(idfa) && StringUtils.isNotEmpty(idfa)) {
clientInfo.setIdfa(SecureUtil.md5(idfa));
}
clientInfo.setClientIp(params.get("ip"));
clientInfo.setUa(params.get("ua"));
clientInfo.setPhoneModel(encode(params.get("model")));
DeliveryDeviceInfo deliveryDeviceInfo = new DeliveryDeviceInfo();
deliveryDeviceInfo.setClick_time(System.currentTimeMillis());
deliveryDeviceInfo.setAd_group_id(params.get("campaign_id"));
deliveryDeviceInfo.setAd_creative_id(params.get("cid"));
deliveryDeviceInfo.setAd_plan_id(params.get("adid"));
deliveryDeviceInfo.setMedia(Media.VIDEOAPP_JRTT.name);
deliveryDeviceInfo.setPlatform_id(params.get("platform_id"));
deliveryDeviceInfo.setDj_channel(params.get("channel"));
deliveryDeviceInfo.setVideoResourceId(params.get("videoResourceId"));
deliveryDeviceInfo.setCallback_param(params.get("callback_param"));
if (Objects.isNull(deliveryDeviceInfo.getCallback_param())) {
deliveryDeviceInfo.setCallback_url(params.get("callback_url"));
}
deliveryDeviceInfo.setAdvertiser_id(params.get("advertiser_id"));
deliveryDeviceInfo.setUuid(UUID.randomUUID().toString());
deliveryDeviceInfo.setAd_platform_type(params.get("ad_platform_type"));
deliveryDeviceInfo.setTarget_audience(params.get("target_audience"));
deliveryDeviceInfo.setIp(params.get("ip"));
deliveryDeviceInfo.setVideoId(params.get("videoId"));
if (!filter.contains(params.get("oaid"))) {
deliveryDeviceInfo.setOaid(params.get("oaid"));
}
if (StringUtils.isNotEmpty(clientInfo.getImei())) {
deliveryDeviceInfo.setImeiMd5(clientInfo.getImei());
}
if (StringUtils.isNotEmpty(clientInfo.getPhoneModel())) {
deliveryDeviceInfo.setModel(clientInfo.getPhoneModel());
}
//通投智选union_site
deliveryDeviceInfo.setUnion_site(params.get("union_site"));
deliveryDeviceInfo.setPartId(params.get("part_id"));
//巨量广告体验版中特有的宏参,代表巨量广告体验版的广告ID
deliveryDeviceInfo.setPromotion_id(emptyIsNull(params.get("promotion_id")));
//巨量广告体验版中特有的宏参,代表巨量广告体验版的项目ID
deliveryDeviceInfo.setProject_id(emptyIsNull(params.get("project_id")));
//巨量广告体验版中的广告名称
deliveryDeviceInfo.setPromotion_name(emptyIsNull(params.get("promotion_name")));
//巨量广告体验版中的项目名称
deliveryDeviceInfo.setProject_name(emptyIsNull(params.get("project_name")));
//信息流投放广告来源(碎片 1 书籍 2)
deliveryDeviceInfo.setSource(parseInt(params.get("source")));
deliveryDeviceInfo.setMid1(emptyIsNull(params.get("mid1")));
deliveryDeviceInfo.setMid2(emptyIsNull(params.get("mid2")));
deliveryDeviceInfo.setMid3(emptyIsNull(params.get("mid3")));
deliveryDeviceInfo.setMid4(emptyIsNull(params.get("mid4")));
deliveryDeviceInfo.setMid5(emptyIsNull(params.get("mid5")));
deliveryDeviceInfo.setMid6(emptyIsNull(params.get("mid6")));
storyKafkaTemplate.send("growth_ad_click", JSONObject.toJSONString(params));
return new NovelAction(clientInfo,deliveryDeviceInfo);
}
enum DeviceType {
IMEI("imei",(c) -> isNotEmptyAndSNull(c.getImei())?c.getImei():null),
OAID("oaid", (c) -> isNotEmptyAndSNull(c.getOaid())?c.getOaid():null),
......@@ -245,4 +347,36 @@ public class ClickbackService extends ServiceHelper{
return StringUtils.isNotEmpty(str) && !filter.contains(str);
}
}
enum DeviceVideoType {
OAID("oaid", (c) -> isNotEmptyAndSNull(c.getOaid())?c.getOaid():null),
IDFA("idfa",(c) -> isNotEmptyAndSNull(c.getIdfa())?c.getIdfa():null),
IP_UA("ipua",(c) ->
(isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getUa())) ?
(("0".equals(c.getOs()) ? c.getClientIp().concat(StringUtils.substringBefore(c.getUa(), " Chrome/")) :
( c.getUa().startsWith("bi kan duan ju") ? Arrays.stream(c.getSystemVersion().split("\\.")).collect(Collectors.joining("_")):
c.getClientIp().concat(c.getUa())))):null),
IP_MODEL("ipmodel",(c) -> isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getPhoneModel())?c.getClientIp().concat(c.getPhoneModel()):null);
private String value;
private Function<ClientInfo,String> fun;
DeviceVideoType(String value, Function<ClientInfo,String> fun) {
this.value = value;
this.fun = fun;
}
public String getValue() {
return this.value;
}
public String getDeviceId(ClientInfo clientInfo){
return fun.apply(clientInfo);
}
private static boolean isNotEmptyAndSNull(String str) {
return StringUtils.isNotEmpty(str) && !"null".equals(str);
}
}
}
......@@ -40,4 +40,16 @@ public class ServiceHelper {
}
return null;
}
public String assembleKey(String deviceId, ClickbackService.DeviceVideoType type) {
switch (type) {
case OAID:
case IDFA:
return deviceId;
case IP_UA:
case IP_MODEL:
return SecureUtil.md5(deviceId);
}
return null;
}
}
......@@ -23,6 +23,10 @@ public class CacheKeyUtils {
private static final String CHANNEL_PREFIX_KEY = "getChannelBy";
private static final String CACHE_VRID_PRE = "vr:";
private static final String CACHE_VID_PRE = "vi:";
public static String getBehavoirKey(Long userId) {
return CACHE_BEHAVIOR_PREFIX + userId + "_" + df.format(new Date()) + "_fv";
......@@ -70,4 +74,12 @@ public class CacheKeyUtils {
}
return model;
}
public static String getDeliveryVRIdCacheKey(String deviceKey, String platformId) {
return CACHE_VRID_PRE + deviceKey + ":" + platformId;
}
public static String getDeliveryVIIdCacheKey(String deviceKey, String platformId) {
return CACHE_VID_PRE + deviceKey + ":" + platformId;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment