Bladeren bron

feat : CP数据推送, 兼容channel非json结构

bilingfeng 9 maanden geleden
bovenliggende
commit
efd335badc

+ 11 - 19
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/CpPushDataServiceImpl.java

@@ -375,10 +375,6 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
         //渠道参数判断
         String channel = param.getChannel();
         Tuple2<Boolean, Boolean> jsonAndEmpty = this.isJsonAndEmpty(channel);
-        //非json, 参数错误
-        if (!jsonAndEmpty.getT1()) {
-            throw new BaseException("参数错误, channel字段非json格式");
-        }
         //查询游戏
         Game game = this.getGameByGameAppId(gameAppId);
         //中间数据
@@ -389,10 +385,10 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
                 .eq(User::getOpenId, param.getOpenId()));
         //玩家信息不存在
         if (user == null) {
-            return this.createUser(game, userData, param, jsonAndEmpty.getT2());
+            return this.createUser(game, userData, param, jsonAndEmpty);
         }
         //玩家信息更新
-        Map<String, String> channelMap = this.updateUser(user, param, game, userData, jsonAndEmpty.getT2());
+        Map<String, String> channelMap = this.updateUser(user, param, game, userData, jsonAndEmpty);
         //构造返回
         return CpPushUserVO.builder().userId(user.getId())
                 .sdkUser(!Objects.equals(user.getAgentId(), Agent.DEFAULT_AGENT))
@@ -400,7 +396,7 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
                 .build();
     }
 
-    private CpPushUserVO createUser(Game game, UserData userData, CpPushUserParam param, boolean isEmptyJson) {
+    private CpPushUserVO createUser(Game game, UserData userData, CpPushUserParam param, Tuple2<Boolean, Boolean> jsonAndEmpty) {
         //游戏id
         Long gameId = game.getId();
         //线程锁Key
@@ -422,7 +418,7 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
                         .last("limit 1"));
                 user = this.transform(gameId, shareUser.getAgentId(), shareUser, param);
             } else {
-                Tuple2<Long, Map<String, String>> tuple2 = this.getUserAgentChannel(game, userData, isEmptyJson);
+                Tuple2<Long, Map<String, String>> tuple2 = this.getUserAgentChannel(game, userData, jsonAndEmpty);
                 user = this.transform(gameId, tuple2.getT1(), null, param);
                 channelMap = tuple2.getT2();
             }
@@ -454,7 +450,7 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
         }
     }
 
-    private Map<String, String> updateUser(User user, CpPushUserParam param, Game game, UserData userData, boolean isEmptyJson) {
+    private Map<String, String> updateUser(User user, CpPushUserParam param, Game game, UserData userData, Tuple2<Boolean, Boolean> jsonAndEmpty) {
         //活跃间隔时长
         long inactiveDay = 15L;
         //判定不活跃时长是否达到限制
@@ -466,7 +462,7 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
             return Collections.emptyMap();
         }
         //渠道id, 链接参数
-        Tuple2<Long, Map<String, String>> tuple2 = this.getUserAgentChannel(game, userData, isEmptyJson);
+        Tuple2<Long, Map<String, String>> tuple2 = this.getUserAgentChannel(game, userData, jsonAndEmpty);
         //查询渠道
         Agent agent = agentService.getById(tuple2.getT1());
         if (agent == null) {
@@ -487,19 +483,15 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
         return tuple2.getT2();
     }
 
-    private Tuple2<Long, Map<String, String>> getUserAgentChannel(Game game, UserData userData, boolean isEmptyJson) {
-        //传入的是空json, 走监测链接匹配
-        if (isEmptyJson) {
-            //todo : 走监测链接匹配
+    private Tuple2<Long, Map<String, String>> getUserAgentChannel(Game game, UserData userData, Tuple2<Boolean, Boolean> jsonAndEmpty) {
+        //channel渠道信息非json格式, 或者是空json
+        if (!jsonAndEmpty.getT1() || jsonAndEmpty.getT2()) {
+            //返回自然量渠道
             return Tuples.of(0L, Collections.emptyMap());
         }
         //渠道id, 链接参数, 分享人id
         Tuple3<Long, Map<String, String>, String> tuple3 = agentService.getUserAgentId(game, userData);
-        //包含 clue_token 但是未匹配到渠道, 防止 agentKey 参数丢失的情况 , 走监测链接补偿匹配
-        if (Objects.equals(tuple3.getT1(), Agent.DEFAULT_AGENT) && tuple3.getT2().containsKey("clue_token")) {
-            //todo : 走监测链接匹配
-            return Tuples.of(0L, Collections.emptyMap());
-        }
+        //返回渠道id, 渠道参数
         return Tuples.of(tuple3.getT1(), tuple3.getT2());
     }