浏览代码

Merge branch 'dev' of GameCenter/game-center into master

zhimo 1 年之前
父节点
当前提交
917802f23c

+ 6 - 0
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/pojo/dto/RoleCombatRankingDTO.java

@@ -57,6 +57,12 @@ public class RoleCombatRankingDTO extends BasePage {
     @ApiModelProperty(value = "是否合服:true -> 合服 ; false -> 不合服")
     private Boolean isMergeServer;
 
+    /**
+     * 区服名称
+     */
+    @ApiModelProperty(value = "区服名称")
+    private String serverName;
+
     /**
      * 排序字段
      */

+ 82 - 6
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/RoleManageServiceImpl.java

@@ -196,7 +196,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
      */
     private Map<String, Object> getNameById(Map<String, Object> dataMap){
 
-        /*//投手名
+        //投手名
         if (dataMap.get("put_user_id") != null) {
             dataMap.put("put_user_name",
                     sysUserRpc.getById(Long.valueOf((String) dataMap.get("put_user_id"))).getData().getNickname());
@@ -215,7 +215,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
         if (dataMap.get("customer_service_id") != null) {
             dataMap.put("customer_service_name",
                     sysUserRpc.getById((Long) dataMap.get("customer_service_id")).getData().getNickname());
-        }*/
+        }
 
         return dataMap;
     }
@@ -240,6 +240,10 @@ public class RoleManageServiceImpl implements IRoleManageService {
             //原始区服列表
             cri.where().andIn("server_id", dto.getServerIds().toArray(String[]::new));
         }
+        if (StringUtils.isNotBlank(dto.getServerName())) {
+            //区服名称
+            cri.where().andLike("server_name", dto.getServerName());
+        }
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {
             cri.where().andEquals("source_system", dto.getSourceSystem());
         }
@@ -284,6 +288,10 @@ public class RoleManageServiceImpl implements IRoleManageService {
             //原始服区服列表
             criRole.where().andIn("server_id", dto.getServerIds().toArray(String[]::new));
         }
+        if (StringUtils.isNotBlank(dto.getServerName())) {
+            //区服名称
+            cri.where().andLike("server_name", dto.getServerName());
+        }
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {
             criRole.where().andEquals("source_system", dto.getSourceSystem());
         }
