|
@@ -11,6 +11,7 @@ import com.zanxiang.game.module.mybatis.mapper.GameUserRoleMapper;
|
|
import com.zanxiang.game.module.sdk.constant.RedisKeyConstant;
|
|
import com.zanxiang.game.module.sdk.constant.RedisKeyConstant;
|
|
import com.zanxiang.game.module.sdk.enums.DataTypeEnum;
|
|
import com.zanxiang.game.module.sdk.enums.DataTypeEnum;
|
|
import com.zanxiang.game.module.sdk.enums.LoginTypeEnum;
|
|
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.GameUserRoleUpdateParam;
|
|
import com.zanxiang.game.module.sdk.pojo.param.UserData;
|
|
import com.zanxiang.game.module.sdk.pojo.param.UserData;
|
|
import com.zanxiang.game.module.sdk.service.IGameUserRoleService;
|
|
import com.zanxiang.game.module.sdk.service.IGameUserRoleService;
|
|
@@ -21,7 +22,11 @@ import com.zanxiang.module.redis.service.IDistributedLockComponent;
|
|
import com.zanxiang.module.util.DateUtil;
|
|
import com.zanxiang.module.util.DateUtil;
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.kafka.clients.producer.KafkaProducer;
|
|
|
|
+import org.apache.kafka.clients.producer.ProducerRecord;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
@@ -53,6 +58,13 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
|
|
@Autowired
|
|
@Autowired
|
|
private IDistributedLockComponent distributedLockComponent;
|
|
private IDistributedLockComponent distributedLockComponent;
|
|
|
|
|
|
|
|
+ @Value("${spring.kafka.game-sdk.gameRoleActiveTopic}")
|
|
|
|
+ private String gameRoleActiveTopic;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ @Qualifier("gameSdkKafkaProducer")
|
|
|
|
+ private KafkaProducer<String, String> kafkaProducer;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Boolean updateUserGameRole(GameUserRoleUpdateParam param, UserData userData) {
|
|
public Boolean updateUserGameRole(GameUserRoleUpdateParam param, UserData userData) {
|
|
@@ -226,4 +238,24 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
|
|
} catch (Exception ignored) {
|
|
} catch (Exception ignored) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @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());
|
|
|
|
+ Map<String, Object> activeParamMap = new HashMap<>(6);
|
|
|
|
+ activeParamMap.put("userId", userData.getUserId());
|
|
|
|
+ activeParamMap.put("gameId", userData.getGameId());
|
|
|
|
+ activeParamMap.put("serverId", param.getServerId());
|
|
|
|
+ activeParamMap.put("roleId", param.getRoleId());
|
|
|
|
+ activeParamMap.put("roleLevel", param.getRoleLevel());
|
|
|
|
+ activeParamMap.put("activeTime", System.currentTimeMillis());
|
|
|
|
+ try {
|
|
|
|
+ kafkaProducer.send(new ProducerRecord<>(gameRoleActiveTopic, userData.getUserId().toString(), JsonUtil.toString(activeParamMap)));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("用户角色活跃信息发送到 Kafka 异常!, activeParamMap : {}, e : {}", JsonUtil.toString(activeParamMap), e.getMessage());
|
|
|
|
+ return Boolean.FALSE;
|
|
|
|
+ }
|
|
|
|
+ return Boolean.TRUE;
|
|
|
|
+ }
|
|
}
|
|
}
|