123333
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ruoyi.cai.ws.handler;
|
|||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.esotericsoftware.minlog.Log;
|
||||||
import com.ruoyi.cai.chat.ChatManager;
|
import com.ruoyi.cai.chat.ChatManager;
|
||||||
import com.ruoyi.cai.ws.bean.FdCtxData;
|
import com.ruoyi.cai.ws.bean.FdCtxData;
|
||||||
import com.ruoyi.cai.ws.bean.Room;
|
import com.ruoyi.cai.ws.bean.Room;
|
||||||
@@ -12,6 +13,7 @@ import com.ruoyi.cai.ws.service.CheckConnectionDTO;
|
|||||||
import com.ruoyi.cai.ws.service.RoomService;
|
import com.ruoyi.cai.ws.service.RoomService;
|
||||||
import com.ruoyi.cai.ws.util.WsExceptionUtil;
|
import com.ruoyi.cai.ws.util.WsExceptionUtil;
|
||||||
import jodd.util.StringUtil;
|
import jodd.util.StringUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.socket.TextMessage;
|
import org.springframework.web.socket.TextMessage;
|
||||||
@@ -23,6 +25,7 @@ import java.util.Map;
|
|||||||
* ws消息处理器统一入口
|
* ws消息处理器统一入口
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class MessageHandleApplication {
|
public class MessageHandleApplication {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -36,6 +39,7 @@ public class MessageHandleApplication {
|
|||||||
|
|
||||||
public void processOn(WebSocketSession session, TextMessage message) {
|
public void processOn(WebSocketSession session, TextMessage message) {
|
||||||
String payload = message.getPayload();
|
String payload = message.getPayload();
|
||||||
|
log.info("调试日志:收到websocket的请求 message={}",payload);
|
||||||
if(StringUtil.isEmpty(payload)){
|
if(StringUtil.isEmpty(payload)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -48,17 +52,20 @@ public class MessageHandleApplication {
|
|||||||
WsToken wsToken = chatManager.getToken(String.valueOf(attributes.get("token")));
|
WsToken wsToken = chatManager.getToken(String.valueOf(attributes.get("token")));
|
||||||
if(wsToken == null){
|
if(wsToken == null){
|
||||||
WsExceptionUtil.throwExceptionFast(session,"无效token");
|
WsExceptionUtil.throwExceptionFast(session,"无效token");
|
||||||
|
log.info("调试日志:无效的token token={}", attributes.get("token"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Long roomId = wsToken.getRoomId();
|
Long roomId = wsToken.getRoomId();
|
||||||
Room room = roomService.load(roomId);
|
Room room = roomService.load(roomId);
|
||||||
if(room == null){
|
if(room == null){
|
||||||
WsExceptionUtil.throwException(session, "房间不可用" ,HangUpEnums.OTHER, roomId);
|
WsExceptionUtil.throwException(session, "房间不可用" ,HangUpEnums.OTHER, roomId);
|
||||||
|
log.info("调试日志:房间不可用 wsToken={}", JSON.toJSONString(wsToken));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CheckConnectionDTO checkConnect = roomService.checkConnect(room);
|
CheckConnectionDTO checkConnect = roomService.checkConnect(room);
|
||||||
if(checkConnect != null){
|
if(checkConnect != null){
|
||||||
WsExceptionUtil.throwException(session,checkConnect.getMessage(),checkConnect.getHangUpEnums(),roomId);
|
WsExceptionUtil.throwException(session,checkConnect.getMessage(),checkConnect.getHangUpEnums(),roomId);
|
||||||
|
log.info("调试日志:链接已完毕 room={}", JSON.toJSONString(room));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IMessageHandler handler = map.get(String.valueOf(method));
|
IMessageHandler handler = map.get(String.valueOf(method));
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.cai.ws.job;
|
package com.ruoyi.cai.ws.job;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.ruoyi.cai.domain.UserCall;
|
import com.ruoyi.cai.domain.UserCall;
|
||||||
import com.ruoyi.cai.notice.YunxinWsServiceV2;
|
import com.ruoyi.cai.notice.YunxinWsServiceV2;
|
||||||
@@ -18,12 +19,14 @@ import com.ruoyi.cai.ws.service.SettleService;
|
|||||||
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
import com.ruoyi.cai.ws.util.RoomWebSocketUtil;
|
||||||
import com.ruoyi.yunxin.Yunxin;
|
import com.ruoyi.yunxin.Yunxin;
|
||||||
import com.ruoyi.cai.notice.enums.CallNoticeEnum;
|
import com.ruoyi.cai.notice.enums.CallNoticeEnum;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class RoomCheckJobService {
|
public class RoomCheckJobService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -39,23 +42,33 @@ public class RoomCheckJobService {
|
|||||||
|
|
||||||
public JobResp checkRoom(Long roomId){
|
public JobResp checkRoom(Long roomId){
|
||||||
Room room = roomService.load(roomId);
|
Room room = roomService.load(roomId);
|
||||||
|
log.info("调试日志:开始检查房间 room={}" , JSON.toJSONString(room));
|
||||||
if(room == null){
|
if(room == null){
|
||||||
return JobResp.builder().nextCreateJob(false).build();
|
return JobResp.builder().nextCreateJob(false).build();
|
||||||
}
|
}
|
||||||
// 检查是否三分钟没有接听
|
// 检查是否三分钟没有接听
|
||||||
|
log.info("调试日志:检查是否三分钟没有接听 roomId={}" , roomId);
|
||||||
JobResp resp = this.checkRoomCallerTimeOut(room);
|
JobResp resp = this.checkRoomCallerTimeOut(room);
|
||||||
if(!resp.isNextCreateJob()){
|
if(!resp.isNextCreateJob()){
|
||||||
|
log.info("调试日志:三分钟没有接听,可能关闭了 roomId={}" , roomId);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
// 检查心跳
|
// 检查心跳
|
||||||
|
log.info("调试日志:检查心跳是否超时 roomId={}" , roomId);
|
||||||
JobResp heartbeat = checkRoomHeartbeat(room);
|
JobResp heartbeat = checkRoomHeartbeat(room);
|
||||||
if(!heartbeat.isNextCreateJob()){
|
if(!heartbeat.isNextCreateJob()){
|
||||||
|
log.info("调试日志:心跳超时了,可能关闭了 roomId={}" , roomId);
|
||||||
return heartbeat;
|
return heartbeat;
|
||||||
}
|
}
|
||||||
this.checkCanCallTime(room);
|
this.checkCanCallTime(room);
|
||||||
// 尝试结算一下
|
// 尝试结算一下
|
||||||
|
log.info("调试日志:开始尝试结算 roomId={}" , roomId);
|
||||||
SettleResp settleResp = settleService.processOn(roomId);
|
SettleResp settleResp = settleService.processOn(roomId);
|
||||||
return JobResp.builder().nextCreateJob(settleResp.isNextRun()).build();
|
JobResp build = JobResp.builder().nextCreateJob(settleResp.isNextRun()).build();
|
||||||
|
if(!build.isNextCreateJob()){
|
||||||
|
log.info("调试日志:结算成功了,可能关闭了 roomId={}" , roomId);
|
||||||
|
}
|
||||||
|
return build;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,17 @@ public class WebSocketUtils {
|
|||||||
* @param message 消息文本
|
* @param message 消息文本
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(String sessionKey, String message) {
|
public static void sendMessage(String sessionKey, String message) {
|
||||||
|
if(sessionKey == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
WebSocketSession session = WebSocketSessionHolder.getSessions(sessionKey);
|
WebSocketSession session = WebSocketSessionHolder.getSessions(sessionKey);
|
||||||
sendMessage(session, message);
|
sendMessage(session, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean close(String sessionKey) {
|
public static boolean close(String sessionKey) {
|
||||||
|
if(sessionKey == null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
WebSocketSession sessions = WebSocketSessionHolder.getSessions(sessionKey);
|
WebSocketSession sessions = WebSocketSessionHolder.getSessions(sessionKey);
|
||||||
return close(sessions);
|
return close(sessions);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="bo.toMobile != null and bo.toMobile != ''">
|
<if test="bo.toMobile != null and bo.toMobile != ''">
|
||||||
and t3.mobile = #{bo.fromMobile}
|
and t3.mobile = #{bo.fromMobile}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="bo.id != null">
|
||||||
|
and t1.id = #{bo.id}
|
||||||
|
</if>
|
||||||
<if test="bo.status != null">
|
<if test="bo.status != null">
|
||||||
and t1.status = #{bo.status}
|
and t1.status = #{bo.status}
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
Reference in New Issue
Block a user