init
This commit is contained in:
@@ -9,18 +9,18 @@ import com.ruoyi.cai.trd.ImMsgGen;
|
||||
import com.ruoyi.cai.ws.bean.Room;
|
||||
import com.ruoyi.cai.ws.bean.UserData;
|
||||
import com.ruoyi.cai.ws.cache.OnlineDataCache;
|
||||
import com.ruoyi.cai.ws.cache.RoomCtxCache;
|
||||
import com.ruoyi.cai.ws.constant.RoomStatusEnums;
|
||||
import com.ruoyi.cai.ws.service.RoomService;
|
||||
import com.ruoyi.cai.ws.service.SettleService;
|
||||
import com.ruoyi.yunxin.Yunxin;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CheckTimeOutJob {
|
||||
@Autowired
|
||||
private OnlineDataCache onlineDataCache;
|
||||
@@ -29,13 +29,14 @@ public class CheckTimeOutJob {
|
||||
@Autowired
|
||||
private UserCallService userCallService;
|
||||
@Autowired
|
||||
private RoomCtxCache roomCtxCache;
|
||||
private SettleService settleService;
|
||||
@Autowired
|
||||
private Yunxin yunxin;
|
||||
|
||||
/**
|
||||
* 1 分钟执行一次
|
||||
* 检查房间是不是三分钟没有接听, 需要自动挂断掉
|
||||
*/
|
||||
@Scheduled(fixedDelay = 60,timeUnit = TimeUnit.SECONDS)
|
||||
// @Scheduled(fixedDelay = 60,timeUnit = TimeUnit.SECONDS)
|
||||
public void run(){
|
||||
Set<String> roomIdStr = onlineDataCache.getAll();
|
||||
for (String roomIdS : roomIdStr) {
|
||||
@@ -45,7 +46,11 @@ public class CheckTimeOutJob {
|
||||
}
|
||||
|
||||
public void deal(Long roomId){
|
||||
log.info("开始执行房间超时检测,是否一直不接 roomId={}",roomId);
|
||||
Room room = roomService.load(roomId);
|
||||
if(room == null){
|
||||
return;
|
||||
}
|
||||
if(!RoomStatusEnums.STATUS_CALLER_CONNECT.getCode().equals(room.getStatus())
|
||||
&& !RoomStatusEnums.STATUS_RECEIVER_CONNECT.getCode().equals(room.getStatus())){
|
||||
return;
|
||||
@@ -66,6 +71,7 @@ public class CheckTimeOutJob {
|
||||
userCallService.update(Wrappers.lambdaUpdate(UserCall.class)
|
||||
.eq(UserCall::getId,roomId)
|
||||
.set(UserCall::getStatus, RoomStatusEnums.STATUS_TIMEOUT_CANCEL.getCode()));
|
||||
// TODO 需要放开主播的接听状态
|
||||
roomService.closeAllFd(roomId);
|
||||
ImDataRes imDataRes = ImMsgGen.callNotice(3, callUserData.getId(), receiverUserData.getId(), 0);
|
||||
yunxin.sendToSync(receiverUserData.getId(),callUserData.getId(),imDataRes);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class HeartbeatJob {
|
||||
|
||||
|
||||
/**
|
||||
* 30秒执行一次
|
||||
* 30秒执行一次 心跳只处理接听后的心跳
|
||||
*/
|
||||
@Scheduled(fixedDelay = 30,timeUnit = TimeUnit.SECONDS)
|
||||
public void run(){
|
||||
@@ -50,6 +50,9 @@ public class HeartbeatJob {
|
||||
try {
|
||||
Long roomId = Long.valueOf(roomIdS);
|
||||
Room room = roomService.load(roomId);
|
||||
if(room == null){
|
||||
return;
|
||||
}
|
||||
if(!room.isCanCall()){
|
||||
return;
|
||||
}
|
||||
@@ -69,7 +72,7 @@ public class HeartbeatJob {
|
||||
userCallService.update(Wrappers.lambdaUpdate(UserCall.class)
|
||||
.eq(UserCall::getId,roomId)
|
||||
.set(UserCall::getStatus, RoomStatusEnums.STATUS_TIMEOUT_CANCEL.getCode()));
|
||||
settleService.processOn(room);
|
||||
settleService.processOn(roomId);
|
||||
}
|
||||
List<String> keys = roomCtxCache.getSessionKeysByRoomId(roomId);
|
||||
RoomWebSocketUtil.sendSendMessage(keys, hangup);
|
||||
|
||||
@@ -25,17 +25,13 @@ public class SettleJob {
|
||||
/**
|
||||
* 每 1 分钟执行一次
|
||||
*/
|
||||
@Scheduled(fixedDelay = 60,timeUnit = TimeUnit.SECONDS)
|
||||
// @Scheduled(fixedDelay = 60,timeUnit = TimeUnit.SECONDS)
|
||||
public void run(){
|
||||
Set<String> all = onlineDataCache.getAll();
|
||||
for (String roomIdS : all) {
|
||||
try {
|
||||
Long roomId = Long.valueOf(roomIdS);
|
||||
Room room = roomService.load(roomId);
|
||||
if(room == null){
|
||||
return;
|
||||
}
|
||||
settleService.processOn(room);
|
||||
settleService.processOn(roomId);
|
||||
}catch (Exception e){
|
||||
log.info("定时任务结算失败!",e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user