hotgame 飘窗对接

This commit is contained in:
tianfeng 2025-12-03 11:55:53 +08:00
parent 31b8d82ee7
commit fab3d9e81f

View File

@ -2,22 +2,31 @@ package com.red.circle.other.app.service.game;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.component.game.hotgame.request.HotGameUserCoinUpdate;
import com.red.circle.component.game.hotgame.request.HotGameUserProfileQuery;
import com.red.circle.component.game.hotgame.response.HotGameCoin;
import com.red.circle.component.game.hotgame.response.HotGameErrorEnum;
import com.red.circle.component.game.hotgame.response.HotGameResponse;
import com.red.circle.component.redis.service.RedisService;
import com.red.circle.external.inner.endpoint.message.ImGroupClient;
import com.red.circle.external.inner.model.cmd.message.BroadcastGroupMsgBodyCmd;
import com.red.circle.external.inner.model.enums.message.GroupMessageTypeEnum;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.exception.ResponseException;
import com.red.circle.framework.core.security.UserCredential;
import com.red.circle.mq.business.model.event.task.TaskApprovalEvent;
import com.red.circle.mq.rocket.business.producer.TaskMqMessage;
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
import com.red.circle.other.app.dto.clientobject.game.HotGameUpdateRequest;
import com.red.circle.other.app.enums.violation.GameOriginEnum;
import com.red.circle.other.app.service.game.override.domain.HotGameUserProfile;
import com.red.circle.other.app.service.game.override.service.HotGameService;
import com.red.circle.other.app.util.OfficialNoticeUtils;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService;
import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig;
import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService;
import com.red.circle.other.inner.enums.config.EnumConfigKey;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.date.LocalDateTimeUtils;
@ -35,6 +44,7 @@ import com.red.circle.wallet.inner.model.enums.GoldOrigin;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -59,6 +69,8 @@ public class HotGameServiceImpl implements HotGameService {
private final EnumConfigCacheService enumConfigCacheService;
private final UserProfileAppConvertor userProfileAppConvertor;
private final TaskMqMessage taskMqMessage;
private final ImGroupClient imGroupClient;
private final GameListConfigService gameListConfigService;
@Override
public HotGameResponse<HotGameUserProfile> getUserProfile(HotGameUserProfileQuery query) {
@ -196,21 +208,48 @@ public class HotGameServiceImpl implements HotGameService {
} catch (Exception ex) {
log.error("ex:{}", Throwables.getStackTraceAsString(ex));
}
//游玩一句游戏结束 每日任务 热游
// taskMqMessage.sendTask(TaskApprovalEvent.builder()
// .taskId(4)
// .userId(userId)
// .day(LocalDateTimeUtils.nowFormat("yyyy-MM-dd"))
// .currencyDiff(param.getCoin())
// .sysOrigin(UserCredential.parseToken(param.getToken()).getSysOrigin())
// .gameName(GoldOrigin.HOT_GAME.name())
// .gameId(Long.parseLong(param.getGameId()))
// .build());
try {
String sysOrigin = UserCredential.parseToken(param.getToken()).getSysOrigin();
GameListConfig gameListConfig = gameListConfigService.getByGameId(param.getGameId(), GameOriginEnum.BAISHUN.name(), sysOrigin);
sendBroadcast(param, gameListConfig);
} catch (Exception e) {
log.error("hotgame游戏飘窗推送失败 ex:{}", e.getMessage());
}
return new HotGameResponse<HotGameCoin>()
.setErrorCode(HotGameErrorEnum.SERVER_ERROR.getErrorCode());
}
private void sendBroadcast(HotGameUserCoinUpdate request, GameListConfig gameListConfig) {
if (gameListConfig == null) {
return;
}
BigDecimal cost = enumConfigCacheService
.getValueBigDecimal(EnumConfigKey.GAME_BROADCAST_AMOUNT, gameListConfig.getSysOrigin()) ;
if (cost == null || cost.compareTo(BigDecimal.ZERO) <= 0) {
cost = BigDecimal.valueOf(5000L);
}
if (request.getCoin() >= cost.longValue()) {
UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(
userProfileGateway.getByUserId(DataTypeUtils.toLong(request.getUid())));
Map<Object, Object> build = OfficialNoticeUtils.buildUserProfile(userProfile);
build.put("gameUrl", gameListConfig.getCover());
build.put("currencyDiff", request.getCoin());
imGroupClient.sendMessageBroadcast(
BroadcastGroupMsgBodyCmd.builder()
.toPlatform(SysOriginPlatformEnum.LIKEI)
.type(GroupMessageTypeEnum.GAME_BAISHUN_WIN)
.data(build)
.build()
);
}
}
private GoldReceiptCmdBuilder createGoldReceiptCmdBuilder(Integer type) {
if (Objects.equals(type, 1)) {
return GoldReceiptCmd.builder().appExpenditure();