房间金币大放送-新增房间内同时在线用户数逻辑
This commit is contained in:
parent
04d01a92ae
commit
c6f3545052
@ -0,0 +1,14 @@
|
||||
package com.red.circle.other.inner.endpoint.task;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
/**
|
||||
* 每日任务进度 Client.
|
||||
*
|
||||
* @author tf
|
||||
*/
|
||||
@FeignClient(name = "roomDailyTaskClient", url = "${feign.other.url}" +
|
||||
RoomDailyTaskClientApi.API_PREFIX)
|
||||
public interface RoomDailyTaskClient extends RoomDailyTaskClientApi {
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package com.red.circle.other.inner.endpoint.task;
|
||||
|
||||
import com.red.circle.framework.dto.ResultResponse;
|
||||
import com.red.circle.other.inner.model.cmd.task.RoomDailyTaskProgressUpdateInnerCmd;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* 每日任务进度 Client API.
|
||||
*
|
||||
* @author tf
|
||||
*/
|
||||
public interface RoomDailyTaskClientApi {
|
||||
|
||||
String API_PREFIX = "/room-daily-task/client";
|
||||
|
||||
/**
|
||||
* 更新任务进度.
|
||||
*/
|
||||
@PostMapping("/update-progress")
|
||||
ResultResponse<Void> updateTaskProgress(@RequestBody RoomDailyTaskProgressUpdateInnerCmd cmd);
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.red.circle.other.inner.model.cmd.task;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 更新每日任务进度命令(内部服务调用).
|
||||
*
|
||||
* @author tf
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class RoomDailyTaskProgressUpdateInnerCmd {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String taskCode;
|
||||
|
||||
private Integer progressValue;
|
||||
|
||||
}
|
||||
@ -11,13 +11,17 @@ import com.red.circle.live.domain.gateway.LiveMicrophoneGateway;
|
||||
import com.red.circle.live.domain.live.LiveMicrophone;
|
||||
import com.red.circle.live.domain.online.LiveRoomUser;
|
||||
import com.red.circle.live.infra.database.cache.service.LiveMicCacheService;
|
||||
import com.red.circle.live.infra.database.cache.service.LiveMicUserCacheService;
|
||||
import com.red.circle.live.infra.database.cache.service.LiveRoomCacheService;
|
||||
import com.red.circle.mq.business.model.event.user.UserHeartbeatEvent;
|
||||
import com.red.circle.mq.rocket.business.producer.UserMqMessageService;
|
||||
import com.red.circle.mq.rocket.business.streams.UserHeartbeatSink;
|
||||
import com.red.circle.other.inner.endpoint.live.RoomManagerClient;
|
||||
import com.red.circle.other.inner.endpoint.task.RoomDailyTaskClient;
|
||||
import com.red.circle.other.inner.endpoint.user.user.UserOnlineClient;
|
||||
import com.red.circle.other.inner.endpoint.user.user.UserProfileClient;
|
||||
import com.red.circle.other.inner.enums.task.RoomDailyTaskCode;
|
||||
import com.red.circle.other.inner.model.cmd.task.RoomDailyTaskProgressUpdateInnerCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.OnlineStatusUploadCmd;
|
||||
import com.red.circle.other.inner.model.dto.live.RoomProfileDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
||||
@ -52,6 +56,8 @@ public class UserHeartbeatListener implements MessageListener {
|
||||
private final UserMqMessageService userMqMessageService;
|
||||
private final MessageEventProcess messageEventProcess;
|
||||
private final LiveRoomCacheService liveRoomCacheService;
|
||||
private final LiveMicUserCacheService liveMicUserCacheService;
|
||||
private final RoomDailyTaskClient roomDailyTaskClient;
|
||||
|
||||
@Override
|
||||
public Action consume(ConsumerMessage message) {
|
||||
@ -88,9 +94,29 @@ public class UserHeartbeatListener implements MessageListener {
|
||||
|
||||
processLiveHeartBeat(event, userProfileDTO);
|
||||
uploadHistoryHeartBeat(event);
|
||||
|
||||
Long roomId = DataTypeUtils.toLong(event.getSessionId());
|
||||
if (roomId != null && roomId > 0) {
|
||||
RoomProfileDTO roomProfile = roomManagerClient.getById(roomId).getBody();
|
||||
if (roomProfile != null && Objects.equals(roomProfile.getUserId(), event.getUserId())) {
|
||||
List<LiveRoomUser> liveRoomUsers = liveMicUserCacheService.listUser(event.getUserId());
|
||||
handleOnlineUserCountTask(event.getUserId(), liveRoomUsers.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//log.warn("consume UserHeartbeat end with {}", System.currentTimeMillis() - startTime);
|
||||
}
|
||||
|
||||
private void handleOnlineUserCountTask(Long roomOwnerId, int onlineCount) {
|
||||
roomDailyTaskClient.updateTaskProgress(
|
||||
new RoomDailyTaskProgressUpdateInnerCmd()
|
||||
.setUserId(roomOwnerId)
|
||||
.setTaskCode(RoomDailyTaskCode.ROOM_ONLINE_USER_COUNT.name())
|
||||
.setProgressValue(onlineCount)
|
||||
);
|
||||
}
|
||||
|
||||
private void processLiveHeartBeat(UserHeartbeatEvent event, UserProfileDTO userProfile) {
|
||||
if (StringUtils.isBlank(event.getSessionId())
|
||||
|| !event.getSessionId().trim().matches(RegexConstant.NUMBER)) {
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package com.red.circle.other.app.inner.endpoint.task;
|
||||
|
||||
import com.red.circle.framework.dto.ResultResponse;
|
||||
import com.red.circle.other.app.dto.cmd.task.RoomDailyTaskProgressUpdateCmd;
|
||||
import com.red.circle.other.app.service.task.RoomDailyTaskProgressService;
|
||||
import com.red.circle.other.inner.endpoint.task.RoomDailyTaskClientApi;
|
||||
import com.red.circle.other.inner.model.cmd.task.RoomDailyTaskProgressUpdateInnerCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 每日任务进度 ClientEndpoint.
|
||||
*
|
||||
* @author tf
|
||||
*/
|
||||
@Validated
|
||||
@RestController
|
||||
@RequestMapping(value = RoomDailyTaskClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@RequiredArgsConstructor
|
||||
public class RoomDailyTaskClientEndpoint implements RoomDailyTaskClientApi {
|
||||
|
||||
private final RoomDailyTaskProgressService roomDailyTaskProgressService;
|
||||
|
||||
@Override
|
||||
public ResultResponse<Void> updateTaskProgress(RoomDailyTaskProgressUpdateInnerCmd cmd) {
|
||||
roomDailyTaskProgressService.updateTaskProgress(
|
||||
new RoomDailyTaskProgressUpdateCmd()
|
||||
.setUserId(cmd.getUserId())
|
||||
.setTaskCode(cmd.getTaskCode())
|
||||
.setProgressValue(cmd.getProgressValue())
|
||||
);
|
||||
return ResultResponse.success(null);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user