|
@@ -54,6 +54,9 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
@Autowired
|
|
@Autowired
|
|
private IKafkaService kafkaService;
|
|
private IKafkaService kafkaService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserAppletService userAppletService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void userAgentUpdate(User user, String channel) {
|
|
public void userAgentUpdate(User user, String channel) {
|
|
log.error("用户登录接收到的渠道参数 userId : {}, channel : {}", user.getId(), channel);
|
|
log.error("用户登录接收到的渠道参数 userId : {}, channel : {}", user.getId(), channel);
|
|
@@ -108,23 +111,30 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
public Tuple3<Long, Map<String, String>, String> getUserAgentId(UserData userData) {
|
|
public Tuple3<Long, Map<String, String>, String> getUserAgentId(UserData userData) {
|
|
log.error("用户注册接收到的渠道参数 userData : {}", JsonUtil.toString(userData));
|
|
log.error("用户注册接收到的渠道参数 userData : {}", JsonUtil.toString(userData));
|
|
//获取游戏信息
|
|
//获取游戏信息
|
|
- GameExt gameExt = gameExtService.getByGameId(userData.getGameId());
|
|
|
|
Game game = gameService.getById(userData.getGameId());
|
|
Game game = gameService.getById(userData.getGameId());
|
|
- //不投放得APP游戏按ip和ua进行渠道匹配
|
|
|
|
- if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())
|
|
|
|
- && !Objects.equals(gameExt.getAdCallBackSwitch(), Boolean.TRUE)) {
|
|
|
|
- UserVisitLog userVisitLog = this.getUserVisitLog(userData);
|
|
|
|
- if (userVisitLog == null) {
|
|
|
|
- return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|
|
|
|
- }
|
|
|
|
- return Tuples.of(userVisitLog.getAgentId(), Collections.emptyMap(), Strings.EMPTY);
|
|
|
|
|
|
+ //微信小游戏解析
|
|
|
|
+ if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) {
|
|
|
|
+ return this.appletChannelTransform(userData.getChannel());
|
|
|
|
+ }
|
|
|
|
+ //APP解析
|
|
|
|
+ if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())) {
|
|
|
|
+ return this.appChannelTransform(game, userData);
|
|
|
|
+ }
|
|
|
|
+ //H5解析
|
|
|
|
+ if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_H5.getId())) {
|
|
|
|
+ return this.h5ChannelTransform(userData.getChannel());
|
|
}
|
|
}
|
|
|
|
+ //默认返回自然量
|
|
|
|
+ return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Tuple3<Long, Map<String, String>, String> appletChannelTransform(String channel) {
|
|
//链接参数
|
|
//链接参数
|
|
- if (Strings.isBlank(userData.getChannel())) {
|
|
|
|
|
|
+ if (Strings.isBlank(channel)) {
|
|
return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|
|
return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|
|
}
|
|
}
|
|
//数据解析
|
|
//数据解析
|
|
- Map<String, String> urlParamMap = this.channelTransform(userData.getChannel());
|
|
|
|
|
|
+ Map<String, String> urlParamMap = this.channelTransform(channel);
|
|
String shareUserId = urlParamMap.get("shareUserId");
|
|
String shareUserId = urlParamMap.get("shareUserId");
|
|
//查询渠道
|
|
//查询渠道
|
|
Agent agent = null;
|
|
Agent agent = null;
|
|
@@ -142,6 +152,48 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
return Tuples.of(agent.getId(), urlParamMap, Strings.isBlank(shareUserId) ? Strings.EMPTY : shareUserId);
|
|
return Tuples.of(agent.getId(), urlParamMap, Strings.isBlank(shareUserId) ? Strings.EMPTY : shareUserId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Tuple3<Long, Map<String, String>, String> appChannelTransform(Game game, UserData userData) {
|
|
|
|
+ //游戏拓展信息
|
|
|
|
+ GameExt gameExt = gameExtService.getByGameId(userData.getGameId());
|
|
|
|
+ //不投放, 不回传, 只归因渠道, -- 不投放, 且回传只存在于导量情况, 导量无注册行为
|
|
|
|
+ if (Objects.equals(game.getIsPut(), Boolean.FALSE) && Objects.equals(gameExt.getAdCallBackSwitch(), Boolean.FALSE)) {
|
|
|
|
+ //查询访问记录
|
|
|
|
+ UserVisitLog userVisitLog = this.getUserVisitLog(userData);
|
|
|
|
+ //返回渠道信息
|
|
|
|
+ return Tuples.of(userVisitLog == null ? 0L : userVisitLog.getAgentId(), Collections.emptyMap(), Strings.EMPTY);
|
|
|
|
+ }
|
|
|
|
+ //投放, 且回传 -- 投放, 且不回传这种情况不存在
|
|
|
|
+ if (Objects.equals(game.getIsPut(), Boolean.TRUE) && Objects.equals(gameExt.getAdCallBackSwitch(), Boolean.TRUE)) {
|
|
|
|
+ //查询访问记录
|
|
|
|
+ UserVisitLog userVisitLog = this.getUserVisitLog(userData);
|
|
|
|
+ if (userVisitLog == null) {
|
|
|
|
+ //未匹配到访问信息, 返回自然凉
|
|
|
|
+ return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|
|
|
|
+ }
|
|
|
|
+ //解析访问记录中得请求参数
|
|
|
|
+ Map<String, String> urlParamMap = this.channelTransform(userVisitLog.getChannel());
|
|
|
|
+ //查询渠道
|
|
|
|
+ Agent agent = this.getAgentByKey(urlParamMap);
|
|
|
|
+ //返回渠道信息
|
|
|
|
+ return Tuples.of(agent == null ? 0L : agent.getId(), urlParamMap, Strings.EMPTY);
|
|
|
|
+ }
|
|
|
|
+ //默认返回自然量
|
|
|
|
+ return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Tuple3<Long, Map<String, String>, String> h5ChannelTransform(String channel) {
|
|
|
|
+ //链接参数
|
|
|
|
+ if (Strings.isBlank(channel)) {
|
|
|
|
+ return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|
|
|
|
+ }
|
|
|
|
+ //数据解析
|
|
|
|
+ Map<String, String> urlParamMap = this.channelTransform(channel);
|
|
|
|
+ //查询渠道
|
|
|
|
+ Agent agent = this.getAgentByKey(urlParamMap);
|
|
|
|
+ //返回
|
|
|
|
+ return Tuples.of(agent == null ? 0L : agent.getId(), urlParamMap, Strings.EMPTY);
|
|
|
|
+ }
|
|
|
|
+
|
|
private UserVisitLog getUserVisitLog(UserData userData) {
|
|
private UserVisitLog getUserVisitLog(UserData userData) {
|
|
//当前时间
|
|
//当前时间
|
|
LocalDateTime regTime = LocalDateTime.now();
|
|
LocalDateTime regTime = LocalDateTime.now();
|
|
@@ -154,7 +206,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
// 1. 策略一 : 根据 ip + ua 精准匹配用户
|
|
// 1. 策略一 : 根据 ip + ua 精准匹配用户
|
|
userVisitLogList = userVisitLogService.list(new LambdaQueryWrapper<UserVisitLog>()
|
|
userVisitLogList = userVisitLogService.list(new LambdaQueryWrapper<UserVisitLog>()
|
|
.eq(UserVisitLog::getIp, userData.getIp())
|
|
.eq(UserVisitLog::getIp, userData.getIp())
|
|
- .eq(UserVisitLog::getUa, userData)
|
|
|
|
|
|
+ .eq(UserVisitLog::getUa, userData.getUa())
|
|
.le(UserVisitLog::getCreateTime, regTime));
|
|
.le(UserVisitLog::getCreateTime, regTime));
|
|
// 判断通过策略一是否拿到数据, 筛选出访问时间与注册时间最接近的
|
|
// 判断通过策略一是否拿到数据, 筛选出访问时间与注册时间最接近的
|
|
if (CollectionUtils.isNotEmpty(userVisitLogList)) {
|
|
if (CollectionUtils.isNotEmpty(userVisitLogList)) {
|
|
@@ -236,6 +288,28 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, String> channelTransform(String channel) {
|
|
public Map<String, String> channelTransform(String channel) {
|
|
|
|
+ if (Strings.isBlank(channel) || Strings.isBlank(channel.trim())) {
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
+ }
|
|
|
|
+ //渠道参数
|
|
|
|
+ Map<String, String> paramMap = this.channelToMap(channel);
|
|
|
|
+ //企业微信拼接字段名
|
|
|
|
+ String callState = "callState";
|
|
|
|
+ //判断是否包含转译参数
|
|
|
|
+ if (!paramMap.containsKey(callState)) {
|
|
|
|
+ return paramMap;
|
|
|
|
+ }
|
|
|
|
+ //小程序访问信息
|
|
|
|
+ UserApplet userApplet = userAppletService.getById(Integer.valueOf(paramMap.get(callState)));
|
|
|
|
+ if (userApplet != null && Strings.isNotBlank(userApplet.getChannel())) {
|
|
|
|
+ paramMap.putAll(this.channelToMap(userApplet.getChannel()));
|
|
|
|
+ paramMap.put("appId", userApplet.getAppId());
|
|
|
|
+ paramMap.put("openId", userApplet.getOpenId());
|
|
|
|
+ }
|
|
|
|
+ return paramMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Map<String, String> channelToMap(String channel) {
|
|
if (Strings.isBlank(channel) || Strings.isBlank(channel.trim())) {
|
|
if (Strings.isBlank(channel) || Strings.isBlank(channel.trim())) {
|
|
return Collections.emptyMap();
|
|
return Collections.emptyMap();
|
|
}
|
|
}
|