@@ -361,6 +369,14 @@ public class RoleManageServiceImpl implements IRoleManageService {
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {
             cri.where().andEquals("source_system", dto.getSourceSystem());
         }
+        if (StringUtils.isNotBlank(dto.getServerName())) {
+            //区服名称
+            cri.where().andLike("boss_server_name", dto.getServerName());
+        }
+        if (CollectionUtils.isEmpty(dto.getServerIds()) && StringUtils.isBlank(dto.getServerName())) {
+            //默认不传查询的区服,只看最新的合服数据
+            cri.where().andEquals("is_merge", 0);
+        }
         //拼接分组条件
         cri.getGroupBy().groupBy("source_system" , "boss_server_id" , "parent_game_id" , "super_game_id");
         //分页
@@ -401,6 +417,10 @@ public class RoleManageServiceImpl implements IRoleManageService {
             //合服区服列表
             criRole.where().andIn("boss_server_id", dto.getServerIds().toArray(String[]::new));
         }
+        if (StringUtils.isNotBlank(dto.getServerName())) {
+            //区服名称
+            cri.where().andLike("boss_server_name", dto.getServerName());
+        }
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {
             criRole.where().andEquals("source_system", dto.getSourceSystem());
         }
@@ -478,6 +498,10 @@ public class RoleManageServiceImpl implements IRoleManageService {
             //原始区服列表
             cri.where().andIn("server_id", dto.getServerIds().toArray(String[]::new));
         }
+        if (StringUtils.isNotBlank(dto.getServerName())) {
+            //区服名称
+            cri.where().andLike("server_name", dto.getServerName());
+        }
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {
             cri.where().andEquals("source_system", dto.getSourceSystem());
         }
@@ -522,6 +546,10 @@ public class RoleManageServiceImpl implements IRoleManageService {
             //原始服区服列表
             criRole.where().andIn("server_id", dto.getServerIds().toArray(String[]::new));
         }
+        if (StringUtils.isNotBlank(dto.getServerName())) {
+            //区服名称
+            cri.where().andLike("server_name", dto.getServerName());
+        }
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {
             criRole.where().andEquals("source_system", dto.getSourceSystem());
         }
@@ -595,6 +623,14 @@ public class RoleManageServiceImpl implements IRoleManageService {
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {
             cri.where().andEquals("source_system", dto.getSourceSystem());
         }
+        if (StringUtils.isNotBlank(dto.getServerName())) {
+            //区服名称
+            cri.where().andLike("boss_server_name", dto.getServerName());
+        }
+        if (CollectionUtils.isEmpty(dto.getServerIds()) && StringUtils.isBlank(dto.getServerName())) {
+            //默认不传查询的区服,只看最新的合服数据
+            cri.where().andEquals("is_merge", 0);
+        }
         //拼接分组条件
         cri.getGroupBy().groupBy("source_system" , "boss_server_id" , "super_game_id");
         //分页
@@ -635,6 +671,10 @@ public class RoleManageServiceImpl implements IRoleManageService {
             //合服区服列表
             criRole.where().andIn("boss_server_id", dto.getServerIds().toArray(String[]::new));
         }
+        if (StringUtils.isNotBlank(dto.getServerName())) {
+            //区服名称
+            cri.where().andLike("boss_server_name", dto.getServerName());
+        }
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {
             criRole.where().andEquals("source_system", dto.getSourceSystem());
         }
@@ -1038,10 +1078,9 @@ public class RoleManageServiceImpl implements IRoleManageService {
                             -- 礼包名
                             source_system,
                             id,
-                            game_id,
                             gift_name
                         FROM dm_game_order.t_game_gift
-                    ) k on j.source_system = k.source_system AND j.send_gift_id = k.id AND j.game_id = k.game_id
+                    ) k on j.source_system = k.source_system AND j.send_gift_id = k.id
                     LEFT JOIN (
                         SELECT
                             source_system ,
@@ -1399,10 +1438,9 @@ public class RoleManageServiceImpl implements IRoleManageService {
                                -- 礼包名
                                source_system,
                                id,
-                               game_id,
                                gift_name
                            FROM dm_game_order.t_game_gift
-                       ) k on j.source_system = k.source_system AND j.send_gift_id = k.id AND j.game_id = k.game_id
+                       ) k on j.source_system = k.source_system AND j.send_gift_id = k.id
                        LEFT JOIN (
                            SELECT
                                source_system ,
@@ -1514,6 +1552,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
                     	server_id, -- 区服ID
                     	MAX(server_name) as server_name, -- 区服名
                     	MAX(dt) as dt, -- 开服时间
+                    	TIMESTAMPDIFF(DAY, MAX(dt), NOW()) start_day, -- 开服天数
                     	boss_server_id, -- 合服ID
                     	MAX(boss_server_name) as boss_server_name, -- 合服名
                     	MAX(merge_time) as merge_time , -- 合服时间
@@ -1600,6 +1639,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
                 	MAX(merge_time) as merge_time , -- 合服时间
                 	TIMESTAMPDIFF(DAY, MAX(merge_time), NOW()) start_day, -- 开服天数
                 	MAX(sum_server_count) as sum_server_count, -- 合服次数
+                	MAX(c.is_merge) as is_merge, -- 是否参与过合服
                 	MAX(b.main_server_id) as main_server_id, -- 主服ID
                 	MAX(b.main_server_name) as main_server_name, -- 主服名
                 	MAX(son_server_ids) as son_server_ids, -- 合服的子服ID列表
@@ -1686,6 +1726,14 @@ public class RoleManageServiceImpl implements IRoleManageService {
                 	) c on a.source_system = c.source_system AND a.game_id = c.game_id AND a.main_server_id = c.server_id
                 	group by a.server_id , a.source_system , a.game_id
                 ) b ON a.source_system = b.b_source_system AND a.super_game_id = b.b_game_id AND a.boss_server_id = b.b_server_id
+                LEFT JOIN (
+                	SELECT
+                		source_system as c_source_system,
+                		game_id,
+                		server_id,
+                		is_merge
+                	FROM dm_game_order.t_game_server_merge
+                ) c on a.source_system = c.c_source_system AND a.boss_server_id = c.server_id AND a.super_game_id = c.game_id
                 """;
     }
 
@@ -1710,6 +1758,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
                     	MAX(merge_time) as merge_time , -- 合服时间
                     	TIMESTAMPDIFF(DAY, MAX(merge_time), NOW()) start_day, -- 开服天数
                     	MAX(sum_server_count) as sum_server_count, -- 合服次数
+                    	MAX(c.is_merge) as is_merge, -- 是否参与过合服
                     	MAX(b.main_server_id) as main_server_id, -- 主服ID
                     	MAX(b.main_server_name) as main_server_name, -- 主服名
                     	MAX(son_server_ids) as son_server_ids, -- 合服的子服ID列表
@@ -1796,6 +1845,14 @@ public class RoleManageServiceImpl implements IRoleManageService {
                     	) c on a.source_system = c.source_system AND a.game_id = c.game_id AND a.main_server_id = c.server_id
                     	group by a.server_id , a.source_system , a.game_id
                     ) b ON a.source_system = b.b_source_system AND a.super_game_id = b.b_game_id AND a.boss_server_id = b.b_server_id
+                    LEFT JOIN (
+                    	SELECT
+                    		source_system as c_source_system,
+                    		game_id,
+                    		server_id,
+                    		is_merge
+                    	FROM dm_game_order.t_game_server_merge
+                    ) c on a.source_system = c.c_source_system AND a.boss_server_id = c.server_id AND a.super_game_id = c.game_id
                 """ + cri +
                 """
                 ) a
@@ -1816,6 +1873,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
                 	server_id, -- 区服ID
                 	MAX(server_name) as server_name, -- 区服名
                 	MAX(dt) as dt, -- 开服日期
+                	TIMESTAMPDIFF(DAY, MAX(dt), NOW()) start_day, -- 开服天数
                 	boss_server_id, -- 合服ID
                 	MAX(boss_server_name) as boss_server_name, -- 合服名
                 	MAX(merge_time) as merge_time , -- 合服时间
@@ -2050,6 +2108,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
                 	MAX(merge_time) as merge_time , -- 合服时间
                 	TIMESTAMPDIFF(DAY, MAX(merge_time), NOW()) start_day, -- 开服天数
                 	MAX(sum_server_count) as sum_server_count, -- 合服次数
+                	MAX(c.is_merge) as is_merge, -- 是否参与过合服
                 	MAX(b.main_server_id) as main_server_id, -- 主服ID
                 	MAX(b.main_server_name) as main_server_name, -- 主服名
                 	MAX(son_server_ids) as son_server_ids, -- 合服的子服ID列表
@@ -2200,6 +2259,14 @@ public class RoleManageServiceImpl implements IRoleManageService {
                 	) c on a.source_system = c.source_system AND a.game_id = c.game_id AND a.main_server_id = c.server_id
                 	group by a.server_id , a.source_system , a.game_id
                 ) b ON a.source_system = b.b_source_system AND a.super_game_id = b.b_game_id AND a.boss_server_id = b.b_server_id
+                LEFT JOIN (
+                	SELECT
+                		source_system as c_source_system,
+                		game_id,
+                		server_id,
+                		is_merge
+                	FROM dm_game_order.t_game_server_merge
+                ) c on a.source_system = c.c_source_system AND a.boss_server_id = c.server_id AND a.super_game_id = c.game_id
                 """;
     }
 
