| 
					
				 | 
			
			
				@@ -3,8 +3,12 @@ package com.zanxiang.game.back.serve.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.github.sd4324530.jtuple.Tuple2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zanxiang.advertising.tencent.base.AdvertisingTencentServer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zanxiang.advertising.tencent.base.pojo.dto.DataReportOfAccountIdRpcDTO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zanxiang.advertising.tencent.base.pojo.dto.UserActionRpcDTO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zanxiang.advertising.tencent.base.rpc.IUserActionSetRpc; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.back.serve.dao.mapper.GameTencentAppApiUserMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.zanxiang.game.back.serve.pojo.TencentAppReport; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.back.serve.pojo.entity.GameTencentAppApiBackLog; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.back.serve.pojo.entity.GameTencentAppApiUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.back.serve.pojo.entity.GameTencentAppCallback; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -13,19 +17,17 @@ import com.zanxiang.game.back.serve.pojo.enums.BackStatusEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.back.serve.service.IGameTencentAppApiBackLogService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.back.serve.service.IGameTencentAppApiUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.game.back.serve.service.IGameTencentAppCallbackService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.zanxiang.module.util.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.zanxiang.module.util.URIUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.zanxiang.module.util.encryption.Md5Util; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.zanxiang.module.util.pojo.ResultVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.dubbo.config.annotation.DubboReference; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.http.ResponseEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.client.RestTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.LocalDateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Collections; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Slf4j 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -38,13 +40,16 @@ implements IGameTencentAppApiUserService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private IGameTencentAppCallbackService gameTencentAppCallbackService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private RestTemplate restTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @DubboReference(providedBy = AdvertisingTencentServer.SERVER_DUBBO_NAME) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private IUserActionSetRpc userActionSetRpc; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public boolean userBack(GameTencentAppApiUser userLog, boolean mustBack) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        BackStatusEnum backStatus = doCallback(userLog, mustBack); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Tuple2<BackStatusEnum, String> backStatus = doCallback(userLog, mustBack); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return update(new LambdaUpdateWrapper<GameTencentAppApiUser>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                .set(GameTencentAppApiUser::getIsBack, backStatus.getBackStatus()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .set(GameTencentAppApiUser::getIsBack, backStatus.first.getBackStatus()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .set(GameTencentAppApiUser::getBackLog, backStatus.second) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .eq(GameTencentAppApiUser::getId, userLog.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -52,9 +57,10 @@ implements IGameTencentAppApiUserService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public boolean tencentUserReport(List<Long> ids) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         listByIds(ids).forEach(userLog -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            BackStatusEnum backStatus = doCallback(userLog, true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Tuple2<BackStatusEnum, String> backStatus = doCallback(userLog, true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             update(new LambdaUpdateWrapper<GameTencentAppApiUser>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .set(GameTencentAppApiUser::getIsBack, backStatus.getBackStatus()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(GameTencentAppApiUser::getIsBack, backStatus.first.getBackStatus()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(GameTencentAppApiUser::getBackLog, backStatus.second) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .eq(GameTencentAppApiUser::getId, userLog.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -62,7 +68,7 @@ implements IGameTencentAppApiUserService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private BackStatusEnum doCallback(GameTencentAppApiUser userLog, boolean mustBack) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Tuple2<BackStatusEnum, String> doCallback(GameTencentAppApiUser userLog, boolean mustBack) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         boolean isBack = mustBack ? false : gameTencentAppApiBackLogService.count(new LambdaQueryWrapper<GameTencentAppApiBackLog>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .eq(GameTencentAppApiBackLog::getGameId, userLog.getGameId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .eq(GameTencentAppApiBackLog::getUserId, userLog.getUserId()) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -70,46 +76,31 @@ implements IGameTencentAppApiUserService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .eq(GameTencentAppApiBackLog::getBackLog, "回传成功") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ) > 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (isBack) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return BackStatusEnum.NO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Tuple2.with(BackStatusEnum.SUCCESS, "回传成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        GameTencentAppCallback callback = gameTencentAppCallbackService.getUserCallback(userLog.getGameId(), userLog.getImei(), userLog.getOaid(), userLog.getAndroidId(), userLog.getIdfa(), userLog.getCaid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if(callback == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return BackStatusEnum.FAILED; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (userLog.getCallbackId() == null || userLog.getCallbackId() < 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Tuple2.with(BackStatusEnum.FAILED, "用户匹配不到广告"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String callbackUrl = URIUtil.decodeURIComponent(callback.getCallback()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        TencentAppReport reportData = TencentAppReport.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                .actions(Collections.singletonList(TencentAppReport.Action.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        .action_time(DateUtil.localDateTimeToSecond(userLog.getRegisterTime())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        .userr_id(TencentAppReport.UserId.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                .hash_imei(StringUtils.isBlank(userLog.getImei()) ? null : Md5Util.encrypt32(userLog.getImei().toLowerCase()).toLowerCase()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                .hash_oaid(StringUtils.isBlank(userLog.getOaid()) ? null : Md5Util.encrypt32(userLog.getOaid()).toLowerCase()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                .hash_android_id(StringUtils.isBlank(userLog.getAndroidId()) ? null : Md5Util.encrypt32(userLog.getAndroidId()).toLowerCase()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                .hash_idfa(StringUtils.isBlank(userLog.getIdfa()) ? null : Md5Util.encrypt32(userLog.getIdfa().toUpperCase()).toLowerCase()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                .caid(userLog.getCaid()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        GameTencentAppCallback callback = gameTencentAppCallbackService.getById(userLog.getCallbackId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        DataReportOfAccountIdRpcDTO dataReportOfAccountIdRpcDTO = DataReportOfAccountIdRpcDTO.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .accountId(userLog.getAdAccountId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .userActionSetId(userLog.getUserActionSetId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .action(UserActionRpcDTO.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .actionTime(userLog.getRegisterTime()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .actionType(ActionTypeEnum.ACTIVATE_APP.getActionType()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .userId(UserActionRpcDTO.UserIdRpcDTO.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                .hashImei(StringUtils.isBlank(userLog.getImei()) ? null : Md5Util.encrypt32(userLog.getImei().toLowerCase()).toLowerCase()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                .hashIdfa(StringUtils.isBlank(userLog.getOaid()) ? null : Md5Util.encrypt32(userLog.getIdfa().toLowerCase()).toLowerCase()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                .hashOaid(StringUtils.isBlank(userLog.getOaid()) ? null : Md5Util.encrypt32(userLog.getOaid().toLowerCase()).toLowerCase()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                .build()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .trace(UserActionRpcDTO.TraceRpcDTO.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                .clickId(callback.getClickId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                 .build()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        .action_type("ACTIVATE_APP") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        .trace(callback.getClickId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        .build())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .build()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        BackStatusEnum backStatus; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String backLog; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ResponseEntity<String> response = restTemplate.postForEntity(callbackUrl, reportData, String.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (response.getStatusCode().is2xxSuccessful()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                backStatus = BackStatusEnum.SUCCESS; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                backLog = "回传成功"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                backStatus = BackStatusEnum.FAILED; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                backLog = "回传识别,失败信息:" + response.getBody(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            log.error(e.getMessage(), e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            backStatus = BackStatusEnum.FAILED; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            backLog = "回传识别,失败原因:" + e.getMessage(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         GameTencentAppApiBackLog gameTencentBackLog = GameTencentAppApiBackLog.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .gameId(userLog.getGameId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .userId(userLog.getUserId()) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -122,9 +113,17 @@ implements IGameTencentAppApiUserService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .androidId(userLog.getAndroidId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .idfa(userLog.getIdfa()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .caid(userLog.getCaid()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                .backLog(backLog) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ResultVO<Boolean> result = userActionSetRpc.reportByAccountId(dataReportOfAccountIdRpcDTO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BackStatusEnum backStatus = BackStatusEnum.FAILED; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (result.isSuccess()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            backStatus = BackStatusEnum.SUCCESS; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            gameTencentBackLog.setBackLog("回传成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            gameTencentBackLog.setBackLog(result.getMsg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         gameTencentAppApiBackLogService.save(gameTencentBackLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return backStatus; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Tuple2.with(backStatus, gameTencentBackLog.getBackLog()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |