|
@@ -2,7 +2,6 @@ package com.zanxiang.game.module.sdk.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
|
|
@@ -58,9 +57,9 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
|
private IUserAppletService userAppletService;
|
|
|
|
|
|
@Override
|
|
|
- public void userAgentUpdate(User user, String channel) {
|
|
|
- log.error("用户登录接收到的渠道参数 userId : {}, channel : {}", user.getId(), channel);
|
|
|
+ public void userAgentUpdate(User user, UserData userData) {
|
|
|
try {
|
|
|
+ String channel = userData.getChannel();
|
|
|
//渠道参数为空
|
|
|
if (Strings.isBlank(channel)) {
|
|
|
return;
|
|
@@ -80,49 +79,54 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
|
return;
|
|
|
}
|
|
|
//30天未登录, 更新渠道
|
|
|
- Map<String, String> urlParamMap = this.channelTransform(channel);
|
|
|
+ Game game = gameService.getById(user.getGameId());
|
|
|
+ //渠道id, 链接参数, 分享人id
|
|
|
+ Tuple3<Long, Map<String, String>, String> tuple3 = this.getUserAgentId(game, userData);
|
|
|
//查询渠道
|
|
|
- Agent agent = this.getAgentByKey(urlParamMap);
|
|
|
+ Agent agent = super.getById(tuple3.getT1());
|
|
|
if (agent == null) {
|
|
|
return;
|
|
|
}
|
|
|
- LocalDateTime localDateTime = LocalDateTime.now();
|
|
|
//更新用户信息
|
|
|
- userService.update(new LambdaUpdateWrapper<User>()
|
|
|
- .set(User::getAgentId, agent.getId())
|
|
|
- .set(User::getChannel, channel)
|
|
|
- .set(User::getUpdateTime, localDateTime)
|
|
|
- .eq(User::getId, user.getId()));
|
|
|
+ user.setAgentId(agent.getId());
|
|
|
+ user.setUpdateTime(LocalDateTime.now());
|
|
|
+ //App的渠道保存解析后的参数, 因为涉及到时间判断
|
|
|
+ if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())) {
|
|
|
+ user.setChannel(JsonUtil.toString(tuple3.getT2()));
|
|
|
+ } else {
|
|
|
+ user.setChannel(channel);
|
|
|
+ }
|
|
|
+ userService.updateById(user);
|
|
|
//添加渠道变更记录
|
|
|
userAgentLogService.agentUpdateLog(user, agent.getId(), channel);
|
|
|
//回传用户信息
|
|
|
- user.setAgentId(agent.getId());
|
|
|
- user.setChannel(channel);
|
|
|
- user.setUpdateTime(localDateTime);
|
|
|
- callBackService.userCallBack(user, urlParamMap);
|
|
|
+ callBackService.userCallBack(user, tuple3.getT2());
|
|
|
//注册信息埋点数据发送到卡夫卡
|
|
|
kafkaService.eventTrack(KafkaEventTrackEnum.KAFKA_EVENT_TRACK_AGENT_UPDATE, JsonUtil.toString(user));
|
|
|
} catch (Exception e) {
|
|
|
- log.error("用户渠道更新异常, userId : {}, channel : {}, e : {}", user.getId(), channel, e.getMessage());
|
|
|
+ log.error("用户渠道更新异常, user : {}, userData : {}, e : {}", JsonUtil.toString(user),
|
|
|
+ JsonUtil.toString(userData), e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Tuple3<Long, Map<String, String>, String> getUserAgentId(UserData userData) {
|
|
|
- log.error("用户注册接收到的渠道参数 userData : {}", JsonUtil.toString(userData));
|
|
|
- //获取游戏信息
|
|
|
- Game game = gameService.getById(userData.getGameId());
|
|
|
- //微信小游戏解析
|
|
|
- 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());
|
|
|
+ public Tuple3<Long, Map<String, String>, String> getUserAgentId(Game game, UserData userData) {
|
|
|
+ try {
|
|
|
+ //微信小游戏解析
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("用户渠道解析异常, game : {}, userData : {}, e : {}", JsonUtil.toString(game),
|
|
|
+ JsonUtil.toString(userData), e.getMessage(), e);
|
|
|
}
|
|
|
//默认返回自然量
|
|
|
return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|