|
@@ -19,7 +19,7 @@ import com.zanxiang.module.redis.service.IDistributedLockComponent;
|
|
|
import com.zanxiang.module.util.DateUtil;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.kafka.clients.producer.KafkaProducer;
|
|
|
+import org.apache.kafka.clients.producer.Producer;
|
|
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@@ -61,14 +61,16 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
|
|
|
@Value("${spring.kafka.game-sdk.gameRoleActiveTopic}")
|
|
|
private String gameRoleActiveTopic;
|
|
|
|
|
|
+ @Value("${server.domain}")
|
|
|
+ private String serverUrl;
|
|
|
+
|
|
|
@Autowired
|
|
|
@Qualifier("gameSdkKafkaProducer")
|
|
|
- private KafkaProducer<String, String> kafkaProducer;
|
|
|
+ private Producer<String, String> kafkaProducer;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean updateUserGameRole(GameUserRoleUpdateParam param, UserData userData) {
|
|
|
- log.error("上报用户信息, param : {}", JsonUtil.toString(param));
|
|
|
//上报类型
|
|
|
Integer dataType = param.getDataType();
|
|
|
//选择服务器
|
|
@@ -99,6 +101,10 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
|
|
|
}
|
|
|
//等级提升更新
|
|
|
if (Objects.equals(dataType, DataTypeEnum.TYPE_LEVEL_UP.getDateType())) {
|
|
|
+ //更新频率限制, 20秒更新一次, 避免游戏实时战力高频上报
|
|
|
+ if (!distributedLockComponent.doLock(RedisKeyConstant.ROLE_LEVEL_UP + userData.getUserId(), 0L, 20L, TimeUnit.SECONDS)) {
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
return super.update(new LambdaUpdateWrapper<GameUserRole>()
|
|
|
.set(GameUserRole::getRoleName, param.getRoleName())
|
|
|
.set(GameUserRole::getRoleLevel, param.getRoleLevel())
|
|
@@ -107,6 +113,7 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
|
|
|
.set(param.getRoleVipLevel() != null, GameUserRole::getRoleVipLevel, param.getRoleVipLevel())
|
|
|
.set(param.getRolePower() != null, GameUserRole::getRolePower, param.getRolePower())
|
|
|
.set(GameUserRole::getUpdateTime, param.getRoleGradeUpdateTime() == null || param.getRoleGradeUpdateTime() <= 0 ? LocalDateTime.now() : DateUtil.secondToLocalDateTime(param.getRoleGradeUpdateTime()))
|
|
|
+ .set(param.getExtra() != null, GameUserRole :: getExtra, JsonUtil.toString(param.getExtra()))
|
|
|
.eq(GameUserRole::getUserId, userData.getUserId())
|
|
|
.eq(GameUserRole::getGameId, userData.getGameId())
|
|
|
.eq(GameUserRole::getRoleId, param.getRoleId()));
|
|
@@ -153,6 +160,7 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
|
|
|
.createTime(param.getRoleGradeUpdateTime() == null || param.getRoleGradeUpdateTime() <= 0 ? LocalDateTime.now() : DateUtil.secondToLocalDateTime(param.getRoleGradeUpdateTime()))
|
|
|
.updateTime(LocalDateTime.now())
|
|
|
.lastLoginTime(LocalDateTime.now())
|
|
|
+ .extra(param.getExtra() == null ? null : JsonUtil.toString(param.getExtra()))
|
|
|
.build();
|
|
|
super.save(userRole);
|
|
|
//更新玩家创角数
|
|
@@ -246,6 +254,10 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
|
|
|
userTokenService.userTokenUpdateCheck(userData);
|
|
|
} catch (Exception ignored) {
|
|
|
}
|
|
|
+ //测试环境不使用kafka
|
|
|
+ if (this.serverUrl.contains("test")) {
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
//活跃提交
|
|
|
Map<String, Object> activeParamMap = new HashMap<>(6);
|
|
|
activeParamMap.put("userId", userData.getUserId());
|