Commit bbfdc13f by Future

多人饮食超时定时器

parent 451bc9c9
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
<groupId>io.geekidea.springbootplus</groupId> <groupId>io.geekidea.springbootplus</groupId>
<artifactId>core</artifactId> <artifactId>core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.geekidea.springbootplus</groupId>
<artifactId>scheduled</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -17,6 +17,6 @@ public interface ImMultiRtcRoomMemberService extends BaseService<ImMultiRtcRoomM ...@@ -17,6 +17,6 @@ public interface ImMultiRtcRoomMemberService extends BaseService<ImMultiRtcRoomM
* @param roomId * @param roomId
* @param state * @param state
*/ */
void changeRoomMemberState(ImClient currentClient, String roomId, Integer state); void changeRoomMemberState(Long fkClientId, String roomId, Integer state);
} }
...@@ -23,10 +23,10 @@ public class ImMultiRtcRoomMemberServiceImpl extends BaseServiceImpl<ImMultiRtcR ...@@ -23,10 +23,10 @@ public class ImMultiRtcRoomMemberServiceImpl extends BaseServiceImpl<ImMultiRtcR
private ImMultiRtcRoomMemberMapper imMultiRtcRoomMemberMapper; private ImMultiRtcRoomMemberMapper imMultiRtcRoomMemberMapper;
@Override @Override
public void changeRoomMemberState(ImClient currentClient, String roomId, Integer state) { public void changeRoomMemberState(Long fkClientId, String roomId, Integer state) {
this.update(new UpdateWrapper<ImMultiRtcRoomMember>().lambda() this.update(new UpdateWrapper<ImMultiRtcRoomMember>().lambda()
.eq(ImMultiRtcRoomMember::getRoomId, roomId) .eq(ImMultiRtcRoomMember::getRoomId, roomId)
.eq(ImMultiRtcRoomMember::getFkClientId, currentClient.getId()) .eq(ImMultiRtcRoomMember::getFkClientId, fkClientId)
.set(ImMultiRtcRoomMember::getState, state)); .set(ImMultiRtcRoomMember::getState, state));
} }
} }
...@@ -44,4 +44,9 @@ public interface MultiMeetService { ...@@ -44,4 +44,9 @@ public interface MultiMeetService {
*/ */
void notAnswered(NotAnsweredMultiMeetParam param); void notAnswered(NotAnsweredMultiMeetParam param);
/**
* 呼叫超时逻辑处理
*/
void callingTimeout();
} }
...@@ -27,6 +27,8 @@ import com.wecloud.multimeet.service.WsMultiMeetWrite; ...@@ -27,6 +27,8 @@ import com.wecloud.multimeet.service.WsMultiMeetWrite;
import com.wecloud.utils.SnowflakeUtil; import com.wecloud.utils.SnowflakeUtil;
import io.geekidea.springbootplus.framework.common.exception.BusinessException; import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -101,20 +103,28 @@ public class MultiMeetServiceImpl implements MultiMeetService { ...@@ -101,20 +103,28 @@ public class MultiMeetServiceImpl implements MultiMeetService {
continue; continue;
} }
// 占线 通知邀请方 // 占线 通知邀请方
ImMultiRtcRoomMember rtcRoomMember = imMultiRtcRoomMemberService.getOne(new QueryWrapper<ImMultiRtcRoomMember>().lambda() ImMultiRtcRoomMember busyMember = imMultiRtcRoomMemberService.getOne(new QueryWrapper<ImMultiRtcRoomMember>().lambda()
.eq(ImMultiRtcRoomMember::getClientId, toClientId) .eq(ImMultiRtcRoomMember::getClientId, toClientId)
.in(ImMultiRtcRoomMember::getState, Lists.newArrayList(MultiRtcMemberStateEnum.ANSWERED.getCode(), MultiRtcMemberStateEnum.CALLING.getCode()))); .in(ImMultiRtcRoomMember::getState, Lists.newArrayList(MultiRtcMemberStateEnum.ANSWERED.getCode(), MultiRtcMemberStateEnum.CALLING.getCode())));
if (rtcRoomMember != null && Lists.newArrayList(MultiRtcMemberStateEnum.ANSWERED.getCode(), MultiRtcMemberStateEnum.CALLING.getCode()).contains(rtcRoomMember.getState())) { if (busyMember != null && Lists.newArrayList(MultiRtcMemberStateEnum.ANSWERED.getCode(), MultiRtcMemberStateEnum.CALLING.getCode()).contains(busyMember.getState())) {
MultiMeetBusyResponse multiMeetBusyResponse = new MultiMeetBusyResponse(); MultiMeetBusyResponse multiMeetBusyResponse = new MultiMeetBusyResponse();
multiMeetBusyResponse.setConversationId(param.getConversationId()); multiMeetBusyResponse.setConversationId(param.getConversationId());
multiMeetBusyResponse.setRoomId(param.getRoomId()); multiMeetBusyResponse.setRoomId(param.getRoomId());
multiMeetBusyResponse.setClientId(currentClient.getClientId()); multiMeetBusyResponse.setClientId(currentClient.getClientId());
multiMeetBusyResponse.setBusyClientId(rtcRoomMember.getClientId()); multiMeetBusyResponse.setBusyClientId(busyMember.getClientId());
multiMeetBusyResponse.setTimestamp(System.currentTimeMillis()); multiMeetBusyResponse.setTimestamp(System.currentTimeMillis());
wsMultiMeetWrite.busy(multiMeetBusyResponse, currentClient.getId()); wsMultiMeetWrite.busy(multiMeetBusyResponse, currentClient.getId());
continue; continue;
} }
ImMultiRtcRoomMember rtcRoomMember = imMultiRtcRoomMemberService.getOne(new QueryWrapper<ImMultiRtcRoomMember>().lambda()
.eq(ImMultiRtcRoomMember::getClientId, toClientId)
.eq(ImMultiRtcRoomMember::getRoomId, param.getRoomId()));
if (rtcRoomMember != null) {
// 该房间已邀请过一次,再次发起邀请
rtcRoomMember.setState(MultiRtcMemberStateEnum.CALLING.getCode());
imMultiRtcRoomMemberService.updateById(rtcRoomMember);
continue;
}
ImMultiRtcRoomMember roomMember = new ImMultiRtcRoomMember(); ImMultiRtcRoomMember roomMember = new ImMultiRtcRoomMember();
roomMember.setId(SnowflakeUtil.getId()); roomMember.setId(SnowflakeUtil.getId());
roomMember.setFkRtcRoomId(rtcRoom.getId()); roomMember.setFkRtcRoomId(rtcRoom.getId());
...@@ -125,7 +135,6 @@ public class MultiMeetServiceImpl implements MultiMeetService { ...@@ -125,7 +135,6 @@ public class MultiMeetServiceImpl implements MultiMeetService {
roomMember.setCreateTime(new Date()); roomMember.setCreateTime(new Date());
roomMember.setUpdateTime(new Date()); roomMember.setUpdateTime(new Date());
roomMembersToSave.add(roomMember); roomMembersToSave.add(roomMember);
RoomMemberDto roomMemberDto = new RoomMemberDto(); RoomMemberDto roomMemberDto = new RoomMemberDto();
roomMemberDto.setFkClientId(toClient.getId()); roomMemberDto.setFkClientId(toClient.getId());
roomMemberDto.setClientId(toClient.getClientId()); roomMemberDto.setClientId(toClient.getClientId());
...@@ -161,7 +170,7 @@ public class MultiMeetServiceImpl implements MultiMeetService { ...@@ -161,7 +170,7 @@ public class MultiMeetServiceImpl implements MultiMeetService {
@Override @Override
public void reject(RejectToMultiMeetParam param) { public void reject(RejectToMultiMeetParam param) {
ImClient currentClient = imClientService.getCurrentClient(); ImClient currentClient = imClientService.getCurrentClient();
imMultiRtcRoomMemberService.changeRoomMemberState(currentClient, param.getRoomId(), MultiRtcMemberStateEnum.REJECTED.getCode()); imMultiRtcRoomMemberService.changeRoomMemberState(currentClient.getId(), param.getRoomId(), MultiRtcMemberStateEnum.REJECTED.getCode());
List<ImMultiRtcRoomMember> rtcRoomMemberList = imMultiRtcRoomMemberService.list( List<ImMultiRtcRoomMember> rtcRoomMemberList = imMultiRtcRoomMemberService.list(
new QueryWrapper<ImMultiRtcRoomMember>().lambda() new QueryWrapper<ImMultiRtcRoomMember>().lambda()
.eq(ImMultiRtcRoomMember::getRoomId, param.getRoomId()) .eq(ImMultiRtcRoomMember::getRoomId, param.getRoomId())
...@@ -198,7 +207,7 @@ public class MultiMeetServiceImpl implements MultiMeetService { ...@@ -198,7 +207,7 @@ public class MultiMeetServiceImpl implements MultiMeetService {
imMultiRtcRoomService.deleteMultiRtcRoomCache(currentClient.getFkAppid(), param.getRoomId()); imMultiRtcRoomService.deleteMultiRtcRoomCache(currentClient.getFkAppid(), param.getRoomId());
imMultiRtcRoomService.updateMultiRtcRoomState(param.getRoomId(), MultiRtcRoomStateEnum.MEETING.getCode()); imMultiRtcRoomService.updateMultiRtcRoomState(param.getRoomId(), MultiRtcRoomStateEnum.MEETING.getCode());
} }
imMultiRtcRoomMemberService.changeRoomMemberState(currentClient, param.getRoomId(), MultiRtcMemberStateEnum.ANSWERED.getCode()); imMultiRtcRoomMemberService.changeRoomMemberState(currentClient.getId(), param.getRoomId(), MultiRtcMemberStateEnum.ANSWERED.getCode());
List<ImMultiRtcRoomMember> rtcRoomMemberList = imMultiRtcRoomMemberService.list( List<ImMultiRtcRoomMember> rtcRoomMemberList = imMultiRtcRoomMemberService.list(
new QueryWrapper<ImMultiRtcRoomMember>().lambda() new QueryWrapper<ImMultiRtcRoomMember>().lambda()
.eq(ImMultiRtcRoomMember::getRoomId, param.getRoomId()) .eq(ImMultiRtcRoomMember::getRoomId, param.getRoomId())
...@@ -226,7 +235,7 @@ public class MultiMeetServiceImpl implements MultiMeetService { ...@@ -226,7 +235,7 @@ public class MultiMeetServiceImpl implements MultiMeetService {
@Override @Override
public void leave(LeaveFromMultiMeetParam param) { public void leave(LeaveFromMultiMeetParam param) {
ImClient currentClient = imClientService.getCurrentClient(); ImClient currentClient = imClientService.getCurrentClient();
imMultiRtcRoomMemberService.changeRoomMemberState(currentClient, param.getRoomId(), MultiRtcMemberStateEnum.LEAVE.getCode()); imMultiRtcRoomMemberService.changeRoomMemberState(currentClient.getId(), param.getRoomId(), MultiRtcMemberStateEnum.LEAVE.getCode());
List<ImMultiRtcRoomMember> rtcRoomMemberList = imMultiRtcRoomMemberService.list( List<ImMultiRtcRoomMember> rtcRoomMemberList = imMultiRtcRoomMemberService.list(
new QueryWrapper<ImMultiRtcRoomMember>().lambda() new QueryWrapper<ImMultiRtcRoomMember>().lambda()
.eq(ImMultiRtcRoomMember::getRoomId, param.getRoomId()) .eq(ImMultiRtcRoomMember::getRoomId, param.getRoomId())
...@@ -253,7 +262,26 @@ public class MultiMeetServiceImpl implements MultiMeetService { ...@@ -253,7 +262,26 @@ public class MultiMeetServiceImpl implements MultiMeetService {
@Override @Override
public void notAnswered(NotAnsweredMultiMeetParam param) { public void notAnswered(NotAnsweredMultiMeetParam param) {
ImClient currentClient = imClientService.getCurrentClient(); ImClient currentClient = imClientService.getCurrentClient();
imMultiRtcRoomMemberService.changeRoomMemberState(currentClient, param.getRoomId(), MultiRtcMemberStateEnum.NOT_ANSWERED.getCode()); imMultiRtcRoomMemberService.changeRoomMemberState(currentClient.getId(), param.getRoomId(), MultiRtcMemberStateEnum.NOT_ANSWERED.getCode());
}
@Override
public void callingTimeout() {
// 10 秒之前的时间
Date tenSecondsBefore = DateUtils.addSeconds(new Date(), -10);
// 获取呼叫时间为10秒之前 并且状态为呼叫中的会议成员
List<ImMultiRtcRoomMember> rtcRoomMemberList = imMultiRtcRoomMemberService.list(
new QueryWrapper<ImMultiRtcRoomMember>().lambda()
.eq(ImMultiRtcRoomMember::getCallTime, tenSecondsBefore)
.eq(ImMultiRtcRoomMember::getState, MultiRtcMemberStateEnum.CALLING.getCode())
);
if (CollectionUtils.isEmpty(rtcRoomMemberList)) {
return;
}
for (ImMultiRtcRoomMember roomMember : rtcRoomMemberList) {
roomMember.setState(MultiRtcMemberStateEnum.NOT_ANSWERED.getCode());
}
imMultiRtcRoomMemberService.updateBatchById(rtcRoomMemberList);
} }
} }
-- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本 -- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本
...@@ -146,6 +146,7 @@ CREATE TABLE `im_multi_rtc_room_member` ...@@ -146,6 +146,7 @@ CREATE TABLE `im_multi_rtc_room_member`
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
KEY `idx_fk_rtc_room_id` (`fk_rtc_room_id`) USING BTREE, KEY `idx_fk_rtc_room_id` (`fk_rtc_room_id`) USING BTREE,
KEY `idx_room_id` (`room_id`) USING BTREE, KEY `idx_room_id` (`room_id`) USING BTREE,
KEY `idx_call_time_state` (`call_time`, `state`) USING BTREE,
KEY `idx_client_id` (`client_id`) USING BTREE KEY `idx_client_id` (`client_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='多人音视频房间成员表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='多人音视频房间成员表';
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
<module>generator</module> <module>generator</module>
<module>core</module> <module>core</module>
<module>client</module> <module>client</module>
<module>scheduled</module>
<!-- <module>api-app</module>--> <!-- <module>api-app</module>-->
<!-- <module>distribution</module>--> <!-- <module>distribution</module>-->
<!-- <module>admin</module>--> <!-- <module>admin</module>-->
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
<description>任务调度JOB模块</description> <description>任务调度JOB模块</description>
<dependencies> <dependencies>
<!-- <dependency>-->
<!-- <groupId>io.geekidea.springbootplus</groupId>--> <dependency>
<!-- <artifactId>example</artifactId>--> <groupId>io.geekidea.springbootplus</groupId>
<!-- </dependency>--> <artifactId>core</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -31,7 +31,7 @@ public class HelloScheduled { ...@@ -31,7 +31,7 @@ public class HelloScheduled {
/** /**
* 每小时执行一次 * 每小时执行一次
*/ */
@Scheduled(cron = "0 0 0/1 * * ? ") // @Scheduled(cron = "*/5 * * * * ? ")
public void hello() throws Exception { public void hello() throws Exception {
log.info("HelloScheduled..."); log.info("HelloScheduled...");
} }
......
package io.geekidea.springbootplus.scheduled;
import com.wecloud.multimeet.service.MultiMeetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* @Author wenzhida
* @Date 2022/3/28 16:34
* @Description 多人音视频相关定时器
*/
@Slf4j
@Component
public class MultiMeetScheduled {
@Autowired
private MultiMeetService multiMeetService;
/**
* 呼叫超时处理
* 每5秒执行一次
*/
@Scheduled(cron = "*/5 * * * * ?")
public void callingTimeout() {
log.info("呼叫超时处理开始...");
multiMeetService.callingTimeout();
log.info("呼叫超时处理结束...");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment