| 
					
				 | 
			
			
				@@ -1,15 +1,19 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.zanxiang.game.module.sdk.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.github.sd4324530.jtuple.Tuple2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.base.pojo.enums.AccountTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.mybatis.entity.Agent; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.mybatis.entity.Game; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.mybatis.entity.User; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zanxiang.game.module.mybatis.entity.UserEvent; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.mybatis.mapper.GameMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.sdk.pojo.param.UserData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.sdk.service.IAgentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.sdk.service.IGameService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zanxiang.game.module.sdk.service.IUserEventService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.module.sdk.service.IUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.module.util.JsonUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -30,11 +34,14 @@ import java.util.Objects; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements IGameService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private IUserService userService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private IAgentService agentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private IUserService userService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private IUserEventService userEventService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public Map<String, Object> getAdSdkConfig(UserData userData) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -46,13 +53,11 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements IG 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //不是微信小程序, 不返回配置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //默认返回不初始化 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return Collections.singletonMap("adSdk", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //目前只有投腾讯才返回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Agent agent = this.getUserAgent(userData.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //查询用户信息以及投放渠道 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Tuple2<User, Agent> userAndAgent = this.getUserAndAgent(userData.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userAndAgent.first; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Agent agent = userAndAgent.second; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //渠道判断, 目前只有投腾讯才返回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (agent != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //腾讯广告 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (Objects.equals(agent.getAccountType(), AccountTypeEnum.TENCENT_MINI_GAME.getValue())) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -63,22 +68,29 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements IG 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return Collections.singletonMap("adSdk", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //当前调试阶段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (userData.getUserId() != null && Objects.equals(game.getStatus(), 2)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //用户判断, 是否调试阶段和测试用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Objects.equals(game.getStatus(), 2) || userEventService.count(new LambdaQueryWrapper<UserEvent>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(UserEvent::getGameId, user.getGameId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .and(qw -> qw.eq(UserEvent::getUsername, user.getUsername()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .or().eq(UserEvent::getUsername, user.getOpenId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .or().eq(UserEvent::getMobile, user.getMobile())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ) > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //默认返回不初始化 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return Collections.singletonMap("adSdk", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private Agent getUserAgent(Long userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Tuple2<User, Agent> getUserAndAgent(Long userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (userId == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Tuple2.with(null, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         User user = userService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (user == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Tuple2.with(null, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return agentService.getById(user.getAgentId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Tuple2.with(user, agentService.getById(user.getAgentId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |