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

修改

parent e4efa100
......@@ -9,8 +9,8 @@ public enum DeviceType {
IMEI("imei",(c) -> isNotEmptyAndSNull(c.getImei())?c.getImei():null),
OAID("oaid", (c) -> isNotEmptyAndSNull(c.getOaid())?c.getOaid():null),
IDFA("idfa",(c) -> isNotEmptyAndSNull(c.getIdfa())?c.getIdfa():null),
IP_MODEL("ipmodel",(c) -> isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getPhoneModel())?c.getClientIp().concat(c.getPhoneModel()):null),
IP_UA("ipua",(c) -> isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getUa())?c.getClientIp().concat(StringUtils.substringBefore(c.getUa(), " Chrome/")):null),
IP_MODEL("ipmodel",(c) -> isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getPhoneModel())?c.getClientIp().concat(c.getPhoneModel()):null),
IP("ip",(c) -> isNotEmptyAndSNull(c.getClientIp())?c.getClientIp():null);
private String value;
......
package com.lwby.aas.controller;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.lwby.aas.DeviceType;
import com.lwby.aas.enums.CallEnum;
import com.lwby.aas.factory.AttributeHandleFactory;
import com.lwby.aas.handle.AttributionHandle;
import com.lwby.aas.handle.BaseHelper;
import com.lwby.aas.handle.Flow;
import com.lwby.aas.util.BaseCallHelper;
import com.lwby.aas.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Objects;
/**
* @author songxinyu
* @version AttributeController.java, v 0.1 2024年02月23日 18:57 songxinyu Exp $
*/
@Controller
@RequestMapping(value = "/attr")
@Slf4j
@ResponseBody
public class AttributeController extends BaseHelper {
@Resource
BaseCallHelper baseCallHelper;
@Resource
AttributeHandleFactory attributeHandleFactory;
@RequestMapping("/testUpload")
public void testUpload() {
String msg = "{\"bookStoreEvent\":1,\"clientInfo\":{\"channel\":210633175,\"clientIp\":\"119.2.220.77\","
+ "\"dID\":\"5af3a4af1984ccfa\",\"ddid\":\"DuZJq0+2z8dswVG3NtNQ96J/HQpiln+MXLew/8UZ/TllZSj5PedZVPzn71LxK9g"
+ "+WdYQboRXHBGJIs6xKyQyehFg\",\"firm\":\"OPPO\",\"fixVersion\":2,\"mainVersion\":2,"
+ "\"oaid\":\"086C4916ADF84ED8AF7B36CC9AC2E6C40f99db49e719aea064697461d0f7756c\",\"os\":\"0\",\"phoneModel\":\"PFVM10\","
+ "\"pkv\":1,\"platformGroupId\":6,\"platformId\":6,\"pm\":\"PFVM10\",\"screenSize\":\"720*1504\","
+ "\"sessionid\":\"wnL6tS5SxV-wnLtNuOOK-942FVeOLLKbj\",\"signVersion\":2,\"subVersion\":30,\"systemVersion\":\"12\","
+ "\"ua\":\"Mozilla/5.0 (Linux; Android 12; PFVM10 Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) "
+ "Version/4.0 Chrome/97.0.4692.98 Mobile Safari/537.36\",\"user\":{\"career\":\"\",\"channel\":210633175,"
+ "\"deviceId\":\"5af3a4af1984ccfa\",\"experience\":1,\"gender\":\"M\",\"headImage\":\"http://cdn.ibreader"
+ ".com/group1/M00/56/07/rBH0olunjn2AeTz8AAAQDrNZNzM090.png\",\"id\":129915974,\"isKaiqiUser\":false,\"isMajia\":false,"
+ "\"isPrivate\":false,\"lastLogin\":1693280011000,\"level\":0,\"mainversion\":2,\"nickname\":\"书友254834\","
+ "\"platformId\":6,\"registrationDate\":1693280011000,\"subversion\":30,\"userStatus\":0,"
+ "\"username\":\"bdNGcUn2jmCeRD\"},\"version\":\"6.2.30.02.210633175\","
+ "\"visitor\":\"wnL6tS5SxV-wnLtNuOOK-942FVeOLLKbj\",\"xClient\":\"dID=5af3a4af1984ccfa;os=0;firm=OPPO;webVersion=new;"
+ "version=6.2.30.02.210633175;username=wnL6tS5SxV-wnLtNuOOK-942FVeOLLKbj;"
+ "ddid=DuZJq0+2z8dswVG3NtNQ96J/HQpiln+MXLew/8UZ/TllZSj5PedZVPzn71LxK9g+WdYQboRXHBGJIs6xKyQyehFg;sv=12;pm=PFVM10;"
+ "ss=720*1504;signVersion=2;androidosv=31;oaid=086C4916ADF84ED8AF7B36CC9AC2E6C40f99db49e719aea064697461d0f7756c;pkv=1;"
+ "\"},\"createTime\":1708877129228,\"extraData\":{},\"id\":\"5302e518-27b6-44e0-8077-499e0d31ad89\"}";
BookStoreEvent event = JSONObject.parseObject(msg, BookStoreEvent.class);
ClientInfo clientInfo = event.getClientInfo();
//获取用户注册时间
UserProfile userProfile = clientInfo.getUser();
if (userProfile == null || userProfile.getRegistrationDate() == null) {
log.error("ClientInfo.userProfile 对像为[{}],BookStoreEvent报文[{}]、对像[{}]",userProfile, msg, event);
return;
}
//ANDROID deviceId
String deviceId = clientInfo.getDID();
//平台ID
Integer platformId = clientInfo.getPlatformId();
//设备ID类型
DeviceType deviceType = null;
//设备ID
String deviceIdKey = null;
//VO对像
DeliveryDeviceInfo deliveryDeviceInfo = null;
//匹配设备ID
for(DeviceType type:DeviceType.values()){
deviceIdKey = type.getDeviceId(clientInfo);
if(null != deviceIdKey && null != (deliveryDeviceInfo = getForRedis(assembleKey(deviceIdKey,platformId)))){
deviceType = type;
clientInfo.setOaid(deliveryDeviceInfo.getOaid()); //回补OAID
break;
}
}
if(DeviceType.IP == deviceType){
//TODO;只发BI 不上报逻辑
baseCallHelper.summaryByUserChannel(clientInfo,CallEnum.IP_CALLBACK.getValue(),deliveryDeviceInfo);
return;
}
Action action = new Action(clientInfo,deliveryDeviceInfo);
for(AttributionHandle handle:attributeHandleFactory.getHandleList()){
if(handle.handle(action) != Flow.NEXT){
break;
}
}
}
}
package com.lwby.aas.enums;
/**
* @author songxinyu
* @version CallEnum.java, v 0.1 2024年02月23日 10:27 songxinyu Exp $
*/
public enum CallEnum {
/**
* 激活回传
*/
ACTIVE_CALLBACK {
@Override
public Integer getValue() {
return 2;
}
@Override
public String getDescription() {
return "激活回传";
}
},
/**
* 商店
*/
STORE_CALLBACK {
@Override
public Integer getValue() {
return 3;
}
@Override
public String getDescription() {
return "商店";
}
},
/**
* 正常扣量
*/
NORMAL_DEDUCTION_CALLBACK {
@Override
public Integer getValue() {
return 4;
}
@Override
public String getDescription() {
return "正常扣量";
}
},
/**
* 老用户扣量(不是当天,活跃天数内)
*/
OLDUSER_DEDUCTION_CALLBACK {
@Override
public Integer getValue() {
return 7;
}
@Override
public String getDescription() {
return "老用户扣量";
}
},
/**
* ip获取点击对象
*/
IP_CALLBACK {
@Override
public Integer getValue() {
return 9;
}
@Override
public String getDescription() {
return "ip";
}
},
;
/**
* 获取对应的枚举的值
*
* @return 对应的枚举的值
*/
public abstract Integer getValue();
/**
* 获取对应的枚举的描述
*
* @return 对应的枚举的描述
*/
public abstract String getDescription();
/**
* 根据对应的枚举的值获取回传类型枚举, 未找到则返回null
*
* @param value 对应的枚举的值
* @return 对应的枚举, 未找到则返回null
*/
public static CallEnum getCallEnum(Integer value) {
for (CallEnum callEnum : CallEnum.values()) {
if (callEnum.getValue().equals(value)) {
return callEnum;
}
}
return null;
}
}
package com.lwby.aas.enums;
/**
* 媒体枚举
* @author zhangxz
* @version MediaEnum.java, v 0.1 2021年01月15日 14:33 zhangxz Exp $
*/
public enum MediaEnum {
/**
* 爱奇艺
*/
QI_YI {
@Override
public String getMediaName() {
return "qiYi";
}
@Override
public String getDesc() {
return "爱奇艺";
}
},
/**
* 今日头条
*/
TOU_TIAO {
@Override
public String getMediaName() {
return "jrtt";
}
@Override
public String getDesc() {
return "今日头条";
}
},
/**
* 今日头条洋葱
*/
TOU_TIAO_ONION {
@Override
public String getMediaName() {
return "jrtt_onion";
}
@Override
public String getDesc() {
return "今日头条洋葱";
}
},
/**
* 广点通
*/
GDT {
@Override
public String getMediaName() {
return "gdt";
}
@Override
public String getDesc() {
return "广点通";
}
},
/**
* 快手
*/
KUAI_SHOW {
@Override
public String getMediaName() {
return "kuaishou";
}
@Override
public String getDesc() {
return "快手";
}
},
/**
* 百度
*/
BAI_DU {
@Override
public String getMediaName() {
return "baidu";
}
@Override
public String getDesc() {
return "百度";
}
},
/**
* 百度搜索
*/
BAI_DU_SOU_SUO {
@Override
public String getMediaName() {
return "baidusousuo";
}
@Override
public String getDesc() {
return "百度搜索";
}
},
/**
* 微信
*/
WECHAT {
@Override
public String getMediaName() {
return "wechat";
}
@Override
public String getDesc() {
return "微信";
}
},
/**
* UC浏览器
*/
UC {
@Override
public String getMediaName() {
return "uc";
}
@Override
public String getDesc() {
return "UC浏览器";
}
},
/**
* UC搜索
*/
UC_SOU_SUO {
@Override
public String getMediaName() {
return "ucsousuo";
}
@Override
public String getDesc() {
return "UC搜索";
}
},
/**
* 趣头条
*/
QU_TOU_TIAO {
@Override
public String getMediaName() {
return "qutoutiao";
}
@Override
public String getDesc() {
return "趣头条";
}
},
/**
* 快手磁力聚星
*/
KUAI_SHOU_KOL {
@Override
public String getMediaName() {
return "kuaishoukol";
}
@Override
public String getDesc() {
return "磁力聚星";
}
},
/**
* 迅雷红桃h5
*/
HONGTAO_H5 {
@Override
public String getMediaName() {
return "hongtaoh5";
}
@Override
public String getDesc() {
return "迅雷红桃h5";
}
},
/**
* 小米
*/
XIAOMI {
@Override
public String getMediaName() {
return "xiaomi";
}
@Override
public String getDesc() {
return "小米";
}
},
/**
* 喜马拉雅
*/
HIMALAYAN {
@Override
public String getMediaName() {
return "himalayan";
}
@Override
public String getDesc() {
return "喜马拉雅";
}
},
/**
* VIVO
*/
VIVO {
@Override
public String getMediaName() {
return "vivo";
}
@Override
public String getDesc() {
return "vivo";
}
},
/**
* OPPO
*/
OPPO {
@Override
public String getMediaName() {
return "oppo";
}
@Override
public String getDesc() {
return "oppo";
}
},
/**
* jrtt_shortVedio
*/
JRTT_SHORTVIDEO_OLD {
@Override
public String getMediaName() {
return "jrtt_shortVideo_old";
}
@Override
public String getDesc() {
return "jrtt_shortVedio_old";
}
},
/**
* jrtt_shortVedio
*/
JRTT_SHORTVIDEO {
@Override
public String getMediaName() {
return "jrtt_shortVideo";
}
@Override
public String getDesc() {
return "jrtt_shortVedio";
}
},
/**
* jrtt_shortVedio
*/
JRTT_WECHATH5 {
@Override
public String getMediaName() {
return "jrtt_wechath5";
}
@Override
public String getDesc() {
return "jrtt_wechath5";
}
},
/**
* tiktok_shortVedio
*/
TIKTOK_SHORTVIDEO {
@Override
public String getMediaName() {
return "tiktok_shortVideo";
}
@Override
public String getDesc() {
return "tiktok_shortVideo";
}
},
/**
* gdt_shortVedio
*/
GDT_SHORTVIDEO {
@Override
public String getMediaName() {
return "gdt_shortVideo";
}
@Override
public String getDesc() {
return "gdt_shortVedio";
}
},
/**
* 网易有道
*/
YOUDAO {
@Override
public String getMediaName() {
return "youdao";
}
@Override
public String getDesc() {
return "网易有道";
}
},
/**
* jrtt_freevideo
*/
JRTT_FREEVIDEO {
@Override
public String getMediaName() {
return "jrtt_freevideo";
}
@Override
public String getDesc() {
return "jrtt_freevideo";
}
};
/**
* 媒体名称
*/
public abstract String getMediaName();
/**
* 媒体描述
*/
public abstract String getDesc();
/**
* 根据媒体名称获取媒体枚举
* @param mediaName 媒体名称
* @return 媒体枚举
*/
public static MediaEnum getByMediaName(String mediaName) {
for (MediaEnum mediaEnum : MediaEnum.values()) {
if (mediaEnum.getMediaName().equals(mediaName)) {
return mediaEnum;
}
}
return null;
}
}
package com.lwby.aas.enums;
public enum StoreEnum {
//媒体 媒体编号 媒体名
//小米 11 xiaomi
//华为 12 huawei
//oppo 13 oppo
//vivo 14 vivo
//应用宝15 yingyongbao
//魅族 16 meizu
//360手助17 360zhushou
//百度手助18 baiduzhushou
//其他(阿里等)19other
//今日头条21 jinritoutiao
//广点通/微信22guangdiantong
//快手 23 kuaishou
xiaomi("11","xiaomi"),
huawei("12","huawei"),
oppo("13","oppo"),
vivo("14","vivo"),
yingyongbao("15","yingyongbao"),
meizu("16","meizu"),
zhushou("17","360zhushou"),
baiduzhushou("18","baiduzhushou"),
other("19","other"),
jinritoutiao("21","jinritoutiao"),
guangdiantong("22","guangdiantong"),
kuaishou("23","kuaishou"),
uc("24","uc"),
qutoutiao("25","qutoutiao"),
youdao("28","youdao"),
dystore("33","dystore")
;
private String storePrefix;
private String storeDesc;
/**
* 获取
*
* @return 对应的
*/
public String getStorePrefix() {
return storePrefix;
}
/**
* 设置
*
* @param storePrefix 要设置的
*/
public void setStorePrefix(String storePrefix) {
this.storePrefix = storePrefix;
}
/**
* 获取
*
* @return 对应的
*/
public String getStoreDesc() {
return storeDesc;
}
/**
* 设置
*
* @param storeDesc 要设置的
*/
public void setStoreDesc(String storeDesc) {
this.storeDesc = storeDesc;
}
StoreEnum(String storePrefix, String storeDesc) {
this.storePrefix = storePrefix;
this.storeDesc = storeDesc;
}
/**
* 根据指定的渠道前缀获取对应的通用状态的枚举对象,未找到则返回null
*
* @param channelPre 指定的渠道前缀
* @return 对应的通用状态的枚举对象,未找到则返回null
*/
public static String getStoreDescByChannelPre(String channelPre){
for (StoreEnum storeEnum : StoreEnum.values()) {
if (storeEnum.getStorePrefix().equals(channelPre)) {
return storeEnum.getStoreDesc();
}
}
return null;
}
/**
* 根据指定的渠道前缀获取对应的通用状态的枚举对象
* @param channelPre 渠道前缀
* @return 枚举对象,未找到则返回null
*/
public static StoreEnum getByChannelPre(String channelPre){
for (StoreEnum storeEnum : StoreEnum.values()) {
if (storeEnum.getStorePrefix().equals(channelPre)) {
return storeEnum;
}
}
return null;
}
}
package com.lwby.aas.factory;
import com.lwby.aas.enums.MediaEnum;
import com.lwby.aas.handle.AttributionHandle;
import com.lwby.aas.service.IMediaActiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author songxinyu
* @version AttributeHandleFactory.java, v 0.1 2024年02月23日 18:51 songxinyu Exp $
*/
@Service
public class AttributeHandleFactory {
@Autowired
ApplicationContext applicationContext;
List<AttributionHandle> handleList = new ArrayList<>();
public List<AttributionHandle> getHandleList() {
return handleList;
}
@PostConstruct
public void init() {
handleList = applicationContext.getBeansOfType(AttributionHandle.class).values().stream()
.sorted(Comparator.comparingInt(AttributionHandle::order).reversed())
.collect(Collectors.toList());
}
}
package com.lwby.aas.factory;
import com.google.common.collect.ArrayListMultimap;
import com.lwby.aas.enums.MediaEnum;
import com.lwby.aas.service.IMediaActiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
@Service
public class MediaActiveFactory {
@Autowired
ApplicationContext applicationContext;
ArrayListMultimap<MediaEnum, IMediaActiveService> multimap = ArrayListMultimap.create();
/**
* @return
*/
/**
*
* @return
*/
public IMediaActiveService getMediaActiveService(MediaEnum mediaEnum) {
List<IMediaActiveService> mediaActiveServices = multimap.get(mediaEnum);
return mediaActiveServices.get(0);
}
/**
*
*/
@PostConstruct
public void init() {
Map<String, IMediaActiveService> type = applicationContext.getBeansOfType(IMediaActiveService.class);
for (Map.Entry<String, IMediaActiveService> item : type.entrySet()) {
multimap.put(item.getValue().getMediaEnum(), item.getValue());
}
}
}
......@@ -137,4 +137,6 @@ public class BaseHelper {
public DeliveryDeviceInfo getForRedis(String key) {
return null;
}
}
package com.lwby.aas.handle;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.lwby.aas.DeviceType;
import com.lwby.aas.enums.CallEnum;
import com.lwby.aas.util.BaseCallHelper;
import com.lwby.aas.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import javax.annotation.PostConstruct;
......@@ -19,6 +23,12 @@ public class TestHandle extends BaseHelper{
@Resource
ApplicationContext applicationContext;
@Resource
BaseCallHelper baseCallHelper;
@Value("${platformPrizeExpire:{}}")
private String platformPrizeExpire;
@PostConstruct
public void load(){
handleList = applicationContext.getBeansOfType(AttributionHandle.class).values().stream()
......@@ -60,12 +70,10 @@ public class TestHandle extends BaseHelper{
}
}
if(Objects.isNull(deliveryDeviceInfo)){
//TODO;如果为空归商店
}
if(DeviceType.IP == deviceType){
//TODO;只发BI 不上报逻辑
baseCallHelper.summaryByUserChannel(clientInfo,CallEnum.IP_CALLBACK.getValue(),deliveryDeviceInfo);
return;
}
Action action = new Action(clientInfo,deliveryDeviceInfo);
......@@ -77,6 +85,7 @@ public class TestHandle extends BaseHelper{
}
public static void main(String[] args) {
new TestHandle().init();
}
......
......@@ -9,6 +9,7 @@ import com.lwby.aas.vo.DeliveryDeviceInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component
public class BeforeHandle extends BaseHelper implements AttributionHandle {
......@@ -24,14 +25,16 @@ public class BeforeHandle extends BaseHelper implements AttributionHandle {
action.setPlatformId(ci.getPlatformId());
action.setUserId(ci.getUser().getId());
action.setChannelId(StringUtils.isNotBlank(dd.getDj_channel()) ? Integer.parseInt(dd.getDj_channel()) : -1);
action.setPlanId(StringUtils.isNotBlank(dd.getAd_plan_id()) ? Integer.parseInt(dd.getAd_plan_id()) : -1);
action.setAdvertiserId(dd.getAdvertiser_id());
action.setDeviceId(ci.getDID());
action.setMedia(dd.getMedia());
action.setNewUser(isCurrentDayTime(ci.getUser().getRegistrationDate()));
action.setRegistrationDate(ci.getUser().getRegistrationDate());
//商店的不赋值
if (Objects.nonNull(dd)) {
action.setChannelId(StringUtils.isNotBlank(dd.getDj_channel()) ? Integer.parseInt(dd.getDj_channel()) : -1);
action.setPlanId(StringUtils.isNotBlank(dd.getAd_plan_id()) ? Integer.parseInt(dd.getAd_plan_id()) : -1);
action.setAdvertiserId(dd.getAdvertiser_id());
action.setMedia(dd.getMedia());
}
return Flow.NEXT;
}
}
package com.lwby.aas.handle.impl;
import com.lwby.aas.enums.CallEnum;
import com.lwby.aas.handle.AttributionHandle;
import com.lwby.aas.handle.AttributionType;
import com.lwby.aas.handle.BaseHelper;
import com.lwby.aas.handle.Flow;
import com.lwby.aas.po.AppChannel;
import com.lwby.aas.service.ICallbackService;
import com.lwby.aas.util.BaseCallHelper;
import com.lwby.aas.vo.Action;
import com.lwby.aas.vo.ClientInfo;
import com.lwby.aas.vo.DeliveryDeviceInfo;
......@@ -28,6 +31,12 @@ public class ChannelAttributionHandle extends BaseHelper implements AttributionH
@Resource
JdbcTemplate lwbyJdbcTemplate;
@Resource
ICallbackService callbackService;
@Resource
BaseCallHelper baseCallHelper;
@Override
public int order() {
return 0;
......@@ -40,6 +49,9 @@ public class ChannelAttributionHandle extends BaseHelper implements AttributionH
public Flow handle0(Action action,AttributionType type) {
String dateStr = DATE_BOTTOM_FORMAT.format(new Date());
String isDeducOneByTodayKey = String.format("v_deduc_%d_%d_%d_%s",action.getDeviceId(),action.getPlatformId(),action.getMedia(),dateStr);
//是否是当天注册用户
boolean isNewUser = isCurrentDayTime(action.getRegistrationDate());
......@@ -47,14 +59,14 @@ public class ChannelAttributionHandle extends BaseHelper implements AttributionH
AppChannel appChannel = getAppChannel(lwbyJdbcTemplate,action.getPlatformId(), action.getChannelId());
//TODO;应该是等于空 或 = 100,如果空怎么办
if (appChannel != null && appChannel.getSprDedu() == 100) {
//TODO;扣量
if (appChannel == null || appChannel.getSprDedu() == 100) {
//TODO;回传
callbackService.registerCallback(action);
return Flow.END;
}
//如果是20 就是回传 20
Integer sprDedu = appChannel.getSprDedu();
String dateStr = DATE_BOTTOM_FORMAT.format(new Date());
//总数
String channelTotal = String.format("%s_total_%d_%d_%d_%s",type.getName(), action.getPlatformId(), type.select(action.getChannelId(),action.getPlanId()), sprDedu, dateStr);
......@@ -70,6 +82,9 @@ public class ChannelAttributionHandle extends BaseHelper implements AttributionH
if(!isNewUser && isAliveByDay(action.getUserId(),30)){
incrby(channelTotal, 1);
//TODO;扣量
baseCallHelper.summaryByUserChannel(action.getClientInfo(), CallEnum.OLDUSER_DEDUCTION_CALLBACK.getValue(), action.getDeliveryDeviceInfo());
//每天扣量过一次,不在重复走
set(isDeducOneByTodayKey,60 * 60 * 24,1);
return Flow.END;
}
......@@ -80,6 +95,7 @@ public class ChannelAttributionHandle extends BaseHelper implements AttributionH
//回传个数 ++
incrby(channelCallback, 1);
//TODO;回传事件
callbackService.registerCallback(action);
return Flow.END;
}
}else{
......@@ -91,11 +107,15 @@ public class ChannelAttributionHandle extends BaseHelper implements AttributionH
if (divide.compareTo(new BigDecimal(percent).setScale(4, RoundingMode.HALF_UP)) <= 0) {
//TODO;回传事件
incrby(channelCallback, 1);
callbackService.registerCallback(action);
return Flow.END;
}
}
//TODO;扣量
baseCallHelper.summaryByUserChannel(action.getClientInfo(), CallEnum.NORMAL_DEDUCTION_CALLBACK.getValue(), action.getDeliveryDeviceInfo());
//每天扣量过一次,不在重复走
set(isDeducOneByTodayKey,60 * 60 * 24,1);
return Flow.END;
}
......
......@@ -3,12 +3,15 @@ package com.lwby.aas.handle.impl;
import com.alicp.jetcache.anno.CacheRefresh;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.lwby.aas.enums.CallEnum;
import com.lwby.aas.handle.AttributionHandle;
import com.lwby.aas.handle.AttributionType;
import com.lwby.aas.handle.BaseHelper;
import com.lwby.aas.handle.Flow;
import com.lwby.aas.po.AppChannel;
import com.lwby.aas.po.CrossCallback;
import com.lwby.aas.service.ICallbackService;
import com.lwby.aas.util.BaseCallHelper;
import com.lwby.aas.vo.Action;
import com.lwby.aas.vo.ClientInfo;
import com.lwby.aas.vo.DeliveryDeviceInfo;
......@@ -30,6 +33,12 @@ public class CrossPlatformAttributionHandle extends BaseHelper implements Attrib
@Resource
JdbcTemplate lwbyJdbcTemplate;
@Resource
BaseCallHelper baseCallHelper;
@Resource
ICallbackService callbackService;
@Override
public int order() {
return 4;
......@@ -38,6 +47,12 @@ public class CrossPlatformAttributionHandle extends BaseHelper implements Attrib
@Override
public Flow handle(Action action) {
String dateStr = DATE_BOTTOM_FORMAT.format(new Date());
String isDeducOneByTodayKey = String.format("v_deduc_%d_%d_%d_%s",action.getDeviceId(),action.getPlatformId(),action.getMedia(),dateStr);
if (exists(isDeducOneByTodayKey)) {
return Flow.END;
}
//获取跨平台帐号配置
CrossPlatformAccount cpa = getCrossPlatformMedia().get(action.getMedia());
//判断是否配置跨平台归因,如果没有则继续执行下一个计划归因处理器
......@@ -47,43 +62,68 @@ public class CrossPlatformAttributionHandle extends BaseHelper implements Attrib
//返回注册时间
long daysSinceRegistration = 0;
//新增纯新用户,全回传,算到扣量分母
boolean isRealNewUser = false;
//两者之间的老用户
boolean isBetweenUser = false;
// 如果是当天注册新用户,则检查跨平台是否注册过,如果注册过,取最早注册时间做判断。
if (isCurrentDayTime(action.getRegistrationDate())) {
daysSinceRegistration = calculateDaysBetweenDates(getEarliestRegistrationTimeByDeviceId(action.getDeviceId()), new Date());
//纯新,判断其他平台最大注册日期
daysSinceRegistration = calculateDaysBetweenDates(getEarliestRegistrationTimeByDeviceId(action.getDeviceId(),action.getPlatformId()), new Date());
if (daysSinceRegistration<cpa.spanCheckMaxDay) {
isBetweenUser = true;
} else if (daysSinceRegistration>=cpa.spanCheckMaxDay && daysSinceRegistration<=150) {
isRealNewUser = true;
}
} else {
daysSinceRegistration = calculateDaysBetweenDates(action.getRegistrationDate(), new Date());
if (daysSinceRegistration<150) {
isBetweenUser = true;
}
}
if(daysSinceRegistration <= cpa.spanCheckMaxDay){
// 纯新用户逻辑
AppChannel appChannel = getAppChannel(lwbyJdbcTemplate,action.getPlatformId(), action.getChannelId());
//TODO;应该是等于空 或 = 100,如果空怎么办
if (appChannel == null || appChannel.getSprDedu() == 100) {
//TODO;回传
callbackService.registerCallback(action);
return Flow.END;
} else if (daysSinceRegistration <= 150) {
// 中间用户逻辑 (注册时间大于 cpa.spanCheckMaxDay 且小于 150 天)
//TODO;直接扣量
} else {
// 老用户逻辑 (注册时间大于等于 150 天)
AppChannel appChannel = getAppChannel(lwbyJdbcTemplate,action.getPlatformId(), action.getChannelId());
}
//TODO;应该是等于空 或 = 100,如果空怎么办
if (appChannel != null && appChannel.getSprDedu() == 100) {
//TODO;回传
return Flow.END;
}
//如果是20 就是回传 20
Integer sprDedu = appChannel.getSprDedu();
String dateStr = DATE_BOTTOM_FORMAT.format(new Date());
//如果是20 就是回传 20
Integer sprDedu = appChannel.getSprDedu();
//总数
String channelTotal = String.format("%s_total_%d_%d_%d_%s",AttributionType.CROSS_PLATFORM, action.getPlatformId(), action.getChannelId(), sprDedu, dateStr);
//回传
String channelCallback = String.format("%s_callback_%d_%d_%d_%s", AttributionType.CROSS_PLATFORM, action.getPlatformId(), action.getChannelId(), sprDedu, dateStr);
double percent = sprDedu.doubleValue();
//总数
String channelTotal = String.format("%s_total_%d_%d_%d_%s",AttributionType.CROSS_PLATFORM, action.getPlatformId(), action.getChannelId(), sprDedu, dateStr);
//回传
String channelCallback = String.format("%s_callback_%d_%d_%d_%s", AttributionType.CROSS_PLATFORM, action.getPlatformId(), action.getChannelId(), sprDedu, dateStr);
long channelTotalCount = incrby(channelTotal, 0, 60 * 60 * 24);
long channelCallbackCount = incrby(channelCallback, 0, 60 * 60 * 24);
double percent = sprDedu.doubleValue();
long channelTotalCount = incrby(channelTotal, 0, 60 * 60 * 24);
long channelCallbackCount = incrby(channelCallback, 0, 60 * 60 * 24);
if(isRealNewUser){
// 纯新用户逻辑
//TODO;回传
incrby(channelCallback,1);
incrby(channelTotal,1);
callbackService.registerCallback(action);
return Flow.END;
} else if (isBetweenUser) {
// 中间用户逻辑 (注册时间大于 cpa.spanCheckMaxDay 且小于 150 天)
//TODO;直接扣量
incrby(channelTotal,1);
baseCallHelper.summaryByUserChannel(action.getClientInfo(), CallEnum.NORMAL_DEDUCTION_CALLBACK.getValue(), action.getDeliveryDeviceInfo());
//每天扣量过一次,不在重复走
set(isDeducOneByTodayKey,60 * 60 * 24,1);
} else {
// 老用户逻辑 (注册时间大于等于 150 天)
//首次随机
if(0 == channelTotalCount){
incrby(channelTotal, 1);
......@@ -91,6 +131,7 @@ public class CrossPlatformAttributionHandle extends BaseHelper implements Attrib
//回传个数 ++
incrby(channelCallback, 1);
//TODO;回传事件
callbackService.registerCallback(action);
return Flow.END;
}
}else{
......@@ -102,11 +143,15 @@ public class CrossPlatformAttributionHandle extends BaseHelper implements Attrib
if (divide.compareTo(new BigDecimal(percent).setScale(4, RoundingMode.HALF_UP)) <= 0) {
//TODO;回传事件
incrby(channelCallback, 1);
callbackService.registerCallback(action);
return Flow.END;
}
}
//TODO;扣量
baseCallHelper.summaryByUserChannel(action.getClientInfo(), CallEnum.NORMAL_DEDUCTION_CALLBACK.getValue(), action.getDeliveryDeviceInfo());
//每天扣量过一次,不在重复走
set(isDeducOneByTodayKey,60 * 60 * 24,1);
return Flow.END;
}
......@@ -130,8 +175,8 @@ public class CrossPlatformAttributionHandle extends BaseHelper implements Attrib
* 获取设备ID的最早注册时间
* @return
*/
public Date getEarliestRegistrationTimeByDeviceId(String deviceId){
Date date = lwbyJdbcTemplate.queryForObject(String.format("select min(registration_date) from user_profiles where device_id = '%s'",deviceId),Date.class);
public Date getEarliestRegistrationTimeByDeviceId(String deviceId,Integer platformId){
Date date = lwbyJdbcTemplate.queryForObject(String.format("select max(registration_date) from user_profiles where platform_id in (5,6,7,51) and platform_id != %d and device_id = '%s'",platformId,deviceId),Date.class);
return Objects.isNull(date)?new Date():date;
}
......
......@@ -2,13 +2,16 @@ package com.lwby.aas.handle.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.lwby.aas.enums.CallEnum;
import com.lwby.aas.handle.AttributionHandle;
import com.lwby.aas.handle.BaseHelper;
import com.lwby.aas.handle.Flow;
import com.lwby.aas.util.BaseCallHelper;
import com.lwby.aas.vo.Action;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Objects;
@Component
......@@ -17,6 +20,9 @@ public class PrizeSevenUserHandle extends BaseHelper implements AttributionHandl
@Value("${platformPrizeExpire:{}}")
private String platformPrizeExpire;
@Resource
BaseCallHelper baseCallHelper;
@Override
public int order() {
return 4;
......@@ -38,6 +44,11 @@ public class PrizeSevenUserHandle extends BaseHelper implements AttributionHandl
set(prizeAssembleKey.concat(String.valueOf(action.getUserId())), 60 * 60 * 24 * 3, 1);
}
}
if(Objects.isNull(action.getDeliveryDeviceInfo())){
//TODO;如果为空归商店
baseCallHelper.callbackToStore(action.getClientInfo(), CallEnum.STORE_CALLBACK.getValue());
return Flow.END;
}
return Flow.NEXT;
}
}
package com.lwby.aas.service;
import com.lwby.aas.vo.Action;
/**
* @author songxinyu
* @version ICallbackService.java, v 0.1 2024年02月23日 16:29 songxinyu Exp $
*/
public interface ICallbackService {
void registerCallback(Action action);
}
package com.lwby.aas.service;
import com.lwby.aas.enums.MediaEnum;
import com.lwby.aas.vo.ClientInfo;
import com.lwby.aas.vo.DeliveryDeviceInfo;
/**
* @author songxinyu
* @version IMediaActiveService.java, v 0.1 2024年02月23日 16:38 songxinyu Exp $
*/
public interface IMediaActiveService {
Integer androidActive(ClientInfo clientInfo, DeliveryDeviceInfo deliveryDeviceInfo);
Integer iosActive(ClientInfo clientInfo,DeliveryDeviceInfo deliveryDeviceInfo);
MediaEnum getMediaEnum();
}
package com.lwby.aas.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.lwby.aas.enums.MediaEnum;
import com.lwby.aas.factory.MediaActiveFactory;
import com.lwby.aas.service.ICallbackService;
import com.lwby.aas.service.IMediaActiveService;
import com.lwby.aas.vo.Action;
import com.lwby.aas.vo.ClientInfo;
import com.lwby.aas.vo.DeliveryDeviceInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @author songxinyu
* @version CallbackServiceImpl.java, v 0.1 2024年02月23日 16:34 songxinyu Exp $
*/
@Slf4j
@Service
public class CallbackServiceImpl implements ICallbackService {
@Resource
MediaActiveFactory mediaActiveFactory;
public final static Integer CALL_BACK_SUCCESS = 0;
@Override
@Async
public void registerCallback(Action action) {
ClientInfo clientInfo = action.getClientInfo();
DeliveryDeviceInfo deliveryDeviceInfo = action.getDeliveryDeviceInfo();
IMediaActiveService mediaActiveService = mediaActiveFactory.getMediaActiveService(MediaEnum.getByMediaName(action.getMedia()));
Integer code = -1;
if(StringUtils.isNotEmpty(clientInfo.getOs())){
switch (clientInfo.getOs()){
case "0":
code = mediaActiveService.androidActive(clientInfo,deliveryDeviceInfo);
break;
case "1":
code = mediaActiveService.iosActive(clientInfo,deliveryDeviceInfo);
break;
default:
code = mediaActiveService.androidActive(clientInfo,deliveryDeviceInfo);
break;
}
}else{
code = mediaActiveService.androidActive(clientInfo,deliveryDeviceInfo);
}
if (!CALL_BACK_SUCCESS.equals(code)) {
log.error("CallbackServiceImpl registerCallback result code error,code={},clientInfo={}",code, JSONObject.toJSONString(clientInfo));
return;
}
}
}
package com.lwby.aas.service.impl.gdt;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lwby.aas.enums.CallEnum;
import com.lwby.aas.enums.MediaEnum;
import com.lwby.aas.handle.BaseHelper;
import com.lwby.aas.service.IMediaActiveService;
import com.lwby.aas.service.impl.gdt.dto.Action;
import com.lwby.aas.service.impl.gdt.dto.GdtAttributeRequest;
import com.lwby.aas.service.impl.gdt.dto.UserId;
import com.lwby.aas.util.BaseCallHelper;
import com.lwby.aas.vo.ClientInfo;
import com.lwby.aas.vo.DeliveryDeviceInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author songxinyu
* @version GdtActiveImpl.java, v 0.1 2024年02月26日 10:25 songxinyu Exp $
*/
@Service
@Slf4j
public class GdtActiveImpl extends BaseHelper implements IMediaActiveService {
@Resource
BaseCallHelper baseCallHelper;
public static final String ATTRIBUTE_EVENTTYPE = "ACTIVATE_APP";
@Override
public Integer androidActive(ClientInfo clientInfo, DeliveryDeviceInfo deliveryDeviceInfo) {
Integer resultCode = -1;
String result = "";
StringBuilder sb = new StringBuilder(deliveryDeviceInfo.getCallback_url());
long actionTime = System.currentTimeMillis() / 1000;
UserId ui = UserId.builder()
.ip(clientInfo.getClientIp())
.oaid(clientInfo.getOaid())
.hash_oaid(SecureUtil.md5(clientInfo.getOaid()))
.hash_imei(clientInfo.getImei())
.hash_android_id(clientInfo.getAndroidid())
.user_agent(clientInfo.getUa())
.build();
Action action = Action.builder().action_time(actionTime)
.user_id(ui)
.action_type(ATTRIBUTE_EVENTTYPE).build();
List actions = new ArrayList();
actions.add(action);
GdtAttributeRequest dto = GdtAttributeRequest.builder()
.actions(actions)
.build();
String userAction = JSONObject.toJSONString(dto);
try {
result = HttpUtil.post(sb.toString(), userAction);
resultCode = (Integer) JSON.parseObject(result).get("code");
if(resultCode == 0){
baseCallHelper.summaryByUserChannel(clientInfo, CallEnum.ACTIVE_CALLBACK.getValue(), deliveryDeviceInfo);
log.info("GdtActiveImpl.androidActive : {}",JSONObject.toJSONString(deliveryDeviceInfo));
String dateStr = DATE_BOTTOM_FORMAT.format(new Date());
String isActiveOneByTodayKey = String.format("v_dec_%d_%d_%d_%s",clientInfo.getDID(),clientInfo.getPlatformId(),deliveryDeviceInfo.getMedia(),dateStr);
//按天激活过一次,就不在上报
set(isActiveOneByTodayKey, 60 * 60 * 24 ,1);
}
} catch (Exception e) {
log.error("GdtActiveImpl.androidActivefive callback_param :{},userAction :{},result :{}" , deliveryDeviceInfo.getCallback_param(),JSONObject.toJSONString(userAction),result,e);
}
return null;
}
@Override
public Integer iosActive(ClientInfo clientInfo, DeliveryDeviceInfo deliveryDeviceInfo) {
return null;
}
@Override
public MediaEnum getMediaEnum() {
return MediaEnum.GDT;
}
}
package com.lwby.aas.service.impl.gdt.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Action {
private Long action_time;
private UserId user_id;
private String action_type;
}
package com.lwby.aas.service.impl.gdt.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class GdtAttributeRequest {
private List<Action> actions;
}
package com.lwby.aas.service.impl.gdt.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserId {
private String hash_imei;
private String oaid;
private String hash_oaid;
private String hash_android_id;
private String ip;
private String user_agent;
}
package com.lwby.aas.service.impl.jrtt;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lwby.aas.enums.CallEnum;
import com.lwby.aas.enums.MediaEnum;
import com.lwby.aas.handle.BaseHelper;
import com.lwby.aas.service.IMediaActiveService;
import com.lwby.aas.service.impl.jrtt.dto.JrttAttributeRequest;
import com.lwby.aas.util.BaseCallHelper;
import com.lwby.aas.vo.ClientInfo;
import com.lwby.aas.vo.DeliveryDeviceInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
/**
* @author songxinyu
* @version JrttActiveImpl.java, v 0.1 2024年02月23日 16:42 songxinyu Exp $
*/
@Service
@Slf4j
public class JrttActiveImpl extends BaseHelper implements IMediaActiveService {
public static final String ATTRIBUTE_URL = "https://analytics.oceanengine.com/api/v2/conversion";
public static final String ATTRIBUTE_EVENTTYPE = "active";
@Resource
BaseCallHelper baseCallHelper;
@Override
public Integer androidActive(ClientInfo clientInfo, DeliveryDeviceInfo deliveryDeviceInfo) {
Integer resultCode = -1;
String result = "";
StringBuilder sb = new StringBuilder(ATTRIBUTE_URL);
JrttAttributeRequest.Device device = new JrttAttributeRequest.Device();
device.setPlatform("android");
device.setImei(clientInfo.getImei());
device.setOaid(clientInfo.getOaid());
JrttAttributeRequest.Ad ad = new JrttAttributeRequest.Ad();
ad.setCallback(deliveryDeviceInfo.getCallback_param());
JrttAttributeRequest.Context context = new JrttAttributeRequest.Context();
context.setAd(ad);
context.setDevice(device);
JrttAttributeRequest request = JrttAttributeRequest.builder().context(context).event_type(ATTRIBUTE_EVENTTYPE).timestamp(
System.currentTimeMillis()).build();
String userJson = JSONObject.toJSONString(request);
try {
result = HttpUtil.post(sb.toString(), userJson);
resultCode = (Integer) JSON.parseObject(result).get("code");
log.info("JrttActiveImpl.androidActivefive callback_param :{},userJson :{},result :{}" , deliveryDeviceInfo.getCallback_param(),userJson,result);
if(resultCode == 0){
baseCallHelper.summaryByUserChannel(clientInfo, CallEnum.ACTIVE_CALLBACK.getValue(), deliveryDeviceInfo);
log.info("JrttActiveImpl.androidActive : {}",JSONObject.toJSONString(deliveryDeviceInfo));
String dateStr = DATE_BOTTOM_FORMAT.format(new Date());
String isActiveOneByTodayKey = String.format("v_dec_%d_%d_%d_%s",clientInfo.getDID(),clientInfo.getPlatformId(),deliveryDeviceInfo.getMedia(),dateStr);
//按天激活过一次,就不在上报
set(isActiveOneByTodayKey, 60 * 60 * 24 ,1);
}
} catch (Exception e) {
log.error("JrttActiveImpl.androidActivefive callback_param :{},userJson :{},result :{}" , deliveryDeviceInfo.getCallback_param(),JSONObject.toJSONString(userJson),result,e);
}
return resultCode;
}
@Override
public Integer iosActive(ClientInfo clientInfo, DeliveryDeviceInfo deliveryDeviceInfo) {
return -1;
}
@Override
public MediaEnum getMediaEnum() {
return MediaEnum.TOU_TIAO;
}
}
package com.lwby.aas.service.impl.jrtt.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author songxinyu
* @version JrttAttributeRequest.java, v 0.1 2024年02月23日 17:05 songxinyu Exp $
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class JrttAttributeRequest {
/**
* {
* "event_type": "active",
* "context": {
* "ad": {
* "callback": "EPHk9cX3pv4CGJax4ZENKI7w4MDev_4C",
* }
* },
* "timestamp": 1604888786102
* }
*/
/**
* 回传的事件,例如”激活“、”付费“
*/
private String event_type;
/**
* 包含一些关键的上下文信息
*/
private Context context;
/**
* 事件发生的毫秒级时间戳
*/
private long timestamp;
@Data
public static class Context {
/**
* 包含一些关键的广告相关信息
*/
private Ad ad;
private Device device;
}
@Data
public static class Ad {
/**
* callback 字段有两个获取途径,对于监测链接归因的方式,需要从监测链接的__CALLBACK_PARAM__这个宏获取这个字段值;
*/
private String callback;
}
@Data
public static class Device {
/**
* 设备平台
*/
private String platform;
private String imei;
private String oaid;
private String idfa;
}
}
package com.lwby.aas.util;
/**
* @author songxinyu
* @version BaseCache.java, v 0.1 2024年02月22日 18:53 songxinyu Exp $
*/
public class BaseCacheUtils {
public static String buildKey(String prefix, Object... keys) {
StringBuilder sb = new StringBuilder();
sb.append(prefix);
for (Object key : keys) {
sb.append(":");
sb.append(key);
}
return sb.toString();
}
}
package com.lwby.aas.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lwby.aas.enums.StoreEnum;
import com.lwby.aas.handle.BaseHelper;
import com.lwby.aas.vo.ClientInfo;
import com.lwby.aas.vo.DeliveryDeviceInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.FailureCallback;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.SuccessCallback;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
/**
* @author songxinyu
* @version BaseCallHelper.java, v 0.1 2024年02月23日 11:04 songxinyu Exp $
*/
@Slf4j
@Component
public class BaseCallHelper extends BaseHelper {
@Resource
RedisTemplate redisTemplate;
@Resource
private KafkaTemplate<String, String> kafkaTemplate;
public void callbackToStore(ClientInfo clientInfo, Integer type) {
String deviceId = clientInfo.getDID();
Integer platformId = clientInfo.getPlatformId();
//商店用户是否在该平台近30天访问的用户,是,不发给BI消息,否,发给BI消息
String aliveDeviceKey = BaseCacheUtils.buildKey("market:activeness", 30, platformId, deviceId);
if (!redisTemplate.hasKey(aliveDeviceKey)) {
//发送给BI消息
summaryByUserChannel(clientInfo, type,null);
if (log.isInfoEnabled()) {
log.info(
"deliveryDeviceInfo is null, send message, deviceId={}, platformId={}, aliveDeviceKey={}",
deviceId, platformId,aliveDeviceKey);
}
} else {
//不发送给BI消息
if (log.isInfoEnabled()) {
log.info(
"deliveryDeviceInfo is null, no send message, deviceId={}, platformId={}, aliveDeviceKey={}",
deviceId, platformId,aliveDeviceKey);
}
}
}
/**
* 根据用户注册渠道归因
* @param clientInfo
* @param type 区分不回传和从商店发大数据消息标识
*/
public void summaryByUserChannel(ClientInfo clientInfo, Integer type, DeliveryDeviceInfo deliveryDeviceInfo) {
Integer channel = clientInfo.getChannel();
String channelStr = String.valueOf(channel);
String channelPrefix = channelStr.substring(0, 2);
final String media = StoreEnum.getStoreDescByChannelPre(channelPrefix);
String device_id = clientInfo.getDID();
String prizeAssembleKey = "c:ouser:";
if (deliveryDeviceInfo == null) {
//商店的
deliveryDeviceInfo = new DeliveryDeviceInfo();
deliveryDeviceInfo.setOs(clientInfo.getOs());
//type如果为2,代表扣量,设置返回BI is_call字段为4,否则还是设置返回BI is_call字段为3
deliveryDeviceInfo.setIs_call(type);
deliveryDeviceInfo.setDevice_id(device_id);
deliveryDeviceInfo.setMedia(media);
deliveryDeviceInfo.setAd_plan_id("0");
deliveryDeviceInfo.setAd_group_id("0");
deliveryDeviceInfo.setAd_creative_id("0");
deliveryDeviceInfo.setActive_time(System.currentTimeMillis());
deliveryDeviceInfo.setChannel(String.valueOf(clientInfo.getChannel()));
deliveryDeviceInfo.setPlatform_id(String.valueOf(clientInfo.getPlatformId()));
//deliveryDeviceInfo.setOcpc_device_id(matchDeviceId);
//deliveryDeviceInfo.setOcpc_device_id_type(deviceIdType);
deliveryDeviceInfo.setDj_channel(channelStr);
//deliveryDeviceInfo.setEncryption_type(encryptType);
if (clientInfo.getUser() == null) {
log.error("BaseCallHelper.summaryMediaBySource store clientInfo.getUser() is null : {}", JSONObject.toJSONString(clientInfo));
} else {
deliveryDeviceInfo.setUserId(clientInfo.getUser().getId());
if (exists(prizeAssembleKey.concat(String.valueOf(clientInfo.getUser().getId())))) {
deliveryDeviceInfo.setDevice_status(2);
log.info("BaseCallHelper is set status,clinetinfo={}, deliveryDeviceInfo={}",JSONObject.toJSONString(clientInfo), JSON.toJSONString(deliveryDeviceInfo));
} else {
deliveryDeviceInfo.setDevice_status(0);
log.info("BaseCallHelper is not set status,clinetinfo={}, deliveryDeviceInfo={}",JSONObject.toJSONString(clientInfo), JSON.toJSONString(deliveryDeviceInfo));
}
}
} else {
//三个不回传条件的,扣量的
//deliveryDeviceInfo.setOcpc_device_id(matchDeviceId);
//deliveryDeviceInfo.setOcpc_device_id_type(deviceIdType);
//deliveryDeviceInfo.setEncryption_type(encryptType);
deliveryDeviceInfo.setOs(clientInfo.getOs());
deliveryDeviceInfo.setIs_call(type);
deliveryDeviceInfo.setDevice_id(device_id);
deliveryDeviceInfo.setActive_time(System.currentTimeMillis());
deliveryDeviceInfo.setChannel(String.valueOf(clientInfo.getChannel()));
deliveryDeviceInfo.setUserId(clientInfo.getUser().getId());
if (clientInfo.getUser() == null) {
log.error("BaseCallHelper.summaryMediaBySource clientInfo.getUser() is null : {}", JSONObject.toJSONString(clientInfo));
} else {
deliveryDeviceInfo.setUserId(clientInfo.getUser().getId());
if (exists(prizeAssembleKey.concat(String.valueOf(clientInfo.getUser().getId())))) {
deliveryDeviceInfo.setDevice_status(2);
log.info("BaseCallHelper.dedu is set status,clinetinfo={}, deliveryDeviceInfo={}",JSONObject.toJSONString(clientInfo), JSON.toJSONString(deliveryDeviceInfo));
} else {
deliveryDeviceInfo.setDevice_status(0);
log.info("BaseCallHelper.dedu is not set status,clinetinfo={}, deliveryDeviceInfo={}",JSONObject.toJSONString(clientInfo), JSON.toJSONString(deliveryDeviceInfo));
}
}
}
ListenableFuture active_result = kafkaTemplate.send("ocpc_result", JSONObject.toJSONString(deliveryDeviceInfo));
active_result.addCallback(new SuccessCallback() {
@Override
public void onSuccess(Object o) {
log.info("BaseCallHelper.summaryByUserChannel done,sendKafkaMessageType:{},归因 成功 :{} " ,type,o);
}
}, new FailureCallback() {
@Override
public void onFailure(Throwable throwable) {
log.info("BaseCallHelper.summaryByUserChannel done,sendKafkaMessageType:{},归因出错,业务回滚或补偿 :{} " ,type,throwable);
}
});
log.info("BaseCallHelper.summaryByUserChannel done,store_access: device_id:{},channel:{},sendKafkaMessageType:{}",device_id,channel,type);
}
}
spring:
# datasource:
# dmp:
# jdbc-url: jdbc:oceanbase://t4k45ch7fuiw0.oceanbase.aliyuncs.com:3306/dmp?zeroDateTimeBehavior=round&characterEncoding=utf8&serverTimezone=Asia/Shanghai&autoReconnect=true
# username: dmp
# password: Lwby@123!@#
# driver-class-name: com.alipay.oceanbase.jdbc.Driver
# initialSize: 2
# minIdle: 2
# dmpadmin:
# jdbc-url: jdbc:mysql://rm-2zeo09186ukqa8zh1.mysql.rds.aliyuncs.com:3306/lwby-admin
# username: lwby
# password: VjxYfmY8J77ISChp
# driver-class-name: com.mysql.cj.jdbc.Driver
# initialSize: 2
# minIdle: 2
# redis:
# host: 127.0.0.1
# port: 6379
datasource:
lwby:
jdbc-url: jdbc:mysql://rm-2zeo09186ukqa8zh1.mysql.rds.aliyuncs.com/lwby?zeroDateTimeBehavior=convertToNull&characterEncoding=utf8&autoReconnect=true
username: lwby
password: VjxYfmY8J77ISChp
driver-class-name: com.mysql.cj.jdbc.Driver
initialSize: 2
minIdle: 2
marketing:
jdbc-url: jdbc:mysql://rm-2zeo09186ukqa8zh1.mysql.rds.aliyuncs.com/lwby?zeroDateTimeBehavior=convertToNull&characterEncoding=utf8&autoReconnect=true
username: lwby
password: VjxYfmY8J77ISChp
driver-class-name: com.mysql.cj.jdbc.Driver
initialSize: 2
minIdle: 2
redis:
host: 172.17.243.150
port: 6379
kafka:
bootstrap-servers: 172.17.243.58:9092,172.17.243.59:9092,172.17.243.60:9092,172.17.243.61:9092,172.17.243.62:9092
bootstrap-servers: 172.17.255.143:9092
producer:
retries: 3
acks: 1
......
......@@ -11,7 +11,7 @@ spring:
application:
name: ssa
profiles:
active: prod
active: test
#prometheus监控平台配置
management:
......
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