@@ -2222,6 +2289,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
                     	MAX(merge_time) as merge_time , -- 合服时间
                     	TIMESTAMPDIFF(DAY, MAX(merge_time), NOW()) start_day, -- 开服天数
                     	MAX(sum_server_count) as sum_server_count, -- 合服次数
+                    	MAX(c.is_merge) as is_merge, -- 是否参与过合服
                     	MAX(b.main_server_id) as main_server_id, -- 主服ID
                     	MAX(b.main_server_name) as main_server_name, -- 主服名
                     	MAX(son_server_ids) as son_server_ids, -- 合服的子服ID列表
@@ -2372,6 +2440,14 @@ public class RoleManageServiceImpl implements IRoleManageService {
                     	) c on a.source_system = c.source_system AND a.game_id = c.game_id AND a.main_server_id = c.server_id
                     	group by a.server_id , a.source_system , a.game_id
                     ) b ON a.source_system = b.b_source_system AND a.super_game_id = b.b_game_id AND a.boss_server_id = b.b_server_id
+                    LEFT JOIN (
+                    	SELECT
+                    		source_system as c_source_system,
+                    		game_id,
+                    		server_id,
+                    		is_merge
+                    	FROM dm_game_order.t_game_server_merge
+                    ) c on a.source_system = c.c_source_system AND a.boss_server_id = c.server_id AND a.super_game_id = c.game_id
                 """ + cri +
                 """
                 ) a

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <解决微信和支付宝支付逻辑中的高并发引起的全局变量bug> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <用户注册加线程锁, token活跃更新> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 5 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/constant/RedisKeyConstant.java

