|
@@ -2,16 +2,14 @@ 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.mybatis.entity.Agent;
|
|
|
import com.zanxiang.game.module.mybatis.entity.User;
|
|
|
import com.zanxiang.game.module.mybatis.entity.UserLoginLog;
|
|
|
import com.zanxiang.game.module.mybatis.mapper.AgentMapper;
|
|
|
-import com.zanxiang.game.module.sdk.service.IAgentService;
|
|
|
-import com.zanxiang.game.module.sdk.service.ICallBackService;
|
|
|
-import com.zanxiang.game.module.sdk.service.IUserLoginLogService;
|
|
|
-import com.zanxiang.game.module.sdk.service.IUserService;
|
|
|
+import com.zanxiang.game.module.sdk.service.*;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
@@ -42,41 +40,51 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
|
@Autowired
|
|
|
private ICallBackService callBackService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserAgentLogService userAgentLogService;
|
|
|
+
|
|
|
@Override
|
|
|
public void userAgentUpdate(User user, String channel) {
|
|
|
log.error("用户登录接收到的渠道参数 userId : {}, channel : {}", user.getId(), channel);
|
|
|
- //渠道参数为空
|
|
|
- if (Strings.isBlank(channel)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- //判断用户是否超过30天未登录
|
|
|
- List<UserLoginLog> userLoginLogList = userLoginLogService.list(new LambdaQueryWrapper<UserLoginLog>()
|
|
|
- .eq(UserLoginLog::getUserId, user.getId())
|
|
|
- .orderByDesc(UserLoginLog::getCreateTime)
|
|
|
- .last("limit 1"));
|
|
|
- if (CollectionUtils.isEmpty(userLoginLogList)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- //最近登录时间
|
|
|
- LocalDateTime lastLoginTime = userLoginLogList.get(0).getCreateTime();
|
|
|
- //最近登录未超过30天
|
|
|
- if (lastLoginTime.plusDays(30L).isAfter(LocalDateTime.now())) {
|
|
|
- return;
|
|
|
- }
|
|
|
- //30天未登录, 更新渠道
|
|
|
- Map<String, String> urlParamMap = this.channelTransform(channel);
|
|
|
- //查询渠道
|
|
|
- Agent agent = this.getAgentByKey(urlParamMap);
|
|
|
- if (agent == null) {
|
|
|
- return;
|
|
|
+ try {
|
|
|
+ //渠道参数为空
|
|
|
+ if (Strings.isBlank(channel)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //判断用户是否超过30天未登录
|
|
|
+ List<UserLoginLog> userLoginLogList = userLoginLogService.list(new LambdaQueryWrapper<UserLoginLog>()
|
|
|
+ .eq(UserLoginLog::getUserId, user.getId())
|
|
|
+ .orderByDesc(UserLoginLog::getCreateTime)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (CollectionUtils.isEmpty(userLoginLogList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //最近登录时间
|
|
|
+ LocalDateTime lastLoginTime = userLoginLogList.get(0).getCreateTime();
|
|
|
+ //最近登录未超过30天
|
|
|
+ if (lastLoginTime.plusDays(30L).isAfter(LocalDateTime.now())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //30天未登录, 更新渠道
|
|
|
+ Map<String, String> urlParamMap = this.channelTransform(channel);
|
|
|
+ //查询渠道
|
|
|
+ Agent agent = this.getAgentByKey(urlParamMap);
|
|
|
+ if (agent == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //更新用户信息
|
|
|
+ userService.update(new LambdaUpdateWrapper<User>()
|
|
|
+ .set(User::getAgentId, agent.getId())
|
|
|
+ .set(User::getChannel, channel)
|
|
|
+ .set(User::getUpdateTime, LocalDateTime.now())
|
|
|
+ .eq(User::getId, user.getId()));
|
|
|
+ //添加渠道变更记录
|
|
|
+ userAgentLogService.agentUpdateLog(user, agent.getId(), channel);
|
|
|
+ //回传用户信息
|
|
|
+ callBackService.userCallBack(user, urlParamMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("用户渠道更新异常, userId : {}, channel : {}, e : {}", user.getId(), channel, e.getMessage());
|
|
|
}
|
|
|
- //更新用户信息
|
|
|
- user.setAgentId(agent.getId());
|
|
|
- user.setChannel(channel);
|
|
|
- user.setUpdateTime(LocalDateTime.now());
|
|
|
- userService.updateById(user);
|
|
|
- //回传用户信息
|
|
|
- callBackService.userCallBack(user, urlParamMap);
|
|
|
}
|
|
|
|
|
|
@Override
|