@@ -47,4 +47,9 @@ public class RedisKeyConstant {
      */
     public static final String ORDER_EXPIRE_LOCK = RedisKeyConstant.REDIS_PREFIX + "order_expire_lock_";
 
+    /**
+     * 用户注册
+     */
+    public static final String USER_CREATE = RedisKeyConstant.REDIS_PREFIX + "user_create";
+
 }

+ 7 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IUserTokenService.java

@@ -24,6 +24,13 @@ public interface IUserTokenService extends IService<UserToken> {
      */
     ResultVO<Long> cpTokenCheck(String appId, Long userId, String token, String sign);
 
+    /**
+     * 用户活跃token更新
+     *
+     * @param userData 用户数据
+     */
+    void userTokenUpdateCheck(UserData userData);
+
     /**
      * 用户令牌到期时间检查
      *

+ 10 - 6
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameUserRoleServiceImpl.java

@@ -14,10 +14,7 @@ import com.zanxiang.game.module.sdk.enums.LoginTypeEnum;
 import com.zanxiang.game.module.sdk.pojo.param.GameRoleActiveCallParam;
 import com.zanxiang.game.module.sdk.pojo.param.GameUserRoleUpdateParam;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
-import com.zanxiang.game.module.sdk.service.IGameUserRoleService;
-import com.zanxiang.game.module.sdk.service.IGameUserService;
-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.redis.service.IDistributedLockComponent;
 import com.zanxiang.module.util.DateUtil;
 import com.zanxiang.module.util.JsonUtil;
@@ -58,6 +55,9 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
     @Autowired
     private IDistributedLockComponent distributedLockComponent;
 
+    @Autowired
+    private IUserTokenService userTokenService;
+
     @Value("${spring.kafka.game-sdk.gameRoleActiveTopic}")
     private String gameRoleActiveTopic;
 
@@ -241,8 +241,12 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
 
     @Override
     public boolean gameRoleActiveCall(UserData userData, GameRoleActiveCallParam param) {
-        log.error("接收到前端用户角色活跃上报, userId : {}, gameId : {}, serverId : {}, roleId : {}, roleLevel : {}",
-                userData.getUserId(), userData.getGameId(), param.getServerId(), param.getRoleId(), param.getRoleLevel());
+        //token临期失效判断
+        try {
+            userTokenService.userTokenUpdateCheck(userData);
+        } catch (Exception ignored) {
+        }
+        //活跃提交
         Map<String, Object> activeParamMap = new HashMap<>(6);
         activeParamMap.put("userId", userData.getUserId());
         activeParamMap.put("gameId", userData.getGameId());

+ 15 - 4
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/LoginServiceImpl.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.zanxiang.game.module.base.pojo.enums.BanStatusEnum;
 import com.zanxiang.game.module.base.pojo.enums.HttpStatusEnum;
 import com.zanxiang.game.module.mybatis.entity.*;
+import com.zanxiang.game.module.sdk.constant.RedisKeyConstant;
 import com.zanxiang.game.module.sdk.enums.LoginTypeEnum;
 import com.zanxiang.game.module.sdk.enums.SmsTypeEnum;
 import com.zanxiang.game.module.sdk.pojo.dto.GameAppletDTO;
@@ -17,7 +18,9 @@ import com.zanxiang.game.module.sdk.service.*;
 import com.zanxiang.game.module.sdk.service.api.WxApiService;
 import com.zanxiang.game.module.sdk.util.RegexUtil;
 import com.zanxiang.game.module.sdk.util.RegisterUtil;
+import com.zanxiang.module.redis.service.IDistributedLockComponent;
 import com.zanxiang.module.util.JsonUtil;
+import com.zanxiang.module.util.exception.BaseException;
 import com.zanxiang.module.util.pojo.ResultVO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.logging.log4j.util.Strings;
@@ -31,6 +34,7 @@ import reactor.util.function.Tuples;
 import java.time.LocalDateTime;
 import java.util.Map;
 import java.util.Objects;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author : lingfeng
@@ -95,6 +99,9 @@ public class LoginServiceImpl implements IRegisterLoginService {
     @Autowired
     private IGameUserRoleService gameUserRoleService;
 
+    @Autowired
+    private IDistributedLockComponent distributedLockComponent;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public ResultVO<UserLoginVO> loginWxCode(LoginVxCodeParam param, UserData userData) {
@@ -109,10 +116,6 @@ public class LoginServiceImpl implements IRegisterLoginService {
                 gameAppletDTO.getAppSecret(), gameAppletDTO.getType());
         String openId = resultMap.get("openid");
         String sessionKey = resultMap.get("session_key");
-
-        log.error("登录用户, param : {}, userData : {}, resultMap : {}", JsonUtil.toString(param),
-                JsonUtil.toString(userData), JsonUtil.toString(resultMap));
-
         //根据openId查询用户
         User user = userService.getOne(new LambdaQueryWrapper<User>()
                 .eq(User::getGameId, userData.getGameId()).eq(User::getOpenId, openId));
@@ -269,6 +272,12 @@ public class LoginServiceImpl implements IRegisterLoginService {
     }
 
     private User userCreateSave(UserData userData, String userName, String password, String mobile, String openId, String sessionKey) {
+        //锁Key
+        String lockKey = RedisKeyConstant.USER_CREATE + "_" + userData.getGameId() + "_" + userName;
+        //上锁
+        if (!distributedLockComponent.doLock(lockKey, 3L, 10L, TimeUnit.SECONDS)) {
+            throw new BaseException("用户信息正在注册中, 请稍后重试");
+        }
         //渠道id, 链接参数, 分享人id
         Tuple3<Long, Map<String, String>, String> tuple3 = agentService.getUserAgentId(userData);
         //分享人id
@@ -297,6 +306,8 @@ public class LoginServiceImpl implements IRegisterLoginService {
                 .createTime(LocalDateTime.now())
                 .updateTime(LocalDateTime.now())
                 .build());
+        //释放锁
+        distributedLockComponent.unlock(lockKey);
         return user;
     }
 

+ 21 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/UserTokenServiceImpl.java

@@ -1,6 +1,7 @@
 package com.zanxiang.game.module.sdk.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zanxiang.game.module.base.pojo.enums.BanStatusEnum;
 import com.zanxiang.game.module.base.util.DateUtils;
@@ -17,6 +18,7 @@ import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.service.*;
 import com.zanxiang.game.module.sdk.util.RedisUtil;
 import com.zanxiang.game.module.sdk.util.SignUtil;
+import com.zanxiang.module.util.DateUtil;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.encryption.Md5Util;
@@ -105,6 +107,25 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
         return re;
     }
 
+    @Override
+    public void userTokenUpdateCheck(UserData userData) {
+        //过期时间
+        LocalDateTime expireTime = DateUtil.secondToLocalDateTime(userData.getExpireTime());
+        //判断是否1天内过期
+        if (expireTime == null || LocalDateTime.now().plusDays(1).isBefore(expireTime)) {
+            return;
+        }
+        //更新token的时效时长
+        super.update(new LambdaUpdateWrapper<UserToken>()
+                .set(UserToken::getExpireTime, DateUtils.localDateTimeToSecond(LocalDateTime.now()) + ExpireTimeEnum.ONE_WEEK.getTime())
+                .set(UserToken::getUpdateTime, LocalDateTime.now())
+                .eq(UserToken::getUserId, userData.getUserId())
+                .eq(UserToken::getToken, userData.getToken()));
+        //删除token信息缓存
+        redisUtil.deleteCache(this.getTokenInfoKey(userData.getToken(), userData.getDeviceType()));
+        redisUtil.deleteCache(this.getUserTokenKey(userData.getUserId(), userData.getDeviceType()));
+    }
+
     @Override
     public Boolean userTokenExpireTimeCheck(UserData userData) {
         log.error("缓存token验证请求 userData : {}", JsonUtil.toString(userData));